Help implementing game logic from fish fillets
Re: Help implementing game logic from fish fillets
Any idea how to apply distortion effects with shaders to simulate underwater settings? if there is some kind of shaders that simulate caustic effects too that would be amazing. Thanks!
Re: Help implementing game logic from fish fillets
Maybe water shaders like in Oxygen not Included:
https://www.shadertoy.com/user/frankbatista
https://www.shadertoy.com/view/tlX3RH
or
https://www.shadertoy.com/user/Mafrans
https://www.shadertoy.com/view/wdG3Rz
https://www.shadertoy.com/user/frankbatista
https://www.shadertoy.com/view/tlX3RH
Code: Select all
// https://www.shadertoy.com/user/frankbatista
// Found this on GLSL sandbox. I really liked it, changed a few things and made it tileable.
// :)
// by David Hoskins.
// Water turbulence effect by joltz0r 2013-07-04, improved 2013-07-07
// Redefine below to see the tiling...
//#define SHOW_TILING
#define TAU 6.28318530718
#define MAX_ITER 5
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
float time = iTime * .5+23.0;
// uv should be the 0-1 uv of texture...
vec2 uv = fragCoord.xy / iResolution.xy;
#ifdef SHOW_TILING
vec2 p = mod(uv*TAU*2.0, TAU)-250.0;
#else
vec2 p = mod(uv*TAU, TAU)-250.0;
#endif
vec2 i = vec2(p);
float c = 1.0;
float inten = .005;
for (int n = 0; n < MAX_ITER; n++)
{
float t = time * (1.0 - (3.5 / float(n+1)));
i = p + vec2(cos(t - i.x) + sin(t + i.y), sin(t - i.y) + cos(t + i.x));
c += 1.0/length(vec2(p.x / (sin(i.x+t)/inten),p.y / (cos(i.y+t)/inten)));
}
c /= float(MAX_ITER);
c = 1.17-pow(c, 1.4);
vec3 colour = vec3(pow(abs(c), 8.0));
colour = clamp(colour + vec3(0.0, 0.35, 0.5), 0.0, 1.0);
#ifdef SHOW_TILING
// Flash tile borders...
vec2 pixel = 2.0 / iResolution.xy;
uv *= 2.0;
float f = floor(mod(iTime*.5, 2.0)); // Flash value.
vec2 first = step(pixel, uv) * f; // Rule out first screen pixels and flash.
uv = step(fract(uv), pixel); // Add one line of pixels per tile.
colour = mix(colour, vec3(1.0, 1.0, 0.0), (uv.x + uv.y) * first.x * first.y); // Yellow line
#endif
fragColor = vec4(colour, 1.0);
}
https://www.shadertoy.com/user/Mafrans
https://www.shadertoy.com/view/wdG3Rz
Re: Help implementing game logic from fish fillets
thank you! it works! I'm trying to figure out how to apply it only to the background and not the foreground now.darkfrei wrote: ↑Thu Mar 10, 2022 8:54 am Maybe water shaders like in Oxygen not Included:
https://www.shadertoy.com/user/frankbatista
https://www.shadertoy.com/view/tlX3RH
orCode: Select all
// https://www.shadertoy.com/user/frankbatista // Found this on GLSL sandbox. I really liked it, changed a few things and made it tileable. // :) // by David Hoskins. // Water turbulence effect by joltz0r 2013-07-04, improved 2013-07-07 // Redefine below to see the tiling... //#define SHOW_TILING #define TAU 6.28318530718 #define MAX_ITER 5 void mainImage( out vec4 fragColor, in vec2 fragCoord ) { float time = iTime * .5+23.0; // uv should be the 0-1 uv of texture... vec2 uv = fragCoord.xy / iResolution.xy; #ifdef SHOW_TILING vec2 p = mod(uv*TAU*2.0, TAU)-250.0; #else vec2 p = mod(uv*TAU, TAU)-250.0; #endif vec2 i = vec2(p); float c = 1.0; float inten = .005; for (int n = 0; n < MAX_ITER; n++) { float t = time * (1.0 - (3.5 / float(n+1))); i = p + vec2(cos(t - i.x) + sin(t + i.y), sin(t - i.y) + cos(t + i.x)); c += 1.0/length(vec2(p.x / (sin(i.x+t)/inten),p.y / (cos(i.y+t)/inten))); } c /= float(MAX_ITER); c = 1.17-pow(c, 1.4); vec3 colour = vec3(pow(abs(c), 8.0)); colour = clamp(colour + vec3(0.0, 0.35, 0.5), 0.0, 1.0); #ifdef SHOW_TILING // Flash tile borders... vec2 pixel = 2.0 / iResolution.xy; uv *= 2.0; float f = floor(mod(iTime*.5, 2.0)); // Flash value. vec2 first = step(pixel, uv) * f; // Rule out first screen pixels and flash. uv = step(fract(uv), pixel); // Add one line of pixels per tile. colour = mix(colour, vec3(1.0, 1.0, 0.0), (uv.x + uv.y) * first.x * first.y); // Yellow line #endif fragColor = vec4(colour, 1.0); }
https://www.shadertoy.com/user/Mafrans
https://www.shadertoy.com/view/wdG3Rz
Re: Help implementing game logic from fish fillets
I am not familiar with shaders, can you show the shader code for Löve?
If your background is a canvas, then you can can apply your shader to that canvas only.
Re: Help implementing game logic from fish fillets
it's working now, I just can't apply to the whole background because then it loses much colors and brightness so I was testing how to apply to only particular places.
This is the code:
* Update, I apply with different levels of transparency depending on the zone of the background so that there's not much loss of color and brightness
This is the code:
Code: Select all
if shader1==false and shader2==true then --Draw second shader if enabled (shadertoy)
--love.graphics.rectangle('fill', 0, 0,1920, 680)
drawallcontent()
love.graphics.setShader(shader)
love.graphics.setColor(1,1,1,0.8)
love.graphics.draw (level1bck2, 0,0,0,1/dividx,1/dividy)
love.graphics.setColor(1,1,1,0.95)
love.graphics.draw (level1bck, 0,0,0,1/dividx,1/dividy)
love.graphics.setColor(1,1,1,1)
love.graphics.draw (level1frg, 0,0,0,1/dividx,1/dividy)
pb:drawAgents ()
pb:drawBlocks ()
love.graphics.setShader()
end
Re: Help implementing game logic from fish fillets
Hello, I'm just missing a last and very important function to make my game fully playable and I'm not sure how to approach it:
I need to create a function that detects when an agent has reached the exit.
To achieve that first I added a new number for the map tables (number 2) like this:
Please check the whole file here: https://codeberg.org/glitchapp/fish-fil ... evel-1.lua
The next thing I need to do is to create a function that detect when an agent collides with those exit marks. I've been thinking of creating also special objects for that purpose, what do yo think would be the best solution?
This is a function detecting collision of agents with blocks:
Please check the whole file and code here: https://codeberg.org/glitchapp/fish-fil ... blocks.lua
Thanks in advance!
I need to create a function that detects when an agent has reached the exit.
To achieve that first I added a new number for the map tables (number 2) like this:
Code: Select all
level.w = 0 -- map width in tiles (same as highest x)
level.h = #level.map -- map height in tiles
for y, xs in ipairs (level.map) do
for x, value in ipairs (xs) do
if value == 1 then
-- now value is true
level.map[y][x] = true
if level.w < x then level.w = x end
elseif value==0 then
-- now value is false
level.map[y][x] = false
elseif value==2 then
level.map[y][x] = "exit"
elseif value==3 then
level.map[y][x] = "border"
end
end
end
The next thing I need to do is to create a function that detect when an agent collides with those exit marks. I've been thinking of creating also special objects for that purpose, what do yo think would be the best solution?
This is a function detecting collision of agents with blocks:
Code: Select all
function pb:isCollisionBlockToAllAgents (blockA, dx, dy)
for i, agent in ipairs (self.agents) do
if self:isBlockToBlockCollision (blockA, agent, dx, dy) then
return agent -- dead agent :(
end
end
return false
end
Thanks in advance!
Re: Help implementing game logic from fish fillets
Must be something like:
The exit is an area, that have tiles.
We have two collision conditions:
1) At least one block of fish is in exit area to exit.
2) The whole fish must be in the exit area.
Just use new list with exits and check if it has the collision with agent of check for all agents that all of them have collision with exit area.
Pseudocode:
and than pb.exitAreas can be defined as block and agents: position and all tiles in any form for example rectangle.
The exit is an area, that have tiles.
We have two collision conditions:
1) At least one block of fish is in exit area to exit.
2) The whole fish must be in the exit area.
Just use new list with exits and check if it has the collision with agent of check for all agents that all of them have collision with exit area.
Pseudocode:
Code: Select all
function pb:areAllAgentsInExitAreas ()
for i, agent in ipairs (self.agents) do
if not self:isCollisionAgentToAnyExitArea (agent) then
return false -- at least one of agents is not on exit, the game is not over
end
return true -- all agents are in exit areas, level is done
end
Code: Select all
function pb:isCollisionAgentToAnyExitArea (agent)
for i, area in ipairs (self.exitAreas) do
if self:isBlockToBlockCollision (area, agent, 0, 0) then -- dx and dy are 0
return true -- collision one of areas to agent in /this/ position
end
end
return false -- this agent has no collision with any of exit areas
end
Re: Help implementing game logic from fish fillets
oh thank you! amazing it's almost done!
I added the two functions, now the last part missing is to call those functions to check if the collision is happening.
I created something like this:
Am I in the right direction?
I have an idea, the game is too big with the assets right now so I will make a small demo of the first level to post it here, I will upload it in a few minutes:
So there it is, don't select any other level than the first one because it will crash.
What I think it needs to be done is to call that function and ask if there is collision to the exit or if the two agents are colliding with the exit area.
If I add this function to the pb:mainMoving the game crashed when moving, I though that would be the way to know if the agents are in the exit...
--self:isCollisionAgentToAnyExitArea (agent)
*if the dialogs annoys you please press "c", I did not have time to fix the interface for the demo
I added the two functions, now the last part missing is to call those functions to check if the collision is happening.
I created something like this:
Code: Select all
function pb:getCollisionExit (Agent)
for i, agent in ipairs (self.agents) do
if agent == self.agent then
-- no collision detection with active agent
elseif self:isCollisionAgentToAnyExitArea (agent) then
return true -- collision with exit
end
end
end
I have an idea, the game is too big with the assets right now so I will make a small demo of the first level to post it here, I will upload it in a few minutes:
So there it is, don't select any other level than the first one because it will crash.
What I think it needs to be done is to call that function and ask if there is collision to the exit or if the two agents are colliding with the exit area.
Code: Select all
function pb:getBlocksToMove (agent, dx, dy)
local blocks = {}
local canMove = self:getCollisionBlocks (agent, blocks, dx, dy)
return blocks, canMove
end
function pb:moveAgent (agent, dx, dy)
self.agent.x = self.agent.x + dx
self.agent.y = self.agent.y + dy
end
function pb:moveBlocks (blocks, dx, dy)
for i, block in ipairs (blocks) do
block.x = block.x + dx
block.y = block.y + dy
if soundon==true then
--scrape6:play() --friction sound
end
end
end
function pb:isCollisionBlockToAllBlocks (blockA, dx, dy)
for i, block in ipairs (self.blocks) do
if not (block == blockA)
and self:isBlockToBlockCollision (blockA, block, dx, dy) then
return true
end
end
return false
end
function pb:isCollisionBlockToAllAgents (blockA, dx, dy)
for i, agent in ipairs (self.agents) do
if self:isBlockToBlockCollision (blockA, agent, dx, dy) then
return agent -- dead agent :(
end
end
return false
end
function pb:areAllAgentsInExitAreas ()
for i, agent in ipairs (self.agents) do
if not self:isCollisionAgentToAnyExitArea (agent) then
return false -- at least one of agents is not on exit, the game is not over
end
return true -- all agents are in exit areas, level is done
end
end
function pb:isCollisionAgentToAnyExitArea (agent)
for i, area in ipairs (self.exitAreas) do
if self:isBlockToBlockCollision (area, agent, 0, 0) then -- dx and dy are 0
return true -- collision one of areas to agent in /this/ position
end
end
return false -- this agent has no collision with any of exit areas
end
function pb:fallBlocks (blocks)
local dx, dy = 0, 1 -- no horizontal speed, but positive (down) vertical
for i = 1, self.gridWidth do
for i, block in ipairs (blocks) do
if self:isBlockToMapCollision (block, dx, dy) then
-- not falling
block.deadly = false
-- table.remove (blocks, i)
elseif self:isCollisionBlockToAllBlocks (block, dx, dy) then
block.deadly = false
-- collision to block: probably not falling
elseif block.deadly and self:isCollisionBlockToAllAgents (block, dx, dy) then
local deadAgent = self:isCollisionBlockToAllAgents (block, dx, dy)
deadAgent.dead = true
block.deadly = false
-- table.remove (blocks, i)
elseif self:isCollisionBlockToAllAgents (block, dx, dy) then
-- the block is on fish
else
-- sure falling
if soundon==true then
--impactmetal:play() --impact sound
end
block.x = block.x + dx -- never changes
block.y = block.y + dy
block.deadly = true
end
end
end
end
function pb:mainMoving (dx, dy)
local agent = self.agent -- active agent
if dx > 0 then
agent.direction = "right"
elseif dx < 0 then
agent.direction = "left"
end
local blocks, canMove = self:getBlocksToMove (agent, dx, dy)
if canMove then
self:moveAgent (agent, dx, dy)
self:moveBlocks (blocks, dx, dy)
self:fallBlocks (self.blocks, dx, dy)
--self:isCollisionAgentToAnyExitArea (agent)
end
end
--self:isCollisionAgentToAnyExitArea (agent)
*if the dialogs annoys you please press "c", I did not have time to fix the interface for the demo
Re: Help implementing game logic from fish fillets
I've fixed your credits (just style and functions, not the text of it):
Re: Help implementing game logic from fish fillets
Oh thank you, it does not look pixelated now, a lot better! I will upload it to the repository in the next update!
I like the button being highlighted with borders when hovered, I will add it to the main menu probably
Thanks again for all the help darkfrei!
Who is online
Users browsing this forum: No registered users and 1 guest