Allow floating devices to have different speeds.
This commit is contained in:
parent
11acc030e5
commit
680a0c2790
39
main.lua
39
main.lua
|
@ -47,6 +47,7 @@ local player = {
|
|||
turtles=3,
|
||||
dead=false,
|
||||
deadTimer=2,
|
||||
float_speed=0,
|
||||
}
|
||||
|
||||
function resetPlayer()
|
||||
|
@ -66,16 +67,17 @@ function love.load()
|
|||
if game.entities[typekey] == nil then
|
||||
game.entities[typekey] = {}
|
||||
end
|
||||
table.insert(
|
||||
game.entities[typekey],
|
||||
{
|
||||
x=mapObj.x,
|
||||
y=mapObj.y,
|
||||
w=mapObj.width,
|
||||
h=mapObj.height,
|
||||
type=mapObj.type,
|
||||
}
|
||||
)
|
||||
local entity = {
|
||||
x=mapObj.x,
|
||||
y=mapObj.y,
|
||||
w=mapObj.width,
|
||||
h=mapObj.height,
|
||||
type=mapObj.type,
|
||||
}
|
||||
if entity.type == "floatdev" then
|
||||
entity.speed = mapObj.properties.speed or game.FLOATDEV_SPEED
|
||||
end
|
||||
table.insert(game.entities[typekey], entity)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -144,8 +146,8 @@ function love.update(dt)
|
|||
else
|
||||
local playerRect = tilePos2Rect(screenPixelToTilePos(player.pos))
|
||||
local turtleRect = tilePos2Rect(player.turtlePos)
|
||||
if player.floating then
|
||||
player.pos.y = player.pos.y + game.FLOATDEV_SPEED*dt
|
||||
if player.float_speed ~= 0 then
|
||||
player.pos.y = player.pos.y + player.float_speed*dt
|
||||
end
|
||||
for i, vehicle in ipairs(game.entities.vehicles) do
|
||||
if rectanglesIntersect(playerRect, vehicle) then
|
||||
|
@ -161,17 +163,20 @@ function love.update(dt)
|
|||
vehicle.y = -vehicle.h
|
||||
end
|
||||
end
|
||||
player.floating = false
|
||||
player.float_speed = 0
|
||||
for i, floatdev in ipairs(game.entities.floatdevs) do
|
||||
if not player.floating and rectanglesIntersect(playerRect, floatdev) then
|
||||
player.floating = true
|
||||
if player.float_speed == 0 and rectanglesIntersect(playerRect, floatdev) then
|
||||
player.float_speed = floatdev.speed
|
||||
end
|
||||
floatdev.y = floatdev.y + game.FLOATDEV_SPEED*dt
|
||||
floatdev.y = floatdev.y + floatdev.speed*dt
|
||||
if floatdev.y > t2p(game.PLAYFIELD_HEIGHT) then
|
||||
floatdev.y = -floatdev.h
|
||||
end
|
||||
if floatdev.y + floatdev.h < t2p(0) then
|
||||
floatdev.y = t2p(game.PLAYFIELD_HEIGHT)
|
||||
end
|
||||
end
|
||||
if not player.floating then
|
||||
if player.float_speed == 0 then
|
||||
for i, water in ipairs(game.entities.waters) do
|
||||
if not player.dead and rectanglesIntersect(playerRect, water) then
|
||||
player.dead = true
|
||||
|
|
65
map.lua
65
map.lua
|
@ -9,7 +9,7 @@ return {
|
|||
tilewidth = 16,
|
||||
tileheight = 16,
|
||||
nextlayerid = 4,
|
||||
nextobjectid = 12,
|
||||
nextobjectid = 15,
|
||||
properties = {},
|
||||
tilesets = {
|
||||
{
|
||||
|
@ -89,11 +89,11 @@ return {
|
|||
type = "water",
|
||||
shape = "rectangle",
|
||||
x = 80,
|
||||
y = -0.25,
|
||||
y = 0,
|
||||
width = 48,
|
||||
height = 160,
|
||||
rotation = 0,
|
||||
visible = false,
|
||||
visible = true,
|
||||
properties = {}
|
||||
},
|
||||
{
|
||||
|
@ -106,7 +106,7 @@ return {
|
|||
width = 64,
|
||||
height = 160,
|
||||
rotation = 0,
|
||||
visible = false,
|
||||
visible = true,
|
||||
properties = {}
|
||||
}
|
||||
}
|
||||
|
@ -157,12 +157,27 @@ return {
|
|||
type = "floatdev",
|
||||
shape = "rectangle",
|
||||
x = 98,
|
||||
y = 32,
|
||||
y = 16,
|
||||
width = 12,
|
||||
height = 32,
|
||||
rotation = 0,
|
||||
visible = true,
|
||||
properties = {}
|
||||
},
|
||||
{
|
||||
id = 12,
|
||||
name = "",
|
||||
type = "floatdev",
|
||||
shape = "rectangle",
|
||||
x = 114,
|
||||
y = 16,
|
||||
width = 12,
|
||||
height = 16,
|
||||
rotation = 0,
|
||||
visible = true,
|
||||
properties = {}
|
||||
properties = {
|
||||
["speed"] = -10
|
||||
}
|
||||
},
|
||||
{
|
||||
id = 2,
|
||||
|
@ -196,12 +211,27 @@ return {
|
|||
type = "floatdev",
|
||||
shape = "rectangle",
|
||||
x = 98,
|
||||
y = 98,
|
||||
y = 72,
|
||||
width = 12,
|
||||
height = 32,
|
||||
rotation = 0,
|
||||
visible = true,
|
||||
properties = {}
|
||||
},
|
||||
{
|
||||
id = 13,
|
||||
name = "",
|
||||
type = "floatdev",
|
||||
shape = "rectangle",
|
||||
x = 114,
|
||||
y = 80,
|
||||
width = 12,
|
||||
height = 16,
|
||||
rotation = 0,
|
||||
visible = true,
|
||||
properties = {}
|
||||
properties = {
|
||||
["speed"] = -10
|
||||
}
|
||||
},
|
||||
{
|
||||
id = 3,
|
||||
|
@ -235,12 +265,27 @@ return {
|
|||
type = "floatdev",
|
||||
shape = "rectangle",
|
||||
x = 98,
|
||||
y = 160,
|
||||
y = 128,
|
||||
width = 12,
|
||||
height = 32,
|
||||
rotation = 0,
|
||||
visible = true,
|
||||
properties = {}
|
||||
},
|
||||
{
|
||||
id = 14,
|
||||
name = "",
|
||||
type = "floatdev",
|
||||
shape = "rectangle",
|
||||
x = 114,
|
||||
y = 144,
|
||||
width = 12,
|
||||
height = 16,
|
||||
rotation = 0,
|
||||
visible = true,
|
||||
properties = {}
|
||||
properties = {
|
||||
["speed"] = -10
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
25
map.tmx
25
map.tmx
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<map version="1.8" tiledversion="1.8.6" orientation="orthogonal" renderorder="right-down" width="20" height="10" tilewidth="16" tileheight="16" infinite="0" nextlayerid="4" nextobjectid="12">
|
||||
<map version="1.8" tiledversion="1.8.6" orientation="orthogonal" renderorder="right-down" width="20" height="10" tilewidth="16" tileheight="16" infinite="0" nextlayerid="4" nextobjectid="15">
|
||||
<editorsettings>
|
||||
<export target="map.lua" format="lua"/>
|
||||
</editorsettings>
|
||||
|
@ -21,18 +21,33 @@
|
|||
</data>
|
||||
</layer>
|
||||
<objectgroup id="3" name="hazards">
|
||||
<object id="4" type="water" x="80" y="-0.25" width="48" height="160"/>
|
||||
<object id="4" type="water" x="80" y="0" width="48" height="160"/>
|
||||
<object id="5" type="water" x="144" y="0" width="64" height="160"/>
|
||||
</objectgroup>
|
||||
<objectgroup id="2" name="entities" tintcolor="#aa0000">
|
||||
<object id="1" type="vehicle" x="18" y="0" width="12" height="16"/>
|
||||
<object id="8" type="floatdev" x="82" y="0" width="12" height="16"/>
|
||||
<object id="11" type="floatdev" x="98" y="32" width="12" height="16"/>
|
||||
<object id="11" type="floatdev" x="98" y="16" width="12" height="32"/>
|
||||
<object id="12" type="floatdev" x="114" y="16" width="12" height="16">
|
||||
<properties>
|
||||
<property name="speed" type="int" value="-10"/>
|
||||
</properties>
|
||||
</object>
|
||||
<object id="2" type="vehicle" x="18" y="64" width="12" height="16"/>
|
||||
<object id="7" type="floatdev" x="82" y="64" width="12" height="16"/>
|
||||
<object id="10" type="floatdev" x="98" y="98" width="12" height="16"/>
|
||||
<object id="10" type="floatdev" x="98" y="72" width="12" height="32"/>
|
||||
<object id="13" type="floatdev" x="114" y="80" width="12" height="16">
|
||||
<properties>
|
||||
<property name="speed" type="int" value="-10"/>
|
||||
</properties>
|
||||
</object>
|
||||
<object id="3" type="vehicle" x="18" y="128" width="12" height="16"/>
|
||||
<object id="6" type="floatdev" x="82" y="128" width="12" height="16"/>
|
||||
<object id="9" type="floatdev" x="98" y="160" width="12" height="16"/>
|
||||
<object id="9" type="floatdev" x="98" y="128" width="12" height="32"/>
|
||||
<object id="14" type="floatdev" x="114" y="144" width="12" height="16">
|
||||
<properties>
|
||||
<property name="speed" type="int" value="-10"/>
|
||||
</properties>
|
||||
</object>
|
||||
</objectgroup>
|
||||
</map>
|
||||
|
|
Loading…
Reference in New Issue
Block a user