From: Ingo Ruhnke Date: Sat, 20 Mar 2004 02:27:32 +0000 (+0000) Subject: - added music support and support for starting levels to the worldmap X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=2cea58600cea4838a6f7ba00f66f9ede187eba39;p=supertux.git - added music support and support for starting levels to the worldmap SVN-Revision: 272 --- diff --git a/data/images/worldmap/antarctica.scm b/data/images/worldmap/antarctica.scm index 307738168..acd130b0a 100644 --- a/data/images/worldmap/antarctica.scm +++ b/data/images/worldmap/antarctica.scm @@ -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 index 000000000..5840ca5f3 Binary files /dev/null and b/data/images/worldmap/levelmarker.png differ diff --git a/data/levels/default/worldmap.scm b/data/levels/default/worldmap.scm index ae525cd14..3d4f16dde 100644 --- a/data/levels/default/worldmap.scm +++ b/data/levels/default/worldmap.scm @@ -16,6 +16,20 @@ 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 diff --git a/src/worldmap.cpp b/src/worldmap.cpp index b68b1254e..95cdbc9b3 100644 --- a/src/worldmap.cpp +++ b/src/worldmap.cpp @@ -17,11 +17,13 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +#include #include #include #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 = ""; + 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((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((DATA_PREFIX "/music/" + music).c_str())); + play_music(song, 1); + while(!quit) { draw(); get_input(); update(); SDL_Delay(20); } + + free_music(song); } } // namespace WorldMapNS diff --git a/src/worldmap.h b/src/worldmap.h index 2f97619f6..d8317936c 100644 --- a/src/worldmap.h +++ b/src/worldmap.h @@ -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 tilemap; int width; int height; + typedef std::vector Levels; + Levels levels; + + Mix_Music* song; + enum Direction { NONE, WEST, EAST, NORTH, SOUTH }; Direction tux_direction; Point tux_tile_pos;