Increased Invaders difficulty

This commit increases invaders difficulty a little bit and cleans up the
code (moved static enemy data to the top of the file, made keygrabber a
part of capi, not an own local variable)

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Gregor Best 2008-10-19 19:28:11 +02:00 committed by Julien Danjou
parent a48e71af18
commit 08a700f132
1 changed files with 20 additions and 21 deletions

View File

@ -26,9 +26,8 @@ local wibox = wibox
local widget = widget
local awful = require("awful")
local beautiful = require("awful.beautiful")
local keygrabber = keygrabber
local image = image
local capi = { screen = screen, mouse = mouse }
local capi = { screen = screen, mouse = mouse, keygrabber = keygrabber }
local tonumber = tonumber
local table = table
@ -43,12 +42,17 @@ local gamedata = { }
gamedata.field = { }
gamedata.field.x = 100
gamedata.field.y = 100
gamedata.field.h = 600
gamedata.field.w = 800
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
gamedata.enemies.w = 20
gamedata.enemies.rows = 5
gamedata.enemies.count = gamedata.enemies.rows * 6
local player = { }
local game = { }
@ -134,7 +138,7 @@ function shots.handle()
s.screen = nil
gamedata.ammo = gamedata.ammo + 1
else
g.y = g.y - 3
g.y = g.y - 6
s:geometry(g)
end
end
@ -179,13 +183,9 @@ end
function enemies.setup()
gamedata.enemies.data = { }
gamedata.enemies.h = 10
gamedata.enemies.w = 20
gamedata.enemies.rows = 4
gamedata.enemies.x = 10
gamedata.enemies.y = 5
gamedata.enemies.dir = 1
gamedata.enemies.count = gamedata.enemies.rows * 8
if not gamedata.enemies.shots then gamedata.enemies.shots = { } end
gamedata.enemies.shots.max = 10
gamedata.enemies.shots.fired = 0
@ -268,7 +268,7 @@ function enemies.handle ()
if gamedata.enemies.speed_count < gamedata.enemies.speed then return false end
gamedata.enemies.speed_count = 0
gamedata.enemies.x = gamedata.enemies.x + math.floor((gamedata.enemies.w * gamedata.enemies.dir) / 4)
if gamedata.enemies.x > gamedata.field.w - (2 * gamedata.enemies.w * (gamedata.enemies.count / gamedata.enemies.rows + 1)) - 10
if gamedata.enemies.x > gamedata.field.w - (2 * gamedata.enemies.w * (gamedata.enemies.count / gamedata.enemies.rows + 1)) + 5
or gamedata.enemies.x <= 10 then
gamedata.enemies.y = gamedata.enemies.y + gamedata.enemies.h
gamedata.enemies.dir = gamedata.enemies.dir * (-1)
@ -461,7 +461,6 @@ function run(args)
if args['solidbg'] then gamedata.solidbg = args['solidbg'] end
end
gamedata.ammo_max = 10
gamedata.score = 0
gamedata.name = ""
gamedata.ammo = gamedata.ammo_max
@ -526,10 +525,10 @@ function run(args)
enemies.setup()
gamedata.player = player.new()
keygrabber.run(keyhandler)
capi.keygrabber.run(keyhandler)
gamedata.running = true
end
awful.hooks.timer.register(0.03, shots.handle)
awful.hooks.timer.register(0.02, shots.handle)
awful.hooks.timer.register(0.03, shots.handle_enemy)
awful.hooks.timer.register(0.01, enemies.handle)