#include <star.hpp>
Inherits MovingSprite.
Public Member Functions | |
Star (const Vector &pos, Direction direction=RIGHT) | |
virtual void | update (float elapsed_time) |
This function is called once per frame and allows the object to update it's state. | |
virtual void | collision_solid (const CollisionHit &hit) |
this function is called when the object collided with something solid | |
virtual HitResponse | collision (GameObject &other, const CollisionHit &hit) |
this function is called when the object collided with any other object | |
Private Attributes | |
Physic | physic |
Definition at line 22 of file star.hpp.
Definition at line 24 of file star.cpp.
References INITIALJUMP, LEFT, physic, Physic::set_velocity(), and STAR_SPEED.
00024 : 00025 MovingSprite(pos, "images/powerups/star/star.sprite", LAYER_OBJECTS, COLGROUP_MOVING), 00026 physic() 00027 { 00028 physic.set_velocity((direction == LEFT) ? -STAR_SPEED : STAR_SPEED, INITIALJUMP); 00029 }
void Star::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 32 of file star.cpp.
References Physic::get_movement(), MovingObject::movement, and physic.
00033 { 00034 movement = physic.get_movement(elapsed_time); 00035 }
void Star::collision_solid | ( | const CollisionHit & | hit | ) | [virtual] |
this function is called when the object collided with something solid
Reimplemented from MovingObject.
Definition at line 38 of file star.cpp.
References CollisionHit::bottom, Physic::get_velocity_x(), JUMPSTAR_SPEED, CollisionHit::left, physic, CollisionHit::right, Physic::set_velocity_x(), Physic::set_velocity_y(), and CollisionHit::top.
00039 { 00040 if(hit.bottom) { 00041 physic.set_velocity_y(JUMPSTAR_SPEED); 00042 } else if(hit.top) { 00043 physic.set_velocity_y(0); 00044 } else if(hit.left || hit.right) { 00045 physic.set_velocity_x(-physic.get_velocity_x()); 00046 } 00047 }
HitResponse Star::collision | ( | GameObject & | other, | |
const CollisionHit & | hit | |||
) | [virtual] |
this function is called when the object collided with any other object
Implements MovingObject.
Definition at line 50 of file star.cpp.
References ABORT_MOVE, FORCE_MOVE, Player::make_invincible(), and GameObject::remove_me().
00051 { 00052 Player* player = dynamic_cast<Player*> (&other); 00053 if(player) { 00054 player->make_invincible(); 00055 remove_me(); 00056 return ABORT_MOVE; 00057 } 00058 00059 return FORCE_MOVE; 00060 }
Physic Star::physic [private] |