YAY
- Mask functionality - Rehandled Animations (now consistent)
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
}
|
||||
|
||||
-- constants
|
||||
o.acc = 45
|
||||
o.acc = 45
|
||||
o.friction = 20
|
||||
o.gravity = 9.81
|
||||
o.climbHeight = 4
|
||||
@@ -31,11 +31,12 @@
|
||||
o.canJump = true
|
||||
o.canFall = true
|
||||
o.canFriction = true
|
||||
|
||||
-- sprite
|
||||
o.mask_type = animation.moth_mask
|
||||
-- sprite
|
||||
o.sprite_offset = {x = 8, y = 16}
|
||||
o.target_offset = {x = 0, y = 12}
|
||||
|
||||
o.target_offset = {x = 0, y = 12}
|
||||
o.body = Animation:New(animation.nancy.idle)
|
||||
o.mask = Animation:New(animation.moth_mask.idle)
|
||||
-- lights
|
||||
|
||||
|
||||
@@ -85,27 +86,53 @@ function Player:Smart()
|
||||
end
|
||||
|
||||
function Player:HandleAnimation()
|
||||
|
||||
-- flip sprite to look in the direction is moving
|
||||
if self.vel.x ~= 0 then self.sprite_flip.x = math.sign(self.vel.x) end
|
||||
|
||||
-- animation manager
|
||||
if self.isOnLadder then
|
||||
self:LoadAnimation(animation.nancy.jump)
|
||||
self.body = self.body:ChangeTo(animation.nancy.jump)
|
||||
self.mask = self.mask:ChangeTo(self.mask_type.jump)
|
||||
elseif self.isOnGround == 0 and self.isJumping and self.vel.y > 1.25 then
|
||||
self:LoadAnimation(animation.nancy.fall)
|
||||
self.body = self.body:ChangeTo(animation.nancy.fall)
|
||||
self.mask = self.mask:ChangeTo(self.mask_type.fall)
|
||||
elseif self.isOnGround == 0 and self.vel.y < 0 then
|
||||
self:LoadAnimation(animation.nancy.jump)
|
||||
self.body = self.body:ChangeTo(animation.nancy.jump)
|
||||
self.mask = self.mask:ChangeTo(self.mask_type.jump)
|
||||
elseif self.vel.x ~= 0 then
|
||||
self:LoadAnimation(animation.nancy.run)
|
||||
self.body = self.body:ChangeTo(animation.nancy.run)
|
||||
self.mask = self.mask:ChangeTo(self.mask_type.run)
|
||||
else
|
||||
self:LoadAnimation(animation.nancy.idle)
|
||||
self.body = self.body:ChangeTo(animation.nancy.idle)
|
||||
self.mask = self.mask:ChangeTo(self.mask_type.idle)
|
||||
end
|
||||
|
||||
-- special case: idle animation gets slower by time
|
||||
if self.anim_path == animation.nancy.idle.path then
|
||||
if self.anim_speed < 0.5 then self.anim_speed = self.anim_speed + 0.001 end
|
||||
if self.body.anim_path == animation.nancy.idle.path then
|
||||
if self.body.anim_speed < 0.5 then self.body.anim_speed = self.body.anim_speed + 0.001 end
|
||||
end
|
||||
|
||||
self.body:Animate()
|
||||
self.body:Draw(
|
||||
self.pos.x - Camera.pos.x - ( (self.sprite_offset.x) * math.cos(self.sprite_rotation) - (self.sprite_offset.y) * math.sin(self.sprite_rotation)) * self.sprite_scale.x * self.sprite_flip.x,
|
||||
self.pos.y - Camera.pos.y - ( (self.sprite_offset.x) * math.sin(self.sprite_rotation) + (self.sprite_offset.y) * math.cos(self.sprite_rotation)) * self.sprite_scale.y * self.sprite_flip.y,
|
||||
self.sprite_rotation,
|
||||
self.sprite_scale.x * self.sprite_flip.x,
|
||||
self.sprite_scale.y * self.sprite_flip.y
|
||||
)
|
||||
self.mask:Draw(
|
||||
self.pos.x - Camera.pos.x - ( (self.sprite_offset.x) * math.cos(self.sprite_rotation) - (self.sprite_offset.y) * math.sin(self.sprite_rotation)) * self.sprite_scale.x * self.sprite_flip.x,
|
||||
self.pos.y - Camera.pos.y - ( (self.sprite_offset.x) * math.sin(self.sprite_rotation) + (self.sprite_offset.y) * math.cos(self.sprite_rotation)) * self.sprite_scale.y * self.sprite_flip.y,
|
||||
self.sprite_rotation,
|
||||
self.sprite_scale.x * self.sprite_flip.x,
|
||||
self.sprite_scale.y * self.sprite_flip.y
|
||||
)
|
||||
|
||||
--[[
|
||||
love.graphics.print(self.body.frame .. "/".. self.body.frames.." - "..self.body.subframe.."/"..self.body.speed.." ("..current_dt..")")
|
||||
love.graphics.print(animation.nancy.idle.path,0,20)
|
||||
love.graphics.print(self.body.path,0,30)
|
||||
]]
|
||||
end
|
||||
|
||||
function Player:DoPhysics()
|
||||
|
||||
Reference in New Issue
Block a user