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 "sprite/sprite.hpp"
20 #include "sprite/sprite_manager.hpp"
21 #include "object/sprite_particle.hpp"
22 #include "supertux/globals.hpp"
23 #include "supertux/sector.hpp"
27 SpriteParticle::SpriteParticle(std::string sprite_name, std::string action,
28 Vector position, AnchorPoint anchor, Vector velocity, Vector acceleration,
33 acceleration(acceleration),
34 drawing_layer(drawing_layer_),
35 light(0.0f,0.0f,0.0f),
36 lightsprite(sprite_manager->create("images/objects/lightmap_light/lightmap_light-tiny.sprite")),
39 sprite = sprite_manager->create(sprite_name);
40 if (!sprite.get()) throw std::runtime_error("Could not load sprite "+sprite_name);
41 sprite->set_action(action, 1);
42 sprite->set_animation_loops(1); //TODO: this is necessary because set_action will not set "loops" when "action" is the default action
44 this->position -= get_anchor_pos(sprite->get_current_hitbox(), anchor);
46 if(sprite_name=="images/objects/particles/sparkle.sprite")
49 lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE));
50 lightsprite->set_color(Color(0.1f, 0.1f, 0.1f));
54 SpriteParticle::~SpriteParticle()
60 SpriteParticle::hit(Player& )
65 SpriteParticle::update(float elapsed_time)
67 // die when animation is complete
68 if (sprite->animation_done()) {
73 // calculate new position and velocity
74 position.x += velocity.x * elapsed_time;
75 position.y += velocity.y * elapsed_time;
76 velocity.x += acceleration.x * elapsed_time;
77 velocity.y += acceleration.y * elapsed_time;
79 // die when too far offscreen
80 Vector camera = Sector::current()->camera->get_translation();
81 if ((position.x < camera.x - 128) || (position.x > SCREEN_WIDTH + camera.x + 128) ||
82 (position.y < camera.y - 128) || (position.y > SCREEN_HEIGHT + camera.y + 128)) {
89 SpriteParticle::draw(DrawingContext& context)
91 sprite->draw(context, position, drawing_layer);
93 //Sparkles glow in the dark
95 context.get_light(position, &light );
96 if (light.red + light.green + light.blue < 3.0){
97 context.push_target();
98 context.set_target(DrawingContext::LIGHTMAP);
99 sprite->draw(context, position, drawing_layer);
100 lightsprite->draw(context, position + Vector(12,12), 0);
101 context.pop_target();