1 // $Id: rainsplash.cpp 3327 2006-04-13 15:02:40Z ravu_al_hemio $
4 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
5 // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include "sprite_particle.hpp"
26 SpriteParticle::SpriteParticle(std::string sprite_name, Vector position, Vector velocity, Vector acceleration, int drawing_layer)
27 : position(position), velocity(velocity), acceleration(acceleration), drawing_layer(drawing_layer)
29 sprite = sprite_manager->create(sprite_name);
30 if (!sprite) throw std::runtime_error("Could not load sprite "+sprite_name);
31 sprite->set_animation_loops(1);
34 SpriteParticle::~SpriteParticle()
40 SpriteParticle::hit(Player& )
45 SpriteParticle::update(float elapsed_time)
47 // die when animation is complete
48 if (sprite->animation_done()) {
53 // calculate new position and velocity
54 position.x += velocity.x * elapsed_time;
55 position.y += velocity.y * elapsed_time;
56 velocity.x += acceleration.x * elapsed_time;
57 velocity.y += acceleration.y * elapsed_time;
59 // die when too far offscreen
60 Vector camera = Sector::current()->camera->get_translation();
61 if ((position.x < camera.x - 128) || (position.x > SCREEN_WIDTH + camera.x + 128) ||
62 (position.y < camera.y - 128) || (position.y > SCREEN_HEIGHT + camera.y + 128)) {
69 SpriteParticle::draw(DrawingContext& context)
71 sprite->draw(context, position, drawing_layer);