feat:initial addition of collectible actors

This commit is contained in:
Kazhnuz 2020-01-26 12:28:53 +01:00
parent b4fcd33163
commit 46c1a53f5e
7 changed files with 56 additions and 0 deletions

View file

@ -3,6 +3,7 @@ local Obj = {}
-- On charge toutes les différentes types d'acteurs
local cwd = (...):gsub('%.init$', '') .. "."
Obj.Player = require(cwd .. "player")
Obj.Ring = require(cwd .. "items.ring")
Obj.index = {}
Obj.index["player"] = Obj.Player
@ -13,4 +14,8 @@ Obj.collisions["invisible"] = require(cwd .. "collisions.invisible")
Obj.collisions["floor"] = require(cwd .. "collisions.floor")
Obj.collisions["textured"] = require(cwd .. "collisions.textured")
Obj.index = {}
Obj.index[01] = Obj.Ring
Obj.index[02] = Obj.Ring
return Obj

View file

@ -0,0 +1,12 @@
local Parent = require "game.modules.world.actors.parent"
local Collectible = Parent:extend()
function Collectible:new(world, x, y, z, w, h, d)
Collectible.super.new(self, world, "collectible", x, y, z, w, h, d, false)
end
function Collectible:getPicked(player)
self:destroy()
end
return Collectible

View file

@ -0,0 +1,17 @@
local cwd = (...):gsub('%.ring$', '') .. "."
local Collectible = require(cwd .. "collectible")
local Ring = Collectible:extend()
function Ring:new(world, x, y, z)
Ring.super.new(self, world, x, y, z+6, 16, 10, 16)
self:setSprite("ring", 0, 0)
end
function Ring:getPicked(player)
--player.rings = player.rings + 1
--player:addScore(10)
self:destroy()
end
return Ring

View file

@ -50,6 +50,12 @@ function Player:updateStart(dt)
end
end
function Player:collisionResponse(collision)
if collision.other.type == "collectible" then
collision.other.owner:getPicked(self)
end
end
function Player:animationEnded(name)
end

View file

@ -52,6 +52,7 @@ function ShootMap:loadCollisions()
--self.world:newCollision("floor", 0, 0, -16, w, h, 16)
for i, chunk in ipairs(self.layout) do
chunk:spawnGrounds((i-1)*31*8)
chunk:spawnObjects((i-1)*31*8)
end
end

View file

@ -29,6 +29,17 @@ function Chunk:spawnGrounds(x)
end
end
function Chunk:spawnObjects(x)
for i=1, 5 do
for j=1, 8 do
local id = self.data.objects[i][j]
if (id ~= 0) then
self.map.world:newObjFromIndex(id, x+(j-1)*31+12, (i-1)*20, 0)
end
end
end
end
function Chunk:draw(x)
for i=1, 5 do
for j=1, 8 do

View file

@ -21,6 +21,10 @@ function ParentWorld:loadMapObjects()
self:addInvisibleWalls()
end
function ParentWorld:newObjFromIndex(id, x, y, z)
self.obj.index[id](self, x, y, z)
end
function ParentWorld:addInvisibleWalls()
local w, h = self:getDimensions()
print(w, h)