editor progress, generic keybinds, player coyote value, cursed book entity, level changes, camera adjustments
This commit is contained in:
118
data/scripts/entities/cursed_book.lua
Normal file
118
data/scripts/entities/cursed_book.lua
Normal file
@@ -0,0 +1,118 @@
|
||||
CursedBook = Entity:New(x,y)
|
||||
|
||||
function CursedBook:New(x,y)
|
||||
local o = Entity:New(x,y)
|
||||
|
||||
-- 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(LoadedEntities,o)
|
||||
o.id = #LoadedEntities
|
||||
|
||||
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
|
||||
@@ -3,6 +3,7 @@ Fairy = Entity:New(x,y)
|
||||
function Fairy:New(x,y)
|
||||
local o = Entity:New(x,y)
|
||||
|
||||
-- behaviour
|
||||
o.pos = {x = x, y = y}
|
||||
o.speed = 0.23
|
||||
o.range = 20
|
||||
@@ -13,9 +14,13 @@ Fairy = Entity:New(x,y)
|
||||
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"))
|
||||
|
||||
o.lightRange = 0
|
||||
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange)
|
||||
-- timer
|
||||
o.particle_timer = 0
|
||||
o.particle_time = 5
|
||||
|
||||
table.insert(LoadedEntities,o)
|
||||
o.id = #LoadedEntities
|
||||
@@ -26,8 +31,6 @@ Fairy = Entity:New(x,y)
|
||||
end
|
||||
|
||||
function Fairy: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 - 10
|
||||
@@ -39,18 +42,27 @@ function Fairy:Smart()
|
||||
self.vel.x = 0
|
||||
self.vel.y = 0
|
||||
else
|
||||
self.vel.x = math.cos(angle)*self.speed*distance/(8*game.scale)
|
||||
self.vel.y = math.sin(angle)*self.speed*distance/(8*game.scale)
|
||||
self.vel.x = math.cos(angle)*self.speed*distance/8
|
||||
self.vel.y = math.sin(angle)*self.speed*distance/8
|
||||
|
||||
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.fairy,
|
||||
direction = angle-math.rad(180),
|
||||
speed = self.speed*distance/(16*game.scale),
|
||||
light = 85
|
||||
}
|
||||
|
||||
Particle:New(self.pos.x,self.pos.y,particle_data)
|
||||
local particle_data = {
|
||||
animation = animation.particle.simple,
|
||||
sprite_tint = HEX2RGB("#fe00d1"),
|
||||
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()
|
||||
@@ -60,11 +72,12 @@ function Fairy:HandleAnimation()
|
||||
end
|
||||
|
||||
function Fairy:DoPhysics()
|
||||
|
||||
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
|
||||
-- move
|
||||
|
||||
self:CollisionMove()
|
||||
self:LightAdjust()
|
||||
end
|
||||
|
||||
@@ -26,16 +26,23 @@ Particle = Entity:New(x,y)
|
||||
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
|
||||
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange)
|
||||
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
|
||||
o.body = Animation:New(particle_data.animation)
|
||||
o:centerOffset(o.body)
|
||||
if not o.animation_active then
|
||||
o.body.speed = 0
|
||||
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)
|
||||
@@ -62,16 +69,32 @@ function Particle:Kill()
|
||||
end
|
||||
|
||||
function Particle:HandleAnimation()
|
||||
self.body:Animate()
|
||||
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
|
||||
self:Draw(self.body)
|
||||
if self.body ~= nil then
|
||||
self.body:Animate()
|
||||
self:Draw(self.body)
|
||||
end
|
||||
end
|
||||
|
||||
function Particle:DoPhysics()
|
||||
self:Move()
|
||||
-- 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
|
||||
|
||||
@@ -7,37 +7,40 @@
|
||||
Player.coins = 0
|
||||
|
||||
-- physics
|
||||
o.moveSpeed = 1.3
|
||||
o.zeroSpeed = 0.01
|
||||
o.move_x = 0
|
||||
o.moveSpeed = 1.3 -- gameworld pixels
|
||||
o.zeroSpeed = 0.01 -- gameworld pixels
|
||||
o.move_x = 0 -- gameworld pixels
|
||||
|
||||
o.airFriction = 0.01
|
||||
o.groundFriction = 0.3
|
||||
o.airFriction = 0.01 -- gameworld pixels
|
||||
o.groundFriction = 0.3 -- gameworld pixels
|
||||
|
||||
o.jumpImpulse = 3.5
|
||||
o.jumpImpulse = 3.5 -- gameworld pixels
|
||||
|
||||
o.dashCooldownTime = 0.1
|
||||
o.dashCooldownTimer = 0
|
||||
o.coyoteAmount = 5 -- int
|
||||
o.coyoteValue = 5 -- frames
|
||||
|
||||
o.dashTimer = 0
|
||||
o.dashTime = 0.15
|
||||
o.dashDistance = 40
|
||||
o.dashSpeed = o.dashDistance / (o.dashTime*60)
|
||||
o.dashCount = 1
|
||||
o.dashCooldownTime = 0.1 -- seconds
|
||||
o.dashCooldownTimer = 0 -- seconds
|
||||
|
||||
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 = 0 -- int
|
||||
|
||||
o.boxCollision = {
|
||||
from = {x = -8, y = -16},
|
||||
to = {x = 8, y = 0}
|
||||
from = {x = -8, y = -16}, --gameworld pixels
|
||||
to = {x = 8, y = 0} -- gameworld pixels
|
||||
}
|
||||
|
||||
o.lightRange = 0--32
|
||||
o.lightRange = 344 -- screen pixels
|
||||
|
||||
-- status
|
||||
o.isDashing = false
|
||||
o.isJumping = false
|
||||
o.isOnGround = 0
|
||||
o.coyoteValue = 5
|
||||
o.isOnLadder = false
|
||||
o.isOnGround = true
|
||||
o.isOnLadder = false
|
||||
o.canJump = true
|
||||
o.canFall = true
|
||||
o.canFriction = true
|
||||
@@ -48,7 +51,7 @@
|
||||
o.body = Animation:New(animation.nancy.idle)
|
||||
o.mask = Animation:New(animation.moth_mask.idle)
|
||||
o:centerOffset(o.body)
|
||||
o:getBoundingBox(o.body, 3,-3,0,-1)
|
||||
o:getBoundingBox(o.body,0,3,-1,-3)
|
||||
|
||||
-- lights
|
||||
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange)
|
||||
@@ -85,12 +88,19 @@ function Player:Smart()
|
||||
self.vel.x = self.vel.x
|
||||
|
||||
if Keybind:CheckDown(Keybind.move.jump) then
|
||||
if self.isOnGround then
|
||||
if self.coyoteValue > 0 then
|
||||
self.vel.y = -self.jumpImpulse
|
||||
self.coyoteValue = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if self.isOnGround then
|
||||
self.coyoteValue = self.coyoteAmount
|
||||
elseif self.coyoteValue > 0 then
|
||||
self.coyoteValue = self.coyoteValue - 1
|
||||
end
|
||||
|
||||
self.dashCooldownTimer = math.max(0,self.dashCooldownTimer - current_dt)
|
||||
if Keybind:CheckDown(Keybind.move.dash) then
|
||||
if self.dashCooldownTimer == 0
|
||||
@@ -118,14 +128,14 @@ function Player:Smart()
|
||||
end
|
||||
|
||||
function Player:DoPhysics()
|
||||
|
||||
-- reset state
|
||||
self.isOnGround = false
|
||||
|
||||
-- adjust timers
|
||||
self.dashTimer = self.dashTimer - current_dt
|
||||
|
||||
-- DASH STATE
|
||||
if self.dashTimer > 0 then
|
||||
|
||||
-- dash particle
|
||||
local particle_data = {
|
||||
animation = self.body,
|
||||
sprite_tint = HEX2RGB("#fed100"),
|
||||
@@ -137,9 +147,11 @@ function Player:DoPhysics()
|
||||
}
|
||||
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)
|
||||
else
|
||||
-- not in dash; fall normally
|
||||
self.dashTimer = 0
|
||||
self.vel.y = self.vel.y + gravity
|
||||
end
|
||||
@@ -155,7 +167,7 @@ function Player:DoPhysics()
|
||||
else
|
||||
if self.vel.y > 0 then
|
||||
self.isOnGround = true
|
||||
self.dashCount = 1
|
||||
self.dashCount = self.dashAmount
|
||||
self.vel.y = 0
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user