scenes/levels: some general cleanup
This commit is contained in:
parent
443aeb82ea
commit
e4c0d11a1c
|
@ -5,7 +5,6 @@ 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)
|
||||
self.life = 0;
|
||||
--world:add(self, self.x, self.y, self.w, self.h)
|
||||
self:setMotionDirection(dir, speed)
|
||||
end
|
||||
|
||||
|
@ -22,8 +21,8 @@ end
|
|||
function Bullet:update(dt)
|
||||
self:setFilter()
|
||||
|
||||
--self.x, self.y, cols, cols_len = currentLevel.world:move(self, self.x + self.xsp*dt, self.y + self.ysp*dt, bulletFilter)
|
||||
cols, cols_len = self:move(dt)
|
||||
local cols, cols_len
|
||||
self.x, self.y, cols, cols_len = self:move(dt)
|
||||
|
||||
for j=1,cols_len do
|
||||
local other = cols[j].other
|
||||
|
|
|
@ -7,7 +7,6 @@ function Debris:new(level, x, y, speed, dir, timelimit)
|
|||
self.life = 0;
|
||||
self.timer = 0
|
||||
self.timelimit = timelimit or 2
|
||||
--world:add(self, self.x, self.y, self.w, self.h)
|
||||
self:setMotionDirection(dir, speed)
|
||||
self.grav = 1
|
||||
self.bounce = 0.5
|
||||
|
|
|
@ -7,13 +7,12 @@ function GFX:new(level, x, y, spritename, animID)
|
|||
local width, height
|
||||
self.name = spritename
|
||||
self.animID = animID
|
||||
width = 16--assets.sprites[spritename].width
|
||||
height = 16--assets.sprites[spritename].height
|
||||
width = 16
|
||||
height = 16
|
||||
GFX.super.new(self, level, "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
|
||||
--world:add(self, self.x, self.y, self.w, self.h)
|
||||
end
|
||||
|
||||
function GFX:update(dt)
|
||||
|
|
|
@ -44,7 +44,7 @@ function Entity:update(dt)
|
|||
|
||||
end
|
||||
|
||||
function Entity:register() -- On enregistre la hitbox dans le monde, pour l'instant les deux parties du programmes sont séparé (génération et enregistrement, peut-être qu'elles seront fusionnées)
|
||||
function Entity:register()
|
||||
self.world:addEntity(self, self.x, self.y, self.w, self.h)
|
||||
end
|
||||
|
||||
|
@ -61,7 +61,8 @@ function Entity:setMotion(xsp, ysp)
|
|||
end
|
||||
|
||||
function Entity:setMotionDirection(dir,spd)
|
||||
local dir = math.rad(dir) -- On commence par convertir la vitesse en radians
|
||||
-- On commence par convertir l'angle en radians
|
||||
local dir = math.rad(dir)
|
||||
|
||||
local xsp, ysp, cos, sin
|
||||
cos = math.cos(dir)
|
||||
|
@ -122,6 +123,7 @@ end
|
|||
function Entity:move(dt)
|
||||
self.onGround = false
|
||||
local xsp, ysp = self.xsp * dt, self.ysp * dt
|
||||
local cols, cols_len
|
||||
self.x, self.y, cols, cols_len = self.world:moveEntity(self, self.x + xsp, self.y + ysp, self.filter)
|
||||
|
||||
for i=1, cols_len do
|
||||
|
|
|
@ -2,7 +2,8 @@ local Entity = require "scenes.levels.entities.parent"
|
|||
|
||||
local Player = Entity:extend()
|
||||
|
||||
-- Initialisation functions
|
||||
-- INIT functions
|
||||
-- Initialize the player
|
||||
|
||||
function Player:new(level, x, y, playerID)
|
||||
|
||||
|
@ -60,8 +61,8 @@ function Player:initWeapon()
|
|||
self:setWeapon()
|
||||
end
|
||||
|
||||
|
||||
-- UPDATE and COLLISION functions
|
||||
-- Physics and function called every game update
|
||||
|
||||
function Player:update(dt)
|
||||
self.keys = self.level.keys
|
||||
|
@ -122,6 +123,7 @@ function Player:limitMovement()
|
|||
end
|
||||
|
||||
-- GAMEPLAY functions
|
||||
-- Where the player act and move
|
||||
|
||||
function Player:shoot()
|
||||
if self.keys["B"].isPressed then
|
||||
|
@ -173,7 +175,6 @@ function Player:actionMove(dt)
|
|||
self.ysp = self.jmp
|
||||
self.isJumping = true
|
||||
self.level.assets:playSFX("jump")
|
||||
--assets.sprites["cochon"]:resetAnimation(self.animations["jump"])
|
||||
end
|
||||
|
||||
if (self.isJumping == true) and (self.ysp < (-4 * 60)) and (not (self.keys["A"].isDown)) then
|
||||
|
@ -236,9 +237,8 @@ function Player:draw(dt)
|
|||
self.level.assets.sprites[self.stats.race]:drawAnimation(drawx, drawy, 0, self.direction, 1, 16, 36)
|
||||
end
|
||||
|
||||
-- Death and hit functions
|
||||
|
||||
|
||||
-- DEATH and HIT functions
|
||||
-- All function related to damage management
|
||||
|
||||
function Player:takeHit(damage)
|
||||
if (self.hp <= damage) then
|
||||
|
@ -249,12 +249,6 @@ function Player:takeHit(damage)
|
|||
end
|
||||
|
||||
function Player:die()
|
||||
--self.hp = self.stats.maxHP
|
||||
--self.x = self.startx-16
|
||||
--self.y = self.starty-12
|
||||
--self.xsp = 0
|
||||
--self.ysp = 0
|
||||
--currentLevel.world:update(self, self.x,self.y)
|
||||
self.manager:setDeathTimer(1)
|
||||
self:destroy()
|
||||
end
|
||||
|
|
|
@ -27,8 +27,7 @@ function Weapon:update(dt)
|
|||
|
||||
self.rotation = self.rotation + (dt * 90)*8
|
||||
|
||||
--self.x, self.y, cols, cols_len = currentLevel.world:move(self, self.x + self.xsp*dt, self.y + self.ysp*dt, bulletFilter)
|
||||
cols, cols_len = self:move(dt)
|
||||
local cols, cols_len = self:move(dt)
|
||||
|
||||
for j=1,cols_len do
|
||||
local other = cols[j].other
|
||||
|
|
Loading…
Reference in New Issue