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