player respawn, spikes & hazard objects
This commit is contained in:
parent
2ce41d541f
commit
7f42dea6fa
Binary file not shown.
Before Width: | Height: | Size: 4.1 KiB After Width: | Height: | Size: 4.0 KiB |
|
@ -1,6 +1,9 @@
|
||||||
return {
|
return {
|
||||||
name = "test",
|
name = "test",
|
||||||
tileset = tileset.library,
|
tileset = tileset.library,
|
||||||
|
properties = {
|
||||||
|
darkness = false
|
||||||
|
},
|
||||||
tiles = {
|
tiles = {
|
||||||
{ 1, 14, 14, 14, 14, 14, 14, 1, 14, 14, 14, 14, 14, 14, 14, 1},
|
{ 1, 14, 14, 14, 14, 14, 14, 1, 14, 14, 14, 14, 14, 14, 14, 1},
|
||||||
{ 1, 4, 0, 0, 0, 0, 2, 14, 4, 0, 0, 0, 0, 0, 2, 1},
|
{ 1, 4, 0, 0, 0, 0, 2, 14, 4, 0, 0, 0, 0, 0, 2, 1},
|
||||||
|
|
|
@ -45,6 +45,14 @@
|
||||||
o.canFall = true
|
o.canFall = true
|
||||||
o.canFriction = true
|
o.canFriction = true
|
||||||
o.maskType = animation.moth_mask
|
o.maskType = animation.moth_mask
|
||||||
|
o.anchorRespawn = {
|
||||||
|
x = o.pos.x,
|
||||||
|
y = o.pos.y
|
||||||
|
}
|
||||||
|
o.anchorRope = {
|
||||||
|
x = nil,
|
||||||
|
y = nil
|
||||||
|
}
|
||||||
|
|
||||||
-- sprite
|
-- sprite
|
||||||
o.target_offset = {x = 0, y = 0}
|
o.target_offset = {x = 0, y = 0}
|
||||||
|
@ -166,6 +174,15 @@ function Player:DoPhysics()
|
||||||
self.vel.y = 0
|
self.vel.y = 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if self:isCollidingAt(self.pos.x, self.pos.y, LoadedObjects.Hazards) then
|
||||||
|
self:Respawn()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Player:Respawn()
|
||||||
|
self.pos.x = self.anchorRespawn.x
|
||||||
|
self.pos.y = self.anchorRespawn.y
|
||||||
end
|
end
|
||||||
|
|
||||||
function Player:HandleAnimation()
|
function Player:HandleAnimation()
|
||||||
|
|
|
@ -53,7 +53,9 @@ function GameDraw()
|
||||||
GameworldDrawPrepare()
|
GameworldDrawPrepare()
|
||||||
GameworldDrawBackground()
|
GameworldDrawBackground()
|
||||||
GameworldDrawForeground()
|
GameworldDrawForeground()
|
||||||
|
if LevelData.properties.darkness then
|
||||||
GameworldDrawLighting()
|
GameworldDrawLighting()
|
||||||
|
end
|
||||||
GameworldDrawParticles()
|
GameworldDrawParticles()
|
||||||
GameworldDrawEntities()
|
GameworldDrawEntities()
|
||||||
GameworldDrawEnd()
|
GameworldDrawEnd()
|
||||||
|
|
|
@ -3,19 +3,28 @@ function ExportLevel(levelname, filename)
|
||||||
filename = filename or "output.lua"
|
filename = filename or "output.lua"
|
||||||
filename = "Mothback/export/"..filename
|
filename = "Mothback/export/"..filename
|
||||||
exportFile = io.open(filename, "w+")
|
exportFile = io.open(filename, "w+")
|
||||||
|
|
||||||
if exportFile then
|
if exportFile then
|
||||||
exportFile:write("return {")
|
|
||||||
logPrint("Exporting level \"".. levelname .. "\"...")
|
logPrint("Exporting level \"".. levelname .. "\"...")
|
||||||
exportFile:write("\n name = \"" .. levelname .. "\",")
|
exportFile:write("return {")
|
||||||
|
|
||||||
logPrint("- level name")
|
logPrint("- level name")
|
||||||
|
exportFile:write("\n name = \"" .. levelname .. "\",")
|
||||||
|
|
||||||
|
logPrint("- tileset")
|
||||||
for k, v in pairs(tileset) do
|
for k, v in pairs(tileset) do
|
||||||
if v == LevelData.tileset then
|
if v == LevelData.tileset then
|
||||||
exportFile:write("\n tileset = tileset." .. k .. ",")
|
exportFile:write("\n tileset = tileset." .. k .. ",")
|
||||||
logPrint("- tileset")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
exportFile:write("\n tiles = {")
|
|
||||||
|
logPrint("- properties")
|
||||||
|
exportFile:write("\n properties = {")
|
||||||
|
exportFile:write("\n darkness = true")
|
||||||
|
exportFile:write("\n },")
|
||||||
|
|
||||||
logPrint("- tiles")
|
logPrint("- tiles")
|
||||||
|
exportFile:write("\n tiles = {")
|
||||||
local rows = #LevelTiles
|
local rows = #LevelTiles
|
||||||
for i = 1, #LevelTiles do
|
for i = 1, #LevelTiles do
|
||||||
exportFile:write("\n { ")
|
exportFile:write("\n { ")
|
||||||
|
@ -33,10 +42,12 @@ function ExportLevel(levelname, filename)
|
||||||
end
|
end
|
||||||
logPrint(" - All rows 100%")
|
logPrint(" - All rows 100%")
|
||||||
exportFile:write("\n },")
|
exportFile:write("\n },")
|
||||||
exportFile:write("\n objects = {}")
|
|
||||||
logPrint("- objects")
|
logPrint("- objects")
|
||||||
exportFile:write("\n}")
|
exportFile:write("\n objects = {}")
|
||||||
|
|
||||||
logPrint("Exporting complete.")
|
logPrint("Exporting complete.")
|
||||||
|
exportFile:write("\n}")
|
||||||
exportFile:close()
|
exportFile:close()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -338,6 +338,7 @@ function TileCreateObjects()
|
||||||
LoadedObjects.Collisions = {}
|
LoadedObjects.Collisions = {}
|
||||||
LoadedObjects.Platforms = {}
|
LoadedObjects.Platforms = {}
|
||||||
LoadedObjects.Ladders = {}
|
LoadedObjects.Ladders = {}
|
||||||
|
LoadedObjects.Hazards = {}
|
||||||
|
|
||||||
TileOptimizeObjects()
|
TileOptimizeObjects()
|
||||||
|
|
||||||
|
@ -625,6 +626,17 @@ function TileCreateObjects()
|
||||||
)
|
)
|
||||||
table.insert(LoadedObjects.Platforms,plat)
|
table.insert(LoadedObjects.Platforms,plat)
|
||||||
|
|
||||||
|
elseif type == "bottom_hazard" then
|
||||||
|
|
||||||
|
|
||||||
|
local hazard = Collision:New(
|
||||||
|
base_x,
|
||||||
|
base_y + tileProperties.height * 12/16 * tileProperties.scale,
|
||||||
|
base_x + tileProperties.width * tileProperties.scale,
|
||||||
|
base_y + tileProperties.height * tileProperties.scale
|
||||||
|
)
|
||||||
|
table.insert(LoadedObjects.Hazards,hazard)
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,8 @@ LoadedObjects = {
|
||||||
|
|
||||||
Collisions = {},
|
Collisions = {},
|
||||||
Platforms = {},
|
Platforms = {},
|
||||||
Ladders = {}
|
Ladders = {},
|
||||||
|
Hazards = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
-- level functions
|
-- level functions
|
||||||
|
@ -20,6 +21,10 @@ function LoadedObjects.DrawCollisions()
|
||||||
for _, ladder in pairs(LoadedObjects.Ladders) do
|
for _, ladder in pairs(LoadedObjects.Ladders) do
|
||||||
ladder:Draw(2)
|
ladder:Draw(2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
for _, hazard in pairs(LoadedObjects.Hazards) do
|
||||||
|
hazard:Draw(1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- returns true if theres a collision at that point
|
-- returns true if theres a collision at that point
|
||||||
|
@ -58,7 +63,8 @@ function SetCollisionFlags()
|
||||||
local Check = {
|
local Check = {
|
||||||
LoadedObjects.Collisions,
|
LoadedObjects.Collisions,
|
||||||
LoadedObjects.Ladders,
|
LoadedObjects.Ladders,
|
||||||
LoadedObjects.Platforms
|
LoadedObjects.Platforms,
|
||||||
|
LoadedObjects.Hazards
|
||||||
}
|
}
|
||||||
for _, type in pairs(Check) do
|
for _, type in pairs(Check) do
|
||||||
for _, object in pairs(type) do
|
for _, object in pairs(type) do
|
||||||
|
@ -72,4 +78,11 @@ function SetCollisionFlags()
|
||||||
platform.disable = true
|
platform.disable = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
for _, platform in pairs(LoadedObjects.Hazards) do
|
||||||
|
if main_Player.isOnGround then
|
||||||
|
platform.disable = true
|
||||||
|
else
|
||||||
|
platform.disable = false
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -82,15 +82,13 @@ properties[50] = {
|
||||||
}
|
}
|
||||||
|
|
||||||
properties[61] = {
|
properties[61] = {
|
||||||
overlay = {1},
|
type = "bottom_hazard",
|
||||||
type = "emtpy",
|
depth = "foreground"
|
||||||
depth = "background"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
properties[62] = {
|
properties[62] = {
|
||||||
overlay = {1},
|
type = "top_hazard",
|
||||||
type = "emtpy",
|
depth = "foreground"
|
||||||
depth = "background"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return properties
|
return properties
|
||||||
|
|
Loading…
Reference in New Issue