Advertisement
Kirabo

Untitled

Jul 31st, 2016
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.15 KB | None | 0 0
  1. /*
  2. OUR FIRST VIDEO GAME
  3.  
  4. This is our first attempt at creating a video game using OpenGL and C++.
  5. The team members are, from youngest to oldest:
  6. - Toni, Ugo, Vanja.
  7.  
  8. The project started on Saturday, July 30, 2016, after a straight week of learning OpenGL without stopping.
  9. After a short discussion in a local cafe, we decided what the main concepts of the game would be, and what
  10. problems we'll be looking to solve while developing the game. The game is basically a prototype for our
  11. upcoming gargantuan project, (codename: Sektor Exitium) so it leaves much to be desired for, which is fine.
  12.  
  13. The basic premise is that you're a jailbird on a prison colony planet, with the goal of fleeing from the
  14. facility. This way, we get to experiment with various game mechanics, while avoiding the more complicated
  15. issues such as AI, procedural generation of open worlds, complex combat and crafting systems, etc...
  16.  
  17. Here's to a successful first project!
  18. */
  19.  
  20. #include <iostream> // STD includes
  21. #include <cstdlib>
  22. #include <math.h>
  23. #include <string>
  24. #include <conio.h>
  25.  
  26. #define GLEW_STATIC
  27.  
  28. #include <GL/glew.h> // GLEW includes
  29.  
  30. #include <GLFW/glfw3.h> // GLFW includes
  31.  
  32. #include "Shader.h" // GL includes
  33. #include "Resource_manager.h"
  34. #include "Texture.h"
  35.  
  36. #include <glm/glm.hpp> // GLM Mathematics
  37. #include <glm/gtc/matrix_transform.hpp>
  38. #include <glm/gtc/type_ptr.hpp>
  39.  
  40. #include <SOIL.h> // Other Libs
  41.  
  42. using namespace std;
  43. using namespace glm;
  44.  
  45. // Window properties
  46. GLuint screenWidth = 1200, screenHeight = 675;
  47.  
  48. // Function prototypes
  49. void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode);
  50. void mouse_callback(GLFWwindow* window, double xpos, double ypos);
  51.  
  52. int nextTile, previousTile;
  53. int h = 20, w = 36, a, b;
  54. int x = 2, y = 2;
  55. int Matrix[20][36] =
  56. {
  57. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 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 },
  76. { 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 }
  77. };
  78.  
  79. int main() {
  80.  
  81. system("COLOR 0B");
  82.  
  83. Matrix[x][y] = 5;
  84. previousTile = 0;
  85.  
  86. for (a = 0; a < h; a++) {
  87. cout << endl;
  88. for (b = 0; b < w; b++) {
  89. cout << Matrix[a][b] << ' ';
  90. }
  91. }
  92.  
  93. // Sets up everything window related using GLFW
  94. glfwInit();
  95. glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
  96. glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
  97. glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
  98. glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
  99. glfwWindowHint(GLFW_SAMPLES, 4);
  100.  
  101. GLFWwindow* window = glfwCreateWindow(screenWidth, screenHeight, "Sektor Exitium: Escape", nullptr, nullptr);
  102. glfwMakeContextCurrent(window); // Start the application windowed
  103.  
  104. glfwSetKeyCallback(window, key_callback); // Set the required callback functions
  105. glfwSetCursorPosCallback(window, mouse_callback);
  106.  
  107.  
  108. glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); // Cursor options
  109.  
  110.  
  111. glewExperimental = GL_TRUE; // Initialize GLEW to setup the OpenGL Function pointers
  112. glewInit();
  113.  
  114. glViewport(0, 0, screenWidth, screenHeight); // Define the viewport dimensions
  115.  
  116. Shader ourShader = ResourceManager::LoadShader("shader.vs", "shader.frag", nullptr, "test");
  117.  
  118. // GAME LOOP STARTS HERE
  119. while (!glfwWindowShouldClose(window))
  120. {
  121.  
  122. glfwPollEvents();
  123.  
  124. glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
  125. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  126.  
  127. ourShader.Use();
  128.  
  129. glfwSwapBuffers(window);
  130. }
  131. // GAME LOOP ENDS HERE
  132.  
  133. ResourceManager::Clear();
  134.  
  135. }
  136.  
  137. // Function for keyboard input
  138.  
  139. void key_callback(GLFWwindow * window, int key, int scancode, int action, int mode)
  140. {
  141. if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
  142. glfwSetWindowShouldClose(window, GL_TRUE);
  143. if (key == GLFW_KEY_UP && action == GLFW_PRESS) {
  144. if (Matrix[y - 1][x] == 1) {
  145. cout << "You hit a wall!";
  146. }
  147. else {
  148. Matrix[y][x] = 0;
  149. Matrix[y - 1][x] = 5;
  150. y = y - 1;
  151. for (a = 0; a < h; a++) {
  152. cout << endl;
  153. for (b = 0; b < w; b++) {
  154. cout << Matrix[a][b] << ' ';
  155. }
  156. }
  157. }
  158. }
  159. if (key == GLFW_KEY_DOWN && action == GLFW_PRESS) {
  160.  
  161. if (Matrix[y + 1][x] == 1) {
  162. cout << "You hit a wall!";
  163. }
  164. else {
  165. Matrix[y][x] = 0;
  166. Matrix[y + 1][x] = 5;
  167. y = y + 1;
  168. for (a = 0; a < h; a++) {
  169. cout << endl;
  170. for (b = 0; b < w; b++) {
  171. cout << Matrix[a][b] << ' ';
  172. }
  173. }
  174. }
  175. }
  176. if (key == GLFW_KEY_LEFT && action == GLFW_PRESS) {
  177. if (Matrix[y][x - 1] == 1) {
  178. cout << "You hit a wall!";
  179. }
  180. else {
  181. Matrix[y][x] = 0;
  182. Matrix[y][x - 1] = 5;
  183. x = x - 1;
  184. for (a = 0; a < h; a++) {
  185. cout << endl;
  186. for (b = 0; b < w; b++) {
  187. cout << Matrix[a][b] << ' ';
  188. }
  189. }
  190. }
  191. }
  192. if (key == GLFW_KEY_RIGHT && action == GLFW_PRESS) {
  193. if (Matrix[y][x + 1] == 1) {
  194. cout << "You hit a wall!";
  195. }
  196. else {
  197. Matrix[y][x] = 0;
  198. Matrix[y][x + 1] = 5;
  199. x = x + 1;
  200. for (a = 0; a < h; a++) {
  201. cout << endl;
  202. for (b = 0; b < w; b++) {
  203. cout << Matrix[a][b] << ' ';
  204. }
  205. }
  206. }
  207. }
  208. }
  209.  
  210. // Function for mouse input
  211. void mouse_callback(GLFWwindow * window, double xpos, double ypos)
  212. {
  213.  
  214. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement