improvements to particles and animation can now have variable speed
This commit is contained in:
parent
e8242f6564
commit
d3796a0204
@ -1,6 +1,6 @@
|
||||
Animation = {}
|
||||
|
||||
function Animation:new(anim_data)
|
||||
function Animation:new(anim_data,speed)
|
||||
local o = {}
|
||||
|
||||
o.path = anim_data.path
|
||||
@ -8,6 +8,7 @@ function Animation:new(anim_data)
|
||||
o.imgs = anim_data.imgs
|
||||
o.subframe = 0
|
||||
o.frame = 1
|
||||
o.speed = speed or 1
|
||||
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
@ -46,11 +47,11 @@ end
|
||||
function Animation:animate()
|
||||
if self.frames[self.frame] ~= 0 then
|
||||
-- try to animate
|
||||
self.subframe = self.subframe + current_dt
|
||||
self.subframe = self.subframe + 1
|
||||
|
||||
if self.subframe > self.frames[self.frame] then
|
||||
self.subframe = self.subframe - self.frames[self.frame]
|
||||
self.frame = self.frame + 1
|
||||
if self.subframe > self.frames[self.frame]*game.framerate then
|
||||
self.subframe = self.subframe - self.frames[self.frame]*game.framerate
|
||||
self.frame = self.frame + self.speed
|
||||
end
|
||||
|
||||
-- cycle
|
||||
|
@ -78,10 +78,13 @@ function Fairy:doLogic()
|
||||
|
||||
local particle_data = {
|
||||
animation = animation.particle.simple,
|
||||
animation_speed = 1,
|
||||
sprite_tint = hex2rgb("#fed100"),
|
||||
sprite_alpha_fade = true,
|
||||
direction = angle-math.rad(180+math.random(60)-30),
|
||||
speed = 0.8*(distance/50),
|
||||
speed_increase = -0.01,
|
||||
time = 0.75
|
||||
}
|
||||
Particle:new(self.pos.x,self.pos.y,particle_data)
|
||||
end
|
||||
|
@ -15,12 +15,13 @@ function Particle:new(x,y,particle_data)
|
||||
o.sprite_scale = particle_data.sprite_scale or o.sprite_scale
|
||||
o.sprite_tint = particle_data.sprite_tint or o.sprite_tint
|
||||
o.sprite_alpha = particle_data.sprite_alpha or o.sprite_alpha
|
||||
o.sprite_alpha_fade = particle_data.sprite_alpha_fade or false
|
||||
o.sprite_alpha_base = o.sprite_alpha
|
||||
|
||||
o.sprite_flip = particle_data.sprite_flip or o.sprite_flip
|
||||
o.animation_active = particle_data.animation_active or false
|
||||
|
||||
o.time = 0.5
|
||||
o.time = particle_data.time or nil
|
||||
if o.time ~= nil then o.time = o.time * game.framerate end
|
||||
|
||||
o.timer = 0
|
||||
|
||||
o.vel = {
|
||||
@ -39,14 +40,12 @@ function Particle:new(x,y,particle_data)
|
||||
|
||||
-- animations
|
||||
if particle_data.animation ~= nil then
|
||||
o.body = Animation:new(particle_data.animation)
|
||||
o.body = Animation:new(particle_data.animation,particle_data.animation_speed)
|
||||
o:centerOffset(o.body)
|
||||
o:createBox(o.body)
|
||||
if not o.animation_active then
|
||||
o.body.speed = 0
|
||||
end
|
||||
end
|
||||
|
||||
-- particle id handled differently from other entities
|
||||
table.insert(LoadedObjects.Particles,o)
|
||||
o.id = #LoadedObjects.Particles
|
||||
|
||||
@ -71,13 +70,12 @@ function Particle:kill()
|
||||
end
|
||||
|
||||
function Particle:handleAnimation()
|
||||
self.timer = self.timer + current_dt
|
||||
self.sprite_alpha = self.sprite_alpha_base*(self.time-self.timer)/self.time
|
||||
if self.light ~= nil then
|
||||
self:adjustLight()
|
||||
self.light.range = self.light_range * self.sprite_alpha/2
|
||||
self.timer = self.timer + 1
|
||||
|
||||
if self.sprite_alpha_fade ~= false then
|
||||
self.sprite_alpha = self.sprite_alpha_base*(self.time-self.timer)/self.time
|
||||
end
|
||||
if self.sprite_alpha < 0 then self:kill() end
|
||||
|
||||
if self.body ~= nil then
|
||||
self.body:animate()
|
||||
self:draw(self.body)
|
||||
@ -93,6 +91,15 @@ function Particle:doPhysics()
|
||||
end
|
||||
-- move
|
||||
self:moveWithCollision()
|
||||
|
||||
if self.light ~= nil then
|
||||
self:adjustLight()
|
||||
self.light.range = self.light_range * self.sprite_alpha/2
|
||||
end
|
||||
|
||||
if self.time ~= nil then
|
||||
if self.timer >= self.time then self:kill() end
|
||||
end
|
||||
end
|
||||
|
||||
function Particle:debug()
|
||||
|
@ -212,8 +212,10 @@ function Player:doPhysics()
|
||||
-- dash particle
|
||||
local particle_data = {
|
||||
animation = self.body,
|
||||
animation_speed = 0,
|
||||
sprite_tint = hex2rgb("#fed100"),
|
||||
sprite_alpha = 0.5,
|
||||
time = 0.2,
|
||||
sprite_flip = {
|
||||
x = self.sprite_flip.x,
|
||||
y = self.sprite_flip.y
|
||||
@ -245,8 +247,10 @@ function Player:doPhysics()
|
||||
|
||||
local particle_data = {
|
||||
animation = self.body,
|
||||
animation_speed = 0,
|
||||
sprite_tint = hex2rgb("#fed100"),
|
||||
sprite_alpha = 0.5,
|
||||
time = 0.05,
|
||||
sprite_flip = {
|
||||
x = self.sprite_flip.x,
|
||||
y = self.sprite_flip.y
|
||||
|
@ -34,8 +34,12 @@ function stepGame()
|
||||
|
||||
if Keybind:checkPressed(Keybind.debug.reposition) then
|
||||
if not editor_mode then
|
||||
main_player.pos.x, main_player.pos.y = 16,-10
|
||||
main_player.pos.x, main_player.pos.y = 75,50
|
||||
end
|
||||
for _, entity in pairs(LoadedObjects.Entities) do
|
||||
if entity.id ~= main_player.id then entity:kill() end
|
||||
end
|
||||
activateSpawns()
|
||||
end
|
||||
|
||||
if Keybind:checkPressed(Keybind.debug.reload) then
|
||||
|
Loading…
Reference in New Issue
Block a user