5c53c36f957e61535240c9924e38216e89c20854
[supertux.git] / src / world.h
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2004 SuperTux Development Team, see AUTHORS for details
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 // 
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20 #ifndef SUPERTUX_WORLD_H
21 #define SUPERTUX_WORLD_H
22
23 #include <vector>
24 #include <SDL.h>
25 #include "type.h"
26 #include "scene.h"
27 #include "special.h"
28 #include "particlesystem.h"
29 #include "gameobjs.h"
30
31 /** The World class holds a level and all the game objects (badguys,
32     bouncy distros, etc) that are needed to run a game. */
33 class World
34 {
35  public:
36   Level* level;
37   
38   std::vector<BouncyDistro> bouncy_distros;
39   std::vector<BrokenBrick>  broken_bricks;
40   std::vector<BouncyBrick>  bouncy_bricks;
41   std::vector<FloatingScore> floating_scores;
42
43   std::vector<BadGuy> bad_guys;
44   std::vector<upgrade_type> upgrades;
45   std::vector<bullet_type> bullets;
46   std::vector<ParticleSystem*> particle_systems;
47
48   static World* current_;
49  public:
50   static World* current() { return current_; }
51
52   World();
53   ~World();
54   
55   Level* get_level() { return level; }
56
57   void set_defaults();
58
59   void draw();
60   void action();
61
62   /** Checks for all possible collisions. And calls the
63       collision_handlers, which the collision_objects provide for this
64       case (or not). */
65   void collision_handler();
66   
67   void arrays_free();
68
69   /** Load data for this level: 
70       Returns -1, if the loading of the level failed. */
71   int  load(const char* subset, int level);
72
73   /** Load data for this level: 
74       Returns -1, if the loading of the level failed. */
75   int  load(const std::string& filename);
76
77   void activate_particle_systems();
78   void activate_bad_guys();
79
80   void add_score(float x, float y, int s);
81   void add_bouncy_distro(float x, float y);
82   void add_broken_brick(Tile* tile, float x, float y);
83   void add_broken_brick_piece(Tile* tile, float x, float y, float xm, float ym);
84   void add_bouncy_brick(float x, float y);
85   void add_bad_guy(float x, float y, BadGuyKind kind);
86   void add_upgrade(float x, float y, int dir, int kind);
87   void add_bullet(float x, float y, float xm, int dir);
88
89   /** Try to grab the coin at the given coordinates */
90   void trygrabdistro(float x, float y, int bounciness);
91
92   /** Try to break the brick at the given coordinates */
93   void trybreakbrick(float x, float y, bool small);
94
95   /** Try to get the content out of a bonus box, thus emptying it */
96   void tryemptybox(float x, float y, int col_side);
97
98   /** Try to bumb a badguy that might we walking above Tux, thus shaking
99       the tile which the badguy is walking on an killing him this way */
100   void trybumpbadguy(float x, float y);
101 };
102
103 extern World world;
104
105 #endif /*SUPERTUX_WORLD_H*/
106