X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Ftrigger%2Fclimbable.cpp;h=42b8f60e4e17bc36821191bf1fd71a542a0faf71;hb=1f5ff04e5283398473b4ac033258b17af0ed08f0;hp=b2a4e4923ed971ddd335b633d4f19691a23756cb;hpb=fea3446f05e1e7673607b835c269d3e8d1929ab3;p=supertux.git diff --git a/src/trigger/climbable.cpp b/src/trigger/climbable.cpp index b2a4e4923..42b8f60e4 100644 --- a/src/trigger/climbable.cpp +++ b/src/trigger/climbable.cpp @@ -1,12 +1,10 @@ -// $Id$ -// // SuperTux - Climbable area // 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 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 3 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 @@ -14,32 +12,27 @@ // 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. +// along with this program. If not, see . -#include +#include "trigger/climbable.hpp" -#include "climbable.hpp" -#include "game_session.hpp" -#include "lisp/lisp.hpp" -#include "lisp/writer.hpp" -#include "object_factory.hpp" -#include "main.hpp" -#include "sector.hpp" -#include "level.hpp" -#include "gettext.hpp" -#include "object/tilemap.hpp" +#include "object/player.hpp" +#include "supertux/globals.hpp" +#include "supertux/object_factory.hpp" +#include "util/gettext.hpp" +#include "util/reader.hpp" namespace { - const float GRACE_DX = 8; // how far off may the player's bounding-box be x-wise - const float GRACE_DY = 8; // how far off may the player's bounding-box be y-wise - const float ACTIVATE_TRY_FOR = 1; // how long to try correcting mis-alignment of player and climbable before giving up - const float POSITION_FIX_AX = 50; // x-wise acceleration applied to player when trying to align player and Climbable - const float POSITION_FIX_AY = 50; // y-wise acceleration applied to player when trying to align player and Climbable +const float GRACE_DX = 8; // how far off may the player's bounding-box be x-wise +const float GRACE_DY = 8; // how far off may the player's bounding-box be y-wise +const float ACTIVATE_TRY_FOR = 1; // how long to try correcting mis-alignment of player and climbable before giving up +const float POSITION_FIX_AX = 30; // x-wise acceleration applied to player when trying to align player and Climbable +const float POSITION_FIX_AY = 50; // y-wise acceleration applied to player when trying to align player and Climbable } -Climbable::Climbable(const lisp::Lisp& reader) - : climbed_by(0) +Climbable::Climbable(const Reader& reader) : + climbed_by(0), + activate_try_timer() { reader.get("x", bbox.p1.x); reader.get("y", bbox.p1.y); @@ -49,8 +42,9 @@ Climbable::Climbable(const lisp::Lisp& reader) bbox.set_size(w, h); } -Climbable::Climbable(const Rect& area) - : climbed_by(0) +Climbable::Climbable(const Rectf& area) : + climbed_by(0), + activate_try_timer() { bbox = area; } @@ -64,19 +58,6 @@ Climbable::~Climbable() } void -Climbable::write(lisp::Writer& writer) -{ - writer.start_list("climbable"); - - writer.write_float("x", bbox.p1.x); - writer.write_float("y", bbox.p1.y); - writer.write_float("width", bbox.get_width()); - writer.write_float("height", bbox.get_height()); - - writer.end_list("climbable"); -} - -void Climbable::update(float /*elapsed_time*/) { if (!climbed_by) return; @@ -93,8 +74,8 @@ Climbable::draw(DrawingContext& context) if (climbed_by) { context.push_transform(); context.set_translation(Vector(0, 0)); - Vector pos = Vector(0, SCREEN_HEIGHT/2 - gold_text->get_height()/2); - context.draw_center_text(gold_text, "Up we go...", pos, LAYER_GUI); + Vector pos = Vector(0, SCREEN_HEIGHT/2 - Resources::normal_font->get_height()/2); + context.draw_center_text(Resources::normal_font, _("Up we go..."), pos, LAYER_HUD, Climbable::text_color); context.pop_transform(); } } @@ -103,16 +84,19 @@ void Climbable::event(Player& player, EventType type) { if ((type == EVENT_ACTIVATE) || (activate_try_timer.started())) { - if (may_climb(player)) { - climbed_by = &player; - player.start_climbing(*this); - activate_try_timer.stop(); - } else { - if (type == EVENT_ACTIVATE) activate_try_timer.start(ACTIVATE_TRY_FOR); - if (player.get_bbox().p1.x < get_bbox().p1.x - GRACE_DX) player.add_velocity(Vector(POSITION_FIX_AX,0)); - if (player.get_bbox().p2.x > get_bbox().p2.x + GRACE_DX) player.add_velocity(Vector(-POSITION_FIX_AX,0)); - if (player.get_bbox().p1.y < get_bbox().p1.y - GRACE_DY) player.add_velocity(Vector(0,POSITION_FIX_AY)); - if (player.get_bbox().p2.y > get_bbox().p2.y + GRACE_DY) player.add_velocity(Vector(0,-POSITION_FIX_AY)); + if(player.get_grabbed_object() == NULL){ + if(may_climb(player)) { + climbed_by = &player; + player.start_climbing(*this); + activate_try_timer.stop(); + } else { + if (type == EVENT_ACTIVATE) activate_try_timer.start(ACTIVATE_TRY_FOR); + // the "-13" to y velocity prevents Tux from walking in place on the ground for horizonal adjustments + if (player.get_bbox().p1.x < get_bbox().p1.x - GRACE_DX) player.add_velocity(Vector(POSITION_FIX_AX,-13)); + if (player.get_bbox().p2.x > get_bbox().p2.x + GRACE_DX) player.add_velocity(Vector(-POSITION_FIX_AX,-13)); + if (player.get_bbox().p1.y < get_bbox().p1.y - GRACE_DY) player.add_velocity(Vector(0,POSITION_FIX_AY)); + if (player.get_bbox().p2.y > get_bbox().p2.y + GRACE_DY) player.add_velocity(Vector(0,-POSITION_FIX_AY)); + } } } if(type == EVENT_LOSETOUCH) { @@ -122,7 +106,7 @@ Climbable::event(Player& player, EventType type) } bool -Climbable::may_climb(Player& player) +Climbable::may_climb(Player& player) { if (player.get_bbox().p1.x < get_bbox().p1.x - GRACE_DX) return false; if (player.get_bbox().p2.x > get_bbox().p2.x + GRACE_DX) return false; @@ -131,5 +115,4 @@ Climbable::may_climb(Player& player) return true; } -IMPLEMENT_FACTORY(Climbable, "climbable"); - +/* EOF */