1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#pragma once
#include "bitmap.h"
#include <cstdint>
#include <cstring>
#include <vector>
#define TILE_TYPE(x) ((x)&0xf)
#define TILE_DATA(x) (x >> 4 & 0xf)
#define MAKE_TILE(t, d) ((((d)&0xf) << 4) + ((t)&0xf))
class Train;
enum TileType : uint8_t {
TileGround,
TileWall,
TileTrack
};
enum TrackDirection : uint8_t {
NorthSouth,
EastWest,
SouthEast,
SouthWest,
NorthWest,
NorthEast,
};
class Level {
public:
Level(int width, int height, Bitmap& tileSprites);
~Level() { delete[] m_tiles; }
uint8_t get(int x, int y);
void set(int x, int y, uint8_t tile);
bool inBounds(int x, int y) const { return x >= 0 && x < m_width && y >= 0 && y < m_height; }
void update();
void draw(Bitmap& bitmap, int xo, int yo);
Train* addVehicle();
void toggleTile(int x, int y);
void save() const;
void load();
private:
Bitmap& m_tileSprites;
int m_width, m_height;
uint8_t* m_tiles;
std::vector<Train> m_vehicles;
};
TrackDirection ChooseDirection(Level& level, int x, int y);
|