Changed egg shadow draw layer so it will no longer appear in front of bonusblocks...
[supertux.git] / src / supertux / tile.hpp
index 3e13d9b..d0dd424 100644 (file)
@@ -1,6 +1,7 @@
 //  SuperTux
 //  Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
+//  Copyright (C) 2010 Florian Forster <supertux at octo.it>
 //
 //  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
 #ifndef HEADER_SUPERTUX_SUPERTUX_TILE_HPP
 #define HEADER_SUPERTUX_SUPERTUX_TILE_HPP
 
-#include <stdint.h>
 #include <vector>
+#include <stdint.h>
 
-#include "math/rect.hpp"
+#include "math/rectf.hpp"
 #include "video/surface.hpp"
 #include "util/reader_fwd.hpp"
 
-class TileSet;
 class DrawingContext;
 
-/**
-   Tile Class
-*/
 class Tile
 {
 public:
+  static bool draw_editor_images;
   /// bitset for tile attributes
   enum {
     /** solid tile that is indestructible by Tux */
@@ -86,18 +84,28 @@ public:
   };
 
   struct ImageSpec {
-    ImageSpec(const std::string& newfile, const Rect& newrect)
+    ImageSpec(const std::string& newfile, const Rectf& newrect)
       : file(newfile), rect(newrect)
     { }
 
     std::string file;
-    Rect rect;
+    Rectf rect;
+  };
+
+  enum
+  {
+    UNI_DIR_NORTH = 0,
+    UNI_DIR_SOUTH = 1,
+    UNI_DIR_WEST  = 2,
+    UNI_DIR_EAST  = 3,
+    UNI_DIR_MASK  = 3
   };
 
 private:
-  const TileSet         *tileset;
   std::vector<ImageSpec> imagespecs;
-  std::vector<Surface*>  images;
+  std::vector<SurfacePtr>  images;
+  std::vector<ImageSpec> editor_imagespecs;
+  std::vector<SurfacePtr>  editor_images;
 
   /// tile attributes
   uint32_t attributes;
@@ -105,11 +113,17 @@ private:
   /** General purpose data attached to a tile (content of a box, type of coin)*/
   int data;
 
-  float anim_fps;
+  float fps;
 
 public:
+  Tile();
+  Tile(const std::vector<ImageSpec>& images, const std::vector<ImageSpec>& editor_images,
+       uint32_t attributes, uint32_t data, float fps);
   ~Tile();
 
+  /** load Surfaces, if not already loaded */
+  void load_images();
+
   /** Draw a tile on the screen */
   void draw(DrawingContext& context, const Vector& pos, int z_pos) const;
 
@@ -119,38 +133,50 @@ public:
   int getData() const
   { return data; }
 
-  /// returns the width of the tile in pixels
-  int getWidth() const
+  /** Checks the SLOPE attribute. Returns "true" if set, "false" otherwise. */
+  bool is_slope() const
   {
-    if(!images.size())
-      return 0;
-    return (int) images[0]->get_width();
+    return attributes & SLOPE;
   }
 
-  /// returns the height of the tiles in pixels
-  int getHeight() const
+  /** Determine the solidity of a tile. This version behaves correctly for
+   * unisolid tiles by taking position and movement of the object in question
+   * into account. Because creating the arguments for this function can be
+   * expensive, you should handle trivial cases using the "is_solid()" and
+   * "is_unisolid()" methods first. */
+  bool is_solid (const Rectf& tile_bbox, const Rectf& position, const Vector& movement) const;
+
+  /** This version only checks the SOLID flag to determine the solidity of a
+   * tile. This means it will always return "true" for unisolid tiles. To
+   * determine the *current* solidity of unisolid tiles, use the "is_solid"
+   * method that takes position and movement into account (see above). */
+  bool is_solid() const
   {
-    if(!images.size())
-      return 0;
-    return (int) images[0]->get_height();
+    return attributes & SOLID;
   }
 
-protected:
-  friend class TileSet;
-  Tile(const TileSet *tileset);
-  Tile(const TileSet *tileset, std::vector<std::string> images, Rect rect,
-       uint32_t attributes = 0, uint32_t data = 0, float animfps = 1.0);
-
-  void load_images();
+  /** Checks the UNISOLID attribute. Returns "true" if set, "false" otherwise. */
+  bool is_unisolid() const
+  {
+    return attributes & UNISOLID;
+  }
 
-  /// parses the tile and returns it's id number
-  uint32_t parse(const Reader& reader);
-  void parse_images(const Reader& cur);
+  void print_debug(int id) const;
 
+private:
   //Correct small oddities in attributes that naive people
   //might miss (and rebuke them for it)
   void correct_attributes();
 
+  /** Returns zero if a unisolid tile is non-solid due to the movement
+   * direction, non-zero if the tile is solid due to direction. */
+  bool check_movement_unisolid (const Vector& movement) const;
+
+  /** Returns zero if a unisolid tile is non-solid due to the position of the
+   * tile and the object, non-zero if the tile is solid. */
+  bool check_position_unisolid (const Rectf& obj_bbox,
+                                const Rectf& tile_bbox) const;
+
 private:
   Tile(const Tile&);
   Tile& operator=(const Tile&);