I am writing a game for the is based around the very popular game "Geometry Wars". I am a new programmer, but I am willing to spend alot of time writing as well as learning how to program. So far I have created an avatar and background. Created my avatar to rotate to my mouse position, made my avatar move and also made him shoot bullets.
My error so far is that when my avatar shoots the bullet by clicking the mouse. The bullet will dispear if he clicks the mouse again. I would like to prevent this from happening by creating a loop sequence so that the avatar will automatically shoot bullets, but I have tried looping my statements and they have not worked.
For those of you who would like to help, please download my code which I have attached and take a look at it! Thank You!
Type Objects
x as integer
y as integer
id as integer
r as integer
h as integer
w as integer
EndType
Global background as objects
Global player as objects
Global bullet as objects
`variables for lives, not yet used
Global Lives As Integer
Global NumOfBullets As Integer = 0
Global MaxBullets as integer = 0
Global PX As Integer
Global PY As Integer
Global PZ As Integer
`variables for the ship/bullet
Global shipx as float = 562.0
Global bulletx as float = 562.0
Global shipy as float = 384.0
Global bullety as float = 384.0
Global shipxvel as float `x velocity for ship
Global shipyvel as float `y velocity for ship
Global shipangle as float = 0.0 `angle for ship
sync on : sync rate 60
Set Display Mode 1124, 768, 32
velocity as float = 2.0 `change this to increase/decrease speed
`Giving Identification to the Sprites
background.id = 1
player.id = 2
bullet.id = 3
Music = 1
set image colorkey 255,255,255
load image "media\avatar.bmp", player.id
Load image "media\TheGrid.png", background.id
Load image "media\bullet.bmp", bullet.id
Load Music "media\Music.mp3", Music
`Draw the sprite once so we can offset it
`This allows for rotation point to be in the middle
Sprite background.id, 0, 0, background.id
Sprite bullet.id, shipx, shipy, bullet.id
Sprite player.id, shipx, shipy, player.id
Offset Sprite player.id, Sprite Width(player.id) / 2, Sprite Height(player.id) / 2
Offset Sprite bullet.id, Sprite Width(bullet.id) / 2, Sprite Height(bullet.id) / 2
Draw Sprites First
`~~~~~~~~~~~~~~~~~~~~~~~~~~~~Main Loop~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Repeat
`Plays the Music for the Game
Play Music Music
`find the x velocity to move the ship at our chosen angle
`using the formula x velocity = v*cos(angle)
shipxvel = velocity * cos(shipangle - 90)
`there is a "-90" in there because the sprite is facing up/forward, equivalent to 90 degrees
`on the unit circle and not 0 degrees
`now for the y velocity
shipyvel = velocity * sin(shipangle - 90)
`Loop Function Move_Avatar()
Move_Avatar()
`Loop Function Mouse_Position()
Mouse_Position(PX, PY, PZ)
`Loop Function Follow_Mouse()
Point_Sprite(player.id,mousex(),mousey())
move sprite player.id, 0.1
`Loop Function Shoot_Bullet()
Shoot_Bullet()
sprite player.id, shipx, shipy, player.id
sync
Until escapekey() = 1
`~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~END MAIN LOOP~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`******************************************************
`Function Move_Avatar
`Post: Avatar will respond accordingly to WASD key inputs
`******************************************************
Function Move_Avatar()
`if the user hits the up arrowkey, move the ship fowards at it's chosen angle
if keystate(17)=1
dec shipy, 2
endif
`if the user hits the down arrowkey, move the ship backwards at it's chosen angle
if keystate(30) = 1
dec shipx, 2
endif
`use the left and right arrowkeys to increase, decrease the angle
if keystate(31)=1
inc shipy, 2
endif
`do the same for the leftkey
if keystate(32)=1
inc shipx, 2
endif
EndFunction
`$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
`Function for Mouse_Position
`Post: Will find Mouse Coordinates and Return as a variable
`Aquire the mouse the by storing all variables into one
`and then putting that variable into a text
`$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Function Mouse_Position(PX, PY, PZ)
`Storing Mouse Position into variables created in the Function
PX = MouseX()
PY = MouseY()
PZ = MouseZ()
`Storing Location into one Variable
MouseP = PX + PY + PZ
Output As String
`Creating Text to Display location of the mouse
Output = "Mouse Position:" + Str$(PX) + "," + Str$(PY) + "," + Str$(PZ)
Text 20, 20, Output
EndFunction MouseP
`@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
`Function for Point_Sprite
`Post: Avatar will be pointed at the mouse
`@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Function Point_Sprite(s,x,y)
`Giving Sprite Location
dx = Sprite X(s) - x
dy = Sprite Y(s) - y
`Rotating Sprite to rotation of the mouse
ang# = Wrapvalue(Atanfull(dx,dy)*-1)
Rotate Sprite s,ang#
Endfunction
`######################################################
`Function for Shoot_Bullet
`Post: Bullets can be shot from all directions from avatar
`######################################################
Function Shoot_Bullet()
If mouseclick()
sprite bullet.id, shipx, shipy, bullet.id
rotate sprite bullet.id, sprite angle(player.id)
Endif
Move Sprite bullet.id, 50
EndFunction
Beginning Programmer
Professional Nerd