function to improve entities moving on collisions and fixed accordingly
made math.round() changed vector() and fixed accordingly
This commit is contained in:
@@ -36,20 +36,30 @@ function Arrow:drawBackground()
|
||||
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
|
||||
-- horizontal collision
|
||||
self:moveX(
|
||||
self.vel.x,
|
||||
function()
|
||||
self.stuck = true
|
||||
end
|
||||
)
|
||||
|
||||
if not self.stuck then
|
||||
-- vertical collision
|
||||
self:moveY(
|
||||
self.vel.y,
|
||||
function()
|
||||
self.stuck = true
|
||||
end
|
||||
)
|
||||
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
|
||||
|
||||
self:adjustLight()
|
||||
end
|
||||
|
||||
@@ -67,6 +67,13 @@ function CursedBook:doLogic()
|
||||
elseif self.status == 4 then
|
||||
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
function CursedBook:handleAnimation()
|
||||
@@ -101,15 +108,21 @@ function CursedBook:handleAnimation()
|
||||
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:moveWithCollision()
|
||||
-- horizontal collision
|
||||
self:moveX(
|
||||
self.vel.x,
|
||||
function()
|
||||
self.vel.x = 0
|
||||
end
|
||||
)
|
||||
-- vertical collision
|
||||
self:moveY(
|
||||
self.vel.y,
|
||||
function()
|
||||
self.vel.y = 0
|
||||
end
|
||||
)
|
||||
-- final position
|
||||
self:adjustLight()
|
||||
end
|
||||
|
||||
|
||||
@@ -34,7 +34,6 @@ function Fairy:new(x,y)
|
||||
end
|
||||
|
||||
function Fairy:doLogic()
|
||||
|
||||
if self:checkVisionLine(main_player,self.vision_range) then
|
||||
|
||||
self.target.x = main_player.pos.x + main_player.target_offset.x
|
||||
@@ -63,31 +62,19 @@ function Fairy:doLogic()
|
||||
|
||||
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 angle = getAngleFromVector(vector(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
|
||||
local random_x = math.random(-1, 1)
|
||||
local random_y = math.random(-1, 1)
|
||||
self.vel.x = self.vel.x * 0.9 + random_x/10
|
||||
self.vel.y = self.vel.y * 0.9 + random_y/10
|
||||
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,
|
||||
animation_speed = 1,
|
||||
sprite_tint = hex2rgb("#fed100"),
|
||||
sprite_alpha_fade = true,
|
||||
direction = angle-math.rad(180+math.random(60)-30),
|
||||
speed = 0.8*(distance/50),
|
||||
speed_increase = -0.01,
|
||||
time = 0.75
|
||||
}
|
||||
Particle:new(self.pos.x,self.pos.y,particle_data)
|
||||
local random_x = math.random(-6, 6)
|
||||
local random_y = math.random(-6, 6)
|
||||
self.vel.x = math.cos(angle)*self.speed + random_x/10
|
||||
self.vel.y = math.sin(angle)*self.speed + random_y/10
|
||||
end
|
||||
end
|
||||
|
||||
@@ -95,19 +82,42 @@ 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.particle_timer = self.particle_timer + 1
|
||||
if self.particle_timer >= self.particle_time then
|
||||
local vector = vector(self.vel.x,self.vel.y)
|
||||
local angle = getAngleFromVector(vector)
|
||||
self.particle_timer = 0
|
||||
local particle_data = {
|
||||
animation = animation.particle.simple,
|
||||
animation_speed = 1,
|
||||
sprite_tint = hex2rgb("#fed100"),
|
||||
sprite_alpha_fade = true,
|
||||
direction = angle-math.rad(180+math.random(60)-30),
|
||||
speed = 1,
|
||||
speed_increase = -0.01,
|
||||
time = 0.75
|
||||
}
|
||||
Particle:new(self.pos.x,self.pos.y,particle_data)
|
||||
end
|
||||
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:moveWithCollision()
|
||||
self.vel.x = 0
|
||||
self.vel.y = 0
|
||||
|
||||
-- horizontal collision
|
||||
self:moveX(
|
||||
self.vel.x,
|
||||
function()
|
||||
self.vel.x = 0
|
||||
end
|
||||
)
|
||||
-- vertical collision
|
||||
self:moveY(
|
||||
self.vel.y,
|
||||
function()
|
||||
self.vel.y = 0
|
||||
end
|
||||
)
|
||||
-- final position
|
||||
self:adjustLight()
|
||||
end
|
||||
|
||||
|
||||
@@ -36,10 +36,6 @@ function HookAnchor:drawBackground()
|
||||
)
|
||||
end
|
||||
|
||||
function HookAnchor:doPhysics()
|
||||
end
|
||||
|
||||
|
||||
function Fairy:debug()
|
||||
Entity.debug(self)
|
||||
end
|
||||
|
||||
@@ -44,8 +44,9 @@ function Kupo:doLogic()
|
||||
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)
|
||||
local angle = getAngleFromVector(vector(distance_x,distance_y))
|
||||
self.draw_bow = false
|
||||
if distance <= self.range then
|
||||
if self.hostile == true then
|
||||
@@ -153,7 +154,3 @@ function Kupo:handleAnimation()
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
function Kupo:doPhysics()
|
||||
self:moveWithCollision()
|
||||
end
|
||||
|
||||
@@ -89,26 +89,32 @@ function Particle:handleAnimation()
|
||||
end
|
||||
end
|
||||
|
||||
function Particle:doPhysics()
|
||||
function Particle:doLogic()
|
||||
-- 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:moveWithCollision()
|
||||
|
||||
if self.light ~= nil then
|
||||
self:adjustLight()
|
||||
self.light.range = self.light_range * self.sprite_alpha/2
|
||||
end
|
||||
|
||||
if self.time ~= nil then
|
||||
if self.timer >= self.time then self:kill() end
|
||||
end
|
||||
end
|
||||
|
||||
function Particle:doPhysics()
|
||||
-- horizontal collision
|
||||
self:moveX(
|
||||
self.vel.x
|
||||
)
|
||||
-- vertical collision
|
||||
self:moveY(
|
||||
self.vel.y
|
||||
)
|
||||
-- final position
|
||||
self:adjustLight()
|
||||
end
|
||||
|
||||
function Particle:debug()
|
||||
-- draw center CYAN
|
||||
love.graphics.setColor(0,1,1)
|
||||
|
||||
@@ -155,7 +155,7 @@ function Player:doLogic()
|
||||
end
|
||||
|
||||
-- set dash values
|
||||
self.dashDirection = getAngleFromVector(horizontal, vertical)
|
||||
self.dashDirection = getAngleFromVector(vector(horizontal, vertical))
|
||||
self.dash_timer = math.floor(self.dash_time * game.framerate)
|
||||
end
|
||||
else
|
||||
@@ -232,10 +232,10 @@ function Player:doPhysics()
|
||||
-- hook state
|
||||
if self.is_hooked then
|
||||
self.move_x = 0
|
||||
local hook = vector(self.pos.x, self.pos.y, self.hook_anchor.x, self.hook_anchor.y)
|
||||
local hook = vector(self.hook_anchor.x - self.pos.x, self.hook_anchor.y - self.pos.y)
|
||||
local dist = math.min(getVectorValue(hook), self.hook_distance)
|
||||
|
||||
local hook_angle = getAngleFromVector(hook[1],hook[2])-math.rad(180)
|
||||
local hook_angle = getAngleFromVector(hook)-math.rad(180)
|
||||
|
||||
if Keybind:checkDown(Keybind.move.right) then
|
||||
hook_angle = hook_angle - self.hook_swing_speed
|
||||
@@ -264,8 +264,13 @@ function Player:doPhysics()
|
||||
local pos_y = self.hook_anchor.y + dist * 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
|
||||
|
||||
self:moveX(
|
||||
pos_x - self.pos.x
|
||||
)
|
||||
self:moveY(
|
||||
pos_y - self.pos.y
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
@@ -276,24 +281,26 @@ function Player:doPhysics()
|
||||
end
|
||||
|
||||
-- horizontal collision
|
||||
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
|
||||
self.wall_hit = 0
|
||||
else
|
||||
self.wall_hit = math.sign(self.vel.x)
|
||||
self.vel.x = 0
|
||||
end
|
||||
self.wall_hit = 0
|
||||
self:moveX(
|
||||
self.vel.x,
|
||||
function()
|
||||
self.wall_hit = math.sign(self.vel.x)
|
||||
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.is_on_ground = true
|
||||
self.dash_count = self.dash_amount
|
||||
self:moveY(
|
||||
self.vel.y,
|
||||
function()
|
||||
if self.vel.y > 0 then
|
||||
self.is_on_ground = true
|
||||
self.dash_count = self.dash_amount
|
||||
end
|
||||
self.vel.y = 0
|
||||
end
|
||||
self.vel.y = 0
|
||||
end
|
||||
)
|
||||
|
||||
-- if u collision w hazard, respawn
|
||||
if self:isCollidingAt(self.pos.x, self.pos.y, LoadedObjects.Hazards) then
|
||||
|
||||
Reference in New Issue
Block a user