Help implementing game logic from fish fillets

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
pgimeno
Party member
Posts: 3672
Joined: Sun Oct 18, 2015 2:58 pm

Re: Help implementing game logic from fish fillets

Post by pgimeno »

glitchapp wrote: Sat Jul 01, 2023 5:00 pm
pgimeno wrote: Sat Jul 01, 2023 11:09 am Don't miss my edits where I give you some tips :)
which edits? you mean about this problem of the spectrogram?
You apparently read my message while I was editing it. I added this part after you quoted it:

pgimeno wrote: Cubic Player had that effect built in, and I loved it so much that made my own spectrogram plug-in for another player, gst123, to get it back when CP was no longer an option for me.

I can see two ways to do them with love: scrolling and the CP way. Cubic Player made a sweep from left to right, darkening pixels that were going to be redrawn, leaving a fading band between the past sweep and the current position. Not sure if I've explained that clearly.

Drawing it may be a bit of a challenge. I can figure a way by using a canvas (two canvases if you plan to use scrolling), an image, an imagedata object of 1 x number_of_frequencies, and the Image:replacePixels function. The ImageData would receive the colours of one pixel row; you'd use it to refresh the image, then draw the image to the canvas and either fade the canvas (for the CP method) or scroll it using the other canvas as an auxiliary one.
glitchapp
Party member
Posts: 264
Joined: Tue Oct 05, 2021 10:34 am
Contact:

Re: Help implementing game logic from fish fillets

Post by glitchapp »

pgimeno wrote: Sun Jul 02, 2023 3:52 am
glitchapp wrote: Sat Jul 01, 2023 5:00 pm
pgimeno wrote: Sat Jul 01, 2023 11:09 am Don't miss my edits where I give you some tips :)
which edits? you mean about this problem of the spectrogram?
You apparently read my message while I was editing it. I added this part after you quoted it:

pgimeno wrote: Cubic Player had that effect built in, and I loved it so much that made my own spectrogram plug-in for another player, gst123, to get it back when CP was no longer an option for me.

I can see two ways to do them with love: scrolling and the CP way. Cubic Player made a sweep from left to right, darkening pixels that were going to be redrawn, leaving a fading band between the past sweep and the current position. Not sure if I've explained that clearly.

Drawing it may be a bit of a challenge. I can figure a way by using a canvas (two canvases if you plan to use scrolling), an image, an imagedata object of 1 x number_of_frequencies, and the Image:replacePixels function. The ImageData would receive the colours of one pixel row; you'd use it to refresh the image, then draw the image to the canvas and either fade the canvas (for the CP method) or scroll it using the other canvas as an auxiliary one.
Now I understand. I think it could even be done by just writing rectangles on the current canvas and letting them disappear after a period of time. This way of course is not the most optimal, but I don't really know how to create an imagedata and refresh the image. If someone try I may learn but I currently have no idea how to achieve that.

Thanks for the idea, I'm hopeful that someone would take the challenge and if someone does that library would be worth of its own repository.
User avatar
pgimeno
Party member
Posts: 3672
Joined: Sun Oct 18, 2015 2:58 pm

Re: Help implementing game logic from fish fillets

Post by pgimeno »

glitchapp wrote: Sun Jul 02, 2023 4:30 am Now I understand. I think it could even be done by just writing rectangles on the current canvas and letting them disappear after a period of time. This way of course is not the most optimal, but I don't really know how to create an imagedata and refresh the image. If someone try I may learn but I currently have no idea how to achieve that.
It's not that hard. You create the 1xN imagedata with love.image.newImageData(1, N), and then an image from it with love.graphics.newImage(imagedata). Every frame, you refresh the imagedata using ImageData:mapPixel followed by (Image):replacePixels(imagedata), and then you can draw the one-pixel-thick image on the canvas.
glitchapp
Party member
Posts: 264
Joined: Tue Oct 05, 2021 10:34 am
Contact:

Re: Help implementing game logic from fish fillets

Post by glitchapp »

right, will see what I can do, however my priority now is to correct bugs and make the game more stable, I actually added a lot features and with every new feature I add new bugs arise and this project has grown way too much... once I solve the most critical problems I will see if I can add more features. Just in case anyone is interested betatesters are more than welcome: feel free to report the bugs to issues in the repository or to send pull requests.
glitchapp
Party member
Posts: 264
Joined: Tue Oct 05, 2021 10:34 am
Contact:

Re: Help implementing game logic from fish fillets

Post by glitchapp »

darkfrei wrote: Fri Jun 23, 2023 10:19 am Can you try to reduce .png size with this tool?
https://forums.factorio.com/viewtopic.p ... 71#p250171
zorg wrote: Fri Jun 23, 2023 12:42 pm You still need to be aware that even opus has quite a lot of settings you need to understand and pick the most suitable ones. For voice, you can go down to very low bitrates, especially with Opus. 32kbps would be enough for a vocal recording that wouldn't cut out any frequencies human voices can produce.

