2008-10-14 18:16:26 +02:00
|
|
|
----------------------------------------------------------------------------
|
|
|
|
-- @author Gregor "farhaven" Best
|
|
|
|
-- @copyright 2008 Gregor "farhaven" Best
|
|
|
|
-- @release @AWESOME_VERSION@
|
|
|
|
----------------------------------------------------------------------------
|
|
|
|
|
Various changes to awful.util and invaders
This commit changes various aspects of awful.util and invaders:
awful.util:
- added awful.util.getdir(d)
This function takes one argument and returns a matching directory,
as of now, only "cache" is supported. The return value is either
$XDG_CACHE_HOME/awesome/ or $HOME/.cache/awesome/, XDG_CACHE_HOME
takes precedence
invaders:
- renamed invaders to awesome invaders
at two places in the sourcecode, invaders is referred to as
"Space Invaders for Awesome". As Taiko holds the trademark for
the term "Space Invaders", I changed both of its occurences to
"Awesome Invaders" to avoid conflicts with the law of Japan and
the United States of America (and possibly others)
- added support for XDG_CACHE_HOME
this change adds support for XDG_CACHE_HOME as the cache directory
for highscores and screenshots
- added some parameters to invaders.run()
this change adds three parameters to invaders.run, supplied as a
table. They are "x", "y" and "solidbg".
"x" sets the X coordinate of the playfield
"y" sets the Y coordinate of the playfield
"solidbg" sets the color of the playfield background for people who
have problems with transparency. This still looks rather hackish and
needs to be polished
- changed startup position
up until now, invaders always started at (100,100) on the first
screen, now it starts centered to the screen on which the mouse cursor
is.
2008-10-17 19:05:57 +02:00
|
|
|
--{{{ Awesome Invaders by Gregor "farhaven" Best
|
2008-10-14 21:39:56 +02:00
|
|
|
-- The ultra-cool retro graphics are done by Andrei "Garoth" Thorp.
|
2008-10-14 18:16:26 +02:00
|
|
|
--
|
|
|
|
-- Use Left and Right to control motion, Space to fire, q quits the game,
|
|
|
|
-- s creates a screenshot in ~/.cache/awesome (needs ImageMagick).
|
|
|
|
--
|
|
|
|
-- Maybe there are some huge memory leaks here and there, if you notice one,
|
|
|
|
-- message me.
|
|
|
|
--
|
|
|
|
-- Anyway, have fun :)
|
|
|
|
--
|
|
|
|
-- Start this by adding
|
|
|
|
-- require("invaders")
|
|
|
|
-- to the top of your rc.lua and adding
|
|
|
|
-- invaders.run()
|
|
|
|
-- to the bottom of rc.lua or as a keybinding
|
|
|
|
--}}}
|
|
|
|
|
|
|
|
local wibox = wibox
|
2009-06-30 12:26:39 +02:00
|
|
|
local timer = timer
|
2008-10-14 18:16:26 +02:00
|
|
|
local widget = widget
|
|
|
|
local awful = require("awful")
|
2008-11-13 11:53:41 +01:00
|
|
|
local beautiful = require("beautiful")
|
2008-10-14 18:16:26 +02:00
|
|
|
local image = image
|
2008-10-19 19:28:11 +02:00
|
|
|
local capi = { screen = screen, mouse = mouse, keygrabber = keygrabber }
|
2008-10-14 18:16:26 +02:00
|
|
|
|
|
|
|
local tonumber = tonumber
|
|
|
|
local table = table
|
|
|
|
local math = math
|
|
|
|
local os = os
|
|
|
|
local io = io
|
|
|
|
|
Various changes to awful.util and invaders
This commit changes various aspects of awful.util and invaders:
awful.util:
- added awful.util.getdir(d)
This function takes one argument and returns a matching directory,
as of now, only "cache" is supported. The return value is either
$XDG_CACHE_HOME/awesome/ or $HOME/.cache/awesome/, XDG_CACHE_HOME
takes precedence
invaders:
- renamed invaders to awesome invaders
at two places in the sourcecode, invaders is referred to as
"Space Invaders for Awesome". As Taiko holds the trademark for
the term "Space Invaders", I changed both of its occurences to
"Awesome Invaders" to avoid conflicts with the law of Japan and
the United States of America (and possibly others)
- added support for XDG_CACHE_HOME
this change adds support for XDG_CACHE_HOME as the cache directory
for highscores and screenshots
- added some parameters to invaders.run()
this change adds three parameters to invaders.run, supplied as a
table. They are "x", "y" and "solidbg".
"x" sets the X coordinate of the playfield
"y" sets the Y coordinate of the playfield
"solidbg" sets the color of the playfield background for people who
have problems with transparency. This still looks rather hackish and
needs to be polished
- changed startup position
up until now, invaders always started at (100,100) on the first
screen, now it starts centered to the screen on which the mouse cursor
is.
2008-10-17 19:05:57 +02:00
|
|
|
--- Space Invaders look-alike
|
2008-10-14 18:16:26 +02:00
|
|
|
module("invaders")
|
|
|
|
|
|
|
|
local gamedata = { }
|
|
|
|
gamedata.field = { }
|
|
|
|
gamedata.field.x = 100
|
|
|
|
gamedata.field.y = 100
|
2008-10-19 19:28:11 +02:00
|
|
|
gamedata.field.h = 400
|
|
|
|
gamedata.field.w = 600
|
2008-10-14 18:16:26 +02:00
|
|
|
gamedata.running = false
|
|
|
|
gamedata.highscore = { }
|
|
|
|
gamedata.enemies = { }
|
2008-10-19 19:28:11 +02:00
|
|
|
gamedata.enemies.h = 10
|
|
|
|
gamedata.enemies.w = 20
|
|
|
|
gamedata.enemies.rows = 5
|
|
|
|
gamedata.enemies.count = gamedata.enemies.rows * 6
|
2008-10-21 21:17:07 +02:00
|
|
|
gamedata.enemies[1] = image("@AWESOME_ICON_PATH@/invaders/enemy_1.png")
|
|
|
|
gamedata.enemies[2] = image("@AWESOME_ICON_PATH@/invaders/enemy_2.png")
|
|
|
|
gamedata.enemies[3] = image("@AWESOME_ICON_PATH@/invaders/enemy_3.png")
|
2008-10-14 18:16:26 +02:00
|
|
|
|
|
|
|
local player = { }
|
|
|
|
local game = { }
|
|
|
|
local shots = { }
|
|
|
|
local enemies = { }
|
|
|
|
|
2009-01-28 14:23:07 +01:00
|
|
|
function player.new ()
|
2009-05-05 17:32:53 +02:00
|
|
|
p = wibox({ bg = gamedata.solidbg or "#12345600" })
|
Various changes to awful.util and invaders
This commit changes various aspects of awful.util and invaders:
awful.util:
- added awful.util.getdir(d)
This function takes one argument and returns a matching directory,
as of now, only "cache" is supported. The return value is either
$XDG_CACHE_HOME/awesome/ or $HOME/.cache/awesome/, XDG_CACHE_HOME
takes precedence
invaders:
- renamed invaders to awesome invaders
at two places in the sourcecode, invaders is referred to as
"Space Invaders for Awesome". As Taiko holds the trademark for
the term "Space Invaders", I changed both of its occurences to
"Awesome Invaders" to avoid conflicts with the law of Japan and
the United States of America (and possibly others)
- added support for XDG_CACHE_HOME
this change adds support for XDG_CACHE_HOME as the cache directory
for highscores and screenshots
- added some parameters to invaders.run()
this change adds three parameters to invaders.run, supplied as a
table. They are "x", "y" and "solidbg".
"x" sets the X coordinate of the playfield
"y" sets the Y coordinate of the playfield
"solidbg" sets the color of the playfield background for people who
have problems with transparency. This still looks rather hackish and
needs to be polished
- changed startup position
up until now, invaders always started at (100,100) on the first
screen, now it starts centered to the screen on which the mouse cursor
is.
2008-10-17 19:05:57 +02:00
|
|
|
p:geometry({ width = 24,
|
2008-10-27 16:42:02 +01:00
|
|
|
height = 16,
|
|
|
|
x = gamedata.field.x + (gamedata.field.w / 2),
|
|
|
|
y = gamedata.field.y + gamedata.field.h - (16 + 5) })
|
2009-01-27 20:52:34 +01:00
|
|
|
p.screen = gamedata.screen
|
2008-10-14 18:16:26 +02:00
|
|
|
|
2008-11-12 11:48:51 +01:00
|
|
|
w = widget({ type = "imagebox" })
|
2008-10-14 18:16:26 +02:00
|
|
|
w.image = image("@AWESOME_ICON_PATH@/invaders/player.png")
|
2008-10-19 19:14:55 +02:00
|
|
|
p.widgets = w
|
2008-10-14 18:16:26 +02:00
|
|
|
|
|
|
|
return p
|
|
|
|
end
|
|
|
|
|
2009-01-28 14:23:07 +01:00
|
|
|
function player.move(x)
|
2008-11-08 16:27:06 +01:00
|
|
|
if not gamedata.running then return false end
|
2008-10-27 17:12:04 +01:00
|
|
|
local g = gamedata.player:geometry()
|
2008-10-14 18:16:26 +02:00
|
|
|
|
2008-10-27 17:12:04 +01:00
|
|
|
if x < 0 and g.x > gamedata.field.x then
|
|
|
|
g.x = g.x + x
|
|
|
|
elseif x > 0 and g.x < gamedata.field.x + gamedata.field.w - 30 then
|
|
|
|
g.x = g.x + x
|
2008-10-14 18:16:26 +02:00
|
|
|
end
|
|
|
|
|
2008-10-27 17:12:04 +01:00
|
|
|
gamedata.player:geometry(g)
|
2008-10-14 18:16:26 +02:00
|
|
|
end
|
|
|
|
|
2009-01-28 14:23:07 +01:00
|
|
|
function player.fire()
|
2008-11-08 16:27:06 +01:00
|
|
|
if not gamedata.running then return false end
|
2008-10-27 17:17:47 +01:00
|
|
|
if gamedata.ammo == 1 then
|
|
|
|
gamedata.ammo = 0
|
Various changes to awful.util and invaders
This commit changes various aspects of awful.util and invaders:
awful.util:
- added awful.util.getdir(d)
This function takes one argument and returns a matching directory,
as of now, only "cache" is supported. The return value is either
$XDG_CACHE_HOME/awesome/ or $HOME/.cache/awesome/, XDG_CACHE_HOME
takes precedence
invaders:
- renamed invaders to awesome invaders
at two places in the sourcecode, invaders is referred to as
"Space Invaders for Awesome". As Taiko holds the trademark for
the term "Space Invaders", I changed both of its occurences to
"Awesome Invaders" to avoid conflicts with the law of Japan and
the United States of America (and possibly others)
- added support for XDG_CACHE_HOME
this change adds support for XDG_CACHE_HOME as the cache directory
for highscores and screenshots
- added some parameters to invaders.run()
this change adds three parameters to invaders.run, supplied as a
table. They are "x", "y" and "solidbg".
"x" sets the X coordinate of the playfield
"y" sets the Y coordinate of the playfield
"solidbg" sets the color of the playfield background for people who
have problems with transparency. This still looks rather hackish and
needs to be polished
- changed startup position
up until now, invaders always started at (100,100) on the first
screen, now it starts centered to the screen on which the mouse cursor
is.
2008-10-17 19:05:57 +02:00
|
|
|
local gb = gamedata.player:geometry()
|
2008-10-14 18:16:26 +02:00
|
|
|
shots.fire(gb.x + 9, gb.y - 10, "#00FF00")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-28 14:23:07 +01:00
|
|
|
function shots.fire (x, y, color)
|
2009-05-05 17:32:53 +02:00
|
|
|
local s = wibox({ bg = color })
|
2008-10-27 16:42:02 +01:00
|
|
|
s:geometry({ width = 4,
|
|
|
|
height = 10,
|
|
|
|
x = x,
|
|
|
|
y = y })
|
2009-01-27 20:52:34 +01:00
|
|
|
s.screen = gamedata.screen
|
2008-10-14 18:16:26 +02:00
|
|
|
|
2008-10-27 17:06:51 +01:00
|
|
|
if not gamedata.shot or gamedata.shot.screen == nil then
|
|
|
|
gamedata.shot = s
|
2008-10-14 18:16:26 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-28 14:23:07 +01:00
|
|
|
function shots.fire_enemy (x, y, color)
|
2008-10-14 18:16:26 +02:00
|
|
|
if gamedata.enemies.shots.fired < gamedata.enemies.shots.max then
|
|
|
|
gamedata.enemies.shots.fired = gamedata.enemies.shots.fired + 1
|
2009-05-05 17:32:53 +02:00
|
|
|
local s = wibox({ bg = color })
|
2008-10-27 16:42:02 +01:00
|
|
|
s:geometry({ width = 4,
|
|
|
|
height = 10,
|
|
|
|
x = x,
|
|
|
|
y = y })
|
2009-01-27 20:52:34 +01:00
|
|
|
s.screen = gamedata.screen
|
2008-10-14 18:16:26 +02:00
|
|
|
for i = 1, gamedata.enemies.shots.max do
|
|
|
|
if not gamedata.enemies.shots[i] or gamedata.enemies.shots[i].screen == nil then
|
|
|
|
gamedata.enemies.shots[i] = s
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-28 14:23:07 +01:00
|
|
|
function shots.handle()
|
2008-10-14 18:16:26 +02:00
|
|
|
if not gamedata.running then return false end
|
2008-10-27 17:17:47 +01:00
|
|
|
if gamedata.ammo == 1 then return false end
|
2008-10-14 18:16:26 +02:00
|
|
|
|
2008-10-27 17:06:51 +01:00
|
|
|
local s = gamedata.shot
|
|
|
|
if s and s.screen then
|
2008-10-27 17:17:47 +01:00
|
|
|
gamedata.ammo = 0
|
2008-10-27 17:06:51 +01:00
|
|
|
local g = s:geometry()
|
|
|
|
if g.y < gamedata.field.y + 15 then
|
|
|
|
s.screen = nil
|
2008-10-27 17:17:47 +01:00
|
|
|
gamedata.ammo = 1
|
2008-10-27 17:06:51 +01:00
|
|
|
else
|
|
|
|
g.y = g.y - 6
|
|
|
|
s:geometry(g)
|
2008-10-14 18:16:26 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2009-01-28 14:23:07 +01:00
|
|
|
function shots.handle_enemy ()
|
2008-10-14 18:16:26 +02:00
|
|
|
if not gamedata.running then return false end
|
|
|
|
if gamedata.enemies.shots.fired == 0 then return false end
|
|
|
|
|
|
|
|
for i = 1, gamedata.enemies.shots.max do
|
|
|
|
local s = gamedata.enemies.shots[i]
|
|
|
|
if s and s.screen then
|
|
|
|
local g = s:geometry()
|
|
|
|
if g.y > gamedata.field.y + gamedata.field.h - 15 then
|
|
|
|
s.screen = nil
|
|
|
|
gamedata.enemies.shots.fired = gamedata.enemies.shots.fired - 1
|
|
|
|
else
|
|
|
|
g.y = g.y + 3
|
|
|
|
s:geometry(g)
|
|
|
|
end
|
Various changes to awful.util and invaders
This commit changes various aspects of awful.util and invaders:
awful.util:
- added awful.util.getdir(d)
This function takes one argument and returns a matching directory,
as of now, only "cache" is supported. The return value is either
$XDG_CACHE_HOME/awesome/ or $HOME/.cache/awesome/, XDG_CACHE_HOME
takes precedence
invaders:
- renamed invaders to awesome invaders
at two places in the sourcecode, invaders is referred to as
"Space Invaders for Awesome". As Taiko holds the trademark for
the term "Space Invaders", I changed both of its occurences to
"Awesome Invaders" to avoid conflicts with the law of Japan and
the United States of America (and possibly others)
- added support for XDG_CACHE_HOME
this change adds support for XDG_CACHE_HOME as the cache directory
for highscores and screenshots
- added some parameters to invaders.run()
this change adds three parameters to invaders.run, supplied as a
table. They are "x", "y" and "solidbg".
"x" sets the X coordinate of the playfield
"y" sets the Y coordinate of the playfield
"solidbg" sets the color of the playfield background for people who
have problems with transparency. This still looks rather hackish and
needs to be polished
- changed startup position
up until now, invaders always started at (100,100) on the first
screen, now it starts centered to the screen on which the mouse cursor
is.
2008-10-17 19:05:57 +02:00
|
|
|
if game.collide(gamedata.player, s) then
|
2008-10-14 18:16:26 +02:00
|
|
|
game.over()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-28 14:23:07 +01:00
|
|
|
function enemies.new (t)
|
2009-05-05 17:32:53 +02:00
|
|
|
e = wibox({ bg = gamedata.solidbg or "#12345600" })
|
2008-10-27 16:42:02 +01:00
|
|
|
e:geometry({ height = gamedata.enemies.h,
|
|
|
|
width = gamedata.enemies.w,
|
2008-10-14 18:16:26 +02:00
|
|
|
x = gamedata.field.x,
|
|
|
|
y = gamedata.field.y })
|
2009-01-27 20:52:34 +01:00
|
|
|
e.screen = gamedata.screen
|
2008-11-12 11:48:51 +01:00
|
|
|
w = widget({ type = "imagebox" })
|
2008-10-21 21:17:07 +02:00
|
|
|
w.image = gamedata.enemies[t]
|
|
|
|
|
2008-10-19 19:14:55 +02:00
|
|
|
e.widgets = w
|
2008-10-14 18:16:26 +02:00
|
|
|
return e
|
|
|
|
end
|
|
|
|
|
2009-01-28 14:23:07 +01:00
|
|
|
function enemies.setup()
|
2008-10-14 18:16:26 +02:00
|
|
|
gamedata.enemies.data = { }
|
|
|
|
gamedata.enemies.x = 10
|
|
|
|
gamedata.enemies.y = 5
|
|
|
|
gamedata.enemies.dir = 1
|
|
|
|
if not gamedata.enemies.shots then gamedata.enemies.shots = { } end
|
|
|
|
gamedata.enemies.shots.max = 10
|
|
|
|
gamedata.enemies.shots.fired = 0
|
|
|
|
|
|
|
|
gamedata.enemies.speed_count = 0
|
|
|
|
|
|
|
|
for y = 1, gamedata.enemies.rows do
|
|
|
|
gamedata.enemies.data[y] = { }
|
|
|
|
for x = 1, math.ceil((gamedata.enemies.count / gamedata.enemies.rows) + 1) do
|
2008-10-21 19:17:51 +02:00
|
|
|
gamedata.enemies.data[y][x] = enemies.new((y % 3) + 1)
|
2008-10-14 18:16:26 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-10-27 17:06:51 +01:00
|
|
|
if gamedata.shot then
|
|
|
|
gamedata.shot.screen = nil
|
2008-10-14 18:16:26 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
for i = 1, gamedata.enemies.shots.max do
|
|
|
|
if gamedata.enemies.shots[i] then
|
|
|
|
gamedata.enemies.shots[i].screen = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-28 14:23:07 +01:00
|
|
|
function enemies.handle ()
|
2008-10-14 18:16:26 +02:00
|
|
|
if not gamedata.running then return false end
|
|
|
|
|
|
|
|
gamedata.enemies.number = 0
|
|
|
|
|
|
|
|
for y = 1, #gamedata.enemies.data do
|
|
|
|
for x = 1, #gamedata.enemies.data[y] do
|
|
|
|
local e = gamedata.enemies.data[y][x]
|
|
|
|
if e.screen then
|
|
|
|
local g = e:geometry()
|
|
|
|
gamedata.enemies.number = gamedata.enemies.number + 1
|
|
|
|
if gamedata.enemies.speed_count == (gamedata.enemies.speed - 1) then
|
|
|
|
g.y = math.floor(gamedata.field.y + gamedata.enemies.y + ((y - 1) * gamedata.enemies.h * 2))
|
|
|
|
g.x = math.floor(gamedata.field.x + gamedata.enemies.x + ((x - 1) * gamedata.enemies.w * 2))
|
|
|
|
e:geometry(g)
|
Various changes to awful.util and invaders
This commit changes various aspects of awful.util and invaders:
awful.util:
- added awful.util.getdir(d)
This function takes one argument and returns a matching directory,
as of now, only "cache" is supported. The return value is either
$XDG_CACHE_HOME/awesome/ or $HOME/.cache/awesome/, XDG_CACHE_HOME
takes precedence
invaders:
- renamed invaders to awesome invaders
at two places in the sourcecode, invaders is referred to as
"Space Invaders for Awesome". As Taiko holds the trademark for
the term "Space Invaders", I changed both of its occurences to
"Awesome Invaders" to avoid conflicts with the law of Japan and
the United States of America (and possibly others)
- added support for XDG_CACHE_HOME
this change adds support for XDG_CACHE_HOME as the cache directory
for highscores and screenshots
- added some parameters to invaders.run()
this change adds three parameters to invaders.run, supplied as a
table. They are "x", "y" and "solidbg".
"x" sets the X coordinate of the playfield
"y" sets the Y coordinate of the playfield
"solidbg" sets the color of the playfield background for people who
have problems with transparency. This still looks rather hackish and
needs to be polished
- changed startup position
up until now, invaders always started at (100,100) on the first
screen, now it starts centered to the screen on which the mouse cursor
is.
2008-10-17 19:05:57 +02:00
|
|
|
if game.collide(gamedata.player, e) or g.y > gamedata.field.y + gamedata.field.h - 20 then
|
2008-10-14 18:16:26 +02:00
|
|
|
game.over()
|
|
|
|
end
|
|
|
|
end
|
2008-10-27 17:06:51 +01:00
|
|
|
if gamedata.ammo == 0 then
|
|
|
|
local s = gamedata.shot
|
2008-10-14 18:16:26 +02:00
|
|
|
if s and s.screen and game.collide(e, s) then
|
2008-10-27 17:06:51 +01:00
|
|
|
gamedata.enemies.number = gamedata.enemies.number - 1
|
2008-10-27 17:17:47 +01:00
|
|
|
gamedata.ammo = 1
|
2008-10-27 17:06:51 +01:00
|
|
|
e.screen = nil
|
|
|
|
s.screen = nil
|
|
|
|
|
|
|
|
if (y % 3) == 0 then
|
|
|
|
gamedata.score = gamedata.score + 15
|
|
|
|
elseif (y % 3) == 1 then
|
|
|
|
gamedata.score = gamedata.score + 10
|
|
|
|
else
|
|
|
|
gamedata.score = gamedata.score + 5
|
2008-10-14 18:16:26 +02:00
|
|
|
end
|
2008-10-27 17:24:27 +01:00
|
|
|
gamedata.field.status.text = gamedata.score.." | "..gamedata.round.." "
|
2008-10-14 18:16:26 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local x = math.random(1, gamedata.enemies.count / gamedata.enemies.rows)
|
|
|
|
if gamedata.enemies.speed_count == (gamedata.enemies.speed - 1)
|
|
|
|
and math.random(0, 150) <= 1
|
|
|
|
and gamedata.enemies.data[y][x].screen then
|
|
|
|
shots.fire_enemy(math.floor(gamedata.field.x + gamedata.enemies.x + ((x - 1) * gamedata.enemies.w)),
|
|
|
|
gamedata.field.y + gamedata.enemies.y + gamedata.enemies.h,
|
|
|
|
"#FF0000")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if gamedata.enemies.number == 0 then
|
|
|
|
enemies.setup()
|
2008-10-27 17:24:27 +01:00
|
|
|
gamedata.round = gamedata.round + 1
|
|
|
|
gamedata.field.status.text = gamedata.score.." | "..gamedata.round.." "
|
2008-10-15 18:59:31 +02:00
|
|
|
if gamedata.enemies.speed > 1 then gamedata.enemies.speed = gamedata.enemies.speed - 1 end
|
2008-10-14 18:16:26 +02:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
gamedata.enemies.speed_count = gamedata.enemies.speed_count + 1
|
|
|
|
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)
|
2008-10-19 19:28:11 +02:00
|
|
|
if gamedata.enemies.x > gamedata.field.w - (2 * gamedata.enemies.w * (gamedata.enemies.count / gamedata.enemies.rows + 1)) + 5
|
2008-10-14 18:16:26 +02:00
|
|
|
or gamedata.enemies.x <= 10 then
|
|
|
|
gamedata.enemies.y = gamedata.enemies.y + gamedata.enemies.h
|
|
|
|
gamedata.enemies.dir = gamedata.enemies.dir * (-1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-28 14:23:07 +01:00
|
|
|
function keyhandler(mod, key, event)
|
2008-12-16 15:02:54 +01:00
|
|
|
if event ~= "press" then return true end
|
2008-10-14 18:16:26 +02:00
|
|
|
if gamedata.highscore.getkeys then
|
|
|
|
if key:len() == 1 and gamedata.name:len() < 20 then
|
|
|
|
gamedata.name = gamedata.name .. key
|
|
|
|
elseif key == "BackSpace" then
|
|
|
|
gamedata.name = gamedata.name:sub(1, gamedata.name:len() - 1)
|
|
|
|
elseif key == "Return" then
|
|
|
|
gamedata.highscore.window.screen = nil
|
|
|
|
game.highscore_add(gamedata.score, gamedata.name)
|
|
|
|
game.highscore_show()
|
|
|
|
gamedata.highscore.getkeys = false
|
|
|
|
end
|
|
|
|
gamedata.namebox.text = " Name: " .. gamedata.name .. "|"
|
|
|
|
else
|
|
|
|
if key == "Left" then
|
|
|
|
player.move(-10)
|
|
|
|
elseif key == "Right" then
|
|
|
|
player.move(10)
|
|
|
|
elseif key == "q" then
|
|
|
|
game.quit()
|
|
|
|
return false
|
|
|
|
elseif key == " " then
|
|
|
|
player.fire()
|
|
|
|
elseif key == "s" then
|
2008-11-06 16:00:26 +01:00
|
|
|
awful.util.spawn("import -window root "..gamedata.cachedir.."/invaders-"..os.time()..".png")
|
2008-11-08 16:27:06 +01:00
|
|
|
elseif key == "p" then
|
|
|
|
gamedata.running = not gamedata.running
|
2008-10-14 18:16:26 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2009-01-28 14:23:07 +01:00
|
|
|
function game.collide(o1, o2)
|
2008-10-14 18:16:26 +02:00
|
|
|
g1 = o1:geometry()
|
|
|
|
g2 = o2:geometry()
|
|
|
|
|
|
|
|
--check if o2 is inside o1
|
|
|
|
if g2.x >= g1.x and g2.x <= g1.x + g1.width
|
|
|
|
and g2.y >= g1.y and g2.y <= g1.y + g1.height then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2009-01-28 14:23:07 +01:00
|
|
|
function game.over ()
|
2008-10-14 18:16:26 +02:00
|
|
|
gamedata.running = false
|
|
|
|
game.highscore(gamedata.score)
|
|
|
|
end
|
|
|
|
|
2009-01-28 14:23:07 +01:00
|
|
|
function game.quit()
|
2008-10-14 18:16:26 +02:00
|
|
|
gamedata.running = false
|
|
|
|
|
|
|
|
if gamedata.highscore.window then
|
|
|
|
gamedata.highscore.window.screen = nil
|
2008-10-19 19:14:55 +02:00
|
|
|
gamedata.highscore.window.widgets = nil
|
2008-10-14 18:16:26 +02:00
|
|
|
end
|
|
|
|
|
Various changes to awful.util and invaders
This commit changes various aspects of awful.util and invaders:
awful.util:
- added awful.util.getdir(d)
This function takes one argument and returns a matching directory,
as of now, only "cache" is supported. The return value is either
$XDG_CACHE_HOME/awesome/ or $HOME/.cache/awesome/, XDG_CACHE_HOME
takes precedence
invaders:
- renamed invaders to awesome invaders
at two places in the sourcecode, invaders is referred to as
"Space Invaders for Awesome". As Taiko holds the trademark for
the term "Space Invaders", I changed both of its occurences to
"Awesome Invaders" to avoid conflicts with the law of Japan and
the United States of America (and possibly others)
- added support for XDG_CACHE_HOME
this change adds support for XDG_CACHE_HOME as the cache directory
for highscores and screenshots
- added some parameters to invaders.run()
this change adds three parameters to invaders.run, supplied as a
table. They are "x", "y" and "solidbg".
"x" sets the X coordinate of the playfield
"y" sets the Y coordinate of the playfield
"solidbg" sets the color of the playfield background for people who
have problems with transparency. This still looks rather hackish and
needs to be polished
- changed startup position
up until now, invaders always started at (100,100) on the first
screen, now it starts centered to the screen on which the mouse cursor
is.
2008-10-17 19:05:57 +02:00
|
|
|
if gamedata.field.background then
|
2008-10-27 16:42:02 +01:00
|
|
|
gamedata.field.background.screen = nil
|
Various changes to awful.util and invaders
This commit changes various aspects of awful.util and invaders:
awful.util:
- added awful.util.getdir(d)
This function takes one argument and returns a matching directory,
as of now, only "cache" is supported. The return value is either
$XDG_CACHE_HOME/awesome/ or $HOME/.cache/awesome/, XDG_CACHE_HOME
takes precedence
invaders:
- renamed invaders to awesome invaders
at two places in the sourcecode, invaders is referred to as
"Space Invaders for Awesome". As Taiko holds the trademark for
the term "Space Invaders", I changed both of its occurences to
"Awesome Invaders" to avoid conflicts with the law of Japan and
the United States of America (and possibly others)
- added support for XDG_CACHE_HOME
this change adds support for XDG_CACHE_HOME as the cache directory
for highscores and screenshots
- added some parameters to invaders.run()
this change adds three parameters to invaders.run, supplied as a
table. They are "x", "y" and "solidbg".
"x" sets the X coordinate of the playfield
"y" sets the Y coordinate of the playfield
"solidbg" sets the color of the playfield background for people who
have problems with transparency. This still looks rather hackish and
needs to be polished
- changed startup position
up until now, invaders always started at (100,100) on the first
screen, now it starts centered to the screen on which the mouse cursor
is.
2008-10-17 19:05:57 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
gamedata.player.screen = nil
|
2008-10-19 19:14:55 +02:00
|
|
|
gamedata.player.widgets = nil
|
Various changes to awful.util and invaders
This commit changes various aspects of awful.util and invaders:
awful.util:
- added awful.util.getdir(d)
This function takes one argument and returns a matching directory,
as of now, only "cache" is supported. The return value is either
$XDG_CACHE_HOME/awesome/ or $HOME/.cache/awesome/, XDG_CACHE_HOME
takes precedence
invaders:
- renamed invaders to awesome invaders
at two places in the sourcecode, invaders is referred to as
"Space Invaders for Awesome". As Taiko holds the trademark for
the term "Space Invaders", I changed both of its occurences to
"Awesome Invaders" to avoid conflicts with the law of Japan and
the United States of America (and possibly others)
- added support for XDG_CACHE_HOME
this change adds support for XDG_CACHE_HOME as the cache directory
for highscores and screenshots
- added some parameters to invaders.run()
this change adds three parameters to invaders.run, supplied as a
table. They are "x", "y" and "solidbg".
"x" sets the X coordinate of the playfield
"y" sets the Y coordinate of the playfield
"solidbg" sets the color of the playfield background for people who
have problems with transparency. This still looks rather hackish and
needs to be polished
- changed startup position
up until now, invaders always started at (100,100) on the first
screen, now it starts centered to the screen on which the mouse cursor
is.
2008-10-17 19:05:57 +02:00
|
|
|
gamedata.player = nil
|
2008-10-14 18:16:26 +02:00
|
|
|
|
|
|
|
gamedata.field.north.screen = nil
|
|
|
|
gamedata.field.north = nil
|
|
|
|
|
|
|
|
gamedata.field.south.screen = nil
|
|
|
|
gamedata.field.south = nil
|
|
|
|
|
|
|
|
gamedata.field.west.screen = nil
|
|
|
|
gamedata.field.west = nil
|
|
|
|
|
|
|
|
gamedata.field.east.screen = nil
|
|
|
|
gamedata.field.east = nil
|
|
|
|
|
|
|
|
for y = 1, #gamedata.enemies.data do
|
|
|
|
for x = 1, #gamedata.enemies.data[y] do
|
|
|
|
gamedata.enemies.data[y][x].screen = nil
|
2008-10-19 19:14:55 +02:00
|
|
|
gamedata.enemies.data[y][x].widgets = nil
|
2008-10-14 18:16:26 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-10-27 17:06:51 +01:00
|
|
|
if gamedata.shot then gamedata.shot.screen = nil end
|
2008-10-14 18:16:26 +02:00
|
|
|
|
|
|
|
for i = 1, gamedata.enemies.shots.max do
|
|
|
|
if gamedata.enemies.shots[i] then gamedata.enemies.shots[i].screen = nil end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-28 14:23:07 +01:00
|
|
|
function game.highscore_show ()
|
2008-11-12 11:48:51 +01:00
|
|
|
gamedata.highscore.table = widget({ type = "textbox" })
|
2008-10-14 18:16:26 +02:00
|
|
|
|
2009-03-20 21:08:12 +01:00
|
|
|
gamedata.highscore.table.text = "\tHighscores:\t\n"
|
2008-10-14 18:16:26 +02:00
|
|
|
|
|
|
|
for i = 1, 5 do
|
|
|
|
gamedata.highscore.table.text = gamedata.highscore.table.text .. "\n\t" .. gamedata.highscore[i]
|
|
|
|
end
|
|
|
|
|
|
|
|
gamedata.highscore.table.text = gamedata.highscore.table.text .. "\n\n Press Q to quit"
|
|
|
|
|
2009-03-20 21:08:12 +01:00
|
|
|
gamedata.highscore.window:geometry(gamedata.highscore.table:extents())
|
|
|
|
gamedata.highscore.window:geometry({ x = gamedata.field.x + math.floor(gamedata.field.w / 2) - 100,
|
|
|
|
y = gamedata.field.y + math.floor(gamedata.field.h / 2) - 55 })
|
|
|
|
gamedata.highscore.window.screen = gamedata.screen
|
|
|
|
|
|
|
|
gamedata.highscore.window.widgets = gamedata.highscore.table
|
|
|
|
|
Various changes to awful.util and invaders
This commit changes various aspects of awful.util and invaders:
awful.util:
- added awful.util.getdir(d)
This function takes one argument and returns a matching directory,
as of now, only "cache" is supported. The return value is either
$XDG_CACHE_HOME/awesome/ or $HOME/.cache/awesome/, XDG_CACHE_HOME
takes precedence
invaders:
- renamed invaders to awesome invaders
at two places in the sourcecode, invaders is referred to as
"Space Invaders for Awesome". As Taiko holds the trademark for
the term "Space Invaders", I changed both of its occurences to
"Awesome Invaders" to avoid conflicts with the law of Japan and
the United States of America (and possibly others)
- added support for XDG_CACHE_HOME
this change adds support for XDG_CACHE_HOME as the cache directory
for highscores and screenshots
- added some parameters to invaders.run()
this change adds three parameters to invaders.run, supplied as a
table. They are "x", "y" and "solidbg".
"x" sets the X coordinate of the playfield
"y" sets the Y coordinate of the playfield
"solidbg" sets the color of the playfield background for people who
have problems with transparency. This still looks rather hackish and
needs to be polished
- changed startup position
up until now, invaders always started at (100,100) on the first
screen, now it starts centered to the screen on which the mouse cursor
is.
2008-10-17 19:05:57 +02:00
|
|
|
local fh = io.open(gamedata.cachedir.."/highscore_invaders", "w")
|
|
|
|
|
2008-10-14 18:16:26 +02:00
|
|
|
if not fh then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
for i = 1, 5 do
|
|
|
|
fh:write(gamedata.highscore[i].."\n")
|
|
|
|
end
|
|
|
|
|
|
|
|
fh:close()
|
|
|
|
end
|
|
|
|
|
2009-01-28 14:23:07 +01:00
|
|
|
function game.highscore_add (score, name)
|
2008-10-14 18:16:26 +02:00
|
|
|
local t = gamedata.highscore
|
|
|
|
|
|
|
|
for i = 5, 1, -1 do
|
|
|
|
if tonumber(t[i]:match("(%d+) ")) <= score then
|
|
|
|
if t[i+1] then t[i+1] = t[i] end
|
|
|
|
t[i] = score .. " " .. name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
gamedata.highscore = t
|
|
|
|
end
|
|
|
|
|
2009-01-28 14:23:07 +01:00
|
|
|
function game.highscore (score)
|
2008-11-08 20:43:00 +01:00
|
|
|
if gamedata.highscore.window and gamedata.highscore.window.screen then return false end
|
Various changes to awful.util and invaders
This commit changes various aspects of awful.util and invaders:
awful.util:
- added awful.util.getdir(d)
This function takes one argument and returns a matching directory,
as of now, only "cache" is supported. The return value is either
$XDG_CACHE_HOME/awesome/ or $HOME/.cache/awesome/, XDG_CACHE_HOME
takes precedence
invaders:
- renamed invaders to awesome invaders
at two places in the sourcecode, invaders is referred to as
"Space Invaders for Awesome". As Taiko holds the trademark for
the term "Space Invaders", I changed both of its occurences to
"Awesome Invaders" to avoid conflicts with the law of Japan and
the United States of America (and possibly others)
- added support for XDG_CACHE_HOME
this change adds support for XDG_CACHE_HOME as the cache directory
for highscores and screenshots
- added some parameters to invaders.run()
this change adds three parameters to invaders.run, supplied as a
table. They are "x", "y" and "solidbg".
"x" sets the X coordinate of the playfield
"y" sets the Y coordinate of the playfield
"solidbg" sets the color of the playfield background for people who
have problems with transparency. This still looks rather hackish and
needs to be polished
- changed startup position
up until now, invaders always started at (100,100) on the first
screen, now it starts centered to the screen on which the mouse cursor
is.
2008-10-17 19:05:57 +02:00
|
|
|
local fh = io.open(gamedata.cachedir.."/highscore_invaders", "r")
|
|
|
|
|
2008-10-14 18:16:26 +02:00
|
|
|
if fh then
|
|
|
|
for i = 1, 5 do
|
|
|
|
gamedata.highscore[i] = fh:read("*line")
|
|
|
|
end
|
|
|
|
fh:close()
|
|
|
|
else
|
|
|
|
for i = 1, 5 do
|
|
|
|
gamedata.highscore[i] = ((6-i)*20).." foo"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local newentry = false
|
|
|
|
for i = 1, 5 do
|
|
|
|
local s = tonumber(gamedata.highscore[i]:match("(%d+) .*"))
|
|
|
|
if s <= score then newentry = true end
|
|
|
|
end
|
|
|
|
|
2009-05-05 17:32:53 +02:00
|
|
|
gamedata.highscore.window = wibox({ bg = gamedata.btheme.bg_focus or "#333333",
|
2008-10-27 16:42:02 +01:00
|
|
|
fg = gamedata.btheme.fg_focus or "#FFFFFF" })
|
|
|
|
gamedata.highscore.window:geometry({ height = 20,
|
|
|
|
width = 300,
|
2008-10-14 18:16:26 +02:00
|
|
|
x = gamedata.field.x + math.floor(gamedata.field.w / 2) - 150,
|
|
|
|
y = gamedata.field.y + math.floor(gamedata.field.h / 2) })
|
2009-01-27 20:52:34 +01:00
|
|
|
gamedata.highscore.window.screen = gamedata.screen
|
2008-10-14 18:16:26 +02:00
|
|
|
|
2008-11-12 11:48:51 +01:00
|
|
|
gamedata.namebox = widget({ type = "textbox" })
|
2008-10-14 18:16:26 +02:00
|
|
|
gamedata.namebox.text = " Name: |"
|
2008-10-19 19:14:55 +02:00
|
|
|
gamedata.highscore.window.widgets = gamedata.namebox
|
2008-10-14 18:16:26 +02:00
|
|
|
|
|
|
|
if newentry then
|
|
|
|
gamedata.name = ""
|
|
|
|
gamedata.highscore.getkeys = true
|
|
|
|
else
|
|
|
|
game.highscore_show()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-10-21 19:28:45 +02:00
|
|
|
--- Run Awesome Invaders
|
|
|
|
-- @param args A table with parameters.
|
|
|
|
-- x the X coordinate of the playing field.
|
|
|
|
-- y the Y coordinate of the playing field.
|
|
|
|
-- if either of these is left out, the game is placed in the center of the focused screen.
|
|
|
|
-- solidbg the background color of the playing field. If none is given, the playing field is transparent.
|
Various changes to awful.util and invaders
This commit changes various aspects of awful.util and invaders:
awful.util:
- added awful.util.getdir(d)
This function takes one argument and returns a matching directory,
as of now, only "cache" is supported. The return value is either
$XDG_CACHE_HOME/awesome/ or $HOME/.cache/awesome/, XDG_CACHE_HOME
takes precedence
invaders:
- renamed invaders to awesome invaders
at two places in the sourcecode, invaders is referred to as
"Space Invaders for Awesome". As Taiko holds the trademark for
the term "Space Invaders", I changed both of its occurences to
"Awesome Invaders" to avoid conflicts with the law of Japan and
the United States of America (and possibly others)
- added support for XDG_CACHE_HOME
this change adds support for XDG_CACHE_HOME as the cache directory
for highscores and screenshots
- added some parameters to invaders.run()
this change adds three parameters to invaders.run, supplied as a
table. They are "x", "y" and "solidbg".
"x" sets the X coordinate of the playfield
"y" sets the Y coordinate of the playfield
"solidbg" sets the color of the playfield background for people who
have problems with transparency. This still looks rather hackish and
needs to be polished
- changed startup position
up until now, invaders always started at (100,100) on the first
screen, now it starts centered to the screen on which the mouse cursor
is.
2008-10-17 19:05:57 +02:00
|
|
|
function run(args)
|
|
|
|
gamedata.screen = capi.screen[capi.mouse.screen]
|
2008-10-21 16:25:06 +02:00
|
|
|
gamedata.field.x = gamedata.screen.geometry.x + math.floor((gamedata.screen.geometry.width - gamedata.field.w) / 2)
|
|
|
|
gamedata.field.y = gamedata.screen.geometry.y + math.floor((gamedata.screen.geometry.height - gamedata.field.h) / 2)
|
2009-01-27 20:52:34 +01:00
|
|
|
gamedata.screen = capi.mouse.screen
|
2008-10-19 19:28:11 +02:00
|
|
|
|
Various changes to awful.util and invaders
This commit changes various aspects of awful.util and invaders:
awful.util:
- added awful.util.getdir(d)
This function takes one argument and returns a matching directory,
as of now, only "cache" is supported. The return value is either
$XDG_CACHE_HOME/awesome/ or $HOME/.cache/awesome/, XDG_CACHE_HOME
takes precedence
invaders:
- renamed invaders to awesome invaders
at two places in the sourcecode, invaders is referred to as
"Space Invaders for Awesome". As Taiko holds the trademark for
the term "Space Invaders", I changed both of its occurences to
"Awesome Invaders" to avoid conflicts with the law of Japan and
the United States of America (and possibly others)
- added support for XDG_CACHE_HOME
this change adds support for XDG_CACHE_HOME as the cache directory
for highscores and screenshots
- added some parameters to invaders.run()
this change adds three parameters to invaders.run, supplied as a
table. They are "x", "y" and "solidbg".
"x" sets the X coordinate of the playfield
"y" sets the Y coordinate of the playfield
"solidbg" sets the color of the playfield background for people who
have problems with transparency. This still looks rather hackish and
needs to be polished
- changed startup position
up until now, invaders always started at (100,100) on the first
screen, now it starts centered to the screen on which the mouse cursor
is.
2008-10-17 19:05:57 +02:00
|
|
|
if args then
|
2008-10-27 16:42:02 +01:00
|
|
|
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
|
Various changes to awful.util and invaders
This commit changes various aspects of awful.util and invaders:
awful.util:
- added awful.util.getdir(d)
This function takes one argument and returns a matching directory,
as of now, only "cache" is supported. The return value is either
$XDG_CACHE_HOME/awesome/ or $HOME/.cache/awesome/, XDG_CACHE_HOME
takes precedence
invaders:
- renamed invaders to awesome invaders
at two places in the sourcecode, invaders is referred to as
"Space Invaders for Awesome". As Taiko holds the trademark for
the term "Space Invaders", I changed both of its occurences to
"Awesome Invaders" to avoid conflicts with the law of Japan and
the United States of America (and possibly others)
- added support for XDG_CACHE_HOME
this change adds support for XDG_CACHE_HOME as the cache directory
for highscores and screenshots
- added some parameters to invaders.run()
this change adds three parameters to invaders.run, supplied as a
table. They are "x", "y" and "solidbg".
"x" sets the X coordinate of the playfield
"y" sets the Y coordinate of the playfield
"solidbg" sets the color of the playfield background for people who
have problems with transparency. This still looks rather hackish and
needs to be polished
- changed startup position
up until now, invaders always started at (100,100) on the first
screen, now it starts centered to the screen on which the mouse cursor
is.
2008-10-17 19:05:57 +02:00
|
|
|
end
|
|
|
|
|
2008-10-14 18:16:26 +02:00
|
|
|
gamedata.score = 0
|
|
|
|
gamedata.name = ""
|
2008-10-27 17:17:47 +01:00
|
|
|
gamedata.ammo = 1
|
2008-10-27 17:24:27 +01:00
|
|
|
gamedata.round = 1
|
2008-10-15 18:59:31 +02:00
|
|
|
gamedata.btheme = beautiful.get()
|
2008-10-14 18:16:26 +02:00
|
|
|
|
Various changes to awful.util and invaders
This commit changes various aspects of awful.util and invaders:
awful.util:
- added awful.util.getdir(d)
This function takes one argument and returns a matching directory,
as of now, only "cache" is supported. The return value is either
$XDG_CACHE_HOME/awesome/ or $HOME/.cache/awesome/, XDG_CACHE_HOME
takes precedence
invaders:
- renamed invaders to awesome invaders
at two places in the sourcecode, invaders is referred to as
"Space Invaders for Awesome". As Taiko holds the trademark for
the term "Space Invaders", I changed both of its occurences to
"Awesome Invaders" to avoid conflicts with the law of Japan and
the United States of America (and possibly others)
- added support for XDG_CACHE_HOME
this change adds support for XDG_CACHE_HOME as the cache directory
for highscores and screenshots
- added some parameters to invaders.run()
this change adds three parameters to invaders.run, supplied as a
table. They are "x", "y" and "solidbg".
"x" sets the X coordinate of the playfield
"y" sets the Y coordinate of the playfield
"solidbg" sets the color of the playfield background for people who
have problems with transparency. This still looks rather hackish and
needs to be polished
- changed startup position
up until now, invaders always started at (100,100) on the first
screen, now it starts centered to the screen on which the mouse cursor
is.
2008-10-17 19:05:57 +02:00
|
|
|
gamedata.cachedir = awful.util.getdir("cache")
|
|
|
|
|
|
|
|
if gamedata.solidbg then
|
2009-05-05 17:32:53 +02:00
|
|
|
gamedata.field.background = wibox({ bg = gamedata.solidbg })
|
2008-10-27 16:42:02 +01:00
|
|
|
gamedata.field.background:geometry({ x = gamedata.field.x,
|
|
|
|
y = gamedata.field.y,
|
|
|
|
height = gamedata.field.h,
|
|
|
|
width = gamedata.field.w })
|
2009-01-27 20:52:34 +01:00
|
|
|
gamedata.field.background.screen = gamedata.screen
|
Various changes to awful.util and invaders
This commit changes various aspects of awful.util and invaders:
awful.util:
- added awful.util.getdir(d)
This function takes one argument and returns a matching directory,
as of now, only "cache" is supported. The return value is either
$XDG_CACHE_HOME/awesome/ or $HOME/.cache/awesome/, XDG_CACHE_HOME
takes precedence
invaders:
- renamed invaders to awesome invaders
at two places in the sourcecode, invaders is referred to as
"Space Invaders for Awesome". As Taiko holds the trademark for
the term "Space Invaders", I changed both of its occurences to
"Awesome Invaders" to avoid conflicts with the law of Japan and
the United States of America (and possibly others)
- added support for XDG_CACHE_HOME
this change adds support for XDG_CACHE_HOME as the cache directory
for highscores and screenshots
- added some parameters to invaders.run()
this change adds three parameters to invaders.run, supplied as a
table. They are "x", "y" and "solidbg".
"x" sets the X coordinate of the playfield
"y" sets the Y coordinate of the playfield
"solidbg" sets the color of the playfield background for people who
have problems with transparency. This still looks rather hackish and
needs to be polished
- changed startup position
up until now, invaders always started at (100,100) on the first
screen, now it starts centered to the screen on which the mouse cursor
is.
2008-10-17 19:05:57 +02:00
|
|
|
end
|
2008-10-14 18:16:26 +02:00
|
|
|
|
2009-03-20 21:08:12 +01:00
|
|
|
gamedata.field.status = widget({ type = "textbox" })
|
|
|
|
gamedata.field.status.text = gamedata.score.." | "..gamedata.round .. " "
|
|
|
|
|
|
|
|
gamedata.field.caption = widget({ type = "textbox" })
|
|
|
|
gamedata.field.caption.text = " Awesome Invaders"
|
|
|
|
|
2009-05-05 17:32:53 +02:00
|
|
|
gamedata.field.north = wibox({ bg = gamedata.btheme.bg_focus or "#333333",
|
2008-10-27 16:42:02 +01:00
|
|
|
fg = gamedata.btheme.fg_focus or "#FFFFFF" })
|
2008-10-14 18:16:26 +02:00
|
|
|
gamedata.field.north:geometry({ width = gamedata.field.w + 10,
|
2009-03-20 21:08:12 +01:00
|
|
|
height = gamedata.field.caption:extents()["height"],
|
2008-10-27 16:42:02 +01:00
|
|
|
x = gamedata.field.x - 5,
|
2009-03-20 21:08:12 +01:00
|
|
|
y = gamedata.field.y - gamedata.field.caption:extents()["height"] })
|
2009-01-27 20:52:34 +01:00
|
|
|
gamedata.field.north.screen = gamedata.screen
|
2008-10-14 18:16:26 +02:00
|
|
|
|
2009-03-20 21:08:12 +01:00
|
|
|
gamedata.field.north.widgets = {
|
|
|
|
{
|
|
|
|
gamedata.field.caption,
|
|
|
|
["layout"] = awful.widget.layout.horizontal.leftright
|
|
|
|
},
|
|
|
|
{
|
|
|
|
gamedata.field.status,
|
|
|
|
["layout"] = awful.widget.layout.horizontal.rightleft
|
|
|
|
},
|
|
|
|
["layout"] = awful.widget.layout.horizontal.rightleft
|
|
|
|
}
|
2008-10-14 18:16:26 +02:00
|
|
|
|
2009-05-05 17:32:53 +02:00
|
|
|
gamedata.field.south = wibox({ bg = gamedata.btheme.bg_focus or "#333333",
|
2008-10-27 16:42:02 +01:00
|
|
|
fg = gamedata.btheme.fg_focus or "#FFFFFF" })
|
|
|
|
gamedata.field.south:geometry({ width = gamedata.field.w,
|
|
|
|
height = 5,
|
2008-10-14 18:16:26 +02:00
|
|
|
x = gamedata.field.x,
|
|
|
|
y = gamedata.field.y + gamedata.field.h - 5 })
|
2009-01-27 20:52:34 +01:00
|
|
|
gamedata.field.south.screen = gamedata.screen
|
2008-10-14 18:16:26 +02:00
|
|
|
|
2009-05-05 17:32:53 +02:00
|
|
|
gamedata.field.west = wibox({ bg = gamedata.btheme.bg_focus or "#333333",
|
2008-10-27 16:42:02 +01:00
|
|
|
fg = gamedata.btheme.fg_focus or "#FFFFFF" })
|
2008-10-14 21:39:56 +02:00
|
|
|
gamedata.field.west:geometry({ width = 5,
|
2008-10-27 16:42:02 +01:00
|
|
|
height = gamedata.field.h,
|
|
|
|
x = gamedata.field.x - 5,
|
|
|
|
y = gamedata.field.y })
|
2009-01-27 20:52:34 +01:00
|
|
|
gamedata.field.west.screen = gamedata.screen
|
2008-10-14 18:16:26 +02:00
|
|
|
|
2009-05-05 17:32:53 +02:00
|
|
|
gamedata.field.east = wibox({ bg = gamedata.btheme.bg_focus or "#333333",
|
2008-10-27 16:42:02 +01:00
|
|
|
fg = gamedata.btheme.fg_focus or "#FFFFFF" })
|
2008-10-14 18:16:26 +02:00
|
|
|
gamedata.field.east:geometry({ width = 5,
|
|
|
|
height = gamedata.field.h,
|
|
|
|
x = gamedata.field.x + gamedata.field.w,
|
|
|
|
y = gamedata.field.y })
|
2009-01-27 20:52:34 +01:00
|
|
|
gamedata.field.east.screen = gamedata.screen
|
2008-10-14 18:16:26 +02:00
|
|
|
|
|
|
|
gamedata.enemies.speed = 5
|
|
|
|
enemies.setup()
|
|
|
|
|
Various changes to awful.util and invaders
This commit changes various aspects of awful.util and invaders:
awful.util:
- added awful.util.getdir(d)
This function takes one argument and returns a matching directory,
as of now, only "cache" is supported. The return value is either
$XDG_CACHE_HOME/awesome/ or $HOME/.cache/awesome/, XDG_CACHE_HOME
takes precedence
invaders:
- renamed invaders to awesome invaders
at two places in the sourcecode, invaders is referred to as
"Space Invaders for Awesome". As Taiko holds the trademark for
the term "Space Invaders", I changed both of its occurences to
"Awesome Invaders" to avoid conflicts with the law of Japan and
the United States of America (and possibly others)
- added support for XDG_CACHE_HOME
this change adds support for XDG_CACHE_HOME as the cache directory
for highscores and screenshots
- added some parameters to invaders.run()
this change adds three parameters to invaders.run, supplied as a
table. They are "x", "y" and "solidbg".
"x" sets the X coordinate of the playfield
"y" sets the Y coordinate of the playfield
"solidbg" sets the color of the playfield background for people who
have problems with transparency. This still looks rather hackish and
needs to be polished
- changed startup position
up until now, invaders always started at (100,100) on the first
screen, now it starts centered to the screen on which the mouse cursor
is.
2008-10-17 19:05:57 +02:00
|
|
|
gamedata.player = player.new()
|
2008-10-19 19:28:11 +02:00
|
|
|
capi.keygrabber.run(keyhandler)
|
Various changes to awful.util and invaders
This commit changes various aspects of awful.util and invaders:
awful.util:
- added awful.util.getdir(d)
This function takes one argument and returns a matching directory,
as of now, only "cache" is supported. The return value is either
$XDG_CACHE_HOME/awesome/ or $HOME/.cache/awesome/, XDG_CACHE_HOME
takes precedence
invaders:
- renamed invaders to awesome invaders
at two places in the sourcecode, invaders is referred to as
"Space Invaders for Awesome". As Taiko holds the trademark for
the term "Space Invaders", I changed both of its occurences to
"Awesome Invaders" to avoid conflicts with the law of Japan and
the United States of America (and possibly others)
- added support for XDG_CACHE_HOME
this change adds support for XDG_CACHE_HOME as the cache directory
for highscores and screenshots
- added some parameters to invaders.run()
this change adds three parameters to invaders.run, supplied as a
table. They are "x", "y" and "solidbg".
"x" sets the X coordinate of the playfield
"y" sets the Y coordinate of the playfield
"solidbg" sets the color of the playfield background for people who
have problems with transparency. This still looks rather hackish and
needs to be polished
- changed startup position
up until now, invaders always started at (100,100) on the first
screen, now it starts centered to the screen on which the mouse cursor
is.
2008-10-17 19:05:57 +02:00
|
|
|
gamedata.running = true
|
2008-10-14 18:16:26 +02:00
|
|
|
end
|
|
|
|
|
2009-06-30 12:26:39 +02:00
|
|
|
-- Start timers
|
|
|
|
local t = timer { timeout = 0.02 }
|
|
|
|
t:add_signal("timeout", shots.handle)
|
|
|
|
t:start()
|
|
|
|
local t = timer { timeout = 0.03 }
|
|
|
|
t:add_signal("timeout", shots.handle_enemy)
|
|
|
|
t:start()
|
|
|
|
local t = timer { timeout = 0.01 }
|
|
|
|
t:add_signal("timeout", enemies.handle)
|
|
|
|
t:start()
|