From cbf29ced658b144130dfaccee319cbd5f58f984e Mon Sep 17 00:00:00 2001 From: lustlion Date: Sat, 5 Feb 2022 12:32:47 +0100 Subject: [PATCH] Shader for lighting, fairy line of view, tileset change, broke lights, sorry --- assets/tileset/library.png | Bin 4303 -> 4151 bytes data/dialog_sequences.lua | 12 +++--- data/levels/level1.lua | 6 +-- data/scripts.lua | 1 + data/scripts/entities/decoration.lua | 2 +- data/scripts/entities/fairy.lua | 24 +++++++---- data/scripts/entities/player.lua | 4 +- data/scripts/entity.lua | 58 +++++++++++++++++++++++++++ data/scripts/game.lua | 4 +- data/scripts/lights.lua | 46 +++++++++++++++++---- data/shaders.lua | 31 ++++++++++++++ data/tileset/library.lua | 15 +++++++ main.lua | 4 +- 13 files changed, 176 insertions(+), 31 deletions(-) create mode 100644 data/shaders.lua diff --git a/assets/tileset/library.png b/assets/tileset/library.png index a4ffe1672dc16eceeea4e8a7ad8242df412e8692..9fcf3c5587345df6ec091abf9bdcd59cdd77b30a 100644 GIT binary patch delta 4142 zcmV+}5Yg|?A-5oqFnL2Mm08pr=%8c5ruO`Dbk(W+=$gaoU;Xr%^m z;ItC$agj(B32wWWB-iu+hXuhNIBa`OIIOrW+6q>yJ+@pq5e}PIi9J9orAkpBrP+k0 zB}Hw%J$O80d+Zs%c`q|l#y@G4%#7{NGtVB|-}l)j0E`}BW`820BJrTe?mCTL3_u+Kk$T83qx2{1+WH{FHkXqw!)V;ORDHBsz9J_)S?COq1&%@sGtEK z23-X!ufWOsyIs(V$|);gQ zfyv~atuna6_*C#fbE#zoPz%3WsJlVN+gS;fAmC;Y$bauA7wLZ&?Narl@T&|==2rr4 zx4_&kRVPZ+B5Ji8D}P`T+7Gd_(%bq}MdjD31?YF-m-tiyI?9czDB} z*uIyN|9}23Fmw_a7y<@{f%{(r!)Jh@=S4cdtcfrl5Vg{o+V>K$?`84-!&UKj==tRQ z{@3Y*q<{RZFfRE+CxN}E#0A?skZBJ-BhDY)0e=1_c@HwKWY58jJhZhlvq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Ty>%_J+}X^lUVG!^Ca7B@l)Z&dPv|0pMNnXX6$j= z{syp)+xkHd;Cf=+|BC3KD*8)vfIK#h2* zmBDMRe`;Nzpa*DB4&R6V2!ASkYd+`!8s&#i8jwTl>w?n6JmKl>VtxmCz5rP?u7^mV zS7yQ8HTDNk^)k+Yz!3c03`WzC+p=^@Gx z>ms@xulc2Rj}hwY!Uo_|pq+w5>XbH&34BWcs?gX@*3Y0DqIy;l5pUPT}1_ zb?Z~Fw@9S321h8RR0iI<)yH;lX8LGCV%beB(%J33D2obHr{1jFG9dpycK$!o7d! z=X6)o{0?KVZu9^HlYjaCouaY@hd&VJz^y0G??7dI8W@=Z8l2b`#j9=XJSlu94lL;R zBhT+38=Uekq{Mfi2ph-D=)A`ft0$48LQL7$ce1Dpy1Gu?Ej4x%kNRoL) z4?V(_$#P411lB)658#%SuP%W3?s-k_Zb})X`LC@^eDx3U+W0c8EgkFn`iXoy(G8e> z29Lhc%O++2x?aH~PP6R)rv7)#Ec6h{eNbFHMg1){80Q1_}gFW`R+a~!U-P+JNLhGUSfyP zf^#OQyfn+qUB=K}aUxkah%tQ7ZfIB?j`mNeL=b}lsXdEhg#EgHLESre@^4 z4$|Xq9rL{kCgzTPk~OmScvc7pbf+}HTN(1TXf#PlwO6bX#B{Ar|J3!`kTZj zxCFg0g=lPVs6YS}R)z2}g(wm~5NHBT5hlfg(o8t-Sfy(GK%fb%ZvgXYZadC;1C)s$ z2sDCisR-X=(=nw?{I#uJAdpSpFN+fBZ$QEjDA3nvlVH<4A@5kFYWzT;33}oa9JIQD p^$ImDk_;A^fhHLYPwzlK^M3}3xqw(tTJ!(_002ovPDHLkV1mf7c_IJ+ diff --git a/data/dialog_sequences.lua b/data/dialog_sequences.lua index bfce314..026f53e 100644 --- a/data/dialog_sequences.lua +++ b/data/dialog_sequences.lua @@ -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} } diff --git a/data/levels/level1.lua b/data/levels/level1.lua index 67a715a..e3236ab 100644 --- a/data/levels/level1.lua +++ b/data/levels/level1.lua @@ -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 = {} diff --git a/data/scripts.lua b/data/scripts.lua index 4671cb1..d0cabfd 100644 --- a/data/scripts.lua +++ b/data/scripts.lua @@ -1,5 +1,6 @@ -- data require "data/enums" +require "data/shaders" require "data/scripts/locale" -- support functions require "data/scripts/math" diff --git a/data/scripts/entities/decoration.lua b/data/scripts/entities/decoration.lua index 2c676fb..0ffc0d7 100644 --- a/data/scripts/entities/decoration.lua +++ b/data/scripts/entities/decoration.lua @@ -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) diff --git a/data/scripts/entities/fairy.lua b/data/scripts/entities/fairy.lua index d886baf..004ba63 100644 --- a/data/scripts/entities/fairy.lua +++ b/data/scripts/entities/fairy.lua @@ -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 diff --git a/data/scripts/entities/player.lua b/data/scripts/entities/player.lua index 177e503..14f76fd 100644 --- a/data/scripts/entities/player.lua +++ b/data/scripts/entities/player.lua @@ -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) diff --git a/data/scripts/entity.lua b/data/scripts/entity.lua index 9d68d9a..d2e59cb 100644 --- a/data/scripts/entity.lua +++ b/data/scripts/entity.lua @@ -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) diff --git a/data/scripts/game.lua b/data/scripts/game.lua index 0b2aadd..adbf776 100644 --- a/data/scripts/game.lua +++ b/data/scripts/game.lua @@ -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 diff --git a/data/scripts/lights.lua b/data/scripts/lights.lua index fecd7bf..aef5630 100644 --- a/data/scripts/lights.lua +++ b/data/scripts/lights.lua @@ -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 diff --git a/data/shaders.lua b/data/shaders.lua new file mode 100644 index 0000000..65f7024 --- /dev/null +++ b/data/shaders.lua @@ -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