-
Notifications
You must be signed in to change notification settings - Fork 0
/
Level.cpp
161 lines (151 loc) · 7.8 KB
/
Level.cpp
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// Created by Cyborg on 4/28/23.
#include "Level.h"
#include <iostream>
/********************************************************
* Level -- Level Class for the game, has tilemap and collision
*
* Author: Nathaniel Clark, Sebastian Mark
*
* Purpose: To allow for easy level making and handleing
********************************************************/
//constructor
Level::Level(std::string tileMapPath) {
this->currentLevel = 1;
this->tileMapPath = tileMapPath;
//level 1 array
const int level[] = {
// #78 is a black tile
78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
78, 0, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 5, 78,
78, 10, 11, 12, 13, 12, 12, 13, 12, 13, 13, 12, 13, 14, 15, 78,
78, 20, 21, 6, 7, 8, 9, 7, 8, 9, 17, 16, 9, 24, 25, 78,
78, 30, 21, 16, 17, 27, 28, 29, 18, 17, 7, 6, 7, 24, 35, 78,
78, 10, 21, 26, 27, 7, 6, 18, 19, 9, 26, 28, 18, 24, 25, 78,
78, 20, 31, 32, 33, 33, 32, 33, 32, 33, 32, 32, 33, 34, 35, 78,
78, 40, 41, 42, 43, 41, 42, 43, 44, 41, 42, 43, 44, 41, 45, 78,
78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
};
this->levelDesign.load(tileMapPath, sf::Vector2u(16, 16), level, 16, 9);
bool tileisWalkableLevel1[] = {
false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false,
false, false, true, true, true, true, true, true, true, true, true, true, true, true, false, false,
false, false, true, true, true, true, true, true, true, true, true, true, true, true, false, false,
false, false, true, true, true, true, true, true, true, true, true, true, true, true, false, false,
false, false, true, true, true, true, true, true, true, true, true, true, true, true, false, false,
false, false, true, true, true, true, true, true, true, true, true, true, true, true, false, false,
false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false,
};
for (int i = 0; i < 144; i++){
tileIsWalkable[i] = tileisWalkableLevel1[i];
}
}
//get the tilemap if you need to use it
TileMap* Level::getTilemap() {
return &levelDesign;
}
/********************************************************
* nextLevel - makes the game go to the next level
*
* Parameters - none
*
* Return - void
********************************************************/
void Level::nextLevel() {
this->currentLevel += 1;
if (currentLevel == 2) {
level2();
return;
}
if (currentLevel == 3){
level3();
return;
}
}
/********************************************************
* isTileXWalkable - sees if tile X is walkable
*
* Parameters - indexX, index we want to check is walkable
*
* Return - true if walkable, else false
********************************************************/
bool Level::isTileXWalkable(int indexX) {
if (indexX < 0 || indexX > 144){
return false;
}
return tileIsWalkable[indexX];
}
//level 2 arrays
void Level::level2() {
const int level[] = {
// #78 is a black tile
0, 1, 2, 3, 4, 5, 78, 78, 78, 78, 0, 1, 2, 3, 4, 5,
10, 11, 12, 13, 14, 2, 1, 2, 3, 4, 1, 11, 12, 13, 14, 15,
20, 31, 6, 7, 8, 12, 12, 13, 12, 13, 13, 6, 7, 9, 34, 25,
40, 55, 21, 6, 7, 8, 9, 7, 8, 9, 17, 16, 9, 24, 54, 45,
78, 10, 21, 16, 17, 27, 28, 29, 18, 17, 7, 6, 7, 24, 35, 78,
0, 1, 21, 26, 27, 27, 6, 18, 19, 9, 26, 28, 18, 24, 4, 5,
20, 11, 17, 18, 19, 33, 32, 33, 32, 33, 32, 8, 7, 6, 14, 25,
30, 31, 32, 33, 34, 50, 42, 43, 44, 41, 55, 31, 32, 33, 34, 15,
40, 41, 42, 43, 44, 45, 78, 78, 78, 78, 40, 41, 42, 43, 44, 45,
};
this->levelDesign.load(tileMapPath, sf::Vector2u(16, 16), level, 16, 9);
bool tileisWalkableLevel2[] = {
false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false,
false, true, true, true, true, false, false, false, false, false, false, true, true, true, true, false,
false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false,
false, false, true, true, true, true, true, true, true, true, true, true, true, true, false, false,
false, false, true, true, true, true, true, true, true, true, true, true, true, true, false, false,
false, false, true, true, true, true, true, true, true, true, true, true, true, true, false, false,
false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false,
false, true, true, true, true, false, false, false, false, false, false, true, true, true, true, false,
false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false,
};
for (int i = 0; i < 144; i++){
tileIsWalkable[i] = tileisWalkableLevel2[i];
}
}
//level 3 arrays
void Level::level3() {
const int level[] = {
// #78 is a black tile
0, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 5,
10, 11, 12, 13, 12, 12, 13, 12, 13, 12, 13, 12, 13, 12, 14, 15,
20, 21, 6, 7, 8, 26, 27, 27, 6, 18, 17, 6, 7, 9, 24, 25,
10, 21, 26, 50, 41, 55, 9, 7, 8, 9, 50, 42, 55, 19, 24, 35,
20, 21, 9, 1, 2, 3, 28, 29, 18, 17, 3, 1, 2, 9, 24, 15,
10, 21, 23, 26, 27, 27, 6, 18, 19, 9, 26, 28, 18, 6, 24, 25,
20, 21, 22, 18, 19, 33, 32, 23, 22, 33, 32, 8, 7, 6, 24, 35,
30, 31, 32, 33, 34, 50, 53, 31, 34, 54, 55, 31, 32, 33, 34, 15,
40, 41, 42, 43, 44, 45, 40, 41, 42, 45, 40, 41, 42, 43, 44, 45,
};
this->levelDesign.load(tileMapPath, sf::Vector2u(16, 16), level, 16, 9);
bool tileisWalkableLevel3[] = {
false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false,
false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false,
false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false,
false, true, true, false, false, false, true, true, true, true, false, false, false, true, true, false,
false, true, true, false, false, false, true, true, true, true, false, false, false, true, true, false,
false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false,
false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false,
false, true, true, true, true, false, false, true, true, false, false, true, true, true, true, false,
false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false,
};
for (int i = 0; i < 144; i++){
tileIsWalkable[i] = tileisWalkableLevel3[i];
}
}
void Level::setTileMapPath(std::string tileMapPath) {
this->tileMapPath = tileMapPath;
}
/********************************************************
* getCurrentLevel - returns the current level
*
* Parameters - none
*
* Return - int value of current level
********************************************************/
int Level::getCurrentLevel() {
return currentLevel;
}