respawn stuff
This commit is contained in:
parent
add1f7c3f0
commit
c4a50ec616
6
coin.lua
6
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
|
||||
|
24
main.lua
24
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
|
||||
|
||||
|
53
maps/map.lua
53
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 = "",
|
||||
|
11
maps/map.tmx
11
maps/map.tmx
@ -1,5 +1,5 @@
|
||||
<?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">
|
||||
<image source="tiles_spritesheet.png" trans="ff05fa" width="914" height="936"/>
|
||||
</tileset>
|
||||
@ -10,7 +10,7 @@
|
||||
</layer>
|
||||
<layer name="hidden" width="100" height="10">
|
||||
<data encoding="base64" compression="zlib">
|
||||
eJxjYBgFo4A2QGqgHTAIgBQONq3sIZYeBZQDaoXtcI8TWueBoWLmKCAfDIf4oFYZjC0/0aueoacdo4B4MBofo2AUDD8AACv4AqU=
|
||||
eJxjYBgFo4A2QGqgHTAIgBQONq3sIZYeBYMHDPc4oXUewGY+pfYM9zgZamA4xAct0iY2M+kRVsMhPoYTGI2PUTAKhh8AAM1CAos=
|
||||
</data>
|
||||
</layer>
|
||||
<objectgroup name="platforms">
|
||||
@ -18,7 +18,6 @@
|
||||
<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="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="12" x="2591" y="350.5" width="69" height="68.5"/>
|
||||
<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="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="73" x="2240" y="420" width="140.182" height="70"/>
|
||||
</objectgroup>
|
||||
<objectgroup name="coins">
|
||||
<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="45" x="2031" y="420.5" width="70" height="71"/>
|
||||
<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="48" x="2591.5" y="209.5" width="70" height="71"/>
|
||||
<object id="49" x="2730.5" y="211" width="69.5" height="70"/>
|
||||
<object id="47" x="2521.5" y="281.5" width="70" height="70.5"/>
|
||||
<object id="48" x="2662.5" y="280.5" width="70" height="71"/>
|
||||
<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="52" x="3220.5" y="140" width="70.5" height="70.5"/>
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user