Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- OUR FIRST VIDEO GAME
- This is our first attempt at creating a video game using OpenGL and C++.
- The team members are, from youngest to oldest:
- - Toni, Ugo, Vanja.
- The project started on Saturday, July 30, 2016, after a straight week of learning OpenGL without stopping.
- After a short discussion in a local cafe, we decided what the main concepts of the game would be, and what
- problems we'll be looking to solve while developing the game. The game is basically a prototype for our
- upcoming gargantuan project, (codename: Sektor Exitium) so it leaves much to be desired for, which is fine.
- The basic premise is that you're a jailbird on a prison colony planet, with the goal of fleeing from the
- facility. This way, we get to experiment with various game mechanics, while avoiding the more complicated
- issues such as AI, procedural generation of open worlds, complex combat and crafting systems, etc...
- Here's to a successful first project!
- */
- #include <iostream> // STD includes
- #include <cstdlib>
- #include <math.h>
- #include <string>
- #include <conio.h>
- #define GLEW_STATIC
- #include <GL/glew.h> // GLEW includes
- #include <GLFW/glfw3.h> // GLFW includes
- #include "Shader.h" // GL includes
- #include "Resource_manager.h"
- #include "Texture.h"
- #include <glm/glm.hpp> // GLM Mathematics
- #include <glm/gtc/matrix_transform.hpp>
- #include <glm/gtc/type_ptr.hpp>
- #include <SOIL.h> // Other Libs
- using namespace std;
- using namespace glm;
- // Window properties
- GLuint screenWidth = 1200, screenHeight = 675;
- // Function prototypes
- void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode);
- void mouse_callback(GLFWwindow* window, double xpos, double ypos);
- int nextTile, previousTile;
- int h = 20, w = 36, a, b;
- int x = 2, y = 2;
- int Matrix[20][36] =
- {
- { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
- { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
- { 1, 0,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ile = 0;
- for (a = 0; a < h; a++) {
- cout << endl;
- for (b = 0; b < w; b++) {
- cout << Matrix[a][b] << ' ';
- }
- }
- // Sets up everything window related using GLFW
- glfwInit();
- glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
- glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
- glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
- glfwWindowHint(GLFW_SAMPLES, 4);
- GLFWwindow* window = glfwCreateWindow(screenWidth, screenHeight, "Sektor Exitium: Escape", nullptr, nullptr);
- glfwMakeContextCurrent(window); // Start the application windowed
- glfwSetKeyCallback(window, key_callback); // Set the required callback functions
- glfwSetCursorPosCallback(window, mouse_callback);
- glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); // Cursor options
- glewExperimental = GL_TRUE; // Initialize GLEW to setup the OpenGL Function pointers
- glewInit();
- glViewport(0, 0, screenWidth, screenHeight); // Define the viewport dimensions
- Shader ourShader = ResourceManager::LoadShader("shader.vs", "shader.frag", nullptr, "test");
- // GAME LOOP STARTS HERE
- while (!glfwWindowShouldClose(window))
- {
- glfwPollEvents();
- glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- ourShader.Use();
- glfwSwapBuffers(window);
- }
- // GAME LOOP ENDS HERE
- ResourceManager::Clear();
- }
- // Function for keyboard input
- void key_callback(GLFWwindow * window, int key, int scancode, int action, int mode)
- {
- if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
- glfwSetWindowShouldClose(window, GL_TRUE);
- if (key == GLFW_KEY_UP && action == GLFW_PRESS) {
- if (Matrix[y - 1][x] == 1) {
- cout << "You hit a wall!";
- }
- else {
- Matrix[y][x] = 0;
- Matrix[y - 1][x] = 5;
- y = y - 1;
- for (a = 0; a < h; a++) {
- cout << endl;
- for (b = 0; b < w; b++) {
- cout << Matrix[a][b] << ' ';
- }
- }
- }
- }
- if (key == GLFW_KEY_DOWN && action == GLFW_PRESS) {
- if (Matrix[y + 1][x] == 1) {
- cout << "You hit a wall!";
- }
- else {
- Matrix[y][x] = 0;
- Matrix[y + 1][x] = 5;
- y = y + 1;
- for (a = 0; a < h; a++) {
- cout << endl;
- for (b = 0; b < w; b++) {
- cout << Matrix[a][b] << ' ';
- }
- }
- }
- }
- if (key == GLFW_KEY_LEFT && action == GLFW_PRESS) {
- if (Matrix[y][x - 1] == 1) {
- cout << "You hit a wall!";
- }
- else {
- Matrix[y][x] = 0;
- Matrix[y][x - 1] = 5;
- x = x - 1;
- for (a = 0; a < h; a++) {
- cout << endl;
- for (b = 0; b < w; b++) {
- cout << Matrix[a][b] << ' ';
- }
- }
- }
- }
- if (key == GLFW_KEY_RIGHT && action == GLFW_PRESS) {
- if (Matrix[y][x + 1] == 1) {
- cout << "You hit a wall!";
- }
- else {
- Matrix[y][x] = 0;
- Matrix[y][x + 1] = 5;
- x = x + 1;
- for (a = 0; a < h; a++) {
- cout << endl;
- for (b = 0; b < w; b++) {
- cout << Matrix[a][b] << ' ';
- }
- }
- }
- }
- }
- // Function for mouse input
- void mouse_callback(GLFWwindow * window, double xpos, double ypos)
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement