Help implementing game logic from fish fillets

General discussion about LÖVE, Lua, game development, puns, and unicorns.
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 »

I've done it!

Oh sorry I'm bad at reading the code of others, I was moving the wrong variable, I have to move self.agent.tx and I was moving self.agent.x

Code: Select all

	targetX = nil
	targetY = nil
	
	moves = false
function pb:updateAgents (dt)
	local up =    love.keyboard.isScancodeDown('w', 'up')
	local down =  love.keyboard.isScancodeDown('s', 'down')
	--local right = love.keyboard.isScancodeDown('d', 'right')
	--local left =  love.keyboard.isScancodeDown('a', 'left')

-- input works for not moving object only
	if not moves then
		local left =  love.keyboard.isScancodeDown('a', 'left')
		local right =  love.keyboard.isScancodeDown('d', 'right')
		local up =    love.keyboard.isScancodeDown('w', 'up')
		local down =  love.keyboard.isScancodeDown('s', 'down')
		if right and not left then
			moves = "right"
			targetX = self.agent.tx + 1
		
		elseif left and not right then
			moves = "left"
			targetX = self.agent.tx - 1
		--elseif up and not down then
			--moves = "up"
			--targetY = self.agent.ty + 1
		
		--elseif down and not up then
			--moves = "down"
			--targetY = self.agent.ty + 1
		end
		
	end
	-- need to move in this tick too
	if moves =="right" then
			self.agent.tx = self.agent.tx + dt*self.agent.vx
			if self.agent.tx >= targetX then
				self.agent.tx = targetX
				moves = false
			end
			
	elseif moves=="left" then 
			if self.agent.tx >= targetX then
				self.agent.tx = targetX
				moves = false
			end

	elseif moves=="up" then 
			if self.agent.ty >= targetY then
				self.agent.ty = targetY
				moves = false
			end
	elseif moves=="down" then 
			if self.agent.ty >= targetY then
				self.agent.ty = targetY
				moves = false
			end
			print ("targetX= "..targetY)
			print (self.agent.ty)
			
	end			
It works partially, it works to the right and left, but to the left moves faster and I don't know why. It also do not detect collisions when moving to the left and right and go thorugh the objects, but I know why, I have to put the code inside the right section.

This is a step forward, once I finish this I will start with the gravity and also implement the flag that says when the objects are deadly.

I implemented a game status to switch between the old and new code for debug purposes. That should allow anyone to check the problematic code and compare it to the old. I also added a live reloading library so you don't need to stop the game to see the changes if you change the code. This feature currently works only with main.lua and is commented by default till I solve some issues, if you change other files just stop the game as usual If you want to use the live library uncomment (--mylivecode = require ("livecode")) on main.lua . I hope all of this is useful.

New update: There are many bugs and unsolved problems arising with this challenge, and because I have fun implementing new features and I learn by doing it, I'm adding layers of complexity to the already hard problem of solving the game logic of this game which of course causes new bugs. Instead of asking here for help every time a new bug arises (there are going to be many) I implemented a small documentation app with slab (https://github.com/flamendless/Slab) with which you can check and have track of all the solved and unsolved game logic and not game logic related problems and bugs inside the game. This tool is already built in so you can check and keep track of the development inside the game. Besides all of the added features I try to keep the game as small as possible (currently only 431Kb!). I hope all of that helps keeping people informed about the development status and push the development forward!

You can of course keep asking and discussing your questions, suggestions and solutions here. I just want to free this thread of too much unnecessary information so that people can get straight to the point and discuss the problems they like or they want to try to solve. You can also use git to do so by opening issues there or forking / sending pull requests to the repository( links are inside the tool).
Attachments
luasok.love
(430.47 KiB) Downloaded 117 times
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 »

