java - What is the logic behind collision detection in 2d games? -
this question has answer here:
- collision detection complex shapes 1 answer
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
Post a Comment