-converted remaining classes to GameObject
[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 #include "display_manager.h"
34
35 class Level;
36
37 /** The World class holds a level and all the game objects (badguys,
38     bouncy distros, etc) that are needed to run a game. */
39 class World
40 {
41 private:
42   typedef std::list<BadGuy*> BadGuys;
43   BadGuys bad_guys_to_add;
44   typedef std::list<Trampoline*> Trampolines;
45   Trampolines trampolines;
46   Level* level;
47   Player* tux;
48
49   Timer scrolling_timer;
50
51   int distro_counter;
52   bool counting_distros;
53   int currentmusic;
54
55   static World* current_;
56 public:
57   BadGuys bad_guys;
58
59   std::vector<Upgrade*> upgrades;
60   std::vector<Bullet*> bullets;
61   std::vector<GameObject*> gameobjects;
62
63   DisplayManager displaymanager;
64
65 public:
66   static World* current() { return current_; }
67   static void set_current(World* w) { current_ = w; }
68
69   World(const std::string& filename);
70   World(const std::string& subset, int level_nr);
71   //World() {};
72   ~World();
73   
74   Level*  get_level() { return level; }
75   Player* get_tux() { return tux; }
76
77   void add_object(GameObject* object);
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   /** Checks for all possible collisions. And calls the
89       collision_handlers, which the collision_objects provide for this
90       case (or not). */
91   void collision_handler();
92
93   void parse_objects(lisp_object_t* cur);
94   
95   void activate_particle_systems();
96
97   void add_score(const Vector& pos, int s);
98   void add_bouncy_distro(const Vector& pos);
99   void add_broken_brick(const Vector& pos, Tile* tile);
100   void add_broken_brick_piece(const Vector& pos,
101       const Vector& movement, Tile* tile);
102   void add_bouncy_brick(const Vector& pos);
103
104   BadGuy* add_bad_guy(float x, float y, BadGuyKind kind);
105
106   void add_upgrade(const Vector& pos, Direction dir, UpgradeKind kind);
107   void add_bullet(const Vector& pos, float xm, Direction dir);
108
109   /** Try to grab the coin at the given coordinates */
110   void trygrabdistro(float x, float y, int bounciness);
111
112   /** Try to break the brick at the given coordinates */
113   bool trybreakbrick(float x, float y, bool small);
114
115   /** Try to get the content out of a bonus box, thus emptying it */
116   void tryemptybox(float x, float y, Direction col_side);
117
118   /** Try to bumb a badguy that might we walking above Tux, thus shaking
119       the tile which the badguy is walking on an killing him this way */
120   void trybumpbadguy(float x, float y);
121
122   /** Apply bonuses active in the player status, used to reactivate
123       bonuses from former levels */
124   void apply_bonuses();
125 };
126
127 /** FIMXE: Workaround for the leveleditor mainly */
128 extern World global_world;
129
130 #endif /*SUPERTUX_WORLD_H*/
131
132 /* Local Variables: */
133 /* mode:c++ */
134 /* End: */
135