I would like to ask a question not related to the game logic but the graphics. The game to which the game logic of this game is based was first created almost 24 years ago (1998) with the lately port done on 2004 and the last commercial sequel from 2007. They all look awesome and beautiful to me specially for the time they were created, but computers, graphic cards and graphic libraries have evolved a lot since they were created. My question is: how would you approach trying to bring a port to modern standards and trying to harness as much graphical power as possible and as love and its libraries can harness. I have some ideas in mind but I would like to know the opinion of others which for sure have more experience than me developing in lua and love. The first thing that comes to my mind when thinking about how to harness modern graphic cards power with love and lua are shaders and 3d graphics. There are many libraries out there that bring 3d graphics inside love and I would like to ask you which do you think fits this game or if you think it's a good idea at all. Even knowing that this is a personal project with very limited resources and skills I would like to try to make something exciting and remarkable and not just cloning old ideas from 20 years ago by just making a 1 to 1 clone in lua and love. That would be very boring and would probably not be interesting at all. So let me know your thoughts about it, I would be very interested to know how would you approach this.
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: Tue Feb 08, 2022 7:14 am just cloning old ideas from 20 years ago by just making a 1 to 1 clone in lua and love
It's the best practice for newbies, you can be sure that the game will bee not too bad as it can.

Just try to make all what you can: physical simulations, good old mechanics from good old games. After some experience you can make your own ideas much better and faster than without this experience.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
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: Tue Feb 08, 2022 10:34 am
glitchapp wrote: Tue Feb 08, 2022 7:14 am just cloning old ideas from 20 years ago by just making a 1 to 1 clone in lua and love
It's the best practice for newbies, you can be sure that the game will bee not too bad as it can.

Just try to make all what you can: physical simulations, good old mechanics from good old games. After some experience you can make your own ideas much better and faster than without this experience.
You are right, for sure I will try to finish the mechanics because otherwise the game would be unplayable. but I'm thinking on how and which tools use to start doing graphics, and I'm thinking to try to do everything in 3d probably with blender, and if I do so, I wonder if I will use those graphics as simple rendered flat tiles or should I experiment trying to use real 3d assets instead of 2d tiles? I just wonder, I may try to experiment with the second idea, but I'm not sure which library should I use to at least try to experiment with that possibility as I never used 3d in love before...

I'm thinking on give a try to g3d groverburger, there are awesome games and demos made with it, I've just tested a demo of a minecraft port with this tool and the performance is awesome.

By the way one of the coolest games I tested with this tool is actually a sokoban game too: Hoarder's Horrible House of Stuff

Update: I just downloaded g3d and I'm going to experiment with it and see how it would look like when rendering the map in 3d, if I like it I will post here the results with the love file. I'm not sure if I will use it for the whole game but I like to experiment with different possibilities.
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 »

Before touching of blender and 3d, just make the 2d version with any placeholder graphics, that the game will be ready and playable.
The process to make it better is pretty infinite :)
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
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: Tue Feb 08, 2022 12:21 pm Before touching of blender and 3d, just make the 2d version with any placeholder graphics, that the game will be ready and playable.
The process to make it better is pretty infinite :)
You are right, I will, I just needed a pause with the game logic, but I will be back to it

I'm not thinking on starting the graphics without having the game logic finished, I'm just experimenting.

Just in case someone knows how to write the cells with grooverburger, I'm trying it with this:

Code: Select all

function draw_level()

