java - What is the logic behind collision detection in 2d games? -


this question has answer here:

i want create 2d game tile based map. main problem collision. if there tree in way, how make sprite not move through tree?

pseudo-code:

some_event() {     if (bullet.x == monster.x && bullet.y == monster.y) {         collision_occurs();     } } 

of course semantics such event fired , whether or not event handler makes more sense (i.e.: collision_occurs() when x , y coordinates meet, rather if meet while some_event() fired) depend on game.

if analyze more notice bullet , monster aren't 1 pixel each, more like:

// while approaching left if ((bullet.x + (bullet.radius)) >= (monster.x + (monster.radius))) 

these fine details come after. have moving objects , these objects share coordinates. when these coordinates, properties of representational objects, near enough, "collision" occurs , methodology follows.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -