|
@@ -0,0 +1,187 @@
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+function love.load()
|
|
|
+ local init = require("init")
|
|
|
+ init.load()
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
+function turnLeft(direction)
|
|
|
+ if direction == "left" then
|
|
|
+ newDirection = "down"
|
|
|
+ end
|
|
|
+ if direction == "down" then
|
|
|
+ newDirection = "right"
|
|
|
+ end
|
|
|
+ if direction == "right" then
|
|
|
+ newDirection = "up"
|
|
|
+ end
|
|
|
+ if direction == "up" then
|
|
|
+ newDirection = "left"
|
|
|
+ end
|
|
|
+
|
|
|
+ return newDirection
|
|
|
+end
|
|
|
+
|
|
|
+function turnRight(direction)
|
|
|
+ if direction == "left" then
|
|
|
+ newDirection = "up"
|
|
|
+ end
|
|
|
+ if direction == "down" then
|
|
|
+ newDirection = "left"
|
|
|
+ end
|
|
|
+ if direction == "right" then
|
|
|
+ newDirection = "down"
|
|
|
+ end
|
|
|
+ if direction == "up" then
|
|
|
+ newDirection = "right"
|
|
|
+ end
|
|
|
+
|
|
|
+ return newDirection
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
+function movePlayer(x, y, toDirection)
|
|
|
+ if toDirection == "left" then
|
|
|
+ x = x - 1
|
|
|
+ end
|
|
|
+ if toDirection == "right" then
|
|
|
+ x = x + 1
|
|
|
+ end
|
|
|
+ if toDirection == "up" then
|
|
|
+ y = y - 1
|
|
|
+ end
|
|
|
+ if toDirection == "down" then
|
|
|
+ y = y + 1
|
|
|
+ end
|
|
|
+ return x, y
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
+function love.keypressed(key)
|
|
|
+ if key == p1_keyleft then
|
|
|
+ p1_direction = turnLeft(p1_direction)
|
|
|
+ end
|
|
|
+
|
|
|
+
|
|
|
+ if key == p1_keyright then
|
|
|
+ p1_direction = turnRight(p1_direction)
|
|
|
+ end
|
|
|
+
|
|
|
+
|
|
|
+ if key == p2_keyleft then
|
|
|
+ p2_direction = turnLeft(p2_direction)
|
|
|
+ end
|
|
|
+
|
|
|
+
|
|
|
+ if key == p2_keyright then
|
|
|
+ p2_direction = turnRight(p2_direction)
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+function statePlayer(currentstate)
|
|
|
+
|
|
|
+
|
|
|
+ if collisionArray[x1][y1] == 0 then
|
|
|
+ else
|
|
|
+ p1_state = "crashed"
|
|
|
+ end
|
|
|
+
|
|
|
+
|
|
|
+end
|
|
|
+
|
|
|
+function love.update(dt)
|
|
|
+
|
|
|
+ if love.keyboard.isDown(game_keyquit) then
|
|
|
+ love.event.quit()
|
|
|
+ end
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (p1_state == "alive" and p2_state == "alive") then
|
|
|
+
|
|
|
+
|
|
|
+ x1, y1 = movePlayer(x1, y1, p1_direction)
|
|
|
+ if (y1 >= maxHeight) or (y1 <= 0) or (x1 >= maxWidth) or (x1 <= 0) then
|
|
|
+ p1_state = "crashed"
|
|
|
+ end
|
|
|
+ if not (p1_state == "crashed") then
|
|
|
+ if collisionArray[x1][y1] > 0 then
|
|
|
+ p1_state = "crashed"
|
|
|
+ else
|
|
|
+ collisionArray[x1][y1] = 1
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+
|
|
|
+ x2, y2 = movePlayer(x2, y2, p2_direction)
|
|
|
+ if (y2 >= maxHeight) or (y2 <= 0) or (x2 >= maxWidth) or (x2 <= 0) then
|
|
|
+ p2_state = "crashed"
|
|
|
+ end
|
|
|
+ if not (p2_state == "crashed") then
|
|
|
+ if collisionArray[x2][y2] > 0 then
|
|
|
+ p2_state = "crashed"
|
|
|
+ else
|
|
|
+ collisionArray[x2][y2] = 2
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ end
|
|
|
+
|
|
|
+end
|
|
|
+
|
|
|
+function love.draw()
|
|
|
+
|
|
|
+
|
|
|
+ love.graphics.setCanvas(canvas)
|
|
|
+
|
|
|
+
|
|
|
+ love.graphics.setColor(p1_color)
|
|
|
+ love.graphics.point(x1, y1)
|
|
|
+
|
|
|
+
|
|
|
+ love.graphics.setColor(p2_color)
|
|
|
+ love.graphics.point(x2, y2)
|
|
|
+
|
|
|
+
|
|
|
+ love.graphics.setCanvas()
|
|
|
+
|
|
|
+ love.graphics.setBackgroundColor(bg_color)
|
|
|
+
|
|
|
+
|
|
|
+ love.graphics.setColor(border_color)
|
|
|
+ love.graphics.rectangle("line", 0, 0, maxWidth - 1, maxHeight - 1)
|
|
|
+
|
|
|
+
|
|
|
+ love.graphics.setColor(255, 255, 255, 255)
|
|
|
+ love.graphics.draw(canvas)
|
|
|
+
|
|
|
+
|
|
|
+ love.graphics.setColor(text_color)
|
|
|
+ love.graphics.print ('p1:' .. p1_state .. ' p2:' .. p2_state , 25, 25)
|
|
|
+
|
|
|
+end
|
|
|
+
|