- moved gameobjects into there own file
authorIngo Ruhnke <grumbel@gmx.de>
Sun, 11 Apr 2004 11:52:29 +0000 (11:52 +0000)
committerIngo Ruhnke <grumbel@gmx.de>
Sun, 11 Apr 2004 11:52:29 +0000 (11:52 +0000)
- moved drawshape to tile.h

SVN-Revision: 468

16 files changed:
src/Makefile.am
src/badguy.cpp
src/collision.cpp
src/gameloop.cpp
src/gameobjs.cpp [new file with mode: 0644]
src/gameobjs.h [new file with mode: 0644]
src/level.h
src/leveleditor.cpp
src/resources.cpp
src/scene.cpp
src/scene.h
src/tile.cpp
src/tile.h
src/title.cpp
src/world.cpp
src/world.h

index bbf335a..e0d711e 100644 (file)
@@ -1,7 +1,7 @@
 bin_PROGRAMS = supertux
 
 supertux_SOURCES = \
-badguy.cpp badguy.h bitmask.cpp bitmask.h button.cpp button.h collision.cpp collision.h configfile.cpp configfile.h defines.h gameloop.cpp gameloop.h globals.cpp globals.h high_scores.cpp high_scores.h intro.cpp intro.h level.cpp level.h leveleditor.cpp leveleditor.h lispreader.cpp lispreader.h menu.cpp menu.h particlesystem.cpp particlesystem.h physic.cpp physic.h player.cpp player.h scene.cpp scene.h screen.cpp screen.h setup.cpp setup.h sound.cpp sound.h special.cpp special.h supertux.cpp supertux.h text.cpp text.h texture.cpp texture.h timer.cpp timer.h title.cpp title.h type.cpp type.h world.cpp world.h worldmap.cpp worldmap.h tile.h tile.cpp mousecursor.cpp mousecursor.h resources.h resources.cpp
+badguy.cpp badguy.h bitmask.cpp bitmask.h button.cpp button.h collision.cpp collision.h configfile.cpp configfile.h defines.h gameloop.cpp gameloop.h globals.cpp globals.h high_scores.cpp high_scores.h intro.cpp intro.h level.cpp level.h leveleditor.cpp leveleditor.h lispreader.cpp lispreader.h menu.cpp menu.h particlesystem.cpp particlesystem.h physic.cpp physic.h player.cpp player.h scene.cpp scene.h screen.cpp screen.h setup.cpp setup.h sound.cpp sound.h special.cpp special.h supertux.cpp supertux.h text.cpp text.h texture.cpp texture.h timer.cpp timer.h title.cpp title.h type.cpp type.h world.cpp world.h worldmap.cpp worldmap.h tile.h tile.cpp mousecursor.cpp mousecursor.h resources.h resources.cpp gameobjs.h gameobjs.cpp
 
 # EOF #
 noinst_HEADERS = 
index 4b2b7db..723dd30 100644 (file)
@@ -16,6 +16,7 @@
 #include "badguy.h"
 #include "scene.h"
 #include "screen.h"
+#include "world.h"
 #include "tile.h"
 
 texture_type img_bsod_squished_left[1];
index 17164c5..de62b7a 100644 (file)
@@ -14,6 +14,7 @@
 #include "collision.h"
 #include "bitmask.h"
 #include "scene.h"
+#include "world.h"
 #include "tile.h"
 
 bool rectcollision(base_type* one, base_type* two)
@@ -285,7 +286,7 @@ void collision_handler()
 
 Tile* gettile(float x, float y)
 {
-  return TileManager::instance()->get(GameSession::current()->get_level()->gettileid(x, y));
+  return TileManager::instance()->get(World::current()->get_level()->gettileid(x, y));
 }
 
 bool issolid(float x, float y)
index 93c5aef..e18a80b 100644 (file)
@@ -102,7 +102,7 @@ GameSession::GameSession(const std::string& subset, int levelnb, int mode)
 
   /* Init the game: */
   world->arrays_free();
-  set_defaults();
+  world->set_defaults();
 
   strcpy(level_subset, subset.c_str());
 
@@ -397,7 +397,7 @@ GameSession::action()
 
       /* Either way, (re-)load the (next) level... */
       tux.level_begin();
