You don't need setrotation unless you want to align your bullet sprite to its direction of travel. You need to keep track of your bullet direction and move it along that path.
Here is the simplest demo I could knock up...
SuperStrict
Type bullet
Field xdir:float
Field ydir:Float
Field x:float
Field y:float
Global blist:TList = New TList
Function Create:bullet( x:Float, y:Float, xdir:Float, ydir:float )
Local n:bullet = New bullet
n.x = x
n.y = y
n.xdir = xdir / 50
n.ydir = ydir / 50
blist.addlast( n )
Return n
End Function
Method update()
x :+ xdir
y :+ ydir
If ( x < -10 Or x > 610 Or y < -10 Or y > 610 ) blist.remove( Self )
End Method
Function updateall()
For Local b:bullet = EachIn blist
b.update()
Next
End Function
Function drawall()
For Local b:bullet = EachIn blist
b.draw()
Next
End Function
Method draw()
DrawRect( x - 1, y - 1, 3, 3 )
End Method
End Type
Global playerX:Int = 300
Global playerY:Int = 400
Graphics 600, 600
While Not AppTerminate()
bullet.Updateall()
Cls
bullet.Drawall()
DrawRect( playerX - 5, playerY, 10, 4 )
If ( KeyDown( KEY_A ) ) playerX = Max( 0, playerX - 5 )
If ( KeyDown( KEY_D ) ) playerX = Min( 600, playerX + 5 )
If MouseDown(1) bullet.Create( playerX, playerY, MouseX() - playerX, MouseY() - playerY )
Flip 1
Wend
|