source: trunk/src/layer.cpp @ 57

Last change on this file since 57 was 57, checked in by sam, 11 years ago

Various fixes.

  • Property svn:keywords set to Id
File size: 879 bytes
RevLine 
[38]1
2#include "layer.h"
3
[47]4Layer::Layer(char const *name, int w, int h, FILE *fp)
[38]5{
6    width = w;
7    height = h;
8    data = new unsigned int[w * h];
9
[47]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)
[57]15        z++;
[47]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;
22
[38]23    fread(data, sizeof(unsigned int), width * height, fp);
24    for (int n = 0; n < width * height; n++)
25    {
26        unsigned int i = data[n];
27        // XXX: endianness swapping might be necessary here
28        data[n] = i ? i - 1 : 0;
29    }
30}
31
32Layer::~Layer()
33{
34    delete data;
35}
36
[47]37int Layer::GetZ()
38{
39    return z;
40}
41
[38]42unsigned int Layer::GetTile(int x, int y)
43{
44    return data[y * width + x];
45}
46
Note: See TracBrowser for help on using the repository browser.