invaders: remove useless shots table

this commit removes the now useless table gamedata.shots and replaces it
with a single variable of the name gamedata.shot
This commit is contained in:
Gregor Best 2008-10-27 17:06:51 +01:00 committed by Julien Danjou
parent 2a839ad875
commit 7c20b14ce5
1 changed files with 29 additions and 41 deletions

View File

@ -46,7 +46,6 @@ gamedata.field.h = 400
gamedata.field.w = 600
gamedata.running = false
gamedata.ammo_max = 1
gamedata.shots = { }
gamedata.highscore = { }
gamedata.enemies = { }
gamedata.enemies.h = 10
@ -108,11 +107,8 @@ function shots.fire (x, y, color)
y = y })
s.screen = 1
for i = 1, gamedata.ammo_max do
if not gamedata.shots[i] or gamedata.shots[i].screen == nil then
gamedata.shots[i] = s
break
end
if not gamedata.shot or gamedata.shot.screen == nil then
gamedata.shot = s
end
end
@ -141,8 +137,7 @@ function shots.handle()
gamedata.ammo = gamedata.ammo_max
for i = 1, gamedata.ammo_max do
local s = gamedata.shots[i]
local s = gamedata.shot
if s and s.screen then
gamedata.ammo = gamedata.ammo - 1
local g = s:geometry()
@ -154,7 +149,6 @@ function shots.handle()
s:geometry(g)
end
end
end
gamedata.field.status.text = gamedata.score.." | "..gamedata.ammo .. " "
end
@ -215,10 +209,8 @@ function enemies.setup()
end
end
for i = 1, gamedata.ammo_max do
if gamedata.shots[i] then
gamedata.shots[i].screen = nil
end
if gamedata.shot then
gamedata.shot.screen = nil
end
for i = 1, gamedata.enemies.shots.max do
@ -247,9 +239,8 @@ function enemies.handle ()
game.over()
end
end
if gamedata.ammo < gamedata.ammo_max then
for i = 1, gamedata.ammo_max do
local s = gamedata.shots[i]
if gamedata.ammo == 0 then
local s = gamedata.shot
if s and s.screen and game.collide(e, s) then
gamedata.enemies.number = gamedata.enemies.number - 1
e.screen = nil
@ -269,7 +260,6 @@ function enemies.handle ()
end
end
end
end
local x = math.random(1, gamedata.enemies.count / gamedata.enemies.rows)
if gamedata.enemies.speed_count == (gamedata.enemies.speed - 1)
@ -381,9 +371,7 @@ function game.quit()
end
end
for i = 1, gamedata.ammo_max do
if gamedata.shots[i] then gamedata.shots[i].screen = nil end
end
if gamedata.shot then gamedata.shot.screen = nil end
for i = 1, gamedata.enemies.shots.max do
if gamedata.enemies.shots[i] then gamedata.enemies.shots[i].screen = nil end