;; src/tile.cpp, unisolid is 3 not 2
(supertux-tiles
(tile
+ (id 2947)
+ (images
+ "objects/bonus_block/full-0.png"
+ "objects/bonus_block/full-1.png"
+ "objects/bonus_block/full-2.png"
+ "objects/bonus_block/full-3.png"
+ "objects/bonus_block/full-4.png"
+ "objects/bonus_block/full-3.png"
+ "objects/bonus_block/full-2.png"
+ "objects/bonus_block/full-1.png"
+ "objects/bonus_block/full-0.png"
+ "objects/bonus_block/full-0.png"
+ "objects/bonus_block/full-0.png"
+ )
+ (solid #t)
+ (fullbox #t)
+ (next-tile 84)
+ (editor-images "objects/bonus_block/bonus-rain.png")
+ (data 10)
+ (fps 15)
+ )
+
+ (tile
(id 2946)
(images
"objects/bonus_block/full-0.png"
)
(tilegroup
(name "Block")
- (tiles 27 28 29 47 48 50 49 211 77 51 52 212 78 62 61 213 44 83 84 102 140 103 104 105 112 128 2943 2944 2945 2946 1311 2153)
+ (tiles 27 28 29 47 48 50 49 211 77 51 52 212 78 62 61 213 44 83 2947 84 102 140 103 104 105 112 128 2943 2944 2945 2946 1311 2153)
)
(tilegroup
(name "Background")
(image "tiles/snow/slope-upper.png" )
)
-;; next-id: 2947
+;; next-id: 2948
)
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ; 384
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ; 416
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ; 448
-0 0 0 0 2946 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ; 480
+0 0 0 0 2946 0 0 0 2947 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ; 480
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ; 512
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ; 544
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ; 576
11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 ; 864
11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 ; 896
11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 ; 928
- ))
-
- (bonusblock
- (x 256 )
- (y 640 )
- (contents "coin" )
- (count 3 )
- )
-
+ ))
+
+ (bonusblock
+ (x 256 )
+ (y 640 )
+ (contents "coin" )
+ (count 3 )
+ )
+
(bonusblock
(x 384 )
(y 640 )
#include "object/broken_brick.hpp"
#include "object/flower.hpp"
#include "object/bouncy_coin.hpp"
+#include "object/coin_rain.hpp"
#include "object/growup.hpp"
#include "object/oneup.hpp"
#include "object/player.hpp"
case 7: contents = CONTENT_TRAMPOLINE; break;
case 8: contents = CONTENT_PORTTRAMPOLINE; break;
case 9: contents = CONTENT_ROCK; break;
+ case 10: contents = CONTENT_RAIN; break;
default:
log_warning << "Invalid box contents" << std::endl;
contents = CONTENT_COIN;
contents = CONTENT_PORTTRAMPOLINE;
} else if(contentstring == "rock") {
contents = CONTENT_ROCK;
+ } else if(contentstring == "rain") {
+ contents = CONTENT_RAIN;
} else {
log_warning << "Invalid box contents '" << contentstring << "'" << std::endl;
}
sound_manager->play("sounds/upgrade.wav");
break;
}
+
+ case CONTENT_RAIN:
+ {
+ hit_counter = 1; // multiple hits of coin rain is not allowed
+ Sector::current()->add_object(new CoinRain(get_pos(), true));
+ sound_manager->play("sounds/upgrade.wav");
+ }
}
if(script != "") { // scripts always run if defined
CONTENT_LIGHT,
CONTENT_TRAMPOLINE,
CONTENT_PORTTRAMPOLINE,
- CONTENT_ROCK
+ CONTENT_ROCK,
+ CONTENT_RAIN
};
protected:
#include "supertux/sector.hpp"
Coin::Coin(const Vector& pos)
- : MovingSprite(pos, "images/objects/coin/coin.sprite", LAYER_TILES, COLGROUP_TOUCHABLE),
+ : MovingSprite(pos, "images/objects/coin/coin.sprite", LAYER_TILES, COLGROUP_MOVING),
path(),
walker(),
offset(),
- from_tilemap(false)
+ from_tilemap(false),
+ physic()
{
sound_manager->preload("sounds/coin.wav");
}
path(boost::shared_ptr<Path>(tilemap->get_path())),
walker(boost::shared_ptr<PathWalker>(tilemap->get_walker())),
offset(),
- from_tilemap(true)
+ from_tilemap(true),
+ physic()
{
if(walker.get()) {
Vector v = path->get_base();
}
Coin::Coin(const Reader& reader)
- : MovingSprite(reader, "images/objects/coin/coin.sprite", LAYER_TILES, COLGROUP_TOUCHABLE),
+ : MovingSprite(reader, "images/objects/coin/coin.sprite", LAYER_TILES, COLGROUP_MOVING),
path(),
walker(),
offset(),
- from_tilemap(false)
+ from_tilemap(false),
+ physic()
{
const lisp::Lisp* pathLisp = reader.get_lisp("path");
if (pathLisp) {
return ABORT_MOVE;
}
+/* The following defines a coin subject to gravity */
+HeavyCoin::HeavyCoin(const Vector& pos)
+ : Coin(pos),
+ physic()
+{
+ physic.enable_gravity(true);
+ sound_manager->preload("sounds/coin.wav");
+}
+
+HeavyCoin::HeavyCoin(const Vector& pos, const Vector& init_velocity)
+ : Coin(pos),
+ physic()
+{
+ physic.enable_gravity(true);
+ sound_manager->preload("sounds/coin.wav");
+ physic.set_velocity(init_velocity);
+}
+
+HeavyCoin::HeavyCoin(const Reader& reader)
+ : Coin(reader),
+ physic()
+{
+ physic.enable_gravity(true);
+ sound_manager->preload("sounds/coin.wav");
+}
+
+void
+HeavyCoin::update(float elapsed_time)
+{
+ // enable physics
+ movement = physic.get_movement(elapsed_time);
+}
+
+void
+HeavyCoin::collision_solid(const CollisionHit& hit)
+{
+ if(hit.bottom) {
+ physic.set_velocity_y(0);
+ }
+ if(hit.right || hit.left) {
+ physic.set_velocity_x(-physic.get_velocity_x());
+ }
+}
+
/* EOF */
#define HEADER_SUPERTUX_OBJECT_COIN_HPP
#include "object/moving_sprite.hpp"
+#include "supertux/physic.hpp"
class Path;
class PathWalker;
boost::shared_ptr<PathWalker> walker;
Vector offset;
bool from_tilemap;
+ Physic physic;
+};
+
+class HeavyCoin : public Coin
+{
+public:
+ HeavyCoin(const Vector& pos);
+ HeavyCoin(const Vector& pos, const Vector& init_velocity);
+ HeavyCoin(const Reader& reader);
+
+ virtual void update(float elapsed_time);
+ virtual void collision_solid(const CollisionHit& hit);
+
+private:
+ Physic physic;
};
#endif
--- /dev/null
+// SuperTux
+// Copyright (C) 2013 LMH <lmh.0013@gmail.com>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include "object/coin_rain.hpp"
+
+#include "math/random_generator.hpp"
+#include "object/coin.hpp"
+#include "sprite/sprite.hpp"
+#include "sprite/sprite_manager.hpp"
+#include "supertux/sector.hpp"
+
+static const float DROP_TIME = .1f; // time duration between "drops" of coin rain
+
+CoinRain::CoinRain(const Vector& pos, bool emerge) :
+ sprite(),
+ position(pos),
+ emerge_distance(0),
+ timer(),
+ counter(0),
+ drop(0)
+{
+ sprite = sprite_manager->create("images/objects/coin/coin.sprite");
+
+ if(emerge) {
+ emerge_distance = sprite->get_height();
+ }
+}
+
+void
+CoinRain::update(float elapsed_time)
+{
+ // first a single (untouchable) coin flies up above the sector
+ if(position.y > -32){
+ float dist = -500 * elapsed_time;
+ position.y += dist;
+ emerge_distance += dist;
+ } // then the first collectable coin drops from one of ten random positions
+ else if (counter==0){
+ drop = gameRandom.rand(10);
+ Sector::current()->add_object(new HeavyCoin(Vector (position.x+32*((drop<5)?-drop-1:drop-4),-32)));
+ counter++;
+ timer.start(DROP_TIME);
+ } // finally the remainder of the coins drop in a determined but appears to be a random order
+ else if(timer.check()){
+ if(counter<10){
+ drop += 7;
+ if(drop >= 10) drop -=10;
+ Sector::current()->add_object(new HeavyCoin(Vector (position.x+32*((drop<5)?-drop-1:drop-4),-32)));
+ counter++;
+ timer.start(DROP_TIME);
+ }else{
+ remove_me();
+ }
+ }
+}
+
+void
+CoinRain::draw(DrawingContext& context)
+{
+ int layer;
+ if(emerge_distance > 0) {
+ layer = LAYER_OBJECTS - 5;
+ } else {
+ layer = LAYER_OBJECTS + 5;
+ }
+ sprite->draw(context, position, layer);
+}
+
+/* EOF */
--- /dev/null
+// SuperTux
+// Copyright (C) 2013 LMH <lmh.0013@gmail.com>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef HEADER_SUPERTUX_OBJECT_COIN_RAIN_HPP
+#define HEADER_SUPERTUX_OBJECT_COIN_RAIN_HPP
+
+#include <memory>
+
+#include "math/vector.hpp"
+#include "sprite/sprite_ptr.hpp"
+#include "supertux/game_object.hpp"
+#include "supertux/timer.hpp"
+#include "video/color.hpp"
+
+class Sprite;
+
+class CoinRain : public GameObject
+{
+public:
+ CoinRain(const Vector& pos, bool emerge=false);
+ virtual void update(float elapsed_time);
+ virtual void draw(DrawingContext& context);
+
+private:
+ SpritePtr sprite;
+ Vector position;
+ float emerge_distance;
+ Timer timer;
+ int counter;
+ int drop;
+};
+
+#endif
+
+/* EOF */
{
total_coins += block->hit_counter;
continue;
+ } else if (block->contents == BonusBlock::CONTENT_RAIN) {
+ total_coins += 10;
+ continue;
}
#if 0
// FIXME: do we want this? q.v. src/object/oneup.cpp
#include "object/candle.hpp"
#include "object/cloud_particle_system.hpp"
#include "object/coin.hpp"
+#include "object/coin_rain.hpp"
#include "object/comet_particle_system.hpp"
#include "object/decal.hpp"
#include "object/display_effect.hpp"
add_factory<Explosion>("explosion");
add_factory<Firefly>("firefly");
add_factory<Gradient>("gradient");
+ add_factory<HeavyCoin>("heavycoin");
add_factory<HurtingPlatform>("hurting_platform");
add_factory<IceCrusher>("icecrusher");
add_factory<InfoBlock>("infoblock");