Gonna Die
Gonna Die for FreeBASIC.
Concept : Defend the space station from incoming asteroids using your two arrays of cannons.
Genre : Arcade / Twitch Shooter
Controls :
Cannon array 1 : W, A, S
Cannon array 2 : up, down, right
The cannons are done. Now I need to add asteroids. :)
option explicit
screen 14,32,2
width 40,30
screenset 0,1
windowtitle "Gonna Die"
const maxBullets = 5
const vk_w = 17
const vk_a = 30
const vk_s = 31
const vk_up = 72
const vk_right = 77
const vk_down = 80
dim shared i as integer
dim shared reloadTimer as integer
reloadTimer = 15
type projectileTP
x as integer
y as integer
vspeed as integer
hspeed as integer
active as integer
end type
dim shared bullets(maxBullets) as projectileTP
dim shared asteriods(maxBullets) as projectileTP
sub moveBullets
for i = 1 to maxBullets
bullets(i).x = bullets(i).x + bullets(i).hspeed
bullets(i).y = bullets(i).y + bullets(i).vspeed
next i
end sub
function createBullets(x,y,hspeed,vspeed)
dim bulletID
if reloadTimer > 0 then exit sub
bulletId = 0
for i = 1 to maxBullets
if not bullets(i).active then
bulletId = i
exit for
end if
next i
if bulletId then
bullets(bulletId).x = x
bullets(bulletId).y = y
bullets(bulletId).active = 1
bullets(bulletId).hspeed = hspeed
bullets(bulletId).vspeed = vspeed
reloadTimer = 10
createBullets = 1
end if
end function
sub handleInput
if multikey(vk_w) then if createBullets(15,12,0,-1) then exit sub
if multikey(vk_a) then if createBullets(12,15,-1,0) then exit sub
if multikey(vk_s) then if createBullets(15,18,0,+1) then exit sub
if multikey(vk_up) then if createBullets(24,12,0,-1) then exit sub
if multikey(vk_right) then if createBullets(27,15,1,0) then exit sub
if multikey(vk_down) then createBullets(24,18,0,1)
end sub
sub drawBullets
for i = 1 to maxBullets
if bullets(i).active then
locate bullets(i).y, bullets(i).x
color rgb(255,0,0)
print "o";
end if
next i
end sub
sub killBullets
for i = 1 to maxBullets
if bullets(i).y < 1 or bullets(i).y > 30 then bullets(i).active = 0
if bullets(i).x < 1 or bullets(i).x > 40 then bullets(i).active = 0
next i
end sub
sub drawStation
color rgb(200,200,200)
locate 13,15
print "# #### #"
locate 14,15
print "# ###### #"
locate 15,13
print "##############"
locate 16,15
print "# ###### #"
locate 17,15
print "# #### #"
end sub
do
cls
color rgb(255,255,255)
print "Score : 00000"
drawStation
moveBullets
handleInput
killBullets
drawBullets
reloadTimer = reloadTimer - 1
screencopy
sleep 25
loop until multikey(1)
sleep




