#include <secretarea_trigger.hpp>
Inherits TriggerBase.
Public Member Functions | |
SecretAreaTrigger (const Reader &reader) | |
SecretAreaTrigger (const Rectf &area, std::string fade_tilemap="") | |
~SecretAreaTrigger () | |
void | event (Player &player, EventType type) |
Receive trigger events. | |
void | draw (DrawingContext &context) |
The GameObject should draw itself onto the provided DrawingContext if this function is called. | |
Private Attributes | |
Timer | message_timer |
bool | message_displayed |
std::string | message |
message to display, default "You found a secret area!" | |
std::string | fade_tilemap |
tilemap to fade away when trigger is activated, or empty if you don't care | |
Static Private Attributes | |
static Color | text_color |
Definition at line 29 of file secretarea_trigger.hpp.
SecretAreaTrigger::SecretAreaTrigger | ( | const Reader & | reader | ) |
Definition at line 31 of file secretarea_trigger.cpp.
References _(), MovingObject::bbox, fade_tilemap, lisp::Lisp::get(), message, message_displayed, Rectf::p1, Rectf::set_size(), Vector::x, and Vector::y.
00031 : 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 }
SecretAreaTrigger::SecretAreaTrigger | ( | const Rectf & | area, | |
std::string | fade_tilemap = "" | |||
) |
Definition at line 52 of file secretarea_trigger.cpp.
References MovingObject::bbox, and message_displayed.
00052 : 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 }
SecretAreaTrigger::~SecretAreaTrigger | ( | ) |
Receive trigger events.
Implements TriggerBase.
Definition at line 82 of file secretarea_trigger.cpp.
References Sector::current(), TriggerBase::EVENT_TOUCH, fade_tilemap, Sector::gameobjects, Sector::get_level(), message_displayed, MESSAGE_TIME, message_timer, Statistics::secrets, Timer::start(), and Level::stats.
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 }
void SecretAreaTrigger::draw | ( | DrawingContext & | context | ) | [virtual] |
The GameObject should draw itself onto the provided DrawingContext if this function is called.
Reimplemented from TriggerBase.
Definition at line 67 of file secretarea_trigger.cpp.
References Timer::check(), DrawingContext::draw_center_text(), LAYER_HUD, message, message_timer, Resources::normal_font, DrawingContext::pop_transform(), DrawingContext::push_transform(), GameObject::remove_me(), SCREEN_HEIGHT, DrawingContext::set_translation(), Timer::started(), and text_color.
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 }
Color SecretAreaTrigger::text_color [static, private] |
Timer SecretAreaTrigger::message_timer [private] |
bool SecretAreaTrigger::message_displayed [private] |
Definition at line 42 of file secretarea_trigger.hpp.
Referenced by event(), and SecretAreaTrigger().
std::string SecretAreaTrigger::message [private] |
message to display, default "You found a secret area!"
Definition at line 43 of file secretarea_trigger.hpp.
Referenced by draw(), and SecretAreaTrigger().
std::string SecretAreaTrigger::fade_tilemap [private] |
tilemap to fade away when trigger is activated, or empty if you don't care
Definition at line 44 of file secretarea_trigger.hpp.
Referenced by event(), and SecretAreaTrigger().