scenes/level: declare the actors in the world instead of in the scene
This commit is contained in:
parent
5ff324f5b0
commit
cb831e117f
|
@ -2,8 +2,8 @@ local Entity = require "scenes.levels.entities.parent"
|
|||
|
||||
local Block = Entity:extend()
|
||||
|
||||
function Block:new(level, x , y, item)
|
||||
Block.super.new(self, level, "block", x, y, 16, 16)
|
||||
function Block:new(world, x , y, item)
|
||||
Block.super.new(self, world, "block", x, y, 16, 16)
|
||||
self.item = item or 0
|
||||
end
|
||||
|
||||
|
@ -15,11 +15,11 @@ function Block:breakBlock()
|
|||
local x, y = self:getCenter()
|
||||
local spd = 250
|
||||
local dist = 0
|
||||
self.obj.Debris(self.level, x+dist, y-dist, spd, 270+45)
|
||||
self.obj.Debris(self.level, x+dist, y+dist, spd, 45)
|
||||
self.obj.Debris(self.level, x-dist, y+dist, spd, 180+45)
|
||||
self.obj.Debris(self.level, x-dist, y-dist, spd, 180-45)
|
||||
self.obj.GFX(self.level, self.x+8, self.y+8, "poof", 1)
|
||||
self.obj.Debris(self.world, x+dist, y-dist, spd, 270+45)
|
||||
self.obj.Debris(self.world, x+dist, y+dist, spd, 45)
|
||||
self.obj.Debris(self.world, x-dist, y+dist, spd, 180+45)
|
||||
self.obj.Debris(self.world, x-dist, y-dist, spd, 180-45)
|
||||
self.obj.GFX(self.world, self.x+8, self.y+8, "poof", 1)
|
||||
self.level.assets:playSFX("break")
|
||||
self.level.playermanager.score = self.level.playermanager.score + 10
|
||||
self:destroy()
|
||||
|
|
|
@ -2,8 +2,8 @@ local Entity = require "scenes.levels.entities.parent"
|
|||
|
||||
local Bullet = Entity:extend()
|
||||
|
||||
function Bullet:new(level, x, y, w, h, speed, dir)
|
||||
Bullet.super.new(self, level, "bullet", x - (w / 2), y - (h / 2), w, h)
|
||||
function Bullet:new(world, x, y, w, h, speed, dir)
|
||||
Bullet.super.new(self, world, "bullet", x - (w / 2), y - (h / 2), w, h)
|
||||
self.life = 0;
|
||||
self:setMotionDirection(dir, speed)
|
||||
end
|
||||
|
|
|
@ -2,8 +2,8 @@ local Entity = require "scenes.levels.entities.parent"
|
|||
|
||||
local Collision = Entity:extend()
|
||||
|
||||
function Collision:new(level, x, y, w, h, collType)
|
||||
Collision.super.new(self, level, collType, x, y, w, h)
|
||||
function Collision:new(world, x, y, w, h, collType)
|
||||
Collision.super.new(self, world, collType, x, y, w, h)
|
||||
|
||||
self:setDebugColor(0,0,0)
|
||||
end
|
||||
|
|
|
@ -2,8 +2,8 @@ local Entity = require "scenes.levels.entities.parent"
|
|||
|
||||
local Debris = Entity:extend()
|
||||
|
||||
function Debris:new(level, x, y, speed, dir, timelimit)
|
||||
Debris.super.new(self, level, "debris", x - 4, y - 4, 8, 8)
|
||||
function Debris:new(world, x, y, speed, dir, timelimit)
|
||||
Debris.super.new(self, world, "debris", x - 4, y - 4, 8, 8)
|
||||
self.life = 0;
|
||||
self.timer = 0
|
||||
self.timelimit = timelimit or 2
|
||||
|
|
|
@ -2,10 +2,10 @@ local Entity = require "scenes.levels.entities.parent"
|
|||
|
||||
local Ennemy = Entity:extend()
|
||||
|
||||
function Ennemy:new(level, x, y, w, h, hp, power, armor)
|
||||
function Ennemy:new(world, x, y, w, h, hp, power, armor)
|
||||
local w = w or 16
|
||||
local h = h or 16
|
||||
Ennemy.super.new(self, level, "ennemy", x, y, w, h)
|
||||
Ennemy.super.new(self, world, "ennemy", x, y, w, h)
|
||||
self.power = power or 1
|
||||
self.armor = armor or 0
|
||||
self.maxhp = hp or 3
|
||||
|
@ -30,10 +30,10 @@ end
|
|||
function Ennemy:getDamage(base_damage)
|
||||
local damage = math.max(base_damage - self.armor, 1)
|
||||
self.hp = math.max(0, self.hp - damage)
|
||||
self.obj.Numbers(self.level, self.x+8, self.y+8, damage, {1,0,0})
|
||||
self.obj.Numbers(self.world, self.x+8, self.y+8, damage, {1,0,0})
|
||||
if (self.hp == 0) then
|
||||
self:destroy()
|
||||
self.obj.GFX(self.level, self.x+8, self.y+8, "poof", 1)
|
||||
self.obj.GFX(self.world, self.x+8, self.y+8, "poof", 1)
|
||||
self.level.playermanager.score = self.level.playermanager.score + 100
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,13 +3,13 @@ local Animator = require "core.modules.assets.animator"
|
|||
|
||||
local GFX = Entity:extend()
|
||||
|
||||
function GFX:new(level, x, y, spritename, animID)
|
||||
function GFX:new(world, x, y, spritename, animID)
|
||||
local width, height
|
||||
self.name = spritename
|
||||
self.animID = animID
|
||||
width = 16
|
||||
height = 16
|
||||
GFX.super.new(self, level, "gfx", x - (width/2), y - (height/2), width, height)
|
||||
GFX.super.new(self, world, "gfx", x - (width/2), y - (height/2), width, height)
|
||||
self.animation = self.level.assets.sprites[spritename]:clone()
|
||||
self.duration = self.animation:getAnimationDuration()
|
||||
self.timer = 0
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
local Entity = require "scenes.levels.entities.parent"
|
||||
local NumberGFX = Entity:extend()
|
||||
|
||||
function NumberGFX:new(level, x, y, number, color)
|
||||
NumberGFX.super.new(self, level, "number", x - 8, y - 24, 16, 16)
|
||||
function NumberGFX:new(world, x, y, number, color)
|
||||
NumberGFX.super.new(self, world, "number", x - 8, y - 24, 16, 16)
|
||||
self.number = number or 0
|
||||
self.color = color or {1, 1, 1}
|
||||
self.life = 1.5
|
||||
|
|
|
@ -9,7 +9,7 @@ function Coin:new(level, x, y, anim, value)
|
|||
end
|
||||
|
||||
function Coin:takeLoot()
|
||||
self.obj.GFX(self.level, self.x+8, self.y+8, "sparkle", 1)
|
||||
self.obj.GFX(self.world, self.x+8, self.y+8, "sparkle", 1)
|
||||
self:destroy()
|
||||
self.level.playermanager.gold = self.level.playermanager.gold + self.value
|
||||
self.level.playermanager.score = self.level.playermanager.score + 10
|
||||
|
|
|
@ -2,8 +2,8 @@ local Coin = require "scenes.levels.entities.loot.coin"
|
|||
|
||||
local Coin5 = Coin:extend()
|
||||
|
||||
function Coin5:new(level, x, y)
|
||||
Coin5.super.new(self, level, x, y, "coin10", 10)
|
||||
function Coin5:new(world, x, y)
|
||||
Coin5.super.new(self, world, x, y, "coin10", 10)
|
||||
end
|
||||
|
||||
return Coin5
|
||||
|
|
|
@ -2,8 +2,8 @@ local Coin = require "scenes.levels.entities.loot.coin"
|
|||
|
||||
local Coin5 = Coin:extend()
|
||||
|
||||
function Coin5:new(level, x, y)
|
||||
Coin5.super.new(self, level, x, y, "coin5", 5)
|
||||
function Coin5:new(world, x, y)
|
||||
Coin5.super.new(self, world, x, y, "coin5", 5)
|
||||
end
|
||||
|
||||
return Coin5
|
||||
|
|
|
@ -9,7 +9,7 @@ function Loot:new(level, x, y, name)
|
|||
end
|
||||
|
||||
function Loot:takeLoot()
|
||||
self.obj.GFX(self.level, self.x+8, self.y+8, "sparkle", 1)
|
||||
self.obj.GFX(self.world, self.x+8, self.y+8, "sparkle", 1)
|
||||
self:destroy()
|
||||
self.level.playermanager.gold = self.level.playermanager.gold + 1
|
||||
self.level.playermanager.score = self.level.playermanager.score + 10
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
local Entity = Object:extend() -- On créer la classe des entitées, c'est la classe de base
|
||||
|
||||
function Entity:new(level, collType, x, y, w, h) -- On enregistre une nouvelle entité, avec par défaut sa hitbox.
|
||||
self:initPhysics(level, collType, x, y, w, h)
|
||||
function Entity:new(world, collType, x, y, w, h) -- On enregistre une nouvelle entité, avec par défaut sa hitbox.
|
||||
self:initPhysics(world, collType, x, y, w, h)
|
||||
self.destroyed = false
|
||||
self.registered = false
|
||||
self:setDebugColor(0,0,0)
|
||||
end
|
||||
|
||||
function Entity:initPhysics(level, collType, x, y, w, h)
|
||||
self.level = level
|
||||
self.world = level.world
|
||||
self.camera = level.camera
|
||||
function Entity:initPhysics(world, collType, x, y, w, h)
|
||||
self.level = world.scene
|
||||
self.world = world
|
||||
self.camera = self.level.camera
|
||||
self.obj = self.world.obj
|
||||
self.collType = collType
|
||||
|
||||
|
|
|
@ -5,15 +5,15 @@ local Player = Entity:extend()
|
|||
-- INIT functions
|
||||
-- Initialize the player
|
||||
|
||||
function Player:new(level, x, y, playerID)
|
||||
function Player:new(world, x, y, playerID)
|
||||
|
||||
local w, h = 32, 24
|
||||
self.direction = 1
|
||||
|
||||
self.startx, self.starty = x, y
|
||||
|
||||
Player.super.new(self, level, "player", x - (w / 2), y - (h / 2), w, h)
|
||||
self.manager = level.playermanager
|
||||
Player.super.new(self, world, "player", x - (w / 2), y - (h / 2), w, h)
|
||||
self.manager = self.level.playermanager
|
||||
|
||||
self.center = {
|
||||
x = self.x,
|
||||
|
@ -185,7 +185,7 @@ function Player:actionMove(dt)
|
|||
end
|
||||
|
||||
function Player:launchWeapon()
|
||||
self.obj.Weapon(self.level, self.center.x, self.center.y, self.weapon, 350 * utils.math.sign(self.direction))
|
||||
self.obj.Weapon(self.world, self.center.x, self.center.y, self.weapon, 350 * utils.math.sign(self.direction))
|
||||
end
|
||||
|
||||
function Player:changeWeapon(id)
|
||||
|
|
|
@ -2,8 +2,8 @@ local Entity = require "scenes.levels.entities.parent"
|
|||
|
||||
local Weapon = Entity:extend()
|
||||
|
||||
function Weapon:new(level, x, y, id, xsp, ysp)
|
||||
Weapon.super.new(self, level, "weapon", x-8, y - 8, 16, 16)
|
||||
function Weapon:new(world, x, y, id, xsp, ysp)
|
||||
Weapon.super.new(self, world, "weapon", x-8, y - 8, 16, 16)
|
||||
self.weaponid = id or 0
|
||||
self.xsp = xsp or 0
|
||||
self.ysp = ysp or 0
|
||||
|
|
|
@ -38,7 +38,7 @@ end
|
|||
|
||||
function PlayerManager:spawnPlayer(playerID)
|
||||
local play = self.players[playerID]
|
||||
Obj.Player(self.scene, self.startx, self.starty, playerID)
|
||||
Obj.Player(self.scene.world, self.startx, self.starty, playerID)
|
||||
self.activePlayer = playerID
|
||||
end
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ function World:addEntityByNameOnGrid(name, x, y, w, h)
|
|||
end
|
||||
|
||||
function World:addEntityByName(name, x, y)
|
||||
self.obj.index[name](self.scene, x, y)
|
||||
self.obj.index[name](self, x, y)
|
||||
end
|
||||
|
||||
function World:loadCollisions()
|
||||
|
@ -89,7 +89,7 @@ function World:addCollision(x, y, w, h, name)
|
|||
if w == 0 then
|
||||
w = 1
|
||||
end
|
||||
self.obj.Collision(self.scene, x, y, w, h, name)
|
||||
self.obj.Collision(self, x, y, w, h, name)
|
||||
end
|
||||
|
||||
-- ENTITY MANAGEMENT COMPABILITY FUNCTIONS
|
||||
|
|
Loading…
Reference in New Issue