View Single Post
Old 03 June 2018, 20:17   #24
Shatterhand
Warhasneverbeensomuchfun
 
Shatterhand's Avatar
 
Join Date: Jun 2001
Location: Rio de Janeiro / Brazil
Age: 41
Posts: 3,450
Quote:
Originally Posted by Retro1234 View Post
Your still trying to check them all in 1 game loop they only move what 4 pixels max per loop you won't miss any thing.

Even if you check them all at once like your code above it should be quick.
I've made Quasarius.
[ Show youtube player ]

if I remember correctly, enemies move 2 pixels when they move, player laser moves at 8 pixels.

What I did on that game (and keep in minding I was still learning a lot of this stuff and I know it wasn't the smartest way) was first check if the laser sprite was colliding with the color of the enemy (all the enemies have a color in common). If it is, then figure out what enemy the laser is hitting.

With all 12 enemies on screen, I had to do just 48 checks. Believe it or not, THIS CAUSED a hiccup on the game. I switched to test just half of enemies at one loop then half of the enemies at the following loop. Many times I just missed the collision on the next loop because the laser had already moved past the enemy. So when the laser hits an enemy, on the next frame if its not destroyed (when it didn't detect what enemy it was hitting), the laser does not move. But the enemy still moves and sometimes I'd STILL MISS the collision because of this.

So I changed the movement of the enemies, which ended up helping gameplay. Half of enemies move in a frame, half of the other enemies move at the other frame, up until you have just 6 enemies on screen. This made the enemies move faster when you have less enemies (something that was already planned, but I wasn't going to do it this way), so I was ok with it, but I really scratched my head on how hard this was.

Of course on this game specifically I could have used a grid approach since the movement is a lot more restricted (and there was no need to check sprite collision against playfield before checking what was causing the collision, I am pretty sure this just created unnecesary extra overload), but like I said, I was still learning (and still am )
Shatterhand is offline  
 
Page generated in 0.11118 seconds with 11 queries