From a52abd0b971a184b24d9ce2f3053fd143f8472ec Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Mon, 29 Apr 2019 16:13:09 +0200 Subject: [PATCH] examples/plateformer: add basic actors --- examples/gameplay/plateform/actors/init.lua | 4 +++ examples/gameplay/plateform/actors/player.lua | 28 +++++++++++++++++++ examples/gameplay/plateform/actors/wall.lua | 8 ++++++ 3 files changed, 40 insertions(+) create mode 100644 examples/gameplay/plateform/actors/player.lua create mode 100644 examples/gameplay/plateform/actors/wall.lua diff --git a/examples/gameplay/plateform/actors/init.lua b/examples/gameplay/plateform/actors/init.lua index c378039..8a009b1 100644 --- a/examples/gameplay/plateform/actors/init.lua +++ b/examples/gameplay/plateform/actors/init.lua @@ -3,8 +3,12 @@ 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"] = require(cwd .. "player") Obj.collisions = {} +Obj.collisions["wall"] = require(cwd .. "wall") return Obj diff --git a/examples/gameplay/plateform/actors/player.lua b/examples/gameplay/plateform/actors/player.lua new file mode 100644 index 0000000..be46fb3 --- /dev/null +++ b/examples/gameplay/plateform/actors/player.lua @@ -0,0 +1,28 @@ +local Base = require "gamecore.modules.world.actors.actor2D" +local Player = Base:extend() + +function Player:new(world, x, y, id) + Player.super.new(self, world, "player", x, y, 16, 24, true) + self.playerid = id +end + +function Player:update(dt) + self.xfrc = 480*3 + + if self.keys["up"].isDown then + --self.ysp = -120 + end + if self.keys["down"].isDown then + --self.ysp = 120 + end + if self.keys["left"].isDown then + self.xsp = -120 + end + if self.keys["right"].isDown then + self.xsp = 120 + end + + Player.super.update(self, dt) +end + +return Player diff --git a/examples/gameplay/plateform/actors/wall.lua b/examples/gameplay/plateform/actors/wall.lua new file mode 100644 index 0000000..12c109d --- /dev/null +++ b/examples/gameplay/plateform/actors/wall.lua @@ -0,0 +1,8 @@ +local Base = require "gamecore.modules.world.actors.actor2D" +local Wall = Base:extend() + +function Wall:new(world, x, y, w, h) + Parent.super.new(self, world, "wall", x, y, w, h, true) +end + +return Wall