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)
@ -454,14 +454,13 @@ function run(args)
gamedata.screen = capi.screen[capi.mouse.screen]
gamedata.field.x = gamedata.screen.coords.x + math.floor((gamedata.screen.coords.width - gamedata.field.w) / 2)
gamedata.field.y = gamedata.screen.coords.y + math.floor((gamedata.screen.coords.height - gamedata.field.h) / 2)
if args then
if args['x'] then gamedata.field.x = args['x'] end
if args['y'] then gamedata.field.y = args['y'] end
if args['solidbg'] then gamedata.solidbg = args['solidbg'] end
end
gamedata.ammo_max = 10
gamedata.score = 0
gamedata.name = ""
gamedata.ammo = gamedata.ammo_max
@ -479,14 +478,14 @@ function run(args)
gamedata.field.background.screen = 1
end
gamedata.field.north = wibox({ position = "floating",
gamedata.field.north = wibox({ position = "floating",
bg = gamedata.btheme.bg_focus or "#333333",
fg = gamedata.btheme.fg_focus or "#FFFFFF" })
gamedata.field.north:geometry({ width = gamedata.field.w + 10,
height = 15,
x = gamedata.field.x - 5,
y = gamedata.field.y - 15 })
gamedata.field.north.screen = 1
gamedata.field.north.screen = 1
gamedata.field.status = widget({ type = "textbox", name = "status", align = "right" })
gamedata.field.status.text = gamedata.score.." | "..gamedata.ammo .. " "
@ -502,34 +501,34 @@ function run(args)
gamedata.field.south:geometry({ width = gamedata.field.w, height = 5,
x = gamedata.field.x,
y = gamedata.field.y + gamedata.field.h - 5 })
gamedata.field.south.screen = 1
gamedata.field.south.screen = 1
gamedata.field.west = wibox({ position = "floating",
gamedata.field.west = wibox({ position = "floating",
bg = gamedata.btheme.bg_focus or "#333333",
fg = gamedata.btheme.fg_focus or "#FFFFFF" })
gamedata.field.west:geometry({ width = 5,
height = gamedata.field.h,
x = gamedata.field.x - 5,
y = gamedata.field.y })
gamedata.field.west.screen = 1
gamedata.field.west.screen = 1
gamedata.field.east = wibox({ position = "floating",
gamedata.field.east = wibox({ position = "floating",
bg = gamedata.btheme.bg_focus or "#333333",
fg = gamedata.btheme.fg_focus or "#FFFFFF" })
gamedata.field.east:geometry({ width = 5,
height = gamedata.field.h,
x = gamedata.field.x + gamedata.field.w,
y = gamedata.field.y })
gamedata.field.east.screen = 1
gamedata.field.east.screen = 1
gamedata.enemies.speed = 5
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)