Simple enough, it doesn't work. And It's making me mad. Thanks in advance.
rem Init
disable escapekey
#constant false 0
#constant true 1
scrhgt = screen height()
scrwid = screen width()
global paused = false
sync on : sync rate 100
backdrop off
color backdrop rgb(0,0,0)
set window title " Still Dying - Zeta "
randomize timer()
rem Types
type entity
x, y, id, shots, lives, amount, delay, health, status as integer
endtype
type shot
x, y, id, state, amount as integer
endtype
rem Globals
player as entity
player.id = 1
dim enemy(7) as entity
dim bullets(5) as shot
for b = 1 to 5
for y = 17 to 23
bullets(b).state = false
bullets(b).id = y
bullets(1).amount = 1
next y
next b
global gamestate = 0
global enemydelay = 20000
global Htmr
global desttime
global currbullet = 1
global currenemy = 1
global char=1
global bullet=2
global GameOver=3
global enemyimg=11
global healthbackground=12
global healthbar=13
global healthbarS=24
dim MM(4)
for mm = 1 to 4
MM(mm) = mm + 5
next mm
dim MMS(4)
for n = 1 to 4
MMS(n) = n + 8
next n
gosub LoadImages
game:
gosub SetupPlayer
gosub SetupEnemies
mainloop:
rem Main loop
do
select gamestate
case 0
gosub mainmenu
endcase
case 1
rem Init area
if player.status = 0
fadeIn(player.id, 500, 0, 0)
player.status = 1
else
playerinput()
if enemymovedelay => 10
MoveEnemies()
enemymovedelay = 0
else
inc enemymovedelay, 1
endif
TrackStats()
movebullet()
enemytimer()
check()
for b = 1 to 5
if sprite collision(enemy(b).id, player.id) = true
if enemy(b).delay < timer()
dec player.health, 1
enemy(b).delay = timer() + 200
else
inc enemy(b).delay
endif
endif
next b
endif
ink rgb(255,255,255)
sync
endcase
case 2
`if file exist("saves\"+save$
repeat
center text scrwid, scrhgt, str$(percent) + "% " + "Loaded!"
inc percent, 1
until percent = 100
endcase
endselect
loop
end
rem Main Menu
mainmenu:
alpha2 = 255 : alpha3 = 255 : alpha4 = 255
sprite MMS(1), 0, 0, MM(1)
set sprite priority MMS(1), 0
sprite MMS(2), 284, 320, MM(2): // exit
set sprite priority MMS(2), 1
sprite MMS(3), 266, 221, MM(3): // load
set sprite priority MMS(3), 1
sprite MMS(4), 283, 138, MM(4): // new
set sprite priority MMS(4), 1
ink rgb(255,255,0),0
do
mx = mousex() : my = mousey() : mc = mouseclick()
if mx => 276 and mx =< 353 and my => 314 and my =< 353
if mc = 1
for mmss = 1 to 4
hide sprite MMS(mmss)
next mmss
end : // exit
else
dec alpha2,5
if alpha2 < 0 then alpha2 = 255
set sprite alpha MMS(2), alpha2
endif
else
alpha2 = 255
set sprite alpha MMS(2), alpha2
endif
if mx => 264 and mx =< 362 and my => 219 and my =< 282
if mc = 1
for mmss = 1 to 4
hide sprite MMS(mmss)
next mmss
gamestate = 2
gosub mainloop
else
dec alpha3,5
if alpha3 < 0 then alpha3 = 255
set sprite alpha MMS(3), alpha3
endif
else
alpha3 = 255
set sprite alpha MMS(3), alpha3
endif
if mx => 271 and mx =< 381 and my => 134 and my =< 191
if mc = 1
gamestate = 1
for mmss = 1 to 4
hide sprite MMS(mmss)
next mmss
gosub mainloop
else
dec alpha4, 5
if alpha4 < 0 then alpha4 = 255
set sprite alpha MMS(4), alpha4
endif
else
alpha4 = 255
set sprite alpha MMS(4), alpha4
endif
sync
loop
return
LoadImages:
rem Make images/Load images
circle 10,10,10
get image char, 0, 0, 22, 22
cls
ink rgb(25,250,10)
circle 10,10,10
get image enemyimg, 0, 0, 22, 22
ink rgb(255,255,255)
cls
box 0,0,112,30
ink rgb(10,10,10),0
box 1,1,111,29
get image healthbackground,0,0,112,30,1
cls
ink rgb(255,0,0),0
box 0,0,110,28
get image healthbar,0,0,110,28,1
cls
set text font "Impact"
set text size 50
ink rgb(255,255,255)
center text screen width()/2, screen height()/2, "Game Over!"
center text screen width()/2, screen height()/3, "Press 'escape' to exit!"
get image GameOver,0,0,640,480
cls
set text font "Ariel"
set text size 15
load bitmap "media\Main_Menu.png", 1 `Main Menu
get image MM(2), 284, 354, 348, 383 `Exit Button
get image MM(3), 266, 274, 356, 333 `Load Game Button
get image MM(4), 283, 208, 380, 258 `New Game Button
delete bitmap 1
load image "media\Main_Menu_Blank.png", MM(1)
load image "media\Bullet.png", bullet
return
SetupPlayer:
sprite player.id, screen width()/2, 400, char
player.health = 100
player.lives = 3
player.x = sprite x(player.id)
player.y = sprite y(player.id)
player.status = 0
return
SetupEnemies:
px = player.x : py = player.y
for s = 1 to 5
enemy(s).id = s + 3
okay = false
repeat
x = rnd(scrwid - 10) : y = rnd(scrhgt - 500)
if abs(px - x) > 30 and abs(py - y) > 30 then okay = true : // be sure it is a ways away from player
until okay = true
enemy(s).x = x-10 : enemy(s).y = y-25
enemy(s).status = 1 : // active
sprite enemy(s).id, enemy(s).x, enemy(s).y, enemyimg
next s
return
rem Functions
function playerinput()
` Check for right arrow
if rightkey() = 1
player.x = sprite x(player.id)
if player.x => 617
player.x = sprite x(player.id)
else
player.x = player.x + 2
endif
endif
` Check for left arrow
if leftkey() = 1
player.x = sprite x(player.id)
if player.x =< 3
player.x = sprite x(player.id)
else
player.x = player.x - 2
endif
endif
if spacekey() = 1
if bullets(1).amount < 5
if currbullet < 5
bullets(currbullet).state = true
bullets(currbullet).x = sprite x(player.id)
bullets(currbullet).y = sprite y(player.id)
sprite bullets(currbullet).id, bullets(currbullet).x, bullets(currbullet).y, bullet
inc bullets(1).amount
inc currbullet
endif
endif
endif
` Show the player (after the x and y may have changed)
sprite player.id, player.x, player.y, char
endfunction
function check() `Checks a whole load of things.
if player.health =< 0
dec player.lives
if player.lives <= 0
fadeOut(player.id, 500, 255)
hide all sprites
sprite GameOver, 0, 0, GameOver
fadeIn(GameOver, 500, 0, 0)
do
cls
sprite GameOver, 0, 0, GameOver
if escapekey() = 1 then end
sync
loop
endif
fadeOut(player.id, 0, 255)
sprite player.id, screen width()/2, 400, char
player.x = screen width()/2
player.y = 400
fadeIn(player.id, 500, 0, 1)
endif
if escapekey() = 1
wait 0150
if paused = false
paused = true
repeat
cls
center text screen width()/2, screen height()/2, "Paused!"
TrackStats()
sync
if escapekey() = 1
paused = false
TrackStats()
wait 0150
endif
until paused = false
endif
endif
endfunction
rem Decides when an enemy should enter play
function enemytimer()
if timer() > desttime
if enemy(b).amount < 5
enemy(currenemy).x = rnd(600)+20
enemy(currenemy).y = 0 - 16
sprite enemy(currenemy).id, enemy(currenemy).x, 0 - 16, char
show sprite enemy(currenemy).id
inc enemy(b).amount, 1
inc currenemy, 1
if currenemy > 7 then currenemy = 1
desttime = timer() + enemydelay
endif
endif
endfunction
rem Handles bullets.
function movebullet()
for b = 1 to 5
if sprite exist(bullets(b).id)
x = sprite x(bullets(b).id) : y = sprite y(bullets(b).id)
if x < 0 or x > ScrWid then hide sprite bullets(b).id : exit
if y < 0 or y > ScrHgt then hide sprite bullets(b).id : exit
endif
inc bullets(b).y, 2
sprite bullets(b).id, bullets(b).x, bullets(b).y, bullet
if sprite collision(bullets(b).id, enemy(b).id)=1
delete sprite enemy(b).id
endif
next b
endfunction
function MoveEnemies()
for b = 1 to 5
for a = 1 to 5
if enemy(a).status = 1 and enemy(b).status = 1 and a <> b
if ( abs(enemy(a).y - enemy(b).y) < sprite height(enemy(b).id)-1 ) and ( abs(enemy(a).x - enemy(b).x) < sprite width(enemy(b).id)-1 )
if enemy(a).y => enemy(b).y
dec enemy(b).y, 1
else
inc enemy(b).y, 1
endif
if enemy(a).x => enemy(b).x
dec enemy(b).x, 1
else
inc enemy(b).x, 1
endif
else
if abs(enemy(b).y - player.y) > 4
if enemy(b).y => player.y
dec enemy(b).y, 1
else
inc enemy(b).y, 1
endif
endif
if abs(enemy(b).x - player.x) > 4
if enemy(b).x => player.x
dec enemy(b).x, 1
else
inc enemy(b).x, 1
endif
endif
endif
endif
sprite enemy(b).id, enemy(b).x, enemy(b).y, enemyimg
next a
next b
endfunction
function TrackStats()
ink rgb(255,255,255)
paste image healthbackground, 50, 20
for life = 1 to player.lives
paste image char, (life * 30)+35, 120
next life
set text font "courier"
set text size 25
center text 105, 80, "LIVES"
center text 105, 0, "Health"
sprite healthbarS, 51, 21, healthbar
if player.health < 0 then player.health = 0
stretch sprite healthbarS, player.health, 100
endfunction
function fadeIn(spr, tmp, alpha_value, death) `Sprite number, offset, and starting alpha value.
set sprite alpha spr, alpha_value
offset = tmp / 255
tmr = timer() + offset
repeat
if timer() > tmr then inc alpha_value : tmr = timer() + offset : set sprite alpha spr, alpha_value
if death = 1
if timer() > Htmr
inc player.health, 1
Htmr = timer() + 15
if player.health > 100 then player.health = 100
endif
endif
TrackStats()
sync
until alpha_value = 255
endfunction
function fadeOut(spr, tmp, alpha_value)
set sprite alpha spr, 255
offset = tmp / 255
tmr = timer() + offset
repeat
if timer() > tmr then dec alpha_value : tmr = timer() + offset : set sprite alpha spr, alpha_value
TrackStats()
sync
until alpha_value = 0
endfunction
-------------------------------------------------------------