-
Notifications
You must be signed in to change notification settings - Fork 0
/
LevelMap.hpp
66 lines (50 loc) · 1.67 KB
/
LevelMap.hpp
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
#pragma once
#include <array>
#include <memory>
#include <vector>
class GameElement;
#include "Elements.hpp"
#include "Constants.hpp"
// TODO: Separate Pixel out into a separate file
class Pixel
{
public:
Pixel(int x, int y);
Pixel(int x, int y, std::unique_ptr<GameElement> startingElem);
void update();
void render();
void addElem(std::unique_ptr<GameElement> elem);
std::unique_ptr<GameElement> removeBySymbol(const char symbol);
int getX() const;
int getY() const;
private:
// NOTE: Must consider implications of storing x and y in pixel and elements. Should it just be in pixel?
// When rendering elements, should I do a check pixel (x, y) matches element (x, y) and update elem?
int x;
int y;
Height maxHeight;
// height-ordered stack of game element pointers
std::vector<std::unique_ptr<GameElement>> stack;
/*
Iterates through stack until it finds an element with a lesser height, then inserts at itr + 1
(on top of old highest height elem). If the new element = max height of stack, insert it at end
Making a performance tradeoff on insertion to ensure that peeking the stack always returns the highest-
height element. This will make rendering much faster at a cost
*/
void insertByHeight(std::unique_ptr<GameElement> elemPtr);
};
class LevelMap {
public:
LevelMap();
~LevelMap()=default;
void update();
void render();
bool moveBySymbol(int x, int y, char symbol, std::pair<int, int> direction);
bool movePlayable(const std::pair<int, int>& direction);
static constexpr int MAP_WIDTH = 80;
static constexpr int MAP_HEIGHT = 20;
private:
int playableX;
int playableY;
std::array<std::array<std::unique_ptr<Pixel>, MAP_WIDTH>, MAP_HEIGHT> map;
};