1 #ifndef __COLLISION_GRID_H__
2 #define __COLLISION_GRID_H__
5 #include "special/moving_object.h"
7 using namespace SuperTux;
9 class CollisionGridIterator;
12 * A rectangular grid to keep track of all moving game objects. It allows fast
13 * queries for all objects in a rectangular area.
18 CollisionGrid(float width, float height);
21 void add_object(MovingObject* object);
22 void remove_object(MovingObject* object);
24 void check_collisions();
27 friend class CollisionGridIterator;
33 /** (pseudo) timestamp. When reading from the grid the timestamp is
34 * changed so that you can easily avoid reading an object multiple times
35 * when it is in several cells that you check.
38 /// index in the objects vector
42 /** Element for the single linked list in each grid cell */
46 ObjectWrapper* object_wrapper;
49 void remove_object_from_gridcell(int gridcell, ObjectWrapper* wrapper);
50 void collide_object(ObjectWrapper* wrapper);
51 void collide_object_object(ObjectWrapper* wrapper, ObjectWrapper* wrapper2);
52 void move_object(ObjectWrapper* wrapper);
54 typedef std::vector<GridEntry*> GridEntries;
56 typedef std::vector<ObjectWrapper*> Objects;
58 size_t cells_x, cells_y;
63 int iterator_timestamp;
66 extern CollisionGrid* bla;