From c39fc7792b6567408d8db43730a1187f5ca79b38 Mon Sep 17 00:00:00 2001 From: Eri! Date: Tue, 19 Apr 2011 21:14:56 +0200 Subject: [PATCH 01/57] fixed dirction --- wall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wall.py b/wall.py index c80b611..84a32e0 100644 --- a/wall.py +++ b/wall.py @@ -8,7 +8,7 @@ def init(): s.connect(("172.22.99.6", 1338)) def pixel(x, y, color="ff0000"): - s.send("02%02x%02x%s\r\n" % (16 - x, 15 - y, color)) + s.send("02%02x%02x%s\r\n" % (x + 1, y + 1 , color)) # fixed wrong direction def frame(buf): s.send("03%s\r\n" % buf) From d0c2586b043f66a3841b7486ad54131cf298b2e5 Mon Sep 17 00:00:00 2001 From: Eri! Date: Wed, 29 Jun 2011 00:43:17 +0200 Subject: [PATCH 02/57] random coloured rpxelrain for pentawall --- rain/README.md | 4 +++ rain/conf.lua | 9 ++++++ rain/helper.lua | 1 + rain/main.lua | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ rain/wall.lua | 1 + 5 files changed, 91 insertions(+) create mode 100644 rain/README.md create mode 100644 rain/conf.lua create mode 120000 rain/helper.lua create mode 100644 rain/main.lua create mode 120000 rain/wall.lua diff --git a/rain/README.md b/rain/README.md new file mode 100644 index 0000000..48ea38e --- /dev/null +++ b/rain/README.md @@ -0,0 +1,4 @@ +rain +==== + +Based on Twobit's spalten, this is a simple rain with random coloured pixels. diff --git a/rain/conf.lua b/rain/conf.lua new file mode 100644 index 0000000..5d6c0db --- /dev/null +++ b/rain/conf.lua @@ -0,0 +1,9 @@ +function love.conf(t) + t.title = "coloured_rain" + t.author = "eri!" + t.screen.width = 320 + t.screen.height = 300 + t.screen.vsync = false + t.modules.physics = false + t.modules.mouse = false +end diff --git a/rain/helper.lua b/rain/helper.lua new file mode 120000 index 0000000..039178c --- /dev/null +++ b/rain/helper.lua @@ -0,0 +1 @@ +../lib/helper.lua \ No newline at end of file diff --git a/rain/main.lua b/rain/main.lua new file mode 100644 index 0000000..e65d072 --- /dev/null +++ b/rain/main.lua @@ -0,0 +1,76 @@ +require "helper" +require "wall" + +function love.keypressed(key) + if key == "escape" then + love.event.push "q" + + end + +end + + +function love.load() + wall = Wall("ledwall", 1338, 3) + + time = love.timer.getTime() * 1000 + + tick = 0 + +end + +drops = {} +colours = {"ff0000", "0000ff", "00ff00", "ff00ff", "ffff00", "00ffff"} +fade1 = {"bb0000", "0000bb", "00bb00", "bb00bb", "bbbb00", "00bbbb"} +fade2 = {"770000", "000077", "007700", "770077", "777700", "007777"} +fade3 = {"330000", "000033", "003300", "330033", "333300", "003333"} +fade4 = {"000000", "000000", "000000", "000000", "000000", "000000"} + +function love.update(dt) + -- constant 30 FPS + local t = love.timer.getTime() * 1000 + time = time + 1000 / 30 + love.timer.sleep(time - t) + + if math.random(2) == 1 then + local drop = { + x = math.random(0, 15), + y = 0, + colour + } + drop.colour = math.random(1, 6) + table.insert(drops, drop) + end + + for i, drop in ipairs(drops) do + drop.y = drop.y + 1 + if drop.y > 18 then + table.remove(drops, i) + end + end + + +end + +function drop() + + for i, drop in ipairs(drops) do + local y = math.floor(drop.y) + wall:pixel(drop.x, y, colours[drop.colour]) + wall:pixel(drop.x, y - 1, fade1[drop.colour]) + wall:pixel(drop.x, y - 2, fade2[drop.colour]) + wall:pixel(drop.x, y - 3, fade3[drop.colour]) + wall:pixel(drop.x, y - 4, fade4[drop.colour]) + end + +end + +function love.draw() + + drop() + -- send the stuff abroad + wall:draw() +end + + + diff --git a/rain/wall.lua b/rain/wall.lua new file mode 120000 index 0000000..d37ae93 --- /dev/null +++ b/rain/wall.lua @@ -0,0 +1 @@ +../lib/wall.lua \ No newline at end of file From 5bab915ac318df16be08992c8bce2c984fb93c90 Mon Sep 17 00:00:00 2001 From: Eri! Date: Mon, 1 Aug 2011 21:07:29 +0200 Subject: [PATCH 03/57] README: s/twobit/2bt/ --- rain/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rain/README.md b/rain/README.md index 48ea38e..8882ca3 100644 --- a/rain/README.md +++ b/rain/README.md @@ -1,4 +1,4 @@ rain ==== - -Based on Twobit's spalten, this is a simple rain with random coloured pixels. + +Based on 2bt's spalten, this is a simple rain with random coloured pixels. From a9bae233b151e2663c9a4ad678b19305808b1629 Mon Sep 17 00:00:00 2001 From: dodo Date: Tue, 13 Sep 2011 22:21:51 +0200 Subject: [PATCH 04/57] fullscreen spalten --- spalten/draw.lua | 12 ++++++------ spalten/field.lua | 42 ++++++++++++++++++++++-------------------- spalten/main.lua | 4 ++-- 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/spalten/draw.lua b/spalten/draw.lua index 02484f6..855314f 100644 --- a/spalten/draw.lua +++ b/spalten/draw.lua @@ -14,9 +14,9 @@ gem_colors[6] = "00bbbb" function Field:draw() - for y = 0, 14 do + for y = 0, self.height+1 do local row = self.grid[y] or {} - for x = 0, 7 do + for x = 0, self.width+1 do local gem = row[x] if self.state == "normal" and y > 0 and x == self.x then @@ -25,7 +25,7 @@ function Field:draw() end local color = gem and gem_colors[gem] or "888888" - wall:pixel(self.pos + x, y, color) + wall:pixel(self.pos + x-1, y-1, color) end end @@ -34,15 +34,15 @@ function Field:draw() for _, coords in pairs(self.gems_in_line) do local color = ({ "ffffff", "000000" })[self.state_delay % 3 + 1] if color then - wall:pixel(self.pos + coords.x, coords.y, color) + wall:pixel(self.pos + coords.x-1, coords.y-1, color) end end end -- draw score local score = self.score - local y = 13 - local x = self.pos == 0 and 7 or self.pos + local y = self.height + local x = self.pos == 0 and self.width or self.pos-1 while score > 0 and y >= 0 do if score % 2 > 0 then wall:pixel(x, y, "aaaaaa") diff --git a/spalten/field.lua b/spalten/field.lua index 32c0de0..3143bd0 100644 --- a/spalten/field.lua +++ b/spalten/field.lua @@ -6,12 +6,14 @@ require "draw" function Field:init(pos, key_state) self.pos = pos self.key_state = key_state + self.height = 15 + self.width = 7 -- init clear grid self.grid = {} - for i = 1, 13 do + for i = 1, self.height do local row = {} - for j = 1, 6 do + for j = 1, self.width do row[j] = 0 end self.grid[i] = row @@ -58,7 +60,7 @@ end function Field:newColumn() - self.x = 3 + self.x = 4 self.y = 1 self.column[1] = math.random(self.level) self.column[2] = math.random(self.level) @@ -77,7 +79,7 @@ end function Field:collision() - if self.x < 1 or self.x > 6 or self.y > 13 then + if self.x < 1 or self.x > self.width or self.y > self.height then return true end for y = math.max(1, self.y - 2), self.y do @@ -92,9 +94,9 @@ end function Field:collapse() local grid = self.grid local ret = false - for x = 1, 6 do + for x = 1, self.width do local drop = false - for y = 13, 1, -1 do + for y = self.height, 1, -1 do drop = drop or grid[y][x] == 0 if drop then grid[y][x] = grid[y - 1] and grid[y - 1][x] or 0 @@ -203,8 +205,8 @@ function Field:update() -- lower the field self.current_raise = self.current_raise - 1 - for x = 1, 6 do - for y = 13, 2, -1 do + for x = 1, self.width do + for y = self.height, 2, -1 do self.grid[y][x] = self.grid[y - 1][x] end self.grid[1][x] = 0 @@ -215,15 +217,15 @@ function Field:update() -- raise the field self.current_raise = self.current_raise + 1 self.state_delay = 2 - for x = 1, 6 do + for x = 1, self.width do if self.grid[1][x] > 0 then self.state = "over" self.state_delay = 30 end - for y = 1, 12 do + for y = 1, self.height-1 do self.grid[y][x] = self.grid[y + 1][x] end - self.grid[13][x] = -1 + self.grid[self.height][x] = -1 end else @@ -250,12 +252,12 @@ function Field:findGemsInLine() local grid = self.grid local function addGem(x, y) - self.gems_in_line[y .. " " .. x] = { x = x, y = y } + self.gems_in_line[y .. " " .. x] = { x = x, y = y } end -- [-] check - for y = 1, 13 do - for x = 1, 4 do + for y = 1, self.height do + for x = 1, self.width-2 do if grid[y][x] > 0 and grid[y][x] == grid[y][x + 1] and grid[y][x] == grid[y][x + 2] then @@ -267,8 +269,8 @@ function Field:findGemsInLine() end end -- [|] check - for x = 1, 6 do - for y = 1, 11 do + for x = 1, self.width do + for y = 1, self.height-2 do if grid[y][x] > 0 and grid[y][x] == grid[y + 1][x] and grid[y][x] == grid[y + 2][x] then @@ -280,8 +282,8 @@ function Field:findGemsInLine() end end -- [\] check - for y = 1, 11 do - for x = 1, 4 do + for y = 1, self.height-2 do + for x = 1, self.width-2 do if grid[y][x] > 0 and grid[y][x] == grid[y + 1][x + 1] and grid[y][x] == grid[y + 2][x + 2] then @@ -293,8 +295,8 @@ function Field:findGemsInLine() end end -- [/] check - for y = 1, 11 do - for x = 3, 6 do + for y = 1, self.height-2 do + for x = 3, self.width do if grid[y][x] > 0 and grid[y][x] == grid[y + 1][x - 1] and grid[y][x] == grid[y + 2][x - 2] then diff --git a/spalten/main.lua b/spalten/main.lua index d3a370e..4e7c662 100644 --- a/spalten/main.lua +++ b/spalten/main.lua @@ -24,11 +24,11 @@ function love.load() math.randomseed(os.time()) time = love.timer.getTime() * 1000 - wall = Wall("localhost", 1338, 3, true) + wall = Wall("ledwall", 1338, 3, false) fields = { Field(0, wall.input[1]), - Field(8, false), -- bot + Field(9, false), -- bot } fields[1]:setOpponent(fields[2]) From 50e551174272ab47ab029b4be467dbe86a4f3d23 Mon Sep 17 00:00:00 2001 From: dodo Date: Tue, 13 Sep 2011 22:24:39 +0200 Subject: [PATCH 05/57] balken: 3D spalten fork --- balken/.field.lua.kate-swp | Bin 0 -> 50 bytes balken/.wall.lua.kate-swp | Bin 0 -> 47 bytes balken/README.md | 4 + balken/bot.lua | 132 ++++++++++++++++ balken/conf.lua | 9 ++ balken/draw.lua | 55 +++++++ balken/field.lua | 316 +++++++++++++++++++++++++++++++++++++ balken/helper.lua | 1 + balken/lust.lua | 1 + balken/main.lua | 71 +++++++++ balken/wall.lua | 1 + 11 files changed, 590 insertions(+) create mode 100644 balken/.field.lua.kate-swp create mode 100644 balken/.wall.lua.kate-swp create mode 100644 balken/README.md create mode 100644 balken/bot.lua create mode 100644 balken/conf.lua create mode 100644 balken/draw.lua create mode 100644 balken/field.lua create mode 120000 balken/helper.lua create mode 120000 balken/lust.lua create mode 100644 balken/main.lua create mode 120000 balken/wall.lua diff --git a/balken/.field.lua.kate-swp b/balken/.field.lua.kate-swp new file mode 100644 index 0000000000000000000000000000000000000000..416c429978234ef4b250fce185a28144e6b32cf1 GIT binary patch literal 50 zcmZQzV36@nEJ;-eE>A2_aLdd|RnS!kOD!tS%+FIW)H4VUXJBBk1!6we;7}lC=L!Hq C77Jtm literal 0 HcmV?d00001 diff --git a/balken/.wall.lua.kate-swp b/balken/.wall.lua.kate-swp new file mode 100644 index 0000000000000000000000000000000000000000..67f50f33abe2ccd2250e695a72d2d75442ed1a88 GIT binary patch literal 47 ycmZQzV36@nEJ;-eE>A2_aLdd|RnS!kOD!tS%+FIW)H4VUVqjoM17Z+hb_D<)Sqf4B literal 0 HcmV?d00001 diff --git a/balken/README.md b/balken/README.md new file mode 100644 index 0000000..ace1748 --- /dev/null +++ b/balken/README.md @@ -0,0 +1,4 @@ +balken +======= + +3D spalten :) diff --git a/balken/bot.lua b/balken/bot.lua new file mode 100644 index 0000000..746feaa --- /dev/null +++ b/balken/bot.lua @@ -0,0 +1,132 @@ + + +function Field:getInput() + + local key_down = {} + if self.key_state then + -- human + key_down.right = self.key_state.right + key_down.left = self.key_state.left + key_down.down = self.key_state.down + key_down.rot = self.key_state.a + + else + -- bot + key_down = self:bot() + end + + local events = {} + local dx = bool[key_down.right] - bool[key_down.left] + if dx ~= self.input.dx then + self.input.rep = 0 + end + self.input.dx = dx + self.input.rep = self.input.rep - 1 + if self.input.rep <= 0 then + events.dx = dx + self.input.rep = 3 + else + events.dx = 0 + end + events.down = key_down.down + events.rot = key_down.rot and not self.input.rot + self.input.rot = key_down.rot + + return events +end + + +function Field:bot() + + -- stateless bot - very inefficient, but it kinda works + -- go through all moves, choose the 'best' + + local save_x = self.x + local save_y = self.y + + local moves = {} + -- do nothing if no move can be found + moves[0] = { + { x = self.x, rot = 0 } + } + + for rot = 0, 2 do + for x = 1, 6 do + self.x = x + self.y = save_y + if not self:collision() then + repeat + self.y = self.y + 1 + until self:collision() + self.y = self.y - 1 + if self.y >= 3 then + self:pushColumn() + + self:findGemsInLine() + local magic = self.combo_count * 4 + for y2 = 1, 13 do + if math.max(unpack(self.grid[y2])) > 0 then + magic = magic + y2 + break + end + end + + if not moves[magic] then + moves[magic] = {} + end + table.insert(moves[magic], { x = x, rot = rot }) + + self.gems_in_line = {} + self.combo_count = 0 + + + -- reverse the push + self.grid[self.y][self.x] = 0 + self.grid[self.y - 1][self.x] = 0 + self.grid[self.y - 2][self.x] = 0 + end + + end + end + + -- rotate + local c = self.column + c[1], c[2], c[3] = c[3], c[1], c[2] + end + self.x = save_x + self.y = save_y + + -- select any of the best moves + local max_magic = 0 + for i, l in pairs(moves) do + if i > max_magic then + max_magic = i + end + end + + local best_move = moves[max_magic][1] + for _, move in ipairs(moves[max_magic]) do + if math.abs(move.x - self.x) < math.abs(best_move.x - self.x) then + best_move = move + end + end + + local key_down = {} + + -- easy bot + key_down.left = self.x > best_move.x and math.random(10) == 1 + key_down.right = self.x < best_move.x and math.random(10) == 1 + key_down.down = self.x == best_move.x and self.y > math.random(10) + key_down.rot = best_move.rot > 0 and math.random(3) == 1 + +--[[ + -- fast bot + key_down.left = self.x > best_move.x + key_down.right = self.x < best_move.x + key_down.down = self.x == best_move.x or math.random(3) == 1 + key_down.rot = best_move.rot > 0 and math.random(2) == 1 +--]] + + return key_down +end + diff --git a/balken/conf.lua b/balken/conf.lua new file mode 100644 index 0000000..b031537 --- /dev/null +++ b/balken/conf.lua @@ -0,0 +1,9 @@ +function love.conf(t) + t.title = "spalten" + t.author = "twobit" + t.screen.width = 320 + t.screen.height = 300 + t.screen.vsync = false + t.modules.physics = false + t.modules.mouse = false +end diff --git a/balken/draw.lua b/balken/draw.lua new file mode 100644 index 0000000..855314f --- /dev/null +++ b/balken/draw.lua @@ -0,0 +1,55 @@ + +local gem_colors = {} + +gem_colors[-1] = "555555" -- brick +gem_colors[0] = "000000" -- background + +gem_colors[1] = "bb2200" +gem_colors[2] = "00aabb" +gem_colors[3] = "00bb00" +gem_colors[4] = "bbbb00" +gem_colors[5] = "8800bb" +gem_colors[6] = "00bbbb" + + +function Field:draw() + + for y = 0, self.height+1 do + local row = self.grid[y] or {} + for x = 0, self.width+1 do + + local gem = row[x] + if self.state == "normal" and y > 0 and x == self.x then + -- also draw active column + gem = self.column[self.y - y + 1] or gem + end + + local color = gem and gem_colors[gem] or "888888" + wall:pixel(self.pos + x-1, y-1, color) + end + end + + -- draw flashing gems + if self.state == "highlight" then + for _, coords in pairs(self.gems_in_line) do + local color = ({ "ffffff", "000000" })[self.state_delay % 3 + 1] + if color then + wall:pixel(self.pos + coords.x-1, coords.y-1, color) + end + end + end + + -- draw score + local score = self.score + local y = self.height + local x = self.pos == 0 and self.width or self.pos-1 + while score > 0 and y >= 0 do + if score % 2 > 0 then + wall:pixel(x, y, "aaaaaa") + end + score = math.floor(score / 2) + y = y - 1 + end +end + + diff --git a/balken/field.lua b/balken/field.lua new file mode 100644 index 0000000..3143bd0 --- /dev/null +++ b/balken/field.lua @@ -0,0 +1,316 @@ +Field = Object:new() + +require "bot" +require "draw" + +function Field:init(pos, key_state) + self.pos = pos + self.key_state = key_state + self.height = 15 + self.width = 7 + + -- init clear grid + self.grid = {} + for i = 1, self.height do + local row = {} + for j = 1, self.width do + row[j] = 0 + end + self.grid[i] = row + end + + -- how many different sorts of gems + self.level = 5 + -- inverse dropping speed + self.drop_delay = 20 + + self.score = 0 + self.drop_count = 0 + self.combo_count = 0 + + self.column = {} + self:newColumn() + + self.state = "normal" + self.state_delay = 0 + + self.gems_in_line = {} + self.opponent = nil + + self.raise = 0 + self.current_raise = 0 + + self.input = { dx = 0, rep = 0 } + +end + + +function Field:setOpponent(opponent) + self.opponent = opponent +end + + +function Field:raiseField(count) + self.raise = self.raise + count + if self.state == "normal" then + self.state = "wait" + self.state_delay = 10 + end +end + + +function Field:newColumn() + self.x = 4 + self.y = 1 + self.column[1] = math.random(self.level) + self.column[2] = math.random(self.level) + self.column[3] = math.random(self.level) +end + + +function Field:pushColumn() + for y = 1, 3 do + if self.y - y + 1 > 0 then + self.grid[self.y - y + 1][self.x] = self.column[y] + end + end +end + + + +function Field:collision() + if self.x < 1 or self.x > self.width or self.y > self.height then + return true + end + for y = math.max(1, self.y - 2), self.y do + if self.grid[y][self.x] ~= 0 then + return true + end + end + return false +end + + +function Field:collapse() + local grid = self.grid + local ret = false + for x = 1, self.width do + local drop = false + for y = self.height, 1, -1 do + drop = drop or grid[y][x] == 0 + if drop then + grid[y][x] = grid[y - 1] and grid[y - 1][x] or 0 + ret = grid[y][x] > 0 or ret + end + end + end + return ret +end + + +function Field:update() + + self.state_delay = self.state_delay - 1 + if self.state == "normal" then + + local events = self:getInput() + + if events.rot then + local c = self.column + c[1], c[2], c[3] = c[3], c[1], c[2] + end + -- x-movement + if events.dx ~= 0 then + local x = self.x + self.x = self.x + events.dx + if self:collision() then + self.x = x + end + end + -- y-movement + self.drop_count = self.drop_count + 1 + local y = self.y + if events.down or self.drop_count >= self.drop_delay then + self.y = self.y + 1 + self.drop_count = 0 + end + if self:collision() then + self.y = y + + self:pushColumn() + if self.y < 3 then + self.state = "over" + self.state_delay = 30 + else + -- check for gems to be removed from the grid + self.combo_count = 0 + if self:findGemsInLine() then + self.state = "highlight" + self.state_delay = 20 + else + self.state = "wait" + self.state_delay = 10 + end + end + end + + elseif self.state == "highlight" then + if self.state_delay == 0 then + + -- remove gems + for _, coords in pairs(self.gems_in_line) do + self.grid[coords.y][coords.x] = 0 + self.score = self.score + 1 + end + self.gems_in_line = {} + + self.state = "collapse" + self.state_delay = 2 + end + + elseif self.state == "collapse" then + if self.state_delay == 0 then + + if self:collapse() then + -- keep collapsing + self.state_delay = 2 + else + if self:findGemsInLine() then + self.state = "highlight" + self.state_delay = 20 + else + self.state = "wait" + self.state_delay = 10 + + -- initiate lowering of one's field + -- and raising of opponent's field + if self.combo_count > 1 then + self.raise = self.raise - (self.combo_count - 1) + if self.raise < 0 then + if self.opponent then + self.opponent:raiseField(-self.raise) + end + self.raise = 0 + end + end + + end + end + end + + elseif self.state == "wait" then + if self.state_delay == 0 then + + if self.current_raise > self.raise then + -- lower the field + self.current_raise = self.current_raise - 1 + + for x = 1, self.width do + for y = self.height, 2, -1 do + self.grid[y][x] = self.grid[y - 1][x] + end + self.grid[1][x] = 0 + end + self.state_delay = 2 + + elseif self.current_raise < self.raise then + -- raise the field + self.current_raise = self.current_raise + 1 + self.state_delay = 2 + for x = 1, self.width do + if self.grid[1][x] > 0 then + self.state = "over" + self.state_delay = 30 + end + for y = 1, self.height-1 do + self.grid[y][x] = self.grid[y + 1][x] + end + self.grid[self.height][x] = -1 + end + + else + self:newColumn() + self.state = "normal" + end + end + + elseif self.state == "over" then + -- TODO + + if self.state_delay == 0 then + love.event.push "q" + end + + end +end + + +function Field:findGemsInLine() + + -- TODO: make the code look nicer + + local grid = self.grid + + local function addGem(x, y) + self.gems_in_line[y .. " " .. x] = { x = x, y = y } + end + + -- [-] check + for y = 1, self.height do + for x = 1, self.width-2 do + if grid[y][x] > 0 and + grid[y][x] == grid[y][x + 1] and + grid[y][x] == grid[y][x + 2] then + addGem(x, y) + addGem(x + 1, y) + addGem(x + 2, y) + self.combo_count = self.combo_count + 1 + end + end + end + -- [|] check + for x = 1, self.width do + for y = 1, self.height-2 do + if grid[y][x] > 0 and + grid[y][x] == grid[y + 1][x] and + grid[y][x] == grid[y + 2][x] then + addGem(x, y) + addGem(x, y + 1) + addGem(x, y + 2) + self.combo_count = self.combo_count + 1 + end + end + end + -- [\] check + for y = 1, self.height-2 do + for x = 1, self.width-2 do + if grid[y][x] > 0 and + grid[y][x] == grid[y + 1][x + 1] and + grid[y][x] == grid[y + 2][x + 2] then + addGem(x, y) + addGem(x + 1, y + 1) + addGem(x + 2, y + 2) + self.combo_count = self.combo_count + 1 + end + end + end + -- [/] check + for y = 1, self.height-2 do + for x = 3, self.width do + if grid[y][x] > 0 and + grid[y][x] == grid[y + 1][x - 1] and + grid[y][x] == grid[y + 2][x - 2] then + addGem(x, y) + addGem(x - 1, y + 1) + addGem(x - 2, y + 2) + self.combo_count = self.combo_count + 1 + end + end + end + + -- return true if we found something + return next(self.gems_in_line) ~= nil +end + + + diff --git a/balken/helper.lua b/balken/helper.lua new file mode 120000 index 0000000..039178c --- /dev/null +++ b/balken/helper.lua @@ -0,0 +1 @@ +../lib/helper.lua \ No newline at end of file diff --git a/balken/lust.lua b/balken/lust.lua new file mode 120000 index 0000000..f6e54d1 --- /dev/null +++ b/balken/lust.lua @@ -0,0 +1 @@ +../lib/lust.lua \ No newline at end of file diff --git a/balken/main.lua b/balken/main.lua new file mode 100644 index 0000000..4e7c662 --- /dev/null +++ b/balken/main.lua @@ -0,0 +1,71 @@ +require "helper" +require "wall" +require "field" + + +function love.keypressed(key) + if key == "escape" then + love.event.push "q" + + elseif key == "f1" then + wall:record(true) + print("recording...") + + elseif key == "f2" then + wall:record(false) + print("recording stopped") + + end +end + + + +function love.load() + math.randomseed(os.time()) + time = love.timer.getTime() * 1000 + + wall = Wall("ledwall", 1338, 3, false) + + fields = { + Field(0, wall.input[1]), + Field(9, false), -- bot + } + + fields[1]:setOpponent(fields[2]) + fields[2]:setOpponent(fields[1]) + +end + + +function love.update(dt) + -- constant 30 FPS + local t = love.timer.getTime() * 1000 + time = time + 1000 / 30 + love.timer.sleep(time - t) + + wall:update_input() + + -- allow 2nd player to join + if not fields[2].key_state then + if wall.input[2].a then + fields[2].key_state = wall.input[2] + end + end + + fields[1]:update() + fields[2]:update() + +end + + +function love.draw() + + fields[1]:draw() + fields[2]:draw() + + -- send the stuff abroad + wall:draw() +end + + + diff --git a/balken/wall.lua b/balken/wall.lua new file mode 120000 index 0000000..d37ae93 --- /dev/null +++ b/balken/wall.lua @@ -0,0 +1 @@ +../lib/wall.lua \ No newline at end of file From ecb32afb06b88d0aa38ee812ec5e114ca08ec894 Mon Sep 17 00:00:00 2001 From: dodo Date: Tue, 13 Sep 2011 23:08:40 +0200 Subject: [PATCH 06/57] swap the swp --- .gitignore | 1 + balken/.field.lua.kate-swp | Bin 50 -> 0 bytes balken/.wall.lua.kate-swp | Bin 47 -> 0 bytes 3 files changed, 1 insertion(+) delete mode 100644 balken/.field.lua.kate-swp delete mode 100644 balken/.wall.lua.kate-swp diff --git a/.gitignore b/.gitignore index 0d20b64..6927e76 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.pyc +*swp diff --git a/balken/.field.lua.kate-swp b/balken/.field.lua.kate-swp deleted file mode 100644 index 416c429978234ef4b250fce185a28144e6b32cf1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 50 zcmZQzV36@nEJ;-eE>A2_aLdd|RnS!kOD!tS%+FIW)H4VUXJBBk1!6we;7}lC=L!Hq C77Jtm diff --git a/balken/.wall.lua.kate-swp b/balken/.wall.lua.kate-swp deleted file mode 100644 index 67f50f33abe2ccd2250e695a72d2d75442ed1a88..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 47 ycmZQzV36@nEJ;-eE>A2_aLdd|RnS!kOD!tS%+FIW)H4VUVqjoM17Z+hb_D<)Sqf4B From b96338ca661c1843cd01f3cb2ea33f28bf48e02e Mon Sep 17 00:00:00 2001 From: dodo Date: Wed, 14 Sep 2011 02:35:53 +0200 Subject: [PATCH 07/57] 3:D --- balken/bot.lua | 8 ++-- balken/draw.lua | 88 ++++++++++++++++++++++++++++++++++---------- balken/field.lua | 96 +++++++++++++++++++++++++++--------------------- 3 files changed, 127 insertions(+), 65 deletions(-) diff --git a/balken/bot.lua b/balken/bot.lua index 746feaa..2d14a00 100644 --- a/balken/bot.lua +++ b/balken/bot.lua @@ -65,7 +65,7 @@ function Field:bot() self:findGemsInLine() local magic = self.combo_count * 4 for y2 = 1, 13 do - if math.max(unpack(self.grid[y2])) > 0 then + if math.max(unpack(self.grid[self.layer][y2])) > 0 then magic = magic + y2 break end @@ -81,9 +81,9 @@ function Field:bot() -- reverse the push - self.grid[self.y][self.x] = 0 - self.grid[self.y - 1][self.x] = 0 - self.grid[self.y - 2][self.x] = 0 + self.grid[self.layer][self.y][self.x] = 0 + self.grid[self.layer][self.y - 1][self.x] = 0 + self.grid[self.layer][self.y - 2][self.x] = 0 end end diff --git a/balken/draw.lua b/balken/draw.lua index 855314f..b24bc66 100644 --- a/balken/draw.lua +++ b/balken/draw.lua @@ -1,33 +1,81 @@ +local string = string +local floor = math.floor + + local gem_colors = {} +gem_colors[-2] = {136, 136, 136} -- border +gem_colors[-1] = { 85, 85, 85} -- brick +gem_colors[0] = { 0, 0, 0} -- background -gem_colors[-1] = "555555" -- brick -gem_colors[0] = "000000" -- background +gem_colors[1] = {187, 34, 0} +gem_colors[2] = { 0, 170, 187} +gem_colors[3] = { 0, 187, 0} +gem_colors[4] = {187, 187, 0} +gem_colors[5] = {136, 0, 187} +gem_colors[6] = { 0, 187, 187} -gem_colors[1] = "bb2200" -gem_colors[2] = "00aabb" -gem_colors[3] = "00bb00" -gem_colors[4] = "bbbb00" -gem_colors[5] = "8800bb" -gem_colors[6] = "00bbbb" +local function Color(c) + return string.format("%02X%02X%02X", floor(c[1]), floor(c[2]), floor(c[3])) +end function Field:draw() - for y = 0, self.height+1 do - local row = self.grid[y] or {} - for x = 0, self.width+1 do + local layer = self.layer + if self.state ~= "normal" then + layer = (layer - 1) % self.width + 1 + end - local gem = row[x] - if self.state == "normal" and y > 0 and x == self.x then - -- also draw active column - gem = self.column[self.y - y + 1] or gem - end + local g = {} + for i = 0, self.height+1 do + local row = {} + for j = 0, self.width+1 do + row[j] = {} + for i, col in ipairs(gem_colors[0]) do + row[j][i] = col + end + end + g[i] = row + end - local color = gem and gem_colors[gem] or "888888" - wall:pixel(self.pos + x-1, y-1, color) - end - end + for _z = 0, self.width+1 do + local z = ((self.width - _z) + layer) % self.width + 1 + for y = 0, self.height+1 do + local row = self.grid[z][y] or {} + for x = 0, self.width+1 do + + local gem = row[x] + if self.state == "normal" and y > 0 and x == self.x then + -- also draw active column + gem = self.column[self.y - y + 1] or gem + end + local is_empty = + g[y][x][1] == gem_colors[0][1] and + g[y][x][2] == gem_colors[0][2] and + g[y][x][3] == gem_colors[0][3] + gem = gem or -2 + for i, col in ipairs(gem_colors[gem]) do + if is_empty or gem ~= 0 then + g[y][x][i] = col * _z/(self.width+1) + if gem ~= -2 then + g[y][x][i] = g[y][x][i] * ( + (z == layer or + (x==self.x and + y>=self.y-2 and + y<=self.y)) and + 1 or 0.3) + end + end + end + end + end + end + for y = 0, self.height+1 do + for x = 0, self.width+1 do + wall:pixel(self.pos + x-1, y-1, Color(g[y][x])) + end + end -- draw flashing gems if self.state == "highlight" then diff --git a/balken/field.lua b/balken/field.lua index 3143bd0..8ea7eea 100644 --- a/balken/field.lua +++ b/balken/field.lua @@ -11,19 +11,26 @@ function Field:init(pos, key_state) -- init clear grid self.grid = {} - for i = 1, self.height do - local row = {} - for j = 1, self.width do - row[j] = 0 - end - self.grid[i] = row - end + for h = 1, self.width do + local layer = {} + for i = 1, self.height do + local row = {} + for j = 1, self.width do + row[j] = 0 + end + layer[i] = row + end + self.grid[h] = layer + end -- how many different sorts of gems self.level = 5 -- inverse dropping speed self.drop_delay = 20 + -- start layer - 1 + self.layer = 0 + self.score = 0 self.drop_count = 0 self.combo_count = 0 @@ -60,6 +67,7 @@ end function Field:newColumn() + self.layer = (self.layer + 1) % self.width + 1 self.x = 4 self.y = 1 self.column[1] = math.random(self.level) @@ -71,7 +79,7 @@ end function Field:pushColumn() for y = 1, 3 do if self.y - y + 1 > 0 then - self.grid[self.y - y + 1][self.x] = self.column[y] + self.grid[self.layer][self.y - y + 1][self.x] = self.column[y] end end end @@ -83,7 +91,7 @@ function Field:collision() return true end for y = math.max(1, self.y - 2), self.y do - if self.grid[y][self.x] ~= 0 then + if self.grid[self.layer][y][self.x] ~= 0 then return true end end @@ -94,13 +102,14 @@ end function Field:collapse() local grid = self.grid local ret = false + local z = self.layer for x = 1, self.width do local drop = false for y = self.height, 1, -1 do - drop = drop or grid[y][x] == 0 + drop = drop or grid[z][y][x] == 0 if drop then - grid[y][x] = grid[y - 1] and grid[y - 1][x] or 0 - ret = grid[y][x] > 0 or ret + grid[z][y][x] = grid[z][y - 1] and grid[z][y - 1][x] or 0 + ret = grid[z][y][x] > 0 or ret end end end @@ -159,7 +168,7 @@ function Field:update() -- remove gems for _, coords in pairs(self.gems_in_line) do - self.grid[coords.y][coords.x] = 0 + self.grid[self.layer][coords.y][coords.x] = 0 self.score = self.score + 1 end self.gems_in_line = {} @@ -205,28 +214,32 @@ function Field:update() -- lower the field self.current_raise = self.current_raise - 1 - for x = 1, self.width do - for y = self.height, 2, -1 do - self.grid[y][x] = self.grid[y - 1][x] - end - self.grid[1][x] = 0 - end + for z = 1, self.width do + for x = 1, self.width do + for y = self.height, 2, -1 do + self.grid[z][y][x] = self.grid[z][y - 1][x] + end + self.grid[z][1][x] = 0 + end + end self.state_delay = 2 elseif self.current_raise < self.raise then -- raise the field self.current_raise = self.current_raise + 1 self.state_delay = 2 - for x = 1, self.width do - if self.grid[1][x] > 0 then - self.state = "over" - self.state_delay = 30 - end - for y = 1, self.height-1 do - self.grid[y][x] = self.grid[y + 1][x] - end - self.grid[self.height][x] = -1 - end + for z = 1, self.width do + for x = 1, self.width do + if self.grid[z][1][x] > 0 then + self.state = "over" + self.state_delay = 30 + end + for y = 1, self.height-1 do + self.grid[z][y][x] = self.grid[z][y + 1][x] + end + self.grid[z][self.height][x] = -1 + end + end else self:newColumn() @@ -250,6 +263,7 @@ function Field:findGemsInLine() -- TODO: make the code look nicer local grid = self.grid + local z = self.layer local function addGem(x, y) self.gems_in_line[y .. " " .. x] = { x = x, y = y } @@ -258,9 +272,9 @@ function Field:findGemsInLine() -- [-] check for y = 1, self.height do for x = 1, self.width-2 do - if grid[y][x] > 0 and - grid[y][x] == grid[y][x + 1] and - grid[y][x] == grid[y][x + 2] then + if grid[z][y][x] > 0 and + grid[z][y][x] == grid[z][y][x + 1] and + grid[z][y][x] == grid[z][y][x + 2] then addGem(x, y) addGem(x + 1, y) addGem(x + 2, y) @@ -271,9 +285,9 @@ function Field:findGemsInLine() -- [|] check for x = 1, self.width do for y = 1, self.height-2 do - if grid[y][x] > 0 and - grid[y][x] == grid[y + 1][x] and - grid[y][x] == grid[y + 2][x] then + if grid[z][y][x] > 0 and + grid[z][y][x] == grid[z][y + 1][x] and + grid[z][y][x] == grid[z][y + 2][x] then addGem(x, y) addGem(x, y + 1) addGem(x, y + 2) @@ -284,9 +298,9 @@ function Field:findGemsInLine() -- [\] check for y = 1, self.height-2 do for x = 1, self.width-2 do - if grid[y][x] > 0 and - grid[y][x] == grid[y + 1][x + 1] and - grid[y][x] == grid[y + 2][x + 2] then + if grid[z][y][x] > 0 and + grid[z][y][x] == grid[z][y + 1][x + 1] and + grid[z][y][x] == grid[z][y + 2][x + 2] then addGem(x, y) addGem(x + 1, y + 1) addGem(x + 2, y + 2) @@ -297,9 +311,9 @@ function Field:findGemsInLine() -- [/] check for y = 1, self.height-2 do for x = 3, self.width do - if grid[y][x] > 0 and - grid[y][x] == grid[y + 1][x - 1] and - grid[y][x] == grid[y + 2][x - 2] then + if grid[z][y][x] > 0 and + grid[z][y][x] == grid[z][y + 1][x - 1] and + grid[z][y][x] == grid[z][y + 2][x - 2] then addGem(x, y) addGem(x - 1, y + 1) addGem(x - 2, y + 2) From ea89065b753c6b1c3b376698a70d68bcf729037c Mon Sep 17 00:00:00 2001 From: eri451 Date: Mon, 21 Nov 2011 08:14:33 +0100 Subject: [PATCH 08/57] variable dropspeed --- rain/main.lua | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/rain/main.lua b/rain/main.lua index e65d072..f3effc1 100644 --- a/rain/main.lua +++ b/rain/main.lua @@ -35,6 +35,7 @@ function love.update(dt) if math.random(2) == 1 then local drop = { x = math.random(0, 15), + dy = dy(), y = 0, colour } @@ -42,11 +43,23 @@ function love.update(dt) table.insert(drops, drop) end + function dy() + dy = math.random() + if dy >= 0.4 then + return dy + else + return 1 + end + end + for i, drop in ipairs(drops) do - drop.y = drop.y + 1 - if drop.y > 18 then + drop.y = drop.y + drop.dy + if drop.y > 19 then table.remove(drops, i) end + if i >= 25 then + table.remove(drops, i) + end end From aa5f322dfd5ee07ae799c77f3365fb7251f7e034 Mon Sep 17 00:00:00 2001 From: eri451 Date: Mon, 21 Nov 2011 09:14:24 +0100 Subject: [PATCH 09/57] cleaned indentation --- rain/main.lua | 80 +++++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/rain/main.lua b/rain/main.lua index f3effc1..c4da838 100644 --- a/rain/main.lua +++ b/rain/main.lua @@ -2,19 +2,19 @@ require "helper" require "wall" function love.keypressed(key) - if key == "escape" then - love.event.push "q" - - end - + if key == "escape" then + love.event.push "q" + + end + end function love.load() - wall = Wall("ledwall", 1338, 3) + wall = Wall("ledwall", 1338, 3) + + time = love.timer.getTime() * 1000 - time = love.timer.getTime() * 1000 - tick = 0 end @@ -27,21 +27,21 @@ fade3 = {"330000", "000033", "003300", "330033", "333300", "003333"} fade4 = {"000000", "000000", "000000", "000000", "000000", "000000"} function love.update(dt) - -- constant 30 FPS - local t = love.timer.getTime() * 1000 - time = time + 1000 / 30 - love.timer.sleep(time - t) - - if math.random(2) == 1 then - local drop = { - x = math.random(0, 15), + -- constant 30 FPS + local t = love.timer.getTime() * 1000 + time = time + 1000 / 30 + love.timer.sleep(time - t) + + if math.random(2) == 1 then + local drop = { + x = math.random(0, 15), dy = dy(), - y = 0, - colour - } - drop.colour = math.random(1, 6) - table.insert(drops, drop) - end + y = 0, + colour + } + drop.colour = math.random(1, 6) + table.insert(drops, drop) + end function dy() dy = math.random() @@ -52,37 +52,37 @@ function love.update(dt) end end - for i, drop in ipairs(drops) do - drop.y = drop.y + drop.dy - if drop.y > 19 then - table.remove(drops, i) - end + for i, drop in ipairs(drops) do + drop.y = drop.y + drop.dy + if drop.y > 19 then + table.remove(drops, i) + end if i >= 25 then table.remove(drops, i) end - end + end end function drop() - - for i, drop in ipairs(drops) do - local y = math.floor(drop.y) - wall:pixel(drop.x, y, colours[drop.colour]) - wall:pixel(drop.x, y - 1, fade1[drop.colour]) - wall:pixel(drop.x, y - 2, fade2[drop.colour]) - wall:pixel(drop.x, y - 3, fade3[drop.colour]) - wall:pixel(drop.x, y - 4, fade4[drop.colour]) - end - + + for i, drop in ipairs(drops) do + local y = math.floor(drop.y) + wall:pixel(drop.x, y, colours[drop.colour]) + wall:pixel(drop.x, y - 1, fade1[drop.colour]) + wall:pixel(drop.x, y - 2, fade2[drop.colour]) + wall:pixel(drop.x, y - 3, fade3[drop.colour]) + wall:pixel(drop.x, y - 4, fade4[drop.colour]) + end + end function love.draw() drop() - -- send the stuff abroad - wall:draw() + -- send the stuff abroad + wall:draw() end From f911b382b42f2bf64350dce882d40505ca660595 Mon Sep 17 00:00:00 2001 From: eri451 Date: Tue, 22 Nov 2011 21:40:16 +0100 Subject: [PATCH 10/57] better fade, bg/fg --- rain/main.lua | 60 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/rain/main.lua b/rain/main.lua index c4da838..d5ea0e0 100644 --- a/rain/main.lua +++ b/rain/main.lua @@ -1,6 +1,15 @@ require "helper" require "wall" +function tohex(colour) + return string.format("%.2x%.2x%.2x",unpack(colour)) +end + +function inbound(p) + if p > 1 then p = 1 elseif p < 0 then p = 0 end + return p +end + function love.keypressed(key) if key == "escape" then love.event.push "q" @@ -9,7 +18,6 @@ function love.keypressed(key) end - function love.load() wall = Wall("ledwall", 1338, 3) @@ -20,11 +28,12 @@ function love.load() end drops = {} -colours = {"ff0000", "0000ff", "00ff00", "ff00ff", "ffff00", "00ffff"} -fade1 = {"bb0000", "0000bb", "00bb00", "bb00bb", "bbbb00", "00bbbb"} -fade2 = {"770000", "000077", "007700", "770077", "777700", "007777"} -fade3 = {"330000", "000033", "003300", "330033", "333300", "003333"} -fade4 = {"000000", "000000", "000000", "000000", "000000", "000000"} +-- colours = {"ff0000", "0000ff", "00ff00", "ff00ff", "ffff00", "00ffff"} +colours = { + {255,0,0}, {0,0,255}, {0,255,0}, {255,0,255}, {255,255,0}, {0,255,255}, + fadesteps = 10, + +} function love.update(dt) -- constant 30 FPS @@ -35,11 +44,16 @@ function love.update(dt) if math.random(2) == 1 then local drop = { x = math.random(0, 15), - dy = dy(), + dy = dy(), y = 0, - colour + colour = colours[math.random(1, 6)] } - drop.colour = math.random(1, 6) + local p, r,g,b + r, g, b = unpack(drop.colour) + p = inbound(drop.dy * 1.3) + r, g, b = r*p, g*p, b*p + drop.colour = {r,g,b} + table.insert(drops, drop) end @@ -54,10 +68,10 @@ function love.update(dt) for i, drop in ipairs(drops) do drop.y = drop.y + drop.dy - if drop.y > 19 then + if drop.y > 15 + colours.fadesteps + 1 then table.remove(drops, i) end - if i >= 25 then + if i >= 30 then table.remove(drops, i) end end @@ -66,14 +80,19 @@ function love.update(dt) end function drop() - - for i, drop in ipairs(drops) do + for _, drop in ipairs(drops) do local y = math.floor(drop.y) - wall:pixel(drop.x, y, colours[drop.colour]) - wall:pixel(drop.x, y - 1, fade1[drop.colour]) - wall:pixel(drop.x, y - 2, fade2[drop.colour]) - wall:pixel(drop.x, y - 3, fade3[drop.colour]) - wall:pixel(drop.x, y - 4, fade4[drop.colour]) + --wall:pixel(drop.x, y, colours[drop.colour]) + wall:pixel(drop.x, y, tohex(drop.colour)) + + local p, r,g,b + local steps = colours.fadesteps + for i = steps, 0, -1 do + p = inbound(i * 1/(steps+1)) + r, g, b = unpack(drop.colour) + r, g, b = r*p, g*p, b*p + wall:pixel(drop.x, y - steps + i - 1, tohex({r,g,b})) + end end end @@ -83,7 +102,4 @@ function love.draw() drop() -- send the stuff abroad wall:draw() -end - - - +end \ No newline at end of file From 6b8ac4e0555cf01074670c82f71e93f1f091d293 Mon Sep 17 00:00:00 2001 From: eri451 Date: Tue, 22 Nov 2011 21:58:34 +0100 Subject: [PATCH 11/57] variable drop length --- rain/main.lua | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/rain/main.lua b/rain/main.lua index d5ea0e0..d0c5a63 100644 --- a/rain/main.lua +++ b/rain/main.lua @@ -29,11 +29,7 @@ end drops = {} -- colours = {"ff0000", "0000ff", "00ff00", "ff00ff", "ffff00", "00ffff"} -colours = { - {255,0,0}, {0,0,255}, {0,255,0}, {255,0,255}, {255,255,0}, {0,255,255}, - fadesteps = 10, - -} +colours = {{255,0,0}, {0,0,255}, {0,255,0}, {255,0,255}, {255,255,0}, {0,255,255}} function love.update(dt) -- constant 30 FPS @@ -46,7 +42,8 @@ function love.update(dt) x = math.random(0, 15), dy = dy(), y = 0, - colour = colours[math.random(1, 6)] + colour = colours[math.random(1, 6)], + fadesteps = math.random(4,10), } local p, r,g,b r, g, b = unpack(drop.colour) @@ -68,7 +65,7 @@ function love.update(dt) for i, drop in ipairs(drops) do drop.y = drop.y + drop.dy - if drop.y > 15 + colours.fadesteps + 1 then + if drop.y > 15 + drop.fadesteps + 1 then table.remove(drops, i) end if i >= 30 then @@ -86,7 +83,7 @@ function drop() wall:pixel(drop.x, y, tohex(drop.colour)) local p, r,g,b - local steps = colours.fadesteps + local steps = drop.fadesteps for i = steps, 0, -1 do p = inbound(i * 1/(steps+1)) r, g, b = unpack(drop.colour) From 1c32a611af502128a75710119eeaf469975d88d4 Mon Sep 17 00:00:00 2001 From: dodo Date: Tue, 22 Nov 2011 22:41:57 +0100 Subject: [PATCH 12/57] dont hardcode wall size --- lib/wall.lua | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/wall.lua b/lib/wall.lua index 1634074..b47e72c 100644 --- a/lib/wall.lua +++ b/lib/wall.lua @@ -40,7 +40,11 @@ local local_keys = { function Wall:init(host, port, priority, remote_pads) self.buffer = {} - for i = 1, 15 * 16 do + + self.width = 16 + self.height = 15 + + for i = 1, self.width * self.height do self.buffer[i] = "000000" end @@ -86,8 +90,8 @@ function Wall:record(flag) end function Wall:pixel(x, y, color) - if 0 <= x and x < 16 and 0 <= y and y < 15 then - self.buffer[y * 16 + x + 1] = color + if 0 <= x and x < self.width and 0 <= y and y < self.height then + self.buffer[y * self.width + x + 1] = color end end @@ -135,11 +139,11 @@ function Wall:update_input() end function Wall:draw() - local w = love.graphics.getWidth() / 16 - local h = love.graphics.getHeight() / 15 + local w = love.graphics.getWidth() / self.width + local h = love.graphics.getHeight() / self.height for i, color in ipairs(self.buffer) do - local x = ((i - 1) % 16) * w - local y = math.floor((i - 1) / 16) * h + local x = ((i - 1) % self.width) * w + local y = math.floor((i - 1) / self.width) * h local r, g, b = color:match "(..)(..)(..)" r = tonumber("0x" .. r) g = tonumber("0x" .. g) From 1e835be12135657dffc37bca6fb9572b18c35926 Mon Sep 17 00:00:00 2001 From: dodo Date: Wed, 23 Nov 2011 02:26:21 +0100 Subject: [PATCH 13/57] metablobs --- blob/README.md | 4 + blob/conf.lua | 9 +++ blob/helper.lua | 1 + blob/main.lua | 192 ++++++++++++++++++++++++++++++++++++++++++++++++ blob/wall.lua | 1 + 5 files changed, 207 insertions(+) create mode 100644 blob/README.md create mode 100644 blob/conf.lua create mode 120000 blob/helper.lua create mode 100644 blob/main.lua create mode 120000 blob/wall.lua diff --git a/blob/README.md b/blob/README.md new file mode 100644 index 0000000..788d21b --- /dev/null +++ b/blob/README.md @@ -0,0 +1,4 @@ +blob +==== + +metablobs diff --git a/blob/conf.lua b/blob/conf.lua new file mode 100644 index 0000000..03b925c --- /dev/null +++ b/blob/conf.lua @@ -0,0 +1,9 @@ +function love.conf(t) + t.title = "metablob" + t.author = "dodo" + t.screen.width = 320 + t.screen.height = 300 + t.screen.vsync = false + t.modules.physics = false + t.modules.mouse = false +end diff --git a/blob/helper.lua b/blob/helper.lua new file mode 120000 index 0000000..039178c --- /dev/null +++ b/blob/helper.lua @@ -0,0 +1 @@ +../lib/helper.lua \ No newline at end of file diff --git a/blob/main.lua b/blob/main.lua new file mode 100644 index 0000000..4b4ebb5 --- /dev/null +++ b/blob/main.lua @@ -0,0 +1,192 @@ +require "helper" +require "wall" + +require 'socket' +math.randomseed(socket.gettime()*10000) + +-- helpers + +function R(...) + return math.random(...) +end + +function hex(r,g,b) + if g == nil then + b = r.b + g = r.b + r = r.r + end + return string.format("%.2x%.2x%.2x",r,g,b) +end + +function shuffle(t) + local n = #t + + while n >= 2 do + -- n is now the last pertinent index + local k = math.random(n) -- 1 <= k <= n + -- Quick swap + t[n], t[k] = t[k], t[n] + n = n - 1 + end + + return t +end + +function inbound(p, _min, _max) + if _min == nil then _min = 0 end + if _max == nil then _max = 1 end + if p > _max then p = _max elseif p < _min then p = _min end + return p +end + +function sqdist(a, b) + local x = b.x - a.x + local y = b.y - a.y + return x*x + y*y +end + +function dist(...) + return math.sqrt(sqdist(...)) +end + +-- values + +nr = 13 +blobs = {} + + +-- helpervalues +local __maxbound = 1.5 +local __reznr = 1 / nr +local __maxd = 0 + +-------------------------------------------------------------------------------- + + +function update() + for _, blob in ipairs(blobs) do + local d = 0.3 + blob.dir.x = (blob.dir.x + R()*d - d*0.5)*0.9 + blob.dir.y = (blob.dir.y + R()*d - d*0.5)*0.9 + + blob.strength = (blob.strength + R()*10 - 5)*0.8 + --blob.radius = (blob.radius + R()*0.1 - 0.05) + + blob.x = blob.x + blob.dir.x + blob.y = blob.y + blob.dir.y + + if blob.x > wall.width * __maxbound then + blob.x = - wall.width * __maxbound + elseif blob.x < - wall.width * __maxbound then + blob.x = wall.width * __maxbound + end + + if blob.y > wall.height * __maxbound then + blob.y = - wall.height * __maxbound + elseif blob.y < - wall.height * __maxbound then + blob.y = wall.height * __maxbound + end + + + for k, c in pairs(blob.color) do + blob.color[k] = c + R()*10 - 5 + end + end +end + +function draw() + + for y = 1, wall.height do + for x = 1, wall.width do + local curpos = {x=x,y=y} + + local r,g,b = 0,0,0 + for _, blob in ipairs(blobs) do + + local d = dist(curpos, blob) + if d < 0.9 then d = d * 0.9 end + --d = math.log(d)*2 + --d = math.log((d*d) / (__maxd*__maxd)) + ---d = math.log10((__maxd / (d * blob.radius)) + d = math.log((__maxd*blob.radius) / d) + --d = (1 - d) / __maxd + --d = math.log(d) + + d = d * blob.strength + + r = r + blob.color.r * d + g = g + blob.color.g * d + b = b + blob.color.b * d + end + + r = inbound(r * __reznr,0,255) + g = inbound(g * __reznr,0,255) + b = inbound(b * __reznr,0,255) + + --print(x,y,r,g,b) + + wall:pixel(x-1, y-1, hex(r,g,b)) + end + end + +end + +-------------------------------------------------------------------------------- + +function love.load() + wall = Wall("ledwall", 1338, 3) + + __maxd = math.sqrt(wall.width*wall.height) + + time = love.timer.getTime() * 1000 + + tick = 0 + + + -- initialize + + for i=1,nr do + local blob = { + dir={ + x = R()*1.5-0.75, + y = R()*1.5-0.75, + }, + strength = (R()*9 + 1), + radius = R()+0.5, + color = {r=0,g=0,b=0},--{ r=R(150,200), g=R(150,200), b=R(150.200) }, + x = R()*wall.width*__maxbound - wall.width*__maxbound*0.5, + y = R()*wall.height*__maxbound - wall.height*__maxbound*0.5, + } + + for i, c in ipairs(shuffle({"r","g","b"})) do + blob.color[c] = R() * 40 + 60 * i + end + + table.insert(blobs, blob) + end + +end + + +function love.keypressed(key) + if key == "escape" then + love.event.push "q" + end +end + +function love.update(dt) + -- constant 30 FPS + local t = love.timer.getTime() * 1000 + time = time + 1000 / 30 + love.timer.sleep(time - t) + + update() +end + + +function love.draw() + draw() + -- send the stuff abroad + wall:draw() +end \ No newline at end of file diff --git a/blob/wall.lua b/blob/wall.lua new file mode 120000 index 0000000..d37ae93 --- /dev/null +++ b/blob/wall.lua @@ -0,0 +1 @@ +../lib/wall.lua \ No newline at end of file From c0dd6c9e150e464257f6048c27011346aebda2a5 Mon Sep 17 00:00:00 2001 From: dodo Date: Wed, 23 Nov 2011 03:21:56 +0100 Subject: [PATCH 14/57] add lust --- blob/lust.lua | 1 + 1 file changed, 1 insertion(+) create mode 120000 blob/lust.lua diff --git a/blob/lust.lua b/blob/lust.lua new file mode 120000 index 0000000..f6e54d1 --- /dev/null +++ b/blob/lust.lua @@ -0,0 +1 @@ +../lib/lust.lua \ No newline at end of file From 9d156139dbc8bb6122bdb8f3aadd0fa972f1ee84 Mon Sep 17 00:00:00 2001 From: dodo Date: Wed, 23 Nov 2011 03:22:10 +0100 Subject: [PATCH 15/57] fireflies --- blob/main.lua | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/blob/main.lua b/blob/main.lua index 4b4ebb5..194225b 100644 --- a/blob/main.lua +++ b/blob/main.lua @@ -52,7 +52,7 @@ end -- values -nr = 13 +nr = 42 blobs = {} @@ -66,25 +66,27 @@ local __maxd = 0 function update() for _, blob in ipairs(blobs) do - local d = 0.3 + local d = 0.9 blob.dir.x = (blob.dir.x + R()*d - d*0.5)*0.9 blob.dir.y = (blob.dir.y + R()*d - d*0.5)*0.9 - blob.strength = (blob.strength + R()*10 - 5)*0.8 + --blob.strength = (blob.strength + R()*10 - 5)*0.8 --blob.radius = (blob.radius + R()*0.1 - 0.05) blob.x = blob.x + blob.dir.x blob.y = blob.y + blob.dir.y + local w = wall.width * __maxbound - wall.width if blob.x > wall.width * __maxbound then - blob.x = - wall.width * __maxbound - elseif blob.x < - wall.width * __maxbound then + blob.x = - w + elseif blob.x < - w then blob.x = wall.width * __maxbound end + local h = wall.height * __maxbound - wall.height if blob.y > wall.height * __maxbound then - blob.y = - wall.height * __maxbound - elseif blob.y < - wall.height * __maxbound then + blob.y = - h + elseif blob.y < - h then blob.y = wall.height * __maxbound end @@ -92,7 +94,17 @@ function update() for k, c in pairs(blob.color) do blob.color[k] = c + R()*10 - 5 end + + if tick%50 == 0 then + local c = blob.color + local tmp = c.r + c.r = c.g + c.g = c.b + c.b = tmp + end end + + tick = tick + 1 end function draw() @@ -120,9 +132,16 @@ function draw() b = b + blob.color.b * d end - r = inbound(r * __reznr,0,255) - g = inbound(g * __reznr,0,255) - b = inbound(b * __reznr,0,255) + local m = 1 + --local sum = (r + g + b)/3 + --local m = inbound(sum/256)--inbound(math.sqrt(sum)) + --if m == 0 then m = -m end + --if sum < 33 and sum > 188 then m = 0 end + + + r = inbound(m*r * __reznr,0,255) + g = inbound(m*g * __reznr,0,255) + b = inbound(m*b * __reznr,0,255) --print(x,y,r,g,b) @@ -155,8 +174,8 @@ function love.load() strength = (R()*9 + 1), radius = R()+0.5, color = {r=0,g=0,b=0},--{ r=R(150,200), g=R(150,200), b=R(150.200) }, - x = R()*wall.width*__maxbound - wall.width*__maxbound*0.5, - y = R()*wall.height*__maxbound - wall.height*__maxbound*0.5, + x = R()*wall.width*__maxbound, + y = R()*wall.height*__maxbound, } for i, c in ipairs(shuffle({"r","g","b"})) do From d835d6f4b20dad4d74db690f89dabb4f58f6790c Mon Sep 17 00:00:00 2001 From: eri451 Date: Sat, 3 Dec 2011 03:25:20 +0100 Subject: [PATCH 16/57] 3d search --- balken/field.lua | 129 +++++++++++++++++++++++------------------------ 1 file changed, 63 insertions(+), 66 deletions(-) diff --git a/balken/field.lua b/balken/field.lua index 8ea7eea..03ca2ff 100644 --- a/balken/field.lua +++ b/balken/field.lua @@ -102,17 +102,18 @@ end function Field:collapse() local grid = self.grid local ret = false - local z = self.layer - for x = 1, self.width do - local drop = false - for y = self.height, 1, -1 do - drop = drop or grid[z][y][x] == 0 - if drop then - grid[z][y][x] = grid[z][y - 1] and grid[z][y - 1][x] or 0 - ret = grid[z][y][x] > 0 or ret - end - end - end + for z = 1, self.width do + for x = 1, self.width do + local drop = false + for y = self.height, 1, -1 do + drop = drop or grid[z][y][x] == 0 + if drop then + grid[z][y][x] = grid[z][y - 1] and grid[z][y - 1][x] or 0 + ret = grid[z][y][x] > 0 or ret + end + end + end + end return ret end @@ -168,7 +169,7 @@ function Field:update() -- remove gems for _, coords in pairs(self.gems_in_line) do - self.grid[self.layer][coords.y][coords.x] = 0 + self.grid[coords.z][coords.y][coords.x] = 0 self.score = self.score + 1 end self.gems_in_line = {} @@ -257,6 +258,22 @@ function Field:update() end end +local spiral = {} +do + local p = { x = 0, y = 0 } + local d, n, s = "y", 1, 1 + for c = 1, 3 do + for _ = 1, 2 do + for i = 1, n do + table.insert(spiral, {p.x,p.y}) + p[d] = p[d] + s*1 + end + d = d == "y" and "x" or "y" + end + s = s * -1 + n = n + 1 + end +end function Field:findGemsInLine() @@ -265,62 +282,42 @@ function Field:findGemsInLine() local grid = self.grid local z = self.layer - local function addGem(x, y) - self.gems_in_line[y .. " " .. x] = { x = x, y = y } + local function addGem(x, y, z) + self.gems_in_line[y .. " " .. x .. " " .. z] = { x = x, y = y, z = z } end - -- [-] check - for y = 1, self.height do - for x = 1, self.width-2 do - if grid[z][y][x] > 0 and - grid[z][y][x] == grid[z][y][x + 1] and - grid[z][y][x] == grid[z][y][x + 2] then - addGem(x, y) - addGem(x + 1, y) - addGem(x + 2, y) - self.combo_count = self.combo_count + 1 - end - end - end - -- [|] check - for x = 1, self.width do - for y = 1, self.height-2 do - if grid[z][y][x] > 0 and - grid[z][y][x] == grid[z][y + 1][x] and - grid[z][y][x] == grid[z][y + 2][x] then - addGem(x, y) - addGem(x, y + 1) - addGem(x, y + 2) - self.combo_count = self.combo_count + 1 - end - end - end - -- [\] check - for y = 1, self.height-2 do - for x = 1, self.width-2 do - if grid[z][y][x] > 0 and - grid[z][y][x] == grid[z][y + 1][x + 1] and - grid[z][y][x] == grid[z][y + 2][x + 2] then - addGem(x, y) - addGem(x + 1, y + 1) - addGem(x + 2, y + 2) - self.combo_count = self.combo_count + 1 - end - end - end - -- [/] check - for y = 1, self.height-2 do - for x = 3, self.width do - if grid[z][y][x] > 0 and - grid[z][y][x] == grid[z][y + 1][x - 1] and - grid[z][y][x] == grid[z][y + 2][x - 2] then - addGem(x, y) - addGem(x - 1, y + 1) - addGem(x - 2, y + 2) - self.combo_count = self.combo_count + 1 - end - end - end + local function getCell(x, y, z) + z = grid[z] + if z ~= nil then + y = z[y] + if y ~= nil then + return y[x] + end + end + end + + for z = 1, self.width-2 do + for y = 1, self.height-2 do + for x = 1, self.width-2 do + for _, range in ipairs({ {1,9,1}, {2,5,0} }) do + local _y = range[3] + for i = range[1], range[2] do + local _x, _z = spiral[i][1], spiral[i][2] + local cell = getCell(x,y,z) + if cell > 0 and + cell == getCell(x + 1*_x, y + 1*_y, z + 1*_z) and + cell == getCell(x + 2*_x, y + 2*_y, z + 2*_z) then + addGem(x, y, z) + addGem(x + 1*_x, y + 1*_y, z + 1*_z) + addGem(x + 2*_x, y + 2*_y, z + 2*_z) + self.combo_count = self.combo_count + 1 + end + end + -- the turbine + end + end + end + end -- return true if we found something return next(self.gems_in_line) ~= nil From a1f19f9d62ff0950adfbef380cc948d821bed780 Mon Sep 17 00:00:00 2001 From: dodo Date: Thu, 29 Dec 2011 04:07:23 +0100 Subject: [PATCH 17/57] mv helper functions in own file --- blob/framework.lua | 1 + blob/main.lua | 50 +--------------------------------------------- lib/framework.lua | 47 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 49 deletions(-) create mode 120000 blob/framework.lua create mode 100644 lib/framework.lua diff --git a/blob/framework.lua b/blob/framework.lua new file mode 120000 index 0000000..1350e61 --- /dev/null +++ b/blob/framework.lua @@ -0,0 +1 @@ +../lib/framework.lua \ No newline at end of file diff --git a/blob/main.lua b/blob/main.lua index 194225b..47c3ed2 100644 --- a/blob/main.lua +++ b/blob/main.lua @@ -1,54 +1,6 @@ require "helper" require "wall" - -require 'socket' -math.randomseed(socket.gettime()*10000) - --- helpers - -function R(...) - return math.random(...) -end - -function hex(r,g,b) - if g == nil then - b = r.b - g = r.b - r = r.r - end - return string.format("%.2x%.2x%.2x",r,g,b) -end - -function shuffle(t) - local n = #t - - while n >= 2 do - -- n is now the last pertinent index - local k = math.random(n) -- 1 <= k <= n - -- Quick swap - t[n], t[k] = t[k], t[n] - n = n - 1 - end - - return t -end - -function inbound(p, _min, _max) - if _min == nil then _min = 0 end - if _max == nil then _max = 1 end - if p > _max then p = _max elseif p < _min then p = _min end - return p -end - -function sqdist(a, b) - local x = b.x - a.x - local y = b.y - a.y - return x*x + y*y -end - -function dist(...) - return math.sqrt(sqdist(...)) -end +require "framework" -- values diff --git a/lib/framework.lua b/lib/framework.lua new file mode 100644 index 0000000..9a937b8 --- /dev/null +++ b/lib/framework.lua @@ -0,0 +1,47 @@ + +require 'socket' +math.randomseed(socket.gettime()*10000) + +function R(...) + return math.random(...) +end + +function hex(r,g,b) + if g == nil then + b = r.b + g = r.b + r = r.r + end + return string.format("%.2x%.2x%.2x",r,g,b) +end + +function shuffle(t) + local n = #t + + while n >= 2 do + -- n is now the last pertinent index + local k = math.random(n) -- 1 <= k <= n + -- Quick swap + t[n], t[k] = t[k], t[n] + n = n - 1 + end + + return t +end + +function inbound(p, _min, _max) + if _min == nil then _min = 0 end + if _max == nil then _max = 1 end + if p > _max then p = _max elseif p < _min then p = _min end + return p +end + +function sqdist(a, b) + local x = b.x - a.x + local y = b.y - a.y + return x*x + y*y +end + +function dist(...) + return math.sqrt(sqdist(...)) +end From 04bd05ede60aa5dbfbaa98e7eb616b92ea7aa3ed Mon Sep 17 00:00:00 2001 From: dodo Date: Thu, 29 Dec 2011 08:11:58 +0100 Subject: [PATCH 18/57] greetings from the 28c3 congress --- space/README.md | 4 + space/conf.lua | 9 ++ space/framework.lua | 1 + space/helper.lua | 1 + space/lust.lua | 1 + space/main.lua | 262 ++++++++++++++++++++++++++++++++++++++++++++ space/wall.lua | 1 + 7 files changed, 279 insertions(+) create mode 100644 space/README.md create mode 100644 space/conf.lua create mode 120000 space/framework.lua create mode 120000 space/helper.lua create mode 120000 space/lust.lua create mode 100644 space/main.lua create mode 120000 space/wall.lua diff --git a/space/README.md b/space/README.md new file mode 100644 index 0000000..cf35bc1 --- /dev/null +++ b/space/README.md @@ -0,0 +1,4 @@ +space +===== + +??? diff --git a/space/conf.lua b/space/conf.lua new file mode 100644 index 0000000..9411edd --- /dev/null +++ b/space/conf.lua @@ -0,0 +1,9 @@ +function love.conf(t) + t.title = "space" + t.author = "dodo" + t.screen.width = 320 + t.screen.height = 300 + t.screen.vsync = false + t.modules.physics = false + t.modules.mouse = false +end diff --git a/space/framework.lua b/space/framework.lua new file mode 120000 index 0000000..1350e61 --- /dev/null +++ b/space/framework.lua @@ -0,0 +1 @@ +../lib/framework.lua \ No newline at end of file diff --git a/space/helper.lua b/space/helper.lua new file mode 120000 index 0000000..039178c --- /dev/null +++ b/space/helper.lua @@ -0,0 +1 @@ +../lib/helper.lua \ No newline at end of file diff --git a/space/lust.lua b/space/lust.lua new file mode 120000 index 0000000..f6e54d1 --- /dev/null +++ b/space/lust.lua @@ -0,0 +1 @@ +../lib/lust.lua \ No newline at end of file diff --git a/space/main.lua b/space/main.lua new file mode 100644 index 0000000..4e48f6a --- /dev/null +++ b/space/main.lua @@ -0,0 +1,262 @@ +require "helper" +require "wall" +require "framework" + +-- values + +nr = 32 +env = { + stars = {level=3}, +} + + + +-- helpervalues +-- local __maxbound = 1.5 +-- local __reznr = 1 / (nr*0.1) -- / (nr*3) +-- local __maxd = 0 + + +local operator = { + ["+"]=function(a,b)return a+b end, + ["-"]=function(a,b)return a-b end} + +-------------------------------------------------------------------------------- + +function starlight(t) -- temperature in kelvin + local max = 50 + t = math.min(30000,math.max(0,t)) + if t < 3500 then + return math.ceil(t/3500*max), 0, 0 + elseif t < 6000 then + return max, math.ceil((t-3500)/2500*max), 0 + elseif t < 10000 then + return max, max, math.ceil((t-6000)/4000*max) + else + local r = max - math.ceil((t-10000)/20000*max) + return r, r, max + end +end + +-------------------------------------------------------------------------------- + +Vector = Object:new() +function Vector:init(opts) + self.x = opts.x or 0.0 + self.y = opts.y or 0.0 +end + +function Vector:clone() + return Vector(self) +end + +function Vector:add(vec) + self.x = self.x + vec.x + self.y = self.y + vec.y + return self -- chainable +end + +function Vector:sub(vec) + self.x = self.x - vec.x + self.y = self.y - vec.y + return self -- chainable +end + +function Vector:mul(val) + if type(val) == 'number' then + self.x = self.x * val + self.y = self.y * val + else + self.x = self.x * val.x + self.y = self.y * val.y + end + return self -- chainable +end + +function Vector:dot(vec) + return self.x * vec.x + self.y * vec.y +end + +function Vector:len() + return math.sqrt(self:dot(self)) +end + +function Vector:norm() + return self:mul(1/self:len()) +end + +-------------------------------------------------------------------------------- + +Star = Object:new() +function Star:init(opts) + opts = opts or {} + self.pos = Vector(opts) + self.dir = Vector(opts.dir or {}) + self.color = opts.color or hex( 20, 20, 0 ) +end + +function Star:update() + self.pos:add(self.dir) + self.pos.x = inroundbound(self.pos.x, 0, wall.width) + self.pos.y = inroundbound(self.pos.y, 0, wall.height) + + if #(env.player._state) > 0 then + for _, oc in ipairs(env.player._state) do + local o, c = oc:sub(1,1), oc:sub(2) + self.dir[c] = operator[o](self.dir[c], -1) + end + self.dir:norm():mul(0.4) + end +end + +function Star:draw() + local x, y = self.pos.x, self.pos.y + wall:pixel(floor(x), floor(y), self.color) +end + +-------------------------------------------------------------------------------- + +Player = Object:new() +function Player:init(opts) + opts = opts or {} + self.pos = Vector(opts) + self.color = opts.color or hex(200, 200, 200) + self._state = {} +end + +function Player:update() + local newstate = {} + for dir, oc in pairs({left="-x", right="+x", up="-y", down="+y" }) do + if wall.input[1][dir] then + local o, c = oc:sub(1,1), oc:sub(2) + self.pos[c] = operator[o](self.pos[c], 0.5) + table.insert(newstate, oc) + end + end + if #newstate > 0 then + self._state = newstate + end + + self.pos.x = inroundbound(self.pos.x, 0, wall.width) + self.pos.y = inroundbound(self.pos.y, 0, wall.height) +end + +function Player:draw() + local x, y = floor(self.pos.x), floor(self.pos.y) + wall:pixel(x, y, self.color) + + if #(self._state) > 0 then + for _, oc in ipairs(self._state) do + local o, c = oc:sub(1,1), oc:sub(2) + local coord = { x=x , y=y } + coord[c] = operator[o](coord[c], -1) + coord[c] = inbound(coord[c], 0, wall[({x="width",y="height"})[c]]) + wall:pixel(coord.x, coord.y, self.color) + end + end +end + +-------------------------------------------------------------------------------- + +function update() + wall:update_input() + + for y = 1, wall.height do + for x = 1, wall.width do + wall:pixel(x-1, y-1, hex(0,0,0)) + end + end + + for level = 1, env.stars.level do + if tick%(level*10) then + for _, star in ipairs(env.stars[level] or {}) do + star:update() + end + end + end + + env.player:update() + + tick = tick + 1 +end + +function draw() + + + + for level = 1, env.stars.level do + if tick%(level*10) then + for _, star in ipairs(env.stars[level] or {}) do + star:draw() + end + end + end + env.player:draw() + +end + +-------------------------------------------------------------------------------- + +function love.load() + wall = Wall("176.99.24.251", 1338, 3, false) -- "176.99.24.251" + +-- __maxd = math.sqrt(wall.width*wall.height) + + time = love.timer.getTime() * 1000 + + tick = 0 + + + -- initialize + + for level = 1, env.stars.level do + env.stars[level] = env.stars[level] or {} + for i = 1, 10 do + star = Star { + x = (R()*wall.width), + y = (R()*wall.height), + dir = { + x = (R()*0.2), + y = (R()*0.08-0.04), + }, + color = hex( starlight(((174+level*10)*R())^2) ), +-- color = hex( starlight(30000*R()) ), + } + + star.dir:norm():mul(0.1) + +-- env.stars[1][(level-1)*10+i] = star + env.stars[level][i] = star + + end + end + + env.player = Player { + x = wall.width*0.5, + y = wall.height*0.5, + } + +end + + +function love.keypressed(key) + if key == "escape" then + love.event.push "q" + end +end + +function love.update(dt) + -- constant 30 FPS + local t = love.timer.getTime() * 1000 + time = time + 1000 / 30 + love.timer.sleep(time - t) + + update() +end + + +function love.draw() + draw() + -- send the stuff abroad + wall:draw() +end diff --git a/space/wall.lua b/space/wall.lua new file mode 120000 index 0000000..d37ae93 --- /dev/null +++ b/space/wall.lua @@ -0,0 +1 @@ +../lib/wall.lua \ No newline at end of file From 1f7af182a17551ab4485afe1e15c7ffb72e7e292 Mon Sep 17 00:00:00 2001 From: dodo Date: Thu, 29 Dec 2011 08:12:46 +0100 Subject: [PATCH 19/57] inroundbound helper --- lib/framework.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/framework.lua b/lib/framework.lua index 9a937b8..71d115f 100644 --- a/lib/framework.lua +++ b/lib/framework.lua @@ -1,6 +1,7 @@ require 'socket' math.randomseed(socket.gettime()*10000) +floor = math.floor function R(...) return math.random(...) @@ -36,6 +37,19 @@ function inbound(p, _min, _max) return p end +function inroundbound(p, _min, _max) + local len = _max - _min + if _min == nil then _min = 0 end + if _max == nil then _max = 1 end + while p < _min do + p = p + len + end + while p > _max do + p = p - len + end + return p +end + function sqdist(a, b) local x = b.x - a.x local y = b.y - a.y From b96bd8d174f8b415c8de6e2b106adf162643d21c Mon Sep 17 00:00:00 2001 From: dodo Date: Thu, 29 Dec 2011 11:30:59 +0100 Subject: [PATCH 20/57] shoot! --- lib/framework.lua | 4 ++ space/main.lua | 103 +++++++++++++++++++++++++++++++++++++++++----- spalten/main.lua | 3 +- 3 files changed, 99 insertions(+), 11 deletions(-) diff --git a/lib/framework.lua b/lib/framework.lua index 71d115f..1e5038c 100644 --- a/lib/framework.lua +++ b/lib/framework.lua @@ -1,7 +1,11 @@ require 'socket' math.randomseed(socket.gettime()*10000) + floor = math.floor +round = function (x) + return floor(x+0.5) +end function R(...) return math.random(...) diff --git a/space/main.lua b/space/main.lua index 4e48f6a..36a1808 100644 --- a/space/main.lua +++ b/space/main.lua @@ -42,6 +42,7 @@ end Vector = Object:new() function Vector:init(opts) + opts = opts or {} self.x = opts.x or 0.0 self.y = opts.y or 0.0 end @@ -82,7 +83,13 @@ function Vector:len() end function Vector:norm() - return self:mul(1/self:len()) + local len = self:len() + if len < 0.00000001 then + self:mul(0) + else + self:mul(1/len) + end + return self -- chainable end -------------------------------------------------------------------------------- @@ -91,7 +98,7 @@ Star = Object:new() function Star:init(opts) opts = opts or {} self.pos = Vector(opts) - self.dir = Vector(opts.dir or {}) + self.dir = Vector(opts.dir) self.color = opts.color or hex( 20, 20, 0 ) end @@ -103,15 +110,15 @@ function Star:update() if #(env.player._state) > 0 then for _, oc in ipairs(env.player._state) do local o, c = oc:sub(1,1), oc:sub(2) - self.dir[c] = operator[o](self.dir[c], -1) + self.dir[c] = operator[o](self.dir[c], -0.6) end - self.dir:norm():mul(0.4) + self.dir:norm():mul(0.6) end end function Star:draw() local x, y = self.pos.x, self.pos.y - wall:pixel(floor(x), floor(y), self.color) + wall:pixel(round(x), round(y), self.color) end -------------------------------------------------------------------------------- @@ -122,6 +129,7 @@ function Player:init(opts) self.pos = Vector(opts) self.color = opts.color or hex(200, 200, 200) self._state = {} + self.projectiles = setmetatable({length=0}, { __mode = 'k' }) end function Player:update() @@ -133,15 +141,47 @@ function Player:update() table.insert(newstate, oc) end end + self.pos.x = inroundbound(self.pos.x, 0, wall.width) + self.pos.y = inroundbound(self.pos.y, 0, wall.height) if #newstate > 0 then self._state = newstate end - self.pos.x = inroundbound(self.pos.x, 0, wall.width) - self.pos.y = inroundbound(self.pos.y, 0, wall.height) + -- shoot + if wall.input[1].a and self.projectiles.length <3 then + local dir = Vector() + for _, oc in ipairs(self._state) do + local o, c = oc:sub(1,1), oc:sub(2) + dir[c] = operator[o](dir[c], 1) + end + if dir:len() > 0 then + local projectile = Projectile { + x = self.pos.x+1, + y = self.pos.y+1, + dir = dir:norm():mul(0.8), + } + projectile.life = projectile -- self reference + -- table.insert(self.projectiles, projectile) + self.projectiles[projectile] = projectile + self.projectiles.length = self.projectiles.length + 1 + end + end + + for key, projectile in pairs(self.projectiles) do + if key ~= "length" then + projectile:update() + end + end + end function Player:draw() + for key, projectile in pairs(self.projectiles) do + if key ~= "length" then + projectile:draw() + end + end + local x, y = floor(self.pos.x), floor(self.pos.y) wall:pixel(x, y, self.color) @@ -150,10 +190,53 @@ function Player:draw() local o, c = oc:sub(1,1), oc:sub(2) local coord = { x=x , y=y } coord[c] = operator[o](coord[c], -1) - coord[c] = inbound(coord[c], 0, wall[({x="width",y="height"})[c]]) + coord[c] = inbound(coord[c], 1, wall[({x="width",y="height"})[c]]) wall:pixel(coord.x, coord.y, self.color) end end + +end + +-------------------------------------------------------------------------------- + +Projectile = Object:new() +function Projectile:init(opts) + opts = opts or {} + self.pos = Vector(opts) + self.dir = Vector(opts.dir) + self.color = opts.color or hex(180, 20, 0) + self.energy = opts.energy or 10 + self.max_energy = self.energy + self.life = nil -- will be set by parent +end + +function Projectile:update() + if self.life == nil then return end + self.energy = self.energy - 1 + if self.energy == 0 then + env.player.projectiles[self] = nil + env.player.projectiles.length = env.player.projectiles.length - 1 + self.life = nil -- delete, or just simply die + return + end + local rel_energy = self.energy/self.max_energy + if rel_energy > 0.2 then + local dir = Vector() + for _, oc in ipairs(env.player._state) do + local o, c = oc:sub(1,1), oc:sub(2) + dir[c] = operator[o](dir[c], 1) + end + self.pos:add(dir:norm():mul(rel_energy)) + end + self.pos:add(self.dir) +end + +function Projectile:draw() + if self.life == nil then return end + if self.pos.x == inbound(self.pos.x, 1, wall.width) and + self.pos.y == inbound(self.pos.y, 1, wall.height) then + wall:pixel(round(self.pos.x-1), round(self.pos.y-1), self.color) + end end -------------------------------------------------------------------------------- @@ -168,7 +251,7 @@ function update() end for level = 1, env.stars.level do - if tick%(level*10) then + if tick%level == 0 then for _, star in ipairs(env.stars[level] or {}) do star:update() end @@ -219,7 +302,7 @@ function love.load() x = (R()*0.2), y = (R()*0.08-0.04), }, - color = hex( starlight(((174+level*10)*R())^2) ), + color = hex( starlight(((174-level*20)*R())^2) ), -- color = hex( starlight(30000*R()) ), } diff --git a/spalten/main.lua b/spalten/main.lua index 4e7c662..e74a84c 100644 --- a/spalten/main.lua +++ b/spalten/main.lua @@ -24,7 +24,8 @@ function love.load() math.randomseed(os.time()) time = love.timer.getTime() * 1000 - wall = Wall("ledwall", 1338, 3, false) + --wall = Wall("ledwall", 1338, 3, false) + wall = Wall(nil, nil, 3, false) fields = { Field(0, wall.input[1]), From f9221122d8725a491b06452ce684e84be3fd84fd Mon Sep 17 00:00:00 2001 From: dodo Date: Thu, 29 Dec 2011 12:04:29 +0100 Subject: [PATCH 21/57] absolute player position --- space/main.lua | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/space/main.lua b/space/main.lua index 36a1808..7dc1bab 100644 --- a/space/main.lua +++ b/space/main.lua @@ -127,6 +127,7 @@ Player = Object:new() function Player:init(opts) opts = opts or {} self.pos = Vector(opts) + self.coords = self.pos:clone() self.color = opts.color or hex(200, 200, 200) self._state = {} self.projectiles = setmetatable({length=0}, { __mode = 'k' }) @@ -147,13 +148,16 @@ function Player:update() self._state = newstate end + -- direction + local dir = Vector() + for _, oc in ipairs(self._state) do + local o, c = oc:sub(1,1), oc:sub(2) + dir[c] = operator[o](dir[c], 1) + end + self.coords:add(dir) + -- shoot if wall.input[1].a and self.projectiles.length <3 then - local dir = Vector() - for _, oc in ipairs(self._state) do - local o, c = oc:sub(1,1), oc:sub(2) - dir[c] = operator[o](dir[c], 1) - end if dir:len() > 0 then local projectile = Projectile { x = self.pos.x+1, From 7c7d65d2028f73ffbb3e5505393e347c601aec32 Mon Sep 17 00:00:00 2001 From: dodo Date: Thu, 29 Dec 2011 12:04:48 +0100 Subject: [PATCH 22/57] dont access globals --- space/main.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/space/main.lua b/space/main.lua index 7dc1bab..b425f68 100644 --- a/space/main.lua +++ b/space/main.lua @@ -160,6 +160,7 @@ function Player:update() if wall.input[1].a and self.projectiles.length <3 then if dir:len() > 0 then local projectile = Projectile { + source = self, x = self.pos.x+1, y = self.pos.y+1, dir = dir:norm():mul(0.8), @@ -212,21 +213,25 @@ function Projectile:init(opts) self.energy = opts.energy or 10 self.max_energy = self.energy self.life = nil -- will be set by parent + self.source = opts.source + if not self.source then + error("no source given") + end end function Projectile:update() if self.life == nil then return end self.energy = self.energy - 1 if self.energy == 0 then - env.player.projectiles[self] = nil - env.player.projectiles.length = env.player.projectiles.length - 1 + self.source.projectiles[self] = nil + self.source.projectiles.length = self.source.projectiles.length - 1 self.life = nil -- delete, or just simply die return end local rel_energy = self.energy/self.max_energy if rel_energy > 0.2 then local dir = Vector() - for _, oc in ipairs(env.player._state) do + for _, oc in ipairs(self.source._state) do local o, c = oc:sub(1,1), oc:sub(2) dir[c] = operator[o](dir[c], 1) end From c1b98da9a69f0bf056ce3fec8900685ba3d73df4 Mon Sep 17 00:00:00 2001 From: dodo Date: Thu, 29 Dec 2011 12:23:48 +0100 Subject: [PATCH 23/57] return modulo as well --- lib/framework.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/framework.lua b/lib/framework.lua index 1e5038c..bbd5391 100644 --- a/lib/framework.lua +++ b/lib/framework.lua @@ -41,17 +41,25 @@ function inbound(p, _min, _max) return p end -function inroundbound(p, _min, _max) +function inroundbound_with_count(p, _min, _max) + local count = 0 local len = _max - _min if _min == nil then _min = 0 end if _max == nil then _max = 1 end while p < _min do + count = count + 1 p = p + len end while p > _max do + count = count - 1 p = p - len end - return p + return p, count +end + +function inroundbound(...) + local ret, _ = inroundbound_with_count(...) + return ret end function sqdist(a, b) From 0aeeedb70ce181d5ce099c2b64d10596bf5cd8eb Mon Sep 17 00:00:00 2001 From: dodo Date: Thu, 29 Dec 2011 12:24:44 +0100 Subject: [PATCH 24/57] fixed player abs pos when out of roundbound --- space/main.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/space/main.lua b/space/main.lua index b425f68..aaef7b5 100644 --- a/space/main.lua +++ b/space/main.lua @@ -142,8 +142,10 @@ function Player:update() table.insert(newstate, oc) end end - self.pos.x = inroundbound(self.pos.x, 0, wall.width) - self.pos.y = inroundbound(self.pos.y, 0, wall.height) + local cx, cy + self.pos.x, cx = inroundbound_with_count(self.pos.x, 0, wall.width) + self.pos.y, cy = inroundbound_with_count(self.pos.y, 0, wall.height) + self.coords:add { x = -cx * wall.width, y = -cy * wall.height } if #newstate > 0 then self._state = newstate end From ad8748a4615ed0ee220869cb8e2613b9b0f7699d Mon Sep 17 00:00:00 2001 From: dodo Date: Thu, 29 Dec 2011 13:00:29 +0100 Subject: [PATCH 25/57] Target --- space/main.lua | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/space/main.lua b/space/main.lua index aaef7b5..912f850 100644 --- a/space/main.lua +++ b/space/main.lua @@ -157,6 +157,7 @@ function Player:update() dir[c] = operator[o](dir[c], 1) end self.coords:add(dir) +-- print(self.coords.x, self.coords.y) -- shoot if wall.input[1].a and self.projectiles.length <3 then @@ -168,7 +169,6 @@ function Player:update() dir = dir:norm():mul(0.8), } projectile.life = projectile -- self reference - -- table.insert(self.projectiles, projectile) self.projectiles[projectile] = projectile self.projectiles.length = self.projectiles.length + 1 end @@ -204,6 +204,32 @@ function Player:draw() end +-------------------------------------------------------------------------------- + +Target = Object:new() +function Target:init(opts) + opts = opts or {} + self.coords = Vector(opts) + self.color = opts.color or hex(0, 180, 0) + self.source = opts.source + if not self.source then + error("no source given") + end +end + +function Target:update() + +end + +function Target:draw() + local pos = self.coords:clone():sub(self.source.coords):add(self.source.pos) + pos.x = inbound(pos.x, 1, wall.width) + pos.y = inbound(pos.y, 1, wall.height) + wall:pixel(floor(pos.x-1), floor(pos.y-1), self.color) +end + + + -------------------------------------------------------------------------------- Projectile = Object:new() @@ -271,13 +297,15 @@ function update() env.player:update() + for _, target in ipairs(env.targets or {}) do + target:update() + end + tick = tick + 1 end function draw() - - for level = 1, env.stars.level do if tick%(level*10) then for _, star in ipairs(env.stars[level] or {}) do @@ -285,6 +313,11 @@ function draw() end end end + + for _, target in ipairs(env.targets or {}) do + target:draw() + end + env.player:draw() end @@ -330,6 +363,12 @@ function love.load() y = wall.height*0.5, } + env.targets = {} + env.targets[1] = Target { + source = env.player, + x = 0, + y = 0, + } end From 074b62e94d3ee8ca5320fbaf95ef2beaa5b55fb1 Mon Sep 17 00:00:00 2001 From: dodo Date: Thu, 29 Dec 2011 13:55:11 +0100 Subject: [PATCH 26/57] let user halt with b --- space/main.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/space/main.lua b/space/main.lua index 912f850..fbd66d6 100644 --- a/space/main.lua +++ b/space/main.lua @@ -113,6 +113,8 @@ function Star:update() self.dir[c] = operator[o](self.dir[c], -0.6) end self.dir:norm():mul(0.6) + else + self.dir:norm():mul(0.1) end end @@ -150,6 +152,11 @@ function Player:update() self._state = newstate end + -- halt + if wall.input[1].b then + self._state = {} + end + -- direction local dir = Vector() for _, oc in ipairs(self._state) do @@ -350,8 +357,6 @@ function love.load() -- color = hex( starlight(30000*R()) ), } - star.dir:norm():mul(0.1) - -- env.stars[1][(level-1)*10+i] = star env.stars[level][i] = star From eb0b8636a7c6f00ad7aa15521c1d54d1e8524eab Mon Sep 17 00:00:00 2001 From: dodo Date: Thu, 29 Dec 2011 13:55:58 +0100 Subject: [PATCH 27/57] change color when target is out of pov --- space/main.lua | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/space/main.lua b/space/main.lua index fbd66d6..b37afa4 100644 --- a/space/main.lua +++ b/space/main.lua @@ -218,6 +218,7 @@ function Target:init(opts) opts = opts or {} self.coords = Vector(opts) self.color = opts.color or hex(0, 180, 0) + self.away_color = opts.away_color or hex(0, 60, 0) self.source = opts.source if not self.source then error("no source given") @@ -230,9 +231,14 @@ end function Target:draw() local pos = self.coords:clone():sub(self.source.coords):add(self.source.pos) - pos.x = inbound(pos.x, 1, wall.width) - pos.y = inbound(pos.y, 1, wall.height) - wall:pixel(floor(pos.x-1), floor(pos.y-1), self.color) + local x,y + x = inbound(pos.x, 1, wall.width) + y = inbound(pos.y, 1, wall.height) + local color = self.color + if pos.x ~= x or pos.y ~= y then + color = self.away_color + end + wall:pixel(floor(x-1), floor(y-1), color) end From 45152cf5d1135363a11fa4834b0f82e1ad9c7b69 Mon Sep 17 00:00:00 2001 From: apohle Date: Thu, 29 Dec 2011 14:52:53 +0100 Subject: [PATCH 28/57] add enemys --- space/main.lua | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/space/main.lua b/space/main.lua index b37afa4..bf75a77 100644 --- a/space/main.lua +++ b/space/main.lua @@ -241,6 +241,36 @@ function Target:draw() wall:pixel(floor(x-1), floor(y-1), color) end +-------------------------------------------------------------------------------- +Enemy = Object:new() +function Enemy:init(opts) + opts = opts or {} + self.coords = Vector(opts) + self.dir = Vector(opts.dir) + self.color = opts.color or hex(180, 0, 0) + self.away_color = opts.away_color or hex(60, 0, 0) + self.source = opts.source + if not self.source then + error("no source given") + end +end + +function Enemy:update() + self.coords:add(self.dir) + +end + +function Enemy:draw() + local pos = self.coords:clone():sub(self.source.coords):add(self.source.pos) + local x,y + x = inbound(pos.x, 1, wall.width) + y = inbound(pos.y, 1, wall.height) + local color = self.color + if pos.x ~= x or pos.y ~= y then + color = self.away_color + end + wall:pixel(floor(x-1), floor(y-1), color) +end -------------------------------------------------------------------------------- @@ -314,6 +344,10 @@ function update() target:update() end + for _, enemy in ipairs(env.enemys or {}) do + enemy:update() + end + tick = tick + 1 end @@ -331,6 +365,10 @@ function draw() target:draw() end + for _, enemy in ipairs(env.enemys or {}) do + enemy:draw() + end + env.player:draw() end @@ -338,7 +376,7 @@ end -------------------------------------------------------------------------------- function love.load() - wall = Wall("176.99.24.251", 1338, 3, false) -- "176.99.24.251" + wall = Wall(false, 1338, 3, false) -- "176.99.24.251" -- __maxd = math.sqrt(wall.width*wall.height) @@ -380,6 +418,14 @@ function love.load() x = 0, y = 0, } + + env.enemys = {} + env.enemys[1] = Enemy { + source = env.player, + x = 3, + y = 3, + dir = {x=-0.01, y=-0.01} + } end From 0a4227e848736206a58bded96af2260ce8c9ca15 Mon Sep 17 00:00:00 2001 From: dodo Date: Thu, 29 Dec 2011 15:06:03 +0100 Subject: [PATCH 29/57] smoother viewport jumps --- space/main.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/space/main.lua b/space/main.lua index bf75a77..61d5517 100644 --- a/space/main.lua +++ b/space/main.lua @@ -147,7 +147,10 @@ function Player:update() local cx, cy self.pos.x, cx = inroundbound_with_count(self.pos.x, 0, wall.width) self.pos.y, cy = inroundbound_with_count(self.pos.y, 0, wall.height) - self.coords:add { x = -cx * wall.width, y = -cy * wall.height } + self.coords:add { + x = -cx * wall.width * 0.5, + y = -cy * wall.height * 0.5, + } if #newstate > 0 then self._state = newstate end From 6b42693eac3985cc39ca1a427cb508b5abe27412 Mon Sep 17 00:00:00 2001 From: apohle Date: Thu, 29 Dec 2011 16:01:20 +0100 Subject: [PATCH 30/57] flash enemy --- space/main.lua | 47 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/space/main.lua b/space/main.lua index bf75a77..f85755d 100644 --- a/space/main.lua +++ b/space/main.lua @@ -181,6 +181,17 @@ function Player:update() end end + if wall.input[2].left then + local enemy = Enemy { + source = env.enemys, + origin = env.player, + x = 3, + y = 3, + dir = {x=-0.05, y=-0.05}, + } + env.enemys[enemy] = enemy + end + for key, projectile in pairs(self.projectiles) do if key ~= "length" then projectile:update() @@ -246,6 +257,7 @@ Enemy = Object:new() function Enemy:init(opts) opts = opts or {} self.coords = Vector(opts) + self.flash = nil self.dir = Vector(opts.dir) self.color = opts.color or hex(180, 0, 0) self.away_color = opts.away_color or hex(60, 0, 0) @@ -253,15 +265,32 @@ function Enemy:init(opts) if not self.source then error("no source given") end + self.origin = opts.origin + if not self.origin then + error("no origin given") + end end function Enemy:update() - self.coords:add(self.dir) + if self.flash == nil then + if self.coords.x <= 0 and self.coords.y <= 0 then + self.flash = 10 + else + self.coords:add(self.dir) + end + end + if self.flash then + self.flash = self.flash - 1 + + if self.flash == 0 then + self.source[self] = nil + end + end end function Enemy:draw() - local pos = self.coords:clone():sub(self.source.coords):add(self.source.pos) + local pos = self.coords:clone():sub(self.origin.coords):add(self.origin.pos) local x,y x = inbound(pos.x, 1, wall.width) y = inbound(pos.y, 1, wall.height) @@ -344,7 +373,7 @@ function update() target:update() end - for _, enemy in ipairs(env.enemys or {}) do + for _, enemy in pairs(env.enemys or {}) do enemy:update() end @@ -365,7 +394,7 @@ function draw() target:draw() end - for _, enemy in ipairs(env.enemys or {}) do + for _, enemy in pairs(env.enemys or {}) do enemy:draw() end @@ -419,13 +448,15 @@ function love.load() y = 0, } - env.enemys = {} - env.enemys[1] = Enemy { - source = env.player, + env.enemys = setmetatable({}, { __mode = 'k'}) + local enemy = Enemy { + source = env.enemys, + origin = env.player, x = 3, y = 3, - dir = {x=-0.01, y=-0.01} + dir = {x=-0.05, y=-0.05}, } + env.enemys[enemy] = enemy end From e33b70d8a9e5d52e470d32cc4331e3614e91a4cc Mon Sep 17 00:00:00 2001 From: dodo Date: Thu, 29 Dec 2011 16:37:46 +0100 Subject: [PATCH 31/57] flash animation --- lib/framework.lua | 1 + space/main.lua | 30 ++++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/lib/framework.lua b/lib/framework.lua index bbd5391..cdd1ab7 100644 --- a/lib/framework.lua +++ b/lib/framework.lua @@ -2,6 +2,7 @@ require 'socket' math.randomseed(socket.gettime()*10000) +ceil = math.ceil floor = math.floor round = function (x) return floor(x+0.5) diff --git a/space/main.lua b/space/main.lua index 30a31ad..9a8784b 100644 --- a/space/main.lua +++ b/space/main.lua @@ -262,8 +262,10 @@ function Enemy:init(opts) self.coords = Vector(opts) self.flash = nil self.dir = Vector(opts.dir) + self.radius = opts.radius or 3 self.color = opts.color or hex(180, 0, 0) self.away_color = opts.away_color or hex(60, 0, 0) + self.flash_color = opts.flash_color or hex(180, 60, 0) self.source = opts.source if not self.source then error("no source given") @@ -295,13 +297,29 @@ end function Enemy:draw() local pos = self.coords:clone():sub(self.origin.coords):add(self.origin.pos) local x,y - x = inbound(pos.x, 1, wall.width) - y = inbound(pos.y, 1, wall.height) + x = inbound(pos.x, 1, wall.width) - 1 + y = inbound(pos.y, 1, wall.height) - 1 local color = self.color - if pos.x ~= x or pos.y ~= y then - color = self.away_color + if self.flash then + local r = self.radius/self.flash + color = self.flash_color + for ry = floor(y-r), ceil(y+r) do + if ry == inbound(ry, 0, wall.height-1) then + for rx = floor(x-r), ceil(x+r) do + if rx == inbound(rx, 0, wall.width-1) then + if Vector({x=rx,y=ry}):sub({x=x,y=y}):len() <= r then + wall:pixel(floor(rx), floor(ry), color) + end + end + end + end + end + else + if pos.x ~= x+1 or pos.y ~= y+1 then + color = self.away_color + end + wall:pixel(floor(x), floor(y), color) end - wall:pixel(floor(x-1), floor(y-1), color) end @@ -312,7 +330,7 @@ function Projectile:init(opts) opts = opts or {} self.pos = Vector(opts) self.dir = Vector(opts.dir) - self.color = opts.color or hex(180, 20, 0) + self.color = opts.color or hex(0, 80, 180) self.energy = opts.energy or 10 self.max_energy = self.energy self.life = nil -- will be set by parent From db3cbaaf84caa4b40b467a56d6201887f2b3cf11 Mon Sep 17 00:00:00 2001 From: apohle Date: Thu, 29 Dec 2011 16:51:24 +0100 Subject: [PATCH 32/57] random enemies --- space/main.lua | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/space/main.lua b/space/main.lua index f85755d..a3d982b 100644 --- a/space/main.lua +++ b/space/main.lua @@ -74,6 +74,10 @@ function Vector:mul(val) return self -- chainable end +function Vector:neg() + return self:mul(-1) +end + function Vector:dot(vec) return self.x * vec.x + self.y * vec.y end @@ -182,12 +186,16 @@ function Player:update() end if wall.input[2].left then + local speed = 0.05 + local start_x = R(5, 10) * shuffle({-1,1})[1] + local start_y = R(5, 10) * shuffle({-1,1})[1] + local enemy = Enemy { source = env.enemys, origin = env.player, - x = 3, - y = 3, - dir = {x=-0.05, y=-0.05}, + x = start_x, + y = start_y, + dir = Vector({ x = (R()-0.5), y = (R()-0.5) }):norm():mul(speed), } env.enemys[enemy] = enemy end @@ -276,6 +284,12 @@ function Enemy:update() if self.coords.x <= 0 and self.coords.y <= 0 then self.flash = 10 else + local speed = self.dir:len() + local to_targets = Vector(self.coords):add(env.targets.sum):neg():norm() + local away_from_player = Vector(env.player.coords):sub(self.coords):norm() + self.dir:add(to_targets):add(away_from_player):norm():mul(speed) + + --self.dir = Vector(self):norm():mul(speed), self.coords:add(self.dir) end end @@ -369,9 +383,12 @@ function update() env.player:update() + local sum = Vector() for _, target in ipairs(env.targets or {}) do target:update() + sum:add(target.coords) end + env.targets.sum = sum for _, enemy in pairs(env.enemys or {}) do enemy:update() @@ -441,7 +458,7 @@ function love.load() y = wall.height*0.5, } - env.targets = {} + env.targets = { sum = Vector() } env.targets[1] = Target { source = env.player, x = 0, From 4101bc32db611ecc31a56b73048f5728e00efa4d Mon Sep 17 00:00:00 2001 From: dodo Date: Thu, 29 Dec 2011 16:57:19 +0100 Subject: [PATCH 33/57] Vector:eq method --- lib/framework.lua | 1 + space/main.lua | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/lib/framework.lua b/lib/framework.lua index cdd1ab7..0f21f6a 100644 --- a/lib/framework.lua +++ b/lib/framework.lua @@ -2,6 +2,7 @@ require 'socket' math.randomseed(socket.gettime()*10000) +abs = math.abs ceil = math.ceil floor = math.floor round = function (x) diff --git a/space/main.lua b/space/main.lua index abf41f6..69c92b5 100644 --- a/space/main.lua +++ b/space/main.lua @@ -96,6 +96,11 @@ function Vector:norm() return self -- chainable end +function Vector:eq(vec, tolerance) + tolerance = tolerance or 0 + return abs(self.x - vec.x) <= tolerance and abs(self.y - vec.y) <= tolerance +end + -------------------------------------------------------------------------------- Star = Object:new() From 6b3a81e5511f3df2020718a819484c72131da0b8 Mon Sep 17 00:00:00 2001 From: apoh Date: Thu, 29 Dec 2011 17:14:56 +0100 Subject: [PATCH 34/57] enemies to target --- space/main.lua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/space/main.lua b/space/main.lua index 69c92b5..638d4ed 100644 --- a/space/main.lua +++ b/space/main.lua @@ -291,15 +291,19 @@ end function Enemy:update() if self.flash == nil then - if self.coords.x <= 0 and self.coords.y <= 0 then - self.flash = 10 - else + for _, target in ipairs(env.targets or {}) do + if self.coords:eq(target.coords, 0.1) then + self.flash = 10 + break + end + end + + if not self.flash then local speed = self.dir:len() - local to_targets = Vector(self.coords):add(env.targets.sum):neg():norm() - local away_from_player = Vector(env.player.coords):sub(self.coords):norm() + local to_targets = env.targets.sum:clone():sub(self.coords):norm() + local away_from_player = env.player.coords:clone():sub(self.coords):neg():norm():mul(0.1) self.dir:add(to_targets):add(away_from_player):norm():mul(speed) - --self.dir = Vector(self):norm():mul(speed), self.coords:add(self.dir) end end From fa02d0cbe70af7c22d7a8a58b20e86b6fd3b0c89 Mon Sep 17 00:00:00 2001 From: apoh Date: Thu, 29 Dec 2011 17:57:32 +0100 Subject: [PATCH 35/57] add enemies automaticly --- space/main.lua | 76 +++++++++++++++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 28 deletions(-) diff --git a/space/main.lua b/space/main.lua index 638d4ed..256159b 100644 --- a/space/main.lua +++ b/space/main.lua @@ -194,18 +194,7 @@ function Player:update() end if wall.input[2].left then - local speed = 0.05 - local start_x = R(5, 10) * shuffle({-1,1})[1] - local start_y = R(5, 10) * shuffle({-1,1})[1] - - local enemy = Enemy { - source = env.enemys, - origin = env.player, - x = start_x, - y = start_y, - dir = Vector({ x = (R()-0.5), y = (R()-0.5) }):norm():mul(speed), - } - env.enemys[enemy] = enemy + add_enemy() end for key, projectile in pairs(self.projectiles) do @@ -245,7 +234,7 @@ function Target:init(opts) opts = opts or {} self.coords = Vector(opts) self.color = opts.color or hex(0, 180, 0) - self.away_color = opts.away_color or hex(0, 60, 0) + self.away_color = opts.away_color or hex(0, 100, 0) self.source = opts.source if not self.source then error("no source given") @@ -277,7 +266,7 @@ function Enemy:init(opts) self.dir = Vector(opts.dir) self.radius = opts.radius or 3 self.color = opts.color or hex(180, 0, 0) - self.away_color = opts.away_color or hex(60, 0, 0) + self.away_color = opts.away_color or hex(100, 0, 0) self.flash_color = opts.flash_color or hex(180, 60, 0) self.source = opts.source if not self.source then @@ -290,10 +279,11 @@ function Enemy:init(opts) end function Enemy:update() + if self.flash == 0 then return end if self.flash == nil then for _, target in ipairs(env.targets or {}) do if self.coords:eq(target.coords, 0.1) then - self.flash = 10 + self.flash = 30 break end end @@ -313,11 +303,13 @@ function Enemy:update() if self.flash == 0 then self.source[self] = nil + env.enemys.length = env.enemys.length - 1 end end end function Enemy:draw() + if self.flash == 0 then return end local pos = self.coords:clone():sub(self.origin.coords):add(self.origin.pos) local x,y x = inbound(pos.x, 1, wall.width) - 1 @@ -344,6 +336,16 @@ function Enemy:draw() wall:pixel(floor(x), floor(y), color) end end +function Enemy:addEnemy() + local enemy = Enemy { + source = env.enemys, + origin = env.player, + x = start_x, + y = start_y, + dir = Vector({ x = (R()-0.5), y = (R()-0.5) }):norm():mul(speed), + } + env.enemys[enemy] = enemy +end -------------------------------------------------------------------------------- @@ -420,8 +422,14 @@ function update() end env.targets.sum = sum - for _, enemy in pairs(env.enemys or {}) do - enemy:update() + for key, enemy in pairs(env.enemys or {}) do + if key ~= "length" then + enemy:update() + end + end + + if env.enemys.length == 0 then + add_enemy() end tick = tick + 1 @@ -441,18 +449,37 @@ function draw() target:draw() end - for _, enemy in pairs(env.enemys or {}) do - enemy:draw() + for key, enemy in pairs(env.enemys or {}) do + if key ~= "length" then + enemy:draw() + end end env.player:draw() end +function add_enemy() + local speed = 0.05 + local start_x = R(5, 10) * shuffle({-1,1})[1] + local start_y = R(5, 10) * shuffle({-1,1})[1] + + local enemy = Enemy { + source = env.enemys, + origin = env.player, + x = start_x, + y = start_y, + dir = Vector({ x = (R()-0.5), y = (R()-0.5) }):norm():mul(speed), + } + env.enemys[enemy] = enemy + env.enemys.length = env.enemys.length + 1 +end + -------------------------------------------------------------------------------- function love.load() wall = Wall(false, 1338, 3, false) -- "176.99.24.251" + --wall = Wall('176.99.24.251', 1338, 3, false) -- "176.99.24.251" -- __maxd = math.sqrt(wall.width*wall.height) @@ -495,15 +522,8 @@ function love.load() y = 0, } - env.enemys = setmetatable({}, { __mode = 'k'}) - local enemy = Enemy { - source = env.enemys, - origin = env.player, - x = 3, - y = 3, - dir = {x=-0.05, y=-0.05}, - } - env.enemys[enemy] = enemy + env.enemys = setmetatable({length=0}, { __mode = 'k'}) + add_enemy() end From 23ce8beda1f0165bb1db79525de00956efbcecf4 Mon Sep 17 00:00:00 2001 From: dodo Date: Thu, 29 Dec 2011 18:55:18 +0100 Subject: [PATCH 36/57] thats a bug --- space/main.lua | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/space/main.lua b/space/main.lua index 638d4ed..94be359 100644 --- a/space/main.lua +++ b/space/main.lua @@ -156,10 +156,7 @@ function Player:update() local cx, cy self.pos.x, cx = inroundbound_with_count(self.pos.x, 0, wall.width) self.pos.y, cy = inroundbound_with_count(self.pos.y, 0, wall.height) - self.coords:add { - x = -cx * wall.width * 0.5, - y = -cy * wall.height * 0.5, - } + if #newstate > 0 then self._state = newstate end From 38889c219e5ab17cea92acfc2a3862d48c23c96f Mon Sep 17 00:00:00 2001 From: dodo Date: Thu, 29 Dec 2011 18:55:36 +0100 Subject: [PATCH 37/57] destroy methods --- space/main.lua | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/space/main.lua b/space/main.lua index 94be359..abf4595 100644 --- a/space/main.lua +++ b/space/main.lua @@ -309,11 +309,15 @@ function Enemy:update() self.flash = self.flash - 1 if self.flash == 0 then - self.source[self] = nil + self:destroy() end end end +function Enemy:destroy() + self.source[self] = nil +end + function Enemy:draw() local pos = self.coords:clone():sub(self.origin.coords):add(self.origin.pos) local x,y @@ -362,13 +366,20 @@ end function Projectile:update() if self.life == nil then return end + -- deceased? self.energy = self.energy - 1 if self.energy == 0 then - self.source.projectiles[self] = nil - self.source.projectiles.length = self.source.projectiles.length - 1 - self.life = nil -- delete, or just simply die - return + return self:destroy() + end + -- hit? + for _, enemy in ipairs(env.enemys or {}) do + if self.coords:eq(enemy.coords, 0.1) then + enemy:destroy() + self:destroy() + return + end end + -- direction local rel_energy = self.energy/self.max_energy if rel_energy > 0.2 then local dir = Vector() @@ -381,6 +392,12 @@ function Projectile:update() self.pos:add(self.dir) end +function Projectile:destroy() + self.source.projectiles[self] = nil + self.source.projectiles.length = self.source.projectiles.length - 1 + self.life = nil -- delete, or just simply die +end + function Projectile:draw() if self.life == nil then return end if self.pos.x == inbound(self.pos.x, 1, wall.width) and From 3406e1a32f13f3a91740d3dff4e5d4415d40060a Mon Sep 17 00:00:00 2001 From: dodo Date: Thu, 29 Dec 2011 18:59:34 +0100 Subject: [PATCH 38/57] typo --- space/main.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/space/main.lua b/space/main.lua index abf4595..08112f9 100644 --- a/space/main.lua +++ b/space/main.lua @@ -196,13 +196,13 @@ function Player:update() local start_y = R(5, 10) * shuffle({-1,1})[1] local enemy = Enemy { - source = env.enemys, + source = env.enemies, origin = env.player, x = start_x, y = start_y, dir = Vector({ x = (R()-0.5), y = (R()-0.5) }):norm():mul(speed), } - env.enemys[enemy] = enemy + env.enemies[enemy] = enemy end for key, projectile in pairs(self.projectiles) do @@ -372,7 +372,7 @@ function Projectile:update() return self:destroy() end -- hit? - for _, enemy in ipairs(env.enemys or {}) do + for _, enemy in ipairs(env.enemies or {}) do if self.coords:eq(enemy.coords, 0.1) then enemy:destroy() self:destroy() @@ -434,7 +434,7 @@ function update() end env.targets.sum = sum - for _, enemy in pairs(env.enemys or {}) do + for _, enemy in pairs(env.enemies or {}) do enemy:update() end @@ -455,7 +455,7 @@ function draw() target:draw() end - for _, enemy in pairs(env.enemys or {}) do + for _, enemy in pairs(env.enemies or {}) do enemy:draw() end @@ -509,15 +509,15 @@ function love.load() y = 0, } - env.enemys = setmetatable({}, { __mode = 'k'}) + env.enemies = setmetatable({}, { __mode = 'k'}) local enemy = Enemy { - source = env.enemys, + source = env.enemies, origin = env.player, x = 3, y = 3, dir = {x=-0.05, y=-0.05}, } - env.enemys[enemy] = enemy + env.enemies[enemy] = enemy end From 358f561c756c22818548f2f3c3b0688153069550 Mon Sep 17 00:00:00 2001 From: dodo Date: Thu, 29 Dec 2011 19:00:35 +0100 Subject: [PATCH 39/57] dont create first enemy --- space/main.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/space/main.lua b/space/main.lua index 08112f9..065d11d 100644 --- a/space/main.lua +++ b/space/main.lua @@ -510,14 +510,14 @@ function love.load() } env.enemies = setmetatable({}, { __mode = 'k'}) - local enemy = Enemy { - source = env.enemies, - origin = env.player, - x = 3, - y = 3, - dir = {x=-0.05, y=-0.05}, - } - env.enemies[enemy] = enemy +-- local enemy = Enemy { +-- source = env.enemies, +-- origin = env.player, +-- x = 3, +-- y = 3, +-- dir = {x=-0.05, y=-0.05}, +-- } +-- env.enemies[enemy] = enemy end From 7a5ee1fccb26fc5b82ee66b2132c29f060cd2c72 Mon Sep 17 00:00:00 2001 From: Johannes Kroll Date: Thu, 29 Dec 2011 21:23:30 +0100 Subject: [PATCH 40/57] random drops with water effect hacked on 28c3 day 3 :) --- drops/README.md | 4 + drops/SciTE.properties | 2 + drops/conf.lua | 9 ++ drops/helper.lua | 1 + drops/lust.lua | 1 + drops/main.lua | 195 +++++++++++++++++++++++++++++++++++++++++ drops/wall.lua | 1 + 7 files changed, 213 insertions(+) create mode 100644 drops/README.md create mode 100644 drops/SciTE.properties create mode 100644 drops/conf.lua create mode 120000 drops/helper.lua create mode 120000 drops/lust.lua create mode 100644 drops/main.lua create mode 120000 drops/wall.lua diff --git a/drops/README.md b/drops/README.md new file mode 100644 index 0000000..a59e51a --- /dev/null +++ b/drops/README.md @@ -0,0 +1,4 @@ +drops +==== + +some random drops with water effect hacked together on 28c3 day 3 :) diff --git a/drops/SciTE.properties b/drops/SciTE.properties new file mode 100644 index 0000000..41a142f --- /dev/null +++ b/drops/SciTE.properties @@ -0,0 +1,2 @@ +command.go.*.lua=love . +# lua5.1 "$(FileNameExt)" diff --git a/drops/conf.lua b/drops/conf.lua new file mode 100644 index 0000000..afe8d7c --- /dev/null +++ b/drops/conf.lua @@ -0,0 +1,9 @@ +function love.conf(t) + t.title = "drops" + t.author = "synaesthesin" + t.screen.width = 320 + t.screen.height = 300 + t.screen.vsync = false + t.modules.physics = false + t.modules.mouse = false +end diff --git a/drops/helper.lua b/drops/helper.lua new file mode 120000 index 0000000..039178c --- /dev/null +++ b/drops/helper.lua @@ -0,0 +1 @@ +../lib/helper.lua \ No newline at end of file diff --git a/drops/lust.lua b/drops/lust.lua new file mode 120000 index 0000000..f6e54d1 --- /dev/null +++ b/drops/lust.lua @@ -0,0 +1 @@ +../lib/lust.lua \ No newline at end of file diff --git a/drops/main.lua b/drops/main.lua new file mode 100644 index 0000000..16aa3b8 --- /dev/null +++ b/drops/main.lua @@ -0,0 +1,195 @@ +require "helper" +require "wall" + +require 'socket' +math.randomseed(socket.gettime()*10000) + +-- helpers + +function R(...) + return math.random(...) +end + +function hex(r,g,b) + if g == nil then + b = r.b + g = r.g + r = r.r + end + for _, c in pairs({r,g,b}) do c= inbound(c) end + return string.format("%.2x%.2x%.2x",math.sqrt(r)*255,math.sqrt(g)*255,math.sqrt(b)*255) +end + +function shuffle(t) + local n = #t + + while n >= 2 do + -- n is now the last pertinent index + local k = math.random(n) -- 1 <= k <= n + -- Quick swap + t[n], t[k] = t[k], t[n] + n = n - 1 + end + + return t +end + +function inbound(p, _min, _max) + if _min == nil then _min = 0 end + if _max == nil then _max = 1 end + if p > _max then p = _max elseif p < _min then p = _min end + return p +end + +function sqdist(a, b) + local x = b.x - a.x + local y = b.y - a.y + return x*x + y*y +end + +function dist(...) + return math.sqrt(sqdist(...)) +end + +-- values + +pix1= {} +pix2= {} +tick= 0 + +-------------------------------------------------------------------------------- + +function fade(buffer, step) + local w= wall.width + local h= wall.height + + for y= 1, h do + for x= 1, w do + buffer[y*w+x].r= inbound(buffer[y*w+x].r-step, 0, 1.0) + buffer[y*w+x].g= inbound(buffer[y*w+x].g-step, 0, 1.0) + buffer[y*w+x].b= inbound(buffer[y*w+x].b-step, 0, 1.0) + end + end +end + +function blur(buffer, dx, dy) + local w= wall.width + local h= wall.height + + local f0= 0.5+dx + local f1= 0.5-dx + local f2= 0.5+dy + local f3= 0.5-dy + local fx= -2 --- (math.sin(tick*0.014)*0.5 + 1) + local fa= .125 + local fb= .125 + local fc= .125 + local fd= .125 + + + for y= 1, h do + for x= 1, w do + for _, c in ipairs({ "r", "g" , "b" }) do + pix2[y*w+x][c]= inbound( (pix1[y*w+x-1][c]*f0 + pix1[y*w+x+1][c]*f1 + + pix1[(y-1)*w+x][c]*f2 + pix1[(y+1)*w+x][c]*f3 + + pix1[(y-1)*w+x-1][c]*fa + pix1[(y-1)*w+x+1][c]*fb + + pix1[(y+1)*w+x-1][c]*fc + pix1[(y+1)*w+x+1][c]*fd + + pix2[y*w+x][c]*fx) * .8, 0, 2.0) +-- pix2[y*w+x][c]*fx) * .2, -1, 2.0) + end + end + end +end + + +function update() + local w= wall.width + local h= wall.height + + blur(pix1, math.sin(tick*0.00649)*.05, math.cos(tick*.0127)*.051) + --fade(pix1, 1) + local p= pix1 + pix1= pix2 + pix2= p + + tick= tick+1 + + if tick%10 == 0 then + for i=1,2 do + local x= R(2, w-1) + local y= R(2, h-1) + for _, c in ipairs({"r", "g", "b"}) do + --print(pixels[y*w+x][c]) + pix1[y*w+x][c]= inbound(pix1[y*w+x][c] + R(0, 1), 0, 1.0) + end + end + end +end + +function draw() + local w= wall.width + local h= wall.height + + for y= 1, h do + for x= 1, w do + wall:pixel(x-1, y-1, hex(pix1[y*w+x])) + end + end +-- wall:pixel(x-1, y-1, hex(r,g,b)) +end + +-------------------------------------------------------------------------------- + +function love.load() + wall = Wall("176.99.24.251", 1338, 4) + + __maxd = math.sqrt(wall.width*wall.height) + + time = love.timer.getTime() * 1000 + + tick = 0 + + -- initialize + + local w= wall.width + local h= wall.height + + for y= -1, h+1 do + for x= -1, w+1 do + pix1[y*w+x+1]= { r=0, g=0, b=0 } + pix2[y*w+x+1]= { r=0, g=0, b=0 } + end + end +end + + +function love.keypressed(key) + w= 0 + if key == "escape" then + love.event.push "q" + elseif key == " " then + print("space") + w= w+1 + if w%2==0 then + wall:init() + else + wall:init("176.99.24.251", 1338, 4) + end + end +end + +function love.update(dt) + -- constant 30 FPS + local t = love.timer.getTime() * 1000 + time = time + 1000 / 30 + love.timer.sleep(time - t) + + update() +end + + +function love.draw() + draw() + -- send the stuff abroad + wall:draw() +end \ No newline at end of file diff --git a/drops/wall.lua b/drops/wall.lua new file mode 120000 index 0000000..d37ae93 --- /dev/null +++ b/drops/wall.lua @@ -0,0 +1 @@ +../lib/wall.lua \ No newline at end of file From 47007a56c19c581483a927786fa0e48a776d039f Mon Sep 17 00:00:00 2001 From: dodo Date: Fri, 30 Dec 2011 00:55:08 +0100 Subject: [PATCH 41/57] flexible consts --- space/main.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/space/main.lua b/space/main.lua index 065d11d..1015912 100644 --- a/space/main.lua +++ b/space/main.lua @@ -191,9 +191,10 @@ function Player:update() end if wall.input[2].left then + local r, range = 10, 20 local speed = 0.05 - local start_x = R(5, 10) * shuffle({-1,1})[1] - local start_y = R(5, 10) * shuffle({-1,1})[1] + local start_x = R(r, range) * shuffle({-1,1})[1] + local start_y = R(r, range) * shuffle({-1,1})[1] local enemy = Enemy { source = env.enemies, From 34a417021fbec8f717d36c81287a40aafa86d4d9 Mon Sep 17 00:00:00 2001 From: dodo Date: Fri, 30 Dec 2011 00:55:43 +0100 Subject: [PATCH 42/57] let enemies really die when hit --- space/main.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/space/main.lua b/space/main.lua index 1015912..200bba0 100644 --- a/space/main.lua +++ b/space/main.lua @@ -316,6 +316,7 @@ function Enemy:update() end function Enemy:destroy() + self.flash = 0 self.source[self] = nil end From b833a596f665625997d6feccd77dd0d33226f669 Mon Sep 17 00:00:00 2001 From: dodo Date: Fri, 30 Dec 2011 00:56:29 +0100 Subject: [PATCH 43/57] abs pos for projectile in collision check --- space/main.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/space/main.lua b/space/main.lua index 200bba0..db8cced 100644 --- a/space/main.lua +++ b/space/main.lua @@ -374,8 +374,9 @@ function Projectile:update() return self:destroy() end -- hit? - for _, enemy in ipairs(env.enemies or {}) do - if self.coords:eq(enemy.coords, 0.1) then + for _, enemy in pairs(env.enemies or {}) do + local c = self.source.coords:clone():sub(self.source.pos):add(self.pos) + if c:eq(enemy.coords, 1) then enemy:destroy() self:destroy() return From 6997a6629d0d47fe0909ee67b2247258f7c3525b Mon Sep 17 00:00:00 2001 From: dodo Date: Fri, 30 Dec 2011 00:56:58 +0100 Subject: [PATCH 44/57] stats --- space/main.lua | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/space/main.lua b/space/main.lua index db8cced..40022ea 100644 --- a/space/main.lua +++ b/space/main.lua @@ -8,6 +8,10 @@ nr = 32 env = { stars = {level=3}, } +stats = { + enemies = 0, + targets = 0, +} @@ -310,6 +314,7 @@ function Enemy:update() self.flash = self.flash - 1 if self.flash == 0 then + stats.targets = stats.targets + 1 self:destroy() end end @@ -357,7 +362,7 @@ function Projectile:init(opts) self.pos = Vector(opts) self.dir = Vector(opts.dir) self.color = opts.color or hex(0, 80, 180) - self.energy = opts.energy or 10 + self.energy = opts.energy or 15 self.max_energy = self.energy self.life = nil -- will be set by parent self.source = opts.source @@ -377,6 +382,7 @@ function Projectile:update() for _, enemy in pairs(env.enemies or {}) do local c = self.source.coords:clone():sub(self.source.pos):add(self.pos) if c:eq(enemy.coords, 1) then + stats.enemies = stats.enemies + 1 enemy:destroy() self:destroy() return @@ -528,6 +534,11 @@ function love.keypressed(key) if key == "escape" then love.event.push "q" end + if key == "escape" or key == "q" then + print("Statistics") + print("target hits:", stats.targets) + print("enemies killed:", stats.enemies) + end end function love.update(dt) From 84c3891c8ea32191ce765eb56a31e5d0fc42e1e4 Mon Sep 17 00:00:00 2001 From: dodo Date: Fri, 30 Dec 2011 01:36:20 +0100 Subject: [PATCH 45/57] greater range --- space/main.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/space/main.lua b/space/main.lua index 40022ea..f89525c 100644 --- a/space/main.lua +++ b/space/main.lua @@ -195,7 +195,7 @@ function Player:update() end if wall.input[2].left then - local r, range = 10, 20 + local r, range = 100, 200 local speed = 0.05 local start_x = R(r, range) * shuffle({-1,1})[1] local start_y = R(r, range) * shuffle({-1,1})[1] From d0488a8fdc76c7586463b25216c774e6168c8e85 Mon Sep 17 00:00:00 2001 From: dodo Date: Fri, 30 Dec 2011 01:37:09 +0100 Subject: [PATCH 46/57] targets have a higher priority in draw order (and therefor in the radar) --- space/main.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/space/main.lua b/space/main.lua index f89525c..d64a5c5 100644 --- a/space/main.lua +++ b/space/main.lua @@ -460,13 +460,14 @@ function draw() end end + for _, enemy in pairs(env.enemies or {}) do + enemy:draw() + end + for _, target in ipairs(env.targets or {}) do target:draw() end - for _, enemy in pairs(env.enemies or {}) do - enemy:draw() - end env.player:draw() From 9768223acfe4413028a53d144fa8e7fc0689281a Mon Sep 17 00:00:00 2001 From: apoh Date: Fri, 30 Dec 2011 04:14:19 +0100 Subject: [PATCH 47/57] first buggy sokobanimplementation --- sokoban/example_level.txt | 10 +++ sokoban/main.lua | 126 ++++++++++++++++++++++++++++++++++---- space/main.lua | 10 --- 3 files changed, 123 insertions(+), 23 deletions(-) create mode 100644 sokoban/example_level.txt diff --git a/sokoban/example_level.txt b/sokoban/example_level.txt new file mode 100644 index 0000000..0717f14 --- /dev/null +++ b/sokoban/example_level.txt @@ -0,0 +1,10 @@ +Microban 1 +#### +# .# +# ### +#*@ # +# $ # +# ### +#### +Title: Microban 1 +Author: David W Skinner diff --git a/sokoban/main.lua b/sokoban/main.lua index c5bd6fd..6507ff8 100644 --- a/sokoban/main.lua +++ b/sokoban/main.lua @@ -23,30 +23,127 @@ local operator = { Player = Object:new() function Player:init(opts) opts = opts or {} - self.pos = { x = 1, y=2 } + self.pos = { x = opts.x, y=opts.y } + self.old_pos = { x = opts.x, y=opts.y } + self.color = opts.color or hex( 255, 255, 255 ) end function Player:update() - local x, y = self.pos.x, self.pos.y - wall:pixel(round(x), round(y), self.color) + + + local old_pos = {x = self.pos.x, y = self.pos.y} + local dir = {x = 0, y = 0} + for cursor_dir, oc in pairs({left="-x", right="+x", up="-y", down="+y" }) do + if wall.input[1][cursor_dir] then + local o, c = oc:sub(1,1), oc:sub(2) + if c == 'x' then + if o == '-' then + dir.x = -1 + self.pos.x = self.pos.x - 1 + else + dir.x = 1 + self.pos.x = self.pos.x + 1 + end + elseif c == 'y' then + if o == '-' then + dir.y = -1 + self.pos.y = self.pos.y - 1 + else + dir.y = 1 + self.pos.y = self.pos.y + 1 + end + end + end + end + + local x, y = round(self.pos.x), round(self.pos.y) + + -- if next pixel is boulder don't move + if #env.level.level > 0 then + if env.level.level[x][y] == '#' then + self.pos.x = old_pos.x + self.pos.y = old_pos.y + end + end + + -- if next is boulder move boulder too + if env.level.boxes[x] and env.level.boxes[x][y] then + env.level.boxes[x][y] = false + local box_x = x + dir.x + local box_y = y + dir.y + env.level.boxes[box_x] = env.level.boxes[box_x] or {} + env.level.boxes[box_x][box_y] = true + end + + x, y = round(self.pos.x), round(self.pos.y) + -- remove old position + wall:pixel(round(old_pos.x), round(old_pos.y), hex(0,0,0)) + wall:pixel(x, y, self.color) + --end end function Player:draw() local x, y = self.pos.x, self.pos.y - wall:pixel(round(x), round(y), self.color) end -------------------------------------------------------------------------------- -function update() - wall:update_input() +Level = Object:new() +function Level:init(opts) + self.level_file = io.open('example_level.txt') + self.level = {} + self.boxes = {} + self.boulder_color = hex( 0, 0, 200 ) + self.box_color = hex( 200, 200, 0 ) + self.hole_color = hex( 80, 80, 0) + self.player = {x = 0, y = 0} - for y = 1, wall.height do - for x = 1, wall.width do - wall:pixel(x-1, y-1, hex(0,0,0)) +end + +function Level:update() + --redraw boxes + for x in pairs(self.boxes) do + for y in pairs(self.boxes[x]) do + if self.boxes[x][y] then + wall:pixel(x, y, self.box_color) + end end end +end + +function Level:draw(opts) + local pos_x = 0 + local pos_y = 0 + + for line in self.level_file:lines() do + for c in line:gmatch('.') do + pos_x = pos_x + 1 + self.level[pos_x] = self.level[pos_x] or {} + self.level[pos_x][pos_y] = c + if c == '#' then + wall:pixel(pos_x, pos_y, self.boulder_color) + elseif c == '$' then + wall:pixel(pos_x, pos_y, self.box_color) + self.boxes[pos_x] = self.boxes[pos_x] or {} + self.boxes[pos_x][pos_y] = true + elseif c == '.' then + wall:pixel(pos_x, pos_y, self.hole_color) + elseif c == '@' then + env.player.pos.x = pos_x + env.player.pos.y = pos_y + end + end + pos_x = 0 + pos_y = pos_y + 1 + end +end +-------------------------------------------------------------------------------- + +function update() + wall:update_input() + + env.level:update() env.player:update() tick = tick + 1 @@ -54,6 +151,7 @@ end function draw() + env.level:draw() env.player:draw() end @@ -62,17 +160,19 @@ end function love.load() wall = Wall(false, 1338, 3, false) -- "176.99.24.251" - --wall = Wall('176.99.24.251', 1338, 3, false) -- "176.99.24.251" + --wall = Wall('176.99.24.251', 1338, 2, false) -- "176.99.24.251" -- __maxd = math.sqrt(wall.width*wall.height) time = love.timer.getTime() * 1000 env.player = Player { - x = wall.width*0.5, - y = wall.height*0.5, + x = -1, + y = -1 } + env.level = Level {} + tick = 0 end @@ -86,7 +186,7 @@ end function love.update(dt) -- constant 30 FPS local t = love.timer.getTime() * 1000 - time = time + 1000 / 30 + time = time + 1000 / 13 love.timer.sleep(time - t) update() diff --git a/space/main.lua b/space/main.lua index 6240611..d34ce6d 100644 --- a/space/main.lua +++ b/space/main.lua @@ -443,7 +443,6 @@ function update() end env.targets.sum = sum -<<<<<<< HEAD for key, enemy in pairs(env.enemys or {}) do if key ~= "length" then enemy:update() @@ -452,10 +451,6 @@ function update() if env.enemys.length == 0 then add_enemy() -======= - for _, enemy in pairs(env.enemies or {}) do - enemy:update() ->>>>>>> 6997a6629d0d47fe0909ee67b2247258f7c3525b end tick = tick + 1 @@ -475,15 +470,10 @@ function draw() target:draw() end -<<<<<<< HEAD for key, enemy in pairs(env.enemys or {}) do if key ~= "length" then enemy:draw() end -======= - for _, enemy in pairs(env.enemies or {}) do - enemy:draw() ->>>>>>> 6997a6629d0d47fe0909ee67b2247258f7c3525b end env.player:draw() From e5c7119a0384745a9fbe68303e9457ff00ccaf29 Mon Sep 17 00:00:00 2001 From: Johannes Kroll Date: Fri, 30 Dec 2011 16:17:58 +0100 Subject: [PATCH 48/57] quick conway's game of life hack --- drops/main.lua | 11 +- life/README.md | 4 + life/SciTE.properties | 2 + life/conf.lua | 9 ++ life/helper.lua | 1 + life/lust.lua | 1 + life/main.lua | 261 ++++++++++++++++++++++++++++++++++++++++++ life/wall.lua | 1 + 8 files changed, 286 insertions(+), 4 deletions(-) create mode 100644 life/README.md create mode 100644 life/SciTE.properties create mode 100644 life/conf.lua create mode 120000 life/helper.lua create mode 120000 life/lust.lua create mode 100644 life/main.lua create mode 120000 life/wall.lua diff --git a/drops/main.lua b/drops/main.lua index 16aa3b8..c1bbe8d 100644 --- a/drops/main.lua +++ b/drops/main.lua @@ -102,11 +102,12 @@ function blur(buffer, dx, dy) end +nextdrops= 0 function update() local w= wall.width local h= wall.height - blur(pix1, math.sin(tick*0.00649)*.05, math.cos(tick*.0127)*.051) + blur(pix1, math.sin(tick*0.00649)*.1, math.cos(tick*.0127)*.1) --fade(pix1, 1) local p= pix1 pix1= pix2 @@ -114,8 +115,9 @@ function update() tick= tick+1 - if tick%10 == 0 then - for i=1,2 do + + if tick>nextdrops then + for i=1,R(1,2) do local x= R(2, w-1) local y= R(2, h-1) for _, c in ipairs({"r", "g", "b"}) do @@ -123,6 +125,7 @@ function update() pix1[y*w+x][c]= inbound(pix1[y*w+x][c] + R(0, 1), 0, 1.0) end end + nextdrops= R(tick+10, tick+200) end end @@ -141,7 +144,7 @@ end -------------------------------------------------------------------------------- function love.load() - wall = Wall("176.99.24.251", 1338, 4) + wall = Wall("176.99.24.251", 1338, 1) __maxd = math.sqrt(wall.width*wall.height) diff --git a/life/README.md b/life/README.md new file mode 100644 index 0000000..d1d4dd7 --- /dev/null +++ b/life/README.md @@ -0,0 +1,4 @@ +life +==== + +game of life. 28c3 day 4 diff --git a/life/SciTE.properties b/life/SciTE.properties new file mode 100644 index 0000000..41a142f --- /dev/null +++ b/life/SciTE.properties @@ -0,0 +1,2 @@ +command.go.*.lua=love . +# lua5.1 "$(FileNameExt)" diff --git a/life/conf.lua b/life/conf.lua new file mode 100644 index 0000000..43aae2c --- /dev/null +++ b/life/conf.lua @@ -0,0 +1,9 @@ +function love.conf(t) + t.title = "life" + t.author = "synaesthesin" + t.screen.width = 320 + t.screen.height = 300 + t.screen.vsync = false + t.modules.physics = false + t.modules.mouse = false +end diff --git a/life/helper.lua b/life/helper.lua new file mode 120000 index 0000000..039178c --- /dev/null +++ b/life/helper.lua @@ -0,0 +1 @@ +../lib/helper.lua \ No newline at end of file diff --git a/life/lust.lua b/life/lust.lua new file mode 120000 index 0000000..f6e54d1 --- /dev/null +++ b/life/lust.lua @@ -0,0 +1 @@ +../lib/lust.lua \ No newline at end of file diff --git a/life/main.lua b/life/main.lua new file mode 100644 index 0000000..1696ce3 --- /dev/null +++ b/life/main.lua @@ -0,0 +1,261 @@ +require "helper" +require "wall" + +require 'socket' +math.randomseed(socket.gettime()*10000) + +-- helpers + +function R(...) + return math.random(...) +end + +function hex(r,g,b) + if g == nil then + b = r.b + g = r.g + r = r.r + end + for _, c in pairs({r,g,b}) do c= inbound(c) end + return string.format("%.2x%.2x%.2x",math.sqrt(r)*255,math.sqrt(g)*255,math.sqrt(b)*255) +end + +function shuffle(t) + local n = #t + + while n >= 2 do + -- n is now the last pertinent index + local k = math.random(n) -- 1 <= k <= n + -- Quick swap + t[n], t[k] = t[k], t[n] + n = n - 1 + end + + return t +end + +function inbound(p, _min, _max) + if _min == nil then _min = 0 end + if _max == nil then _max = 1 end + if p > _max then p = _max elseif p < _min then p = _min end + return p +end + +function sqdist(a, b) + local x = b.x - a.x + local y = b.y - a.y + return x*x + y*y +end + +function dist(...) + return math.sqrt(sqdist(...)) +end + +-- values + +pix1= {} +pix2= {} +tick= 0 + +-------------------------------------------------------------------------------- + +function fade(buffer, step) + local w= wall.width + local h= wall.height + + for y= 1, h do + for x= 1, w do + buffer[y*w+x].r= inbound(buffer[y*w+x].r-step, 0, 1.0) + buffer[y*w+x].g= inbound(buffer[y*w+x].g-step, 0, 1.0) + buffer[y*w+x].b= inbound(buffer[y*w+x].b-step, 0, 1.0) + end + end +end + +function blur(pix1, pix2, dx, dy) + local w= wall.width + local h= wall.height + + local f0= 0.25+dx + local f1= 0.25-dx + local f2= 0.25+dy + local f3= 0.25-dy + local fx= -.25 --- (math.sin(tick*0.014)*0.5 + 1) + local fa= .125 + local fb= .125 + local fc= .125 + local fd= .125 + + + for y= 1, h do + for x= 1, w do + for _, c in ipairs({ "r", "g" , "b" }) do + pix2[y*w+x][c]= inbound( (pix1[y*w+x-1][c]*f0 + pix1[y*w+x+1][c]*f1 + + pix1[(y-1)*w+x][c]*f2 + pix1[(y+1)*w+x][c]*f3 + + pix1[(y-1)*w+x-1][c]*fa + pix1[(y-1)*w+x+1][c]*fb + + pix1[(y+1)*w+x-1][c]*fc + pix1[(y+1)*w+x+1][c]*fd + + pix2[y*w+x][c]*fx) * .6, 0, 2.0) +-- pix2[y*w+x][c]*fx) * .2, -1, 2.0) + end + pix2[y*w+x].alive= pix1[y*w+x].alive + end + end +end + + +function life(buf1, buf2) + local w= wall.width + local h= wall.height + + local neighborcount= {} + + local aliveTotal= 0 + + for y= 0, h do + for x= 0, w do + neighborcount[y*w+x+1]= 0 + for _, o in ipairs({ {-1,-1}, { 0,-1}, { 1,-1}, + {-1, 0}, { 1, 0}, + {-1, 1}, { 0, 1}, { 1, 1}}) do + if buf1[(y+o[1])*w+x+o[2]+1].alive==1 then neighborcount[y*w+x+1]= neighborcount[y*w+x+1]+1 end + end + end + end + for y= 0, h do + for x= 0, w do + buf2[y*w+x+1]= { r= buf1[y*w+x+1].r, g= buf1[y*w+x+1].g, b= buf1[y*w+x+1].b, alive= buf1[y*w+x+1].alive } + + local neighbors= neighborcount[y*w+x+1] + local alive= buf2[y*w+x+1].alive + +-- Any live cell with fewer than two live neighbours dies, as if caused by under-population. + if neighbors<2 and alive~=0 then + buf2[y*w+x+1].alive= 0 --= { r=.5,g=0,b=0, alive=0 } + end +-- Any live cell with two or three live neighbours lives on to the next generation. + if (neighbors==2 or neighbors==3) and alive~=0 then + buf2[y*w+x+1].alive= 1 --= { r=1,g=1,b=1, alive=1 } + end +-- Any live cell with more than three live neighbours dies, as if by overcrowding. + if neighbors>3 and alive~=0 then + buf2[y*w+x+1].alive= 0 --= { r=0,g=0,b=0, alive=0 } + end +-- Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction. + if neighbors==3 and alive==0 then + buf2[y*w+x+1]= { r=1,g=1,b=1, alive=1 } + end + + if buf2[y*w+x+1].alive==1 then aliveTotal= aliveTotal+1 end + end + end + + return aliveTotal +end + +lastAlive= 0 +curAlive= 0 + +nextdrops= 0 +function update() + local w= wall.width + local h= wall.height + + -- blur(pix1, pix2, math.sin(tick*0.00649)*.1, math.cos(tick*.0127)*.1) + if tick%3==0 then + lastAlive= curAlive + curAlive= life(pix1, pix2) + end + --fade(pix2, .1) +-- blur(pix1, pix2, 0, 0) + fade(pix2, .1) + local p= pix1 + pix1= pix2 + pix2= p + + + tick= tick+1 + + + if tick>nextdrops then + if math.abs(curAlive-lastAlive)<2 or tick>nextdrops+1000 then + for i=1,R(1,15) do + local x= R(1, w) + local y= R(1, h) + for _, c in ipairs({"r", "g", "b"}) do + --print(pixels[y*w+x][c]) + pix1[y*w+x][c]= inbound(pix1[y*w+x][c] + R(.5, .5), 0, 1.0) + end + pix1[y*w+x].alive= 1 + end + nextdrops= tick+5 --R(tick+1, tick+1) + end + end +end + +function draw() + local w= wall.width + local h= wall.height + + for y= 1, h do + for x= 1, w do + wall:pixel(x-1, y-1, hex(pix1[y*w+x])) + end + end +-- wall:pixel(x-1, y-1, hex(r,g,b)) +end + +-------------------------------------------------------------------------------- + +function love.load() + wall = Wall("176.99.24.251", 1338, 2) + + __maxd = math.sqrt(wall.width*wall.height) + + time = love.timer.getTime() * 1000 + + tick = 0 + + -- initialize + + local w= wall.width + local h= wall.height + + for y= -1, h+1 do + for x= -1, w+1 do + pix1[y*w+x+1]= { r=0, g=0, b=0 } + pix2[y*w+x+1]= { r=0, g=0, b=0 } + end + end +end + + +function love.keypressed(key) + w= 0 + if key == "escape" then + love.event.push "q" + elseif key == " " then + print("space") + w= w+1 + if w%2==0 then + wall:init() + else + wall:init("176.99.24.251", 1338, 4) + end + end +end + +function love.update(dt) + -- constant 30 FPS + local t = love.timer.getTime() * 1000 + time = time + 1000 / 30 + love.timer.sleep(time - t) + + update() +end + + +function love.draw() + draw() + -- send the stuff abroad + wall:draw() +end \ No newline at end of file diff --git a/life/wall.lua b/life/wall.lua new file mode 120000 index 0000000..d37ae93 --- /dev/null +++ b/life/wall.lua @@ -0,0 +1 @@ +../lib/wall.lua \ No newline at end of file From 384c61f4f61ebe3ab60a4cb4b57f69db98637110 Mon Sep 17 00:00:00 2001 From: apoh Date: Fri, 30 Dec 2011 17:23:18 +0100 Subject: [PATCH 49/57] collisiondetection for boxes --- sokoban/main.lua | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/sokoban/main.lua b/sokoban/main.lua index 6507ff8..41ea7ea 100644 --- a/sokoban/main.lua +++ b/sokoban/main.lua @@ -39,42 +39,52 @@ function Player:update() if c == 'x' then if o == '-' then dir.x = -1 - self.pos.x = self.pos.x - 1 else dir.x = 1 - self.pos.x = self.pos.x + 1 end elseif c == 'y' then if o == '-' then dir.y = -1 - self.pos.y = self.pos.y - 1 else dir.y = 1 - self.pos.y = self.pos.y + 1 end end end end + self.pos.x = self.pos.x + dir.x + self.pos.y = self.pos.y + dir.y + local x, y = round(self.pos.x), round(self.pos.y) + local reset_player = false -- if next pixel is boulder don't move if #env.level.level > 0 then if env.level.level[x][y] == '#' then - self.pos.x = old_pos.x - self.pos.y = old_pos.y + reset_player = true end end -- if next is boulder move boulder too if env.level.boxes[x] and env.level.boxes[x][y] then - env.level.boxes[x][y] = false + -- calculate next position of box local box_x = x + dir.x local box_y = y + dir.y - env.level.boxes[box_x] = env.level.boxes[box_x] or {} - env.level.boxes[box_x][box_y] = true + -- if box is movebal move :) + if env.level.level[box_x][box_y] ~= '#' then + env.level.boxes[x][y] = false + env.level.boxes[box_x] = env.level.boxes[box_x] or {} + env.level.boxes[box_x][box_y] = true + else + reset_player = true + end end + -- dont move the player if some unallowed movement occured + if reset_player then + self.pos.x = old_pos.x + self.pos.y = old_pos.y + end x, y = round(self.pos.x), round(self.pos.y) -- remove old position wall:pixel(round(old_pos.x), round(old_pos.y), hex(0,0,0)) From 7416460e2abb4f39fb3b75f7d3417d2c8e01bd19 Mon Sep 17 00:00:00 2001 From: apoh Date: Fri, 30 Dec 2011 17:38:00 +0100 Subject: [PATCH 50/57] gamelogic ready --- sokoban/example_level.txt | 4 ++-- sokoban/main.lua | 28 ++++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/sokoban/example_level.txt b/sokoban/example_level.txt index 0717f14..21d0882 100644 --- a/sokoban/example_level.txt +++ b/sokoban/example_level.txt @@ -1,7 +1,7 @@ Microban 1 #### -# .# -# ### +# # +# .### #*@ # # $ # # ### diff --git a/sokoban/main.lua b/sokoban/main.lua index 41ea7ea..76265ee 100644 --- a/sokoban/main.lua +++ b/sokoban/main.lua @@ -25,7 +25,7 @@ function Player:init(opts) opts = opts or {} self.pos = { x = opts.x, y=opts.y } self.old_pos = { x = opts.x, y=opts.y } - self.color = opts.color or hex( 255, 255, 255 ) + self.color = opts.color or hex( 200, 200, 200 ) end function Player:update() @@ -103,18 +103,30 @@ function Level:init(opts) self.level_file = io.open('example_level.txt') self.level = {} self.boxes = {} - self.boulder_color = hex( 0, 0, 200 ) + self.holes = {} + self.boulder_color = hex( 0, 0, 150 ) self.box_color = hex( 200, 200, 0 ) - self.hole_color = hex( 80, 80, 0) + self.hole_color = hex( 150, 0, 0) + self.filled_color = hex( 0, 150, 0) self.player = {x = 0, y = 0} end function Level:update() + --redraw holes + for x in pairs(self.holes) do + for y in pairs(self.holes[x]) do + if self.holes[x][y] then + wall:pixel(x, y, self.hole_color) + end + end + end --redraw boxes for x in pairs(self.boxes) do for y in pairs(self.boxes[x]) do - if self.boxes[x][y] then + if self.boxes[x][y] and self.holes[x] and self.holes[x][y] then + wall:pixel(x, y, self.filled_color) + elseif self.boxes[x][y] then wall:pixel(x, y, self.box_color) end end @@ -138,6 +150,14 @@ function Level:draw(opts) self.boxes[pos_x][pos_y] = true elseif c == '.' then wall:pixel(pos_x, pos_y, self.hole_color) + self.holes[pos_x] = self.holes[pos_x] or {} + self.holes[pos_x][pos_y] = true + elseif c == '*' then + wall:pixel(pos_x, pos_y, self.box_color) + self.holes[pos_x] = self.holes[pos_x] or {} + self.holes[pos_x][pos_y] = true + self.boxes[pos_x] = self.boxes[pos_x] or {} + self.boxes[pos_x][pos_y] = true elseif c == '@' then env.player.pos.x = pos_x env.player.pos.y = pos_y From 9699c6fd2ae34f3481fb28f107ddeed6a8140694 Mon Sep 17 00:00:00 2001 From: apoh Date: Sat, 31 Dec 2011 14:09:15 +0100 Subject: [PATCH 51/57] fixed boxesbug --- sokoban/example_level.txt | 6 +++--- sokoban/example_level2.txt | 11 +++++++++++ sokoban/main.lua | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 sokoban/example_level2.txt diff --git a/sokoban/example_level.txt b/sokoban/example_level.txt index 21d0882..27f5762 100644 --- a/sokoban/example_level.txt +++ b/sokoban/example_level.txt @@ -1,8 +1,8 @@ Microban 1 #### -# # -# .### -#*@ # +# .# +# @### +#* # # $ # # ### #### diff --git a/sokoban/example_level2.txt b/sokoban/example_level2.txt new file mode 100644 index 0000000..1c3241e --- /dev/null +++ b/sokoban/example_level2.txt @@ -0,0 +1,11 @@ + #### +#### ## +# $ # +# *** # +# . . ## +## * * # + ##*** # + # $ ### + # @ # + ##### +; Connection diff --git a/sokoban/main.lua b/sokoban/main.lua index 76265ee..5ef40d5 100644 --- a/sokoban/main.lua +++ b/sokoban/main.lua @@ -71,7 +71,7 @@ function Player:update() local box_x = x + dir.x local box_y = y + dir.y -- if box is movebal move :) - if env.level.level[box_x][box_y] ~= '#' then + if env.level.level[box_x][box_y] ~= '#' and not (env.level.boxes[box_x] and env.level.boxes[box_x][box_y]) then env.level.boxes[x][y] = false env.level.boxes[box_x] = env.level.boxes[box_x] or {} env.level.boxes[box_x][box_y] = true From 80c9b47c7629a283b066181674b76b7a4e8c6004 Mon Sep 17 00:00:00 2001 From: apoh Date: Sat, 31 Dec 2011 14:33:16 +0100 Subject: [PATCH 52/57] multiple keydownevents when key is pressed fixed --- sokoban/main.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/sokoban/main.lua b/sokoban/main.lua index 5ef40d5..9815f5e 100644 --- a/sokoban/main.lua +++ b/sokoban/main.lua @@ -7,6 +7,10 @@ require "framework" env = { } +-- this value is used for blocing new keyentrys +block_keyevents = false + + -- helpervalues -- local __maxbound = 1.5 @@ -34,7 +38,8 @@ function Player:update() local old_pos = {x = self.pos.x, y = self.pos.y} local dir = {x = 0, y = 0} for cursor_dir, oc in pairs({left="-x", right="+x", up="-y", down="+y" }) do - if wall.input[1][cursor_dir] then + if wall.input[1][cursor_dir] and not block_keyevents then + block_keyevents = true local o, c = oc:sub(1,1), oc:sub(2) if c == 'x' then if o == '-' then @@ -213,10 +218,14 @@ function love.keypressed(key) end end +function love.keyreleased(key) + block_keyevents = false +end + function love.update(dt) -- constant 30 FPS local t = love.timer.getTime() * 1000 - time = time + 1000 / 13 + time = time + 1000 / 30 love.timer.sleep(time - t) update() From e13f3037ab20c5c4406451bf88ff3c3d47b847ab Mon Sep 17 00:00:00 2001 From: apoh Date: Mon, 2 Jan 2012 14:34:11 +0100 Subject: [PATCH 53/57] now with mor the one level --- sokoban/README.md | 16 ++- sokoban/example_level.txt | 10 -- sokoban/example_level2.txt | 11 -- sokoban/level.txt | 247 +++++++++++++++++++++++++++++++++++++ sokoban/main.lua | 59 +++++++-- 5 files changed, 312 insertions(+), 31 deletions(-) delete mode 100644 sokoban/example_level.txt delete mode 100644 sokoban/example_level2.txt create mode 100644 sokoban/level.txt diff --git a/sokoban/README.md b/sokoban/README.md index cf35bc1..9921433 100644 --- a/sokoban/README.md +++ b/sokoban/README.md @@ -1,4 +1,14 @@ -space -===== +# Wall-E Sokoban -??? +Play Sokoban on 16x16 multicolor matrix + +## Usage +Start game with + love . + +To play at the wall enter ip-adrress in line ~234. More usefull workaround will come. + +## Commands + * n - next Level + * r - restart current level + * u - undow move (not implemented yet) diff --git a/sokoban/example_level.txt b/sokoban/example_level.txt deleted file mode 100644 index 27f5762..0000000 --- a/sokoban/example_level.txt +++ /dev/null @@ -1,10 +0,0 @@ -Microban 1 -#### -# .# -# @### -#* # -# $ # -# ### -#### -Title: Microban 1 -Author: David W Skinner diff --git a/sokoban/example_level2.txt b/sokoban/example_level2.txt deleted file mode 100644 index 1c3241e..0000000 --- a/sokoban/example_level2.txt +++ /dev/null @@ -1,11 +0,0 @@ - #### -#### ## -# $ # -# *** # -# . . ## -## * * # - ##*** # - # $ ### - # @ # - ##### -; Connection diff --git a/sokoban/level.txt b/sokoban/level.txt new file mode 100644 index 0000000..c444d37 --- /dev/null +++ b/sokoban/level.txt @@ -0,0 +1,247 @@ +; Example Level for Wall-E Sokoban (parts of level http://www.sourcecode.se/sokoban/levtext.php?file=100Boxes.slc) + +; Copyright: Péter Asztalos +; E-Mail: m-forum@m-forum.hu +; Web Site: http://m-forum.hu/sokoban.php +; +; + +#### +# .# +# @### +#* # +# $ # +# ### +#### +; Microban 1 + + #### + # # + # # + #$.# +#### # +# # +#@$. # +####### +; Level 1 + +######## +# # # +# $ # +# #$$ # +## # # +#.. $# # +#.. @# +######## +; Level 2 + +####### +# # +# $ $ # +# $ $@# +# $$ ## +# ...# +###...# + ##### +; Level 3 + + ######## + # @# # + # $ $ # + #$ ####### +## $# # +#. . . # +#. ####### +##### +; Level 4 + +######### +# #@ # +# # # $## +# $ # +## $ # # # +#...## # +########## +; Level 5 + +########### +# @# +# #$ $ $ # +# # $$$$ # +# #$ $ $ # +# # $ # +# #$### ### +# # #.....# +# # #. .# +# .....# +########### +; Level 6 + + ############## + # # + # $ $ $ $ $ # + # # $ #####$ # + # #$ #..#...# + # $ #..#.*.# +## #####..#..## +# ##..# +# $ $ $@$ $$ # +########### # + ##### + +; Level 7 + ##### + #. # + # $@# + #. ## +### ######### +# $ $ $ $ # +# $ # +# ####### ### +#. $ ..# +######## ..# + ##### +; Level 8 + + ######## + # # + # $ # +#### #*#$ # +#... *+.$ # +#.*# #*# # +#. # $ # +# $$ $ # +# ######## +#### +; Level 9 + + ########### + # # + # $ ####$# +## ####....# +# $ #....# +# $$ #.. # +## @$ ### # + # $$ $ $ # + # # # + ########### +; Level 10 + +#### +# ########## +# $$ $ #....# +# #....# +# $$# ....# +# $ @ # ..# +# $##### #### +## # #$ # +# # $$ $ # +# $ #$$ # +# # # # +############ +; Level 11 + +######## +# . # ##### +# .$# $# # +##. # ...# + # $# $##### + # # # + # $# $# + # # + #@ # # + # # # + ####### +; Level 12 + +############# +# # +# $$ # # $$ # +# $$...$$ # +# ##.## # +# .*.....*. # +# ###.### # +#### $.$ #### + # $$$ # + # @ # + ####### +; Level 13 + +############# +# # +# $$ $ $ $ ### +# $######## # +# #.......$ # +# #$$......# # +#@ # ## ### ## +### # # # +# $ # $ # +# #$#$ ### # +# # # ###### +######## +; Level 16 + +######## +#@ .## +# #. # +# $$ #. # +# #.$# +###$##$ ##### +# . $ # +#..# $ $$ # +#..#### ### # +# . $ # +# ########## +#### +; Level 17 + +#### ##### +# ###### # +# $$ $ # +# ###### $ # +## #.*.* $ # +# $....# $ # +# #....#$@ # +# $###### $ # +# # +############# +; Level 18 + + ####### +####### # # +# # # # +# $ $ # # ## +# $$ ### ## # +# $$ #....# # +# $# #....# # +# # ###$### ## +# $ $ $... #$ # +# #$ #...$ # +# #@ ###### # +####### #### +; Level 19 + + #### #### +#### #### ## +# $ # $ # +# .#.#.$ # # +# $*..# #$$## +# ###... $ # +# $ $....#$ # +# #$$# # # +#@ ######## +####### +; Level 21 + +########## +# # # +# # $ # +# $.# $ # +# ..*.#### +##$#.*.* # +# $.#.$ # +# $ # $ # +# # @# +########## +; Level 24 + diff --git a/sokoban/main.lua b/sokoban/main.lua index 9815f5e..f501b0e 100644 --- a/sokoban/main.lua +++ b/sokoban/main.lua @@ -9,8 +9,7 @@ env = { -- this value is used for blocing new keyentrys block_keyevents = false - - +level_stack = {} -- helpervalues -- local __maxbound = 1.5 @@ -34,7 +33,6 @@ end function Player:update() - local old_pos = {x = self.pos.x, y = self.pos.y} local dir = {x = 0, y = 0} for cursor_dir, oc in pairs({left="-x", right="+x", up="-y", down="+y" }) do @@ -105,14 +103,16 @@ end Level = Object:new() function Level:init(opts) - self.level_file = io.open('example_level.txt') + self.level_size = {x = 16, y = 16} self.level = {} self.boxes = {} self.holes = {} + self.current_level = 1 self.boulder_color = hex( 0, 0, 150 ) self.box_color = hex( 200, 200, 0 ) self.hole_color = hex( 150, 0, 0) self.filled_color = hex( 0, 150, 0) + self.background_color = hex( 0, 0, 0) self.player = {x = 0, y = 0} end @@ -142,7 +142,17 @@ function Level:draw(opts) local pos_x = 0 local pos_y = 0 - for line in self.level_file:lines() do + -- redraw whole screen + self.level = {} + self.boxes = {} + self.holes = {} + for x = 0, self.level_size['x'] do + for y = 0, self.level_size['y'] do + wall:pixel(x, y, self.background_color) + end + end + + for _, line in ipairs(level_stack[self.current_level]) do for c in line:gmatch('.') do pos_x = pos_x + 1 self.level[pos_x] = self.level[pos_x] or {} @@ -173,6 +183,15 @@ function Level:draw(opts) end end +function Level:nextLevel(opts) + self.current_level = (self.current_level) % #level_stack + 1 + self:draw() +end + +function Level:restartLevel(opts) + self:draw() +end + -------------------------------------------------------------------------------- function update() @@ -186,7 +205,6 @@ end function draw() - env.level:draw() env.player:draw() end @@ -194,6 +212,25 @@ end -------------------------------------------------------------------------------- function love.load() + local level_file = io.open('level.txt') + + + local i = 0 + local level_counter = 0 + for line in level_file:lines() do + -- first 6 lines are copyright informations + if i > 6 then + -- empty line means new level + if line == '' then + level_counter = level_counter + 1 + else + level_stack[level_counter] = level_stack[level_counter] or {} + table.insert(level_stack[level_counter], line) + end + end + i = i + 1 + end + wall = Wall(false, 1338, 3, false) -- "176.99.24.251" --wall = Wall('176.99.24.251', 1338, 2, false) -- "176.99.24.251" @@ -208,6 +245,8 @@ function love.load() env.level = Level {} + env.level:draw() + tick = 0 end @@ -216,6 +255,12 @@ function love.keypressed(key) if key == "escape" then love.event.push "q" end + if key == "n" then + env.level:nextLevel() + end + if key == "r" then + env.level:restartLevel() + end end function love.keyreleased(key) @@ -225,7 +270,7 @@ end function love.update(dt) -- constant 30 FPS local t = love.timer.getTime() * 1000 - time = time + 1000 / 30 + time = time + 1000 / 23 love.timer.sleep(time - t) update() From 23cb91d309240b1ed4c89beed643916ce5ba9861 Mon Sep 17 00:00:00 2001 From: apoh Date: Mon, 2 Jan 2012 14:45:44 +0100 Subject: [PATCH 54/57] bugfix leveldrawing --- sokoban/main.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sokoban/main.lua b/sokoban/main.lua index f501b0e..c5211c0 100644 --- a/sokoban/main.lua +++ b/sokoban/main.lua @@ -154,7 +154,6 @@ function Level:draw(opts) for _, line in ipairs(level_stack[self.current_level]) do for c in line:gmatch('.') do - pos_x = pos_x + 1 self.level[pos_x] = self.level[pos_x] or {} self.level[pos_x][pos_y] = c if c == '#' then @@ -177,6 +176,7 @@ function Level:draw(opts) env.player.pos.x = pos_x env.player.pos.y = pos_y end + pos_x = pos_x + 1 end pos_x = 0 pos_y = pos_y + 1 From 5a60e8b3f6e91d7e53698f11a773e5408c601897 Mon Sep 17 00:00:00 2001 From: apoh Date: Mon, 2 Jan 2012 16:22:07 +0100 Subject: [PATCH 55/57] place level in the middle of the matrix --- sokoban/main.lua | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/sokoban/main.lua b/sokoban/main.lua index c5211c0..f4c5dbb 100644 --- a/sokoban/main.lua +++ b/sokoban/main.lua @@ -90,7 +90,7 @@ function Player:update() end x, y = round(self.pos.x), round(self.pos.y) -- remove old position - wall:pixel(round(old_pos.x), round(old_pos.y), hex(0,0,0)) + wall:pixel(round(old_pos.x), round(old_pos.y), env.level.background_color) wall:pixel(x, y, self.color) --end end @@ -112,7 +112,7 @@ function Level:init(opts) self.box_color = hex( 200, 200, 0 ) self.hole_color = hex( 150, 0, 0) self.filled_color = hex( 0, 150, 0) - self.background_color = hex( 0, 0, 0) + self.background_color = hex(0, 0, 0) self.player = {x = 0, y = 0} end @@ -152,6 +152,12 @@ function Level:draw(opts) end end + -- place the level in the middle of the field + local start_pos_x = math.floor((self.level_size.x - level_stack[self.current_level]['width']) / 2 ) + pos_x = start_pos_x + local start_pos_y = math.floor((self.level_size.y - level_stack[self.current_level]['height']) / 2 ) + pos_y = start_pos_y + for _, line in ipairs(level_stack[self.current_level]) do for c in line:gmatch('.') do self.level[pos_x] = self.level[pos_x] or {} @@ -178,7 +184,7 @@ function Level:draw(opts) end pos_x = pos_x + 1 end - pos_x = 0 + pos_x = start_pos_x pos_y = pos_y + 1 end end @@ -217,15 +223,20 @@ function love.load() local i = 0 local level_counter = 0 + local current_level_height = 0 for line in level_file:lines() do -- first 6 lines are copyright informations if i > 6 then -- empty line means new level if line == '' then level_counter = level_counter + 1 - else - level_stack[level_counter] = level_stack[level_counter] or {} + current_level_height = 0 + elseif not string.match(line, '^;') then + current_level_height = current_level_height + 1 + level_stack[level_counter] = level_stack[level_counter] or {height = 0, width = 0} table.insert(level_stack[level_counter], line) + level_stack[level_counter]['height'] = current_level_height + level_stack[level_counter]['width'] = math.max(level_stack[level_counter]['width'], string.len(line)) end end i = i + 1 From 86089115e21f626655a6bb25f595150863fe6dc0 Mon Sep 17 00:00:00 2001 From: apoh Date: Mon, 2 Jan 2012 16:42:57 +0100 Subject: [PATCH 56/57] bugfix levelplacement --- sokoban/main.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sokoban/main.lua b/sokoban/main.lua index f4c5dbb..347c1ec 100644 --- a/sokoban/main.lua +++ b/sokoban/main.lua @@ -62,10 +62,8 @@ function Player:update() local reset_player = false -- if next pixel is boulder don't move - if #env.level.level > 0 then - if env.level.level[x][y] == '#' then - reset_player = true - end + if env.level.level[x][y] == '#' then + reset_player = true end -- if next is boulder move boulder too From 3cae928dfa65cb211174b239047464572b400b06 Mon Sep 17 00:00:00 2001 From: dodo Date: Wed, 4 Jan 2012 06:58:20 +0100 Subject: [PATCH 57/57] bugfixes --- space/main.lua | 49 ++++++++++++++++++------------------------------- 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/space/main.lua b/space/main.lua index b701fdd..9537a8e 100644 --- a/space/main.lua +++ b/space/main.lua @@ -342,17 +342,6 @@ function Enemy:draw() wall:pixel(floor(x), floor(y), color) end end -function Enemy:addEnemy() - local enemy = Enemy { - source = env.enemys, - origin = env.player, - x = start_x, - y = start_y, - dir = Vector({ x = (R()-0.5), y = (R()-0.5) }):norm():mul(speed), - } - env.enemys[enemy] = enemy -end - -------------------------------------------------------------------------------- @@ -379,13 +368,15 @@ function Projectile:update() return self:destroy() end -- hit? - for _, enemy in pairs(env.enemies or {}) do - local c = self.source.coords:clone():sub(self.source.pos):add(self.pos) - if c:eq(enemy.coords, 1) then - stats.enemies = stats.enemies + 1 - enemy:destroy() - self:destroy() - return + for key, enemy in pairs(env.enemies or {}) do + if key ~= "length" then + local c = self.source.coords:clone():sub(self.source.pos):add(self.pos) + if c:eq(enemy.coords, 1) then + stats.enemies = stats.enemies + 1 + enemy:destroy() + self:destroy() + return + end end end -- direction @@ -443,13 +434,13 @@ function update() end env.targets.sum = sum - for key, enemy in pairs(env.enemys or {}) do + for key, enemy in pairs(env.enemies or {}) do if key ~= "length" then enemy:update() end end - if env.enemys.length == 0 then + if env.enemies.length == 0 then add_enemy() end @@ -466,20 +457,16 @@ function draw() end end - for _, enemy in pairs(env.enemies or {}) do - enemy:draw() + for key, enemy in pairs(env.enemies or {}) do + if key ~= "length" then + enemy:draw() + end end for _, target in ipairs(env.targets or {}) do target:draw() end - for key, enemy in pairs(env.enemys or {}) do - if key ~= "length" then - enemy:draw() - end - end - env.player:draw() end @@ -497,8 +484,8 @@ function add_enemy() y = start_y, dir = Vector({ x = (R()-0.5), y = (R()-0.5) }):norm():mul(speed), } - env.enemys[enemy] = enemy - env.enemys.length = env.enemys.length + 1 + env.enemies[enemy] = enemy + env.enemies.length = env.enemies.length + 1 end -------------------------------------------------------------------------------- @@ -548,7 +535,7 @@ function love.load() y = 0, } - env.enemys = setmetatable({length=0}, { __mode = 'k'}) + env.enemies = setmetatable({length=0}, { __mode = 'k'}) add_enemy() end