diff --git a/code/entities/fairy.lua b/code/entities/fairy.lua index 0a7a17d..8bf2221 100644 --- a/code/entities/fairy.lua +++ b/code/entities/fairy.lua @@ -68,8 +68,8 @@ function Fairy:Smart() local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2) if distance < self.range then - self.vel.x = 0 - self.vel.y = 0 + 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 diff --git a/code/entities/hook_anchor.lua b/code/entities/hook_anchor.lua new file mode 100644 index 0000000..549d993 --- /dev/null +++ b/code/entities/hook_anchor.lua @@ -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 diff --git a/code/entities/player.lua b/code/entities/player.lua index c09c9e3..ceeb44a 100644 --- a/code/entities/player.lua +++ b/code/entities/player.lua @@ -30,8 +30,6 @@ o.dashAmount = 10 -- int -- hook values - o.hookDistance = 80 - o.hookedDistance = 80 o.hookAnchor = { x = nil, y = nil @@ -145,9 +143,10 @@ function Player:Smart() if self.isHooked then self:Unhook() else - local anchor = self:CheckNearest("decoration",self.hookDistance) + 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 @@ -196,7 +195,7 @@ function Player:DoPhysics() -- 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 + if GetVectorValue(hook) > self.hookDistance then local particle_data = { animation = self.body, sprite_tint = HEX2RGB("#fed100"), @@ -208,10 +207,16 @@ function Player:DoPhysics() } Particle:New(self.pos.x,self.pos.y,particle_data) 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.left) then hook_angle = hook_angle + math.rad(0.05) end - local pos_x = self.hookAnchor.x + self.hookedDistance * math.cos(hook_angle) - local pos_y = self.hookAnchor.y + self.hookedDistance * math.sin(hook_angle) + 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 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 @@ -257,12 +262,18 @@ 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 + 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 - self.body = self.body:ChangeTo(animation.nancy.fall) - if self.vel.y > 1.25 then - self.mask = self.mask:ChangeTo(self.maskType.fall) + 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) @@ -276,7 +287,9 @@ function Player:HandleAnimation() -- 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 + if self.body.anim_speed < 0.5 then + self.body.anim_speed = self.body.anim_speed + 0.001 + end end if self.isHooked then @@ -288,8 +301,10 @@ function Player:HandleAnimation() ) end + logPrint(tostring(self.body.anim_speed)) self.body:Animate() self:Draw(self.body) + if self.dashCount > 0 then self:Draw(self.mask) end diff --git a/code/entity.lua b/code/entity.lua index c94aa99..802c01f 100644 --- a/code/entity.lua +++ b/code/entity.lua @@ -254,4 +254,5 @@ require "code/entities/decoration" require "code/entities/player" require "code/entities/fairy" require "code/entities/cursed_book" +require "code/entities/hook_anchor" require "code/entities/particle" diff --git a/code/in_out.lua b/code/in_out.lua index 8ede03a..06438ce 100644 --- a/code/in_out.lua +++ b/code/in_out.lua @@ -28,7 +28,6 @@ function ExportLevel(levelname, filename) local rows = #LevelTiles for i = 1, #LevelTiles do exportFile:write("\n { ") - logPrint(" - Row "..i.."/"..rows.." "..math.floor(100*((i-1)*100/rows))/100 .."%") for j = 1, #LevelTiles[i] do if j ~= 1 then exportFile:write(", ") @@ -39,8 +38,8 @@ function ExportLevel(levelname, filename) if i ~= #LevelTiles then exportFile:write(", ") end + logPrint(" - Row "..i.."/"..rows.." "..math.floor(100*((i-1)*100/rows))/100 .."%") end - logPrint(" - All rows 100%") exportFile:write("\n },") logPrint("- objects") diff --git a/main.lua b/main.lua index 8cc5d8c..2967580 100644 --- a/main.lua +++ b/main.lua @@ -59,7 +59,8 @@ function love.load() --Kupo:New(100,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) --CursedBook:New(180,68) diff --git a/unused slash dev/to_do.txt b/unused slash dev/to_do.txt index f0bf280..5efdc04 100644 --- a/unused slash dev/to_do.txt +++ b/unused slash dev/to_do.txt @@ -16,6 +16,7 @@ ( ) Gameplay design ( ) Level design ( ) Mechanic design + (X) Swing hook ( ) Entity design (~) FAIRY (X) basic movement