- added music support and support for starting levels to the worldmap
authorIngo Ruhnke <grumbel@gmx.de>
Sat, 20 Mar 2004 02:27:32 +0000 (02:27 +0000)
committerIngo Ruhnke <grumbel@gmx.de>
Sat, 20 Mar 2004 02:27:32 +0000 (02:27 +0000)
SVN-Revision: 272

data/images/worldmap/antarctica.scm
data/images/worldmap/levelmarker.png [new file with mode: 0644]
data/levels/default/worldmap.scm
src/worldmap.cpp
src/worldmap.h

index 3077381..acd130b 100644 (file)
@@ -8,7 +8,7 @@
        (south #f)
        (east  #f)
        (west  #f)
-       (stop #f))
+       (stop  #f))
  (tile (id 1)
        (image "road_h.png")
        (north #f)
diff --git a/data/images/worldmap/levelmarker.png b/data/images/worldmap/levelmarker.png
new file mode 100644 (file)
index 0000000..5840ca5
Binary files /dev/null and b/data/images/worldmap/levelmarker.png differ
index ae525cd..3d4f16d 100644 (file)
                 0 0 0 0 0 4 1 1 6 1 1 6 1 1 4 0 0 0 0 0
                 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
                 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
-                )))
+                ))
+ (levels 
+  (level (name "level1.dat")
+         (x-pos 3)
+         (y-pos 0))
+  (level (name "level2.dat")
+         (x-pos 5)
+         (y-pos 3))
+  (level (name "level3.dat")
+         (x-pos 8)
+         (y-pos 0))
+  (level (name "level4.dat")
+         (x-pos 7)
+         (y-pos 5))
+  ))
 
 ;; EOF ;;
\ No newline at end of file
index b68b125..95cdbc9 100644 (file)
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
+#include <iostream>
 #include <vector>
 #include <assert.h>
 #include "texture.h"
 #include "screen.h"
 #include "lispreader.h"
+#include "gameloop.h"
 #include "worldmap.h"
 
 namespace WorldMapNS {
@@ -103,6 +105,7 @@ WorldMap::WorldMap()
   tux_moving = false;
 
   texture_load(&tux_sprite, DATA_PREFIX "/images/worldmap/tux.png", USE_ALPHA);
+  texture_load(&level_sprite, DATA_PREFIX "/images/worldmap/levelmarker.png", USE_ALPHA);
 
   tux_offset = 0;
 
@@ -113,6 +116,10 @@ WorldMap::WorldMap()
   tux_direction = NONE;
   enter_level = false;
 
+  name = "<no name>";
+  music = "SALCON.MOD";
+  song = 0;
+
   load_map();
 }
 
@@ -144,6 +151,33 @@ WorldMap::load_map()
               reader.read_int("height", &height);
               reader.read_int_vector("data", &tilemap);
             }
+          else if (strcmp(lisp_symbol(lisp_car(element)), "properties") == 0)
+            {
+              LispReader reader(lisp_cdr(element));
+              reader.read_string("name",  &name);
+              reader.read_string("music", &music);
+            }
+          else if (strcmp(lisp_symbol(lisp_car(element)), "levels") == 0)
+            {
+              lisp_object_t* cur = lisp_cdr(element);
+              
+              while(!lisp_nil_p(cur))
+                {
+                  lisp_object_t* element = lisp_car(cur);
+                  
+                  if (strcmp(lisp_symbol(lisp_car(element)), "level") == 0)
+                    {
+                      Level level;
+                      LispReader reader(lisp_cdr(element));
+                      reader.read_string("name",  &level.name);
+                      reader.read_int("x-pos", &level.x);
+                      reader.read_int("y-pos", &level.y);
+                      levels.push_back(level);
+                    }
+                  
+                  cur = lisp_cdr(cur);      
+                }
+            }
           else
             {
               
@@ -206,7 +240,20 @@ WorldMap::update()
 
   if (enter_level)
     {
-      puts("Enter the current level");
+      for(Levels::iterator i = levels.begin(); i != levels.end(); ++i)
+        {
+          if (i->x == tux_tile_pos.x && 
+              i->y == tux_tile_pos.y)
+            {
+              std::cout << "Enter the current level: " << i->name << std::endl;;
+              halt_music();
+              gameloop(const_cast<char*>((DATA_PREFIX "levels/default/" + i->name).c_str()),
+                                         1, ST_GL_LOAD_LEVEL_FILE);
+              play_music(song, 1);
+              break;
+            }
+        }
+      
     }
   else
     {
@@ -335,6 +382,11 @@ WorldMap::draw()
       break;
     }
 
+  for(Levels::iterator i = levels.begin(); i != levels.end(); ++i)
+    {
+      texture_draw(&level_sprite, i->x*32, i->y*32, NO_UPDATE);
+    }
+
   texture_draw(&tux_sprite, (int)x, (int)y, NO_UPDATE);
   flipscreen();
 }
@@ -344,12 +396,17 @@ WorldMap::display()
 {
   quit = false;
 
+  song = load_song(const_cast<char*>((DATA_PREFIX "/music/" + music).c_str()));
+  play_music(song, 1);
+
   while(!quit) {
     draw();
     get_input();
     update();
     SDL_Delay(20);
   }
+
+  free_music(song);
 }
 
 } // namespace WorldMapNS
index 2f97619..d831793 100644 (file)
@@ -42,6 +42,13 @@ struct Pointf
   float y;
 };
 
+struct Level
+{
+  int x;
+  int y;
+  std::string name;
+};
+
 struct Tile
 {
   texture_type sprite;
@@ -76,11 +83,21 @@ class WorldMap
 {
 private:
   texture_type tux_sprite;
+  texture_type level_sprite;
   bool quit;
+
+  std::string name;
+  std::string music;
+
   std::vector<int> tilemap;
   int width;
   int height;
 
+  typedef std::vector<Level> Levels;
+  Levels levels;
+
+  Mix_Music* song;
+
   enum Direction { NONE, WEST, EAST, NORTH, SOUTH };
   Direction tux_direction;
   Point tux_tile_pos;