Candle Class Reference

A burning candle: Simple, scriptable level decoration. More...

#include <candle.hpp>

Inherits MovingSprite, and ScriptInterface.

List of all members.

Public Member Functions

 Candle (const Reader &lisp)
virtual 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 puff_smoke ()
 spawn a puff of smoke
bool get_burning ()
 returns true if candle is lighted
void set_burning (bool burning)
 true: light candle, false: extinguish candle

Private Attributes

bool burning
 true if candle is currently lighted
SurfacePtr candle_light_1
 drawn to lightmap
SurfacePtr candle_light_2
 drawn to lightmap (alternative image)


Detailed Description

A burning candle: Simple, scriptable level decoration.

Definition at line 26 of file candle.hpp.


Constructor & Destructor Documentation

Candle::Candle ( const Reader lisp  ) 

Definition at line 26 of file candle.cpp.

References burning, lisp::Lisp::get(), GameObject::name, and MovingSprite::sprite.

00027   : MovingSprite(lisp, "images/objects/candle/candle.sprite", LAYER_BACKGROUNDTILES+1, COLGROUP_DISABLED), burning(true),
00028     candle_light_1(Surface::create("images/objects/candle/candle-light-1.png")),
00029     candle_light_2(Surface::create("images/objects/candle/candle-light-2.png"))
00030 {
00031   lisp.get("name", name);
00032   lisp.get("burning", burning);
00033 
00034   if (burning) {
00035     sprite->set_action("on");
00036   } else {
00037     sprite->set_action("off");
00038   }
00039 
00040 }


Member Function Documentation

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

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

Reimplemented from MovingSprite.

Definition at line 43 of file candle.cpp.

References MovingObject::bbox, burning, candle_light_1, candle_light_2, DrawingContext::draw_surface(), gameRandom, MovingObject::get_pos(), Rectf::get_size(), MovingSprite::layer, DrawingContext::LIGHTMAP, DrawingContext::pop_target(), DrawingContext::push_target(), RandomGenerator::rand(), DrawingContext::set_target(), and MovingSprite::sprite.

00044 {
00045   // draw regular sprite
00046   sprite->draw(context, get_pos(), layer);
00047 
00048   // draw on lightmap
00049   if (burning) {
00050     Vector pos = get_pos() + (bbox.get_size() - candle_light_1->get_size()) / 2;
00051     context.push_target();
00052     context.set_target(DrawingContext::LIGHTMAP);
00053     // draw approx. 1 in 10 frames darker. Makes the candle flicker
00054     if (gameRandom.rand(10) != 0) {
00055       context.draw_surface(candle_light_1, pos, layer);
00056     } else {
00057       context.draw_surface(candle_light_2, pos, layer);
00058     }
00059     context.pop_target();
00060   }
00061 }

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

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

Implements MovingObject.

Definition at line 64 of file candle.cpp.

References FORCE_MOVE.

00065 {
00066   return FORCE_MOVE;
00067 }

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

Implements ScriptInterface.

Definition at line 70 of file candle.cpp.

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

00071 {
00072   if (name.empty()) return;
00073   scripting::Candle* _this = new scripting::Candle(this);
00074   expose_object(vm, table_idx, _this, name, true);
00075 }

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

Implements ScriptInterface.

Definition at line 78 of file candle.cpp.

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

00079 {
00080   if (name.empty()) return;
00081   scripting::unexpose_object(vm, table_idx, name);
00082 }

void Candle::puff_smoke (  ) 

spawn a puff of smoke

Definition at line 85 of file candle.cpp.

References Sector::add_object(), ANCHOR_MIDDLE, MovingObject::bbox, Sector::current(), Rectf::get_middle(), and LAYER_BACKGROUNDTILES.

Referenced by set_burning().

00086 {
00087   Vector ppos = bbox.get_middle();
00088   Vector pspeed = Vector(0, -150);
00089   Vector paccel = Vector(0,0);
00090   Sector::current()->add_object(new SpriteParticle("images/objects/particles/smoke.sprite", "default", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_BACKGROUNDTILES+2));
00091 }

bool Candle::get_burning (  ) 

returns true if candle is lighted

Definition at line 94 of file candle.cpp.

References burning.

00095 {
00096   return burning;
00097 }

void Candle::set_burning ( bool  burning  ) 

true: light candle, false: extinguish candle

Definition at line 100 of file candle.cpp.

References puff_smoke(), and MovingSprite::sprite.

00101 {
00102   if (this->burning == burning) return;
00103   this->burning = burning;
00104   if (burning) {
00105     sprite->set_action("on");
00106     puff_smoke();
00107   } else {
00108     sprite->set_action("off");
00109     puff_smoke();
00110   }
00111 }


Member Data Documentation

bool Candle::burning [private]

true if candle is currently lighted

Definition at line 50 of file candle.hpp.

Referenced by Candle(), draw(), and get_burning().

SurfacePtr Candle::candle_light_1 [private]

drawn to lightmap

Definition at line 51 of file candle.hpp.

Referenced by draw().

SurfacePtr Candle::candle_light_2 [private]

drawn to lightmap (alternative image)

Definition at line 52 of file candle.hpp.

Referenced by draw().


The documentation for this class was generated from the following files:
Generated on Mon Jun 9 03:38:29 2014 for SuperTux by  doxygen 1.5.1