respawn stuff

This commit is contained in:
Tyrel Souza 2018-01-18 00:41:26 -05:00
parent add1f7c3f0
commit c4a50ec616
5 changed files with 58 additions and 44 deletions

View File

@ -12,6 +12,12 @@ function spawnCoin(x, y)
table.insert(coins, coin) table.insert(coins, coin)
end end
function spawnCoins()
for i, obj in pairs(gameMap.layers['coins'].objects) do
spawnCoin(obj.x, obj.y)
end
end
function coinUpdate(dt) function coinUpdate(dt)
for i, c in ipairs(coins) do for i, c in ipairs(coins) do

View File

@ -2,8 +2,9 @@
function love.load() function love.load()
gameState = "menu" gameState = "menu"
myFont = love.graphics.newFont(30) 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 = love.physics.newWorld(0, 500, false)
myWorld:setCallbacks(beginContact, endContact, preSolve, postSolve) myWorld:setCallbacks(beginContact, endContact, preSolve, postSolve)
@ -13,6 +14,8 @@ function love.load()
sprites.player_stand = love.graphics.newImage('sprites/player_stand.png') sprites.player_stand = love.graphics.newImage('sprites/player_stand.png')
require('player') require('player')
resetPlayerPosition()
require('coin') require('coin')
anim8 = require 'anim8' anim8 = require 'anim8'
sti = require 'sti' sti = require 'sti'
@ -26,9 +29,7 @@ function love.load()
spawnPlatform(obj.x, obj.y, obj.width, obj.height) spawnPlatform(obj.x, obj.y, obj.width, obj.height)
end end
for i, obj in pairs(gameMap.layers['coins'].objects) do spawnCoins()
spawnCoin(obj.x, obj.y)
end
DIRECTION_LEFT = -1 DIRECTION_LEFT = -1
DIRECTION_RIGHT = 1 DIRECTION_RIGHT = 1
@ -45,6 +46,16 @@ function love.update(dt)
for i,c in ipairs(coins) do for i,c in ipairs(coins) do
c.animation:update(dt) c.animation:update(dt)
end end
if gameState == "game" then
timer = timer + dt
end
if #coins == 0 and gameState == "game" then
gameState = "menu"
resetPlayerPosition()
spawnCoins()
end
end end
function love.draw() function love.draw()
@ -67,6 +78,10 @@ function love.draw()
love.graphics.setFont(myFont) love.graphics.setFont(myFont)
love.graphics.printf("Press any key to begin!", 0, 50, love.graphics.getWidth(), "center") love.graphics.printf("Press any key to begin!", 0, 50, love.graphics.getWidth(), "center")
end end
if gameState == "game" then
love.graphics.print("Time:" .. math.ceil(timer), 10, 660)
end
end end
function love.keypressed(key, scancode, isrepeat) function love.keypressed(key, scancode, isrepeat)
@ -76,6 +91,7 @@ function love.keypressed(key, scancode, isrepeat)
if gameState == "menu" then if gameState == "menu" then
gameState = "game" gameState = "game"
timer = 0
end end
end end

View File