If your dub audio tracks have lots of silence in them, you could trim all that out, and only save the parts that actually have spoken voice in them; encoders usually won't do anything to silent regions in terms of replacing them with something like "insert x milliseconds of silence from here" so that's still going to be a waste of space.
This is a solution I found to reduce the assets even further: https://codeberg.org/glitchapp/fish-fil ... ts-encodec

This was the size of the assets before:
Dialogs (dubs): 282.2 Mb
Music: 155.9 Mb

This is after using the new codec:
Dialogs: 11.3 * 9 =101.7Mb (this is an aproximation because not all dialogs are converted yet)
Music: 6 Mb

If you are wondering how it sounds I attached a demo below. With dialogs the results is better but music doesn't sound bad considering that the .ogg is 5.8mb big and the .ecdc has only 85,4kb. Obviously love does not support ecdc format so I had to convert the file to ogg in order to make it work, but you can trust me the source is that small.

Just in case someone find it useful there's a script in the repository to convert the audios from ecdc to ogg.

I'm also considering calling a python script within the game to decode the audios as they are needed with an example I've seen like this:

Code: Select all

local pythonScriptPath = "path/to/your/python_script.py"
local command = "python " .. pythonScriptPath
os.execute(command)
I wonder if it would work but it should because those are calls to os commands...
Attachments
musicplayer2.love
Music player with two audio tracks
(10.9 MiB) Downloaded 119 times
User avatar
pgimeno
Party member
Posts: 3672
Joined: Sun Oct 18, 2015 2:58 pm

Re: Help implementing game logic from fish fillets

Post by pgimeno »

glitchapp wrote: Sun Jul 23, 2023 6:57 am

Code: Select all

local pythonScriptPath = "path/to/your/python_script.py"
local command = "python " .. pythonScriptPath
os.execute(command)
I wonder if it would work but it should because those are calls to os commands...
Not sure if everyone has a Python executable installed. Also, in some Linux installations I have an executable called `python3` but not one called `python`.
glitchapp
Party member
Posts: 264
Joined: Tue Oct 05, 2021 10:34 am
Contact:

Re: Help implementing game logic from fish fillets

Post by glitchapp »

pgimeno wrote: Sun Jul 23, 2023 10:03 am
glitchapp wrote: Sun Jul 23, 2023 6:57 am

Code: Select all

local pythonScriptPath = "path/to/your/python_script.py"
local command = "python " .. pythonScriptPath
os.execute(command)
I wonder if it would work but it should because those are calls to os commands...
Not sure if everyone has a Python executable installed. Also, in some Linux installations I have an executable called `python3` but not one called `python`.
Yes you are right, it is called python3 now. What's even more rare is that someone has the experimental EnCodec library installed and it is required for everything to work, so whoever decides to use the new assets I created should know what he/she is doing.

The new assets will not substitute the old ones because even if the ratio of compression is impressive, there is a perceptible lose in quality specially with music. Another big issue is that it is terribly slow to encode and decode, probably because I used entropy to increase quality. They are simply a new option just in case someone prefer to save bandwith or test the experimental codec.
glitchapp
Party member
Posts: 264
Joined: Tue Oct 05, 2021 10:34 am
Contact:

Re: Help implementing game logic from fish fillets

Post by glitchapp »

Hi, there has been almost no post on updates of this project lately but I think this is worth to post because there's a lot of work behind: There is a full gamepad layout and support and the whole game is fully playable without mouse and keyboard now.

Here is a description of the gamepad layout:
gamepad layout
gamepad layout
xboxgamepad2contrast.jpg (69.48 KiB) Viewed 6513 times
I've been correcting bugs but I may have missed anything so feel free to give feedback if you encounter any issue.

Here there are a some other things I've modified / added recently:
- Music player gui layout has been refactored
- Particle effect and fading color spectrum added to the music bars.
- Radial menu to quickly select some options with the thumbstick.
- A lot of bugs have been corrected, the game is getting very stable and it is now harder to make it crash (please report any critical bug).
- Scripts to download /pack / update and launch the game available here: https://codeberg.org/glitchapp/fish-fil ... e-launcher / https://codeberg.org/glitchapp/fish-fil ... Script.ps1 / https://codeberg.org/glitchapp/fish-fil ... hellScript

Thanks for all the help and contributions so far and feel free to give feedback regarding anything you would like to see improved.
glitchapp
Party member
Posts: 264
Joined: Tue Oct 05, 2021 10:34 am
Contact:

Re: Help implementing game logic from fish fillets

Post by glitchapp »

The biggest issue the game still have has to do with scaling.

