Update of /cvsroot/super-tux/supertux/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27568/src
Modified Files:
worldmap.cpp worldmap.h
Log Message:
- added primitiv scrolling to the worldmap
- added a larger worldmap
Index: worldmap.cpp
===================================================================
RCS file: /cvsroot/super-tux/supertux/src/worldmap.cpp,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- worldmap.cpp 13 Apr 2004 02:19:13 -0000 1.24
+++ worldmap.cpp 15 Apr 2004 19:08:01 -0000 1.25
@@ -112,7 +112,16 @@
}
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 @@
case NONE:
break;
}
-
- sprite->draw((int)x, (int)y);
+
+ return Point((int)x, (int)y);
}
void
@@ -473,21 +482,23 @@
}
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 @@
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();
Index: worldmap.h
===================================================================
RCS file: /cvsroot/super-tux/supertux/src/worldmap.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- worldmap.h 13 Apr 2004 12:25:22 -0000 1.13
+++ worldmap.h 15 Apr 2004 19:08:02 -0000 1.14
@@ -97,12 +97,13 @@
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 @@
Direction input_direction;
bool enter_level;
+ Point offset;
public:
WorldMap();
~WorldMap();
@@ -156,7 +158,7 @@
void update();
/** Draw one frame */
- void draw();
+ void draw(const Point& offset);
Point get_next_tile(Point pos, Direction direction);
Tile* at(Point pos);
|