4 // Copyright (C) 2000 Bill Kendrick <bill@newbreedsoftware.com>
5 // Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.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
27 #include "app/globals.h"
29 #include "tile_manager.h"
32 #include "special/sprite_manager.h"
33 #include "resources.h"
36 #include "video/drawing_context.h"
39 BouncyCoin::BouncyCoin(const Vector& pos)
43 sprite = sprite_manager->create("coin");
44 sprite->set_action("still");
47 BouncyCoin::~BouncyCoin()
53 BouncyCoin::action(float elapsed_time)
55 position.y += -200 * elapsed_time;
62 BouncyCoin::draw(DrawingContext& context)
64 sprite->draw(context, position, LAYER_OBJECTS);
67 //---------------------------------------------------------------------------
69 BrokenBrick::BrokenBrick(Sprite* nsprite,
70 const Vector& pos, const Vector& nmovement)
71 : sprite(new Sprite(*nsprite)), position(pos), movement(nmovement)
76 BrokenBrick::~BrokenBrick()
82 BrokenBrick::action(float elapsed_time)
84 position += movement * elapsed_time;
91 BrokenBrick::draw(DrawingContext& context)
93 sprite->draw_part(context,
94 Vector(rand() % 16, rand() % 16), Vector(16, 16),
95 position, LAYER_OBJECTS + 1);
98 //---------------------------------------------------------------------------
100 FloatingText::FloatingText(const Vector& pos, const std::string& text_)
101 : position(pos), text(text_)
104 position.x -= text.size() * 8;
107 FloatingText::FloatingText(const Vector& pos, int score)
112 // turn int into a string
114 snprintf(str, 10, "%d", score);
117 position.x -= text.size() * 8;
121 FloatingText::action(float elapsed_time)
123 position.y -= 1.4 * elapsed_time;
129 #define FADING_TIME .350
132 FloatingText::draw(DrawingContext& context)
134 // make an alpha animation when disapearing
136 if(timer.get_timeleft() < FADING_TIME)
137 alpha = int(timer.get_timeleft() * 255 / FADING_TIME);
141 context.push_transform();
142 context.set_alpha(alpha);
144 context.draw_text(gold_text, text, position, LEFT_ALLIGN, LAYER_OBJECTS+1);
146 context.pop_transform();
149 Sprite *img_smoke_cloud = 0;
151 SmokeCloud::SmokeCloud(const Vector& pos)
158 SmokeCloud::action(float elapsed_time)
160 position.y -= 120 * elapsed_time;
167 SmokeCloud::draw(DrawingContext& context)
169 img_smoke_cloud->draw(context, position, LAYER_OBJECTS+1);
172 Particles::Particles(const Vector& epicenter, int min_angle, int max_angle,
173 const Vector& initial_velocity, const Vector& acceleration, int number,
174 Color color_, int size_, float life_time, int drawing_layer_)
175 : accel(acceleration), color(color_), size(size_), drawing_layer(drawing_layer_)
180 live_forever = false;
181 timer.start(life_time);
185 for(int p = 0; p < number; p++)
187 Particle* particle = new Particle;
188 particle->pos = epicenter;
190 float angle = ((rand() % (max_angle-min_angle))+min_angle)
191 * (M_PI / 180); // convert to radius
192 particle->vel.x = /*fabs*/(sin(angle)) * initial_velocity.x;
193 // if(angle >= M_PI && angle < M_PI*2)
194 // particle->vel.x *= -1; // work around to fix signal
195 particle->vel.y = /*fabs*/(cos(angle)) * initial_velocity.y;
196 // if(angle >= M_PI_2 && angle < 3*M_PI_2)
197 // particle->vel.y *= -1;
199 particles.push_back(particle);
203 Particles::~Particles()
206 for(std::vector<Particle*>::iterator i = particles.begin();
207 i < particles.end(); i++)
212 Particles::action(float elapsed_time)
214 Vector camera = Sector::current()->camera->get_translation();
217 for(std::vector<Particle*>::iterator i = particles.begin();
218 i != particles.end(); ) {
219 (*i)->pos.x += (*i)->vel.x * elapsed_time;
220 (*i)->pos.y += (*i)->vel.y * elapsed_time;
222 (*i)->vel.x += accel.x * elapsed_time;
223 (*i)->vel.y += accel.y * elapsed_time;
225 if((*i)->pos.x < camera.x || (*i)->pos.x > screen->w + camera.x ||
226 (*i)->pos.y < camera.y || (*i)->pos.y > screen->h + camera.y) {
228 i = particles.erase(i);
234 if((timer.check() && !live_forever) || particles.size() == 0)
239 Particles::draw(DrawingContext& context)
242 for(std::vector<Particle*>::iterator i = particles.begin();
243 i != particles.end(); i++) {
244 context.draw_filled_rect((*i)->pos, Vector(size,size), color,drawing_layer);
248 void load_object_gfx()
251 img_trampoline = sprite_manager->load("trampoline");
252 img_trampoline->start_animation(0);
253 img_flying_platform = sprite_manager->load("flying_platform");
255 img_smoke_cloud = sprite_manager->create("stomp");
258 void free_object_gfx()
260 delete img_smoke_cloud;