-      set_defaults();
+      world->set_defaults();
       
       world->get_level()->cleanup();
 
@@ -655,31 +655,6 @@ GameSession::run()
   return(quit);
 }
 
-/* Draw a tile on the screen: */
-
-void drawshape(float x, float y, unsigned int c, Uint8 alpha)
-{
-  if (c != 0)
-    {
-      Tile* ptile = TileManager::instance()->get(c);
-      if(ptile)
-        {
-          if(ptile->images.size() > 1)
-            {
-              texture_draw(&ptile->images[( ((global_frame_counter*25) / ptile->anim_speed) % (ptile->images.size()))],x,y, alpha);
-            }
-          else if (ptile->images.size() == 1)
-            {
-              texture_draw(&ptile->images[0],x,y, alpha);
-            }
-          else
-            {
-              //printf("Tile not dravable %u\n", c);
-            }
-        }
-    }
-}
-
 /* Bounce a brick: */
 void bumpbrick(float x, float y)
 {
@@ -836,18 +811,18 @@ GameSession::loadgame(int slot)
       level_subset[strlen(level_subset)-1] = '\0';
       fread(&level,sizeof(int),1,fi);
 
-      set_defaults();
+      world->set_defaults();
       world->get_level()->cleanup();
       world->arrays_free();
+      world->get_level()->free_gfx();
+      world->get_level()->free_song();
 
       if(world->get_level()->load(level_subset,level) != 0)
         exit(1);
+
       world->activate_bad_guys();
       world->activate_particle_systems();
-      
-      world->get_level()->free_gfx();
       world->get_level()->load_gfx();
-      world->get_level()->free_song();
       world->get_level()->load_song();
 
       levelintro();
diff --git a/src/gameobjs.cpp b/src/gameobjs.cpp
new file mode 100644 (file)
index 0000000..f166305
--- /dev/null
@@ -0,0 +1,158 @@
+#include "world.h"
+#include "tile.h"
+#include "gameloop.h"
+#include "gameobjs.h"
+
+void bouncy_distro_init(bouncy_distro_type* pbouncy_distro, float x, float y)
+{
+  pbouncy_distro->base.x = x;
+  pbouncy_distro->base.y = y;
+  pbouncy_distro->base.ym = -2;
+}
+
+void bouncy_distro_action(bouncy_distro_type* pbouncy_distro)
+{
+  pbouncy_distro->base.y = pbouncy_distro->base.y + pbouncy_distro->base.ym * frame_ratio;
+
+  pbouncy_distro->base.ym += 0.1 * frame_ratio;
+
+  if (pbouncy_distro->base.ym >= 0)
+    world.bouncy_distros.erase(static_cast<std::vector<bouncy_distro_type>::iterator>(pbouncy_distro));
+}
+
+void bouncy_distro_draw(bouncy_distro_type* pbouncy_distro)
+{
+  texture_draw(&img_distro[0],
+               pbouncy_distro->base.x - scroll_x,
+               pbouncy_distro->base.y);
+}
+
+void broken_brick_init(broken_brick_type* pbroken_brick, Tile* tile, 
+                       float x, float y, float xm, float ym)
+{
+  pbroken_brick->tile   = tile;
+  pbroken_brick->base.x = x;
+  pbroken_brick->base.y = y;
+  pbroken_brick->base.xm = xm;
+  pbroken_brick->base.ym = ym;
+
+  timer_init(&pbroken_brick->timer, true);
+  timer_start(&pbroken_brick->timer,200);
+}
+
+void broken_brick_action(broken_brick_type* pbroken_brick)
+{
+  pbroken_brick->base.x = pbroken_brick->base.x + pbroken_brick->base.xm * frame_ratio;
+  pbroken_brick->base.y = pbroken_brick->base.y + pbroken_brick->base.ym * frame_ratio;
+
+  if (!timer_check(&pbroken_brick->timer))
+    world.broken_bricks.erase(static_cast<std::vector<broken_brick_type>::iterator>(pbroken_brick));
+}
+
+void broken_brick_draw(broken_brick_type* pbroken_brick)
+{
+  SDL_Rect src, dest;
+  src.x = rand() % 16;
+  src.y = rand() % 16;
+  src.w = 16;
+  src.h = 16;
+
+  dest.x = (int)(pbroken_brick->base.x - scroll_x);
+  dest.y = (int)pbroken_brick->base.y;
+  dest.w = 16;
+  dest.h = 16;
+  
+  if (pbroken_brick->tile->images.size() > 0)
+    texture_draw_part(&pbroken_brick->tile->images[0],
+                      src.x,src.y,dest.x,dest.y,dest.w,dest.h);
+}
+
+void bouncy_brick_init(bouncy_brick_type* pbouncy_brick, float x, float y)
+{
+  pbouncy_brick->base.x   = x;
+  pbouncy_brick->base.y   = y;
+  pbouncy_brick->offset   = 0;
+  pbouncy_brick->offset_m = -BOUNCY_BRICK_SPEED;
+  pbouncy_brick->shape    = GameSession::current()->get_level()->gettileid(x, y);
+}
+
+void bouncy_brick_action(bouncy_brick_type* pbouncy_brick)
+{
+
+  pbouncy_brick->offset = (pbouncy_brick->offset +
+                           pbouncy_brick->offset_m * frame_ratio);
+
+  /* Go back down? */
+
+  if (pbouncy_brick->offset < -BOUNCY_BRICK_MAX_OFFSET)
+    pbouncy_brick->offset_m = BOUNCY_BRICK_SPEED;
+
+
+  /* Stop bouncing? */
+
+  if (pbouncy_brick->offset >= 0)
+    world.bouncy_bricks.erase(static_cast<std::vector<bouncy_brick_type>::iterator>(pbouncy_brick));
+}
+
+void bouncy_brick_draw(bouncy_brick_type* pbouncy_brick)
+{
+  int s;
+  SDL_Rect dest;
+  
+  if (pbouncy_brick->base.x >= scroll_x - 32 &&
+      pbouncy_brick->base.x <= scroll_x + screen->w)
+    {
+      dest.x = (int)(pbouncy_brick->base.x - scroll_x);
+      dest.y = (int)pbouncy_brick->base.y;
+      dest.w = 32;
+      dest.h = 32;
+
+      Level* plevel = GameSession::current()->get_level();
+
+      // FIXME: overdrawing hack to clean the tile from the screen to
+      // paint it later at on offseted position
+      if(plevel->bkgd_image[0] == '\0')
+        {
+          fillrect(pbouncy_brick->base.x - scroll_x, pbouncy_brick->base.y,
+                   32,32, 
+                   plevel->bkgd_red, plevel->bkgd_green, plevel->bkgd_blue, 0);
+        }
+      else
+        {
+          s = (int)scroll_x / 30;
+          texture_draw_part(&plevel->img_bkgd, dest.x + s, dest.y, 
+                            dest.x, dest.y,dest.w,dest.h);
+        }
+
+      Tile::draw(pbouncy_brick->base.x - scroll_x,
+                 pbouncy_brick->base.y + pbouncy_brick->offset,
+                 pbouncy_brick->shape);
+    }
+}
+
+void floating_score_init(floating_score_type* pfloating_score, float x, float y, int s)
+{
+  pfloating_score->base.x = x;
+  pfloating_score->base.y = y - 16;
+  timer_init(&pfloating_score->timer,true);
+  timer_start(&pfloating_score->timer,1000);
+  pfloating_score->value = s;
+}
+
+void floating_score_action(floating_score_type* pfloating_score)
+{
+  pfloating_score->base.y = pfloating_score->base.y - 2 * frame_ratio;
+
+  if(!timer_check(&pfloating_score->timer))
+    world.floating_scores.erase(static_cast<std::vector<floating_score_type>::iterator>(pfloating_score));
+}
+
+void floating_score_draw(floating_score_type* pfloating_score)
+{
+  char str[10];
+  sprintf(str, "%d", pfloating_score->value);
+  text_draw(&gold_text, str, (int)pfloating_score->base.x + 16 - strlen(str) * 8, (int)pfloating_score->base.y, 1);
+}
+
+/* EOF */
+
diff --git a/src/gameobjs.h b/src/gameobjs.h
new file mode 100644 (file)
index 0000000..2e24a34
--- /dev/null
@@ -0,0 +1,74 @@
+
+#ifndef SUPERTUX_GAMEOBJS_H
+#define SUPERTUX_GAMEOBJS_H
+
+#include "type.h"
+#include "texture.h"
+#include "timer.h"
+#include "scene.h"
+
+/* Bounciness of distros: */
+#define NO_BOUNCE 0
+#define BOUNCE 1
+
+class bouncy_distro_type
+{
+ public:
+  base_type base;
+};
+
+extern texture_type img_distro[4];
+
+void bouncy_distro_init(bouncy_distro_type* pbouncy_distro, float x, float y);
+void bouncy_distro_action(bouncy_distro_type* pbouncy_distro);
+void bouncy_distro_draw(bouncy_distro_type* pbouncy_distro);
+void bouncy_distro_collision(bouncy_distro_type* pbouncy_distro, int c_object);
+
+#define BOUNCY_BRICK_MAX_OFFSET 8
+#define BOUNCY_BRICK_SPEED 0.9
+
+class Tile;
+
+class broken_brick_type
+{
+ public:
+  base_type base;
+  timer_type timer;
+  Tile* tile;
+};
+
+void broken_brick_init(broken_brick_type* pbroken_brick, Tile* tile,
+                       float x, float y, float xm, float ym);
+void broken_brick_action(broken_brick_type* pbroken_brick);
+void broken_brick_draw(broken_brick_type* pbroken_brick);
+
+class bouncy_brick_type
+{
+ public:
+  float offset;
+  float offset_m;
+  int shape;
+  base_type base;
+};
+
+void bouncy_brick_init(bouncy_brick_type* pbouncy_brick, float x, float y);
+void bouncy_brick_action(bouncy_brick_type* pbouncy_brick);
+void bouncy_brick_draw(bouncy_brick_type* pbouncy_brick);
+
+class floating_score_type
+{
+ public:
+  int value;
+  timer_type timer;
+  base_type base;
+};
+
+void floating_score_init(floating_score_type* pfloating_score, float x, float y, int s);
+void floating_score_action(floating_score_type* pfloating_score);
+void floating_score_draw(floating_score_type* pfloating_score);
+
+#endif 
+
+/* Local Variables: */
+/* mode:c++ */
+/* End */
index dfb1c1e..5a8dd9c 100644 (file)
@@ -107,5 +107,4 @@ class Level
   void load_image(texture_type* ptexture, std::string theme, const char * file, int use_alpha);
 };
 
