Added maze class that handles parsing of the map and rendering of the floor, walls and objectives.

Detects and counts the number of objectives encountered. The number is printed on exit.
This commit is contained in:
trotFunky 2019-11-04 03:05:37 +01:00
parent 55f67099cb
commit 4cf658123b
13 changed files with 31453 additions and 41 deletions

View file

@ -6,9 +6,19 @@
#include "DataHandling/Texture.h"
#include "MovementManager.h"
#include "TileTypes.h"
#include "Maze.h"
static Texture map;
static constexpr float horizontal_speed = 0.05;
static int score = 0;
static Texture ground;
static Texture wall;
static Texture out;
static Texture raptor;
static Model3D raptor_model;
static Maze* maze;
static constexpr float horizontal_speed = 0.15;
static constexpr int units_per_pixel = 2;
static constexpr int map_side = 32;
static constexpr int corner_pos = (map_side*units_per_pixel);
@ -23,7 +33,6 @@ void manage_inputs()
Vec3d translation{0,0,0};
// TODO : camera_translate function in MovementManager that handles both the correct translation and rollback.
if (InputStatus::is_special_key_pressed(GLUT_KEY_RIGHT))
{
translation.z += horizontal_speed;
@ -42,15 +51,24 @@ void manage_inputs()
translation.x -= horizontal_speed;
}
constrained_translation(translation,OGLE::camera,map,units_per_pixel);
constrained_translation(translation,OGLE::camera,maze->map,units_per_pixel);
Vec3i map_colour = current_map_colour(OGLE::camera.get_eyepos(), map, units_per_pixel);
if (map_colour == end)
Vec3i map_colour = current_map_colour(OGLE::camera.get_eyepos(),maze->map, units_per_pixel);
if (map_colour == Tiles::end)
{
std::cout << "Success !" << std::endl;
std::cout << "You managed to collect " << score << " raptors!" << std::endl;
glutDestroyWindow(glutGetWindow());
exit(EXIT_SUCCESS);
}
else if(map_colour == Tiles::objective)
{
if (maze->remove_objective({static_cast<int>(OGLE::camera.get_eyepos().x/maze->scaling_factor),
static_cast<int>(OGLE::camera.get_eyepos().z/maze->scaling_factor)}))
{
score += 1;
}
}
Vec2i mouse_delta = InputStatus::get_mouse_delta(true);
if (mouse_delta.x != 0 || mouse_delta.y != 0)
@ -65,43 +83,29 @@ void display()
{
manage_inputs();
glEnable(GL_ALPHA_TEST);
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
glBindTexture(GL_TEXTURE_2D,map.opengl_id[0]);
// Deactivate interpolation
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glColor4f(1.0f, 1.0f, 1.0f,1.00);
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex3i(0,0,0);
glTexCoord2d(1,0);
glVertex3i(0,0,corner_pos);
glTexCoord2d(1,1);
glVertex3i(corner_pos,0,corner_pos);
glTexCoord2d(0,1);
glVertex3i(corner_pos,0,0);
glEnd();
glDisable(GL_ALPHA_TEST);
maze->draw();
}
int main(int argc, char** argv)
{
OGLE::setup(argc,argv,display,"The Labyrinth !");
map.load_rgb_tga("resources/Map.tga");
ground.load_rgb_tga("resources/ground.tga");
wall.load_rgb_tga("resources/wall.tga");
out.load_rgb_tga("resources/Outside.tga");
raptor.load_rgb_tga("resources/raptor.tga");
raptor_model.load_ascii_off_file("resources/raptor.off");
raptor_model.assign_texture(raptor);
raptor_model.set_scaling(0.0025,0.0025,0.0025);
raptor_model.set_rotation(-90,1,0,0);
OGLE::camera.set_position({corner_pos/2,1,corner_pos/2});
maze = new Maze("resources/Map.tga", 2, ground, wall, out, raptor_model);
// Fill colour is sky blue.
glClearColor(0.53,0.81,0.75,1);
glutMainLoop();
return 0;
}