restructured folder

This commit is contained in:
lustlion
2022-02-12 11:36:43 +01:00
parent e51905de67
commit 8ddf3610ac
33 changed files with 49 additions and 44 deletions

78
code/entities/arrow.lua Normal file
View File

@@ -0,0 +1,78 @@
Arrow = Entity:New(x,y)
function Arrow:New(x,y,rotation,speed)
local o = Entity:New(x,y)
o.type = "arrow"
o.pos = {x = x, y = y}
o.speed = speed or 0
o.sprite_rotation = rotation or 0
o.vel = {
x = o.speed * math.cos(o.sprite_rotation),
y = o.speed * math.sin(o.sprite_rotation)
}
o.sprite_offset = {x = 13, y = 1}
o.stuck = false
o.illuminated = true
-- animations
o.body = Animation:New(animation.kupo.arrow)
table.insert(LoadedObjects.Entities,o)
o.id = #LoadedObjects.Entities
setmetatable(o, self)
self.__index = self
return o
end
function Arrow:HandleAnimation()
self:Draw(self.body)
end
function Arrow:DoPhysics()
if not self.stuck then
-- horizontal collisions
if not isThereAnyCollisionAt(
self.pos.x + self.vel.x,
self.pos.y
) then
self.pos.x = self.pos.x + self.vel.x
else
while not isThereObjectAt(
self.pos.x + math.sign(self.vel.x),
self.pos.y,
LoadedObjects.Collisions
) do
self.pos.x = self.pos.x + math.sign(self.vel.x)
end
self.stuck = true
end
-- vertical collision
if not isThereAnyCollisionAt(
self.pos.x,
self.pos.y + self.vel.y
) then
self.pos.y = self.pos.y + self.vel.y
else
while not isThereObjectAt(
self.pos.x,
self.pos.y + math.sign(self.vel.y),
LoadedObjects.Collisions
) do
self.pos.y = self.pos.y + math.sign(self.vel.y)
end
self.stuck = true
end
-- stuck into collisions
if self.stuck then
--lets allow the arrow to tip a bit into the thing
self.pos.x = self.pos.x + self.vel.x / 5
self.pos.y = self.pos.y + self.vel.y / 5
self.vel.x = 0
self.vel.y = 0
self.illuminated = false
end
end
end

View File

@@ -0,0 +1,119 @@
CursedBook = Entity:New(x,y)
function CursedBook:New(x,y)
local o = Entity:New(x,y)
o.type = "cursed_book"
-- behaviour
o.pos = {x = x, y = y}
o.speed = 0.01
o.range = 20
o.target = {x = x, y = y}
o.status = 0
-- 0 - sleep
-- 1 - getting up
-- 2 - flying
-- 3 - attack windup
-- 4 - attack
o.spawn_range = 100
o.attack_range = 50
-- animations
o.body = Animation:New(animation.cursed_book.spawn)
o.sprite_tint = {0.7,0.7,0.7}
o:centerOffset(o.body)
o:getBoundingBox(o.body)
-- light
o.light_range = 500
o.light = CreateLight(o.pos.x,o.pos.y,o.light_range,2,HEX2RGB("#fe00d1"))
table.insert(LoadedObjects.Entities,o)
o.id = #LoadedObjects.Entities
setmetatable(o, self)
self.__index = self
return o
end
function CursedBook:Smart()
self.target.x = main_Player.pos.x - main_Player.target_offset.x
self.target.y = main_Player.pos.y - main_Player.target_offset.y
local distance_x = self.target.x - self.pos.x
local distance_y = self.target.y - self.pos.y
local angle = GetAngleFromVector(distance_x,distance_y)
local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
if self.status == 0 then
if distance < self.spawn_range then
self.status = 1
end
elseif self.status == -1 then
if distance < self.range then
self.vel.x = 0
self.vel.y = 0
else
self.vel.x = math.cos(angle)*self.speed*distance
self.vel.y = math.sin(angle)*self.speed*distance
end
elseif self.status == 2 then
if distance < self.attack_range then
self.status = 3
end
elseif self.status == 4 then
end
end
function CursedBook:HandleAnimation()
if self.status == 1 then
if self.body.path == "assets/entities/cursed_book/spawn" then
self.body.speed = 1/3
local tint = 0.7 + 0.3 * (self.body.frame-1)/self.body.frames
self.sprite_tint = {tint,tint,tint}
if self.body.frame == self.body.frames then
self.status = 2
self.body = self.body:ChangeTo(animation.cursed_book.flying)
self.sprite_tint = {1,1,1}
--self:getBoundingBox(self.body,2,2,-2,-2)
self:centerOffset(self.body)
end
end
elseif self.status == 3 then
if self.body.path == "assets/entities/cursed_book/flying" then
self.body = self.body:ChangeTo(animation.cursed_book.attack_transition)
self.body.speed = 1/3
self:centerOffset(self.body)
if self.body.frame == self.body.frames then
self.status = 4
self.body = self.body:ChangeTo(animation.cursed_book.attack_loop)
self:centerOffset(self.body)
end
end
end
self.body:Animate()
self:Draw(self.body)
end
function CursedBook:DoPhysics()
if self.isFlying then
local random_x = math.random(-4, 4)/100
local random_y = math.random(-4, 4)/100
self.vel.x = self.vel.x + random_x
self.vel.y = self.vel.y + random_y
end
-- move
self:CollisionMove()
self:LightAdjust()
end
function CursedBook:Debug()
-- draw center GREEN
love.graphics.setColor(0,1,0)
love.graphics.circle("line", -Camera.pos.x + self.pos.x, -Camera.pos.y + self.pos.y, self.spawn_range)
love.graphics.setColor(1,0,0)
love.graphics.circle("line", -Camera.pos.x + self.pos.x, -Camera.pos.y + self.pos.y, self.attack_range)
Entity.Debug(self)
end

View File

@@ -0,0 +1,34 @@
Decoration = Entity:New(x,y)
function Decoration:New(x,y,animation,lightRange)
local o = Entity:New(x,y)
o.type = "decoration"
o.pos = {x = x, y = y}
-- animations
o.body = Animation:New(animation)
o:centerOffset(o.body)
o:getBoundingBox(o.body)
if lightRange ~= nil then
o.lightRange = lightRange
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange)
end
table.insert(LoadedObjects.Entities,o)
o.id = #LoadedObjects.Entities
setmetatable(o, self)
self.__index = self
return o
end
function Decoration:HandleAnimation()
self.body:Animate()
self:Draw(self.body)
end
function Decoration:DoPhysics()
end

115
code/entities/fairy.lua Normal file
View File

@@ -0,0 +1,115 @@
Fairy = Entity:New(x,y)
function Fairy:New(x,y)
local o = Entity:New(x,y)
o.type = "fairy"
-- behaviour
o.pos = {x = x, y = y}
o.speed = 1.4
o.range = 20
o.vision_range = 120
o.target = {x = x, y = y}
o.hover_distance = 60
-- animations
o.body = Animation:New(animation.fairy.flying)
o:centerOffset(o.body)
o:getBoundingBox(o.body)
-- light
o.light_range = 80
o.light = CreateLight(o.pos.x,o.pos.y,o.light_range,nil,HEX2RGB("#fed100"))
-- timer
o.particle_timer = 0
o.particle_time = 5
table.insert(LoadedObjects.Entities,o)
o.id = #LoadedObjects.Entities
setmetatable(o, self)
self.__index = self
return o
end
function Fairy:Smart()
if self:CheckVisionLine(main_Player,self.vision_range) then
self.target.x = main_Player.pos.x + main_Player.target_offset.x
self.target.y = main_Player.pos.y + main_Player.target_offset.y
local below = 1
while not isThereObjectAt(
self.target.x,
self.target.y + below * game.scale,
LoadedObjects.Collisions
) do
below = below + 1
if below >= self.hover_distance then break end
end
local top = 1
while not isThereObjectAt(
self.target.x,
self.target.y - top * game.scale,
LoadedObjects.Collisions
) do
top = top + 1
if top >= self.hover_distance then break end
end
self.target.y = self.target.y - top + below
end
local distance_x = self.target.x - self.pos.x
local distance_y = self.target.y - self.pos.y
local angle = GetAngleFromVector(distance_x,distance_y)
local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
if distance < self.range then
self.vel.x = 0
self.vel.y = 0
else
self.vel.x = math.cos(angle)*self.speed
self.vel.y = math.sin(angle)*self.speed
end
self.particle_timer = self.particle_timer + 1
if self.particle_timer >= self.particle_time then
self.particle_timer = 0
local particle_data = {
animation = animation.particle.simple,
sprite_tint = HEX2RGB("#fed100"),
direction = angle-math.rad(180+math.random(60)-30),
speed = 0.8*(distance/50),
speed_increase = -0.01,
}
Particle:New(self.pos.x,self.pos.y,particle_data)
end
end
function Fairy:HandleAnimation()
self.body:Animate()
--if self:isCollidingWith(main_Player) then self.sprite_tint = {1,0,0} else self.sprite_tint = {1,1,1} end
self:Draw(self.body)
end
function Fairy:DoPhysics()
local random_x = math.random(-4, 4)/10
local random_y = math.random(-4, 4)/10
self.vel.x = self.vel.x + random_x
self.vel.y = self.vel.y + random_y
self:CollisionMove()
self.vel.x = 0
self.vel.y = 0
self:LightAdjust()
end
function Fairy:Debug()
Entity.Debug(self)
self:CheckVisionLineDebug(main_Player,self.vision_range)
end

168
code/entities/kupo.lua Normal file
View File

@@ -0,0 +1,168 @@
Kupo = Entity:New(x,y)
function Kupo:New(x,y)
local o = Entity:New(x,y)
o.type = "kupo"
o.pos = {x = x, y = y}
o.speed = 20
o.range = 200
o.target = {x = x, y = y}
o.sprite_offset = {x = 8, y = 5}
-- animations
o.body = Animation:New(animation.kupo.body)
o.bow = Animation:New(animation.kupo.bow)
-- bow
o.bow_flip = 1
o.bow_rotation = 0
o.bow_frame = 1
o.bow_subframe = 1
o.bow_aim_frame = 0
o.bow_speed = 1/10
o.bow_frames = 6
o.bow_extraframes = 18
o.bow_aim_frames = 8
o.hostile = true
o.lightRange = o.range/2
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange)
table.insert(LoadedObjects.Entities,o)
o.id = #LoadedObjects.Entities
setmetatable(o, self)
self.__index = self
return o
end
function Kupo:Smart()
self.light.pos.x = self.pos.x-self.target_offset.x
self.light.pos.y = self.pos.y-self.target_offset.y
self.target.x = main_Player.pos.x - main_Player.target_offset.x
self.target.y = main_Player.pos.y - main_Player.target_offset.y
local distance_x = self.target.x - self.pos.x
local distance_y = self.target.y - self.pos.y
local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
local angle = GetAngleFromVector(distance_x,distance_y)
self.draw_bow = false
if distance <= self.range then
if self.hostile == true then
self.draw_bow = true
-- fix so it can rotate from 0 to 360
if math.deg(self.bow_rotation - angle) < 0 then
self.bow_rotation = self.bow_rotation + math.rad(360)
end
-- fix so it can rotate from 360 to 0
if math.deg(self.bow_rotation - angle) > 180 then
self.bow_rotation = self.bow_rotation - math.rad(360)
end
-- actual rotation
if self.bow_rotation < angle then
self.bow_rotation = self.bow_rotation + math.rad(2)
else
self.bow_rotation = self.bow_rotation - math.rad(2)
end
--set in place
if math.abs(math.deg(self.bow_rotation) - math.deg(angle)) < 2 then
self.bow_rotation = angle
end
-- holding tight dispersion -- also affects arrows
if self.bow_rotation == angle then
self.bow_rotation = self.bow_rotation + math.rad(math.random(math.abs(math.floor(self.bow_frame-self.bow_aim_frames-self.bow_frames)/2)))
end
-- AIMING AI
self.bow_subframe = self.bow_subframe + current_dt
if self.bow_subframe > self.bow_speed then
self.bow_subframe = self.bow_subframe - self.bow_speed
if self.bow_frame == 3 then
self.bow_aim_frame = self.bow_aim_frame + 1
if self.bow_aim_frame > self.bow_aim_frames then
self.bow_aim_frame = self.bow_aim_frame - self.bow_aim_frames
self.bow_frame = self.bow_frame + 1
Arrow:New(self.pos.x,self.pos.y,self.bow_rotation,15)
end
else
self.bow_frame = self.bow_frame + 1
end
if self.bow_frame > self.bow_frames + self.bow_extraframes then
self.bow_frame = self.bow_frame - self.bow_frames - self.bow_extraframes
end
end
end
else
self.bow_frame = 6
-- rest bow animation
if distance_x > 0 then
if self.bow_rotation > math.rad(45) then
self.bow_rotation = self.bow_rotation - math.rad(3)
elseif self.bow_rotation < math.rad(45) then
self.bow_rotation = self.bow_rotation + math.rad(3)
end
-- set in place
if math.abs(math.deg(self.bow_rotation) - 45) < 3 then
self.bow_rotation = math.rad(45)
end
self.sprite_flip.x = 1
else
if self.bow_rotation > math.rad(135) then
self.bow_rotation = self.bow_rotation - math.rad(3)
elseif self.bow_rotation < math.rad(135) then
self.bow_rotation = self.bow_rotation + math.rad(3)
end
-- set in place
if math.abs(math.deg(self.bow_rotation) - 135) < 3 then
self.bow_rotation = math.rad(135)
end
self.sprite_flip.x = -1
end
end
self.angle = angle
end
function Kupo:HandleAnimation()
local distance_x = self.target.x - self.pos.x
local distance_y = self.target.y - self.pos.y
if distance_x > 0 then
self.sprite_flip.x = 1
else
self.sprite_flip.x = -1
end
-- 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
self.body:Animate()
self:Draw(self.body)
if self.draw_bow == true then
self.bow:DrawFrame(
math.min(self.bow_frame,self.bow_frames),
self.pos.x + ( 8 * math.sin(self.bow_rotation)),
self.pos.y + (2 - 6 * math.cos(self.bow_rotation)),
self.bow_rotation
)
end
end
function Kupo:DoPhysics()
-- horizontal collisions
if not isThereAnyCollisionAt(self.pos.x + self.vel.x, self.pos.y) then
self.pos.x = self.pos.x + self.vel.x
end
if not isThereAnyCollisionAt(self.pos.x, self.pos.y + self.vel.y) then
self.pos.y = self.pos.y + self.vel.y
end
end

View File

@@ -0,0 +1,99 @@
Particle = Entity:New(x,y)
function Particle:New(x,y,particle_data)
local o = Entity:New(x,y)
o.pos = {x = x, y = y}
o.speed = particle_data.speed or 0
o.direction = particle_data.direction or o.direction
o.sprite_rotation = particle_data.sprite_rotation or o.sprite_rotation
o.sprite_offset = particle_data.sprite_offset or o.sprite_offset
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_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.timer = 0
o.vel = {
x = o.speed * math.cos(o.direction),
y = o.speed * math.sin(o.direction)
}
o.speed_increase = particle_data.speed_increase or 0
if particle_data.light ~= nil then
o.lightRange = particle_data.light
local flicker = particle_data.light_flicker or nil
local color = particle_data.light_color or nil
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange,flicker,color)
end
-- animations
if particle_data.animation ~= nil then
o.body = Animation:New(particle_data.animation)
o:centerOffset(o.body)
o:getBoundingBox(o.body)
if not o.animation_active then
o.body.speed = 0
end
end
table.insert(LoadedParticles,o)
o.id = #LoadedParticles
setmetatable(o, self)
self.__index = self
return o
end
function Particle:Kill()
if self.light ~= nil then
KillLight(self.light)
end
if self.id ~= nil then
for _, e in pairs(LoadedParticles) do
if e.id > self.id then
e.id = e.id - 1
end
end
table.remove(LoadedParticles,self.id)
end
self = nil
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:LightAdjust()
self.light.range = self.lightRange * self.sprite_alpha/2
end
if self.sprite_alpha < 0 then self:Kill() end
if self.body ~= nil then
self.body:Animate()
self:Draw(self.body)
end
end
function Particle:DoPhysics()
-- adjust speed
if self.speed_increase ~= 0 then
self.speed = self.speed + self.speed_increase
self.vel.x = self.speed * math.cos(self.direction)
self.vel.y = self.speed * math.sin(self.direction)
end
-- move
self:CollisionMove()
end
function Particle:Debug()
-- draw center CYAN
love.graphics.setColor(0,1,1)
love.graphics.circle("fill", -Camera.pos.x + self.pos.x, -Camera.pos.y + self.pos.y, 1)
end

280
code/entities/player.lua Normal file
View File

@@ -0,0 +1,280 @@
Player = Entity:New(x,y)
function Player:New(x,y)
local o = Entity:New(x,y)
o.type = "player"
-- physics
o.moveSpeed = 1.3 -- gameworld pixels
o.zeroSpeed = 0.01 -- gameworld pixels
o.move_x = 0 -- gameworld pixels
o.airFriction = 0.01 -- gameworld pixels
o.groundFriction = 0.3 -- gameworld pixels
o.jumpImpulse = 3.5 -- gameworld pixels
o.coyoteAmount = 5 -- int
o.coyoteValue = 5 -- frames
o.dashCooldownTime = 0.1 -- seconds
o.dashCooldownTimer = 0 -- seconds
-- dash values
o.dashTimer = 0 -- seconds
o.dashTime = 0.15 -- seconds
o.dashDistance = 40 -- gameworld pixels
o.dashSpeed = o.dashDistance / (o.dashTime*60) -- pixels
o.dashCount = 1 -- int
o.dashAmount = 10 -- int
-- hook values
o.hookDistance = 100
o.hookedDistance = 80
o.hookAnchor = {
x = nil,
y = nil
}
o.boxCollision = {
from = {x = -8, y = -16}, --gameworld pixels
to = {x = 8, y = 0} -- gameworld pixels
}
o.lightRange = 10 -- screen pixels
-- status
o.isDashing = false
o.isJumping = false
o.isHooked = false
o.isOnGround = true
o.isOnLadder = false
o.canJump = true
o.canFall = true
o.canFriction = true
o.maskType = animation.moth_mask
o.anchorRespawn = {
x = o.pos.x,
y = o.pos.y
}
-- sprite
o.target_offset = {x = 0, y = 0}
o.body = Animation:New(animation.nancy.idle)
o.mask = Animation:New(animation.moth_mask.idle)
o:centerOffset(o.body)
o:getBoundingBox(o.body,0,3,-1,-3)
-- lights
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange)
table.insert(LoadedObjects.Entities,o)
o.id = #LoadedObjects.Entities
setmetatable(o, self)
self.__index = self
return o
end
function Player:Smart()
self:LightAdjust(self.target_offset.x,self.target_offset.y)
-- reset coyoteValue
if self.isOnGround then
self.coyoteValue = self.coyoteAmount
elseif self.coyoteValue > 0 then
self.coyoteValue = self.coyoteValue - 1
end
if self.dashTimer <= 0 then
-- horizontal movement
if Keybind:CheckDown(Keybind.move.left) then
self.move_x = -self.moveSpeed
elseif Keybind:CheckDown(Keybind.move.right) then
self.move_x = self.moveSpeed
end
-- jump if on ground (coyotevalue)
if Keybind:CheckDown(Keybind.move.jump) then
if self.coyoteValue > 0 then
self.vel.y = -self.jumpImpulse
self.coyoteValue = 0
end
end
end
-- dash timer
self.dashCooldownTimer = math.max(0,self.dashCooldownTimer - current_dt)
-- try to dash
if Keybind:CheckDown(Keybind.move.dash) then
if self.dashCooldownTimer == 0
and not self.isDashing
and self.dashCount > 0 then
-- state player
self.dashCount = self.dashCount - 1
self.isDashing = true
-- get dash direction
local vertical = 0
if Keybind:CheckDown(Keybind.move.down) then vertical = vertical + 1 end
if Keybind:CheckDown(Keybind.move.up) then vertical = vertical - 1 end
local horizontal = 0
if Keybind:CheckDown(Keybind.move.right) then horizontal = horizontal + 1 end
if Keybind:CheckDown(Keybind.move.left) then horizontal = horizontal - 1 end
-- if no direction, then dash forward
if horizontal == 0 and vertical == 0 then
horizontal = self.sprite_flip.x
end
-- set dash values
self.dashDirection = GetAngleFromVector(horizontal, vertical)
self.dashTimer = self.dashTime
end
else
-- not dashing!
self.isDashing = false
end
if Keybind:CheckDown(Keybind.move.hook) then
local anchor = self:CheckNearest("decoration",self.hookDistance)
if anchor then
self.isHooked = true
self.hookAnchor = {
x = anchor.pos.x,
y = anchor.pos.y
}
end
else
self.isHooked = false
end
end
function Player:DoPhysics()
if self.dashTimer <= 0 then
if self.isOnGround then
self.vel.x = self.vel.x * (1-self.groundFriction)
else
self.vel.x = self.vel.x * (1-self.airFriction)
end
if math.abs(self.vel.x) < self.zeroSpeed then self.vel.x = 0 end
end
-- reset state
self.canFall = true
self.isOnGround = false
-- adjust timers
self.dashTimer = self.dashTimer - current_dt
-- DASH STATE
if self.dashTimer > 0 then
self.canFall = false
-- dash particle
local particle_data = {
animation = self.body,
sprite_tint = HEX2RGB("#fed100"),
sprite_alpha = 0.5,
sprite_flip = {
x = self.sprite_flip.x,
y = self.sprite_flip.y
}
}
Particle:New(self.pos.x,self.pos.y,particle_data)
self.dashCooldownTimer = self.dashCooldownTime
-- dash movement
self.vel.x = self.dashSpeed * math.cos(self.dashDirection)
self.vel.y = self.dashSpeed * math.sin(self.dashDirection)
end
-- hook state
if self.isHooked then
local hook = Vector(self.pos.x, self.pos.y, self.hookAnchor.x, self.hookAnchor.y)
if GetVectorValue(hook) > self.hookedDistance then
local hook_angle = GetAngleFromVector(hook[1],hook[2])
local pos_x = self.hookAnchor.x + self.hookedDistance * math.cos(-math.rad(180)+hook_angle)
local pos_y = self.hookAnchor.y + self.hookedDistance * math.sin(-math.rad(180)+hook_angle)
self.vel.x = self.vel.x + pos_x - self.pos.x
self.vel.y = self.vel.y + pos_y - self.pos.y
end
end
if self.canFall then
-- not in dash or hook; fall normally
self.dashTimer = 0
self.vel.y = self.vel.y + gravity
end
-- horizontal collision
if not self:isCollidingAt(self.pos.x + self.vel.x + self.move_x, self.pos.y, LoadedObjects.Collisions) then
self.pos.x = self.pos.x + self.vel.x + self.move_x
else
self.vel.x = 0
end
-- vertical collision
if not self:isCollidingAt(self.pos.x, self.pos.y + self.vel.y, LoadedObjects.Collisions) then
self.pos.y = self.pos.y + self.vel.y
else
if self.vel.y > 0 then
self.isOnGround = true
self.dashCount = self.dashAmount
end
self.vel.y = 0
end
-- if u collision w hazard, respawn
if self:isCollidingAt(self.pos.x, self.pos.y, LoadedObjects.Hazards) then
self:Respawn()
end
end
function Player:Respawn()
self.pos.x = self.anchorRespawn.x
self.pos.y = self.anchorRespawn.y
end
function Player:HandleAnimation()
-- flip sprite to look in the direction is moving
if self.move_x ~= 0 then self.sprite_flip.x = math.sign(self.move_x) end
-- animation priority
self.body = self.body:ChangeTo(animation.nancy.fall)
if self.vel.y > 1.25 then
self.mask = self.mask:ChangeTo(self.maskType.fall)
elseif self.vel.y < 0 then
self.body = self.body:ChangeTo(animation.nancy.jump)
self.mask = self.mask:ChangeTo(self.maskType.jump)
elseif self.vel.x + self.move_x ~= 0 then
self.body = self.body:ChangeTo(animation.nancy.run)
self.mask = self.mask:ChangeTo(self.maskType.run)
else
self.body = self.body:ChangeTo(animation.nancy.idle)
self.mask = self.mask:ChangeTo(self.maskType.idle)
end
-- special case: idle animation gets slower by time
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
if self.isHooked then
love.graphics.line(
-Camera.pos.x + self.pos.x,
-Camera.pos.y + self.pos.y,
-Camera.pos.x + self.hookAnchor.x,
-Camera.pos.y + self.hookAnchor.y
)
end
self.body:Animate()
self:Draw(self.body)
if self.dashCount > 0 then
self:Draw(self.mask)
end
self.move_x = 0
end