- moved stuff from gamesession to world
[supertux.git] / src / world.h
1 //
2 // Interface: world
3 //
4 // Description: 
5 //
6 //
7 // Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2003
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12
13 #ifndef SUPERTUX_WORLD_H
14 #define SUPERTUX_WORLD_H
15
16 #include <vector>
17 #include <SDL.h>
18 #include "type.h"
19 #include "scene.h"
20 #include "special.h"
21 #include "particlesystem.h"
22
23 /* Bounciness of distros: */
24
25 #define NO_BOUNCE 0
26 #define BOUNCE 1
27
28 struct bouncy_distro_type
29 {
30   base_type base;
31 };
32
33 extern texture_type img_distro[4];
34
35 void bouncy_distro_init(bouncy_distro_type* pbouncy_distro, float x, float y);
36 void bouncy_distro_action(bouncy_distro_type* pbouncy_distro);
37 void bouncy_distro_draw(bouncy_distro_type* pbouncy_distro);
38 void bouncy_distro_collision(bouncy_distro_type* pbouncy_distro, int c_object);
39
40 #define BOUNCY_BRICK_MAX_OFFSET 8
41 #define BOUNCY_BRICK_SPEED 0.9
42
43 struct broken_brick_type
44 {
45   base_type base;
46   timer_type timer;
47   Tile* tile;
48 };
49
50 void broken_brick_init(broken_brick_type* pbroken_brick, Tile* tile,
51                        float x, float y, float xm, float ym);
52 void broken_brick_action(broken_brick_type* pbroken_brick);
53 void broken_brick_draw(broken_brick_type* pbroken_brick);
54
55 struct bouncy_brick_type
56 {
57   float offset;
58   float offset_m;
59   int shape;
60   base_type base;
61 };
62
63 void bouncy_brick_init(bouncy_brick_type* pbouncy_brick, float x, float y);
64 void bouncy_brick_action(bouncy_brick_type* pbouncy_brick);
65 void bouncy_brick_draw(bouncy_brick_type* pbouncy_brick);
66
67 struct floating_score_type
68 {
69   int value;
70   timer_type timer;
71   base_type base;
72 };
73
74 void floating_score_init(floating_score_type* pfloating_score, float x, float y, int s);
75 void floating_score_action(floating_score_type* pfloating_score);
76 void floating_score_draw(floating_score_type* pfloating_score);
77
78 /** Try to grab the coin at the given coordinates */
79 void trygrabdistro(float x, float y, int bounciness);
80
81 /** Try to break the brick at the given coordinates */
82 void trybreakbrick(float x, float y, bool small);
83
84 /** Try to get the content out of a bonus box, thus emptying it */
85 void tryemptybox(float x, float y, int col_side);
86
87 /** Try to bumb a badguy that might we walking above Tux, thus shaking
88     the tile which the badguy is walking on an killing him this way */
89 void trybumpbadguy(float x, float y);
90
91
92 /** The World class holds a level and all the game objects (badguys,
93     bouncy distros, etc) that are needed to run a game. */
94 class World
95 {
96  public:
97   Level* level;
98   
99   std::vector<bouncy_distro_type> bouncy_distros;
100   std::vector<broken_brick_type> broken_bricks;
101   std::vector<bouncy_brick_type> bouncy_bricks;
102   std::vector<BadGuy> bad_guys;
103   std::vector<floating_score_type> floating_scores;
104   std::vector<upgrade_type> upgrades;
105   std::vector<bullet_type> bullets;
106   std::vector<ParticleSystem*> particle_systems;
107
108  public:
109   World();
110   ~World();
111   
112   Level* get_level() { return level; }
113
114   void draw();
115   void action();
116   void arrays_free();
117
118   /** Load data for this level: 
119       Returns -1, if the loading of the level failed. */
120   int  load(const char* subset, int level);
121
122   /** Load data for this level: 
123       Returns -1, if the loading of the level failed. */
124   int  load(const std::string& filename);
125
126   void activate_particle_systems();
127
128   void add_score(float x, float y, int s);
129   void add_bouncy_distro(float x, float y);
130   void add_broken_brick(Tile* tile, float x, float y);
131   void add_broken_brick_piece(Tile* tile, float x, float y, float xm, float ym);
132   void add_bouncy_brick(float x, float y);
133   void add_bad_guy(float x, float y, BadGuyKind kind);
134   void add_upgrade(float x, float y, int dir, int kind);
135   void add_bullet(float x, float y, float xm, int dir);
136 };
137
138 extern World world;
139
140 #endif /*SUPERTUX_WORLD_H*/
141