src/trigger/secretarea_trigger.cpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #include "trigger/secretarea_trigger.hpp"
00018 
00019 #include "object/tilemap.hpp"
00020 #include "supertux/level.hpp"
00021 #include "supertux/globals.hpp"
00022 #include "supertux/object_factory.hpp"
00023 #include "supertux/resources.hpp"
00024 #include "supertux/sector.hpp"
00025 #include "util/gettext.hpp"
00026 #include "util/reader.hpp"
00027 #include "util/writer.hpp"
00028 
00029 static const float MESSAGE_TIME=3.5;
00030 
00031 SecretAreaTrigger::SecretAreaTrigger(const Reader& reader) :
00032   message_timer(),
00033   message_displayed(),
00034   message(),
00035   fade_tilemap()
00036 {
00037   reader.get("x", bbox.p1.x);
00038   reader.get("y", bbox.p1.y);
00039   float w = 32, h = 32;
00040   reader.get("width", w);
00041   reader.get("height", h);
00042   bbox.set_size(w, h);
00043   reader.get("fade-tilemap", fade_tilemap);
00044   reader.get("message", message);
00045   if(message == "") {
00046     message = _("You found a secret area!");
00047   }
00048 
00049   message_displayed = false;
00050 }
00051 
00052 SecretAreaTrigger::SecretAreaTrigger(const Rectf& area, std::string fade_tilemap) :
00053   message_timer(),
00054   message_displayed(),
00055   message(_("You found a secret area!")),
00056   fade_tilemap(fade_tilemap)
00057 {
00058   bbox = area;
00059   message_displayed = false;
00060 }
00061 
00062 SecretAreaTrigger::~SecretAreaTrigger()
00063 {
00064 }
00065 
00066 void
00067 SecretAreaTrigger::draw(DrawingContext& context)
00068 {
00069   if (message_timer.started()) {
00070     context.push_transform();
00071     context.set_translation(Vector(0, 0));
00072     Vector pos = Vector(0, SCREEN_HEIGHT/2 - Resources::normal_font->get_height()/2);
00073     context.draw_center_text(Resources::normal_font, message, pos, LAYER_HUD, SecretAreaTrigger::text_color);
00074     context.pop_transform();
00075   }
00076   if (message_timer.check()) {
00077     remove_me();
00078   }
00079 }
00080 
00081 void
00082 SecretAreaTrigger::event(Player& , EventType type)
00083 {
00084   if(type == EVENT_TOUCH) {
00085     if (!message_displayed) {
00086       message_timer.start(MESSAGE_TIME);
00087       message_displayed = true;
00088       Sector::current()->get_level()->stats.secrets++;
00089 
00090       if (fade_tilemap != "") {
00091         // fade away tilemaps
00092         Sector& sector = *Sector::current();
00093         for(Sector::GameObjects::iterator i = sector.gameobjects.begin(); i != sector.gameobjects.end(); ++i) {
00094           TileMap* tm = dynamic_cast<TileMap*>(*i);
00095           if (!tm) continue;
00096           if (tm->get_name() != fade_tilemap) continue;
00097           tm->fade(0.0, 1.0);
00098         }
00099       }
00100 
00101     }
00102   }
00103 }
00104 
00105 /* EOF */

Generated on Mon Apr 21 03:38:18 2014 for SuperTux by  doxygen 1.5.1