From: Ingo Ruhnke Date: Thu, 15 Apr 2004 19:08:02 +0000 (+0000) Subject: - added primitiv scrolling to the worldmap X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=f9ecdc9dda2a40dbfecc555162ad165d10ff2640;p=supertux.git - added primitiv scrolling to the worldmap - added a larger worldmap SVN-Revision: 527 --- diff --git a/data/levels/default/worldmap.stwm b/data/levels/default/worldmap.stwm index a84c0102a..c8c4f3a38 100644 --- a/data/levels/default/worldmap.stwm +++ b/data/levels/default/worldmap.stwm @@ -1,29 +1,39 @@ -;; Generated with Windstille Editor +;; Generated with Flexlay Editor (supertux-worldmap - (tilemap - (width 20) - (height 15) - (data - 9 9 9 9 9 11 16 12 11 16 16 16 16 12 9 9 9 9 9 9 - 9 9 11 16 16 22 19 17 15 48 40 40 39 23 16 12 9 9 9 9 - 9 9 15 20 18 18 18 13 15 47 19 19 37 40 39 23 16 12 9 9 - 9 11 22 17 11 16 16 16 22 47 48 40 40 40 44 39 19 23 16 12 - 9 15 19 23 22 48 40 40 40 44 46 48 39 19 19 47 19 19 19 17 - 9 15 48 39 19 41 40 40 40 40 42 47 47 19 19 47 19 20 18 13 - 9 15 37 45 40 45 40 40 40 40 43 42 37 40 40 42 19 17 9 9 - 9 15 19 47 19 47 19 19 48 40 42 19 24 25 25 25 26 17 9 9 - 9 14 21 37 40 46 19 48 42 19 24 25 33 32 35 29 28 17 9 9 - 9 9 15 19 19 37 40 42 24 25 33 35 29 29 28 20 18 13 9 9 - 9 9 15 19 19 24 25 25 33 32 35 28 20 18 18 13 9 9 9 9 - 9 9 14 21 19 31 32 32 32 35 28 20 13 9 9 11 16 12 9 9 - 9 9 9 14 21 30 29 29 29 28 20 13 9 11 16 22 20 13 9 9 - 9 9 9 9 14 18 18 18 18 18 13 9 9 14 18 18 13 9 9 9 - 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 - )) - (levels - (level (name "level1.stl") (x 3) (y 6)) - (level (name "level2.stl") (x 5) (y 8)) - (level (name "level3.stl") (x 9) (y 1))) - - ) + (tilemap + (width 40) + (height 30) + (data + 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 + 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 11 12 9 9 9 9 9 9 9 9 9 9 9 9 + 9 9 9 9 9 9 9 11 16 12 11 16 16 16 16 12 9 9 9 9 11 16 16 12 9 9 14 13 9 9 9 9 9 9 9 9 9 9 9 9 + 9 9 9 11 16 16 16 22 19 17 15 24 25 25 26 23 16 12 9 9 14 18 18 13 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 + 9 9 11 22 19 4 19 20 18 13 15 31 32 32 34 26 19 23 16 12 9 9 9 9 9 9 11 16 16 16 16 12 9 9 9 9 9 9 9 9 + 9 9 15 19 48 42 20 13 9 9 15 31 35 29 29 28 19 19 19 23 16 12 9 9 9 11 22 19 24 25 26 23 12 11 16 16 12 9 9 9 + 9 9 15 19 47 19 17 11 16 16 22 30 28 19 48 40 4 40 39 20 18 13 9 9 11 22 19 19 30 36 34 26 23 22 19 19 23 12 9 9 + 9 9 15 19 4 19 23 22 19 19 19 19 24 26 47 19 19 19 47 23 16 16 16 16 22 48 4 40 39 31 32 34 25 25 25 25 26 17 9 9 + 9 9 15 19 37 39 19 4 40 40 40 39 30 28 41 40 4 40 44 40 40 4 40 40 40 42 19 19 47 30 29 29 29 29 29 36 27 17 9 9 + 9 9 15 19 19 47 19 47 24 25 26 4 40 40 4 24 25 25 26 20 18 18 18 21 24 25 25 26 4 40 40 4 40 40 39 31 27 23 12 9 + 9 9 14 18 21 47 19 47 30 29 28 19 24 25 25 33 35 29 28 17 9 9 9 15 30 29 36 27 19 19 19 19 19 19 47 31 34 26 17 9 + 9 9 9 9 15 4 40 4 19 19 24 25 33 35 29 29 28 20 18 13 9 9 9 14 18 21 31 27 48 4 40 40 40 40 4 30 36 27 17 9 + 9 9 9 9 15 19 19 24 25 25 33 32 35 28 20 18 18 13 9 9 9 9 9 9 9 15 31 27 47 24 25 25 25 26 19 19 30 28 17 9 + 9 9 9 9 14 21 19 31 32 32 32 35 28 20 13 9 9 11 16 12 9 9 9 9 9 15 30 28 4 30 36 32 35 28 20 21 19 20 13 9 + 9 9 11 12 9 14 21 30 29 29 29 28 20 13 9 11 16 22 20 13 9 9 9 9 9 14 21 19 37 39 31 32 27 20 13 14 21 17 9 9 + 9 9 14 13 11 12 14 18 18 18 18 18 13 9 9 14 18 18 13 9 9 9 9 9 9 9 14 21 19 47 30 36 27 17 9 9 14 13 9 9 + 9 9 9 9 14 13 9 9 9 9 11 16 16 16 12 9 9 11 16 12 9 9 9 9 9 9 9 14 21 4 19 31 27 17 9 9 9 9 9 9 + 9 9 9 9 9 9 9 11 16 16 22 24 25 26 23 16 16 22 19 23 16 16 12 9 9 9 9 9 15 47 19 30 28 17 9 9 9 9 9 9 + 9 9 9 11 16 16 16 22 19 19 19 30 36 34 25 26 19 24 25 25 25 26 23 16 16 16 16 16 22 47 20 18 18 13 9 9 9 9 9 9 + 9 9 9 15 24 25 26 19 19 19 19 19 30 29 29 28 19 30 29 29 36 34 25 26 19 19 48 4 40 42 17 9 9 9 9 9 9 9 9 9 + 9 9 9 15 31 32 27 4 40 39 19 48 40 40 4 19 48 40 40 4 30 29 29 28 19 19 47 20 18 18 13 9 9 9 9 9 9 9 9 9 + 9 9 9 15 30 36 34 26 19 47 19 47 19 19 47 19 47 19 19 47 19 19 19 48 40 40 42 23 12 9 9 9 9 11 12 9 9 9 9 9 + 9 9 9 14 21 30 29 28 19 37 4 42 19 19 47 19 47 19 19 47 19 19 19 4 19 19 24 26 17 9 9 9 9 14 13 9 9 9 9 9 + 9 9 9 9 14 18 18 18 21 19 19 19 19 19 47 19 47 19 4 42 19 19 48 42 24 25 33 27 17 9 9 9 9 9 9 9 9 9 9 9 + 9 9 9 9 9 9 9 9 14 21 19 24 25 26 4 40 42 19 47 19 19 19 47 19 30 29 36 27 17 9 9 9 9 9 9 9 9 9 9 9 + 9 9 9 11 12 9 9 9 9 14 21 30 36 34 25 26 19 19 37 40 4 40 42 19 20 21 30 28 17 9 9 11 16 16 12 9 9 9 9 9 + 9 9 9 14 13 9 9 9 9 9 14 21 31 32 32 34 25 25 25 25 26 19 19 20 13 14 18 18 13 9 9 14 21 19 23 12 9 9 9 9 + 9 9 9 9 9 9 9 9 9 9 9 15 30 29 29 29 29 29 29 29 28 19 20 13 11 12 9 9 9 9 9 9 14 18 18 13 9 9 9 9 + 9 9 9 9 9 9 9 9 9 9 9 14 18 18 18 18 18 18 18 18 18 18 13 9 14 13 9 9 9 9 9 9 9 9 9 9 9 9 9 9 + 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 + )) +) diff --git a/src/worldmap.cpp b/src/worldmap.cpp index e1d3109b7..0e6bd3d76 100644 --- a/src/worldmap.cpp +++ b/src/worldmap.cpp @@ -112,7 +112,16 @@ Tux::Tux(WorldMap* worldmap_) } void -Tux::draw() +Tux::draw(const Point& offset) +{ + Point pos = get_pos(); + sprite->draw(pos.x + offset.x, + pos.y + offset.y); +} + + +Point +Tux::get_pos() { float x = tile_pos.x * 32; float y = tile_pos.y * 32; @@ -134,8 +143,8 @@ Tux::draw() case NONE: break; } - - sprite->draw((int)x, (int)y); + + return Point((int)x, (int)y); } void @@ -473,21 +482,23 @@ WorldMap::at(Point p) } void -WorldMap::draw() +WorldMap::draw(const Point& offset) { for(int y = 0; y < height; ++y) for(int x = 0; x < width; ++x) { Tile* tile = at(Point(x, y)); - tile->sprite->draw(x*32, y*32); + tile->sprite->draw(x*32 + offset.x, + y*32 + offset.y); } for(Levels::iterator i = levels.begin(); i != levels.end(); ++i) { - leveldot_green->draw(i->x*32, i->y*32); + leveldot_green->draw(i->x*32 + offset.x, + i->y*32 + offset.y); } - tux->draw(); + tux->draw(offset); } void @@ -499,7 +510,20 @@ WorldMap::display() play_music(song, 1); while(!quit) { - draw(); + Point tux_pos = tux->get_pos(); + if (1) + { + offset.x = -tux_pos.x + screen->w/2; + offset.y = -tux_pos.y + screen->h/2; + + if (offset.x > 0) offset.x = 0; + if (offset.y > 0) offset.y = 0; + + if (offset.x < screen->w - width*32) offset.x = screen->w - width*32; + if (offset.y < screen->h - height*32) offset.y = screen->h - height*32; + } + + draw(offset); get_input(); update(); diff --git a/src/worldmap.h b/src/worldmap.h index 0dfc037e6..87745ae89 100644 --- a/src/worldmap.h +++ b/src/worldmap.h @@ -97,12 +97,13 @@ private: public: Tux(WorldMap* worldmap_); - void draw(); + void draw(const Point& offset); void update(float delta); void set_direction(Direction d) { input_direction = d; } bool is_moving() const { return moving; } + Point get_pos(); Point get_tile_pos() const { return tile_pos; } void set_tile_pos(Point p) { tile_pos = p; } }; @@ -141,6 +142,7 @@ private: Direction input_direction; bool enter_level; + Point offset; public: WorldMap(); ~WorldMap(); @@ -156,7 +158,7 @@ public: void update(); /** Draw one frame */ - void draw(); + void draw(const Point& offset); Point get_next_tile(Point pos, Direction direction); Tile* at(Point pos);