Shader for lighting, fairy line of view, tileset change, broke lights, sorry

This commit is contained in:
lustlion 2022-02-05 12:32:47 +01:00
parent 15f5ef8454
commit cbf29ced65
13 changed files with 176 additions and 31 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

View File

@ -1,7 +1,7 @@
DialogSequence = {
Example = {
{Locale.dialogue.example[1],Locale.name.fairy},
{Locale.dialogue.example[2],Locale.name.chaos},
{Locale.dialogue.example[3],Locale.name.life}
}
DialogSequence = {}
DialogSequence.Example = {
{Locale.dialogue.example[1],Locale.name.fairy},
{Locale.dialogue.example[2],Locale.name.chaos},
{Locale.dialogue.example[3],Locale.name.life}
}

View File

@ -5,9 +5,9 @@ return {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2},
{ 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37},
{ 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37},
{ 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37},
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
},
objects = {}

View File

@ -1,5 +1,6 @@
-- data
require "data/enums"
require "data/shaders"
require "data/scripts/locale"
-- support functions
require "data/scripts/math"

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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

31
data/shaders.lua Normal file
View File

@ -0,0 +1,31 @@
myShader = love.graphics.newShader[[
uniform vec2 light_pos;
uniform vec3 light_color;
uniform float range;
uniform float game_scale;
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords ){
vec4 pixel = Texel(texture, texture_coords );//This is the current pixel color
float distance_x = light_pos.x - screen_coords.x;
float distance_y = light_pos.y - screen_coords.y;
float distance = 1-sqrt( pow(distance_x,2) + pow(distance_y,2) ) / game_scale;
if (distance < range){
float alpha = (distance/range);
if (pixel.a > alpha){
pixel.a = alpha;
}
if (color.r<light_color.r){
color.r = light_color.r;
}
if (color.g<light_color.g){
color.g = light_color.g;
}
if (color.b<light_color.b){
color.b = light_color.b;
}
}
return pixel * color;
}
]]

View File

@ -10,6 +10,16 @@ properties[2] = {
depth = "foreground"
}
properties[3] = {
type = "emtpy",
depth = "foreground"
}
properties[4] = {
type = "emtpy",
depth = "foreground"
}
properties[5] = {
type = "emtpy",
depth = "background"
@ -30,6 +40,11 @@ properties[13] = {
depth = "foreground"
}
properties[14] = {
type = "whole",
depth = "foreground"
}
properties[25] = {
overlay = {17,19,21,23},
type = "emtpy",

View File

@ -50,8 +50,8 @@ function love.load()
--Kupo:New(100,150)
--Kupo:New(300,150)
--Decoration:New(200,89,animation.decoration.candelabra,80)
--Fairy:New(200,88)
Decoration:New(200,89,animation.decoration.candelabra,80)
Fairy:New(200,88)
--CursedBook:New(180,68)
gravity = 0.2