From 437271e241e198dc05dfff8d3bcb2c2d8c33fde3 Mon Sep 17 00:00:00 2001 From: Wolfgang Becker Date: Tue, 10 Apr 2007 21:10:53 +0000 Subject: [PATCH] Scroll nonblocking infoblock by moving half a block away. SVN-Revision: 4975 --- src/object/infoblock.cpp | 21 ++++++++++++++++++--- src/object/infoblock.hpp | 3 +++ tools/autopackage/default.apspec | 2 +- 3 files changed, 22 insertions(+), 4 deletions(-) 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] -- 2.11.0