|
@@ -1,4 +1,5 @@
|
|
|
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -22,150 +23,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
+require("init")
|
|
|
+require("players")
|
|
|
+
|
|
|
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
|
|
|
+ players.load()
|
|
|
end
|
|
|
|
|
|
|
|
|
function love.keypressed(key)
|
|
|
- if key == p1_keyleft then
|
|
|
- p1_direction = turnLeft(p1_direction)
|
|
|
+ if key == p1.keyleft then
|
|
|
+ p1.direction = players.turnLeft(p1.direction)
|
|
|
end
|
|
|
|
|
|
|
|
|
- if key == p1_keyright then
|
|
|
- p1_direction = turnRight(p1_direction)
|
|
|
+ if key == p1.keyright then
|
|
|
+ p1.direction = players.turnRight(p1.direction)
|
|
|
end
|
|
|
|
|
|
|
|
|
- if key == p2_keyleft then
|
|
|
- p2_direction = turnLeft(p2_direction)
|
|
|
+ if key == p2.keyleft then
|
|
|
+ p2.direction = players.turnLeft(p2.direction)
|
|
|
end
|
|
|
|
|
|
|
|
|
- if key == p2_keyright then
|
|
|
- p2_direction = turnRight(p2_direction)
|
|
|
+ if key == p2.keyright then
|
|
|
+ p2.direction = players.turnRight(p2.direction)
|
|
|
end
|
|
|
end
|
|
|
|
|
|
-function statePlayer(currentstate)
|
|
|
-
|
|
|
-
|
|
|
- if collisionArray[x1][y1] == 0 then
|
|
|
- else
|
|
|
- p1_state = "crashed"
|
|
|
- end
|
|
|
-
|
|
|
-
|
|
|
-end
|
|
|
|
|
|
function love.update(dt)
|
|
|
+ update_players(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)
|
|
|
+function love.draw()
|
|
|
|
|
|
-
|
|
|
- love.graphics.setColor(p2_color)
|
|
|
- love.graphics.point(x2, y2)
|
|
|
+
|
|
|
+ draw_players()
|
|
|
|
|
|
+
|
|
|
+ love.graphics.setCanvas(canvas)
|
|
|
+ love.graphics.setColor(text_color)
|
|
|
+ font = love.graphics.newFont('SourceCodePro-Regular.ttf', 28)
|
|
|
+ font:setFilter('linear')
|
|
|
+
|
|
|
+ love.graphics.setFont(font);
|
|
|
+ love.graphics.print ('p1:' .. p1.state .. ' p2:' .. p2.state , 25, 25, 0, 1, 1)
|
|
|
+
|
|
|
|
|
|
love.graphics.setCanvas()
|
|
|
|
|
@@ -179,9 +90,6 @@ function love.draw()
|
|
|
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
|
|
|
|