NXEngine v1.0.0.5
[NXEngine.git] / graphics / tileset.cpp
blobc978555e6b406673ec67a5a705c671bf1fff6144
2 // manages the tileset
3 #include "graphics.h"
4 #include "tileset.h"
5 #include "tileset.fdh"
6 using namespace Graphics;
8 extern const char *tileset_names[]; // from stagedata.cpp
9 extern const char *stage_dir; // from main
11 static NXSurface *tileset;
12 static int current_tileset = -1;
14 bool Tileset::Init()
16 tileset = NULL;
17 current_tileset = -1;
18 return 0;
21 void Tileset::Close()
23 delete tileset;
27 void c------------------------------() {}
30 // load the given tileset into memory, replacing any other tileset.
31 bool Tileset::Load(int new_tileset)
33 char fname[MAXPATHLEN];
35 if (new_tileset != current_tileset)
37 if (tileset)
39 delete tileset;
40 current_tileset = -1;
43 sprintf(fname, "%s/Prt%s.pbm", stage_dir, tileset_names[new_tileset]);
45 // always use SDL_DisplayFormat on tilesets; they need to come out of 8-bit
46 // so that we can replace the destroyable star tiles without them palletizing.
47 tileset = NXSurface::FromFile(fname, true, true);
48 if (!tileset)
50 return 1;
53 current_tileset = new_tileset;
56 return 0;
59 // draw the given tile from the current tileset to the screen
60 void Tileset::draw_tile(int x, int y, int t)
62 // 16 tiles per row on all tilesheet
63 int srcx = (t % 16) * TILE_W;
64 int srcy = (t / 16) * TILE_H;
66 DrawSurface(tileset, x, y, srcx, srcy, TILE_W, TILE_H);
69 void Tileset::Reload()
71 if (current_tileset != -1)
73 int tileset = current_tileset;
74 current_tileset = -1;
75 Load(tileset);
80 void c------------------------------() {}
83 NXSurface *Tileset::GetSurface()
85 return tileset;