4 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include "tile_manager.hpp"
28 #include "game_session.hpp"
29 #include "gameobjs.hpp"
30 #include "sprite/sprite_manager.hpp"
31 #include "sprite/sprite.hpp"
32 #include "resources.hpp"
34 #include "tilemap.hpp"
35 #include "video/drawing_context.hpp"
38 #include "random_generator.hpp"
40 /** this controls the time over which a bouncy coin fades */
41 static const float FADE_TIME = .2f;
42 /** this is the total life time of a bouncy coin */
43 static const float LIFE_TIME = .5f;
45 BouncyCoin::BouncyCoin(const Vector& pos, bool emerge)
46 : position(pos), emerge_distance(0)
48 timer.start(LIFE_TIME);
49 sprite = sprite_manager->create("images/objects/coin/coin.sprite");
52 emerge_distance = sprite->get_height();
56 BouncyCoin::~BouncyCoin()
62 BouncyCoin::update(float elapsed_time)
64 float dist = -200 * elapsed_time;
66 emerge_distance += dist;
73 BouncyCoin::draw(DrawingContext& context)
75 float time_left = timer.get_timeleft();
76 bool fading = time_left < FADE_TIME;
78 float alpha = time_left/FADE_TIME;
79 context.push_transform();
80 context.set_alpha(alpha);
84 if(emerge_distance > 0) {
85 layer = LAYER_OBJECTS - 5;
87 layer = LAYER_OBJECTS + 5;
89 sprite->draw(context, position, layer);
92 context.pop_transform();
96 //---------------------------------------------------------------------------
98 BrokenBrick::BrokenBrick(Sprite* nsprite,
99 const Vector& pos, const Vector& nmovement)
100 : sprite(new Sprite(*nsprite)), position(pos), movement(nmovement)
105 BrokenBrick::~BrokenBrick()
111 BrokenBrick::update(float elapsed_time)
113 position += movement * elapsed_time;
120 BrokenBrick::draw(DrawingContext& context)
122 sprite->draw_part(context,
123 Vector(systemRandom.rand(16), systemRandom.rand(16)), Vector(16, 16),
124 position, LAYER_OBJECTS + 1);
127 //---------------------------------------------------------------------------
129 FloatingText::FloatingText(const Vector& pos, const std::string& text_)
130 : position(pos), text(text_)
133 position.x -= text.size() * 8;
136 FloatingText::FloatingText(const Vector& pos, int score)
141 // turn int into a string
143 snprintf(str, 10, "%d", score);
146 position.x -= text.size() * 8;
150 FloatingText::update(float elapsed_time)
152 position.y -= 1.4 * elapsed_time;
158 #define FADING_TIME .350
161 FloatingText::draw(DrawingContext& context)
163 // make an alpha animation when disappearing
165 if(timer.get_timeleft() < FADING_TIME)
166 alpha = int(timer.get_timeleft() * 255 / FADING_TIME);
170 context.push_transform();
171 context.set_alpha(alpha);
173 context.draw_text(gold_text, text, position, ALIGN_LEFT, LAYER_OBJECTS+1);
175 context.pop_transform();
178 Sprite *img_smoke_cloud = 0;
180 SmokeCloud::SmokeCloud(const Vector& pos)
184 sprite = sprite_manager->create("images/objects/particles/stomp.sprite");
187 SmokeCloud::~SmokeCloud()
193 SmokeCloud::update(float elapsed_time)
195 position.y -= 120 * elapsed_time;
202 SmokeCloud::draw(DrawingContext& context)
204 sprite->draw(context, position, LAYER_OBJECTS+1);