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);
23 void move_object(MovingObject* object);
25 void check_collisions();
32 /** (pseudo) timestamp. When reading from the grid the timestamp is
33 * changed so that you can easily avoid reading an object multiple times
34 * when it is in several cells that you check.
37 /// index in the objects vector
41 /** Element for the single linked list in each grid cell */
45 ObjectWrapper* object_wrapper;
48 void remove_object_from_gridcell(int gridcell, MovingObject* object);
49 void collide_object(ObjectWrapper* wrapper);
50 void collide_object_object(ObjectWrapper* wrapper, ObjectWrapper* wrapper2);
52 typedef std::vector<GridEntry*> GridEntries;
54 typedef std::vector<ObjectWrapper*> Objects;
56 size_t cells_x, cells_y;
63 extern CollisionGrid* bla;