love.graphics.draw(bckfish1img,80,230,0,0.4)
love.graphics.draw(bckfish1img,520,250,0,-0.15,0.15)
    for y, row in ipairs(level) do
        for x, cell in ipairs(row) do
		-- love.graphics.setFont(love.graphics.newFont(15))         	--this shouldn't be here, I just deleted it
            if cell ~= empty then
                local cellSize = 23

                    local colors = {
                    --[fish1] = {0.64, 0.53, 1},
                    --[fish1body] = {0.64, 0.53, 1},
                    --[fish2] = {0, 0, 1},
                    --[fish2body] = {0, 0, 1},
                    --[chair1] = {0.5, 0.5, 0},
                    --[table] = {0.62, 0.47, 1},
                    --[chair2] = {1, 0.79, 0.49},
                    --[steelbar] = {0.59, 1, 0.5},
                    --[cushion] = {0.61, 0.9, 1},
                    [wall] = {0.6, 0.58, 0.2},
                    --[obj1] = {0.29,0.43,0.83},
                    --[obj2] = {0.9,0.43,0.83},
                    [empty] = {0.146, 0.73, 0.73},
                }

				
                love.graphics.setColor(colors[cell])
		-- This should substitute the normal rectangles:				
		cell3d = g3d.newModel("assets/players/cube.obj", "assets/levels/level1/bckfish1.png", {y-1,x-1,0}, nil, {0.5,0.5,0.5})
		-- This is how the cells are currently drawn:
                love.graphics.rectangle('fill',(x - 1) * cellSize, (y - 1) * cellSize,cellSize,cellSize)
       
                if debugmode=="yes" then 
                love.graphics.setColor(1, 1, 1)
                love.graphics.print(
                    level[y][x],
                    (x - 1) * cellSize,
                    (y - 1) * cellSize
                )    
                else
				love.graphics.setColor(1, 1, 1)
                love.graphics.print(
                    " ",
                    (x - 1) * cellSize,
                    (y - 1) * cellSize
                )
				end
            end
        end
    end
end
but it does not work because just the last cell of the iteration is what is assigned to the variable cell3d...

The thing is that I don't understand how grooveburger draws the assets, I'm reading the wiki but I'm confused because it seems that it loads the assets and assigns the coordinates / position in space in the same function. I want to load the assets on load.love and draw it on specific position for every cell on love.draw, but for what I see there are not two different functions for it or am I confused?
Last edited by glitchapp on Tue Feb 08, 2022 4:59 pm, edited 2 times in total.
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 »

This:

Code: Select all

    for y, row in ipairs(level) do
        for x, cell in ipairs(row) do
           love.graphics.setFont(love.graphics.newFont(15))
are you really need to set the font on every cell?
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
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: Tue Feb 08, 2022 12:56 pm This:

Code: Select all

    for y, row in ipairs(level) do
        for x, cell in ipairs(row) do
           love.graphics.setFont(love.graphics.newFont(15))
are you really need to set the font on every cell?
I will delete that right now, that shouldn't be there, thanks for making me aware!
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 »

I'm back to the game logic, I thought I would never going to solve this, Some conditional had >= instead of <= and that was causing the problems with the movement inside the grid. The fish now moves inside the grid. Here is the code:

Code: Select all

function pb:updateAgents (dt)

if problemdebug=="1" then
-- input works for not moving object only
	if not moves then
		--local left =  love.keyboard.isScancodeDown('a', 'left')
		--local right =  love.keyboard.isScancodeDown('d', 'right')
		--local up =    love.keyboard.isScancodeDown('w', 'up')
		--local down =  love.keyboard.isScancodeDown('s', 'down')
		local up =    love.keyboard.isScancodeDown('up')
		local down =  love.keyboard.isScancodeDown('down')
		local right =  love.keyboard.isScancodeDown('right')
		local left =  love.keyboard.isScancodeDown('left')

		
		if up and not (down or right or left) then
			moves = "up"
			targetY = self.agent.ty - 1
		
		elseif down and not (up or right or left) then
			moves = "down"
			targetY = self.agent.ty + 1
		
		elseif right and not (up or down or left) then
			moves = "right"
			targetX = self.agent.tx + 1
		
		elseif left and not (up or down or right) then
			moves = "left"
			targetX = self.agent.tx - 1
		end
	end
		
	-- need to move in this tick too
	if moves =="right"  then
			self.agent.tx = self.agent.tx + dt*self.agent.vx
			if self.agent.tx >= targetX then
				self.agent.tx = targetX
				moves = false
			end
	elseif moves=="down" then 
			self.agent.ty = self.agent.ty + dt*self.agent.vup
			if self.agent.ty >= targetY then
				self.agent.ty = targetY
				moves = false
			end			
	elseif moves=="left" then 
			self.agent.tx = self.agent.tx - dt*self.agent.vx
			if self.agent.tx <= targetX then
				self.agent.tx = targetX
				moves = false
			end

	elseif moves=="up" then 
			self.agent.ty = self.agent.ty - dt*self.agent.vup
			if self.agent.ty <= targetY then
				self.agent.ty = targetY
				moves = false
			end
	end			
