feat(exemple/topdown): port topdown exemple

This commit is contained in:
Kazhnuz 2024-10-30 18:38:11 +01:00
parent f091c8ede5
commit cf9c82814d
8 changed files with 138 additions and 92 deletions

View file

@ -9,8 +9,8 @@ return {
height = 30,
tilewidth = 16,
tileheight = 16,
nextlayerid = 5,
nextobjectid = 18,
nextlayerid = 6,
nextobjectid = 24,
properties = {},
tilesets = {
{
@ -346,6 +346,87 @@ return {
properties = {}
}
}
},
{
type = "objectgroup",
draworder = "topdown",
id = 5,
name = "collectibles.coin",
class = "",
visible = true,
opacity = 1,
offsetx = 0,
offsety = 0,
parallaxx = 1,
parallaxy = 1,
properties = {},
objects = {
{
id = 19,
name = "",
type = "",
shape = "rectangle",
x = 112,
y = 80,
width = 16,
height = 16,
rotation = 0,
visible = true,
properties = {}
},
{
id = 20,
name = "",
type = "",
shape = "rectangle",
x = 144,
y = 80,
width = 16,
height = 16,
rotation = 0,
visible = true,
properties = {}
},
{
id = 21,
name = "",
type = "",
shape = "rectangle",
x = 176,
y = 80,
width = 16,
height = 16,
rotation = 0,
visible = true,
properties = {}
},
{
id = 22,
name = "",
type = "",
shape = "rectangle",
x = 208,
y = 80,
width = 16,
height = 16,
rotation = 0,
visible = true,
properties = {}
},
{
id = 23,
name = "",
type = "",
shape = "rectangle",
x = 240,
y = 80,
width = 16,
height = 16,
rotation = 0,
visible = true,
properties = {}
}
}
}
}
}

View file

@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.11.0" orientation="orthogonal" renderorder="right-down" width="30" height="30" tilewidth="16" tileheight="16" infinite="0" nextlayerid="5" nextobjectid="18">
<map version="1.10" tiledversion="1.11.0" orientation="orthogonal" renderorder="right-down" width="30" height="30" tilewidth="16" tileheight="16" infinite="0" nextlayerid="6" nextobjectid="24">
<editorsettings>
<export target="arena.lua" format="lua"/>
</editorsettings>
<tileset firstgid="1" source="overworld.tsx"/>
<layer id="1" name="Calque de Tile 1" width="30" height="30">
<data encoding="csv">
@ -90,4 +93,11 @@
<object id="16" x="128" y="384" width="32" height="32"/>
<object id="17" x="80" y="288" width="32" height="32"/>
</objectgroup>
<objectgroup id="5" name="collectibles.coin">
<object id="19" x="112" y="80" width="16" height="16"/>
<object id="20" x="144" y="80" width="16" height="16"/>
<object id="21" x="176" y="80" width="16" height="16"/>
<object id="22" x="208" y="80" width="16" height="16"/>
<object id="23" x="240" y="80" width="16" height="16"/>
</objectgroup>
</map>

View file

@ -0,0 +1,14 @@
return actor {
type = "coin",
dimensions = {w = 16, h = 16},
isSolid = false,
visuals = {
mode = "box",
color = {r = 1, g = 1, b = 0}
},
onPlayerCollision = function (self, player)
self:destroy()
assets:playSFX("gameplay.collectcoin")
player.coin = player.coin + 1
end
}

View file

@ -1,13 +0,0 @@
local Obj = {}
-- On charge toutes les différentes types d'acteurs
local cwd = (...):gsub('%.init$', '') .. "."
Obj.Player = require(cwd .. "player")
Obj.index = {}
Obj.index["player"] = Obj.Player
Obj.collisions = {}
Obj.collisions["wall"] = require(cwd .. "wall")
return Obj

View file

@ -1,13 +0,0 @@
local Base = require "framework.scenes.world.actors.actor2D"
local Parent = Base:extend()
function Parent:new(world, type, x, y, w, h, isSolid)
self.scene = world.scene
Parent.super.new(self, world, type, x, y, w, h, isSolid)
end
function Parent:draw()
self:drawMainHitbox()
end
return Parent

View file

@ -1,35 +1,37 @@
local cwd = (...):gsub('%.player$', '') .. "."
local Parent = require(cwd .. "parent")
local Player = Parent:extend()
function Player:new(world, x, y, id)
Player.super.new(self, world, "player", x, y, 16, 16, true)
local Player = actor {
type = "player",
dimensions = {w = 16, h = 16},
isSolid = true,
visuals = {
mode = "box",
color = {r = .5, g = 0, b = 0}
}
}
function Player:onInit()
self.coin = 0
end
function Player:updateStart(dt)
self.xfrc, self.yfrc = 480*3, 480*3
function Player:update(dt)
self.friction.x, self.friction.y = 480*3, 480*3
if self.keys["up"].isDown then
self.ysp = -120
if love.keyboard.isDown("up") then
self.speed.y = -120
end
if self.keys["down"].isDown then
self.ysp = 120
if love.keyboard.isDown("down") then
self.speed.y = 120
end
if self.keys["left"].isDown then
self.xsp = -120
if love.keyboard.isDown("left") then
self.speed.x = -120
end
if self.keys["right"].isDown then
self.xsp = 120
if love.keyboard.isDown("right") then
self.speed.x = 120
end
end
function Player:draw()
Player.super.draw(self)
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

View file

@ -1,14 +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)
self:setDebugColor(0,0,0)
end
function Wall:draw()
self:drawMainHitbox()
utils.graphics.resetColor( )
end
return Wall

View file

@ -21,31 +21,10 @@
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
]]
local Scene = require "framework.scenes"
local MovePlayer = Scene:extend()
local World = require "framework.scenes.world.world2D"
function MovePlayer:new(playerNumber, cameraMode)
local playerNumber = playerNumber or 1
local cameraMode = cameraMode or "split"
MovePlayer.super.new(self)
World(self, "scenes.gameplay.moveplayer.actors", "datas/maps/topdown/arena.lua")
self.world:setPlayerNumber(playerNumber)
self.world.cameras:setMode(cameraMode)
self.world:loadMap()
end
function MovePlayer:update(dt)
end
function MovePlayer:draw()
end
return MovePlayer
return world {
actorPath = "scenes.gameplay.moveplayer.actors",
defaultMap = "datas/maps/topdown/arena.lua",
collisions = {
wall = {isSolid = true, type = "wall"}
}
}