-
 #endif /*SUPERTUX_LEVEL_H*/
index 6d16632..2a4d648 100644 (file)
 #include <SDL_image.h>
 #include "leveleditor.h"
 
+#include "world.h"
 #include "screen.h"
 #include "defines.h"
 #include "globals.h"
 #include "setup.h"
 #include "menu.h"
 #include "level.h"
+#include "gameloop.h"
 #include "badguy.h"
 #include "scene.h"
 #include "button.h"
@@ -635,7 +637,7 @@ void le_drawinterface()
 
   /* draw button bar */
   fillrect(screen->w - 64, 0, 64, screen->h, 50, 50, 50,255);
-  drawshape(19 * 32, 14 * 32, le_current_tile);
+  Tile::draw(19 * 32, 14 * 32, le_current_tile);
   
        if(TileManager::instance()->get(le_current_tile)->editor_images.size() > 0)
        texture_draw(&TileManager::instance()->get(le_current_tile)->editor_images[0], 19 * 32, 14 * 32);
@@ -703,21 +705,21 @@ void le_drawlevel()
        else
        a = 128;
       
-       drawshape(32*x - fmodf(pos_x, 32), y * 32, le_current_level->bg_tiles[y][x + (int)(pos_x / 32)],a);
+       Tile::draw(32*x - fmodf(pos_x, 32), y * 32, le_current_level->bg_tiles[y][x + (int)(pos_x / 32)],a);
        
        if(active_tm == TM_IA)
        a = 255;
        else
        a = 128;
        
