2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "object/camera.hpp"
19 #include "object/sprite_particle.hpp"
20 #include "supertux/globals.hpp"
21 #include "supertux/sector.hpp"
25 SpriteParticle::SpriteParticle(std::string sprite_name, std::string action,
26 Vector position, AnchorPoint anchor, Vector velocity, Vector acceleration,
31 acceleration(acceleration),
32 drawing_layer(drawing_layer)
34 sprite = sprite_manager->create(sprite_name);
35 if (!sprite.get()) throw std::runtime_error("Could not load sprite "+sprite_name);
36 sprite->set_action(action, 1);
37 sprite->set_animation_loops(1); //TODO: this is necessary because set_action will not set "loops" when "action" is the default action
39 this->position -= get_anchor_pos(sprite->get_current_hitbox(), anchor);
42 SpriteParticle::~SpriteParticle()
48 SpriteParticle::hit(Player& )
53 SpriteParticle::update(float elapsed_time)
55 // die when animation is complete
56 if (sprite->animation_done()) {
61 // calculate new position and velocity
62 position.x += velocity.x * elapsed_time;
63 position.y += velocity.y * elapsed_time;
64 velocity.x += acceleration.x * elapsed_time;
65 velocity.y += acceleration.y * elapsed_time;
67 // die when too far offscreen
68 Vector camera = Sector::current()->camera->get_translation();
69 if ((position.x < camera.x - 128) || (position.x > SCREEN_WIDTH + camera.x + 128) ||
70 (position.y < camera.y - 128) || (position.y > SCREEN_HEIGHT + camera.y + 128)) {
77 SpriteParticle::draw(DrawingContext& context)
79 sprite->draw(context, position, drawing_layer);