Skn3 : Question about collisions

Monkey Forums/Monkey Programming/Skn3 : Question about collisions

Raz(Posted 2012) [#1]
Hallo!

Just saw you posted this link on the k&p facebook group :D http://www.skn3.com/junk/saucyhater2/game.html

I am wondering how you handle the collisions for this? Are you able to explain it without wasting too much of your own time (seriously, if it's not easy to explain, please don't :D)?

Ta


GC-Martijn(Posted 2012) [#2]
There are many ways.

To keep it simple draw an invisible 2d box around the enemy's and the player.
If the enemy's box (size/2) hits the player box, it collides.

But as I say there are many ways.


Skn3(Posted 2012) [#3]
I probably wasted the whole day today anyways, haha!

Well its using the flixel collision stuff but it goes something like this:

- create some groups, lets say Group:"enemies" and Group:"bullets"
- add objects to groups (some enemies and some bullets, naturally)
- Check collision against two groups at a time.. eg Collide(enemies,players)
- each collision found in that check a callback is fired on each of the two objects that collide OnOverlapNotify(object1,object2)

Now Id imagine you probably meant how did I make them all push around like that? Well that's down to Flixel :D It lets you configure your objects and set a mass, as well as other properties. There is basic 2d physics stuff built in!

You should definitely give monkey flixel a try. Literally as we were developing the demo you linked to, somone said.. "hey I wonder what will happen if we make the enemies collide with the enemies?"

FlxG.Collide(colEnemies, colEnemies, self)


...this code was inserted in the main update code and we hit compile. At that point all three of us were awestruck at the result. At that point we had only had about 3 hours of picking up Flixel so it was a fun moment :)


Raz(Posted 2012) [#4]
Now Id imagine you probably meant how did I make them all push around like that?


Thanks man :D Yeah, that's the part I was interested in, I saw it and thought "this is perfect for what I want!" well chuffed to hear it seems quite simple so I will give Monkey Flixel a look :)