player respawn, spikes & hazard objects

This commit is contained in:
lustlion 2022-02-10 15:53:50 +01:00
parent 2ce41d541f
commit 7f42dea6fa
9 changed files with 83 additions and 27 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

View File

@ -1,18 +1,21 @@
return {
name = "test",
tileset = tileset.library,
properties = {
darkness = false
},
tiles = {
{ 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, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1},
{ 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1},
{ 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1},
{ 1, 4, 0, 0, 0, 0, 2, 13, 4, 0, 0, 0, 0, 0, 2, 1},
{ 1, 13, 13, 13, 13, 13, 13, 1, 4, 0, 0, 0, 0, 0, 2, 1},
{ 1, 1, 1, 1, 1, 1, 1, 1, 4, 0, 0, 0, 0, 0, 2, 1},
{ 1, 1, 1, 1, 1, 1, 1, 1, 13, 13, 13, 13, 13, 13, 13, 1},
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1},
{ 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1},
{ 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1},
{ 1, 4, 0, 0, 0, 0, 2, 13, 4, 0, 0, 0, 0, 0, 2, 1},
{ 1, 13, 13, 13, 13, 13, 13, 1, 4, 0, 0, 0, 0, 0, 2, 1},
{ 1, 1, 1, 1, 1, 1, 1, 1, 4, 0, 0, 0, 0, 0, 2, 1},
{ 1, 1, 1, 1, 1, 1, 1, 1, 13, 13, 13, 13, 13, 13, 13, 1},
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
},
objects = {}
}
}

View File

@ -45,6 +45,14 @@
o.canFall = true
o.canFriction = true
o.maskType = animation.moth_mask
o.anchorRespawn = {
x = o.pos.x,
y = o.pos.y
}
o.anchorRope = {
x = nil,
y = nil
}
-- sprite
o.target_offset = {x = 0, y = 0}
@ -166,6 +174,15 @@ function Player:DoPhysics()
self.vel.y = 0
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
function Player:HandleAnimation()

View File

@ -53,7 +53,9 @@ function GameDraw()
GameworldDrawPrepare()
GameworldDrawBackground()
GameworldDrawForeground()
GameworldDrawLighting()
if LevelData.properties.darkness then
GameworldDrawLighting()
end
GameworldDrawParticles()
GameworldDrawEntities()
GameworldDrawEnd()

View File

@ -3,19 +3,28 @@ function ExportLevel(levelname, filename)
filename = filename or "output.lua"
filename = "Mothback/export/"..filename
exportFile = io.open(filename, "w+")
if exportFile then
exportFile:write("return {")
logPrint("Exporting level \"".. levelname .. "\"...")
exportFile:write("\n name = \"" .. levelname .. "\",")
exportFile:write("return {")
logPrint("- level name")
exportFile:write("\n name = \"" .. levelname .. "\",")
logPrint("- tileset")
for k, v in pairs(tileset) do
if v == LevelData.tileset then
exportFile:write("\n tileset = tileset." .. k .. ",")
logPrint("- tileset")
end
end
exportFile:write("\n tiles = {")
logPrint("- properties")
exportFile:write("\n properties = {")
exportFile:write("\n darkness = true")
exportFile:write("\n },")
logPrint("- tiles")
exportFile:write("\n tiles = {")
local rows = #LevelTiles
for i = 1, #LevelTiles do
exportFile:write("\n { ")
@ -33,10 +42,12 @@ function ExportLevel(levelname, filename)
end
logPrint(" - All rows 100%")
exportFile:write("\n },")
exportFile:write("\n objects = {}")
logPrint("- objects")
exportFile:write("\n}")
exportFile:write("\n objects = {}")
logPrint("Exporting complete.")
exportFile:write("\n}")
exportFile:close()
end
end

View File

@ -338,6 +338,7 @@ function TileCreateObjects()
LoadedObjects.Collisions = {}
LoadedObjects.Platforms = {}
LoadedObjects.Ladders = {}
LoadedObjects.Hazards = {}
TileOptimizeObjects()
@ -625,6 +626,17 @@ function TileCreateObjects()
)
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

View File

@ -3,7 +3,8 @@ LoadedObjects = {
Collisions = {},
Platforms = {},
Ladders = {}
Ladders = {},
Hazards = {}
}
-- level functions
@ -20,6 +21,10 @@ function LoadedObjects.DrawCollisions()
for _, ladder in pairs(LoadedObjects.Ladders) do
ladder:Draw(2)
end
for _, hazard in pairs(LoadedObjects.Hazards) do
hazard:Draw(1)
end
end
-- returns true if theres a collision at that point
@ -58,7 +63,8 @@ function SetCollisionFlags()
local Check = {
LoadedObjects.Collisions,
LoadedObjects.Ladders,
LoadedObjects.Platforms
LoadedObjects.Platforms,
LoadedObjects.Hazards
}
for _, type in pairs(Check) do
for _, object in pairs(type) do
@ -72,4 +78,11 @@ function SetCollisionFlags()
platform.disable = true
end
end
for _, platform in pairs(LoadedObjects.Hazards) do
if main_Player.isOnGround then
platform.disable = true
else
platform.disable = false
end
end
end

View File

@ -82,15 +82,13 @@ properties[50] = {
}
properties[61] = {
overlay = {1},
type = "emtpy",
depth = "background"
type = "bottom_hazard",
depth = "foreground"
}
properties[62] = {
overlay = {1},
type = "emtpy",
depth = "background"
type = "top_hazard",
depth = "foreground"
}
return properties

View File

@ -63,7 +63,7 @@ function love.load()
Fairy:New(200,88)
--CursedBook:New(180,68)
love.audio.play(music.placeholder)
--love.audio.play(music.placeholder)
end
function love.update(dt)