From 72246769112ba00f592702f2dc9ae52b769b6d5f Mon Sep 17 00:00:00 2001 From: Gregor Best Date: Tue, 27 Jan 2009 20:55:56 +0100 Subject: [PATCH] invaders: make most functions local Signed-off-by: Gregor Best Signed-off-by: Julien Danjou --- lib/invaders.lua.in | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/invaders.lua.in b/lib/invaders.lua.in index 301ae986f..35257162f 100644 --- a/lib/invaders.lua.in +++ b/lib/invaders.lua.in @@ -60,7 +60,7 @@ local game = { } local shots = { } local enemies = { } -function player.new () +local function player.new () p = wibox({ position = "floating", bg = gamedata.solidbg or "#12345600" }) p:geometry({ width = 24, @@ -76,7 +76,7 @@ function player.new () return p end -function player.move(x) +local function player.move(x) if not gamedata.running then return false end local g = gamedata.player:geometry() @@ -89,7 +89,7 @@ function player.move(x) gamedata.player:geometry(g) end -function player.fire() +local function player.fire() if not gamedata.running then return false end if gamedata.ammo == 1 then gamedata.ammo = 0 @@ -98,7 +98,7 @@ function player.fire() end end -function shots.fire (x, y, color) +local function shots.fire (x, y, color) local s = wibox({ position = "floating", bg = color }) s:geometry({ width = 4, @@ -112,7 +112,7 @@ function shots.fire (x, y, color) 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 gamedata.enemies.shots.fired = gamedata.enemies.shots.fired + 1 local s = wibox({ position = "floating", @@ -131,7 +131,7 @@ function shots.fire_enemy (x, y, color) end end -function shots.handle() +local function shots.handle() if not gamedata.running then return false end if gamedata.ammo == 1 then return false end @@ -150,7 +150,7 @@ function shots.handle() end -function shots.handle_enemy () +local function shots.handle_enemy () if not gamedata.running then return false end if gamedata.enemies.shots.fired == 0 then return false end @@ -172,7 +172,7 @@ function shots.handle_enemy () end end -function enemies.new (t) +local function enemies.new (t) e = wibox({ position = "floating", bg = gamedata.solidbg or "#12345600" }) e:geometry({ height = gamedata.enemies.h, @@ -187,7 +187,7 @@ function enemies.new (t) return e end -function enemies.setup() +local function enemies.setup() gamedata.enemies.data = { } gamedata.enemies.x = 10 gamedata.enemies.y = 5 @@ -216,7 +216,7 @@ function enemies.setup() end end -function enemies.handle () +local function enemies.handle () if not gamedata.running then return false end gamedata.enemies.number = 0 @@ -285,7 +285,7 @@ function enemies.handle () end end -function keyhandler(mod, key, event) +local function keyhandler(mod, key, event) if event ~= "press" then return true end if gamedata.highscore.getkeys then if key:len() == 1 and gamedata.name:len() < 20 then @@ -318,7 +318,7 @@ function keyhandler(mod, key, event) return true end -function game.collide(o1, o2) +local function game.collide(o1, o2) g1 = o1:geometry() g2 = o2:geometry() @@ -331,12 +331,12 @@ function game.collide(o1, o2) return false end -function game.over () +local function game.over () gamedata.running = false game.highscore(gamedata.score) end -function game.quit() +local function game.quit() gamedata.running = false if gamedata.highscore.window then @@ -378,7 +378,7 @@ function game.quit() end end -function game.highscore_show () +local function game.highscore_show () gamedata.highscore.window:geometry({ height = 140, width = 200, x = gamedata.field.x + math.floor(gamedata.field.w / 2) - 100, @@ -409,7 +409,7 @@ function game.highscore_show () fh:close() end -function game.highscore_add (score, name) +local function game.highscore_add (score, name) local t = gamedata.highscore for i = 5, 1, -1 do @@ -422,7 +422,7 @@ function game.highscore_add (score, name) gamedata.highscore = t end -function game.highscore (score) +local function game.highscore (score) if gamedata.highscore.window and gamedata.highscore.window.screen then return false end local fh = io.open(gamedata.cachedir.."/highscore_invaders", "r")