Log In  

Cart #gamuretihi-0 | 2019-08-16 | Code ▽ | Embed ▽ | No License
4

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.

[Edit]
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.

Cart #zitomarufe-0 | 2019-08-16 | Code ▽ | Embed ▽ | No License
4

P#66686 2019-08-16 00:51 ( Edited 2019-08-16 20:01)

Post-Release Comments
:: dw817

Actually pretty good ! You're even checking the edge of the LEFT and RIGHT to determine if the aliens can travel that far when their neighbors have been shot, just like original Space Invaders.

Going to STAR this and look forward to seeing this cart in the future !

P#66762 2019-08-18 16:23

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.

P#66766 2019-08-18 23:28 ( Edited 2019-08-18 23:29)

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!

P#66962 2019-08-26 15:33 ( Edited 2019-08-27 02:41)

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2020-04-09 23:24 | 0.021s | 2097k | Q:44