end
I started implementing the collisions with the new code.

It works partially , the steel bar moves forward when pushed properly till something is in its path. The chairs too but if you push them from the top they move too far and get stucked inside the walls. The table does not seem to detect the direction where is pushed and do weird things...

The player should not go through and return but just stay where it can not push further.

One solution I'm trying to implement with this last problem is moving the conditional "canMove" before "self.agent.tx = self.agent.tx + dt*self.agent.vx" like this:

Code: Select all

--This commented code is what I am trying to implement below:
--[[elseif right and not (up or down or left) then
		-- move right
		local tdx = dt*self.agent.vx -- delta X in tiles
		local canMove, block = pb:canMove (self.agent, tdx, 0)
		if canMove then
			self.agent.x = self.agent.x + tdx*pb.grigSize
			self.agent.tx = math.floor(self.agent.x*4/self.grigSize+0.5)/4
		elseif block and block.movable then
			self.agent.x = self.agent.x + tdx*pb.grigSize
			local tx = self.agent.tx
			self.agent.tx = math.floor(self.agent.x*4/self.grigSize+0.5)/4
			block.tx = block.tx + self.agent.tx-tx
		end
--]]
--this is the new code in which players move inside the grid, I am trying to insert the collisions above in this new code:
		if moves =="right" then
			self.agent.tx = self.agent.tx + dt*self.agent.vx
			local tdx = dt*self.agent.vx -- delta X in tiles
			local canMove, block = pb:canMove (self.agent, tdx, 0)
			
				if canMove then
				print("self.agent.tx: ", self.agent.tx)
				print("targetX: ",targetX)
						
						if self.agent.tx >= targetX then
							self.agent.tx = targetX
							
							moves = false
						end
				elseif block and block.movable then
						if self.agent.tx >= targetX then
							self.agent.tx = targetX
							moves = false
							local tx = self.agent.tx
							self.agent.tx = targetX
							block.tx = targetX+1
							moves = false
						end
				end
The problem is, that once you are in front of an object or wall it get stuck because it does not detect in which direction is the blocked path. I'm not sure how to solve this.
Attachments
luasok.love
(444.29 KiB) Downloaded 136 times
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 »

Here:

Code: Select all

-- this is the new code in which players move inside the grid, I am trying to insert the collisions above in this new code:
		if moves =="right" then
			self.agent.tx = self.agent.tx + dt*self.agent.vx
Why you move the agent without any checking?

Maybe the better solution:

Code: Select all

local dx, dy = 0, 0
if move = "right" then
	dx = dt*self.agent.vx -- horizontal speed
elseif move = "left" then
	dx = -dt*self.agent.vx  -- minus horizontal speed
if move = "down" then
	dy = dt*self.agent.vy -- some vertical speed
elseif move = "up" then
	dy = -dt*self.agent.vy  -- minus some (or another) vertical speed
end
local canMove, blocks = canAgentMoveAndMovedBlocks (dx, dy) -- returns boolean if agent and collinding blocks are movable and list of blocks to move
if canMove then
	dx, dy = moveAgent(dx, dy) -- move agent and change dx, dy if you need
	moveBlocks(blocks, dx, dy)
else
	-- change agent and blocks as stuck if you need
end
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 1 guest