SpriteParticle Class Reference

#include <sprite_particle.hpp>

Inherits GameObject.

List of all members.

Public Member Functions

 SpriteParticle (std::string sprite_name, std::string action, Vector position, AnchorPoint anchor, Vector velocity, Vector acceleration, int drawing_layer=LAYER_OBJECTS-1)
 ~SpriteParticle ()

Protected Member Functions

virtual void hit (Player &player)
virtual void update (float elapsed_time)
 This function is called once per frame and allows the object to update it's state.
virtual void draw (DrawingContext &context)
 The GameObject should draw itself onto the provided DrawingContext if this function is called.

Private Member Functions

 SpriteParticle (const SpriteParticle &)
SpriteParticleoperator= (const SpriteParticle &)

Private Attributes

SpritePtr sprite
Vector position
Vector velocity
Vector acceleration
int drawing_layer


Detailed Description

Definition at line 27 of file sprite_particle.hpp.


Constructor & Destructor Documentation

SpriteParticle::SpriteParticle ( std::string  sprite_name,
std::string  action,
Vector  position,
AnchorPoint  anchor,
Vector  velocity,
Vector  acceleration,
int  drawing_layer = LAYER_OBJECTS-1 
)

Definition at line 25 of file sprite_particle.cpp.

References SpriteManager::create(), get_anchor_pos(), position, sprite, and sprite_manager.

00027                                                   :
00028   sprite(),
00029   position(position), 
00030   velocity(velocity), 
00031   acceleration(acceleration), 
00032   drawing_layer(drawing_layer)
00033 {
00034   sprite = sprite_manager->create(sprite_name);
00035   if (!sprite.get()) throw std::runtime_error("Could not load sprite "+sprite_name);
00036   sprite->set_action(action, 1);
00037   sprite->set_animation_loops(1); //TODO: this is necessary because set_action will not set "loops" when "action" is the default action
00038 
00039   this->position -= get_anchor_pos(sprite->get_current_hitbox(), anchor);
00040 }

SpriteParticle::~SpriteParticle (  ) 

Definition at line 42 of file sprite_particle.cpp.

References GameObject::remove_me().

00043 {
00044   remove_me();
00045 }

SpriteParticle::SpriteParticle ( const SpriteParticle  )  [private]


Member Function Documentation

void SpriteParticle::hit ( Player player  )  [protected, virtual]

Definition at line 48 of file sprite_particle.cpp.

00049 {
00050 }

void SpriteParticle::update ( float  elapsed_time  )  [protected, 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 53 of file sprite_particle.cpp.

References acceleration, Sector::camera, scripting::camera(), Sector::current(), Camera::get_translation(), position, GameObject::remove_me(), SCREEN_HEIGHT, SCREEN_WIDTH, sprite, velocity, Vector::x, and Vector::y.

00054 {
00055   // die when animation is complete
00056   if (sprite->animation_done()) {
00057     remove_me();
00058     return;
00059   }
00060 
00061   // calculate new position and velocity
00062   position.x += velocity.x * elapsed_time;
00063   position.y += velocity.y * elapsed_time;
00064   velocity.x += acceleration.x * elapsed_time;
00065   velocity.y += acceleration.y * elapsed_time;
00066 
00067   // die when too far offscreen
00068   Vector camera = Sector::current()->camera->get_translation();
00069   if ((position.x < camera.x - 128) || (position.x > SCREEN_WIDTH + camera.x + 128) ||
00070       (position.y < camera.y - 128) || (position.y > SCREEN_HEIGHT + camera.y + 128)) {
00071     remove_me();
00072     return;
00073   }
00074 }

void SpriteParticle::draw ( DrawingContext context  )  [protected, virtual]

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

Implements GameObject.

Definition at line 77 of file sprite_particle.cpp.

References drawing_layer, position, and sprite.

00078 {
00079   sprite->draw(context, position, drawing_layer);
00080 }

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


Member Data Documentation

SpritePtr SpriteParticle::sprite [private]

Definition at line 38 of file sprite_particle.hpp.

Referenced by draw(), SpriteParticle(), and update().

Vector SpriteParticle::position [private]

Definition at line 39 of file sprite_particle.hpp.

Referenced by draw(), SpriteParticle(), and update().

Vector SpriteParticle::velocity [private]

Definition at line 40 of file sprite_particle.hpp.

Referenced by update().

Vector SpriteParticle::acceleration [private]

Definition at line 41 of file sprite_particle.hpp.

Referenced by update().

int SpriteParticle::drawing_layer [private]

Definition at line 42 of file sprite_particle.hpp.

Referenced by draw().


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