I have been able to sort out how to shoot an animated bullet, but i can't figure out how to get the bullet to fire in the direction the player is facing. Right now the bullet will only fire to the right from the players position. Here is what I have so far. Thank you for any help you can give.
rem set a virtual resolution of 320 x 480
SetVirtualResolution ( 320, 480 )
AddVirtualJoystick ( 1, 35, 445, 64 )
AddVirtualButton ( 2, 285, 445, 50 )
rem data structures
type bullettype
alive
x
y
dirx
diry
endtype
dim bullet[100] as bullettype
rem load an image that contains several frames of animation
LoadImage ( 1, "skeleton_walk_001.png" )
CreateSprite ( 1, 1 )
SetSpriteAnimation ( 1, 64, 64, 24 )
SetSpriteDepth ( 1, 0 )
SetSpritePosition ( 1, 160, 200 )
fixspritetoscreen ( 1, 1 )
rem load image of the floor
LoadImage ( 2, "floor_001.png" )
CreateSprite ( 2, 2 )
setspritesize (2, 1024, 1024 )
SetSpriteDepth ( 2, 100 )
rem load image of weapon
LoadImage ( 3, "axe_001.png" )
for b=0 to 100
Createsprite ( 3+b, 3 )
SetspriteVisible ( 3+b, 0 )
SetSpriteAnimation ( 3+b, 64, 64, 8 )
setspritesize ( 3+b, 32, 32 )
next b
playerx = GetSpriteX ( 1 ) +20
playery = GetSpriteY ( 1 ) +10
rem ****************************************************
do
rem move with cursor keys and joystick
mx#=GetVirtualJoystickX( 1 )
my#=GetVirtualJoystickY( 1 )
rem when there is no input stop animation
if ( mX# = 0.0 and mY# = 0.0 )
StopSprite ( 1 )
SetSpriteFrame ( 1, 8 )
else
rem find player position
x# = GetSpriteX ( 1 )
y# = GetSpriteY ( 1 )
rem work out movement direction
x1# = x# - mX#
y1# = y# - mY#
rem face the correct angle
angle# = ATanFull ( x1# - x#, y1# - y# )
SetSpriteAngle ( 1, angle# )
setspriteposition ( 2, GetSpriteX ( 2 ) - ( mX# / .50 ), GetSpriteY ( 2 ) - ( mY# / .50 ) )
rem play animation
if ( GetSpritePlaying ( 1 ) = 0 )
PlaySprite ( 1, 35, 1, 1, 24 )
endif
endif
rem ****************************************************
rem control firing
if getvirtualbuttonpressed ( 2 )
if firing = 0
firing = 1
for b = 0 to 100
if bullet[b].alive=0
bullet[b].alive=1
bullet[b].x=playerx
bullet[b].y=playery
bullet[b].dirx=2
bullet[b].diry=0
SetspriteVisible ( 3+b, 1 )
PlaySprite ( 3+b, 20, 1, 1, 8 )
exit
endif
next b
endif
else
firing = 0
endif
rem control bullet
for b = 0 to 100
if bullet[b].alive=1
bullet[b].x=bullet[b].x+bullet[b].dirx
bullet[b].y=bullet[b].y+bullet[b].diry
if bullet[b].x<-512 then bullet[b].alive=0
if bullet[b].x>512 then bullet[b].alive=0
if bullet[b].y<-512 then bullet[b].alive=0
if bullet[b].y>512 then bullet[b].alive=0
endif
next b
for b = 0 to 100
SetspritePosition ( 3+b, bullet[b].x, bullet[b].y )
next b
rem ****************************************************
rem update the screen
sync ( )
loop