- added translation table for the old format
authorIngo Ruhnke <grumbel@gmx.de>
Thu, 25 Mar 2004 02:13:17 +0000 (02:13 +0000)
committerIngo Ruhnke <grumbel@gmx.de>
Thu, 25 Mar 2004 02:13:17 +0000 (02:13 +0000)
SVN-Revision: 352

src/gameloop.cpp
src/level.cpp
src/player.cpp
src/tile.cpp
src/tile.h

index 13347ad..5addbe7 100644 (file)
@@ -1318,8 +1318,6 @@ void unloadshared(void)
 
 void drawshape(float x, float y, unsigned int c)
 {
-  int z;
-
   Tile* ptile = TileManager::instance()->get
                 (c);
   if(ptile)
@@ -1396,7 +1394,6 @@ void drawshape(float x, float y, unsigned int c)
 
 
 /* What shape is at some position? */
-
 unsigned int shape(float x, float y)
 {
 
@@ -1416,6 +1413,11 @@ unsigned int shape(float x, float y)
   return(c);
 }
 
+Tile* gettile(float x, float y)
+{
+  return TileManager::instance()->get(shape(x, y));
+}
+
 /* Is is ground? */
 
 
@@ -1494,6 +1496,12 @@ bool isfullbox(float x, float y)
     }
 }
 
+bool isdistro(float x, float y)
+{
+  Tile* tile = TileManager::instance()->get(shape(x,y));
+  return tile && tile->distro;
+}
+
 /* Break a brick: */
 
 void trybreakbrick(float x, float y)
@@ -1568,22 +1576,23 @@ void tryemptybox(float x, float y, int col_side)
   else
     col_side = LEFT;
 
-  switch(shape(x,y))
+  // FIXME: Content of boxes must be handled otherwise
+  switch(gettile(x,y)->data)
     {
-    case 'A':      /* Box with a distro! */
+    case 1: //'A':      /* Box with a distro! */
       add_bouncy_distro(((int)(x + 1) / 32) * 32, (int)(y / 32) * 32 - 32);
       play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
       score = score + SCORE_DISTRO;
       distros++;
       break;
-    case 'B':      /* Add an upgrade! */
+    case 2: // 'B':      /* Add an upgrade! */
       if (tux.size == SMALL)     /* Tux is small, add mints! */
         add_upgrade((int)((x + 1) / 32) * 32, (int)(y / 32) * 32 - 32, col_side, UPGRADE_MINTS);
       else     /* Tux is big, add coffee: */
         add_upgrade((int)((x + 1) / 32) * 32, (int)(y / 32) * 32 - 32, col_side, UPGRADE_COFFEE);
       play_sound(sounds[SND_UPGRADE], SOUND_CENTER_SPEAKER);
       break;
-    case '!':     /* Add a golden herring */
+    case 3:// '!':     /* Add a golden herring */
       add_upgrade((int)((x + 1) / 32) * 32, (int)(y / 32) * 32 - 32, col_side, UPGRADE_HERRING);
       break;
     default:
@@ -1599,7 +1608,8 @@ void tryemptybox(float x, float y, int col_side)
 
 void trygrabdistro(float x, float y, int bounciness)
 {
-  if (shape(x, y) == '$')
+  Tile* tile = gettile(x, y);
+  if (tile && tile->distro)
     {
       level_change(&current_level,x, y, TM_IA, '.');
       play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
index 9eb156c..c6fe377 100644 (file)
@@ -249,7 +249,6 @@ int level_load(st_level* plevel, const  char *subset, int level)
 
 int level_load(st_level* plevel, const char* filename)
 {
-  int x, y, j;
   FILE * fi;
   lisp_object_t* root_obj = 0;
   fi = fopen(filename, "r");
@@ -273,10 +272,12 @@ int level_load(st_level* plevel, const char* filename)
   vector<int> bg_tm;
   vector<int> fg_tm;
 
+  int version = 0;
   if (strcmp(lisp_symbol(lisp_car(root_obj)), "supertux-level") == 0)
     {
       LispReader reader(lisp_cdr(root_obj));
 
+      reader.read_int("version",  &version);
       reader.read_int("width",  &plevel->width);
       reader.read_int("time",  &plevel->time_left);
       reader.read_int("bkgd_red",  &plevel->bkgd_red);
@@ -289,14 +290,65 @@ int level_load(st_level* plevel, const char* filename)
       reader.read_string("background",  &plevel->bkgd_image);
       reader.read_string("particle_system", &plevel->particle_system);
       reader.read_int_vector("background-tm",  &bg_tm);
-      reader.read_int_vector("interactive-tm",  &ia_tm);
-      reader.read_int_vector("dynamic-tm",  &dn_tm);
+      reader.read_int_vector("interactive-tm", &ia_tm);
+      reader.read_int_vector("dynamic-tm",     &dn_tm);
       reader.read_int_vector("foreground-tm",  &fg_tm);
-    }
 
+      // Convert old levels to the new tile numbers
+      if (version == 0)
+        {
+          int transtable[256];
+          transtable[(int)'.'] = 0;
+          transtable[(int)'0'] = 0;
+          transtable[(int)'1'] = 1;
+          transtable[(int)'2'] = 2;
+          transtable[(int)'x'] = 77;
+          transtable[(int)'X'] = 77;
+          transtable[(int)'y'] = 78;
+          transtable[(int)'Y'] = 78;
+          transtable[(int)'A'] = 83;
+          transtable[(int)'B'] = 102;
+          transtable[(int)'!'] = 103;
+          transtable[(int)'a'] = 84;
+          transtable[(int)'C'] = 85;
+          transtable[(int)'D'] = 86;
+          transtable[(int)'E'] = 87;
+          transtable[(int)'F'] = 88;
+          transtable[(int)'c'] = 89;
+          transtable[(int)'d'] = 90;
+          transtable[(int)'e'] = 91;
+          transtable[(int)'f'] = 92;
+
+          transtable[(int)'G'] = 93;
+          transtable[(int)'H'] = 94;
+          transtable[(int)'I'] = 95;
+          transtable[(int)'J'] = 96;
+
+          transtable[(int)'g'] = 97;
+          transtable[(int)'h'] = 98;
+          transtable[(int)'i'] = 99;
+          transtable[(int)'j'] = 100
+;
+          transtable[(int)'#'] = 11;
+          transtable[(int)'['] = 13; 
+          transtable[(int)'='] = 14;
+          transtable[(int)']'] = 15;
+          transtable[(int)'$'] = 82;
+          transtable[(int)'^'] = 76;
+          transtable[(int)'*'] = 80;
+          transtable[(int)'|'] = 79;
+          transtable[(int)'\\'] = 81;
+          transtable[(int)'&'] = 75;
+
+          for(std::vector<int>::iterator i = ia_tm.begin(); i != ia_tm.end(); ++i)
+            if (*i < 256)
+              *i = transtable[*i];
+            else
+              puts("Error: Value to high, conversion will fail");
+        }
+    }
 
-  int i;
-  for( i = 0; i < 15; ++i)
+  for(int i = 0; i < 15; ++i)
     {
       plevel->dn_tiles[i] = (unsigned int*) calloc((plevel->width +1) , sizeof(unsigned int) );
       plevel->ia_tiles[i] = (unsigned int*) calloc((plevel->width +1) , sizeof(unsigned int) );
@@ -304,10 +356,10 @@ int level_load(st_level* plevel, const char* filename)
       plevel->fg_tiles[i] = (unsigned int*) calloc((plevel->width +1) , sizeof(unsigned int) );
     }
 
-  i = j = 0;
+  int i = 0;
+  int j = 0;
   for(vector<int>::iterator it = ia_tm.begin(); it != ia_tm.end(); ++it, ++i)
     {
-
       plevel->ia_tiles[j][i] = (*it);
       if(i == plevel->width - 1)
         {
@@ -358,16 +410,16 @@ int level_load(st_level* plevel, const char* filename)
   /*  Mark the end position of this level! - Is a bit wrong here thought * /
 
   for (y = 0; y < 15; ++y)
-    {
-      for (x = 0; x < plevel->width; ++x)
-        {
-          if(plevel->tiles[y][x] == '|')
-            {
-              if(x*32 > endpos)
-                endpos = x*32;
-            }
-        }
-    }*/
+  {
+  for (x = 0; x < plevel->width; ++x)
+  {
+  if(plevel->tiles[y][x] == '|')
+  {
+  if(x*32 > endpos)
+  endpos = x*32;
+  }
+  }
+  }*/
 
   fclose(fi);
   return 0;
@@ -402,6 +454,7 @@ void level_save(st_level* plevel,const  char * subset, int level)
   fprintf(fi,";SuperTux-Level\n");
   fprintf(fi,"(supertux-level\n");
 
+  fprintf(fi,"  (version %d)\n", 1);
   fprintf(fi,"  (name \"%s\")\n", plevel->name.c_str());
   fprintf(fi,"  (theme \"%s\")\n", plevel->theme.c_str());
   fprintf(fi,"  (music \"%s\")\n", plevel->song_title.c_str());
index 1c1c137..c6daeae 100644 (file)
@@ -62,8 +62,10 @@ Player::init()
   size = SMALL;
   got_coffee = false;
 
-  base.x = 0;
+  // FIXME: Make the start position configurable via the levelfile
+  base.x = 100;
   base.y = 240;
+  
   base.xm = 0;
   base.ym = 0;
   old_base = base;
@@ -130,8 +132,8 @@ Player::key_event(SDLKey key, int state)
 void
 Player::level_begin()
 {
-  base.x 0;
-  base.y = 240;
+  base.x  = 100;
+  base.y  = 240;
   base.xm = 0;
   base.ym = 0;
   old_base = base;
@@ -241,7 +243,6 @@ Player::action()
           if(size == SMALL)
             {
               /* Get a distro from a brick? */
-
               if (shape(base.x, base.y) == 'x' ||
                   shape(base.x, base.y) == 'y')
                 {
index 4430e34..09a6f88 100644 (file)
@@ -16,7 +16,7 @@ TileManager* TileManager::instance_  = 0;
 
 TileManager::TileManager()
 {
-  std::string filename = datadir +  "images/tilesets/main.stgt"; 
+  std::string filename = datadir +  "images/tilesets/supertux.stgt"; 
   load_tileset(filename);
 }
 
@@ -46,7 +46,9 @@ void TileManager::load_tileset(std::string filename)
              tile->brick = false;
              tile->ice = false;          
              tile->fullbox = false;          
-              tile->alpha  = 0;
+              tile->alpha = 0;
+              tile->distro = 0;
+              tile->data  = 0;
               tile->anim_speed = 25;
   
               LispReader reader(lisp_cdr(element));
@@ -55,18 +57,20 @@ void TileManager::load_tileset(std::string filename)
               reader.read_bool("brick", &tile->brick);
               reader.read_bool("ice", &tile->ice);        
               reader.read_bool("fullbox", &tile->fullbox);
+              reader.read_bool("distro", &tile->distro);
+              reader.read_int("data",  (int*)&tile->data);
               reader.read_int("alpha",  (int*)&tile->alpha);
               reader.read_int("anim-speed",  &tile->anim_speed);
               reader.read_string_vector("images",  &filenames);
 
              for(std::vector<std::string>::iterator it = filenames.begin(); it != filenames.end(); ++it)
-             {
-             texture_type cur_image;
-             tile->images.push_back(cur_image);
-              texture_load(&tile->images[tile->images.size()-1], 
-                           datadir +  "images/tilesets/" + (*it), 
-                           USE_ALPHA);
-                          }
+                {
+                  texture_type cur_image;
+                  tile->images.push_back(cur_image);
+                  texture_load(&tile->images[tile->images.size()-1], 
+                               datadir +  "images/tilesets/" + (*it), 
+                               USE_ALPHA);
+                }
 
               if (id+tileset_id >= int(tiles.size()))
                 tiles.resize(id+tileset_id+1);
@@ -100,3 +104,6 @@ void TileManager::load_tileset(std::string filename)
       assert(0);
     }
 }
+
+// EOF //
+
index 31212c9..ab78d59 100644 (file)
@@ -23,27 +23,41 @@ Tile Class
 */
 struct Tile
 {
-std::vector<texture_type> images;
-bool solid;
-bool brick;
-bool ice;
-bool fullbox;
-int anim_speed;
-unsigned char alpha;
+  std::vector<texture_type> images;
+
+  /** solid tile that is indestructable by Tux */
+  bool solid;
+
+  /** a brick that can be destroyed by jumping under it */
+  bool brick;
+
+  /** FIXME: ? */
+  bool ice;
+
+  /** Bonusbox, content is stored in \a data */
+  bool fullbox;
+
+  /** Tile is a distro/coin */
+  bool distro;
+
+  /** General purpose data attached to a tile (content of a box, type of coin) */
+  int data;
+
+  int anim_speed;
+  unsigned char alpha;
 };
 
 class TileManager
 {
-private:
- TileManager();
- std::vector<Tile*> tiles;
- static TileManager* instance_ ;
- void load_tileset(std::string filename);
+ private:
 TileManager();
 std::vector<Tile*> tiles;
 static TileManager* instance_ ;
 void load_tileset(std::string filename);
   
-public:
- static TileManager* instance() { return instance_ ? instance_ : instance_ = new TileManager(); }
- Tile* get(unsigned int id) { if( id < tiles.size()) { return tiles[id]; } else { return NULL; } } ;
-
+ public:
+  static TileManager* instance() { return instance_ ? instance_ : instance_ = new TileManager(); }
+  Tile* get(unsigned int id) { if( id < tiles.size()) { return tiles[id]; } else { return NULL; } }
 };
 
 #endif