Przeglądaj źródła

The layer name is no longer ignored.

legacy
Sam Hocevar sam 14 lat temu
rodzic
commit
a3d5f1576b
7 zmienionych plików z 61 dodań i 15 usunięć
  1. +19
    -1
      src/layer.cpp
  2. +11
    -6
      src/layer.h
  3. +6
    -2
      src/map.cpp
  4. +9
    -0
      src/map.h
  5. +3
    -2
      src/test-map.cpp
  6. +3
    -4
      src/tiler.h
  7. +10
    -0
      src/video.h

+ 19
- 1
src/layer.cpp Wyświetl plik

@@ -1,12 +1,25 @@

#include "layer.h"

Layer::Layer(int w, int h, FILE *fp)
Layer::Layer(char const *name, int w, int h, FILE *fp)
{
width = w;
height = h;
data = new unsigned int[w * h];

if (sscanf(name, "Ground %d", &z) == 1)
;
else if (sscanf(name, "Ground Decal %d", &z) == 1)
;
else if (sscanf(name, "Object %d", &z) == 1)
;
else if (sscanf(name, "Wall %d", &z) == 1)
z++;
else if (sscanf(name, "Wall Decal %d", &z) == 1)
z++;
else
z = -1;

fread(data, sizeof(unsigned int), width * height, fp);
for (int n = 0; n < width * height; n++)
{
@@ -21,6 +34,11 @@ Layer::~Layer()
delete data;
}

int Layer::GetZ()
{
return z;
}

unsigned int Layer::GetTile(int x, int y)
{
return data[y * width + x];


+ 11
- 6
src/layer.h Wyświetl plik

@@ -1,21 +1,26 @@

#if !defined __LAYER_H__
#define __LAYER_H__
/*
* The layer object
*/

#if !defined __DH_LAYER_H__
#define __DH_LAYER_H__

#include <cstdio>

class Layer
{
public:
Layer(int w, int h, FILE *fp);
Layer(char const *name, int w, int h, FILE *fp);
~Layer();

int GetZ();
unsigned int GetTile(int x, int y);

//private:
int width, height;
private:
int width, height, z;
unsigned int *data;
};

#endif // __LAYER_H__
#endif // __DH_LAYER_H__


+ 6
- 2
src/map.cpp Wyświetl plik

@@ -27,7 +27,7 @@ Map::Map(char const *path) :
fscanf(fp, "height=\"%u\" ", &height);
fgets(tmp, 1024, fp); // Ignore rest of line
layers = (Layer **)realloc(layers, sizeof(Layer **) * (nlayers + 1));
layers[nlayers] = new Layer(width, height, fp);
layers[nlayers] = new Layer(name, width, height, fp);
nlayers++;
}

@@ -44,8 +44,12 @@ Map::~Map()
void Map::Draw(Tiler *tiler)
{
for (int i = 0; i < nlayers; i++)
{
int z = layers[i]->GetZ();

for (int y = 0; y < 32; y++)
for (int x = 0; x < 32; x++)
tiler->AddTile(layers[i]->GetTile(x, y), x * 32, y * 32, i);
tiler->AddTile(layers[i]->GetTile(x, y), x * 32, y * 32, z);
}
}


+ 9
- 0
src/map.h Wyświetl plik

@@ -1,4 +1,11 @@

/*
* The map object
*/

#if !defined __DH_MAP_H__
#define __DH_MAP_H__

#include <cstdio>

#include "layer.h"
@@ -17,3 +24,5 @@ private:
int nlayers;
};

#endif // __DH_MAP_H__


+ 3
- 2
src/test-map.cpp Wyświetl plik

@@ -13,7 +13,7 @@ int main(int argc, char **argv)
{
Video *video = new Video("Deus Hax", 640, 480);
Tiler *tiler = new Tiler();
Map *map = new Map("maps/testmap-coll.tmx");
Map *map = new Map("maps/testmap-grass.tmx");

for (int done = 0; !done; )
{
@@ -24,9 +24,10 @@ int main(int argc, char **argv)
/* Test stuff */
int playerx, playery;
SDL_GetMouseState(&playerx, &playery);
playerx = playerx * (640 - 32) / 640;
playery = playery * (480 - 32) / 480;

tiler->AddTile(50, playerx, playery, 1);
tiler->AddTile(50, playerx + 64, playery + 32, 3);

tiler->Render();
video->Refresh(33.33333f);


+ 3
- 4
src/tiler.h Wyświetl plik

@@ -1,11 +1,10 @@


/*
* The tile manager
*/

#if !defined __TILER_H__
#define __TILER_H__
#if !defined __DH_TILER_H__
#define __DH_TILER_H__

class TilerData;

@@ -23,5 +22,5 @@ private:
TilerData *data;
};

#endif // __TILER_H__
#endif // __DH_TILER_H__


+ 10
- 0
src/video.h Wyświetl plik

@@ -1,4 +1,11 @@

/*
* The video driver
*/

#if !defined __DH_VIDEO_H__
#define __DH_VIDEO_H__

class VideoData;

class Video
@@ -16,3 +23,6 @@ public:
private:
VideoData *data;
};

#endif // __DH_VIDEO_H__


Ładowanie…
Anuluj
Zapisz