GameObject Class Reference

Base class for all the things that make up Levels' Sectors. More...

#include <game_object.hpp>

Inherits RefCounter.

Inherited by AmbientSound, Background, BouncyCoin, BrokenBrick, Camera, DisplayEffect, Electrifier, EndSequence, FallingCoin, Fireworks, FloatingImage, FloatingText, Gradient, LevelTime, Light, MovingObject, Particles, ParticleSystem, ParticleSystem_Interactive, RainSplash, SmokeCloud, SpecialRiser, Spotlight, SpriteParticle, TextObject, Thunderstorm, TileMap, worldmap::LevelTile, worldmap::SpecialTile, worldmap::SpriteChange, worldmap::Teleporter, and worldmap::Tux.

List of all members.

Public Member Functions

 GameObject ()
 GameObject (const GameObject &rhs)
virtual ~GameObject ()
virtual void update (float elapsed_time)=0
 This function is called once per frame and allows the object to update it's state.
virtual void draw (DrawingContext &context)=0
 The GameObject should draw itself onto the provided DrawingContext if this function is called.
bool is_valid () const
 returns true if the object is not scheduled to be removed yet
void remove_me ()
 schedules this object to be removed at the end of the frame
void add_remove_listener (ObjectRemoveListener *listener)
 registers a remove listener which will be called if the object gets removed/destroyed
void del_remove_listener (ObjectRemoveListener *listener)
 unregisters a remove listener, so it will no longer be called if the object gets removed/destroyed
const std::string & get_name () const

Protected Attributes

std::string name
 a name for the gameobject, this is mostly a hint for scripts and for debugging, don't rely on names being set or being unique

Private Member Functions

GameObjectoperator= (const GameObject &)

Private Attributes

bool wants_to_die
 this flag indicates if the object should be removed at the end of the frame
RemoveListenerListEntryremove_listeners

Classes

struct  RemoveListenerListEntry


Detailed Description

Base class for all the things that make up Levels' Sectors.

Each sector of a level will hold a list of active GameObject while the game is played.

This class is responsible for:

Definition at line 39 of file game_object.hpp.


Constructor & Destructor Documentation

GameObject::GameObject (  ) 

Definition at line 20 of file game_object.cpp.

00020                        :
00021   wants_to_die(false), 
00022   remove_listeners(NULL),
00023   name()
00024 {
00025 }

GameObject::GameObject ( const GameObject rhs  ) 

Definition at line 27 of file game_object.cpp.

00027                                             :
00028   RefCounter(),
00029   wants_to_die(rhs.wants_to_die),
00030   remove_listeners(NULL),
00031   name(rhs.name)
00032 {  
00033 }

GameObject::~GameObject (  )  [virtual]

Definition at line 35 of file game_object.cpp.

References GameObject::RemoveListenerListEntry::listener, GameObject::RemoveListenerListEntry::next, ObjectRemoveListener::object_removed(), and remove_listeners.

00036 {
00037   // call remove listeners (and remove them from the list)
00038   RemoveListenerListEntry* entry = remove_listeners;
00039   while(entry != NULL) {
00040     RemoveListenerListEntry* next = entry->next;
00041     entry->listener->object_removed(this);
00042     delete entry;
00043     entry = next;
00044   }
00045 }


Member Function Documentation

virtual void GameObject::update ( float  elapsed_time  )  [pure 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)

Implemented in BadGuy, YetiStalactite, AmbientSound, Background, BicyclePlatform, Block, BouncyCoin, BrokenBrick, Bullet, Camera, CloudParticleSystem, Coin, CometParticleSystem, DisplayEffect, Electrifier, EndSequence, Explosion, FallingCoin, Fireworks, FloatingImage, FloatingText, Flower, GhostParticleSystem, Gradient, GrowUp, IceCrusher, InfoBlock, Ispy, LevelTime, Light, MagicBlock, MovingSprite, OneUp, Particles, Platform, Player, PneumaticPlatform, PowerUp, PulsingLight, PushButton, RainParticleSystem, RainSplash, Rock, ScriptedObject, SkullTile, SmokeCloud, SnowParticleSystem, SpecialRiser, Spotlight, SpriteParticle, Star, TextObject, Thunderstorm, TileMap, Trampoline, UnstableTile, WeakBlock, Wind, Climbable, Door, Switch, TriggerBase, worldmap::LevelTile, worldmap::SpecialTile, worldmap::SpriteChange, worldmap::Teleporter, and worldmap::Tux.

virtual void GameObject::draw ( DrawingContext context  )  [pure virtual]

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

Implemented in BadGuy, Fish, GhostTree, Root, Stalactite, TreeWillOWisp, WillOWisp, Yeti, AmbientSound, Background, Block, BouncyCoin, BrokenBrick, Bullet, Camera, Candle, DisplayEffect, Electrifier, EndSequence, EndSequenceFireworks, EndSequenceWalkLeft, EndSequenceWalkRight, FallingCoin, Fireworks, FloatingImage, FloatingText, Flower, Gradient, InfoBlock, InvisibleBlock, Lantern, LevelTime, Light, MagicBlock, MovingSprite, Particles, ParticleSystem, ParticleSystem_Interactive, Player, PulsingLight, RainSplash, ScriptedObject, SkullTile, SmokeCloud, SpecialRiser, Spotlight, SpriteParticle, TextObject, Thunderstorm, TileMap, Wind, Climbable, Door, SecretAreaTrigger, Switch, TriggerBase, worldmap::LevelTile, worldmap::SpecialTile, worldmap::SpriteChange, worldmap::Teleporter, and worldmap::Tux.

