belaw the code:
Code: Select all
;>------------------------------------
;
; by Danilo, 20.11.2003 - german forum
; extends by zomtex2003, 23.11.2003
;>------------------------------------
;#Width = 1600
;#Height = 1200
#Width = 640
#Height = 480
;#Width = 1024
;#Height = 768
;#Width = 800
;#Height = 600
PI.f = 3.141593
#x_0 = #Width / 2
#y_0 = #Height / 2
#rotator_speed = 3
#max_objects = 10
CurrentAngle = 180
Structure _OBJ
x.l
y.l
Transparency.l
Degree.f
EndStructure
Procedure.f winkel(x1.f,y1.f,x2.f,y2.f)
a.f = x2-x1
b.f = y2-y1
c.f = Sqr(a*a+b*b)
winkel.f = ACos(a/c)*57.29577
If y1 < y2 : winkel=360-winkel : EndIf
ProcedureReturn winkel
EndProcedure
Procedure.f GSin(winkel.f)
ProcedureReturn Sin(winkel*(2*3.14159265/360))
EndProcedure
Procedure.f GCos(winkel.f)
ProcedureReturn Cos(winkel*(2*3.14159265/360))
EndProcedure
Procedure ObjectSound(x)
PlaySound(0)
EndProcedure
Procedure MakeSprites()
h = #Height-100
CreateSprite(1,512,512,#PB_Sprite_PixelCollision)
CreateSprite(2,512,512,#PB_Sprite_PixelCollision)
CreateSprite(3,h,h,#PB_Sprite_PixelCollision)
CreateSprite(4, 140, 20)
; Radar rotator (green > black)
StartDrawing(SpriteOutput(1))
angle.f=90
Repeat
Line(255,255,GSin(angle)*255.0,GCos(angle)*255,RGB(0, Int(angle*2.8), 0))
angle.f - 0.001
Until angle <=0
StopDrawing()
; Radar objects
StartDrawing(SpriteOutput(2))
For a = 127 To 0 Step -1
Circle(127,127,a,RGB(255-2*a,255-2*a,255-2*a))
Next a
StopDrawing()
ZoomSprite(2,32,32)
; Radar chassis
StartDrawing(SpriteOutput(3))
Circle(h/2,h/2,h/2,RGB($40,$40,$40))
Circle(h/2,h/2,h/2-10,RGB($00,$00,$00))
DrawingMode(4)
For a = 0 To 5
Circle(h/2,h/2,h/10*a,RGB($40,$40,$40))
Next a
For a = -2 To 2
Line(0,h/2+a,h,0,RGB($40,$40,$40))
Next a
For a = -2 To 2
Line(h/2+a,0,0,h,RGB($40,$40,$40))
Next a
For a = 30 To 330 Step 30
Line(h/2,h/2,GSin(a)*h/2,GCos(a)*h/2,RGB($40,$40,$40))
Next a
For i = 0 To #Width Step 32
LineXY(0, i, #Width, i, RGB(0, 80, 0))
Next i
For i = 0 To #Width Step 32
LineXY(i, 0, i, #Width, RGB(0, 80, 0))
Next i
StopDrawing()
EndProcedure
Dim Objects._OBJ(#max_objects)
OpenWindow(0,100,100,640,480,"Radar",#PB_Window_BorderLess)
InitKeyboard()
InitSprite()
InitSound()
OpenWindowedScreen(WindowID(0),0,0,640,480,0,0, #PB_Screen_SmartSynchronization)
Define pd3d.IDirect3DDevice9
EnableASM
!extrn _PB_Screen_Direct3DDevice
!MOV dword EAX, [_PB_Screen_Direct3DDevice]
!MOV dword [v_pd3d],EAX
DisableASM
pd3d\SetRenderState(22,1)
pd3d\SetRenderState(7,0)
LoadSound(0, "sonar2.wav")
LoadSound(2, "background.wav")
SoundVolume(0, 50)
SoundVolume(2, 60)
PlaySound(2, 1)
MakeSprites()
;- Init objects
xKoo = 18
yKoo = 22
Objects(1)\x = xKoo
Objects(1)\y = yKoo
If Round(winkel(0, 0, 12, 12) - (winkel(0, 0, xKoo, yKoo) - winkel(0, 0, 12, 12)), 1) > 360
Objects(1)\Degree = Round(winkel(0, 0, 12, 12) - (winkel(0, 0, xKoo, yKoo) - winkel(0, 0, 12, 12)), 1) - 360
Else
Objects(1)\Degree = Round(winkel(0, 0, 12, 12) - (winkel(0, 0, xKoo, yKoo) - winkel(0, 0, 12, 12)), 1)
EndIf
xKoo = 0
yKoo = 0
Objects(2)\x = xKoo
Objects(2)\y = yKoo
If Round(winkel(0, 0, 12, 12) - (winkel(0, 0, xKoo, yKoo) - winkel(0, 0, 12, 12)), 1) > 360
Objects(2)\Degree = Round(winkel(0, 0, 12, 12) - (winkel(0, 0, xKoo, yKoo) - winkel(0, 0, 12, 12)), 1) - 360
Else
Objects(2)\Degree = Round(winkel(0, 0, 12, 12) - (winkel(0, 0, xKoo, yKoo) - winkel(0, 0, 12, 12)), 1)
EndIf
xKoo = 20
yKoo = -5
Objects(3)\x = xKoo
Objects(3)\y = yKoo
If Round(winkel(0, 0, 12, 12) - (winkel(0, 0, xKoo, yKoo) - winkel(0, 0, 12, 12)), 1) > 360
Objects(3)\Degree = Round(winkel(0, 0, 12, 12) - (winkel(0, 0, xKoo, yKoo) - winkel(0, 0, 12, 12)), 1) - 360
Else
Objects(3)\Degree = Round(winkel(0, 0, 12, 12) - (winkel(0, 0, xKoo, yKoo) - winkel(0, 0, 12, 12)), 1)
EndIf
;- Main loop
Repeat
; ** buffer timer of loop start
timer = ElapsedMilliseconds()
time = timeGetTime_()
ExamineKeyboard()
If IsScreenActive() And ScreenDeactivated = #False
Angle.f + #rotator_speed
If Angle > 360:Angle-360
EndIf
If CurrentAngle = 0 : ObjectSound(0)
EndIf
ClearScreen(RGB(0,0,0))
SpriteQuality(#PB_Sprite_BilinearFiltering)
ZoomSprite(1,#Height-100,#Height-100)
RotateSprite(1,Angle,#PB_Absolute)
CurrentAngle + #rotator_speed
If CurrentAngle >= 180 And Angle = 180: CurrentAngle = 0
EndIf
DisplaySprite(1,(#Width-#Height)/2+50,50)
DisplayTransparentSprite(3,(#Width-#Height)/2+50,50)
; SpriteBlendingMode(5,2)
; Objects
For a = 0 To #max_objects
StartDrawing(SpriteOutput(4))
DrawingMode(4)
Box(0, 0, 140, 20, RGB(0, 255, 0))
DrawingMode(4)
Box(1, 1, 138, 17, RGB(0, 0, 0))
FrontColor(RGB(0, 255, 0))
DrawText(5, 2,"OB:" + Str(a) + " - " + Str(Objects(a)\Degree) + "° - d: " + Str(Sqr(Pow(Objects(a)\x, 2) + Pow(Objects(a)\y, 2))))
StopDrawing()
If Objects(a)\x Or Objects(a)\y
If (CurrentAngle + 180) < Objects(a)\Degree + 180 And (CurrentAngle + 180) > Objects(a)\Degree +175 And Objects(a)\Transparency<200
Objects(a)\Transparency=255
EndIf
EndIf
If Objects(a)>0
Objects(a)\Transparency-#rotator_speed
If Objects(a)\Transparency<0
Objects(a)\Transparency=0
EndIf
EndIf
If Objects(a)\x Or Objects(a)\y
DisplayTransparentSprite(2, (#x_0 - 16) + Objects(a)\x, (#y_0 - 16) - Objects(a)\y, Objects(a)\Transparency)
DisplayTransparentSprite(4, (#x_0 - 16) + Objects(a)\x + 15, (#y_0 - 16) - Objects(a)\y - 5, 255)
EndIf
Next a
g + 1
If g = 50
For a = 1 To 3
Select(a)
Case 1
Objects(a)\x - 3
Objects(a)\y + 2
Case 2
Objects(a)\x + 1
Objects(a)\y + 0
Case 3
Objects(a)\x + 2
Objects(a)\y - 1
EndSelect
If Round(winkel(0, 0, 12, 12) - (winkel(0, 0, Objects(a)\x, Objects(a)\y) - winkel(0, 0, 12, 12)), 1) > 360
Objects(a)\Degree = Round(winkel(0, 0, 12, 12) - (winkel(0, 0, Objects(a)\x, Objects(a)\y) - winkel(0, 0, 12, 12)), 1) - 360
Else
Objects(a)\Degree = Round(winkel(0, 0, 12, 12) - (winkel(0, 0, Objects(a)\x, Objects(a)\y) - winkel(0, 0, 12, 12)), 1)
EndIf
Next a
g = 0
EndIf
; ElseIf ScreenDeactivated = #False
; ScreenDeactivated = #True
; ElseIf IsScreenActive() And ScreenDeactivated = #True
; ScreenDeactivated = #False
; FlipBuffers()
; MakeSprites()
EndIf
FlipBuffers()
Repeat:Delay(1):Until timeGetTime_()-20>=time
Until KeyboardPushed(#PB_Key_Escape)
;- End

