]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Added New Header File and UI Class
authorAndy Belle-Isle <abelleisle@roadrunner.com>
Mon, 7 Sep 2015 16:49:05 +0000 (12:49 -0400)
committerAndy Belle-Isle <abelleisle@roadrunner.com>
Mon, 7 Sep 2015 16:49:05 +0000 (12:49 -0400)
Added UI Class for controlling the UI of course :P
Added gameHeader.h for variables that are accessed by multiple
files/classes

Makefile
src/UIClass.cpp [new file with mode: 0644]
src/UIClass.h [new file with mode: 0644]
src/gameHeader.h [new file with mode: 0644]
src/main.cpp

index 85f2a828b0b81dbcaf7fba7392afa07073e5b567..d2fe513ecd748d06e04f02550bf6529396bccda8 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -3,10 +3,10 @@ FLAGS_WIN32 = -lopengl32 -lmingw32 #-lSDL2_Image
 FLAGS = -m32 -Iinclude -Wall -Werror -lSDL2main -lSDL2
 
 all:
-       @g++ src/main.cpp -o main $(FLAGS_LINUX) $(FLAGS)
+       @g++ src/main.cpp src/UIClass.cpp -o main $(FLAGS_LINUX) $(FLAGS)
 
 win32:
-       @g++ -L lib/ src/main.cpp -o main.exe $(FLAGS_WIN32) $(FLAGS)
+       @g++ -L lib/ src/main.cpp src/UIClass.cpp -o main.exe $(FLAGS_WIN32) $(FLAGS)
 
 clean:
        rm main*
diff --git a/src/UIClass.cpp b/src/UIClass.cpp
new file mode 100644 (file)
index 0000000..711440a
--- /dev/null
@@ -0,0 +1,21 @@
+#include "UIClass.h"
+
+void UIClass::handleEvents(){
+       while(SDL_PollEvent(&e)){
+               switch(e.type){
+               case SDL_QUIT:
+                       gameRunning=false;
+                       break;
+               case SDL_KEYDOWN:
+                       switch(e.key.keysym.sym){
+                       case 27:
+                               gameRunning=false;
+                               break;
+                       default:
+                               break;
+                       }
+               default:
+                       break;
+               }
+       }
+}
\ No newline at end of file
diff --git a/src/UIClass.h b/src/UIClass.h
new file mode 100644 (file)
index 0000000..956dbb8
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef UICLASS_H
+#define UICLASS_H
+
+#include <iostream>
+#include <cstdlib>
+#include <SDL2/SDL.h>
+#include <SDL2/SDL_opengl.h>
+
+extern SDL_Event e;
+extern bool gameRunning;
+
+class UIClass{
+       public:
+               void handleEvents();
+       
+};
+
+#endif //UICLASS_H
\ No newline at end of file
diff --git a/src/gameHeader.h b/src/gameHeader.h
new file mode 100644 (file)
index 0000000..f289527
--- /dev/null
@@ -0,0 +1,23 @@
+///THIS FILE IS USED FOR VARIABLES THAT WILL BE ACCESED BY MULTIPLE CLASSES/FILES
+#include <iostream>
+#include <cstdlib>
+#include <SDL2/SDL.h>
+#include <SDL2/SDL_opengl.h>
+
+#include "UIClass.h" //This can access SDL_Event e, if it won't compile for you, move it down to right above the ui object definition I guess :P
+
+//SDL VARIABLES
+SDL_Window    *window = NULL;
+SDL_Surface   *renderSurface = NULL;
+SDL_GLContext  mainGLContext = NULL;
+
+//WINODWS VARIABLES
+const float sh = SCREEN_HEIGHT;
+const float sw = SCREEN_WIDTH;
+bool gameRunning = true;
+SDL_Event e;
+
+//OTHER VARIABLES
+UIClass ui;
+
+//FUNCTIONS
index 8b3036eef6388ea5b1f948e11e7a01facea51025..f152963a323c2b4c1f9e1f34011ea0064e68de6e 100644 (file)
@@ -7,17 +7,12 @@
 #define SCREEN_HEIGHT 720
 //#define FULLSCREEN
 
-SDL_Window    *window = NULL;
-SDL_Surface   *renderSurface = NULL;
-SDL_GLContext  mainGLContext = NULL;
 
-const float sh = SCREEN_HEIGHT;
-const float sw = SCREEN_WIDTH;
-bool gameRunning = true;
+#include "gameHeader.h"
+
 
 int main(int argc,char **argv){
-       SDL_Event e;
-    //runs startup procedures
+    //runs start-up procedures
     if(SDL_Init(SDL_INIT_VIDEO) < 0){
                std::cout << "SDL was not able to initialize! Error: " << SDL_GetError() << std::endl;
        }else{
@@ -25,7 +20,7 @@ int main(int argc,char **argv){
                //Turn on double Buffering
         SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
         //create the window
-        window = SDL_CreateWindow("Sword Swinger", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL
+        window = SDL_CreateWindow("Independent Study v. Alpha -1.0", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL
                                   #ifdef FULLSCREEN
                                   | SDL_WINDOW_FULLSCREEN
                                   #endif // FULLSCREEN
@@ -33,36 +28,32 @@ int main(int argc,char **argv){
         if(window == NULL){
                std::cout << "The window failed to generate! Error: " << SDL_GetError() << std::endl;
         }else{
-            //set opengl context
+            //set OpenGL context
             mainGLContext = SDL_GL_CreateContext(window);
             if(mainGLContext == NULL){
                std::cout << "The OpenGL context failed to initialize! Error: " << SDL_GetError() << std::endl;
             }
                }
     }
-       // main loop
+       
+       
+       /**************************
+       ****     GAMELOOP      ****
+       **************************/
+       
        glClearColor(1,1,1,0);
        while(gameRunning){
                glClear(GL_COLOR_BUFFER_BIT);
                SDL_GL_SwapWindow(window);
-               while(SDL_PollEvent(&e)){
-                       switch(e.type){
-                       case SDL_QUIT:
-                               gameRunning=false;
-                               break;
-                       case SDL_KEYDOWN:
-                               switch(e.key.keysym.sym){
-                               case 27:
-                                       gameRunning=false;
-                                       break;
-                               default:
-                                       break;
-                               }
-                       default:
-                               break;
-                       }
-               }
+               
+               ui.handleEvents();
        }
+       
+       /**************************
+       ****  CLOSE PROGRAM    ****
+       **************************/
+       
+       
     //closes the window and frees resources
     SDL_GL_DeleteContext(mainGLContext);
     SDL_DestroyWindow(window);