Referenced by SpecialRiser::draw().

bool GameObject::is_valid (  )  const [inline]

returns true if the object is not scheduled to be removed yet

Definition at line 59 of file game_object.hpp.

References wants_to_die.

Referenced by ShortFuse::collision_squished(), MrBomb::collision_squished(), SkyDive::explode(), ShortFuse::explode(), Bomb::explode(), MrBomb::kill_fall(), and Haywire::kill_fall().

00060   {
00061     return !wants_to_die;
00062   }

void GameObject::remove_me (  )  [inline]

schedules this object to be removed at the end of the frame

Definition at line 65 of file game_object.hpp.

References wants_to_die.

Referenced by Yeti::active_update(), WillOWisp::active_update(), TreeWillOWisp::active_update(), Root::active_update(), Block::break_me(), Coin::collect(), Star::collision(), PowerUp::collision(), OneUp::collision(), GrowUp::collision(), Flower::collision(), MoleRock::collision_badguy(), Dart::collision_badguy(), BadGuy::collision_bullet(), MoleRock::collision_player(), Dart::collision_player(), Bullet::collision_solid(), MoleRock::collision_solid(), Dart::collision_solid(), MrTree::collision_squished(), MrBomb::collision_squished(), WillOWisp::deactivate(), Stalactite::deactivate(), Root::deactivate(), MoleRock::deactivate(), Dart::deactivate(), SecretAreaTrigger::draw(), SkyDive::explode(), ShortFuse::explode(), Kugelblitz::explode(), Bomb::explode(), UnstableTile::fall_down(), MrBomb::kill_fall(), Haywire::kill_fall(), BadGuy::set_state(), UnstableTile::slow_fall(), AmbientSound::start_playing(), WeakBlock::update(), UnstableTile::update(), SpriteParticle::update(), SpecialRiser::update(), SmokeCloud::update(), SkullTile::update(), RainSplash::update(), Particles::update(), OneUp::update(), FloatingText::update(), FallingCoin::update(), Explosion::update(), Electrifier::update(), Bullet::update(), BrokenBrick::update(), BouncyCoin::update(), BadGuy::update(), RainSplash::~RainSplash(), and SpriteParticle::~SpriteParticle().

00066   {
00067     wants_to_die = true;
00068   }

void GameObject::add_remove_listener ( ObjectRemoveListener listener  ) 

registers a remove listener which will be called if the object gets removed/destroyed

Definition at line 48 of file game_object.cpp.

References GameObject::RemoveListenerListEntry::listener, GameObject::RemoveListenerListEntry::next, and remove_listeners.

00049 {
00050   RemoveListenerListEntry* entry = new RemoveListenerListEntry();
00051   entry->next = remove_listeners;
00052   entry->listener = listener;
00053   remove_listeners = entry;
00054 }

void GameObject::del_remove_listener ( ObjectRemoveListener listener  ) 

unregisters a remove listener, so it will no longer be called if the object gets removed/destroyed

Definition at line 57 of file game_object.cpp.

References GameObject::RemoveListenerListEntry::listener, GameObject::RemoveListenerListEntry::next, and remove_listeners.

00058 {
00059   RemoveListenerListEntry* entry = remove_listeners;
00060   if (entry->listener == listener) {
00061     remove_listeners = entry->next;
00062     delete entry;
00063     return;
00064   }
00065   RemoveListenerListEntry* next = entry->next;
00066   while(next != NULL) {
00067     if (next->listener == listener) {
00068       entry->next = next->next;
00069       delete next;
00070       break;
00071     }
00072     entry = next;
00073     next = next->next;
00074   }
00075 }

const std::string& GameObject::get_name (  )  const [inline]

Definition at line 81 of file game_object.hpp.

References name.

Referenced by Firefly::collision(), worldmap::WorldMap::get_level_title(), and worldmap::WorldMap::update().

00082   {
00083     return name;
00084   }

GameObject& GameObject::operator= ( const GameObject  )  [private]


Member Data Documentation

bool GameObject::wants_to_die [private]

this flag indicates if the object should be removed at the end of the frame

Definition at line 90 of file game_object.hpp.

Referenced by is_valid(), and remove_me().

RemoveListenerListEntry* GameObject::remove_listeners [private]

Definition at line 97 of file game_object.hpp.

Referenced by add_remove_listener(), del_remove_listener(), and ~GameObject().

std::string GameObject::name [protected]

a name for the gameobject, this is mostly a hint for scripts and for debugging, don't rely on names being set or being unique

Reimplemented in AmbientSound, and ScriptedObject.

Definition at line 104 of file game_object.hpp.

Referenced by Candle::Candle(), Wind::expose(), TileMap::expose(), Thunderstorm::expose(), TextObject::expose(), Player::expose(), Platform::expose(), LevelTime::expose(), DisplayEffect::expose(), Candle::expose(), Camera::expose(), WillOWisp::expose(), get_name(), worldmap::LevelTile::LevelTile(), LevelTime::LevelTime(), Platform::Platform(), Thunderstorm::Thunderstorm(), TileMap::TileMap(), Wind::unexpose(), TileMap::unexpose(), Thunderstorm::unexpose(), TextObject::unexpose(), Player::unexpose(), Platform::unexpose(), LevelTime::unexpose(), DisplayEffect::unexpose(), Candle::unexpose(), Camera::unexpose(), WillOWisp::unexpose(), WillOWisp::WillOWisp(), and Wind::Wind().


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