for how long can you survive?
import "Speed.lib"
import "Keycodes.lib"
constant:
MAX_ENEMIES 256
MAX_BULLETS 64
visible:
enemies?[MAX_ENEMIES]
bullets?[MAX_BULLETS]
hidden:
set redraw off
for i = 0 to MAX_ENEMIES - 1
enemies[i].act = false
next
for i = 0 to MAX_BULLETS - 1
bullets[i].act = false
next
bulletTimer = 0
enemyDelay = 60
enemyTimer = enemyDelay
rem shouldDraw = true
life = 16
startTime = time()
do
bulletTimer = max(bulletTimer - 1, 0)
rem shoot.
mx = mousex()
my = mousey()
if mousebutton(0) and bulletTimer = 0 and not (mx = 320 and my = 240)
bulletTimer = 4
for i = 0 to MAX_BULLETS - 1
if not bullets[i].act
bullets[i].act = true
bullets[i].x# = 320.0
bullets[i].y# = 240.0
dx# = float(mx) - 320.0
dy# = float(my) - 240.0
d# = sqr(dx*dx + dy*dy)
k# = 4.0/d
bullets[i].dx# = dx*k
bullets[i].dy# = dy*k
break
endif
next
endif
rem update bullets.
for i = 0 to MAX_BULLETS - 1
if bullets[i].act
rem move.
bullets[i].x# = bullets[i].x# + bullets[i].dx#
bullets[i].y# = bullets[i].y# + bullets[i].dy#
rem out of screen.
if bullets[i].x# < -16.0 or bullets[i].x# > 656.0 or bullets[i].y# < -16.0 or bullets[i].dy# > 496.0
bullets[i].act = false
endif
endif
next
rem add enemy.
enemyTimer = max(enemyTimer - 1, 0)
if enemyTimer = 0
enemyTimer = enemyDelay
enemyDelay = max(enemyDelay - 1, 20)
for i = 0 to MAX_ENEMIES - 1
if not enemies[i].act
enemies[i].act = true
r = rnd(4)
if r = 0
enemies[i].x# = -16.0
enemies[i].y# = float(rnd(480))
elseif r = 1
enemies[i].y# = -16.0
enemies[i].x# = float(rnd(640))
elseif r = 2
enemies[i].x# = 656.0
enemies[i].y# = float(rnd(480))
else
enemies[i].y# = 496.0
enemies[i].x# = float(rnd(640))
endif
dx# = 320.0 - enemies[i].x#
dy# = 240.0 - enemies[i].y#
k# = 1.0/sqr(dx*dx + dy*dy)
enemies[i].dx# = dx*k
enemies[i].dy# = dy*k
if rnd(8) = 0
enemies[i].st = 32
else
enemies[i].st = 16
endif
enemies[i].r = 128 + rnd(128)
enemies[i].g = 128 + rnd(128)
enemies[i].b = 128 + rnd(128)
break
endif
next
endif
rem update enemies.
for i = 0 to MAX_ENEMIES - 1
if enemies[i].act
enemies[i].x# = enemies[i].x# + enemies[i].dx#
enemies[i].y# = enemies[i].y# + enemies[i].dy#
dx# = abs#(enemies[i].x# - 320.0)
dy# = abs#(enemies[i].y# - 240.0)
if dx < 16.0 and dy < 16.0
enemies[i].act = false
life = life - 1
else
for j = 0 to MAX_BULLETS - 1
if bullets[j].act
dx = abs#(enemies[i].x# - bullets[j].x#)
dy = abs#(enemies[i].y# - bullets[j].y#)
if dx < 16.0 and dy < 16.0
bullets[j].act = false
enemies[i].st = enemies[i].st - 6
if enemies[i].st <= 0
enemies[i].act = false
endif
break
endif
endif
next
endif
endif
next
rem if shouldDraw
set color 0, 0, 0, 16
cls
rem draw player.
set color 255, 255, 255
draw rect 320 - life, 240 - life, life*2, life*2, true
rem draw bullets.
set color 255, 255, 0
for i = 0 to MAX_BULLETS - 1
if bullets[i].act
draw rect int(bullets[i].x#) - 2, int(bullets[i].y#) - 2, 4, 4, true
endif
next
rem draw enemeies.
set color 0, 255, 255
for i = 0 to MAX_ENEMIES - 1
if enemies[i].act
set color enemies[i].r, enemies[i].g, enemies[i].b
s = enemies[i].st
draw rect int(enemies[i].x#) - s/2, int(enemies[i].y#) - s/2, s, s, true
endif
next
set color 255, 255, 255
set caret 320, 0
center "TIME"
center (time() - startTime)/1000
redraw
rem endif
rem shouldDraw = SPD_HoldFrameDraw(60)
proc SPD_HoldFrame 60
until life <= 2 or keydown(VK_ESC, true)
set color 0, 0, 0
cls
set color 255, 255, 255
set caret 320, 200
center "You made it for ", (time() - startTime)/1000, " seconds."
redraw
wait keydown
EDIT: Corrected your spelling, you drunk sack of tomatoes.