-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorldMap.h
131 lines (94 loc) · 3.13 KB
/
WorldMap.h
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// This file is part of the WinRayCast Application (a 3D Engine Demo).
// Copyright (C) 2005 - 2018
// Antonino Calderone (antonino.calderone@gmail.com)
// All rights reserved.
// Licensed under the MIT License.
// See COPYING file in the project root for full license information.
/* -------------------------------------------------------------------------- */
#ifndef __WORLDMAP_H__
#define __WORLDMAP_H__
#include "BitmapBuffer.h"
#include "Player.h"
#include <windows.h>
#pragma warning (disable: 4786)
#include <math.h>
#include <map>
#include <vector>
#include <string>
/* -------------------------------------------------------------------------- */
class WorldMap
{
public:
using Cell = uint64_t;
using Point2d = std::pair<double, double>;
using TextureList = std::map<std::string, std::string>;
WorldMap() = default;
HBITMAP getBmp(int key) const noexcept {
return m_bmp[key];
}
const Point2d& getPlayerCellPos() const noexcept {
return m_playerCellPos;
}
int getRowCount() const noexcept {
return int(m_map.size());
}
int getColCount() const noexcept {
return int(m_map.empty() ? 0 : m_map[0].size());
}
uint32_t getCellDx() const noexcept {
return m_cellDx;
}
uint32_t getCellDy() const noexcept {
return m_cellDy;
}
std::vector<Cell> & operator[](uint32_t index) throw () {
return m_map[index];
}
const std::vector<Cell> & operator[](uint32_t index) const throw () {
return m_map[index];
}
void resizeCell(uint32_t cellDx, uint32_t cellDy) noexcept {
m_cellDx = cellDx;
m_cellDy = cellDy;
m_maxX = getCellDx() * getColCount();
m_maxY = getCellDy() * getRowCount();
}
void setPlayerPos(int x, int y) noexcept {
m_playerCellPos.first = /*player.getX()*/ x / getCellDx();
m_playerCellPos.second = /*player.getY()*/ y / getCellDy();
}
void applyTextureToPanel(int panelKey, HBITMAP hBitmap) noexcept {
m_bmp[panelKey & 0xff] = hBitmap;
}
int getMaxX() const noexcept {
return m_maxX;
}
int getMaxY() const noexcept {
return m_maxY;
}
void set(int row, int col, Cell cellVal) {
if (col < getColCount() && row < getRowCount())
m_map[row][col] = cellVal;
}
bool load(const std::string& fileName);
const TextureList& getTextureList() const noexcept {
return m_textureList;
}
TextureList& getTextureList() noexcept {
return m_textureList;
}
private:
bool setMapInfo(const Cell* array, uint32_t rows, uint32_t cols);
using Row = std::vector<Cell>;
using Matrix = std::vector<Row>;
Matrix m_map;
int m_cellDx = 256;
int m_cellDy = 256;
int m_maxX = 0;
int m_maxY = 0;
Point2d m_playerCellPos{ 0,0 };
HBITMAP m_bmp[256] = { 0 };
TextureList m_textureList;
};
/* -------------------------------------------------------------------------- */
#endif