diff --git a/coin.lua b/coin.lua index 37e83b8..e745e8e 100644 --- a/coin.lua +++ b/coin.lua @@ -12,6 +12,12 @@ function spawnCoin(x, y) table.insert(coins, coin) end +function spawnCoins() + for i, obj in pairs(gameMap.layers['coins'].objects) do + spawnCoin(obj.x, obj.y) + end +end + function coinUpdate(dt) for i, c in ipairs(coins) do diff --git a/main.lua b/main.lua index 2815c1f..93f4a7f 100644 --- a/main.lua +++ b/main.lua @@ -2,8 +2,9 @@ function love.load() gameState = "menu" myFont = love.graphics.newFont(30) + timer = 0 - love.window.setMode(1440, 700) + love.window.setMode(700, 700) myWorld = love.physics.newWorld(0, 500, false) myWorld:setCallbacks(beginContact, endContact, preSolve, postSolve) @@ -13,6 +14,8 @@ function love.load() sprites.player_stand = love.graphics.newImage('sprites/player_stand.png') require('player') + resetPlayerPosition() + require('coin') anim8 = require 'anim8' sti = require 'sti' @@ -26,9 +29,7 @@ function love.load() spawnPlatform(obj.x, obj.y, obj.width, obj.height) end - for i, obj in pairs(gameMap.layers['coins'].objects) do - spawnCoin(obj.x, obj.y) - end + spawnCoins() DIRECTION_LEFT = -1 DIRECTION_RIGHT = 1 @@ -45,6 +46,16 @@ function love.update(dt) for i,c in ipairs(coins) do c.animation:update(dt) end + + if gameState == "game" then + timer = timer + dt + end + + if #coins == 0 and gameState == "game" then + gameState = "menu" + resetPlayerPosition() + spawnCoins() + end end function love.draw() @@ -67,6 +78,10 @@ function love.draw() love.graphics.setFont(myFont) love.graphics.printf("Press any key to begin!", 0, 50, love.graphics.getWidth(), "center") end + if gameState == "game" then + love.graphics.print("Time:" .. math.ceil(timer), 10, 660) + end + end function love.keypressed(key, scancode, isrepeat) @@ -76,6 +91,7 @@ function love.keypressed(key, scancode, isrepeat) if gameState == "menu" then gameState = "game" + timer = 0 end end diff --git a/maps/map.lua b/maps/map.lua index 5ef8bb6..7610acb 100644 --- a/maps/map.lua +++ b/maps/map.lua @@ -8,7 +8,7 @@ return { height = 10, tilewidth = 70, tileheight = 70, - nextobjectid = 65, + nextobjectid = 76, properties = {}, tilesets = { { @@ -68,7 +68,7 @@ return { properties = {}, encoding = "base64", compression = "zlib", - data = "eJxjYBgFo4A2QGqgHTAIgBQONq3sIZYeBZQDaoXtcI8TWueBoWLmKCAfDIf4oFYZjC0/0aueoacdo4B4MBofo2AUDD8AACv4AqU=" + data = "eJxjYBgFo4A2QGqgHTAIgBQONq3sIZYeBYMHDPc4oXUewGY+pfYM9zgZamA4xAct0iY2M+kRVsMhPoYTGI2PUTAKhh8AAM1CAos=" }, { type = "objectgroup", @@ -132,19 +132,6 @@ return { visible = true, properties = {} }, - { - id = 10, - name = "", - type = "", - shape = "rectangle", - x = 2310, - y = 420, - width = 70, - height = 69.5, - rotation = 0, - visible = true, - properties = {} - }, { id = 11, name = "", @@ -274,6 +261,19 @@ return { rotation = 0, visible = true, properties = {} + }, + { + id = 73, + name = "", + type = "", + shape = "rectangle", + x = 2240, + y = 420, + width = 140.182, + height = 70, + rotation = 0, + visible = true, + properties = {} } } }, @@ -282,7 +282,7 @@ return { name = "coins", visible = true, opacity = 1, - offsetx = -33, + offsetx = 0, offsety = 0, draworder = "topdown", properties = {}, @@ -435,8 +435,8 @@ return { name = "", type = "", shape = "rectangle", - x = 2450.5, - y = 210.5, + x = 2521.5, + y = 281.5, width = 70, height = 70.5, rotation = 0, @@ -448,27 +448,14 @@ return { name = "", type = "", shape = "rectangle", - x = 2591.5, - y = 209.5, + x = 2662.5, + y = 280.5, width = 70, height = 71, rotation = 0, visible = true, properties = {} }, - { - id = 49, - name = "", - type = "", - shape = "rectangle", - x = 2730.5, - y = 211, - width = 69.5, - height = 70, - rotation = 0, - visible = true, - properties = {} - }, { id = 50, name = "", diff --git a/maps/map.tmx b/maps/map.tmx index e7ff2d2..59b5a13 100644 --- a/maps/map.tmx +++ b/maps/map.tmx @@ -1,5 +1,5 @@ - + @@ -10,7 +10,7 @@ - eJxjYBgFo4A2QGqgHTAIgBQONq3sIZYeBZQDaoXtcI8TWueBoWLmKCAfDIf4oFYZjC0/0aueoacdo4B4MBofo2AUDD8AACv4AqU= + eJxjYBgFo4A2QGqgHTAIgBQONq3sIZYeBYMHDPc4oXUewGY+pfYM9zgZamA4xAct0iY2M+kRVsMhPoYTGI2PUTAKhh8AAM1CAos= @@ -18,7 +18,6 @@ - @@ -29,6 +28,7 @@ + @@ -42,9 +42,8 @@ - - - + + diff --git a/player.lua b/player.lua index 7c87314..0b6bd31 100644 --- a/player.lua +++ b/player.lua @@ -1,6 +1,8 @@ player = {} +player.start_x = 106 +player.start_y = 465 -- Physics Engine -player.body = love.physics.newBody(myWorld, 100, 100, 'dynamic') +player.body = love.physics.newBody(myWorld, 0, 0, 'dynamic') player.shape = love.physics.newRectangleShape(66, 92) player.fixture = love.physics.newFixture(player.body, player.shape) player.body:setFixedRotation(true) @@ -29,3 +31,7 @@ function playerUpdate(dt) end end end + +function resetPlayerPosition() + player.body:setPosition(player.start_x, player.start_y) +end