- Made some changes to object code
[supertux.git] / src / world.h
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2000 Bill Kendrick <bill@newbreedsoftware.com>
5 //  Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
6 //  Copyright (C) 2004 Ingo Ruhnke <grumbel@gmx.de>
7 //
8 //  This program is free software; you can redistribute it and/or
9 //  modify it under the terms of the GNU General Public License
10 //  as published by the Free Software Foundation; either version 2
11 //  of the License, or (at your option) any later version.
12 //
13 //  This program is distributed in the hope that it will be useful,
14 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 //  GNU General Public License for more details.
17 // 
18 //  You should have received a copy of the GNU General Public License
19 //  along with this program; if not, write to the Free Software
20 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21
22 #ifndef SUPERTUX_WORLD_H
23 #define SUPERTUX_WORLD_H
24
25 #include <vector>
26 #include <SDL.h>
27 #include "type.h"
28 #include "scene.h"
29 #include "special.h"
30 #include "badguy.h"
31 #include "particlesystem.h"
32 #include "gameobjs.h"
33
34 class Level;
35
36 /** The World class holds a level and all the game objects (badguys,
37     bouncy distros, etc) that are needed to run a game. */
38 class World
39 {
40 private:
41   typedef std::list<BadGuy*> BadGuys;
42   BadGuys bad_guys_to_add;
43   typedef std::list<Trampoline*> Trampolines;
44   Trampolines trampolines;
45   Level* level;
46   Player tux;
47
48   Timer scrolling_timer;
49
50   int distro_counter;
51   bool counting_distros;
52   int currentmusic;
53
54   static World* current_;
55 public:
56   BadGuys bad_guys;
57   std::vector<BouncyDistro*> bouncy_distros;
58   std::vector<BrokenBrick*>  broken_bricks;
59   std::vector<BouncyBrick*>  bouncy_bricks;
60   std::vector<FloatingScore*> floating_scores;
61
62   std::vector<Upgrade> upgrades;
63   std::vector<Bullet> bullets;
64   typedef std::vector<ParticleSystem*> ParticleSystems;
65   ParticleSystems particle_systems;
66
67 public:
68   static World* current() { return current_; }
69   static void set_current(World* w) { current_ = w; }
70
71   World(const std::string& filename);
72   World(const std::string& subset, int level_nr);
73   World() {};
74   ~World();
75   
76   Level*  get_level() { return level; }
77   Player* get_tux() { return &tux; }
78
79   void set_defaults();
80
81   void draw();
82   void action(double frame_ratio);
83   void scrolling(double frame_ratio);   // camera scrolling
84
85   void play_music(int musictype);
86   int get_music_type();
87   
88
89   /** Checks for all possible collisions. And calls the
90       collision_handlers, which the collision_objects provide for this
91       case (or not). */
92   void collision_handler();
93   
94   void activate_particle_systems();
95   void activate_bad_guys();
96   void activate_objects();
97
98   void add_score(float x, float y, int s);
99   void add_bouncy_distro(float x, float y);
100   void add_broken_brick(Tile* tile, float x, float y);
101   void add_broken_brick_piece(Tile* tile, float x, float y, float xm, float ym);
102   void add_bouncy_brick(float x, float y);
103
104   BadGuy* add_bad_guy(float x, float y, BadGuyKind kind, bool stay_on_platform = false);
105   template <class T, class U> T* add_object(U data);
106
107   void add_upgrade(float x, float y, Direction dir, UpgradeKind kind);
108   void add_bullet(float x, float y, float xm, Direction dir);
109
110   /** Try to grab the coin at the given coordinates */
111   void trygrabdistro(float x, float y, int bounciness);
112
113   /** Try to break the brick at the given coordinates */
114   void trybreakbrick(float x, float y, bool small);
115
116   /** Try to get the content out of a bonus box, thus emptying it */
117   void tryemptybox(float x, float y, Direction col_side);
118
119   /** Try to bumb a badguy that might we walking above Tux, thus shaking
120       the tile which the badguy is walking on an killing him this way */
121   void trybumpbadguy(float x, float y);
122
123   /** Apply bonuses active in the player status, used to reactivate
124       bonuses from former levels */
125   void apply_bonuses();
126 };
127
128 /** FIMXE: Workaround for the leveleditor mainly */
129 extern World global_world;
130
131 #endif /*SUPERTUX_WORLD_H*/
132
133 /* Local Variables: */
134 /* mode:c++ */
135 /* End: */
136