)
)
(width 5)
- (height 3)
+ (height 4)
(tiles
+ 0 0 44 0 0
7 8 8 8 9
13 14 14 14 15
16 17 17 17 18
#include "audio/sound_manager.hpp"
#include "object/bouncy_coin.hpp"
#include "object/player.hpp"
+#include "object/tilemap.hpp"
#include "supertux/level.hpp"
#include "supertux/object_factory.hpp"
#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_TOUCHABLE),
+ path(),
+ walker(),
+ offset(),
+ from_tilemap(false)
{
sound_manager->preload("sounds/coin.wav");
}
+Coin::Coin(const Vector& pos, TileMap* tilemap)
+ : MovingSprite(pos, "images/objects/coin/coin.sprite", LAYER_TILES, COLGROUP_TOUCHABLE),
+ path(boost::shared_ptr<Path>(tilemap->get_path())),
+ walker(boost::shared_ptr<PathWalker>(tilemap->get_walker())),
+ offset(),
+ from_tilemap(true)
+{
+ if(walker.get()) {
+ Vector v = path->get_base();
+ offset = pos - v;
+ }
+
+ sound_manager->preload("sounds/coin.wav");
+}
+
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_TOUCHABLE),
+ path(),
+ walker(),
+ offset(),
+ from_tilemap(false)
{
+ const lisp::Lisp* pathLisp = reader.get_lisp("path");
+ if (pathLisp) {
+ path.reset(new Path());
+ path->read(*pathLisp);
+ walker.reset(new PathWalker(path.get()));
+ Vector v = path->get_base();
+ set_pos(v);
+ }
+
sound_manager->preload("sounds/coin.wav");
}
void
+Coin::update(float elapsed_time)
+{
+ // if we have a path to follow, follow it
+ if (walker.get()) {
+ Vector v = from_tilemap ? offset + walker->get_pos() : walker->advance(elapsed_time);
+ movement = v - get_pos();
+ }
+}
+
+void
Coin::collect()
{
// TODO: commented out musical code. Maybe fork this for a special "MusicalCoin" object?
#include "object/moving_sprite.hpp"
+class TileMap;
+
class Coin : public MovingSprite
{
public:
Coin(const Vector& pos);
+ Coin(const Vector& pos, TileMap* tilemap);
Coin(const Reader& reader);
HitResponse collision(GameObject& other, const CollisionHit& hit);
void collect();
+ virtual void update(float elapsed_time);
+
+private:
+ boost::shared_ptr<Path> path;
+ boost::shared_ptr<PathWalker> walker;
+ Vector offset;
+ bool from_tilemap;
};
#endif
}
}
- const Path::Node* next_node = & (path->nodes[next_node_nr]);
node_time += elapsed_time * node_mult;
+ return get_pos();
+}
+
+Vector
+PathWalker::get_pos()
+{
+ const Path::Node* current_node = & (path->nodes[current_node_nr]);
+ const Path::Node* next_node = & (path->nodes[next_node_nr]);
Vector new_pos = current_node->position +
(next_node->position - current_node->position) * node_time;
virtual ~PathWalker();
/**
- * advances the path walker on the path and returns the position delta
- * to the last position
+ * advances the path walker on the path and returns its new position
*/
virtual Vector advance(float elapsed_time);
+ /** current position of path walker */
+ Vector get_pos();
+
/** advance until at given node, then stop */
void goto_node(int node_no);
#ifndef HEADER_SUPERTUX_OBJECT_TILEMAP_HPP
#define HEADER_SUPERTUX_OBJECT_TILEMAP_HPP
+#include <boost/shared_ptr.hpp>
+
#include "object/path_walker.hpp"
#include "supertux/game_object.hpp"
#include "supertux/script_interface.hpp"
}
}
- Path *get_path()
- { return path.get(); }
+ boost::shared_ptr<Path> get_path()
+ { return path; }
+
+ boost::shared_ptr<PathWalker> get_walker()
+ { return walker; }
void set_offset(const Vector &offset)
{ this->offset = offset; }
float current_alpha; /**< current tilemap opacity */
float remaining_fade_time; /**< seconds until requested tilemap opacity is reached */
- std::auto_ptr<Path> path;
- std::auto_ptr<PathWalker> walker;
+ boost::shared_ptr<Path> path;
+ boost::shared_ptr<PathWalker> walker;
DrawingContext::Target draw_target; /**< set to LIGHTMAP to draw to lightmap */
Vector offset = tilemap->get_offset();
offset.y = height - offset.y - tilemap->get_bbox().get_height();
tilemap->set_offset(offset);
- Path *path = tilemap->get_path();
+ Path* path = tilemap->get_path().get();
if (path)
transform_path(height, tilemap->get_bbox().get_height(), *path);
}
add_object(new InvisibleBlock(pos));
solids->change(x, y, 0);
} else if(tile->getAttributes() & Tile::COIN) {
- add_object(new Coin(pos));
+ add_object(new Coin(pos, solids));
solids->change(x, y, 0);
} else if(tile->getAttributes() & Tile::FULLBOX) {
add_object(new BonusBlock(pos, tile->getData()));