-        drawshape(32*x - fmodf(pos_x, 32), y * 32, le_current_level->ia_tiles[y][x + (int)(pos_x / 32)],a);
+        Tile::draw(32*x - fmodf(pos_x, 32), y * 32, le_current_level->ia_tiles[y][x + (int)(pos_x / 32)],a);
 
        if(active_tm == TM_FG)
        a = 255;
        else
        a = 128;
        
-       drawshape(32*x - fmodf(pos_x, 32), y * 32, le_current_level->fg_tiles[y][x + (int)(pos_x / 32)],a);
+       Tile::draw(32*x - fmodf(pos_x, 32), y * 32, le_current_level->fg_tiles[y][x + (int)(pos_x / 32)],a);
        
         /* draw whats inside stuff when cursor is selecting those */
         /* (draw them all the time - is this the right behaviour?) */
index 829141d..7aee6bf 100644 (file)
@@ -2,6 +2,7 @@
 #include "scene.h"
 #include "player.h"
 #include "badguy.h"
+#include "gameobjs.h"
 #include "resources.h"
 
 texture_type img_waves[3]; 
@@ -251,7 +252,6 @@ void loadshared()
 
 
   /* Distros: */
-
   texture_load(&img_distro[0], datadir + "/images/shared/distro-0.png",
                USE_ALPHA);
 
