hook anchors. player animation fixed.

This commit is contained in:
lustlion 2022-02-15 10:21:24 +01:00
parent f6541068e0
commit 8def86ade6
7 changed files with 70 additions and 18 deletions

View File

@ -68,8 +68,8 @@ function Fairy:Smart()
local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2) local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
if distance < self.range then if distance < self.range then
self.vel.x = 0 self.vel.x = self.vel.x * 0.9
self.vel.y = 0 self.vel.y = self.vel.y * 0.9
else else
self.vel.x = math.cos(angle)*self.speed self.vel.x = math.cos(angle)*self.speed
self.vel.y = math.sin(angle)*self.speed self.vel.y = math.sin(angle)*self.speed

View File

@ -0,0 +1,35 @@
HookAnchor = Entity:New(x,y)
function HookAnchor:New(x,y,hookDistance)
local o = Entity:New(x,y)
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)
table.insert(LoadedObjects.Entities,o)
o.id = #LoadedObjects.Entities
setmetatable(o, self)
self.__index = self
return o
end
function HookAnchor:HandleAnimation()
self.body:Animate()
self:Draw(self.body)
local particle_data = {
animation = animation.particle.simple,
sprite_tint = HEX2RGB("#fed100")
}
end
function HookAnchor:DoPhysics()
end

View File

@ -30,8 +30,6 @@
o.dashAmount = 10 -- int o.dashAmount = 10 -- int
-- hook values -- hook values
o.hookDistance = 80
o.hookedDistance = 80
o.hookAnchor = { o.hookAnchor = {
x = nil, x = nil,
y = nil y = nil
@ -145,9 +143,10 @@ function Player:Smart()
if self.isHooked then if self.isHooked then
self:Unhook() self:Unhook()
else else
local anchor = self:CheckNearest("decoration",self.hookDistance) local anchor = self:CheckNearest("hook_anchor",self.hookDistance)
if anchor then if anchor then
self.isHooked = true self.isHooked = true
self.hookDistance = anchor.hookDistance
self.hookAnchor = { self.hookAnchor = {
x = anchor.pos.x, x = anchor.pos.x,
y = anchor.pos.y y = anchor.pos.y
@ -196,7 +195,7 @@ function Player:DoPhysics()
-- hook state -- hook state
if self.isHooked then if self.isHooked then
local hook = Vector(self.pos.x, self.pos.y, self.hookAnchor.x, self.hookAnchor.y) local hook = Vector(self.pos.x, self.pos.y, self.hookAnchor.x, self.hookAnchor.y)
if GetVectorValue(hook) > self.hookedDistance then if GetVectorValue(hook) > self.hookDistance then
local particle_data = { local particle_data = {
animation = self.body, animation = self.body,
sprite_tint = HEX2RGB("#fed100"), sprite_tint = HEX2RGB("#fed100"),
@ -208,10 +207,16 @@ function Player:DoPhysics()
} }
Particle:New(self.pos.x,self.pos.y,particle_data) Particle:New(self.pos.x,self.pos.y,particle_data)
local hook_angle = GetAngleFromVector(hook[1],hook[2])-math.rad(180) 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) end if Keybind:CheckDown(Keybind.move.right) then
if Keybind:CheckDown(Keybind.move.left) then hook_angle = hook_angle + math.rad(0.05) end hook_angle = hook_angle - math.rad(0.05)
local pos_x = self.hookAnchor.x + self.hookedDistance * math.cos(hook_angle) self.move_x = 0
local pos_y = self.hookAnchor.y + self.hookedDistance * math.sin(hook_angle) end
if Keybind:CheckDown(Keybind.move.left) then
hook_angle = hook_angle + math.rad(0.05)
self.move_x = 0
end
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.x = self.vel.x + pos_x - self.pos.x
self.vel.y = self.vel.y + pos_y - self.pos.y self.vel.y = self.vel.y + pos_y - self.pos.y
self.pos.x = pos_x self.pos.x = pos_x
@ -257,12 +262,18 @@ end
function Player:HandleAnimation() function Player:HandleAnimation()
-- flip sprite to look in the direction is moving -- 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 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 -- animation priority
self.body = self.body:ChangeTo(animation.nancy.fall) if self.vel.y > 1.25 then
if self.vel.y > 1.25 then self.body = self.body:ChangeTo(animation.nancy.fall)
self.mask = self.mask:ChangeTo(self.maskType.fall) self.mask = self.mask:ChangeTo(self.maskType.fall)
elseif self.vel.y < 0 then elseif self.vel.y < 0 then
self.body = self.body:ChangeTo(animation.nancy.jump) self.body = self.body:ChangeTo(animation.nancy.jump)
self.mask = self.mask:ChangeTo(self.maskType.jump) self.mask = self.mask:ChangeTo(self.maskType.jump)
@ -276,7 +287,9 @@ function Player:HandleAnimation()
-- special case: idle animation gets slower by time -- special case: idle animation gets slower by time
if self.body.anim_path == animation.nancy.idle.path then 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 if self.body.anim_speed < 0.5 then
self.body.anim_speed = self.body.anim_speed + 0.001
end
end end
if self.isHooked then if self.isHooked then
@ -288,8 +301,10 @@ function Player:HandleAnimation()
) )
end end
logPrint(tostring(self.body.anim_speed))
self.body:Animate() self.body:Animate()
self:Draw(self.body) self:Draw(self.body)
if self.dashCount > 0 then if self.dashCount > 0 then
self:Draw(self.mask) self:Draw(self.mask)
end end

View File

@ -254,4 +254,5 @@ require "code/entities/decoration"
require "code/entities/player" require "code/entities/player"
require "code/entities/fairy" require "code/entities/fairy"
require "code/entities/cursed_book" require "code/entities/cursed_book"
require "code/entities/hook_anchor"
require "code/entities/particle" require "code/entities/particle"

View File

@ -28,7 +28,6 @@ function ExportLevel(levelname, filename)
local rows = #LevelTiles local rows = #LevelTiles
for i = 1, #LevelTiles do for i = 1, #LevelTiles do
exportFile:write("\n { ") exportFile:write("\n { ")
logPrint(" - Row "..i.."/"..rows.." "..math.floor(100*((i-1)*100/rows))/100 .."%")
for j = 1, #LevelTiles[i] do for j = 1, #LevelTiles[i] do
if j ~= 1 then if j ~= 1 then
exportFile:write(", ") exportFile:write(", ")
@ -39,8 +38,8 @@ function ExportLevel(levelname, filename)
if i ~= #LevelTiles then if i ~= #LevelTiles then
exportFile:write(", ") exportFile:write(", ")
end end
logPrint(" - Row "..i.."/"..rows.." "..math.floor(100*((i-1)*100/rows))/100 .."%")
end end
logPrint(" - All rows 100%")
exportFile:write("\n },") exportFile:write("\n },")
logPrint("- objects") logPrint("- objects")

View File

@ -59,7 +59,8 @@ function love.load()
--Kupo:New(100,150) --Kupo:New(100,150)
--Kupo:New(300,150) --Kupo:New(300,150)
Decoration:New(200,89,animation.decoration.candelabra,80) HookAnchor:New(200,89)
HookAnchor:New(400,89)
Fairy:New(200,88) Fairy:New(200,88)
--CursedBook:New(180,68) --CursedBook:New(180,68)

View File

@ -16,6 +16,7 @@
( ) Gameplay design ( ) Gameplay design
( ) Level design ( ) Level design
( ) Mechanic design ( ) Mechanic design
(X) Swing hook
( ) Entity design ( ) Entity design
(~) FAIRY (~) FAIRY
(X) basic movement (X) basic movement