From: Matthias Braun Date: Sat, 20 May 2006 12:10:49 +0000 (+0000) Subject: some comments about collision detection X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=9ec9b558e82b12be82072a12092390dc48ad707a;p=supertux.git some comments about collision detection SVN-Revision: 3551 --- diff --git a/src/moving_object.hpp b/src/moving_object.hpp index d18615f1b..2981829e9 100644 --- a/src/moving_object.hpp +++ b/src/moving_object.hpp @@ -30,15 +30,44 @@ class Sector; class CollisionGrid; enum CollisionGroup { + /** Objects in DISABLED group are not tested for collisions */ COLGROUP_DISABLED, + /** + * "default" is moving object. MovingObjects get tested against all other + * objects and against other movingobjects + */ COLGROUP_MOVING, - // moving object but don't collide against other moving objects + /** + * a Moving object, that is not tested against other MovingObjects (or other + * MovingOnlyStatic objects), but is tested against all other objects. + */ COLGROUP_MOVING_ONLY_STATIC, + /** + * Doesn't move and isn't explicitely checked for collisions with other + * objects (but other objects might check with this) + * The difference to COLGROUP_TOUCHABLE is that we can do multiple + * collision response tests in a row which is needed for static object + * that tux walks on. The results for collisions with STATIC objects + * are also sorted by time (so that the first hit gets handled first). + * + * Use this for static obstacles + */ COLGROUP_STATIC, - COLGROUP_MOVINGSTATIC, + /** + * Isn't explicitely checked for collisions with other objects. But other + * objects might check with this object. + * Difference to COLGROUP_STATIC is that collisions with this object are + * only tested once and collision response is typically not handled + * + * Use this for touchable things like spikes/areas or collectibles like + * coins + */ COLGROUP_TOUCHABLE, - COLGROUP_TILEMAP /* not really used at the moment */ + /** + * Should be used for tilemaps + */ + COLGROUP_TILEMAP }; /** diff --git a/src/object/player.cpp b/src/object/player.cpp index 14c20e3b0..80046081a 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -855,7 +855,7 @@ Player::collision(GameObject& other, const CollisionHit& hit) BadGuy* badguy = dynamic_cast (&other); if(badguy != NULL) { - if(safe_timer.started()) + if(safe_timer.started() || invincible_timer.started()) return FORCE_MOVE; return CONTINUE; @@ -879,8 +879,7 @@ Player::kill(bool completely) if(dying || deactivated) return; - if(!completely && - (safe_timer.get_timeleft() > 0 || invincible_timer.get_timeleft() > 0)) + if(!completely && safe_timer.started() || invincible_timer.started()) return; sound_manager->play("sounds/hurt.wav"); diff --git a/src/sector.hpp b/src/sector.hpp index 7a973966d..7a7a7425e 100644 --- a/src/sector.hpp +++ b/src/sector.hpp @@ -156,14 +156,28 @@ private: void try_expose(GameObject* object); void try_unexpose(GameObject* object); - bool collision_static(MovingObject* object, const Vector& movement); - /** Checks for all possible collisions. And calls the collision_handlers, which the collision_objects provide for this case (or not). */ void handle_collisions(); - + + /** + * Collision checks 2 objects against each other and does instant + * collision response handling in case of a collision + */ void collision_object(MovingObject* object1, MovingObject* object2) const; + + /** + * Does collision detection of an object against all other static + * objects (and the tilemap) in the level. Collisions are sorted + * and collision response against the first hit is done. + * + * returns true if the collision detection should be aborted for this object + * (because of ABORT_MOVE in the collision response) + */ + bool collision_static(MovingObject* object, const Vector& movement); + + GameObject* parse_object(const std::string& name, const lisp::Lisp& lisp); void fix_old_tiles();