index c9c506a..4eef38e 100644 (file)
@@ -36,22 +36,5 @@ texture_type img_red_glow;
 timer_type time_left;
 double frame_ratio;
 
-void set_defaults(void)
-{
-  // Set defaults: 
-  scroll_x = 0;
-
-  score_multiplier = 1;
-  timer_init(&super_bkgd_timer, true);
-
-  counting_distros = false;
-  distro_counter = 0;
-
-  endpos = 0;
-
-  /* set current song/music */
-  set_current_music(LEVEL_MUSIC);
-}
-
 // EOF //
 
index 6d0203a..e877d3b 100644 (file)
 #define SUPERTUX_SCENE_H
 
 #include "defines.h"
-#include "gameloop.h"
 #include "player.h"
 #include "badguy.h"
-#include "world.h"
 #include "special.h"
 #include "level.h"
 #include "particlesystem.h"
@@ -43,6 +41,4 @@ extern texture_type img_box_full, img_box_empty, img_mints, img_coffee, img_supe
 extern timer_type time_left;
 extern double frame_ratio;
 
-void set_defaults(void);
-
 #endif /*SUPERTUX_SCENE_H*/
index 3ced8ef..daa63f9 100644 (file)
@@ -10,6 +10,7 @@
 //
 //
 #include "tile.h"
+#include "scene.h"
 #include "assert.h"
 
 TileManager* TileManager::instance_  = 0;
@@ -134,5 +135,29 @@ void TileManager::load_tileset(std::string filename)
     }
 }
 
+void
+Tile::draw(float x, float y, unsigned int c, Uint8 alpha)
+{
+  if (c != 0)
+    {
+      Tile* ptile = TileManager::instance()->get(c);
+      if(ptile)
+        {
+          if(ptile->images.size() > 1)
+            {
+              texture_draw(&ptile->images[( ((global_frame_counter*25) / ptile->anim_speed) % (ptile->images.size()))],x,y, alpha);
+            }
+          else if (ptile->images.size() == 1)
+            {
+              texture_draw(&ptile->images[0],x,y, alpha);
+            }
+          else
+            {
+              //printf("Tile not dravable %u\n", c);
+            }
+        }
+    }
+}
+
 // EOF //
 
index 2175b2b..047bd70 100644 (file)
@@ -57,6 +57,9 @@ struct Tile
   int next_tile;
 
   int anim_speed;
+  
+  /** Draw a tile on the screen: */
+  static void draw(float x, float y, unsigned int c, Uint8 alpha = 255);
 };
 
 struct TileGroup
@@ -92,6 +95,4 @@ class TileManager
   }
 };
 
-
-
 #endif
index 38812ae..5761acd 100644 (file)
@@ -38,6 +38,7 @@
 #include "scene.h"
 #include "player.h"
 #include "math.h"
+#include "tile.h"
 
 void loadshared(void);
 
@@ -86,8 +87,8 @@ void draw_demo(Level* plevel)
     {
       for (int x = 0; x < 21; ++x)
         {
-          drawshape(32*x - fmodf(scroll_x, 32), y * 32,
-                    plevel->ia_tiles[(int)y][(int)x + (int)(scroll_x / 32)]);
+          Tile::draw(32*x - fmodf(scroll_x, 32), y * 32,
+                     plevel->ia_tiles[(int)y][(int)x + (int)(scroll_x / 32)]);
         }
     }
 
index b129cd5..96780b9 100644 (file)
 
 texture_type img_distro[4];
 
+World* World::current_ = 0;
+
 World world;
 
 World::World()
 {
+  // FIXME: Move this to action and draw and everywhere else where the
+  // world calls child functions
+  current_ = this;
+
   level = new Level;
 }
 
@@ -35,6 +41,24 @@ World::~World()
   delete level;
 }
 
+void
+World::set_defaults()
+{
+  // Set defaults: 
+  scroll_x = 0;
+
+  score_multiplier = 1;
+  timer_init(&super_bkgd_timer, true);
+
+  counting_distros = false;
+  distro_counter = 0;
+
+  endpos = 0;
+
+  /* set current song/music */
+  set_current_music(LEVEL_MUSIC);
+}
+
 int
 World::load(const char* subset, int level_nr)
 {
@@ -127,8 +151,8 @@ World::draw()
     {
       for (x = 0; x < 21; ++x)
         {
-          drawshape(32*x - fmodf(scroll_x, 32), y * 32,
-                    level->bg_tiles[(int)y][(int)x + (int)(scroll_x / 32)]);
+          Tile::draw(32*x - fmodf(scroll_x, 32), y * 32,
+                     level->bg_tiles[(int)y][(int)x + (int)(scroll_x / 32)]);
         }
     }
 
@@ -137,8 +161,8 @@ World::draw()
     {
       for (x = 0; x < 21; ++x)
         {
-          drawshape(32*x - fmodf(scroll_x, 32), y * 32,
-                    level->ia_tiles[(int)y][(int)x + (int)(scroll_x / 32)]);
+          Tile::draw(32*x - fmodf(scroll_x, 32), y * 32,
+                     level->ia_tiles[(int)y][(int)x + (int)(scroll_x / 32)]);
         }
     }
 
@@ -171,8 +195,8 @@ World::draw()
     {
       for (x = 0; x < 21; ++x)
         {
-          drawshape(32*x - fmodf(scroll_x, 32), y * 32,
-                    level->fg_tiles[(int)y][(int)x + (int)(scroll_x / 32)]);
+          Tile::draw(32*x - fmodf(scroll_x, 32), y * 32,
+                     level->fg_tiles[(int)y][(int)x + (int)(scroll_x / 32)]);
         }
     }
 
@@ -291,163 +315,10 @@ World::add_bullet(float x, float y, float xm, int dir)
   play_sound(sounds[SND_SHOOT], SOUND_CENTER_SPEAKER);
 }
 
