diff --git a/examples/datas/maps/topdown/arena.lua b/examples/datas/maps/topdown/arena.lua index 6199a60..8c50610 100644 --- a/examples/datas/maps/topdown/arena.lua +++ b/examples/datas/maps/topdown/arena.lua @@ -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 = {} + } + } } } } diff --git a/examples/datas/maps/topdown/arena.tmx b/examples/datas/maps/topdown/arena.tmx index bec3a98..0040dc6 100644 --- a/examples/datas/maps/topdown/arena.tmx +++ b/examples/datas/maps/topdown/arena.tmx @@ -1,5 +1,8 @@ - + + + + @@ -90,4 +93,11 @@ + + + + + + + diff --git a/examples/scenes/gameplay/moveplayer/actors/collectibles/coin.lua b/examples/scenes/gameplay/moveplayer/actors/collectibles/coin.lua new file mode 100644 index 0000000..62783f4 --- /dev/null +++ b/examples/scenes/gameplay/moveplayer/actors/collectibles/coin.lua @@ -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 +} \ No newline at end of file diff --git a/examples/scenes/gameplay/moveplayer/actors/init.lua b/examples/scenes/gameplay/moveplayer/actors/init.lua deleted file mode 100644 index 9d67a55..0000000 --- a/examples/scenes/gameplay/moveplayer/actors/init.lua +++ /dev/null @@ -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 diff --git a/examples/scenes/gameplay/moveplayer/actors/parent.lua b/examples/scenes/gameplay/moveplayer/actors/parent.lua deleted file mode 100644 index 9de5ea3..0000000 --- a/examples/scenes/gameplay/moveplayer/actors/parent.lua +++ /dev/null @@ -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 diff --git a/examples/scenes/gameplay/moveplayer/actors/player.lua b/examples/scenes/gameplay/moveplayer/actors/player.lua index 9e80089..b0436b4 100644 --- a/examples/scenes/gameplay/moveplayer/actors/player.lua +++ b/examples/scenes/gameplay/moveplayer/actors/player.lua @@ -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 diff --git a/examples/scenes/gameplay/moveplayer/actors/wall.lua b/examples/scenes/gameplay/moveplayer/actors/wall.lua deleted file mode 100644 index 2fa73dc..0000000 --- a/examples/scenes/gameplay/moveplayer/actors/wall.lua +++ /dev/null @@ -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 diff --git a/examples/scenes/gameplay/moveplayer/init.lua b/examples/scenes/gameplay/moveplayer/init.lua index 9691a7f..30d6a42 100644 --- a/examples/scenes/gameplay/moveplayer/init.lua +++ b/examples/scenes/gameplay/moveplayer/init.lua @@ -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"} + } +} \ No newline at end of file