Labyrinth-JIN/src/main.cpp

109 lines
No EOL
3 KiB
C++

//
// Created by trotFunky on 03/11/2019.
//
#include <Engine.h>
#include "DataHandling/Texture.h"
#include "MovementManager.h"
#include "TileTypes.h"
#include "Maze.h"
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 int score = 0;
void manage_inputs()
{
if (InputStatus::is_key_pressed(0x1B))
{
glutDestroyWindow(glutGetWindow());
exit(EXIT_SUCCESS);
}
Vec3d translation{0,0,0};
if (InputStatus::is_special_key_pressed(GLUT_KEY_RIGHT))
{
translation.z += horizontal_speed;
}
if (InputStatus::is_special_key_pressed(GLUT_KEY_LEFT))
{
translation.z -= horizontal_speed;
}
if (InputStatus::is_special_key_pressed(GLUT_KEY_UP))
{
translation.x += horizontal_speed;
}
if (InputStatus::is_special_key_pressed(GLUT_KEY_DOWN))
{
translation.x -= horizontal_speed;
}
constrained_translation(translation,OGLE::camera,maze->map,maze->scaling_factor);
Vec3i map_colour = current_map_colour(OGLE::camera.get_eyepos(),maze->map, maze->scaling_factor);
if (map_colour == Tiles::end)
{
std::cout << "Success !" << std::endl;
std::cout << "You managed to collect " << score << " out of " << maze->total_objectives << " 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)
{
OGLE::camera.rotate({0,
-mouse_delta.x / InputStatus::mouse_sensitivity.x,
-mouse_delta.y / InputStatus::mouse_sensitivity.y});
}
}
void display()
{
manage_inputs();
maze->draw();
}
int main(int argc, char** argv)
{
OGLE::setup(argc,argv,display,"The Labyrinth !");
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);
maze = new Maze("resources/Map.tga", 2, ground, wall, out, raptor_model);
OGLE::camera.set_position({static_cast<double>(maze->map.width*maze->scaling_factor/2.0),
1,
static_cast<double>(maze->map.width*maze->scaling_factor/2.0)});
// Fill colour is sky blue.
glClearColor(0.53,0.81,0.75,1);
glutMainLoop();
return 0;
}