#include <weak_block.hpp>
Inherits MovingSprite.
Public Member Functions | |
WeakBlock (const Reader &lisp) | |
HitResponse | collision (GameObject &other, const CollisionHit &hit) |
this function is called when the object collided with any other object | |
void | update (float elapsed_time) |
This function is called once per frame and allows the object to update it's state. | |
Protected Member Functions | |
void | startBurning () |
called by self when hit by a bullet | |
void | spreadHit () |
pass hit to nearby WeakBlock objects | |
Private Types | |
enum | State { STATE_NORMAL, STATE_BURNING, STATE_DISINTEGRATING } |
Private Attributes | |
State | state |
Definition at line 27 of file weak_block.hpp.
enum WeakBlock::State [private] |
STATE_NORMAL | default state |
STATE_BURNING | on fire, still solid |
STATE_DISINTEGRATING | crumbling to dust, no longer solid |
Definition at line 47 of file weak_block.hpp.
00047 { 00048 STATE_NORMAL, 00049 STATE_BURNING, 00050 STATE_DISINTEGRATING 00051 };
WeakBlock::WeakBlock | ( | const Reader & | lisp | ) |
Definition at line 27 of file weak_block.cpp.
References MovingSprite::sprite.
00028 : MovingSprite(lisp, "images/objects/strawbox/strawbox.sprite", LAYER_TILES, COLGROUP_STATIC), state(STATE_NORMAL) 00029 { 00030 sprite->set_action("normal"); 00031 }
HitResponse WeakBlock::collision | ( | GameObject & | other, | |
const CollisionHit & | hit | |||
) | [virtual] |
this function is called when the object collided with any other object
Implements MovingObject.
Definition at line 34 of file weak_block.cpp.
References FORCE_MOVE, log_debug, startBurning(), state, STATE_BURNING, STATE_DISINTEGRATING, and STATE_NORMAL.
00035 { 00036 switch (state) { 00037 00038 case STATE_NORMAL: 00039 if (dynamic_cast<Bullet*>(&other)) { 00040 startBurning(); 00041 } 00042 if (dynamic_cast<Explosion*> (&other)) { 00043 startBurning(); 00044 } 00045 break; 00046 00047 case STATE_BURNING: 00048 case STATE_DISINTEGRATING: 00049 break; 00050 00051 default: 00052 log_debug << "unhandled state" << std::endl; 00053 break; 00054 } 00055 00056 return FORCE_MOVE; 00057 }
void WeakBlock::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)
Reimplemented from MovingSprite.
Definition at line 60 of file weak_block.cpp.
References COLGROUP_DISABLED, GameObject::remove_me(), MovingObject::set_group(), spreadHit(), MovingSprite::sprite, state, STATE_BURNING, STATE_DISINTEGRATING, and STATE_NORMAL.
00061 { 00062 switch (state) { 00063 00064 case STATE_NORMAL: 00065 break; 00066 00067 case STATE_BURNING: 00068 if (sprite->animation_done()) { 00069 state = STATE_DISINTEGRATING; 00070 sprite->set_action("disintegrating", 1); 00071 spreadHit(); 00072 set_group(COLGROUP_DISABLED); 00073 } 00074 break; 00075 00076 case STATE_DISINTEGRATING: 00077 if (sprite->animation_done()) { 00078 remove_me(); 00079 return; 00080 } 00081 break; 00082 00083 } 00084 }
void WeakBlock::startBurning | ( | ) | [protected] |
called by self when hit by a bullet
Definition at line 87 of file weak_block.cpp.
References MovingSprite::sprite, state, STATE_BURNING, and STATE_NORMAL.
Referenced by collision().
00088 { 00089 if (state != STATE_NORMAL) return; 00090 state = STATE_BURNING; 00091 sprite->set_action("burning", 1); 00092 }
void WeakBlock::spreadHit | ( | ) | [protected] |
pass hit to nearby WeakBlock objects
Definition at line 95 of file weak_block.cpp.
References Sector::current(), Sector::gameobjects, MovingObject::get_pos(), log_debug, STATE_NORMAL, Vector::x, and Vector::y.
Referenced by update().
00096 { 00097 Sector* sector = Sector::current(); 00098 if (!sector) { 00099 log_debug << "no current sector" << std::endl; 00100 return; 00101 } 00102 for(Sector::GameObjects::iterator i = sector->gameobjects.begin(); i != sector->gameobjects.end(); ++i) { 00103 WeakBlock* wb = dynamic_cast<WeakBlock*>(*i); 00104 if (!wb) continue; 00105 if (wb == this) continue; 00106 if (wb->state != STATE_NORMAL) continue; 00107 float dx = fabsf(wb->get_pos().x - this->get_pos().x); 00108 float dy = fabsf(wb->get_pos().y - this->get_pos().y); 00109 if ((dx <= 32.5) && (dy <= 32.5)) wb->startBurning(); 00110 } 00111 }
State WeakBlock::state [private] |
Definition at line 52 of file weak_block.hpp.
Referenced by collision(), startBurning(), and update().