X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fobject%2Ftilemap.hpp;h=d67049d7805f748a734b4f45f735f86281df4497;hb=5745d9670262c91e6cd35363fd0d2ec169e7c8a4;hp=82196234ab35910662b32c0c67fb1c58f7ca6ad8;hpb=86181b0a14d89cf45daf97199c3556c4dd1ee7b7;p=supertux.git diff --git a/src/object/tilemap.hpp b/src/object/tilemap.hpp index 82196234a..d67049d78 100644 --- a/src/object/tilemap.hpp +++ b/src/object/tilemap.hpp @@ -1,7 +1,7 @@ // $Id$ // -// SuperTux - A Jump'n Run -// Copyright (C) 2004 Matthias Braun // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -16,16 +16,21 @@ // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + #ifndef SUPERTUX_TILEMAP_H #define SUPERTUX_TILEMAP_H #include #include +#include #include "game_object.hpp" #include "serializable.hpp" #include "math/vector.hpp" #include "video/drawing_context.hpp" +#include "object/path.hpp" +#include "object/path_walker.hpp" +#include "script_interface.hpp" namespace lisp { class Lisp; @@ -34,16 +39,18 @@ class Lisp; class Level; class TileManager; class Tile; +class TileSet; /** * This class is reponsible for drawing the level tiles */ -class TileMap : public GameObject, public Serializable +class TileMap : public GameObject, public Serializable, public ScriptInterface { public: - TileMap(); - TileMap(const lisp::Lisp& reader, TileManager* tile_manager = 0); - TileMap(int layer_, bool solid_, size_t width_, size_t height_); + TileMap(const TileSet *tileset); + TileMap(const lisp::Lisp& reader); + TileMap(const TileSet *tileset, std::string name, int z_pos, bool solid_, + size_t width_, size_t height_); virtual ~TileMap(); virtual void write(lisp::Writer& writer); @@ -51,13 +58,25 @@ public: virtual void update(float elapsed_time); virtual void draw(DrawingContext& context); + /** Move tilemap until at given node, then stop */ + void goto_node(int node_no); + + /** Start moving tilemap */ + void start_moving(); + + /** Stop tilemap at next node */ + void stop_moving(); + + virtual void expose(HSQUIRRELVM vm, SQInteger table_idx); + virtual void unexpose(HSQUIRRELVM vm, SQInteger table_idx); + void set(int width, int height, const std::vector& vec, - int layer, bool solid); + int z_pos, bool solid); /** resizes the tilemap to a new width and height (tries to not destroy the * existing map) */ - void resize(int newwidth, int newheight); + void resize(int newwidth, int newheight, int fill_id = 0); size_t get_width() const { return width; } @@ -65,16 +84,42 @@ public: size_t get_height() const { return height; } + float get_x_offset() const + { return x_offset; } + + float get_y_offset() const + { return y_offset; } + + const Vector& get_movement() const + { + return movement; + } + + void set_x_offset(float x_offset) + { this->x_offset = x_offset; } + + void set_y_offset(float y_offset) + { this->y_offset = y_offset; } + int get_layer() const - { return layer; } - + { return z_pos; } + bool is_solid() const { return solid; } + /** + * Changes Tilemap's solidity, i.e. whether to consider it when doing collision detection. + */ + void set_solid(bool solid = true); + /// returns tile in row y and column y (of the tilemap) const Tile* get_tile(int x, int y) const; /// returns tile at position pos (in world coordinates) const Tile* get_tile_at(const Vector& pos) const; + /// returns tile in row y and column y (of the tilemap) + uint32_t get_tile_id(int x, int y) const; + /// returns tile at position pos (in world coordinates) + uint32_t get_tile_id_at(const Vector& pos) const; void change(int x, int y, uint32_t newtile); @@ -83,11 +128,6 @@ public: /// changes all tiles with the given ID void change_all(uint32_t oldtile, uint32_t newtile); - TileManager* get_tilemanager() const - { - return tilemanager; - } - void set_drawing_effect(DrawingEffect effect) { drawing_effect = effect; @@ -98,19 +138,46 @@ public: return drawing_effect; } + /** + * Start fading the tilemap to opacity given by @c alpha. + * Destination opacity will be reached after @c seconds seconds. Also influences solidity. + */ + void fade(float alpha, float seconds = 0); + + /** + * Instantly switch tilemap's opacity to @c alpha. Also influences solidity. + */ + void set_alpha(float alpha); + + /** + * Return tilemap's opacity. Note that while the tilemap is fading in or out, this will return the current alpha value, not the target alpha. + */ + float get_alpha(); + private: + const TileSet *tileset; + typedef std::vector Tiles; Tiles tiles; - -private: - TileManager* tilemanager; + bool solid; - float speed; + float speed_x; + float speed_y; int width, height; - int layer; + int z_pos; + float x_offset; + float y_offset; + Vector movement; /**< The movement that happened last frame */ DrawingEffect drawing_effect; + float alpha; /**< requested tilemap opacity */ + float current_alpha; /**< current tilemap opacity */ + float remaining_fade_time; /**< seconds until requested tilemap opacity is reached */ + + std::auto_ptr path; + std::auto_ptr walker; + + DrawingContext::Target draw_target; /**< set to LIGHTMAP to draw to lightmap */ }; #endif /*SUPERTUX_TILEMAP_H*/ -