scenes/levels: make collision type initialisation simpler

This commit is contained in:
Kazhnuz 2019-03-03 11:55:52 +01:00
parent c1de0e0971
commit 7f31230b5e
9 changed files with 12 additions and 20 deletions

View File

@ -3,9 +3,8 @@ local Entity = require "scenes.levels.entities.parent"
Block = Entity:extend()
function Block:new(level, item, x ,y)
Block.super.new(self, level, x, y, 16, 16)
Block.super.new(self, level, "block", x, y, 16, 16)
self.item = item or 0
self.collType = "block"
end
function Block:draw(dt)

View File

@ -3,10 +3,9 @@ local Entity = require "scenes.levels.entities.parent"
Bullet = Entity:extend()
function Bullet:new(level, x, y, w, h, speed, dir)
Bullet.super.new(self, level, x - (w / 2), y - (h / 2), w, h)
Bullet.super.new(self, level, "bullet", x - (w / 2), y - (h / 2), w, h)
self.life = 0;
--world:add(self, self.x, self.y, self.w, self.h)
self.collType="bullet"
self:setMotionDirection(dir, speed)
end

View File

@ -3,8 +3,7 @@ local Entity = require "scenes.levels.entities.parent"
Collision = Entity:extend()
function Collision:new(level, collType, x, y, w, h)
Collision.super.new(self, level, x, y, w, h)
self.collType = collType
Collision.super.new(self, level, collType, x, y, w, h)
self:setDebugColor(0,0,0)
end

View File

@ -3,12 +3,11 @@ local Entity = require "scenes.levels.entities.parent"
Debris = Entity:extend()
function Debris:new(level, x, y, speed, dir, timelimit)
Debris.super.new(self, level, x - 4, y - 4, 8, 8)
Debris.super.new(self, level, "debris", x - 4, y - 4, 8, 8)
self.life = 0;
self.timer = 0
self.timelimit = timelimit
--world:add(self, self.x, self.y, self.w, self.h)
self.collType = "debris"
self:setMotionDirection(dir, speed)
self.grav = 1
self.bounce = 0.5

View File

@ -9,8 +9,7 @@ function GFX:new(level, spritename, animID,x,y)
self.animation = assets.sprites[spritename]:cloneAnimation(animID)
width = 16--assets.sprites[spritename].width
height = 16--assets.sprites[spritename].height
GFX.super.new(self, level, x - (width/2), y - (height/2), width, height)
self.collType = "gfx"
GFX.super.new(self, level, "gfx", x - (width/2), y - (height/2), width, height)
self.duration = assets.sprites[spritename]:getAnimationDuration(animID)
self.timer = 0
--world:add(self, self.x, self.y, self.w, self.h)

View File

@ -5,7 +5,7 @@ Coin = Loot:extend()
WeaponLoot = Loot:extend()
function Loot:new(level, name, value, x, y)
Loot.super.new(self, level, x, y, 16, 16)
Loot.super.new(self, level, "loot", x, y, 16, 16)
self.value = value
self.collType = "loot"
self.name = name

View File

@ -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, x, y, w, h) -- On enregistre une nouvelle entité, avec par défaut sa hitbox.
self:initPhysics(level, x, y, w, h)
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)
self.destroyed = false
self.registered = false
self:setDebugColor(0,0,0)
end
function Entity:initPhysics(level, x, y, w, h)
function Entity:initPhysics(level, collType, x, y, w, h)
self.level = level
self.world = level.world
self.collType = ""
self.collType = collType
self.gacc = 500
self.xsp = 0

View File

@ -13,7 +13,7 @@ function Player:new(level, playerID, x, y)
self:initAnimations()
Player.super.new(self, level, x - (w / 2), y - (h / 2), w, h)
Player.super.new(self, level, "player", x - (w / 2), y - (h / 2), w, h)
self.center = {
x = self.x,
@ -31,8 +31,6 @@ function Player:new(level, playerID, x, y)
self:padInit()
self:setDebugColor(0,255,0)
self.collType = "player"
end
function Player:getStats(playerID)

View File

@ -3,9 +3,8 @@ local Entity = require "scenes.levels.entities.parent"
Weapon = Entity:extend()
function Weapon:new(level, id, x, y, xsp)
Weapon.super.new(self, level, x-8, y - 8, 16, 16)
Weapon.super.new(self, level, "weapon", x-8, y - 8, 16, 16)
self.weaponid = id
self.collType="weapon"
self.xsp = xsp
self.ysp = 0
self.rotation = 0