00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "object/camera.hpp"
00019 #include "object/sprite_particle.hpp"
00020 #include "supertux/globals.hpp"
00021 #include "supertux/sector.hpp"
00022
00023 #include <stdexcept>
00024
00025 SpriteParticle::SpriteParticle(std::string sprite_name, std::string action,
00026 Vector position, AnchorPoint anchor, Vector velocity, Vector acceleration,
00027 int drawing_layer) :
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);
00038
00039 this->position -= get_anchor_pos(sprite->get_current_hitbox(), anchor);
00040 }
00041
00042 SpriteParticle::~SpriteParticle()
00043 {
00044 remove_me();
00045 }
00046
00047 void
00048 SpriteParticle::hit(Player& )
00049 {
00050 }
00051
00052 void
00053 SpriteParticle::update(float elapsed_time)
00054 {
00055
00056 if (sprite->animation_done()) {
00057 remove_me();
00058 return;
00059 }
00060
00061
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
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 }
00075
00076 void
00077 SpriteParticle::draw(DrawingContext& context)
00078 {
00079 sprite->draw(context, position, drawing_layer);
00080 }
00081
00082