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
28 #include "tile_manager.hpp"
29 #include "game_session.hpp"
30 #include "gameobjs.hpp"
31 #include "sprite/sprite_manager.hpp"
32 #include "sprite/sprite.hpp"
33 #include "resources.hpp"
35 #include "tilemap.hpp"
36 #include "video/drawing_context.hpp"
40 BouncyCoin::BouncyCoin(const Vector& pos)
44 sprite = sprite_manager->create("coin");
45 sprite->set_action("still");
48 BouncyCoin::~BouncyCoin()
54 BouncyCoin::update(float elapsed_time)
56 position.y += -200 * elapsed_time;
63 BouncyCoin::draw(DrawingContext& context)
65 sprite->draw(context, position, LAYER_OBJECTS);
68 //---------------------------------------------------------------------------
70 BrokenBrick::BrokenBrick(Sprite* nsprite,
71 const Vector& pos, const Vector& nmovement)
72 : sprite(new Sprite(*nsprite)), position(pos), movement(nmovement)
77 BrokenBrick::~BrokenBrick()
83 BrokenBrick::update(float elapsed_time)
85 position += movement * elapsed_time;
92 BrokenBrick::draw(DrawingContext& context)
94 sprite->draw_part(context,
95 Vector(rand() % 16, rand() % 16), Vector(16, 16),
96 position, LAYER_OBJECTS + 1);
99 //---------------------------------------------------------------------------
101 FloatingText::FloatingText(const Vector& pos, const std::string& text_)
102 : position(pos), text(text_)
105 position.x -= text.size() * 8;
108 FloatingText::FloatingText(const Vector& pos, int score)
113 // turn int into a string
115 snprintf(str, 10, "%d", score);
118 position.x -= text.size() * 8;
122 FloatingText::update(float elapsed_time)
124 position.y -= 1.4 * elapsed_time;
130 #define FADING_TIME .350
133 FloatingText::draw(DrawingContext& context)
135 // make an alpha animation when disapearing
137 if(timer.get_timeleft() < FADING_TIME)
138 alpha = int(timer.get_timeleft() * 255 / FADING_TIME);
142 context.push_transform();
143 context.set_alpha(alpha);
145 context.draw_text(gold_text, text, position, LEFT_ALLIGN, LAYER_OBJECTS+1);
147 context.pop_transform();
150 Sprite *img_smoke_cloud = 0;
152 SmokeCloud::SmokeCloud(const Vector& pos)
159 SmokeCloud::update(float elapsed_time)
161 position.y -= 120 * elapsed_time;
168 SmokeCloud::draw(DrawingContext& context)
170 img_smoke_cloud->draw(context, position, LAYER_OBJECTS+1);
173 Particles::Particles(const Vector& epicenter, int min_angle, int max_angle,
174 const Vector& initial_velocity, const Vector& acceleration, int number,
175 Color color_, int size_, float life_time, int drawing_layer_)
176 : accel(acceleration), color(color_), size(size_), drawing_layer(drawing_layer_)
181 live_forever = false;
182 timer.start(life_time);
186 for(int p = 0; p < number; p++)
188 Particle* particle = new Particle;
189 particle->pos = epicenter;
191 float angle = ((rand() % (max_angle-min_angle))+min_angle)
192 * (M_PI / 180); // convert to radius
193 particle->vel.x = /*fabs*/(sin(angle)) * initial_velocity.x;
194 // if(angle >= M_PI && angle < M_PI*2)
195 // particle->vel.x *= -1; // work around to fix signal
196 particle->vel.y = /*fabs*/(cos(angle)) * initial_velocity.y;
197 // if(angle >= M_PI_2 && angle < 3*M_PI_2)
198 // particle->vel.y *= -1;
200 particles.push_back(particle);
204 Particles::~Particles()
207 for(std::vector<Particle*>::iterator i = particles.begin();
208 i < particles.end(); i++)
213 Particles::update(float elapsed_time)
215 Vector camera = Sector::current()->camera->get_translation();
218 for(std::vector<Particle*>::iterator i = particles.begin();
219 i != particles.end(); ) {
220 (*i)->pos.x += (*i)->vel.x * elapsed_time;
221 (*i)->pos.y += (*i)->vel.y * elapsed_time;
223 (*i)->vel.x += accel.x * elapsed_time;
224 (*i)->vel.y += accel.y * elapsed_time;
226 if((*i)->pos.x < camera.x || (*i)->pos.x > SCREEN_WIDTH + camera.x ||
227 (*i)->pos.y < camera.y || (*i)->pos.y > SCREEN_HEIGHT + camera.y) {
229 i = particles.erase(i);
235 if((timer.check() && !live_forever) || particles.size() == 0)
240 Particles::draw(DrawingContext& context)
243 for(std::vector<Particle*>::iterator i = particles.begin();
244 i != particles.end(); i++) {
245 context.draw_filled_rect((*i)->pos, Vector(size,size), color,drawing_layer);
249 void load_object_gfx()
251 img_smoke_cloud = sprite_manager->create("stomp");
254 void free_object_gfx()
256 delete img_smoke_cloud;