From: Wolfgang Becker Date: Tue, 10 Apr 2007 21:10:53 +0000 (+0000) Subject: Scroll nonblocking infoblock by moving half a block away. X-Git-Url: https://git.octo.it/?p=supertux.git;a=commitdiff_plain;h=437271e241e198dc05dfff8d3bcb2c2d8c33fde3 Scroll nonblocking infoblock by moving half a block away. SVN-Revision: 4975 --- diff --git a/src/object/infoblock.cpp b/src/object/infoblock.cpp index 770d69c3f..e5957f391 100644 --- a/src/object/infoblock.cpp +++ b/src/object/infoblock.cpp @@ -29,8 +29,13 @@ #include "log.hpp" #include "object/player.hpp" +namespace { + const float SCROLL_DELAY = 0.5; + const float SCROLL_DISTANCE = 16; +} + InfoBlock::InfoBlock(const lisp::Lisp& lisp) - : Block(sprite_manager->create("images/objects/bonus_block/infoblock.sprite")), shown_pct(0), dest_pct(0) + : Block(sprite_manager->create("images/objects/bonus_block/infoblock.sprite")), shown_pct(0), dest_pct(0), slowdown_scroll(0) { Vector pos; lisp.get("x", pos.x); @@ -98,7 +103,7 @@ InfoBlock::update(float delta) { if (delta == 0) return; - // hide message if player is too far away + // hide message if player is too far away or above infoblock if (dest_pct > 0) { Player* player = get_nearest_player(); if (player) { @@ -106,7 +111,17 @@ InfoBlock::update(float delta) Vector p2 = player->get_pos() + (player->get_bbox().p2 - player->get_bbox().p1) / 2; Vector dist = (p2 - p1); float d = dist.norm(); - if (d > 128) dest_pct = 0; + if (d > 128 || dist.y < 0) dest_pct = 0; + slowdown_scroll += delta; + if ( slowdown_scroll > SCROLL_DELAY ) { + slowdown_scroll = 0; + if (dist.x > SCROLL_DISTANCE) { + infoBox->scrolldown(); + } + if( dist.x < -SCROLL_DISTANCE) { + infoBox->scrollup(); + } + } } } diff --git a/src/object/infoblock.hpp b/src/object/infoblock.hpp index 65eaf16a6..f67b81a29 100644 --- a/src/object/infoblock.hpp +++ b/src/object/infoblock.hpp @@ -45,6 +45,9 @@ protected: std::auto_ptr infoBox; Player* get_nearest_player(); + +private: + float slowdown_scroll; }; #endif diff --git a/tools/autopackage/default.apspec b/tools/autopackage/default.apspec index 030b89fe5..4e2601f55 100644 --- a/tools/autopackage/default.apspec +++ b/tools/autopackage/default.apspec @@ -9,7 +9,7 @@ Maintainer: SuperTux Development Team Packager: Christoph Sommer Summary: SuperTux is a classic style 2D jump and run sidescroller game in a style similar to the original SuperMario games. SoftwareVersion: 0.3.0 -PackageVersion: 1 +PackageVersion: 2 AutopackageTarget: 1.0 [Description]