|
|
|
@ -12,8 +12,18 @@ MazeScreen::MazeScreen(const std::vector<std::vector<int>>& maze):
|
|
|
|
|
maze(maze),
|
|
|
|
|
angleX(0),
|
|
|
|
|
mouseCapture(false), |
|
|
|
|
posX(1), |
|
|
|
|
posZ(1) {} |
|
|
|
|
posX(9999), |
|
|
|
|
posZ(9999), |
|
|
|
|
solid(true) { |
|
|
|
|
for (int i = 0; i < maze.size(); i++) { |
|
|
|
|
for (int j = 0; j < maze[i].size(); j++) { |
|
|
|
|
if (maze[i][j] == 0 && j < posZ) { |
|
|
|
|
posX = i; |
|
|
|
|
posZ = j; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void MazeScreen::display() { |
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
@ -35,6 +45,14 @@ void MazeScreen::display() {
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < maze.size(); i++) { |
|
|
|
|
for (int j = 0; j < maze[i].size(); j++) { |
|
|
|
|
// Draw floor
|
|
|
|
|
glPushMatrix(); |
|
|
|
|
glColor3ub(0x33, 0x33, 0x33); |
|
|
|
|
glTranslatef(i, -1, j); |
|
|
|
|
glutSolidCube(1); |
|
|
|
|
glPopMatrix(); |
|
|
|
|
|
|
|
|
|
float green, blue; |
|
|
|
|
switch (maze[i][j]) { |
|
|
|
|
case -1: |
|
|
|
|
glPushMatrix(); |
|
|
|
@ -49,9 +67,9 @@ void MazeScreen::display() {
|
|
|
|
|
glTranslatef(i, 0, j); |
|
|
|
|
|
|
|
|
|
// Scale green by X
|
|
|
|
|
auto green = Utils::clamp<float>(Utils::nummap<float>(abs(i - posX), 0, 3, 0, 1), 0, 1); |
|
|
|
|
green = Utils::clamp<float>(Utils::nummap<float>(abs(i - posX), 0, 3, 0, 1), 0, 1); |
|
|
|
|
// Scale blue by Z
|
|
|
|
|
auto blue = Utils::clamp<float>(Utils::nummap<float>(abs(j - posZ), 0, 3, 0, 1), 0, 1); |
|
|
|
|
blue = Utils::clamp<float>(Utils::nummap<float>(abs(j - posZ), 0, 3, 0, 1), 0, 1); |
|
|
|
|
|
|
|
|
|
glColor3f(1, green, blue); |
|
|
|
|
glutWireCube(1); |
|
|
|
@ -60,6 +78,13 @@ void MazeScreen::display() {
|
|
|
|
|
glutSolidCube(1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
glPopMatrix(); |
|
|
|
|
break; |
|
|
|
|
case 2: |
|
|
|
|
glPushMatrix(); |
|
|
|
|
glColor3ub(0xee, 0xee, 0x00); |
|
|
|
|
glTranslatef(i, -1, j); |
|
|
|
|
glutSolidCube(1); |
|
|
|
|
glPopMatrix(); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
@ -76,7 +101,7 @@ void MazeScreen::keyboard(unsigned char key, int x, int y) {
|
|
|
|
|
glutSetCursor(GLUT_CURSOR_INHERIT); |
|
|
|
|
} |
|
|
|
|
else if (key == ' ') { |
|
|
|
|
solid = !solid; |
|
|
|
|
solid = false; |
|
|
|
|
}
|
|
|
|
|
else if (key == 'w') { |
|
|
|
|
forceX += 1; |
|
|
|
@ -106,6 +131,10 @@ void MazeScreen::keyboardUp(unsigned char key, int x, int y) {
|
|
|
|
|
else if (key == 'd') { |
|
|
|
|
forceZ -= 1; |
|
|
|
|
} |
|
|
|
|
else if (key == ' ') { |
|
|
|
|
solid = true; |
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int gameTime; |
|
|
|
|