Oh ok, and also the status is just to check if the enemies have been set up and properly placed.
EDIT: I made some changes and it works fine now. Its a bit buggy, though that buggy jittering sort of makes the enemies (Actually zombies, should've explained that eariler) seem more menacing.
function MoveEnemies()
for a = 1 to 5
for b = 1 to 5
if enemy(b).status = 1 and a <> b
sprite enemy(b).id, enemy(b).x, enemy(b).y, enemyimg
if abs(enemy(a).y - enemy(b).y) < 11
if enemy(a).y => enemy(b).y
dec enemy(b).y, 6
else
inc enemy(b).y, 6
endif
endif
if abs(enemy(a).x - enemy(b).x) < 11
if enemy(a).x => enemy(b).x
dec enemy(b).x, 6
else
inc enemy(b).x, 6
endif
endif
if abs(enemy(b).y - player.y) > 4
if enemy(b).y => player.y
dec enemy(b).y
else
inc enemy(b).y
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
next b
next a
endfunction
EDIT TWO: Ok, that lag bug is back lol. I probally need to do some fixing. (Still waiting on some tips to optimize)
But if you can find anything then tell me.
rem |=-------------=|
rem |=-Still-Dying-=|
rem |=-------------=|
rem
rem |=---Coders:---=|
rem
rem |=-Darkzombies-=|
rem
rem |=---Artists:--=|
rem
rem |=----NONE-----=|
rem
rem |=----Index:---=|
rem
rem 1: char (img = 1, spr = 1)
rem 2: bullet (img = 2, spr = 17-23)
rem 3: GameOver (img = 3, spr = 3)
rem 4: enemy (img = 11, spr = 4-10)
rem 5: wall (img = 5, spr = 11) (Ignore this one.)
rem 6: MM (img = 6-10, spr = 12-16)
rem 7: enemyimg (img = 11, spr = 4-10)
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 " Some Name - Some Company "
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 time = timer()
global desttime = time
desttime = desttime + enemydelay
global currbullet = 1
global currenemy = 1
global char=1
global bullet=2
global GameOver=3
global enemyimg=11
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)
player.status = 1
else
playerinput()
if enemymovedelay => 12
MoveEnemies()
enemymovedelay = 0
else
inc enemymovedelay, 1
endif
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() + 550
else
inc enemy(b).delay
endif
endif
next b
endif
ink rgb(255,255,255)
text 50, 50, "Health: "+str$(player.health)
text 50, 60, "Lives: "+str$(player.lives)
text 50, 75, "FPS: "+str$(screen fps())
sync
endcase
case 4
gosub options `(?)
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()
text 700,10,"mx: " + str$(mx)
text 700,30,"my: " + str$(my)
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
`gosub LoadGame
gamestate = 1
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
rem Options (Maybe)
options:
print "Heavy is options!"
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
set text font "Impact"
set text size 50
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
inc bullets(1).amount
inc currbullet
bullets(currbullet).state = true
bullets(currbullet).x = sprite x(player.id)
bullets(currbullet).y = sprite y(player.id)
sprite bullets(bullets(1).amount).id, bullets(bullets(1).amount).x, bullets(bullets(1).amount).y, bullet
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)
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.health = 100
player.x = screen width()/2
player.y = 400
fadeIn(player.id, 500, 0)
endif
if escapekey() = 1
wait 0500
if paused = false
paused = true
repeat
cls
center text screen width()/2, screen height()/2, "Paused!"
sync
if escapekey() = 1
paused = false
wait 0500
endif
until paused = false
endif
endif
endfunction
rem Decides when an enemy should enter play
function enemytimer()
if timer() > desttime
wait 0200
for b = 1 to 1
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
desttime = timer() + enemydelay
endif
next b
endif
endfunction
rem Handles bullets.
function movebullet()
for b = 1 to 5
if bullets(b).state = true
x = sprite x(bullets(b).id) : y = sprite y(bullets(b).id)
if x < 0 or x > ScrWid then bullets(b).state = false : hide sprite bullets(b).id : exit
if y < 0 or y > ScrHgt then bullets(b).state = false : hide sprite bullets(b).id : exit
sprite bullets(b).id,bullets(b).x,bullets(b).y + 2, bullet
endif
next b
endfunction
function MoveEnemies()
for a = 1 to 5
for b = 1 to 5
if enemy(b).status = 1 and a <> b
sprite enemy(b).id, enemy(b).x, enemy(b).y, enemyimg
if abs(enemy(a).y - enemy(b).y) < 11
if enemy(a).y => enemy(b).y
dec enemy(b).y, 6
else
inc enemy(b).y, 6
endif
endif
if abs(enemy(a).x - enemy(b).x) < 11
if enemy(a).x => enemy(b).x
dec enemy(b).x, 6
else
inc enemy(b).x, 6
endif
endif
if abs(enemy(b).y - player.y) > 4
if enemy(b).y => player.y
dec enemy(b).y
else
inc enemy(b).y
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
next b
next a
endfunction
function fadeIn(spr, tmp, alpha_value) `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
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
sync
until alpha_value = 0
endfunction