Re: Help implementing game logic from fish fillets
Posted: Tue Feb 01, 2022 1:41 pm
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
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).
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
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).