I decided to make a space invaders clone in pico-8 over the weekend. I've been having a bit of trouble with a weird collision glitch that only happens when my Alien entities react to colliding with the right side of the screen. I've Worked through the logic in my head and my code should work. I've tried numerous variations of what I currently have in my cart thinking that maybe there is something with the code execution that is causing it to be off.
I'm pretty sure that the problem is related to the bit of code below. However, I'm not 100% sure since I haven't been able to fix it yet :-)
update = function(self) if(self.x <= 0) then adr = 1 self.x = 0 elseif(self.x >= 120) then adr = -1 self.x = 120 end self.x +=self.v*adr end
Please direct me towards a solution if you can. This type of collision detection is usually pretty straightforward to do, but I've spent more time trying to fix this bug than I've spent making everything else.
I was able to fix the problem by moving the collision detection into a different loop to separate it from the position update so that the direction wouldn't be changed before all the entities had finished updating.
You're updating them from left to right. When the last in row collides you change their global direction, which affects this last one right away but the others have moved already. It works on the left because the first in line collides and then the others get the correct dir. You might need to separate the collision detection loop so that everybody moves in the same direction within the same frame.
Hope this helps!
I fixed it. It was as simple as adding an extra for loop in my update function. Although I tried moving the collision detection to the update function, it was still having the same problem because it wasn't looping all the way through the list of entities before changing directions.
Hey, Thanks! Space Invaders and Galaga are two of my favorite classic arcade games. I hoping to make this into a combination of the two. I rarely share the things I make but If you are interested, I might post the finished version. I'm still not sure that I'm happy with the art right now but I have finally convinced myself to just move on and worry about sprites later.
Hey not bad, liking the sprites
I also had a bit of figuring to do regarding the left/right sides when I was making my clone of Space Invaders.
On mine, I have a bounding/collision box that surrounds the whole enemy group. With each enemy death I check the width and height of the group (since it has to check collision with floor and destructible barriers) and update the collision box accordingly. If box hits wall, drop and change direction.
Also a big fan of Space Invaders and Galaga that when I realized there was no Space Invaders a few years back I had to write one up.
curious to see your take on it.. gl get it finished!
[Please log in to post a comment]