feat(exemples): port the plateformer exemple to the new world system
This commit is contained in:
parent
e40683a6b0
commit
816c6fee22
9 changed files with 77 additions and 241 deletions
|
@ -48,6 +48,9 @@ return {
|
|||
loop = 1,
|
||||
speed = 0,
|
||||
pauseAtEnd = false,
|
||||
areas = {
|
||||
["frame1"] = {{type = "punch", box = {position = {x = 16, y = 6}, dimensions = {w = 12, h = 12}}, isSolid = false}}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
local Base = require "framework.scenes.world.actors.actor2D"
|
||||
local Coin = Base:extend()
|
||||
|
||||
function Coin:new(world, x, y)
|
||||
Coin.super.new(self, world, "coin", x, y, 16, 16, false)
|
||||
self:setSprite("coin")
|
||||
end
|
||||
|
||||
function Coin:takeCoin(other)
|
||||
self.obj.GFX(self.world, self.x + 8, self.y + 8, "gfx.sparkle")
|
||||
assets:playSFX("gameplay.collectcoin")
|
||||
self:destroy( )
|
||||
end
|
||||
|
||||
return Coin
|
||||
return actor {
|
||||
type = "coin",
|
||||
dimensions = { w = 16, h = 16 },
|
||||
isSolid = false,
|
||||
visuals = {
|
||||
mode = "sprite",
|
||||
assetName = "coin"
|
||||
},
|
||||
onPlayerCollision = function (self, player)
|
||||
self:destroy()
|
||||
assets:playSFX("gameplay.collectcoin")
|
||||
self.world:showGFX("gfx.sparkle", self.position)
|
||||
player.coin = player.coin + 1
|
||||
end
|
||||
}
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
return {
|
||||
["idle"] = {
|
||||
{
|
||||
{"main", {0, 0, 16, 24}, true}
|
||||
}
|
||||
},
|
||||
["punch"] = {
|
||||
{
|
||||
{"main", {0, 0, 16, 24}, true},
|
||||
{"punch", {16, 6, 12, 12}, false}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
local Obj = {}
|
||||
|
||||
-- On charge toutes les différentes types d'acteurs
|
||||
local cwd = (...):gsub('%.init$', '') .. "."
|
||||
|
||||
Obj.Player = require(cwd .. "player")
|
||||
Obj.GFX = require("framework.scenes.world.actors.gfx2D")
|
||||
|
||||
Obj.index = {}
|
||||
Obj.index["player"] = require(cwd .. "player")
|
||||
Obj.index["coin"] = require(cwd .. "coin")
|
||||
|
||||
Obj.collisions = {}
|
||||
Obj.collisions["wall"] = require(cwd .. "wall")
|
||||
|
||||
return Obj
|
|
@ -1,83 +1,79 @@
|
|||
local Base = require "framework.scenes.world.actors.actor2D"
|
||||
local Player = Base:extend()
|
||||
local Player = actor {
|
||||
type = "player",
|
||||
dimensions = { w = 16, h = 24 },
|
||||
friction = { x = 480 * 3 },
|
||||
isSolid = true,
|
||||
visuals = {
|
||||
mode = "sprite",
|
||||
assetName = "monkey_lad",
|
||||
clone = true,
|
||||
origin = {
|
||||
x = 8,
|
||||
y = 12
|
||||
},
|
||||
getHitboxes = true
|
||||
},
|
||||
gravity = { axis = "y", value = 480 },
|
||||
drawHitboxes = true
|
||||
}
|
||||
|
||||
function Player:new(world, x, y, id)
|
||||
Player.super.new(self, world, "player", x, y, 16, 24, true)
|
||||
self:setSprite("monkey_lad", true, 8, 12)
|
||||
self:setGravity(480)
|
||||
|
||||
self.isPunching = false
|
||||
self.direction = 1
|
||||
self.startx, self.starty = self.x, self.y
|
||||
function Player:onInit()
|
||||
self.isDead = false
|
||||
|
||||
self.start = self.position:clone()
|
||||
self.isPunching = false
|
||||
self.direction = 1
|
||||
self.coin = 0
|
||||
self.punchName = ""
|
||||
self:setHitboxFile("scenes.gameplay.plateform.actors.hitboxes.player")
|
||||
end
|
||||
|
||||
function Player:updateStart(dt)
|
||||
self.xfrc = 480*3
|
||||
|
||||
if self.keys["up"].isPressed and (self.onGround) then
|
||||
self.ysp = -280
|
||||
function Player:update(dt)
|
||||
if love.keyboard.isDown("up") and (self.onGround) then
|
||||
self.speed.y = -280
|
||||
assets:playSFX("gameplay.jump")
|
||||
end
|
||||
if self.keys["down"].isDown then
|
||||
self.mainHitbox:modify(0, 8, 16, 16)
|
||||
if love.keyboard.isDown("down") then
|
||||
self.mainHitbox:modify({x = 0, y = 8}, {w = 16, h = 16})
|
||||
else
|
||||
self.mainHitbox:modify(0, 0, 16, 24)
|
||||
self.mainHitbox:modify({x = 0, y = 0}, {w = 16, h = 24})
|
||||
end
|
||||
if self.keys["left"].isDown and (not self.isPunching) then
|
||||
self.xsp = -120
|
||||
if love.keyboard.isDown("left") and (not self.isPunching) then
|
||||
self.speed.x = -120
|
||||
end
|
||||
if self.keys["right"].isDown and (not self.isPunching) then
|
||||
self.xsp = 120
|
||||
if love.keyboard.isDown("right") and (not self.isPunching) then
|
||||
self.speed.x = 120
|
||||
end
|
||||
|
||||
if self.keys["A"].isDown then
|
||||
if love.keyboard.isDown("a") then
|
||||
self.isPunching = true
|
||||
else
|
||||
self.isPunching = false
|
||||
end
|
||||
|
||||
if (self.isPunching) then
|
||||
self:applyHitboxesCollisions()
|
||||
end
|
||||
|
||||
if self.keys["start"].isPressed then
|
||||
self.scene.menusystem:activate()
|
||||
self.scene.menusystem:switchMenu("PauseMenu")
|
||||
self.scene:flushKeys()
|
||||
end
|
||||
|
||||
self:setDirection(self.xsp)
|
||||
end
|
||||
|
||||
function Player:updateEnd(dt)
|
||||
self:setDirection(self.speed.x)
|
||||
self:setAnimation()
|
||||
|
||||
local width, height = self.world:getDimensions()
|
||||
local _, dimensions = self.world:getBox()
|
||||
|
||||
if (self.y > height + self.h) and (self.isDead == false) then
|
||||
self:addTimer("respawn", 1)
|
||||
if (self.position.y > (dimensions.h + self.dimensions.h)) and (self.isDead == false) then
|
||||
self.timers:newTimer(1, "respawn")
|
||||
self.isDead = true
|
||||
end
|
||||
end
|
||||
|
||||
function Player:setAnimation()
|
||||
self.sprite:setCustomSpeed(math.abs(self.xsp) / 12)
|
||||
self.visual:setCustomSpeed(math.abs(self.speed.x) / 12)
|
||||
if (self.isPunching) then
|
||||
self.sprite:changeAnimation("punch", false)
|
||||
self.visual:changeAnimation("punch", false)
|
||||
else
|
||||
if (self.onGround) then
|
||||
if math.abs(self.xsp) > 0 then
|
||||
self.sprite:changeAnimation("walk", false)
|
||||
if (self.onGround) then
|
||||
if math.abs(self.speed.x) > 0 then
|
||||
self.visual:changeAnimation("walk", false)
|
||||
else
|
||||
self.visual:changeAnimation("idle", true)
|
||||
end
|
||||
else
|
||||
self.sprite:changeAnimation("idle", true)
|
||||
self.visual:changeAnimation("jump", true)
|
||||
end
|
||||
else
|
||||
self.sprite:changeAnimation("jump", true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -86,39 +82,20 @@ function Player:setDirection(direction)
|
|||
if direction ~= 0 then
|
||||
direction = utils.math.sign(direction)
|
||||
self.direction = direction
|
||||
self.sprite:setScallingX(direction)
|
||||
self.visual:setScalling({x = direction})
|
||||
end
|
||||
end
|
||||
|
||||
function Player:timerResponse(timer)
|
||||
if timer == "respawn" then
|
||||
self.x, self.y = self.startx, self.starty
|
||||
self.xspeed = 0
|
||||
self.yspeed = 0
|
||||
self.position.x, self.position.y = self.start.x, self.start.y
|
||||
self.speed.x, self.speed.y = 0, 0
|
||||
self.isDead = false
|
||||
end
|
||||
end
|
||||
|
||||
function Player:collisionResponse(collision)
|
||||
if collision.other.type == "coin" then
|
||||
collision.other.owner:takeCoin(self)
|
||||
end
|
||||
end
|
||||
|
||||
function Player:hitboxResponse(name, type, collision)
|
||||
if (collision.other.type == "coin") and (type == "punch") then
|
||||
collision.other.owner:takeCoin(self)
|
||||
end
|
||||
end
|
||||
|
||||
function Player:draw()
|
||||
Player.super.draw(self)
|
||||
self:drawHitboxes()
|
||||
utils.graphics.resetColor()
|
||||
end
|
||||
|
||||
function Player:drawHUD(id)
|
||||
love.graphics.print(id .. " test", 4, 4)
|
||||
function Player:drawHUD()
|
||||
assets:print("medium", "Coins : " .. self.coin, 8, 8)
|
||||
end
|
||||
|
||||
return Player
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
local Base = require "framework.scenes.world.actors.actor2D"
|
||||
local Wall = Base:extend()
|
||||
|
||||
function Wall:new(world, x, y, w, h)
|
||||
Wall.super.new(self, world, "wall", x, y, w, h, true)
|
||||
end
|
||||
|
||||
return Wall
|
|
@ -1,19 +0,0 @@
|
|||
return {
|
||||
["textures"] = {
|
||||
{"box", "assets/sprites/box.png"},
|
||||
{"boxtop", "assets/sprites/boxtop.png"}
|
||||
},
|
||||
["sprites"] = {
|
||||
{"player", "assets/sprites/monkey_lad"},
|
||||
{"coin", "assets/sprites/coin"},
|
||||
{"sparkle", "assets/sprites/gfx/sparkle"}
|
||||
},
|
||||
["imagefonts"] = {
|
||||
{"medium", "assets/fonts/medium"}
|
||||
},
|
||||
["sfx"] = {
|
||||
{"navigate", "assets/sfx/menu_move.mp3"},
|
||||
{"confirm", "assets/sfx/menu_confirm.mp3"},
|
||||
{"cancel", "assets/sfx/menu_error.mp3"},
|
||||
}
|
||||
}
|
|
@ -21,46 +21,18 @@
|
|||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
]]
|
||||
|
||||
local Scene = require "framework.scenes"
|
||||
local Plateformer = Scene:extend()
|
||||
|
||||
local World = require "framework.scenes.world.world2D"
|
||||
local Pause = require "scenes.gameplay.plateform.pause"
|
||||
|
||||
function Plateformer:new()
|
||||
Plateformer.super.new(self)
|
||||
|
||||
local folder = "scenes.gameplay.plateform"
|
||||
|
||||
World(self, folder .. ".actors", "datas/maps/plateformer/platformer.lua")
|
||||
|
||||
--Pause(self)
|
||||
--self.menusystem:deactivate()
|
||||
--self.menusystem:lockWorldWhenActive(true)
|
||||
--self.menusystem:lockAssetsWhenActive(true)
|
||||
|
||||
self.world:loadMap()
|
||||
end
|
||||
local Plateformer = world {
|
||||
actorPath = "scenes.gameplay.plateform.actors",
|
||||
defaultMap = "datas/maps/plateformer/platformer.lua",
|
||||
collisions = {
|
||||
wall = {isSolid = true, type = "wall"}
|
||||
}
|
||||
}
|
||||
|
||||
function Plateformer:restart()
|
||||
--self.menusystem:deactivate()
|
||||
collectgarbage()
|
||||
self.world:reset()
|
||||
end
|
||||
|
||||
function Plateformer:update(dt)
|
||||
--if (self.menusystem.isActive == true) and self.sources[1].keys["start"].isPressed then
|
||||
--self.menusystem:deactivate()
|
||||
--end
|
||||
end
|
||||
|
||||
function Plateformer:draw()
|
||||
if (self.world.isActive == false) then
|
||||
local w, h = core.screen:getDimensions()
|
||||
love.graphics.setColor(1, 1, 0, 1)
|
||||
love.graphics.printf("PAUSE", 0, 24*3, w, "center")
|
||||
utils.graphics.resetColor()
|
||||
end
|
||||
end
|
||||
|
||||
return Plateformer
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
local ListMenu = require "framework.scenes.gui.menus.listbox"
|
||||
local Widget = require "framework.scenes.gui.menus.widgets"
|
||||
|
||||
local PauseMenu = ListMenu:extend()
|
||||
|
||||
local ResumeWidget = Widget.Text:extend()
|
||||
local RestartWidget = Widget.Text:extend()
|
||||
local ExitWidget = Widget.Text:extend()
|
||||
|
||||
local MENU_NAME = "PauseMenu"
|
||||
|
||||
function PauseMenu:new(scene)
|
||||
self.scene = scene
|
||||
local screenHeight, screenWidth = core.screen:getDimensions()
|
||||
local w, h = 424/4, 240 - 48*4
|
||||
local x, y = 3*w/2, 24*4
|
||||
PauseMenu.super.new(self, scene.menusystem, MENU_NAME, x, y, w, h, 3)
|
||||
|
||||
ResumeWidget()
|
||||
RestartWidget()
|
||||
ExitWidget()
|
||||
end
|
||||
|
||||
-- WIDGETS
|
||||
-- All widgets used by the pause menu
|
||||
|
||||
function ResumeWidget:new()
|
||||
self.scene = core.scenemanager:getScene()
|
||||
local label = "resume"
|
||||
ResumeWidget.super.new(self, MENU_NAME, "medium", label)
|
||||
end
|
||||
|
||||
function ResumeWidget:action()
|
||||
assets:playSFX(self.sfx)
|
||||
self.scene.menusystem:deactivate()
|
||||
end
|
||||
|
||||
function RestartWidget:new()
|
||||
self.scene = core.scenemanager:getScene()
|
||||
local label = "restart"
|
||||
RestartWidget.super.new(self, MENU_NAME, "medium", label)
|
||||
end
|
||||
|
||||
function RestartWidget:action()
|
||||
assets:playSFX(self.sfx)
|
||||
self.scene:restart()
|
||||
end
|
||||
|
||||
function ExitWidget:new()
|
||||
self.scene = core.scenemanager:getScene()
|
||||
local label = "exit"
|
||||
ExitWidget.super.new(self, MENU_NAME, "medium", label)
|
||||
end
|
||||
|
||||
function ExitWidget:action()
|
||||
assets:playSFX(self.sfx)
|
||||
core.scenemanager:setStoredScene("mainmenu")
|
||||
end
|
||||
|
||||
return PauseMenu
|
Loading…
Add table
Reference in a new issue