Collision Detection for multiple objects | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 2

Collision Detection for multiple objects

I am trying to finish a "Flappy Bird Like Game" that was started in my Code Repo project while completing the Game Development course in Sololearn. Here's what I have so far: https://code.sololearn.com/WWQKGcA79Y66/?ref=app As you can see, I have not written collision detection for the green rectangles yet. I know how to code collision detection for each rectangle individually, but I am wanting know if there is a way to write a collision detection that would cover all of the green rectangles without have to code each one by one? Also, I created each rectangle individually and am running through a loop on the canvas. Is there a way perhaps using Math.random that would allow me to do this? One last item, I heard that there is a way to code collision detection based on color, i.e. when the bird runs into the color green anywhere on the canvas, collision is detected. If so, "How is this written"?

25th Mar 2022, 9:47 PM
Robert Haugland
Robert Haugland - avatar
1 Resposta
+ 1
Check this code I did as part of a coding challenge. It does collision detection with the enemy objects. https://github.com/pksjw/classic-arcade-game-clone/blob/master/js/app.js You would need an object or array or some way to refer to them generically to test for some condition.. if a[x] or if this.x...
25th Mar 2022, 9:54 PM
Paul K Sadler
Paul K Sadler - avatar