I managed to make the screen scale properly when you resize the game's windows, but the start size of backgrounds and objects are predefined on this file: https://codeberg.org/glitchapp/fish-fil ... frgbck.lua at the function assignremakesize() which is simply a work around till I find the right formula to calculate it automatically.This basically a mathematical problem, any help to achieve this is welcome.

There are variables that store the windows width and height and the size of the maze in the game logic

--This code loads a game level in the push-blocks game. It sets the game map, grid size, block sizes and outlines, and areas. It also remaps the tiles, sets the block outline, and loads the agents for the level.

Code: Select all

function pb:load (level)
	local width, height = love.graphics.getDimensions()
	self.map = level.map
	self.gridWidth = level.w
	self.gridHeight = level.h
	--self.gridSize = math.floor(math.min(width/(level.w), height/(level.h)))
	self.gridSize = (math.min(width/(level.w), height/(level.h)))
	tileSize = self.gridSize
	gridSize=self.gridSize				-- turns self.gridSize into a global variables needed to reset zoom values on game/mainfunctions/mouseinput.lua
	self.blocks = level.blocks
	self.areas = level.areas
	for i, block in ipairs (self.blocks) do
		remapTiles (block)
		setBlockOutline (block)
	end
	pb:agentsload(level)
end
The variables that store the windows size are:

Code: Select all

local desktopWidth, desktopHeight = love.window.getDesktopDimensions()
The function assignremakesize() initializes the values expx, expy and dividx, dividy. Those values are factors used to resize the background of the levels and the objects / agents so that they align with the underliying grid. For now they are initialized manually but I'm looking for the formula that take all the variables share above and do that math.

Code: Select all

function assignremakesize()

		if res=="720p" then expx=0.38 expy=0.38 dividx=0.75 dividy=0.75
	elseif res=="1080p" then expx=0.52 expy=0.52 dividx=1.02 dividy=1.02
	elseif res=="1440p" then expx=0.670 expy=0.670 dividx=1.33 dividy=1.33
	elseif res=="4k" then expx=1.07 expy=1.07 dividx=2.1 dividy=2.1
	end
I need to make a formula that take those values and initialize the level with proper scaling.
User avatar
darkfrei
Party member
Posts: 1204
Joined: Sat Feb 08, 2020 11:09 pm

Re: Help implementing game logic from fish fillets

Post by darkfrei »

glitchapp wrote: Sat Sep 09, 2023 6:13 am

Code: Select all

function assignremakesize()

		if res=="720p" then expx=0.38 expy=0.38 dividx=0.75 dividy=0.75
	elseif res=="1080p" then expx=0.52 expy=0.52 dividx=1.02 dividy=1.02
	elseif res=="1440p" then expx=0.670 expy=0.670 dividx=1.33 dividy=1.33
	elseif res=="4k" then expx=1.07 expy=1.07 dividx=2.1 dividy=2.1
	end
I need to make a formula that take those values and initialize the level with proper scaling.
Just one solution, but small error for others:

Code: Select all

function calculateScalingValues(res)
--	x	y1
--	720	0.38
--	1080	0.52

	local x = tonumber(res:match("%d+"))
	if res == "4k" then
		x = 2160
	end
	local a1, b1 = 0.84/2160, 0.1
	local y1 = x * a1 + b1
end
Update:

Polynom

Code: Select all

y1 = a*x^2 + b*x + c
gives us:

Code: Select all

a =	3.858024691358e-008
b =	0.00031944444444444
c =	0.13

-- gives
360	0.25
720	0.38
1080	0.52
1440	0.67
1800	0.83
2160	1.0
also

Code: Select all

a2 =	1.5432098765432e-007
b2 =	0.00047222222222222
c2 =	0.33

-- gives
360	0.52
720	0.75
1080	1.02
1440	1.33
1800	1.68
2160	2.07
Used this function:

Code: Select all

function calculateQuadraticPolynomialCoefficients(x1, y1, x2, y2, x3, y3)
	local denom = (x1 - x2) * (x1 - x3) * (x2 - x3)
	local a = (x3 * (y2 - y1) + x2 * (y1 - y3) + x1 * (y3 - y2)) / denom
	local b = (x3^2 * (y1 - y2) + x2^2 * (y3 - y1) + x1^2 * (y2 - y3)) / denom
	local c = (x2 * x3 * (x2 - x3) * y1 + x3 * x1 * (x3 - x1) * y2 + x1 * x2 * (x1 - x2) * y3) / denom
	return {a, b, c}
end

local cs1 = calculateQuadraticPolynomialCoefficients(720, 0.38, 1080, 0.52, 1440, 0.67)
local cs2 = calculateQuadraticPolynomialCoefficients(720, 0.75, 1080, 1.02, 1440, 1.33)
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 8 guests