From 2cea58600cea4838a6f7ba00f66f9ede187eba39 Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Sat, 20 Mar 2004 02:27:32 +0000 Subject: [PATCH] - added music support and support for starting levels to the worldmap SVN-Revision: 272 --- data/images/worldmap/antarctica.scm | 2 +- data/images/worldmap/levelmarker.png | Bin 0 -> 253 bytes data/levels/default/worldmap.scm | 16 +++++++++- src/worldmap.cpp | 59 ++++++++++++++++++++++++++++++++++- src/worldmap.h | 17 ++++++++++ 5 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 data/images/worldmap/levelmarker.png 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 0000000000000000000000000000000000000000..5840ca5f3439258504e37f1b6517bb7403399fe7 GIT binary patch literal 253 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz&H|6fVg?3oVGw3ym^DWND9B#o z>FdgVg;|7AN8hih$Pp+cTjCl~;+&tGo0?a`;9QiNSdyBeP@Y+mp%9Xhs^ISF8}L3w zH4kL2r;B4q#jUqf0=W(ta5(pV`4{e2e>&kph%>_e!2%VQ6BA;S(%leBjD= sAiFT?LCwNz8yL7AXfTAagdPuLUp7_1vTLtI2+(>4Pgg&ebxsLQ0JtDl*#H0l literal 0 HcmV?d00001 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; -- 2.11.0