Code: Select all
FrameLimit 50
tilemap = LoadMap("Media\cdm2.til","Media\tileset.bmp")
PlayObject tilemap,0,0,1
ObjectPickable tilemap,1
guy = LoadObject ("Media\guy.bmp",72)
guy2 = LoadObject ("Media\guy.bmp",72)
ObjectPickable guy2,2
MoveObject guy2,0,200
SetupCollision guy, tilemap, 1, 4, 2
//VARIABLES NEEDED
Const ACCURACY=1 //radar accuracy
Global ang#,fade,speed
ang=0.0 //angle of the pointer
fade=100 //fading speed of the result
speed=7 //speed of the pointer
Repeat
'Ukon ohjaus
If LeftKey() Then TurnObject guy,5
If RightKey() Then TurnObject guy,-5
If UpKey() Then MoveObject guy,2
If DownKey() Then MoveObject guy,-2
CloneCameraPosition guy
DrawGame
Color cbwhite
Text 0,0,FPS()
Radar(50,50,100,guy,tilemap,300)
DrawScreen
Forever
//x = radar drawing position (center)
//y = --||--
//r = radius of the radar circle
//obj = object we get the radar from
//map = tilemap used
//range# = range of the radarbeam
Function Radar(x,y,r,obj,map,range#)
//draw base
Color 0,40,0
Circle x-r/2,y-r/2,r,1
Color 0,80,0
Circle x-r/2,y-r/2,r,0
oldangle=ObjectAngle(obj) //save the old angle of the guy
For i=ang-fade To ang Step ACCURACY //loop trought a loop
RotateObject obj,i
ObjectPick obj
Dist#=Distance(PickedX(),PickedY(),ObjectX(obj),ObjectY(obj))
If Dist<range Then // if the picked object is in the range of the beam
rdist#=dist/range //make the distance good for the scale of the radar
If pickedobject()=map Then
Color 0,150+Max(i-ang,-110),0
Else //this ain't no wall, shoot it!
Color 200+Max(i-ang,-160),0,0
EndIf
Dot x+Cos(i)*r/2*rDist,y-Sin(i)*r/2*rDist
EndIf
Next i
RotateObject obj,oldangle //restore the old angle of the object
//update and draw teh pointer
ang+speed
Color 0,80,0
Line x,y,x+Cos(ang)*r/2,y-Sin(ang)*r/2
EndFunction