invaders: make most functions local
Signed-off-by: Gregor Best <farhaven@googlemail.com> Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
a4a76d6943
commit
7224676911
|
@ -60,7 +60,7 @@ local game = { }
|
||||||
local shots = { }
|
local shots = { }
|
||||||
local enemies = { }
|
local enemies = { }
|
||||||
|
|
||||||
function player.new ()
|
local function player.new ()
|
||||||
p = wibox({ position = "floating",
|
p = wibox({ position = "floating",
|
||||||
bg = gamedata.solidbg or "#12345600" })
|
bg = gamedata.solidbg or "#12345600" })
|
||||||
p:geometry({ width = 24,
|
p:geometry({ width = 24,
|
||||||
|
@ -76,7 +76,7 @@ function player.new ()
|
||||||
return p
|
return p
|
||||||
end
|
end
|
||||||
|
|
||||||
function player.move(x)
|
local function player.move(x)
|
||||||
if not gamedata.running then return false end
|
if not gamedata.running then return false end
|
||||||
local g = gamedata.player:geometry()
|
local g = gamedata.player:geometry()
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ function player.move(x)
|
||||||
gamedata.player:geometry(g)
|
gamedata.player:geometry(g)
|
||||||
end
|
end
|
||||||
|
|
||||||
function player.fire()
|
local function player.fire()
|
||||||
if not gamedata.running then return false end
|
if not gamedata.running then return false end
|
||||||
if gamedata.ammo == 1 then
|
if gamedata.ammo == 1 then
|
||||||
gamedata.ammo = 0
|
gamedata.ammo = 0
|
||||||
|
@ -98,7 +98,7 @@ function player.fire()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function shots.fire (x, y, color)
|
local function shots.fire (x, y, color)
|
||||||
local s = wibox({ position = "floating",
|
local s = wibox({ position = "floating",
|
||||||
bg = color })
|
bg = color })
|
||||||
s:geometry({ width = 4,
|
s:geometry({ width = 4,
|
||||||
|
@ -112,7 +112,7 @@ function shots.fire (x, y, color)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function shots.fire_enemy (x, y, color)
|
local function shots.fire_enemy (x, y, color)
|
||||||
if gamedata.enemies.shots.fired < gamedata.enemies.shots.max then
|
if gamedata.enemies.shots.fired < gamedata.enemies.shots.max then
|
||||||
gamedata.enemies.shots.fired = gamedata.enemies.shots.fired + 1
|
gamedata.enemies.shots.fired = gamedata.enemies.shots.fired + 1
|
||||||
local s = wibox({ position = "floating",
|
local s = wibox({ position = "floating",
|
||||||
|
@ -131,7 +131,7 @@ function shots.fire_enemy (x, y, color)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function shots.handle()
|
local function shots.handle()
|
||||||
if not gamedata.running then return false end
|
if not gamedata.running then return false end
|
||||||
if gamedata.ammo == 1 then return false end
|
if gamedata.ammo == 1 then return false end
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ function shots.handle()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function shots.handle_enemy ()
|
local function shots.handle_enemy ()
|
||||||
if not gamedata.running then return false end
|
if not gamedata.running then return false end
|
||||||
if gamedata.enemies.shots.fired == 0 then return false end
|
if gamedata.enemies.shots.fired == 0 then return false end
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ function shots.handle_enemy ()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function enemies.new (t)
|
local function enemies.new (t)
|
||||||
e = wibox({ position = "floating",
|
e = wibox({ position = "floating",
|
||||||
bg = gamedata.solidbg or "#12345600" })
|
bg = gamedata.solidbg or "#12345600" })
|
||||||
e:geometry({ height = gamedata.enemies.h,
|
e:geometry({ height = gamedata.enemies.h,
|
||||||
|
@ -187,7 +187,7 @@ function enemies.new (t)
|
||||||
return e
|
return e
|
||||||
end
|
end
|
||||||
|
|
||||||
function enemies.setup()
|
local function enemies.setup()
|
||||||
gamedata.enemies.data = { }
|
gamedata.enemies.data = { }
|
||||||
gamedata.enemies.x = 10
|
gamedata.enemies.x = 10
|
||||||
gamedata.enemies.y = 5
|
gamedata.enemies.y = 5
|
||||||
|
@ -216,7 +216,7 @@ function enemies.setup()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function enemies.handle ()
|
local function enemies.handle ()
|
||||||
if not gamedata.running then return false end
|
if not gamedata.running then return false end
|
||||||
|
|
||||||
gamedata.enemies.number = 0
|
gamedata.enemies.number = 0
|
||||||
|
@ -285,7 +285,7 @@ function enemies.handle ()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function keyhandler(mod, key, event)
|
local function keyhandler(mod, key, event)
|
||||||
if event ~= "press" then return true end
|
if event ~= "press" then return true end
|
||||||
if gamedata.highscore.getkeys then
|
if gamedata.highscore.getkeys then
|
||||||
if key:len() == 1 and gamedata.name:len() < 20 then
|
if key:len() == 1 and gamedata.name:len() < 20 then
|
||||||
|
@ -318,7 +318,7 @@ function keyhandler(mod, key, event)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function game.collide(o1, o2)
|
local function game.collide(o1, o2)
|
||||||
g1 = o1:geometry()
|
g1 = o1:geometry()
|
||||||
g2 = o2:geometry()
|
g2 = o2:geometry()
|
||||||
|
|
||||||
|
@ -331,12 +331,12 @@ function game.collide(o1, o2)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function game.over ()
|
local function game.over ()
|
||||||
gamedata.running = false
|
gamedata.running = false
|
||||||
game.highscore(gamedata.score)
|
game.highscore(gamedata.score)
|
||||||
end
|
end
|
||||||
|
|
||||||
function game.quit()
|
local function game.quit()
|
||||||
gamedata.running = false
|
gamedata.running = false
|
||||||
|
|
||||||
if gamedata.highscore.window then
|
if gamedata.highscore.window then
|
||||||
|
@ -378,7 +378,7 @@ function game.quit()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function game.highscore_show ()
|
local function game.highscore_show ()
|
||||||
gamedata.highscore.window:geometry({ height = 140,
|
gamedata.highscore.window:geometry({ height = 140,
|
||||||
width = 200,
|
width = 200,
|
||||||
x = gamedata.field.x + math.floor(gamedata.field.w / 2) - 100,
|
x = gamedata.field.x + math.floor(gamedata.field.w / 2) - 100,
|
||||||
|
@ -409,7 +409,7 @@ function game.highscore_show ()
|
||||||
fh:close()
|
fh:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
function game.highscore_add (score, name)
|
local function game.highscore_add (score, name)
|
||||||
local t = gamedata.highscore
|
local t = gamedata.highscore
|
||||||
|
|
||||||
for i = 5, 1, -1 do
|
for i = 5, 1, -1 do
|
||||||
|
@ -422,7 +422,7 @@ function game.highscore_add (score, name)
|
||||||
gamedata.highscore = t
|
gamedata.highscore = t
|
||||||
end
|
end
|
||||||
|
|
||||||
function game.highscore (score)
|
local function game.highscore (score)
|
||||||
if gamedata.highscore.window and gamedata.highscore.window.screen then return false end
|
if gamedata.highscore.window and gamedata.highscore.window.screen then return false end
|
||||||
local fh = io.open(gamedata.cachedir.."/highscore_invaders", "r")
|
local fh = io.open(gamedata.cachedir.."/highscore_invaders", "r")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue