consistent indentation
This commit is contained in:
@@ -1,56 +1,56 @@
|
||||
Arrow = Entity:New(x,y)
|
||||
|
||||
function Arrow:New(x,y,rotation,speed)
|
||||
local o = Entity:New(x,y)
|
||||
function Arrow:New(x,y,rotation,speed)
|
||||
local o = Entity:New(x,y)
|
||||
|
||||
o.type = "arrow"
|
||||
o.type = "arrow"
|
||||
|
||||
o.pos = {x = x, y = y}
|
||||
o.speed = speed or 10
|
||||
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.pos = {x = x, y = y}
|
||||
o.speed = speed or 10
|
||||
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
|
||||
o.stuck = false
|
||||
o.illuminated = true
|
||||
|
||||
-- animations
|
||||
o.body = Animation:New(animation.kupo.arrow)
|
||||
-- animations
|
||||
o.body = Animation:New(animation.kupo.arrow)
|
||||
|
||||
o.boxCollision = {
|
||||
from = {x = -0.5, y = -0.5}, --gameworld pixels
|
||||
to = {x = 0.5, y = 0.5} -- gameworld pixels
|
||||
}
|
||||
o.boxCollision = {
|
||||
from = {x = -0.5, y = -0.5}, --gameworld pixels
|
||||
to = {x = 0.5, y = 0.5} -- gameworld pixels
|
||||
}
|
||||
|
||||
table.insert(LoadedObjects.Entities,o)
|
||||
o.id = #LoadedObjects.Entities
|
||||
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
return o
|
||||
end
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
return o
|
||||
end
|
||||
|
||||
function Arrow:DrawBackground()
|
||||
self:Draw(self.body)
|
||||
self:Draw(self.body)
|
||||
end
|
||||
|
||||
function Arrow:DoPhysics()
|
||||
if not self:isCollidingAt(self.pos.x + self.vel.x, self.pos.y, LoadedObjects.Collisions) then
|
||||
self.pos.x = self.pos.x + self.vel.x
|
||||
else
|
||||
self.stuck = true
|
||||
end
|
||||
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
|
||||
self.stuck = true
|
||||
end
|
||||
if self.stuck then
|
||||
self.pos.x = self.pos.x + self.vel.x * (2/3)
|
||||
self.pos.y = self.pos.y + self.vel.y * (2/3)
|
||||
self.vel.x = 0
|
||||
self.vel.y = 0
|
||||
end
|
||||
if not self:isCollidingAt(self.pos.x + self.vel.x, self.pos.y, LoadedObjects.Collisions) then
|
||||
self.pos.x = self.pos.x + self.vel.x
|
||||
else
|
||||
self.stuck = true
|
||||
end
|
||||
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
|
||||
self.stuck = true
|
||||
end
|
||||
if self.stuck then
|
||||
self.pos.x = self.pos.x + self.vel.x * (2/3)
|
||||
self.pos.y = self.pos.y + self.vel.y * (2/3)
|
||||
self.vel.x = 0
|
||||
self.vel.y = 0
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,112 +1,112 @@
|
||||
CursedBook = Entity:New(x,y)
|
||||
|
||||
function CursedBook:New(x,y)
|
||||
local o = 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.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
|
||||
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)
|
||||
-- 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 = Light:New(o.pos.x,o.pos.y,o.light_range,2,HEX2RGB("#fe00d1"))
|
||||
-- light
|
||||
o.light_range = 500
|
||||
o.light = Light:New(o.pos.x,o.pos.y,o.light_range,2,HEX2RGB("#fe00d1"))
|
||||
|
||||
table.insert(LoadedObjects.Entities,o)
|
||||
o.id = #LoadedObjects.Entities
|
||||
table.insert(LoadedObjects.Entities,o)
|
||||
o.id = #LoadedObjects.Entities
|
||||
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
return o
|
||||
end
|
||||
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)
|
||||
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
|
||||
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
|
||||
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)
|
||||
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
|
||||
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()
|
||||
self:CollisionMove()
|
||||
self:LightAdjust()
|
||||
end
|
||||
|
||||
function CursedBook:Debug()
|
||||
@@ -115,5 +115,5 @@ function CursedBook:Debug()
|
||||
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)
|
||||
Entity.Debug(self)
|
||||
end
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
Decoration = Entity:New(x,y)
|
||||
|
||||
function Decoration:New(x,y,animation,lightRange)
|
||||
local o = Entity:New(x,y)
|
||||
local o = Entity:New(x,y)
|
||||
|
||||
o.type = "decoration"
|
||||
o.type = "decoration"
|
||||
|
||||
o.pos = {x = x, y = y}
|
||||
o.pos = {x = x, y = y}
|
||||
|
||||
-- animations
|
||||
o.body = Animation:New(animation)
|
||||
o:centerOffset(o.body)
|
||||
o:getBoundingBox(o.body)
|
||||
-- animations
|
||||
o.body = Animation:New(animation)
|
||||
o:centerOffset(o.body)
|
||||
o:getBoundingBox(o.body)
|
||||
|
||||
if lightRange ~= nil then
|
||||
o.lightRange = lightRange
|
||||
o.light = Light:New(o.pos.x,o.pos.y,o.lightRange)
|
||||
end
|
||||
if lightRange ~= nil then
|
||||
o.lightRange = lightRange
|
||||
o.light = Light:New(o.pos.x,o.pos.y,o.lightRange)
|
||||
end
|
||||
|
||||
table.insert(LoadedObjects.Entities,o)
|
||||
o.id = #LoadedObjects.Entities
|
||||
table.insert(LoadedObjects.Entities,o)
|
||||
o.id = #LoadedObjects.Entities
|
||||
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
return o
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
return o
|
||||
end
|
||||
|
||||
function Decoration:HandleAnimation()
|
||||
self.body:Animate()
|
||||
self:Draw(self.body)
|
||||
self.body:Animate()
|
||||
self:Draw(self.body)
|
||||
end
|
||||
|
||||
function Decoration:DoPhysics()
|
||||
|
||||
@@ -1,115 +1,115 @@
|
||||
Fairy = Entity:New(x,y)
|
||||
|
||||
function Fairy:New(x,y)
|
||||
local o = Entity:New(x,y)
|
||||
function Fairy:New(x,y)
|
||||
local o = Entity:New(x,y)
|
||||
|
||||
o.type = "fairy"
|
||||
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
|
||||
-- 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)
|
||||
-- animations
|
||||
o.body = Animation:New(animation.fairy.flying)
|
||||
o:centerOffset(o.body)
|
||||
o:getBoundingBox(o.body)
|
||||
|
||||
-- light
|
||||
o.light_range = 80
|
||||
o.light = Light:New(o.pos.x,o.pos.y,o.light_range,nil,HEX2RGB("#fed100"))
|
||||
-- light
|
||||
o.light_range = 80
|
||||
o.light = Light:New(o.pos.x,o.pos.y,o.light_range,nil,HEX2RGB("#fed100"))
|
||||
|
||||
-- timer
|
||||
o.particle_timer = 0
|
||||
o.particle_time = 5
|
||||
-- timer
|
||||
o.particle_timer = 0
|
||||
o.particle_time = 5
|
||||
|
||||
table.insert(LoadedObjects.Entities,o)
|
||||
o.id = #LoadedObjects.Entities
|
||||
table.insert(LoadedObjects.Entities,o)
|
||||
o.id = #LoadedObjects.Entities
|
||||
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
return o
|
||||
end
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
return o
|
||||
end
|
||||
|
||||
function Fairy:Smart()
|
||||
|
||||
if self:CheckVisionLine(main_Player,self.vision_range) then
|
||||
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
|
||||
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 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)
|
||||
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 = self.vel.x * 0.9
|
||||
self.vel.y = self.vel.y * 0.9
|
||||
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
|
||||
if distance < self.range then
|
||||
self.vel.x = self.vel.x * 0.9
|
||||
self.vel.y = self.vel.y * 0.9
|
||||
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
|
||||
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)
|
||||
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
|
||||
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.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:CollisionMove()
|
||||
self.vel.x = 0
|
||||
self.vel.y = 0
|
||||
|
||||
self:LightAdjust()
|
||||
self:LightAdjust()
|
||||
end
|
||||
|
||||
function Fairy:Debug()
|
||||
Entity.Debug(self)
|
||||
self:CheckVisionLineDebug(main_Player,self.vision_range)
|
||||
Entity.Debug(self)
|
||||
self:CheckVisionLineDebug(main_Player,self.vision_range)
|
||||
end
|
||||
|
||||
@@ -1,40 +1,40 @@
|
||||
HookAnchor = Entity:New(x,y)
|
||||
|
||||
function HookAnchor:New(x,y,hookDistance)
|
||||
local o = Entity:New(x,y)
|
||||
local o = Entity:New(x,y)
|
||||
|
||||
o.type = "hook_anchor"
|
||||
o.type = "hook_anchor"
|
||||
|
||||
o.pos = {x = x, y = y}
|
||||
o.hookDistance = hookDistance or 100
|
||||
-- animations
|
||||
o.body = Animation:New(animation.fairy.flying)
|
||||
o:centerOffset(o.body)
|
||||
o:getBoundingBox(o.body)
|
||||
o.pos = {x = x, y = y}
|
||||
o.hookDistance = hookDistance or 100
|
||||
-- animations
|
||||
o.body = Animation:New(animation.fairy.flying)
|
||||
o:centerOffset(o.body)
|
||||
o:getBoundingBox(o.body)
|
||||
|
||||
|
||||
table.insert(LoadedObjects.Entities,o)
|
||||
o.id = #LoadedObjects.Entities
|
||||
table.insert(LoadedObjects.Entities,o)
|
||||
o.id = #LoadedObjects.Entities
|
||||
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
return o
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
return o
|
||||
end
|
||||
|
||||
function HookAnchor:HandleAnimation()
|
||||
self.body:Animate()
|
||||
self:Draw(self.body)
|
||||
self.body:Animate()
|
||||
self:Draw(self.body)
|
||||
end
|
||||
|
||||
function HookAnchor:DrawBackground()
|
||||
Entity.DrawBackground(self)
|
||||
love.graphics.setColor(1,1,1,0)
|
||||
love.graphics.circle(
|
||||
"fill",
|
||||
-Camera.pos.x + self.pos.x,
|
||||
-Camera.pos.y + self.pos.y,
|
||||
self.hookDistance
|
||||
)
|
||||
Entity.DrawBackground(self)
|
||||
love.graphics.setColor(1,1,1,0)
|
||||
love.graphics.circle(
|
||||
"fill",
|
||||
-Camera.pos.x + self.pos.x,
|
||||
-Camera.pos.y + self.pos.y,
|
||||
self.hookDistance
|
||||
)
|
||||
end
|
||||
|
||||
function HookAnchor:DoPhysics()
|
||||
@@ -42,5 +42,5 @@ end
|
||||
|
||||
|
||||
function Fairy:Debug()
|
||||
Entity.Debug(self)
|
||||
Entity.Debug(self)
|
||||
end
|
||||
|
||||
@@ -1,161 +1,161 @@
|
||||
Kupo = Entity:New(x,y)
|
||||
|
||||
function Kupo:New(x,y)
|
||||
local o = Entity:New(x,y)
|
||||
function Kupo:New(x,y)
|
||||
local o = Entity:New(x,y)
|
||||
|
||||
o.type = "kupo"
|
||||
o.type = "kupo"
|
||||
|
||||
o.pos = {x = x, y = y}
|
||||
o.speed = 20
|
||||
o.range = 200
|
||||
o.target = {x = x, y = y}
|
||||
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)
|
||||
-- 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
|
||||
-- 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.hostile = true
|
||||
|
||||
o.lightRange = o.range/2
|
||||
o.lightRange = o.range/2
|
||||
o.light = Light:New(o.pos.x,o.pos.y,o.lightRange)
|
||||
|
||||
table.insert(LoadedObjects.Entities,o)
|
||||
o.id = #LoadedObjects.Entities
|
||||
table.insert(LoadedObjects.Entities,o)
|
||||
o.id = #LoadedObjects.Entities
|
||||
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
return o
|
||||
end
|
||||
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.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
|
||||
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
|
||||
-- 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
|
||||
-- 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
|
||||
-- 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
|
||||
-- AIMING AI
|
||||
|
||||
self.bow_subframe = self.bow_subframe + current_dt
|
||||
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,10)
|
||||
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
|
||||
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,10)
|
||||
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
|
||||
-- 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
|
||||
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
|
||||
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
|
||||
-- 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)
|
||||
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
|
||||
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()
|
||||
self:CollisionMove()
|
||||
self:CollisionMove()
|
||||
end
|
||||
|
||||
@@ -1,100 +1,100 @@
|
||||
Particle = Entity:New(x,y)
|
||||
LoadedObjects.Particles = {}
|
||||
|
||||
function Particle:New(x,y,particle_data)
|
||||
local o = Entity:New(x,y)
|
||||
function Particle:New(x,y,particle_data)
|
||||
local o = Entity:New(x,y)
|
||||
|
||||
o.pos = {x = x, y = 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.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.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.time = 0.5
|
||||
o.timer = 0
|
||||
|
||||
o.vel = {
|
||||
x = o.speed * math.cos(o.direction),
|
||||
y = o.speed * math.sin(o.direction)
|
||||
}
|
||||
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
|
||||
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 = Light:New(o.pos.x,o.pos.y,o.lightRange,flicker,color)
|
||||
end
|
||||
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 = Light:New(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
|
||||
-- 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(LoadedObjects.Particles,o)
|
||||
o.id = #LoadedObjects.Particles
|
||||
table.insert(LoadedObjects.Particles,o)
|
||||
o.id = #LoadedObjects.Particles
|
||||
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
return o
|
||||
end
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
return o
|
||||
end
|
||||
|
||||
function Particle:Kill()
|
||||
if self.light ~= nil then
|
||||
self.light:Kill()
|
||||
end
|
||||
if self.id ~= nil then
|
||||
for _, e in pairs(LoadedObjects.Particles) do
|
||||
if e.id > self.id then
|
||||
e.id = e.id - 1
|
||||
end
|
||||
end
|
||||
table.remove(LoadedObjects.Particles,self.id)
|
||||
end
|
||||
self = nil
|
||||
end
|
||||
if self.light ~= nil then
|
||||
self.light:Kill()
|
||||
end
|
||||
if self.id ~= nil then
|
||||
for _, e in pairs(LoadedObjects.Particles) do
|
||||
if e.id > self.id then
|
||||
e.id = e.id - 1
|
||||
end
|
||||
end
|
||||
table.remove(LoadedObjects.Particles,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
|
||||
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()
|
||||
-- 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)
|
||||
-- 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
|
||||
|
||||
@@ -1,316 +1,316 @@
|
||||
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.hookAnchor = {
|
||||
x = nil,
|
||||
y = nil
|
||||
}
|
||||
|
||||
o.lightRange = 40 -- 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 = Light:New(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
|
||||
self:Unhook()
|
||||
|
||||
-- state player
|
||||
self.isDashing = true
|
||||
self.dashCount = self.dashCount - 1
|
||||
|
||||
-- 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:CheckPressed(Keybind.move.hook) then
|
||||
if self.isHooked then
|
||||
self:Unhook()
|
||||
else
|
||||
local anchor = self:CheckNearest("hook_anchor",self.hookDistance)
|
||||
if anchor then
|
||||
self.isHooked = true
|
||||
self.hookDistance = anchor.hookDistance
|
||||
self.hookAnchor = {
|
||||
x = anchor.pos.x,
|
||||
y = anchor.pos.y
|
||||
}
|
||||
end
|
||||
end
|
||||
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
|
||||
|
||||
self.vel.y = self.vel.y * (1-self.airFriction)
|
||||
|
||||
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.hookDistance then
|
||||
local hook_angle = GetAngleFromVector(hook[1],hook[2])-math.rad(180)
|
||||
if Keybind:CheckDown(Keybind.move.right) then
|
||||
hook_angle = hook_angle - math.rad(0.05)
|
||||
self.move_x = 0
|
||||
end
|
||||
if Keybind:CheckDown(Keybind.move.left) then
|
||||
hook_angle = hook_angle + math.rad(0.05)
|
||||
self.move_x = 0
|
||||
end
|
||||
|
||||
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)
|
||||
|
||||
local pos_x = self.hookAnchor.x + self.hookDistance * math.cos(hook_angle)
|
||||
local pos_y = self.hookAnchor.y + self.hookDistance * math.sin(hook_angle)
|
||||
self.vel.x = self.vel.x + pos_x - self.pos.x
|
||||
self.vel.y = self.vel.y + pos_y - self.pos.y
|
||||
self.pos.x = pos_x
|
||||
self.pos.y = pos_y
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if self.canFall then
|
||||
-- not in dash
|
||||
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.isHooked then
|
||||
if self.vel.x ~= 0 then
|
||||
self.sprite_flip.x = math.sign(self.vel.x)
|
||||
end
|
||||
elseif self.move_x ~= 0 then
|
||||
self.sprite_flip.x = math.sign(self.move_x)
|
||||
end
|
||||
|
||||
-- animation priority
|
||||
if self.vel.y > 1.25 then
|
||||
self.body = self.body:ChangeTo(animation.nancy.fall)
|
||||
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
|
||||
|
||||
function Player:Unhook()
|
||||
self.isHooked = false
|
||||
self.hookAnchor = nil
|
||||
end
|
||||
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.hookAnchor = {
|
||||
x = nil,
|
||||
y = nil
|
||||
}
|
||||
|
||||
o.lightRange = 40 -- 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 = Light:New(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
|
||||
self:Unhook()
|
||||
|
||||
-- state player
|
||||
self.isDashing = true
|
||||
self.dashCount = self.dashCount - 1
|
||||
|
||||
-- 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:CheckPressed(Keybind.move.hook) then
|
||||
if self.isHooked then
|
||||
self:Unhook()
|
||||
else
|
||||
local anchor = self:CheckNearest("hook_anchor",self.hookDistance)
|
||||
if anchor then
|
||||
self.isHooked = true
|
||||
self.hookDistance = anchor.hookDistance
|
||||
self.hookAnchor = {
|
||||
x = anchor.pos.x,
|
||||
y = anchor.pos.y
|
||||
}
|
||||
end
|
||||
end
|
||||
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
|
||||
|
||||
self.vel.y = self.vel.y * (1-self.airFriction)
|
||||
|
||||
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.hookDistance then
|
||||
local hook_angle = GetAngleFromVector(hook[1],hook[2])-math.rad(180)
|
||||
if Keybind:CheckDown(Keybind.move.right) then
|
||||
hook_angle = hook_angle - math.rad(0.05)
|
||||
self.move_x = 0
|
||||
end
|
||||
if Keybind:CheckDown(Keybind.move.left) then
|
||||
hook_angle = hook_angle + math.rad(0.05)
|
||||
self.move_x = 0
|
||||
end
|
||||
|
||||
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)
|
||||
|
||||
local pos_x = self.hookAnchor.x + self.hookDistance * math.cos(hook_angle)
|
||||
local pos_y = self.hookAnchor.y + self.hookDistance * math.sin(hook_angle)
|
||||
self.vel.x = self.vel.x + pos_x - self.pos.x
|
||||
self.vel.y = self.vel.y + pos_y - self.pos.y
|
||||
self.pos.x = pos_x
|
||||
self.pos.y = pos_y
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if self.canFall then
|
||||
-- not in dash
|
||||
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.isHooked then
|
||||
if self.vel.x ~= 0 then
|
||||
self.sprite_flip.x = math.sign(self.vel.x)
|
||||
end
|
||||
elseif self.move_x ~= 0 then
|
||||
self.sprite_flip.x = math.sign(self.move_x)
|
||||
end
|
||||
|
||||
-- animation priority
|
||||
if self.vel.y > 1.25 then
|
||||
self.body = self.body:ChangeTo(animation.nancy.fall)
|
||||
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
|
||||
|
||||
function Player:Unhook()
|
||||
self.isHooked = false
|
||||
self.hookAnchor = nil
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user