TapestryEngine

A 2D Platformer Game Engine
Log | Files | Refs

Mapper.h (1975B)


      1 #ifndef MAPPER_H
      2 #define MAPPER_H
      3 
      4 #include "Utils.h"
      5 #include "Console.h"
      6 
      7 #define MAX_FEATURES 100
      8 #define MAX_ATTEMPTS 10
      9 
     10 //#if SDL_BYTEORDER == SDL_BIG_ENDIAN
     11 //Uint32 rmask = 0xff000000;
     12 //Uint32 gmask = 0x00ff0000;
     13 //Uint32 bmask = 0x0000ff00;
     14 //Uint32 amask = 0x000000ff;
     15 //#else
     16 //Uint32 rmask = 0x000000ff;
     17 //Uint32 gmask = 0x0000ff00;
     18 //Uint32 bmask = 0x00ff0000;
     19 //Uint32 amask = 0xff000000;
     20 //#endif
     21 
     22 enum FeatureType
     23 {
     24 	ROOM_TEST,
     25 	HALL_TEST
     26 };
     27 
     28 class Feature
     29 {
     30 public:
     31 
     32 	Feature() {};
     33 
     34 	Feature(int h_max, int h_min, int w_max, int w_min)
     35 	{
     36 		GenerateRoom(h_max, h_min, w_max, w_min);
     37 	}
     38 
     39 	SDL_Rect* GetPosition()
     40 	{
     41 		return mPositon;
     42 	}
     43 
     44 	bool GetRotate()
     45 	{
     46 		return mRotated;
     47 	}
     48 
     49 	void SetXY(int x, int y)
     50 	{
     51 		mPositon->x = x;
     52 		mPositon->y = y;
     53 	}
     54 
     55 	void SetRotate(bool rot)
     56 	{
     57 		mRotated = rot;
     58 	}
     59 
     60 	SDL_Rect* GenerateRoom(int h_max, int h_min, int w_max, int w_min);
     61 
     62 	int* GetConnectableFeatures()
     63 	{
     64 		return mConnectableFeatures;
     65 	}
     66 
     67 
     68 protected:
     69 
     70 	SDL_Rect* mPositon;
     71 	bool mRotated;
     72 
     73 	int mConnectableFeatures[2];
     74 };
     75 
     76 class Room_test : public Feature
     77 {
     78 public:
     79 
     80 	Room_test() : Feature(100, 30, 200, 60)
     81 	{
     82 		mConnectableFeatures[ROOM_TEST] = 0;
     83 		mConnectableFeatures[HALL_TEST] = 100;
     84 	}
     85 
     86 protected:
     87 
     88 
     89 };
     90 
     91 class Hall_test : public Feature
     92 {
     93 public:
     94 
     95 	Hall_test() : Feature(10, 10, 100, 10)
     96 	{
     97 		mConnectableFeatures[ROOM_TEST] = 0;
     98 		mConnectableFeatures[HALL_TEST] = 100;
     99 	}
    100 
    101 protected:
    102 
    103 };
    104 
    105 class Mapper
    106 {
    107 public:
    108 
    109 	Mapper() : mFeatureIndex(0) {}
    110 
    111 	SDL_Surface* GetMap()
    112 	{
    113 		return mMap;
    114 	}
    115 
    116 	bool FillRegion(int ttype, SDL_Rect* bounds = NULL);
    117 
    118 	void BuildFeature(Feature* fea);
    119 
    120 	bool AttachFeature(Feature* stem, Feature* bud);
    121 
    122 	bool FitFeature(Feature* stem, Feature* bud, int attempts = 0);
    123 
    124 	Feature* SelectFeature(FeatureType ft);
    125 
    126 	void AddFeature();
    127 
    128 	SDL_Surface* NewMap(int h, int w);
    129 
    130 	SDL_Surface* GenerateMap(int h, int w);
    131 protected:
    132 
    133 	SDL_Surface* mMap;
    134 	Feature* mFeature_Array[MAX_FEATURES];
    135 	int mFeatureIndex;
    136 };
    137 
    138 #endif