NLS Engine  v0.1
The Next Logical Step in game engine design.
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Defines
TiledMap.h
Go to the documentation of this file.
00001 
00012 #pragma once
00013 
00014 // Standard Includes
00015 
00016 // Library Includes
00017 #include <d3d9.h>
00018 #include <d3dx9.h>
00019 #include <boost/unordered_map.hpp>
00020 #include <vector>
00021 
00022 // Local Includes
00023 #include "../RenderableComponent.h"
00024 #include "../../../sharedbase/Envelope.h"
00025 
00026 // Forward Declarations
00027 
00028 // Typedefs
00029 
00030 // Constants
00031 namespace GraphicsCore {
00032   static const unsigned int TILE_WIDTH = 32; // Width of the tile, in pixels
00033   static const unsigned int TILE_HEIGHT = 32; // Height of the tile, in pixels
00034 }
00035 
00036 // Classes
00037 namespace GraphicsCore {
00038   struct Tile {
00039     float x, y; // location
00040     LPDIRECT3DTEXTURE9 texture; // Source texture.
00041     RECT srcRect; // Source location in the texture.
00042   };
00043 
00044   struct TileSet {
00045     std::string name;
00046     unsigned int across;
00047     unsigned int down;
00048     unsigned int firstid;
00049     unsigned int lastid;
00050   };
00051 
00052   class TiledMap : public RenderableComponent {
00053   public:
00054     TiledMap(EntitySPTR, ModuleInterface*, LPDIRECT3DDEVICE9);
00055     virtual ~TiledMap(void);
00056 
00057     void AddTile(float x, float y, std::string texName, int srcX, int srcY);
00058     bool LoadMapData(EnvelopeSPTR data);
00059   private:
00060     void Render(LPDIRECT3DDEVICE9);
00061     LPD3DXSPRITE sprite;
00062     boost::unordered_map<std::string, LPDIRECT3DTEXTURE9> textures; // Map of the various loaded textures.
00063     std::vector<Tile> tiles; // Vector of all tiles to be draw
00064   };
00065 }