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