Shader for lighting, fairy line of view, tileset change, broke lights, sorry
This commit is contained in:
parent
15f5ef8454
commit
cbf29ced65
Binary file not shown.
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.1 KiB |
|
@ -1,7 +1,7 @@
|
||||||
DialogSequence = {
|
DialogSequence = {}
|
||||||
Example = {
|
|
||||||
{Locale.dialogue.example[1],Locale.name.fairy},
|
DialogSequence.Example = {
|
||||||
{Locale.dialogue.example[2],Locale.name.chaos},
|
{Locale.dialogue.example[1],Locale.name.fairy},
|
||||||
{Locale.dialogue.example[3],Locale.name.life}
|
{Locale.dialogue.example[2],Locale.name.chaos},
|
||||||
}
|
{Locale.dialogue.example[3],Locale.name.life}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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},
|
{ 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},
|
{ 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37},
|
||||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
{ 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37},
|
||||||
{ 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},
|
||||||
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
|
{ 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 = {}
|
objects = {}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
-- data
|
-- data
|
||||||
require "data/enums"
|
require "data/enums"
|
||||||
|
require "data/shaders"
|
||||||
require "data/scripts/locale"
|
require "data/scripts/locale"
|
||||||
-- support functions
|
-- support functions
|
||||||
require "data/scripts/math"
|
require "data/scripts/math"
|
||||||
|
|
|
@ -12,7 +12,7 @@ function Decoration:New(x,y,animation,lightRange)
|
||||||
|
|
||||||
if lightRange ~= nil then
|
if lightRange ~= nil then
|
||||||
o.lightRange = lightRange
|
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
|
end
|
||||||
|
|
||||||
table.insert(LoadedEntities,o)
|
table.insert(LoadedEntities,o)
|
||||||
|
|
|
@ -5,7 +5,7 @@ Fairy = Entity:New(x,y)
|
||||||
|
|
||||||
-- behaviour
|
-- behaviour
|
||||||
o.pos = {x = x, y = y}
|
o.pos = {x = x, y = y}
|
||||||
o.speed = 0.23
|
o.speed = 1
|
||||||
o.range = 20
|
o.range = 20
|
||||||
o.target = {x = x, y = y}
|
o.target = {x = x, y = y}
|
||||||
|
|
||||||
|
@ -32,19 +32,22 @@ Fairy = Entity:New(x,y)
|
||||||
|
|
||||||
function Fairy:Smart()
|
function Fairy:Smart()
|
||||||
|
|
||||||
self.target.x = main_Player.pos.x - main_Player.target_offset.x
|
if self:CheckVisionLine(main_Player) then
|
||||||
self.target.y = main_Player.pos.y - main_Player.target_offset.y - 10
|
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_x = self.target.x - self.pos.x
|
||||||
local distance_y = self.target.y - self.pos.y
|
local distance_y = self.target.y - self.pos.y
|
||||||
local angle = GetAngleFromVector(distance_x,distance_y)
|
local angle = GetAngleFromVector(distance_x,distance_y)
|
||||||
local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
|
local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
|
||||||
|
|
||||||
if distance < self.range then
|
if distance < self.range then
|
||||||
self.vel.x = 0
|
self.vel.x = 0
|
||||||
self.vel.y = 0
|
self.vel.y = 0
|
||||||
else
|
else
|
||||||
self.vel.x = math.cos(angle)*self.speed*distance/8
|
self.vel.x = math.cos(angle)*self.speed
|
||||||
self.vel.y = math.sin(angle)*self.speed*distance/8
|
self.vel.y = math.sin(angle)*self.speed
|
||||||
|
|
||||||
end
|
end
|
||||||
self.particle_timer = self.particle_timer + 1
|
self.particle_timer = self.particle_timer + 1
|
||||||
if self.particle_timer >= self.particle_time then
|
if self.particle_timer >= self.particle_time then
|
||||||
|
@ -72,8 +75,8 @@ function Fairy:HandleAnimation()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Fairy:DoPhysics()
|
function Fairy:DoPhysics()
|
||||||
local random_x = math.random(-4, 4)/100
|
local random_x = math.random(-2, 2)/10
|
||||||
local random_y = math.random(-4, 4)/100
|
local random_y = math.random(-2, 2)/10
|
||||||
self.vel.x = self.vel.x + random_x
|
self.vel.x = self.vel.x + random_x
|
||||||
self.vel.y = self.vel.y + random_y
|
self.vel.y = self.vel.y + random_y
|
||||||
-- move
|
-- move
|
||||||
|
@ -81,3 +84,8 @@ function Fairy:DoPhysics()
|
||||||
self:CollisionMove()
|
self:CollisionMove()
|
||||||
self:LightAdjust()
|
self:LightAdjust()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Fairy:Debug()
|
||||||
|
Entity.Debug(self)
|
||||||
|
self:CheckVisionLineDebug(main_Player)
|
||||||
|
end
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
to = {x = 8, y = 0} -- gameworld pixels
|
to = {x = 8, y = 0} -- gameworld pixels
|
||||||
}
|
}
|
||||||
|
|
||||||
o.lightRange = 344 -- screen pixels
|
o.lightRange = 0 -- screen pixels
|
||||||
|
|
||||||
-- status
|
-- status
|
||||||
o.isDashing = false
|
o.isDashing = false
|
||||||
|
@ -47,7 +47,7 @@
|
||||||
o.maskType = animation.moth_mask
|
o.maskType = animation.moth_mask
|
||||||
|
|
||||||
-- sprite
|
-- sprite
|
||||||
o.target_offset = {x = 0, y = 12}
|
o.target_offset = {x = 0, y = 0}
|
||||||
o.body = Animation:New(animation.nancy.idle)
|
o.body = Animation:New(animation.nancy.idle)
|
||||||
o.mask = Animation:New(animation.moth_mask.idle)
|
o.mask = Animation:New(animation.moth_mask.idle)
|
||||||
o:centerOffset(o.body)
|
o:centerOffset(o.body)
|
||||||
|
|
|
@ -73,6 +73,31 @@ function Entity:Kill()
|
||||||
self = nil
|
self = nil
|
||||||
end
|
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)
|
function Entity:Draw(animation)
|
||||||
local c1, c2, c3, a = love.graphics.getColor()
|
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)
|
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
|
return result
|
||||||
end
|
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()
|
function Entity:Debug()
|
||||||
-- draw center GREEN
|
-- draw center GREEN
|
||||||
love.graphics.setColor(0,1,0)
|
love.graphics.setColor(0,1,0)
|
||||||
|
|
|
@ -14,7 +14,7 @@ function GameStep()
|
||||||
for _, enty in pairs(LoadedEntities) do
|
for _, enty in pairs(LoadedEntities) do
|
||||||
enty:DoPhysics()
|
enty:DoPhysics()
|
||||||
end
|
end
|
||||||
|
|
||||||
AnimateTiles()
|
AnimateTiles()
|
||||||
Camera:positionCenterAt(main_Player.pos.x, main_Player.pos.y)
|
Camera:positionCenterAt(main_Player.pos.x, main_Player.pos.y)
|
||||||
--camera:positionAt(main_Player.pos.x, main_Player.pos.y,game.width,game.height)
|
--camera:positionAt(main_Player.pos.x, main_Player.pos.y,game.width,game.height)
|
||||||
|
@ -52,10 +52,10 @@ function GameDraw()
|
||||||
GameworldDrawPrepare()
|
GameworldDrawPrepare()
|
||||||
GameworldDrawParticles()
|
GameworldDrawParticles()
|
||||||
GameworldDrawBackground()
|
GameworldDrawBackground()
|
||||||
|
GameworldDrawLighting()
|
||||||
GameworldDrawEntities()
|
GameworldDrawEntities()
|
||||||
GameworldDrawForeground()
|
GameworldDrawForeground()
|
||||||
GameworldDrawEnd()
|
GameworldDrawEnd()
|
||||||
GameworldDrawLighting()
|
|
||||||
|
|
||||||
-- hud
|
-- hud
|
||||||
textScale = 0.5
|
textScale = 0.5
|
||||||
|
|
|
@ -38,12 +38,18 @@ function KillLight(light)
|
||||||
end
|
end
|
||||||
|
|
||||||
function SetDarkness()
|
function SetDarkness()
|
||||||
|
love.graphics.setCanvas(Canvas.Darkness)
|
||||||
|
|
||||||
love.graphics.setColor(0,0,0,1)
|
love.graphics.setColor(0,0,0,1)
|
||||||
love.graphics.rectangle("fill",0,0,game.width ,game.height)
|
love.graphics.rectangle("fill",0,0,game.width ,game.height)
|
||||||
|
|
||||||
|
love.graphics.setCanvas()
|
||||||
end
|
end
|
||||||
|
|
||||||
function DoLights()
|
function DoLights()
|
||||||
|
|
||||||
|
love.graphics.setCanvas(Canvas.Darkness)
|
||||||
|
|
||||||
for _, light in pairs(Lights) do
|
for _, light in pairs(Lights) do
|
||||||
light.flicker_time = light.flicker_time + 1
|
light.flicker_time = light.flicker_time + 1
|
||||||
|
|
||||||
|
@ -61,27 +67,53 @@ function DoLights()
|
||||||
"fill",
|
"fill",
|
||||||
(light.pos.x - Camera.pos.x) / game.scale,
|
(light.pos.x - Camera.pos.x) / game.scale,
|
||||||
(light.pos.y - Camera.pos.y) / 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
|
||||||
end
|
end
|
||||||
love.graphics.setColor(0,0,0,0)
|
|
||||||
|
myShader:send("game_scale", game.scale)
|
||||||
for _, light in pairs(Lights) do
|
for _, light in pairs(Lights) do
|
||||||
if light.range ~= 0 then
|
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(
|
love.graphics.circle(
|
||||||
"fill",
|
"fill",
|
||||||
(light.pos.x - Camera.pos.x) / game.scale,
|
position.x,
|
||||||
(light.pos.y - Camera.pos.y) / game.scale,
|
position.y,
|
||||||
(light.range + light.flicker) / game.scale
|
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
|
||||||
end
|
end
|
||||||
love.graphics.setBlendMode("alpha")
|
|
||||||
|
love.graphics.setCanvas()
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function DoBorder()
|
function DoBorder()
|
||||||
|
love.graphics.setCanvas(Canvas.Darkness)
|
||||||
|
love.graphics.setCanvas()
|
||||||
end
|
end
|
||||||
|
|
||||||
function DrawDarkness()
|
function DrawDarkness()
|
||||||
love.graphics.draw(Canvas.Darkness, 0, 0, 0, 2/game.scale)
|
love.graphics.draw(Canvas.Darkness, 0, 0, 0, game.scale)
|
||||||
end
|
end
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
]]
|
|
@ -10,6 +10,16 @@ properties[2] = {
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
properties[3] = {
|
||||||
|
type = "emtpy",
|
||||||
|
depth = "foreground"
|
||||||
|
}
|
||||||
|
|
||||||
|
properties[4] = {
|
||||||
|
type = "emtpy",
|
||||||
|
depth = "foreground"
|
||||||
|
}
|
||||||
|
|
||||||
properties[5] = {
|
properties[5] = {
|
||||||
type = "emtpy",
|
type = "emtpy",
|
||||||
depth = "background"
|
depth = "background"
|
||||||
|
@ -30,6 +40,11 @@ properties[13] = {
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
properties[14] = {
|
||||||
|
type = "whole",
|
||||||
|
depth = "foreground"
|
||||||
|
}
|
||||||
|
|
||||||
properties[25] = {
|
properties[25] = {
|
||||||
overlay = {17,19,21,23},
|
overlay = {17,19,21,23},
|
||||||
type = "emtpy",
|
type = "emtpy",
|
||||||
|
|
4
main.lua
4
main.lua
|
@ -50,8 +50,8 @@ function love.load()
|
||||||
|
|
||||||
--Kupo:New(100,150)
|
--Kupo:New(100,150)
|
||||||
--Kupo:New(300,150)
|
--Kupo:New(300,150)
|
||||||
--Decoration:New(200,89,animation.decoration.candelabra,80)
|
Decoration:New(200,89,animation.decoration.candelabra,80)
|
||||||
--Fairy:New(200,88)
|
Fairy:New(200,88)
|
||||||
--CursedBook:New(180,68)
|
--CursedBook:New(180,68)
|
||||||
|
|
||||||
gravity = 0.2
|
gravity = 0.2
|
||||||
|
|
Loading…
Reference in New Issue