-
-
-void bouncy_distro_init(bouncy_distro_type* pbouncy_distro, float x, float y)
-{
-  pbouncy_distro->base.x = x;
-  pbouncy_distro->base.y = y;
-  pbouncy_distro->base.ym = -2;
-}
-
-void bouncy_distro_action(bouncy_distro_type* pbouncy_distro)
-{
-  pbouncy_distro->base.y = pbouncy_distro->base.y + pbouncy_distro->base.ym * frame_ratio;
-
-  pbouncy_distro->base.ym += 0.1 * frame_ratio;
-
-  if (pbouncy_distro->base.ym >= 0)
-    world.bouncy_distros.erase(static_cast<std::vector<bouncy_distro_type>::iterator>(pbouncy_distro));
-}
-
-void bouncy_distro_draw(bouncy_distro_type* pbouncy_distro)
-{
-  texture_draw(&img_distro[0],
-               pbouncy_distro->base.x - scroll_x,
-               pbouncy_distro->base.y);
-}
-
-void broken_brick_init(broken_brick_type* pbroken_brick, Tile* tile, 
-                       float x, float y, float xm, float ym)
-{
-  pbroken_brick->tile   = tile;
-  pbroken_brick->base.x = x;
-  pbroken_brick->base.y = y;
-  pbroken_brick->base.xm = xm;
-  pbroken_brick->base.ym = ym;
-
-  timer_init(&pbroken_brick->timer, true);
-  timer_start(&pbroken_brick->timer,200);
-}
-
-void broken_brick_action(broken_brick_type* pbroken_brick)
-{
-  pbroken_brick->base.x = pbroken_brick->base.x + pbroken_brick->base.xm * frame_ratio;
-  pbroken_brick->base.y = pbroken_brick->base.y + pbroken_brick->base.ym * frame_ratio;
-
-  if (!timer_check(&pbroken_brick->timer))
-    world.broken_bricks.erase(static_cast<std::vector<broken_brick_type>::iterator>(pbroken_brick));
-}
-
-void broken_brick_draw(broken_brick_type* pbroken_brick)
-{
-  SDL_Rect src, dest;
-  src.x = rand() % 16;
-  src.y = rand() % 16;
-  src.w = 16;
-  src.h = 16;
-
-  dest.x = (int)(pbroken_brick->base.x - scroll_x);
-  dest.y = (int)pbroken_brick->base.y;
-  dest.w = 16;
-  dest.h = 16;
-  
-  if (pbroken_brick->tile->images.size() > 0)
-    texture_draw_part(&pbroken_brick->tile->images[0],
-                      src.x,src.y,dest.x,dest.y,dest.w,dest.h);
-}
-
-void bouncy_brick_init(bouncy_brick_type* pbouncy_brick, float x, float y)
-{
-  pbouncy_brick->base.x   = x;
-  pbouncy_brick->base.y   = y;
-  pbouncy_brick->offset   = 0;
-  pbouncy_brick->offset_m = -BOUNCY_BRICK_SPEED;
-  pbouncy_brick->shape    = GameSession::current()->get_level()->gettileid(x, y);
-}
-
-void bouncy_brick_action(bouncy_brick_type* pbouncy_brick)
-{
-
-  pbouncy_brick->offset = (pbouncy_brick->offset +
-                           pbouncy_brick->offset_m * frame_ratio);
-
-  /* Go back down? */
-
-  if (pbouncy_brick->offset < -BOUNCY_BRICK_MAX_OFFSET)
-    pbouncy_brick->offset_m = BOUNCY_BRICK_SPEED;
-
-
-  /* Stop bouncing? */
-
-  if (pbouncy_brick->offset >= 0)
-    world.bouncy_bricks.erase(static_cast<std::vector<bouncy_brick_type>::iterator>(pbouncy_brick));
-}
-
-void bouncy_brick_draw(bouncy_brick_type* pbouncy_brick)
-{
-  int s;
-  SDL_Rect dest;
-  
-  if (pbouncy_brick->base.x >= scroll_x - 32 &&
-      pbouncy_brick->base.x <= scroll_x + screen->w)
-    {
-      dest.x = (int)(pbouncy_brick->base.x - scroll_x);
-      dest.y = (int)pbouncy_brick->base.y;
-      dest.w = 32;
-      dest.h = 32;
-
-      Level* plevel = GameSession::current()->get_level();
-
-      // FIXME: overdrawing hack to clean the tile from the screen to
-      // paint it later at on offseted position
-      if(plevel->bkgd_image[0] == '\0')
-        {
-          fillrect(pbouncy_brick->base.x - scroll_x, pbouncy_brick->base.y,
-                   32,32, 
-                   plevel->bkgd_red, plevel->bkgd_green, plevel->bkgd_blue, 0);
-        }
-      else
-        {
-          s = (int)scroll_x / 30;
-          texture_draw_part(&plevel->img_bkgd, dest.x + s, dest.y, 
-                            dest.x, dest.y,dest.w,dest.h);
-        }
-
-      drawshape(pbouncy_brick->base.x - scroll_x,
-                pbouncy_brick->base.y + pbouncy_brick->offset,
-                pbouncy_brick->shape);
-    }
-}
-
-void floating_score_init(floating_score_type* pfloating_score, float x, float y, int s)
-{
-  pfloating_score->base.x = x;
-  pfloating_score->base.y = y - 16;
-  timer_init(&pfloating_score->timer,true);
-  timer_start(&pfloating_score->timer,1000);
-  pfloating_score->value = s;
-}
-
-void floating_score_action(floating_score_type* pfloating_score)
-{
-  pfloating_score->base.y = pfloating_score->base.y - 2 * frame_ratio;
-
-  if(!timer_check(&pfloating_score->timer))
-    world.floating_scores.erase(static_cast<std::vector<floating_score_type>::iterator>(pfloating_score));
-}
-
-void floating_score_draw(floating_score_type* pfloating_score)
-{
-  char str[10];
-  sprintf(str, "%d", pfloating_score->value);
-  text_draw(&gold_text, str, (int)pfloating_score->base.x + 16 - strlen(str) * 8, (int)pfloating_score->base.y, 1);
-}
-
 /* Break a brick: */
 void trybreakbrick(float x, float y, bool small)
 {
-  Level* plevel = GameSession::current()->get_level();
+  Level* plevel = World::current()->get_level();
   
   Tile* tile = gettile(x, y);
   if (tile->brick)
@@ -491,7 +362,7 @@ void trybreakbrick(float x, float y, bool small)
 /* Empty a box: */
 void tryemptybox(float x, float y, int col_side)
 {
-  Level* plevel = GameSession::current()->get_level();
+  Level* plevel = World::current()->get_level();
 
   Tile* tile = gettile(x,y);
   if (!tile->fullbox)
@@ -534,7 +405,7 @@ void tryemptybox(float x, float y, int col_side)
 /* Try to grab a distro: */
 void trygrabdistro(float x, float y, int bounciness)
 {
-  Level* plevel = GameSession::current()->get_level();
+  Level* plevel = World::current()->get_level();
   Tile* tile = gettile(x, y);
   if (tile && tile->distro)
     {
index 99ca51b..e0137b9 100644 (file)
 #include "scene.h"
 #include "special.h"
 #include "particlesystem.h"
-
-/* Bounciness of distros: */
-
-#define NO_BOUNCE 0
-#define BOUNCE 1
-
-struct bouncy_distro_type
-{
-  base_type base;
-};
-
-extern texture_type img_distro[4];
-
-void bouncy_distro_init(bouncy_distro_type* pbouncy_distro, float x, float y);
-void bouncy_distro_action(bouncy_distro_type* pbouncy_distro);
-void bouncy_distro_draw(bouncy_distro_type* pbouncy_distro);
-void bouncy_distro_collision(bouncy_distro_type* pbouncy_distro, int c_object);
-
-#define BOUNCY_BRICK_MAX_OFFSET 8
-#define BOUNCY_BRICK_SPEED 0.9
-
-struct broken_brick_type
-{
-  base_type base;
-  timer_type timer;
-  Tile* tile;
-};
-
-void broken_brick_init(broken_brick_type* pbroken_brick, Tile* tile,
-                       float x, float y, float xm, float ym);
-void broken_brick_action(broken_brick_type* pbroken_brick);
-void broken_brick_draw(broken_brick_type* pbroken_brick);
-
-struct bouncy_brick_type
-{
-  float offset;
-  float offset_m;
-  int shape;
-  base_type base;
-};
-
-void bouncy_brick_init(bouncy_brick_type* pbouncy_brick, float x, float y);
-void bouncy_brick_action(bouncy_brick_type* pbouncy_brick);
-void bouncy_brick_draw(bouncy_brick_type* pbouncy_brick);
-
-struct floating_score_type
-{
-  int value;
-  timer_type timer;
-  base_type base;
-};
-
-void floating_score_init(floating_score_type* pfloating_score, float x, float y, int s);
-void floating_score_action(floating_score_type* pfloating_score);
-void floating_score_draw(floating_score_type* pfloating_score);
+#include "gameobjs.h"
 
 /** Try to grab the coin at the given coordinates */
 void trygrabdistro(float x, float y, int bounciness);
@@ -97,20 +43,26 @@ class World
   Level* level;
   
   std::vector<bouncy_distro_type> bouncy_distros;
-  std::vector<broken_brick_type> broken_bricks;
-  std::vector<bouncy_brick_type> bouncy_bricks;
-  std::vector<BadGuy> bad_guys;
+  std::vector<broken_brick_type>  broken_bricks;
+  std::vector<bouncy_brick_type>  bouncy_bricks;
   std::vector<floating_score_type> floating_scores;
+
+  std::vector<BadGuy> bad_guys;
   std::vector<upgrade_type> upgrades;
   std::vector<bullet_type> bullets;
   std::vector<ParticleSystem*> particle_systems;
 
+  static World* current_;
  public:
+  static World* current() { return current_; }
+
   World();
   ~World();
   
   Level* get_level() { return level; }
 
+  void set_defaults();
+
   void draw();
   void action();
   void arrays_free();