@ -8,7 +8,7 @@ return {
height = 10, height = 10,
tilewidth = 70, tilewidth = 70,
tileheight = 70, tileheight = 70,
nextobjectid = 65, nextobjectid = 76,
properties = {}, properties = {},
tilesets = { tilesets = {
{ {
@ -68,7 +68,7 @@ return {
properties = {}, properties = {},
encoding = "base64", encoding = "base64",
compression = "zlib", compression = "zlib",
data = "eJxjYBgFo4A2QGqgHTAIgBQONq3sIZYeBZQDaoXtcI8TWueBoWLmKCAfDIf4oFYZjC0/0aueoacdo4B4MBofo2AUDD8AACv4AqU=" data = "eJxjYBgFo4A2QGqgHTAIgBQONq3sIZYeBYMHDPc4oXUewGY+pfYM9zgZamA4xAct0iY2M+kRVsMhPoYTGI2PUTAKhh8AAM1CAos="
}, },
{ {
type = "objectgroup", type = "objectgroup",
@ -132,19 +132,6 @@ return {
visible = true, visible = true,
properties = {} properties = {}
}, },
{
id = 10,
name = "",
type = "",
shape = "rectangle",
x = 2310,
y = 420,
width = 70,
height = 69.5,
rotation = 0,
visible = true,
properties = {}
},
{ {
id = 11, id = 11,
name = "", name = "",
@ -274,6 +261,19 @@ return {
rotation = 0, rotation = 0,
visible = true, visible = true,
properties = {} 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", name = "coins",
visible = true, visible = true,
opacity = 1, opacity = 1,
offsetx = -33, offsetx = 0,
offsety = 0, offsety = 0,
draworder = "topdown", draworder = "topdown",
properties = {}, properties = {},
@ -435,8 +435,8 @@ return {
name = "", name = "",
type = "", type = "",
shape = "rectangle", shape = "rectangle",
x = 2450.5, x = 2521.5,
y = 210.5, y = 281.5,
width = 70, width = 70,
height = 70.5, height = 70.5,
rotation = 0, rotation = 0,
@ -448,27 +448,14 @@ return {
name = "", name = "",
type = "", type = "",
shape = "rectangle", shape = "rectangle",
x = 2591.5, x = 2662.5,
y = 209.5, y = 280.5,
width = 70, width = 70,
height = 71, height = 71,
rotation = 0, rotation = 0,
visible = true, visible = true,
properties = {} properties = {}
}, },
{
id = 49,
name = "",
type = "",
shape = "rectangle",
x = 2730.5,
y = 211,
width = 69.5,
height = 70,
rotation = 0,
visible = true,
properties = {}
},
{ {
id = 50, id = 50,
name = "", name = "",

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" tiledversion="1.1.1" orientation="orthogonal" renderorder="right-down" width="100" height="10" tilewidth="70" tileheight="70" infinite="0" nextobjectid="65"> <map version="1.0" tiledversion="1.1.1" orientation="orthogonal" renderorder="right-down" width="100" height="10" tilewidth="70" tileheight="70" infinite="0" nextobjectid="76">
<tileset firstgid="1" name="map" tilewidth="70" tileheight="70" spacing="2" tilecount="156" columns="12"> <tileset firstgid="1" name="map" tilewidth="70" tileheight="70" spacing="2" tilecount="156" columns="12">
<image source="tiles_spritesheet.png" trans="ff05fa" width="914" height="936"/> <image source="tiles_spritesheet.png" trans="ff05fa" width="914" height="936"/>
</tileset> </tileset>
@ -10,7 +10,7 @@
</layer> </layer>
<layer name="hidden" width="100" height="10"> <layer name="hidden" width="100" height="10">
<data encoding="base64" compression="zlib"> <data encoding="base64" compression="zlib">
eJxjYBgFo4A2QGqgHTAIgBQONq3sIZYeBZQDaoXtcI8TWueBoWLmKCAfDIf4oFYZjC0/0aueoacdo4B4MBofo2AUDD8AACv4AqU= eJxjYBgFo4A2QGqgHTAIgBQONq3sIZYeBYMHDPc4oXUewGY+pfYM9zgZamA4xAct0iY2M+kRVsMhPoYTGI2PUTAKhh8AAM1CAos=
</data> </data>
</layer> </layer>
<objectgroup name="platforms"> <objectgroup name="platforms">
@ -18,7 +18,6 @@
<object id="5" x="561.333" y="421.333" width="420" height="67.3333"/> <object id="5" x="561.333" y="421.333" width="420" height="67.3333"/>
<object id="6" x="1051.33" y="280.667" width="488" height="69.3333"/> <object id="6" x="1051.33" y="280.667" width="488" height="69.3333"/>
<object id="8" x="1259.67" y="560" width="910.33" height="69.3333"/> <object id="8" x="1259.67" y="560" width="910.33" height="69.3333"/>
<object id="10" x="2310" y="420" width="70" height="69.5"/>
<object id="11" x="2450" y="350.5" width="70.5" height="69.5"/> <object id="11" x="2450" y="350.5" width="70.5" height="69.5"/>
<object id="12" x="2591" y="350.5" width="69" height="68.5"/> <object id="12" x="2591" y="350.5" width="69" height="68.5"/>
<object id="13" x="2730" y="350" width="69.5" height="70"/> <object id="13" x="2730" y="350" width="69.5" height="70"/>
@ -29,6 +28,7 @@
<object id="20" x="5603" y="420" width="836" height="70"/> <object id="20" x="5603" y="420" width="836" height="70"/>
<object id="24" x="6440.5" y="350.5" width="420.5" height="69.5"/> <object id="24" x="6440.5" y="350.5" width="420.5" height="69.5"/>
<object id="25" x="6789.5" y="0" width="71" height="350.5"/> <object id="25" x="6789.5" y="0" width="71" height="350.5"/>
<object id="73" x="2240" y="420" width="140.182" height="70"/>
</objectgroup> </objectgroup>
<objectgroup name="coins"> <objectgroup name="coins">
<object id="33" x="211" y="421" width="69" height="68.6667"/> <object id="33" x="211" y="421" width="69" height="68.6667"/>
@ -42,9 +42,8 @@
<object id="44" x="1821" y="422" width="70.5" height="68.5"/> <object id="44" x="1821" y="422" width="70.5" height="68.5"/>
<object id="45" x="2031" y="420.5" width="70" height="71"/> <object id="45" x="2031" y="420.5" width="70" height="71"/>
<object id="46" x="2311" y="280.5" width="70" height="70"/> <object id="46" x="2311" y="280.5" width="70" height="70"/>
<object id="47" x="2450.5" y="210.5" width="70" height="70.5"/> <object id="47" x="2521.5" y="281.5" width="70" height="70.5"/>
<object id="48" x="2591.5" y="209.5" width="70" height="71"/> <object id="48" x="2662.5" y="280.5" width="70" height="71"/>
<object id="49" x="2730.5" y="211" width="69.5" height="70"/>
<object id="50" x="2940.5" y="140.5" width="68.5" height="69.5"/> <object id="50" x="2940.5" y="140.5" width="68.5" height="69.5"/>
<object id="51" x="3080" y="140.5" width="70" height="69"/> <object id="51" x="3080" y="140.5" width="70" height="69"/>
<object id="52" x="3220.5" y="140" width="70.5" height="70.5"/> <object id="52" x="3220.5" y="140" width="70.5" height="70.5"/>

View File

@ -1,6 +1,8 @@
player = {} player = {}
player.start_x = 106
player.start_y = 465
-- Physics Engine -- 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.shape = love.physics.newRectangleShape(66, 92)
player.fixture = love.physics.newFixture(player.body, player.shape) player.fixture = love.physics.newFixture(player.body, player.shape)
player.body:setFixedRotation(true) player.body:setFixedRotation(true)
@ -29,3 +31,7 @@ function playerUpdate(dt)
end end
end end
end end
function resetPlayerPosition()
player.body:setPosition(player.start_x, player.start_y)
end