diff --git a/assets/tileset/library.png b/assets/tileset/library.png index a4ffe16..9fcf3c5 100644 Binary files a/assets/tileset/library.png and b/assets/tileset/library.png differ 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