From: Ricardo Cruz Date: Tue, 11 May 2004 21:53:51 +0000 (+0000) Subject: First implementation of vertical scrolling. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=8d72041c32613175e6b7eecd34007dbb402f0b91;p=supertux.git First implementation of vertical scrolling. SVN-Revision: 1111 --- diff --git a/src/gameobjs.cpp b/src/gameobjs.cpp index 4909308ad..010cf1d04 100644 --- a/src/gameobjs.cpp +++ b/src/gameobjs.cpp @@ -54,7 +54,7 @@ void BouncyDistro::draw() { img_distro[0]->draw(base.x - scroll_x, - base.y); + base.y - scroll_y); } @@ -98,7 +98,7 @@ BrokenBrick::draw() src.h = 16; dest.x = (int)(base.x - scroll_x); - dest.y = (int)base.y; + dest.y = (int)(base.y - scroll_y); dest.w = 16; dest.h = 16; @@ -147,7 +147,7 @@ BouncyBrick::draw() base.x <= scroll_x + screen->w) { dest.x = (int)(base.x - scroll_x); - dest.y = (int)base.y; + dest.y = (int)(base.y - scroll_y); dest.w = 32; dest.h = 32; @@ -157,7 +157,7 @@ BouncyBrick::draw() // paint it later at on offseted position if(plevel->bkgd_image[0] == '\0') { - fillrect(base.x - scroll_x, base.y, + fillrect(base.x - scroll_x, base.y - scroll_y, 32,32, plevel->bkgd_top.red, plevel->bkgd_top.green, plevel->bkgd_top.blue, 0); // FIXME: doesn't respect the gradient, futhermore is this necessary at all?? @@ -170,7 +170,7 @@ BouncyBrick::draw() } Tile::draw(base.x - scroll_x, - base.y + offset, + base.y - scroll_y + offset, shape); } } diff --git a/src/scene.cpp b/src/scene.cpp index d7034a9a0..ccdce0bb4 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -69,7 +69,7 @@ PlayerStatus::BonusType string_to_bonus(const std::string& str) } // FIXME: Move this into a view class -float scroll_x; +float scroll_x, scroll_y; unsigned int global_frame_counter; diff --git a/src/scene.h b/src/scene.h index 6beaeb657..d2fa82f85 100644 --- a/src/scene.h +++ b/src/scene.h @@ -46,7 +46,7 @@ PlayerStatus::BonusType string_to_bonus(const std::string& str); extern PlayerStatus player_status; -extern float scroll_x; +extern float scroll_x, scroll_y; extern unsigned int global_frame_counter; #endif /*SUPERTUX_SCENE_H*/ diff --git a/src/sprite.cpp b/src/sprite.cpp index bb31251a8..5c9c3f652 100644 --- a/src/sprite.cpp +++ b/src/sprite.cpp @@ -79,7 +79,7 @@ Sprite::draw(float x, float y) unsigned int frame = get_current_frame(); if (frame < surfaces.size()) - surfaces[frame]->draw(x - x_hotspot, y - y_hotspot); + surfaces[frame]->draw(x - x_hotspot, y - y_hotspot - scroll_y); } void diff --git a/src/world.cpp b/src/world.cpp index b1ad31f03..094f1be73 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -202,7 +202,7 @@ World::draw() for (x = 0; x < 21; ++x) { Tile::draw(32*x - fmodf(scroll_x, 32), y * 32, - level->bg_tiles[(int)y][(int)x + (int)(scroll_x / 32)]); + level->bg_tiles[(int)y + (int)(scroll_y / 32)][(int)x + (int)(scroll_x / 32)]); } } @@ -212,7 +212,7 @@ World::draw() for (x = 0; x < 21; ++x) { Tile::draw(32*x - fmodf(scroll_x, 32), y * 32, - level->ia_tiles[(int)y][(int)x + (int)(scroll_x / 32)]); + level->ia_tiles[(int)y + (int)(scroll_y / 32)][(int)x + (int)(scroll_x / 32)]); } } @@ -246,7 +246,7 @@ World::draw() for (x = 0; x < 21; ++x) { Tile::draw(32*x - fmodf(scroll_x, 32), y * 32, - level->fg_tiles[(int)y][(int)x + (int)(scroll_x / 32)]); + level->fg_tiles[(int)y + (int)(scroll_y / 32)][(int)x + (int)(scroll_x / 32)]); } } @@ -390,6 +390,18 @@ void World::scrolling(double frame_ratio) scroll_x = 0; if(scroll_x > level->width * 32 - screen->w) scroll_x = level->width * 32 - screen->w; + + /* Y-axis scrolling */ + + int tux_pos_y = (int)(tux.base.y + (tux.base.height/2)); + + scroll_y = tux_pos_y - (screen->h / 2); + + // this code prevent the screen to scroll before the start or after the level's end + if(scroll_y < 0) + scroll_y = 0; + if(scroll_y > level->height * 32 - screen->h) + scroll_y = level->height * 32 - screen->h; } void