Wind Class Reference

Defines an area that will gently push Players in one direction. More...

#include <wind.hpp>

Inherits MovingObject, and ScriptInterface.

List of all members.

Public Member Functions

 Wind (const Reader &reader)
void update (float elapsed_time)
 This function is called once per frame and allows the object to update it's state.
void draw (DrawingContext &context)
 The GameObject should draw itself onto the provided DrawingContext if this function is called.
HitResponse collision (GameObject &other, const CollisionHit &hit)
 this function is called when the object collided with any other object
virtual void expose (HSQUIRRELVM vm, SQInteger table_idx)
virtual void unexpose (HSQUIRRELVM vm, SQInteger table_idx)
Scriptable Methods
void start ()
 start blowing
void stop ()
 stop blowing

Private Attributes

bool blowing
 true if wind is currently switched on
Vector speed
float acceleration
float elapsed_time
 stores last elapsed_time gotten at update()


Detailed Description

Defines an area that will gently push Players in one direction.

Definition at line 29 of file wind.hpp.


Constructor & Destructor Documentation

Wind::Wind ( const Reader reader  ) 

Definition at line 29 of file wind.cpp.

References acceleration, MovingObject::bbox, blowing, COLGROUP_TOUCHABLE, lisp::Lisp::get(), GameObject::name, Rectf::p1, MovingObject::set_group(), Rectf::set_size(), speed, Vector::x, and Vector::y.

00029                                :
00030   blowing(true), 
00031   speed(),
00032   acceleration(100), 
00033   elapsed_time(0)
00034 {
00035   reader.get("name", name);
00036   reader.get("x", bbox.p1.x);
00037   reader.get("y", bbox.p1.y);
00038   float w = 32, h = 32;
00039   reader.get("width", w);
00040   reader.get("height", h);
00041   bbox.set_size(w, h);
00042 
00043   reader.get("blowing", blowing);
00044 
00045   float speed_x = 0, speed_y = 0;
00046   reader.get("speed-x", speed_x);
00047   reader.get("speed-y", speed_y);
00048   speed = Vector(speed_x, speed_y);
00049 
00050   reader.get("acceleration", acceleration);
00051 
00052   set_group(COLGROUP_TOUCHABLE);
00053 }


Member Function Documentation

void Wind::update ( float  elapsed_time  )  [virtual]

This function is called once per frame and allows the object to update it's state.

The elapsed_time is the time since the last frame in seconds and should be the base for all timed calculations (don't use SDL_GetTicks directly as this will fail in pause mode)

Implements GameObject.

Definition at line 56 of file wind.cpp.

References Sector::add_object(), MovingObject::bbox, blowing, Sector::current(), graphicsRandom, LAYER_BACKGROUNDTILES, Rectf::p1, Rectf::p2, RandomGenerator::rand(), RandomGenerator::randf(), speed, Vector::x, and Vector::y.

00057 {
00058   this->elapsed_time = elapsed_time;
00059 
00060   if (!blowing) return;
00061 
00062   // TODO: nicer, configurable particles for wind?
00063   if (graphicsRandom.rand(0, 100) < 20) {
00064     // emit a particle
00065     Vector ppos = Vector(graphicsRandom.randf(bbox.p1.x+8, bbox.p2.x-8), graphicsRandom.randf(bbox.p1.y+8, bbox.p2.y-8));
00066     Vector pspeed = Vector(speed.x, speed.y);
00067     Sector::current()->add_object(new Particles(ppos, 44, 46, pspeed, Vector(0,0), 1, Color(.4f, .4f, .4f), 3, .1f,
00068                                                 LAYER_BACKGROUNDTILES+1));
00069   }
00070 }

void Wind::draw ( DrawingContext context  )  [virtual]

The GameObject should draw itself onto the provided DrawingContext if this function is called.

Implements GameObject.

Definition at line 73 of file wind.cpp.

00074 {
00075 }

HitResponse Wind::collision ( GameObject other,
const CollisionHit hit 
) [virtual]

this function is called when the object collided with any other object

Implements MovingObject.

Definition at line 78 of file wind.cpp.

References ABORT_MOVE, acceleration, Player::add_velocity(), blowing, elapsed_time, Player::on_ground(), and speed.

00079 {
00080   if (!blowing) return ABORT_MOVE;
00081 
00082   Player* player = dynamic_cast<Player*> (&other);
00083   if (player) {
00084     if (!player->on_ground()) {
00085       player->add_velocity(speed * acceleration * elapsed_time, speed);
00086     }
00087   }
00088 
00089   return ABORT_MOVE;
00090 }

void Wind::start (  ) 

start blowing

Definition at line 112 of file wind.cpp.

References blowing.

Referenced by scripting::Wind::start().

00113 {
00114   blowing = true;
00115 }

void Wind::stop (  ) 

stop blowing

Definition at line 118 of file wind.cpp.

References blowing.

Referenced by scripting::Wind::stop().

00119 {
00120   blowing = false;
00121 }

void Wind::expose ( HSQUIRRELVM  vm,
SQInteger  table_idx 
) [virtual]

Implements ScriptInterface.

Definition at line 93 of file wind.cpp.

References scripting::expose_object(), and GameObject::name.

00094 {
00095   if (name == "")
00096     return;
00097 
00098   scripting::Wind* _this = new scripting::Wind(this);
00099   expose_object(vm, table_idx, _this, name, true);
00100 }

void Wind::unexpose ( HSQUIRRELVM  vm,
SQInteger  table_idx 
) [virtual]

Implements ScriptInterface.

Definition at line 103 of file wind.cpp.

References GameObject::name, and scripting::unexpose_object().

00104 {
00105   if (name == "")
00106     return;
00107 
00108   scripting::unexpose_object(vm, table_idx, name);
00109 }


Member Data Documentation

bool Wind::blowing [private]

true if wind is currently switched on

Definition at line 62 of file wind.hpp.

Referenced by collision(), start(), stop(), update(), and Wind().

Vector Wind::speed [private]

Definition at line 63 of file wind.hpp.

Referenced by collision(), update(), and Wind().

float Wind::acceleration [private]

Definition at line 64 of file wind.hpp.

Referenced by collision(), and Wind().

float Wind::elapsed_time [private]

stores last elapsed_time gotten at update()

Definition at line 66 of file wind.hpp.

Referenced by collision().


The documentation for this class was generated from the following files:
Generated on Mon Apr 14 03:38:47 2014 for SuperTux by  doxygen 1.5.1