Is there any better way of doing collision with multiple enemies at a time? I have this collision (Its in the MoveEnemies function) but its REALLY glitchy, the enemies will push each other off-screen and just spaz out constantly. I've been trying to fix it, but to no avail.
rem |=-------------=|
rem |=-Still-Dying-=|
rem |=-------------=|
rem
rem |=---Coders:---=|
rem
rem |=-Darkzombies-=|
rem
rem |=---Artists:--=|
rem
rem |=----Plexes---=|
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 8: healthbackground (img = 12)
rem 7: healthbar (img = 13, spr = 24)
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 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
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)
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 4
rem Do something here
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
`Load()
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
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
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
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 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) < sprite height(enemy(b).id)-1
if enemy(a).y => enemy(b).y
enemy(b).y = sprite y(enemy(b).id)
else
inc enemy(b).y, 9
endif
endif
if abs(enemy(a).x - enemy(b).x) < sprite width(enemy(b).id)-1
if enemy(a).x => enemy(b).x
enemy(b).x = sprite x(enemy(b).id)
else
inc enemy(b).x, 9
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 Load()
scrwid = screen width()/2
scrhgt = screen height()/2
Strech_Coords = 0
repeat
center text scrwid, scrhgt, str$(percent) + "% " + "Loaded!"
inc percent, 1
until percent = 100
endfunction
function TrackStats()
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
stretch sprite healthbarS, player.health, 100
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
Also if you can help me with my shooting system, I made it awhile ago, but it still doesnt work, I planned on fixing it later, and its later, but I don't know whats wrong. Its mainly in movebullet function, but there also a bit in playerinput function and the main loop.