Changeset 47 for trunk/src


Ignore:
Timestamp:
Jul 4, 2010, 2:07:55 AM (11 years ago)
Author:
sam
Message:

The layer name is no longer ignored.

Location:
trunk/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/layer.cpp

    r38 r47  
    22#include "layer.h"
    33
    4 Layer::Layer(int w, int h, FILE *fp)
     4Layer::Layer(char const *name, int w, int h, FILE *fp)
    55{
    66    width = w;
    77    height = h;
    88    data = new unsigned int[w * h];
     9
     10    if (sscanf(name, "Ground %d", &z) == 1)
     11        ;
     12    else if (sscanf(name, "Ground Decal %d", &z) == 1)
     13        ;
     14    else if (sscanf(name, "Object %d", &z) == 1)
     15        ;
     16    else if (sscanf(name, "Wall %d", &z) == 1)
     17        z++;
     18    else if (sscanf(name, "Wall Decal %d", &z) == 1)
     19        z++;
     20    else
     21        z = -1;
    922
    1023    fread(data, sizeof(unsigned int), width * height, fp);
     
    2235}
    2336
     37int Layer::GetZ()
     38{
     39    return z;
     40}
     41
    2442unsigned int Layer::GetTile(int x, int y)
    2543{
  • trunk/src/layer.h

    r38 r47  
    11
    2 #if !defined __LAYER_H__
    3 #define __LAYER_H__
     2/*
     3 * The layer object
     4 */
     5
     6#if !defined __DH_LAYER_H__
     7#define __DH_LAYER_H__
    48
    59#include <cstdio>
     
    812{
    913public:
    10     Layer(int w, int h, FILE *fp);
     14    Layer(char const *name, int w, int h, FILE *fp);
    1115    ~Layer();
    1216
     17    int GetZ();
    1318    unsigned int GetTile(int x, int y);
    1419
    15 //private:
    16     int width, height;
     20private:
     21    int width, height, z;
    1722    unsigned int *data;
    1823};
    1924
    20 #endif // __LAYER_H__
     25#endif // __DH_LAYER_H__
    2126
  • trunk/src/map.cpp

    r38 r47  
    2828        fgets(tmp, 1024, fp); // Ignore rest of line
    2929        layers = (Layer **)realloc(layers, sizeof(Layer **) * (nlayers + 1));
    30         layers[nlayers] = new Layer(width, height, fp);
     30        layers[nlayers] = new Layer(name, width, height, fp);
    3131        nlayers++;
    3232    }
     
    4545{
    4646    for (int i = 0; i < nlayers; i++)
     47    {
     48        int z = layers[i]->GetZ();
     49
    4750        for (int y = 0; y < 32; y++)
    4851            for (int x = 0; x < 32; x++)
    49                 tiler->AddTile(layers[i]->GetTile(x, y), x * 32, y * 32, i);
     52                tiler->AddTile(layers[i]->GetTile(x, y), x * 32, y * 32, z);
     53    }
    5054}
    5155
  • trunk/src/map.h

    r38 r47  
     1
     2/*
     3 * The map object
     4 */
     5
     6#if !defined __DH_MAP_H__
     7#define __DH_MAP_H__
    18
    29#include <cstdio>
     
    1825};
    1926
     27#endif // __DH_MAP_H__
     28
  • trunk/src/test-map.cpp

    r38 r47  
    1414    Video *video = new Video("Deus Hax", 640, 480);
    1515    Tiler *tiler = new Tiler();
    16     Map *map = new Map("maps/testmap-coll.tmx");
     16    Map *map = new Map("maps/testmap-grass.tmx");
    1717
    1818    for (int done = 0; !done; )
     
    2525        int playerx, playery;
    2626        SDL_GetMouseState(&playerx, &playery);
     27        playerx = playerx * (640 - 32) / 640;
     28        playery = playery * (480 - 32) / 480;
    2729
    2830        tiler->AddTile(50, playerx, playery, 1);
    29         tiler->AddTile(50, playerx + 64, playery + 32, 3);
    3031
    3132        tiler->Render();
  • trunk/src/tiler.h

    r38 r47  
    1 
    21
    32/*
     
    54 */
    65
    7 #if !defined __TILER_H__
    8 #define __TILER_H__
     6#if !defined __DH_TILER_H__
     7#define __DH_TILER_H__
    98
    109class TilerData;
     
    2423};
    2524
    26 #endif // __TILER_H__
     25#endif // __DH_TILER_H__
    2726
  • trunk/src/video.h

    r22 r47  
     1
     2/*
     3 * The video driver
     4 */
     5
     6#if !defined __DH_VIDEO_H__
     7#define __DH_VIDEO_H__
    18
    29class VideoData;
     
    1724    VideoData *data;
    1825};
     26
     27#endif // __DH_VIDEO_H__
     28
Note: See TracChangeset for help on using the changeset viewer.