Hi! so I am attempting to make a platformer/puzzler game in which you are not supposed to get clears, or at least, not in the way you normally would. The idea as of now is to have clusters of 4-5 alike blocks make a clear which will cost HP/"hearts"/etc., but jumping to a certain height will clear the bottom rows, which will count towards your score.
...But I can't even get to that part of the game yet, because collisions and some other little technical issues. This is what I have so far.
Controls:
Left/Right = move character,
Up = jump,
X = move tetrad left or right,
Down = soft drop,
Z = rotate (not functional yet)
right now, I am using the game object system from bridg's Pico-8 for beginners tutorials. here's the issue - I need the game blocks to fall and leave no gaps, much like in puyo puyo. to do this they need to collide with other blocks that are the same type of game object. when I put it in as normal, the block launches into the air when it's created. I think this is because it is colliding with itself.
I was trying to do a solution using ipairs to compare the index number of the objects, so that I could exclude the current object and have it only collide with the others. the code i came up with doesn't exactly work, because I am unsure how to get the current object's index number. I feel like this is something resembling the solution though? am i going in the right direction here?
for i,b in ipairs(#objects)do if objects[i]!=self and objects[i.name]=="tet" then self:checkcollide(objects[i],0) self:handlecollide(objects[i],colldir) end end |
I'm also having issues where the tetrad, when it respawns, sometimes does not respond to the movement button anymore. it seems kind of random, like it might happen the first time it respawns or the fifth. here's the code for the tetrad-related inputs and the conditions that determine whether it goes left or right, which is all contained within the self.update function of the object.
if(self.x>96) self.dx=-8 if(self.x<16) self.dx=8 if self.islive then -- ❎ left/right if(btnp(5)) self.x+=self.dx -- 🅾️ rotate if(btnp(4)) then -- haven't got there yet! end -- ⬇️ soft drop if(btn(3)) self.y+=2 end |
i think it may be the way i'm calling it within the statement:
if self.islive then |
maybe sometimes it doesn't successfully call true? this is the code which is supposed to determine that.
inittetrad=function(self) if not self.islive then for i,b in ipairs (self.fblocks) do del(self.fblocks,b) end self.x=56 self.y=8 for i=0,3 do local s =flr(rnd(4)+1) if (#self.fblocks)<4 then add(self.fblocks,s) -- end end end self.islive=true end end, |
So, if anyone can see why any of this isn't working please let me know. I've only been working on this for a few weeks so I am very happy with the progress so far, hope that I can build something fun and memorable here. Here's another cart without the ipairs error so you can see the X button error.
Well I'm not sure if its what you mean to do, and it still has some issues, but I managed to make it not immediately crash.
For this section I made some changes
for i,b in ipairs(#objects)do if objects[i]!=self and objects[i.name]=="tet" then self:checkcollide(objects[i],0) self:handlecollide(objects[i],colldir) end end |
First, ipairs(#objects)
becomes ipairs(objects)
# is used to get the length of the array (a number), ipairs needs the array.
Second, objects[i.name]
becomes objects[i].name
i is the index, so objects[i] would be the object with a .name
The end result is
for i,b in ipairs(objects)do if objects[i]!=self and objects[i].name=="tet" then self:checkcollide(objects[i],0) self:handlecollide(objects[i],colldir) end end |
It seems that now the blocks collapse in on themselves, but they collide well enough with the walls and player.
ah, thanks for the help on that. this is basically where i was before applying the collision code, with the blocks collapsing on themselves. so now i need to figure out how to make this check work the way i want it to.
i was able to fix the problem with the x button and the tetrad not moving. the issue was happening when i was hitting the wall, setting self.dx to -8 and moving the tetrad left, and then landing and respawning. i think for some reason when it respawns it sets self.dx to zero? fixed it by setting self.dx to 8 in the inittetrad() function.
thinking about how to get the check to work. maybe when a game object is created and added to the "objects" table, i could put in an ipairs statement to record the index # to the object itself so that it can be more easily referenced. something like this:
for i,b in ipairs(objects) objects[i].index=i end |
then i could call it in the collision function to ensure that the objects being called do not share an index number, hopefully distinguishing them enough that the "tet" objects do not collide with themselves. Will see if that works when I get home later today.
it worked!! Now the blocks stack and fall. Now I need to figure out clears and some places to optimize the code bc as of now it gets laggy pretty quick as the blocks stack up.
[Please log in to post a comment]