From 3d5538c368cacafa6e41022e9c2f7bf091150252 Mon Sep 17 00:00:00 2001 From: Christoph Sommer Date: Sun, 28 Jan 2007 20:35:11 +0000 Subject: [PATCH] Split EndSequence into multiple types. Defeating the Yeti now triggers an EndSequence. SVN-Revision: 4719 --- data/levels/world1/27 - No More Mr Ice Guy.stl | 9 +-- src/game_session.cpp | 80 +++++++++++++++----------- src/object/endsequence.cpp | 18 +----- src/object/endsequence.hpp | 11 +--- src/object/endsequence_fireworks.cpp | 66 +++++++++++++++++++++ src/object/endsequence_fireworks.hpp | 42 ++++++++++++++ src/object/endsequence_walkleft.cpp | 70 ++++++++++++++++++++++ src/object/endsequence_walkleft.hpp | 43 ++++++++++++++ src/object/endsequence_walkright.cpp | 70 ++++++++++++++++++++++ src/object/endsequence_walkright.hpp | 43 ++++++++++++++ 10 files changed, 385 insertions(+), 67 deletions(-) create mode 100644 src/object/endsequence_fireworks.cpp create mode 100644 src/object/endsequence_fireworks.hpp create mode 100644 src/object/endsequence_walkleft.cpp create mode 100644 src/object/endsequence_walkleft.hpp create mode 100644 src/object/endsequence_walkright.cpp create mode 100644 src/object/endsequence_walkright.hpp diff --git a/data/levels/world1/27 - No More Mr Ice Guy.stl b/data/levels/world1/27 - No More Mr Ice Guy.stl index daea254e6..f2881717b 100644 --- a/data/levels/world1/27 - No More Mr Ice Guy.stl +++ b/data/levels/world1/27 - No More Mr Ice Guy.stl @@ -105,14 +105,7 @@ Effect.fade_in(1); (yeti (x 2) (y 177) - (dead-script " -sector.Tux.make_invincible(); -play_sound(\"sounds/yeti_finish.ogg\"); -wait(6); -Effect.fade_out(5.5); -wait(5.5); -Level.finish(true); -") + (dead-script "sector.Tux.trigger_sequence(\"fireworks\");") ) (particles-snow ) diff --git a/src/game_session.cpp b/src/game_session.cpp index c4ee38348..2b539eeb2 100644 --- a/src/game_session.cpp +++ b/src/game_session.cpp @@ -55,7 +55,6 @@ #include "statistics.hpp" #include "timer.hpp" #include "options_menu.hpp" -#include "object/fireworks.hpp" #include "textscroller.hpp" #include "control/codecontroller.hpp" #include "control/joystickkeyboardcontroller.hpp" @@ -69,6 +68,9 @@ #include "trigger/sequence_trigger.hpp" #include "random_generator.hpp" #include "scripting/squirrel_util.hpp" +#include "object/endsequence_walkright.hpp" +#include "object/endsequence_walkleft.hpp" +#include "object/endsequence_fireworks.hpp" #include "direction.hpp" // the engine will be run with a logical framerate of 64fps. @@ -579,50 +581,60 @@ GameSession::display_info_box(const std::string& text) void GameSession::start_sequence(const std::string& sequencename) { - if(sequencename == "endsequence" || sequencename == "fireworks") { - if(end_sequence) - return; + // handle special "stoptux" sequence + if (sequencename == "stoptux") { + if (!end_sequence) { + log_warning << "Final target reached without an active end sequence" << std::endl; + this->start_sequence("endsequence"); + } + if (end_sequence) end_sequence->stop_tux(); + return; + } + + // abort if a sequence is already playing + if (end_sequence) return; + + if (sequencename == "endsequence") { // Determine walking direction for Tux float xst = 1.f, xend = 2.f; for(std::vector::iterator i = currentsector->gameobjects.begin(); i != currentsector->gameobjects.end(); i++) { SequenceTrigger* st = dynamic_cast(*i); if(!st) - continue; + continue; if(st->get_sequence_name() == "stoptux") - xend = st->get_pos().x; + xend = st->get_pos().x; else if(st->get_sequence_name() == "endsequence") - xst = st->get_pos().y; - } - end_sequence = new EndSequence(); - currentsector->add_object(end_sequence); - end_sequence->start((xst > xend) ? LEFT : RIGHT); - - sound_manager->play_music("music/leveldone.ogg", false); - currentsector->player->invincible_timer.start(7.3f); - - // Stop all clocks. - for(std::vector::iterator i = currentsector->gameobjects.begin(); - i != currentsector->gameobjects.end(); ++i) - { - GameObject* obj = *i; - - LevelTime* lt = dynamic_cast (obj); - if(lt) - lt->stop(); + xst = st->get_pos().y; } - if(sequencename == "fireworks") { - currentsector->add_object(new Fireworks()); - } - } else if(sequencename == "stoptux") { - if(!end_sequence) { - log_warning << "Final target reached without an active end sequence" << std::endl; - this->start_sequence("endsequence"); + if (xst > xend) { + end_sequence = new EndSequenceWalkLeft(); + } else { + end_sequence = new EndSequenceWalkRight(); } - if (end_sequence) end_sequence->stop_tux(); - } else { - log_warning << "Unknown sequence '" << sequencename << "'" << std::endl; + } + else if (sequencename == "fireworks") end_sequence = new EndSequenceFireworks(); + else { + log_warning << "Unknown sequence '" << sequencename << "'. Ignoring." << std::endl; + return; + } + + currentsector->add_object(end_sequence); + end_sequence->start(); + + sound_manager->play_music("music/leveldone.ogg", false); + currentsector->player->invincible_timer.start(10000.0f); + + // Stop all clocks. + for(std::vector::iterator i = currentsector->gameobjects.begin(); + i != currentsector->gameobjects.end(); ++i) + { + GameObject* obj = *i; + + LevelTime* lt = dynamic_cast (obj); + if(lt) + lt->stop(); } } diff --git a/src/object/endsequence.cpp b/src/object/endsequence.cpp index 23c530fbe..2e4cc6a41 100644 --- a/src/object/endsequence.cpp +++ b/src/object/endsequence.cpp @@ -60,7 +60,7 @@ EndSequence::draw(DrawingContext& /*context*/) } void -EndSequence::start(Direction dir) +EndSequence::start() { if (isrunning) return; isrunning = true; @@ -71,8 +71,6 @@ EndSequence::start(Direction dir) tux.set_controller(end_sequence_controller); tux.set_speedlimit(230); //MAX_WALK_XM - walk_dir = dir; - starting(); } @@ -106,25 +104,11 @@ EndSequence::is_done() void EndSequence::starting() { - last_x_pos = -1; - endsequence_timer.start(7.3f); } void EndSequence::running(float /*elapsed_time*/) { - Player& tux = *Sector::current()->player; - - if (tux_may_walk) { - end_sequence_controller->press((walk_dir == RIGHT) ? Controller::RIGHT : Controller::LEFT); - if (int(last_x_pos) == int(tux.get_pos().x)) { - end_sequence_controller->press(Controller::JUMP); - } - } - - last_x_pos = tux.get_pos().x; - - if (endsequence_timer.check()) isdone = true; } void diff --git a/src/object/endsequence.hpp b/src/object/endsequence.hpp index 25e2acdf0..f7ac6476e 100644 --- a/src/object/endsequence.hpp +++ b/src/object/endsequence.hpp @@ -25,7 +25,6 @@ #include "timer.hpp" #include "lisp/lisp.hpp" #include "control/codecontroller.hpp" -#include "direction.hpp" class EndSequence : public GameObject { @@ -36,7 +35,7 @@ public: virtual void update(float elapsed_time); virtual void draw(DrawingContext& context); - void start(Direction dir); /**< play EndSequence */ + void start(); /**< play EndSequence */ void stop_tux(); /**< called when Tux has reached his final position */ void stop(); /**< stop playing EndSequence, mark it as done playing */ bool is_tux_stopped(); /**< returns true if Tux has reached his final position */ @@ -47,15 +46,11 @@ protected: virtual void running(float elapsed_time); /**< called while the EndSequence is running */ virtual void stopping(); /**< called when EndSequence stops */ - CodeController* end_sequence_controller; - float last_x_pos; - Timer endsequence_timer; - -private: bool isrunning; /**< true while EndSequence plays */ bool isdone; /**< true if EndSequence has finished playing */ bool tux_may_walk; /**< true while tux is allowed to walk */ - Direction walk_dir; /**< direction in which Tux should walk */ + CodeController* end_sequence_controller; + }; #endif diff --git a/src/object/endsequence_fireworks.cpp b/src/object/endsequence_fireworks.cpp new file mode 100644 index 000000000..8bcd92786 --- /dev/null +++ b/src/object/endsequence_fireworks.cpp @@ -0,0 +1,66 @@ +// $Id$ +// +// SuperTux - End Sequence: Tux walks right +// Copyright (C) 2007 Christoph Sommer +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include +#include "endsequence_fireworks.hpp" +#include "sector.hpp" +#include "object/player.hpp" +#include "object/fireworks.hpp" + +EndSequenceFireworks::EndSequenceFireworks() +: EndSequence() +{ +} + +EndSequenceFireworks::~EndSequenceFireworks() +{ +} + +void +EndSequenceFireworks::draw(DrawingContext& /*context*/) +{ +} + +void +EndSequenceFireworks::starting() +{ + EndSequence::starting(); + endsequence_timer.start(7.3f); + Sector::current()->add_object(new Fireworks()); +} + +void +EndSequenceFireworks::running(float elapsed_time) +{ + EndSequence::running(elapsed_time); + //Player& tux = *Sector::current()->player; + + if (tux_may_walk) { + end_sequence_controller->press(Controller::JUMP); + } + + if (endsequence_timer.check()) isdone = true; +} + +void +EndSequenceFireworks::stopping() +{ + EndSequence::stopping(); +} + diff --git a/src/object/endsequence_fireworks.hpp b/src/object/endsequence_fireworks.hpp new file mode 100644 index 000000000..aaa7b7992 --- /dev/null +++ b/src/object/endsequence_fireworks.hpp @@ -0,0 +1,42 @@ +// $Id$ +// +// SuperTux - End Sequence: Tux walks right +// Copyright (C) 2007 Christoph Sommer +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#ifndef __ENDSEQUENCE_FIREWORKS_H__ +#define __ENDSEQUENCE_FIREWORKS_H__ + +#include +#include "object/endsequence.hpp" +#include "timer.hpp" + +class EndSequenceFireworks : public EndSequence +{ +public: + EndSequenceFireworks(); + virtual ~EndSequenceFireworks(); + virtual void draw(DrawingContext& context); + +protected: + virtual void starting(); /**< called when EndSequence starts */ + virtual void running(float elapsed_time); /**< called while the EndSequence is running */ + virtual void stopping(); /**< called when EndSequence stops */ + + Timer endsequence_timer; +}; + +#endif diff --git a/src/object/endsequence_walkleft.cpp b/src/object/endsequence_walkleft.cpp new file mode 100644 index 000000000..6a29edf9c --- /dev/null +++ b/src/object/endsequence_walkleft.cpp @@ -0,0 +1,70 @@ +// $Id$ +// +// SuperTux - End Sequence: Tux walks right +// Copyright (C) 2007 Christoph Sommer +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include +#include "endsequence_walkleft.hpp" +#include "sector.hpp" +#include "object/player.hpp" + +EndSequenceWalkLeft::EndSequenceWalkLeft() +: EndSequence() +{ +} + +EndSequenceWalkLeft::~EndSequenceWalkLeft() +{ +} + +void +EndSequenceWalkLeft::draw(DrawingContext& /*context*/) +{ +} + +void +EndSequenceWalkLeft::starting() +{ + EndSequence::starting(); + last_x_pos = -1; + endsequence_timer.start(7.3f); +} + +void +EndSequenceWalkLeft::running(float elapsed_time) +{ + EndSequence::running(elapsed_time); + Player& tux = *Sector::current()->player; + + if (tux_may_walk) { + end_sequence_controller->press(Controller::LEFT); + if (int(last_x_pos) == int(tux.get_pos().x)) { + end_sequence_controller->press(Controller::JUMP); + } + } + + last_x_pos = tux.get_pos().x; + + if (endsequence_timer.check()) isdone = true; +} + +void +EndSequenceWalkLeft::stopping() +{ + EndSequence::stopping(); +} + diff --git a/src/object/endsequence_walkleft.hpp b/src/object/endsequence_walkleft.hpp new file mode 100644 index 000000000..6abac4dd8 --- /dev/null +++ b/src/object/endsequence_walkleft.hpp @@ -0,0 +1,43 @@ +// $Id$ +// +// SuperTux - End Sequence: Tux walks right +// Copyright (C) 2007 Christoph Sommer +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#ifndef __ENDSEQUENCE_WALKLEFT_H__ +#define __ENDSEQUENCE_WALKLEFT_H__ + +#include +#include "object/endsequence.hpp" +#include "timer.hpp" + +class EndSequenceWalkLeft : public EndSequence +{ +public: + EndSequenceWalkLeft(); + virtual ~EndSequenceWalkLeft(); + virtual void draw(DrawingContext& context); + +protected: + virtual void starting(); /**< called when EndSequence starts */ + virtual void running(float elapsed_time); /**< called while the EndSequence is running */ + virtual void stopping(); /**< called when EndSequence stops */ + + float last_x_pos; + Timer endsequence_timer; +}; + +#endif diff --git a/src/object/endsequence_walkright.cpp b/src/object/endsequence_walkright.cpp new file mode 100644 index 000000000..823b29fea --- /dev/null +++ b/src/object/endsequence_walkright.cpp @@ -0,0 +1,70 @@ +// $Id$ +// +// SuperTux - End Sequence: Tux walks right +// Copyright (C) 2007 Christoph Sommer +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include +#include "endsequence_walkright.hpp" +#include "sector.hpp" +#include "object/player.hpp" + +EndSequenceWalkRight::EndSequenceWalkRight() +: EndSequence() +{ +} + +EndSequenceWalkRight::~EndSequenceWalkRight() +{ +} + +void +EndSequenceWalkRight::draw(DrawingContext& /*context*/) +{ +} + +void +EndSequenceWalkRight::starting() +{ + EndSequence::starting(); + last_x_pos = -1; + endsequence_timer.start(7.3f); +} + +void +EndSequenceWalkRight::running(float elapsed_time) +{ + EndSequence::running(elapsed_time); + Player& tux = *Sector::current()->player; + + if (tux_may_walk) { + end_sequence_controller->press(Controller::RIGHT); + if (int(last_x_pos) == int(tux.get_pos().x)) { + end_sequence_controller->press(Controller::JUMP); + } + } + + last_x_pos = tux.get_pos().x; + + if (endsequence_timer.check()) isdone = true; +} + +void +EndSequenceWalkRight::stopping() +{ + EndSequence::stopping(); +} + diff --git a/src/object/endsequence_walkright.hpp b/src/object/endsequence_walkright.hpp new file mode 100644 index 000000000..aae4a2c77 --- /dev/null +++ b/src/object/endsequence_walkright.hpp @@ -0,0 +1,43 @@ +// $Id$ +// +// SuperTux - End Sequence: Tux walks right +// Copyright (C) 2007 Christoph Sommer +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#ifndef __ENDSEQUENCE_WALKRIGHT_H__ +#define __ENDSEQUENCE_WALKRIGHT_H__ + +#include +#include "object/endsequence.hpp" +#include "timer.hpp" + +class EndSequenceWalkRight : public EndSequence +{ +public: + EndSequenceWalkRight(); + virtual ~EndSequenceWalkRight(); + virtual void draw(DrawingContext& context); + +protected: + virtual void starting(); /**< called when EndSequence starts */ + virtual void running(float elapsed_time); /**< called while the EndSequence is running */ + virtual void stopping(); /**< called when EndSequence stops */ + + float last_x_pos; + Timer endsequence_timer; +}; + +#endif -- 2.11.0