You know... like dealing cards on to a table.
So I create an array of locations for the cards to fall (this is just a junk list here, but the locations are good)
Then I click the mouse button (LEFT) and it fires at the first one. All goes well. Target removed.
Then I fire at the next location but the angle is badly off.
Origination point is 0, 0
Code: Select all
; Pressing left mousebutton fires a shot in the direction of the mouse cursor
Enumeration
#Head
#Body
#Bullet
#Cursor
#Target
EndEnumeration
Structure Projectile
x.f
y.f
goalX.f
goalY.f
Angle.l
SpeedoX.f
SpeedoY.f
GoalAngle.l
EndStructure
Global Dim CardPOSX(10) ; X value of TARGET
Global Dim CardPOSY(10) ; Y value of TARGET
Global Dim TLOC(1) ; to check if card has arrived at TARGET LOCATION
Global NewList Projectile.Projectile()
Global Goalangle, SpeedoX.f, SpeedoY.f
cardPosX(0) = 50 ; DECK pile X
cardPosY(0) = 50 ; Y
cardPosX(1) = 550; discard X1
cardPosY(1) = 50 ; Y
cardPosX(2) = 100 ; enemy x 1
cardPosY(2) = 50 ; y
cardPosX(3) = 150 ; enemy X 2
cardPosY(3) = 50 ; y
cardPosX(4) = 250 ; player x1
cardPosY(4) = 50
cardPosX(5) = 100 ; X2
cardPosY(5) = 150
; deal
cardPosX(6) = 200
cardPosY(6) = 150
cardPosX(7) = 300
cardPosY(7) = 150
cardPosX(8) = 50
cardPosY(8) = 450 ; flop
cardPosX(9) = 200
cardPosY(9) = 450 ; 4th street
cardPosX(10) = 500
cardPosY(10) = 450 ; river
Procedure.l gATan(a.l, b.l)
Angle.l = Int(ATan(a/b)*57.2957795)
If b < 0
Angle + 180
EndIf
If Angle < 0 : Angle + 360 : EndIf
If Angle > 359 : Angle - 360 : EndIf
ProcedureReturn Angle
EndProcedure
Procedure.f gSin(Angle.l)
; Eingabe: Angle ( 0 - 360 )
; Ausgabe: Sine with Angle
ProcedureReturn Sin(Angle*0.01745329)
EndProcedure
Procedure.f gCos(Angle.l)
; Entry Angle ( 0 - 360 )
; Output: Cosine with Angle
ProcedureReturn Cos(Angle*0.01745329)
EndProcedure
Procedure NewBullet(x.f, y.f, goalX.f, goalY.f)
AddElement(Projectile())
Projectile()\x = x
Projectile()\y = y
Projectile()\goalx = TLOC(0)
Projectile()\goaly = TLOC(1)
Projectile()\SpeedoX = SpeedoX * 8 ; 10 speeds it up
Projectile()\SpeedoY = SpeedoY * 8
EndProcedure
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
MessageRequester("Error", "DirectX 7 Fail!", 0)
End
EndIf
wide = 800
High = 600
If OpenScreen ( wide, High,32,"Standard") = 0
MessageRequester("Error", "No screen could be Initialized...", 0)
End
EndIf
If InitSprite3D() = 0
MessageRequester("DirectX fail !", "Cannot open DirectX...", #PB_MessageRequester_Ok)
End
EndIf
LoadSprite(#Cursor, "BLIP\cursor0.bmp",#PB_Sprite_Memory)
LoadSprite(1013, "BLIP\blip03.bmp",#PB_Sprite_Texture)
LoadSprite(#Target, "BLIP\blip14.bmp",#PB_Sprite_Memory)
Sprite3DQuality(#PB_Sprite3D_BilinearFiltering)
CreateSprite3D(#Bullet, 1013)
Maus.Point
TLOC(0) = CardPOSX(0)
TLOC(1) = CARDPOSY(0) ; gets initial position for target
Repeat
ClearScreen(RGB(0,0,0))
ExamineMouse()
ExamineKeyboard()
Maus\x = MouseX() - 16
Maus\y = MouseY() - 16
Start3D()
DisplayTransparentSprite(#Target, TLOC(0), TLOC(1) ) ; just to show where we are supposed to be
If MouseButton(1)
a.l = TLOC(0)
b.l = TLOC(1)
GoalAngleX = gATan(a, b)
If Delaytime < 1
Delaytime = 10 ; was 10 THIS IS HOW FAST YOU FIRE
Speedo.l = 12
Lifetime.l = 20 ; was 33
SpeedoX = gCos(GoalAngleX)
SpeedoY = gSin(GoalAngleX)
NewBullet(0,0,SpeedoX , SpeedoY)
DisplaySprite3D(#Bullet, Projectile()\x, Projectile()\y )
EndIf
If Delaytime > 0
Delaytime - 1
EndIf
EndIf
ResetList(Projectile())
While NextElement(Projectile())
If Projectile()\x < 0 Or Projectile()\y < 0 Or Projectile()\x > wide Or Projectile()\y > High
DeleteElement(Projectile())
Else
Projectile()\x + Projectile()\SpeedoX
Projectile()\y + Projectile()\SpeedoY
Projectile()\Angle + 8 ; rotation try 3, 8, 12 and 48
RotateSprite3D(#Bullet, Int(Projectile()\Angle), 0)
DisplaySprite3D(#Bullet, Int(Projectile()\x), Int(Projectile()\y))
EndIf
Wend
; ***************************************************************************************
; check for collision {{THUNK OUT BY Ice-Soft}} mangeld by Rook Zimbabwe
; ***************************************************************************************
ResetList(Projectile())
While NextElement(Projectile())
ForEach(Projectile())
If SpriteCollision(1013, Projectile()\x,Projectile()\y, #Target, TLOC(0), TLOC(1))
DeleteElement(Projectile())
google = google + 1
TLOC(0) = CARDPOSX(google)
TLOC(1) = CARDPOSY(google)
Break
EndIf
Next
Wend
Stop3D()
DisplayTransparentSprite(#Cursor, Maus\x, Maus\y)
StartDrawing( ScreenOutput())
DrawText(370, 550, "X: "+Str(TLOC(0))+" Y: "+Str(TLOC(1)), RGB(255,255,255), RGB(0,0,0))
StopDrawing()
FlipBuffers()
If KeyboardPushed(#PB_Key_Escape)
Quit = 1
EndIf
Delay(3)
Until Quit

