2 // Copyright (C) 2013 LMH <lmh.0013@gmail.com>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "object/coin_rain.hpp"
19 #include "math/random_generator.hpp"
20 #include "object/coin.hpp"
21 #include "sprite/sprite.hpp"
22 #include "sprite/sprite_manager.hpp"
23 #include "supertux/sector.hpp"
25 static const float DROP_TIME = .1f; // time duration between "drops" of coin rain
27 CoinRain::CoinRain(const Vector& pos, bool emerge) :
35 sprite = sprite_manager->create("images/objects/coin/coin.sprite");
38 emerge_distance = sprite->get_height();
43 CoinRain::update(float elapsed_time)
45 // first a single (untouchable) coin flies up above the sector
47 float dist = -500 * elapsed_time;
49 emerge_distance += dist;
50 } // then the first collectable coin drops from one of ten random positions
52 drop = gameRandom.rand(10);
53 Sector::current()->add_object(new HeavyCoin(Vector (position.x+32*((drop<5)?-drop-1:drop-4),-32), Vector (0,0)));
55 timer.start(DROP_TIME);
56 } // finally the remainder of the coins drop in a determined but appears to be a random order
57 else if(timer.check()){
60 if(drop >= 10) drop -=10;
61 Sector::current()->add_object(new HeavyCoin(Vector (position.x+32*((drop<5)?-drop-1:drop-4),-32), Vector (0,0)));
63 timer.start(DROP_TIME);
71 CoinRain::draw(DrawingContext& context)
74 if(emerge_distance > 0) {
75 layer = LAYER_OBJECTS - 5;
77 layer = LAYER_OBJECTS + 5;
79 sprite->draw(context, position, layer);