diff --git a/.gitignore b/.gitignore index 0d20b64..6927e76 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.pyc +*swp 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..2d14a00 --- /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[self.layer][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.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 + 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..b24bc66 --- /dev/null +++ b/balken/draw.lua @@ -0,0 +1,103 @@ + +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] = {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} + +local function Color(c) + return string.format("%02X%02X%02X", floor(c[1]), floor(c[2]), floor(c[3])) +end + + +function Field:draw() + + local layer = self.layer + if self.state ~= "normal" then + layer = (layer - 1) % self.width + 1 + 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 + + 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 + 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..03ca2ff --- /dev/null +++ b/balken/field.lua @@ -0,0 +1,327 @@ +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 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 + + 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.layer = (self.layer + 1) % self.width + 1 + 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.layer][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[self.layer][y][self.x] ~= 0 then + return true + end + end + return false +end + + +function Field:collapse() + local grid = self.grid + local ret = false + 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 + + +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.z][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 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 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() + self.state = "normal" + end + end + + elseif self.state == "over" then + -- TODO + + if self.state_delay == 0 then + love.event.push "q" + end + + 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() + + -- TODO: make the code look nicer + + local grid = self.grid + local z = self.layer + + local function addGem(x, y, z) + self.gems_in_line[y .. " " .. x .. " " .. z] = { x = x, y = y, z = z } + 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 +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 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/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/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/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 diff --git a/blob/main.lua b/blob/main.lua new file mode 100644 index 0000000..47c3ed2 --- /dev/null +++ b/blob/main.lua @@ -0,0 +1,163 @@ +require "helper" +require "wall" +require "framework" + +-- values + +nr = 42 +blobs = {} + + +-- helpervalues +local __maxbound = 1.5 +local __reznr = 1 / nr +local __maxd = 0 + +-------------------------------------------------------------------------------- + + +function update() + for _, blob in ipairs(blobs) do + 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.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 = - 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 = - h + elseif blob.y < - h then + blob.y = wall.height * __maxbound + end + + + 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() + + 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 + + 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) + + 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, + y = R()*wall.height*__maxbound, + } + + 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 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..c1bbe8d --- /dev/null +++ b/drops/main.lua @@ -0,0 +1,198 @@ +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 + + +nextdrops= 0 +function update() + local w= wall.width + local h= wall.height + + blur(pix1, math.sin(tick*0.00649)*.1, math.cos(tick*.0127)*.1) + --fade(pix1, 1) + local p= pix1 + pix1= pix2 + pix2= p + + tick= tick+1 + + + 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 + --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 + nextdrops= R(tick+10, tick+200) + 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, 1) + + __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 diff --git a/lib/framework.lua b/lib/framework.lua new file mode 100644 index 0000000..0f21f6a --- /dev/null +++ b/lib/framework.lua @@ -0,0 +1,75 @@ + +require 'socket' +math.randomseed(socket.gettime()*10000) + +abs = math.abs +ceil = math.ceil +floor = math.floor +round = function (x) + return floor(x+0.5) +end + +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 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, count +end + +function inroundbound(...) + local ret, _ = inroundbound_with_count(...) + return ret +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 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) diff --git a/lib/wall.py b/lib/wall.py index 7372197..60d2571 100644 --- a/lib/wall.py +++ b/lib/wall.py @@ -9,7 +9,7 @@ def init(priority=3): s.send("04%02x\r\n" % priority) def pixel(x, y, color="ff0000"): - s.send("02%02x%02x%s\r\n" % (x+1, y+1, 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) 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 diff --git a/rain/README.md b/rain/README.md new file mode 100644 index 0000000..8882ca3 --- /dev/null +++ b/rain/README.md @@ -0,0 +1,4 @@ +rain +==== + +Based on 2bt'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..d0c5a63 --- /dev/null +++ b/rain/main.lua @@ -0,0 +1,102 @@ +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" + + 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"} +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 + 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 = colours[math.random(1, 6)], + fadesteps = math.random(4,10), + } + 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 + + 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 + drop.dy + if drop.y > 15 + drop.fadesteps + 1 then + table.remove(drops, i) + end + if i >= 30 then + table.remove(drops, i) + end + end + + +end + +function drop() + 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, tohex(drop.colour)) + + local p, r,g,b + local steps = drop.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 + +function love.draw() + + drop() + -- send the stuff abroad + wall:draw() +end \ No newline at end of file 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 diff --git a/sokoban/README.md b/sokoban/README.md new file mode 100644 index 0000000..9921433 --- /dev/null +++ b/sokoban/README.md @@ -0,0 +1,14 @@ +# 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/conf.lua b/sokoban/conf.lua new file mode 100644 index 0000000..bc07f23 --- /dev/null +++ b/sokoban/conf.lua @@ -0,0 +1,9 @@ +function love.conf(t) + t.title = "sokoban" + t.author = "apoh" + t.screen.width = 320 + t.screen.height = 300 + t.screen.vsync = false + t.modules.physics = false + t.modules.mouse = false +end diff --git a/sokoban/framework.lua b/sokoban/framework.lua new file mode 120000 index 0000000..1350e61 --- /dev/null +++ b/sokoban/framework.lua @@ -0,0 +1 @@ +../lib/framework.lua \ No newline at end of file diff --git a/sokoban/helper.lua b/sokoban/helper.lua new file mode 120000 index 0000000..039178c --- /dev/null +++ b/sokoban/helper.lua @@ -0,0 +1 @@ +../lib/helper.lua \ No newline at end of file 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/lust.lua b/sokoban/lust.lua new file mode 120000 index 0000000..f6e54d1 --- /dev/null +++ b/sokoban/lust.lua @@ -0,0 +1 @@ +../lib/lust.lua \ No newline at end of file diff --git a/sokoban/main.lua b/sokoban/main.lua new file mode 100644 index 0000000..347c1ec --- /dev/null +++ b/sokoban/main.lua @@ -0,0 +1,293 @@ +require "helper" +require "wall" +require "framework" + +-- values + +env = { +} + +-- this value is used for blocing new keyentrys +block_keyevents = false +level_stack = {} + +-- 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} + +-------------------------------------------------------------------------------- + +Player = Object:new() +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( 200, 200, 200 ) +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 + 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 + dir.x = -1 + else + dir.x = 1 + end + elseif c == 'y' then + if o == '-' then + dir.y = -1 + else + dir.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[x][y] == '#' then + reset_player = true + end + + -- if next is boulder move boulder too + if env.level.boxes[x] and env.level.boxes[x][y] then + -- calculate next position of box + 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] ~= '#' 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 + 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), env.level.background_color) + wall:pixel(x, y, self.color) + --end +end + +function Player:draw() + local x, y = self.pos.x, self.pos.y +end + +-------------------------------------------------------------------------------- + +Level = Object:new() +function Level:init(opts) + 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 + +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] 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 + end +end + +function Level:draw(opts) + local pos_x = 0 + local pos_y = 0 + + -- 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 + + -- 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 {} + 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) + 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 + end + pos_x = pos_x + 1 + end + pos_x = start_pos_x + pos_y = pos_y + 1 + 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() + wall:update_input() + + env.level:update() + env.player:update() + + tick = tick + 1 +end + +function draw() + + env.player:draw() + +end + +-------------------------------------------------------------------------------- + +function love.load() + local level_file = io.open('level.txt') + + + 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 + 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 + end + + wall = Wall(false, 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 = -1, + y = -1 + } + + env.level = Level {} + + env.level:draw() + + tick = 0 + +end + +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) + block_keyevents = false +end + +function love.update(dt) + -- constant 30 FPS + local t = love.timer.getTime() * 1000 + time = time + 1000 / 23 + love.timer.sleep(time - t) + + update() +end + + +function love.draw() + draw() + -- send the stuff abroad + wall:draw() +end diff --git a/sokoban/wall.lua b/sokoban/wall.lua new file mode 120000 index 0000000..d37ae93 --- /dev/null +++ b/sokoban/wall.lua @@ -0,0 +1 @@ +../lib/wall.lua \ No newline at end of file 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..9537a8e --- /dev/null +++ b/space/main.lua @@ -0,0 +1,568 @@ +require "helper" +require "wall" +require "framework" + +-- values + +nr = 32 +env = { + stars = {level=3}, +} +stats = { + enemies = 0, + targets = 0, +} + + + +-- 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) + opts = opts or {} + 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:neg() + return self:mul(-1) +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() + local len = self:len() + if len < 0.00000001 then + self:mul(0) + else + self:mul(1/len) + end + 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() +function Star:init(opts) + opts = opts or {} + self.pos = Vector(opts) + self.dir = Vector(opts.dir) + 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], -0.6) + end + self.dir:norm():mul(0.6) + else + self.dir:norm():mul(0.1) + end +end + +function Star:draw() + local x, y = self.pos.x, self.pos.y + wall:pixel(round(x), round(y), self.color) +end + +-------------------------------------------------------------------------------- + +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' }) +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 + 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) + + if #newstate > 0 then + 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 + local o, c = oc:sub(1,1), oc:sub(2) + 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 + 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), + } + projectile.life = projectile -- self reference + self.projectiles[projectile] = projectile + self.projectiles.length = self.projectiles.length + 1 + end + end + + if wall.input[2].left then + add_enemy() + 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) + + 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], 1, wall[({x="width",y="height"})[c]]) + wall:pixel(coord.x, coord.y, self.color) + end + end + +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.away_color = opts.away_color or hex(0, 100, 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) + 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 + +-------------------------------------------------------------------------------- +Enemy = Object:new() +function Enemy:init(opts) + opts = opts or {} + 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(100, 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") + end + self.origin = opts.origin + if not self.origin then + error("no origin given") + end +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 = 30 + break + end + end + + if not self.flash then + local speed = self.dir:len() + 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.coords:add(self.dir) + end + end + + if self.flash then + self.flash = self.flash - 1 + + if self.flash == 0 then + stats.targets = stats.targets + 1 + self:destroy() + end + end +end + +function Enemy:destroy() + self.flash = 0 + self.source[self] = nil +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 + y = inbound(pos.y, 1, wall.height) - 1 + local color = self.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 +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(0, 80, 180) + self.energy = opts.energy or 15 + 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 + -- deceased? + self.energy = self.energy - 1 + if self.energy == 0 then + return self:destroy() + end + -- hit? + 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 + local rel_energy = self.energy/self.max_energy + if rel_energy > 0.2 then + local dir = Vector() + 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 + self.pos:add(dir:norm():mul(rel_energy)) + end + 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 + 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 + +-------------------------------------------------------------------------------- + +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 == 0 then + for _, star in ipairs(env.stars[level] or {}) do + star:update() + end + end + end + + 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 key, enemy in pairs(env.enemies or {}) do + if key ~= "length" then + enemy:update() + end + end + + if env.enemies.length == 0 then + add_enemy() + 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 + star:draw() + end + end + end + + 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 + + env.player:draw() + +end + +function add_enemy() + 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] + + local enemy = Enemy { + 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.enemies[enemy] = enemy + env.enemies.length = env.enemies.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) + + 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*20)*R())^2) ), +-- color = hex( starlight(30000*R()) ), + } + +-- 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, + } + + env.targets = { sum = Vector() } + env.targets[1] = Target { + source = env.player, + x = 0, + y = 0, + } + + env.enemies = setmetatable({length=0}, { __mode = 'k'}) + add_enemy() +end + + +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) + -- 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 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..e74a84c 100644 --- a/spalten/main.lua +++ b/spalten/main.lua @@ -24,11 +24,12 @@ function love.load() math.randomseed(os.time()) time = love.timer.getTime() * 1000 - wall = Wall("localhost", 1338, 3, true) + --wall = Wall("ledwall", 1338, 3, false) + wall = Wall(nil, nil, 3, false) fields = { Field(0, wall.input[1]), - Field(8, false), -- bot + Field(9, false), -- bot } fields[1]:setOpponent(fields[2])