Shader for lighting, fairy line of view, tileset change, broke lights, sorry
This commit is contained in:
@@ -12,7 +12,7 @@ function Decoration:New(x,y,animation,lightRange)
|
||||
|
||||
if lightRange ~= nil then
|
||||
o.lightRange = lightRange
|
||||
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange,nil,60/6)
|
||||
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange)
|
||||
end
|
||||
|
||||
table.insert(LoadedEntities,o)
|
||||
|
||||
@@ -5,7 +5,7 @@ Fairy = Entity:New(x,y)
|
||||
|
||||
-- behaviour
|
||||
o.pos = {x = x, y = y}
|
||||
o.speed = 0.23
|
||||
o.speed = 1
|
||||
o.range = 20
|
||||
o.target = {x = x, y = y}
|
||||
|
||||
@@ -32,19 +32,22 @@ Fairy = Entity:New(x,y)
|
||||
|
||||
function Fairy: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 - 10
|
||||
if self:CheckVisionLine(main_Player) 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
|
||||
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)
|
||||
|
||||
if distance < self.range then
|
||||
self.vel.x = 0
|
||||
self.vel.y = 0
|
||||
else
|
||||
self.vel.x = math.cos(angle)*self.speed*distance/8
|
||||
self.vel.y = math.sin(angle)*self.speed*distance/8
|
||||
|
||||
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
|
||||
@@ -72,8 +75,8 @@ function Fairy:HandleAnimation()
|
||||
end
|
||||
|
||||
function Fairy:DoPhysics()
|
||||
local random_x = math.random(-4, 4)/100
|
||||
local random_y = math.random(-4, 4)/100
|
||||
local random_x = math.random(-2, 2)/10
|
||||
local random_y = math.random(-2, 2)/10
|
||||
self.vel.x = self.vel.x + random_x
|
||||
self.vel.y = self.vel.y + random_y
|
||||
-- move
|
||||
@@ -81,3 +84,8 @@ function Fairy:DoPhysics()
|
||||
self:CollisionMove()
|
||||
self:LightAdjust()
|
||||
end
|
||||
|
||||
function Fairy:Debug()
|
||||
Entity.Debug(self)
|
||||
self:CheckVisionLineDebug(main_Player)
|
||||
end
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
to = {x = 8, y = 0} -- gameworld pixels
|
||||
}
|
||||
|
||||
o.lightRange = 344 -- screen pixels
|
||||
o.lightRange = 0 -- screen pixels
|
||||
|
||||
-- status
|
||||
o.isDashing = false
|
||||
@@ -47,7 +47,7 @@
|
||||
o.maskType = animation.moth_mask
|
||||
|
||||
-- sprite
|
||||
o.target_offset = {x = 0, y = 12}
|
||||
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)
|
||||
|
||||
@@ -73,6 +73,31 @@ function Entity:Kill()
|
||||
self = nil
|
||||
end
|
||||
|
||||
function Entity:CheckVisionLine(entity)
|
||||
local target_x = entity.pos.x + entity.target_offset.x
|
||||
local target_y = entity.pos.y + entity.target_offset.y
|
||||
|
||||
local distance_x = target_x - self.pos.x
|
||||
local distance_y = target_y - self.pos.y
|
||||
|
||||
local angle = GetAngleFromVector(distance_x,distance_y)
|
||||
local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
|
||||
|
||||
local is_colliding = false
|
||||
|
||||
for i=1, distance, game.scale do
|
||||
if isThereObjectAt(
|
||||
self.pos.x+math.cos(angle)*i,
|
||||
self.pos.y+math.sin(angle)*i,
|
||||
LoadedObjects.Collisions
|
||||
) then
|
||||
is_colliding = true
|
||||
end
|
||||
end
|
||||
|
||||
return not is_colliding
|
||||
end
|
||||
|
||||
function Entity:Draw(animation)
|
||||
local c1, c2, c3, a = love.graphics.getColor()
|
||||
love.graphics.setColor(self.sprite_tint[1],self.sprite_tint[2],self.sprite_tint[3],self.sprite_alpha)
|
||||
@@ -138,6 +163,39 @@ function Entity:isCollidingAtAll(x,y)
|
||||
return result
|
||||
end
|
||||
|
||||
function Entity:CheckVisionLineDebug(entity)
|
||||
local c1, c2, c3, a = love.graphics.getColor()
|
||||
|
||||
local target_x = entity.pos.x + entity.target_offset.x
|
||||
local target_y = entity.pos.y + entity.target_offset.y
|
||||
|
||||
local distance_x = target_x - self.pos.x
|
||||
local distance_y = target_y - self.pos.y
|
||||
|
||||
local angle = GetAngleFromVector(distance_x,distance_y)
|
||||
local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
|
||||
|
||||
for i=1, distance, game.scale do
|
||||
if isThereObjectAt(
|
||||
self.pos.x+math.cos(angle)*i,
|
||||
self.pos.y+math.sin(angle)*i,
|
||||
LoadedObjects.Collisions
|
||||
) then
|
||||
love.graphics.setColor(1,0,0)
|
||||
else
|
||||
love.graphics.setColor(0,1,0)
|
||||
end
|
||||
love.graphics.line(
|
||||
self.pos.x+math.cos(angle)*i-1 - Camera.pos.x,
|
||||
self.pos.y+math.sin(angle)*i-1 - Camera.pos.y,
|
||||
self.pos.x+math.cos(angle)*i - Camera.pos.x,
|
||||
self.pos.y+math.sin(angle)*i - Camera.pos.y
|
||||
)
|
||||
end
|
||||
|
||||
love.graphics.setColor(c1,c2,c3,a)
|
||||
end
|
||||
|
||||
function Entity:Debug()
|
||||
-- draw center GREEN
|
||||
love.graphics.setColor(0,1,0)
|
||||
|
||||
@@ -14,7 +14,7 @@ function GameStep()
|
||||
for _, enty in pairs(LoadedEntities) do
|
||||
enty:DoPhysics()
|
||||
end
|
||||
|
||||
|
||||
AnimateTiles()
|
||||
Camera:positionCenterAt(main_Player.pos.x, main_Player.pos.y)
|
||||
--camera:positionAt(main_Player.pos.x, main_Player.pos.y,game.width,game.height)
|
||||
@@ -52,10 +52,10 @@ function GameDraw()
|
||||
GameworldDrawPrepare()
|
||||
GameworldDrawParticles()
|
||||
GameworldDrawBackground()
|
||||
GameworldDrawLighting()
|
||||
GameworldDrawEntities()
|
||||
GameworldDrawForeground()
|
||||
GameworldDrawEnd()
|
||||
GameworldDrawLighting()
|
||||
|
||||
-- hud
|
||||
textScale = 0.5
|
||||
|
||||
@@ -38,12 +38,18 @@ function KillLight(light)
|
||||
end
|
||||
|
||||
function SetDarkness()
|
||||
love.graphics.setCanvas(Canvas.Darkness)
|
||||
|
||||
love.graphics.setColor(0,0,0,1)
|
||||
love.graphics.rectangle("fill",0,0,game.width ,game.height)
|
||||
|
||||
love.graphics.setCanvas()
|
||||
end
|
||||
|
||||
function DoLights()
|
||||
|
||||
love.graphics.setCanvas(Canvas.Darkness)
|
||||
|
||||
for _, light in pairs(Lights) do
|
||||
light.flicker_time = light.flicker_time + 1
|
||||
|
||||
@@ -61,27 +67,53 @@ function DoLights()
|
||||
"fill",
|
||||
(light.pos.x - Camera.pos.x) / game.scale,
|
||||
(light.pos.y - Camera.pos.y) / game.scale,
|
||||
(light.range + light.flicker + 1) / game.scale
|
||||
(light.range + light.flicker + 0) / game.scale
|
||||
)
|
||||
end
|
||||
end
|
||||
love.graphics.setColor(0,0,0,0)
|
||||
|
||||
myShader:send("game_scale", game.scale)
|
||||
for _, light in pairs(Lights) do
|
||||
if light.range ~= 0 then
|
||||
local position = {
|
||||
x = (light.pos.x - Camera.pos.x) / game.scale,
|
||||
y = (light.pos.y - Camera.pos.y) / game.scale
|
||||
}
|
||||
local range = (light.range + light.flicker) / game.scale
|
||||
love.graphics.setBlendMode("replace")
|
||||
love.graphics.setColor(0,0,0,0)
|
||||
love.graphics.setShader()
|
||||
love.graphics.circle(
|
||||
"fill",
|
||||
(light.pos.x - Camera.pos.x) / game.scale,
|
||||
(light.pos.y - Camera.pos.y) / game.scale,
|
||||
(light.range + light.flicker) / game.scale
|
||||
position.x,
|
||||
position.y,
|
||||
range
|
||||
)
|
||||
love.graphics.setBlendMode("alpha")
|
||||
love.graphics.setColor(1,1,1)
|
||||
myShader:send("light_color", light.color)
|
||||
myShader:send("light_pos", {position.x*game.scale, position.y*game.scale})
|
||||
myShader:send("range", range)
|
||||
love.graphics.setShader(myShader)
|
||||
love.graphics.circle(
|
||||
"fill",
|
||||
position.x,
|
||||
position.y,
|
||||
range
|
||||
)
|
||||
love.graphics.setShader()
|
||||
end
|
||||
end
|
||||
love.graphics.setBlendMode("alpha")
|
||||
|
||||
love.graphics.setCanvas()
|
||||
|
||||
end
|
||||
|
||||
function DoBorder()
|
||||
love.graphics.setCanvas(Canvas.Darkness)
|
||||
love.graphics.setCanvas()
|
||||
end
|
||||
|
||||
function DrawDarkness()
|
||||
love.graphics.draw(Canvas.Darkness, 0, 0, 0, 2/game.scale)
|
||||
love.graphics.draw(Canvas.Darkness, 0, 0, 0, game.scale)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user