diff options
-rw-r--r-- | doc/QuestList.htm | 40 | ||||
-rw-r--r-- | include/World.h | 63 | ||||
-rw-r--r-- | include/common.h | 96 | ||||
-rw-r--r-- | include/entities.h | 81 | ||||
-rw-r--r-- | src/UIClass.cpp | 85 | ||||
-rw-r--r-- | src/World.cpp | 148 | ||||
-rw-r--r-- | src/entities.cpp | 53 | ||||
-rw-r--r-- | src/main.cpp | 339 |
8 files changed, 636 insertions, 269 deletions
diff --git a/doc/QuestList.htm b/doc/QuestList.htm new file mode 100644 index 0000000..a4bf677 --- /dev/null +++ b/doc/QuestList.htm @@ -0,0 +1,40 @@ +<!DOCTYPE html> +<html> +<head> + <title>Quest</title> + <style> + .title{ + background:#833; + color:white; + font-family:Consolas; + font-size:16px; + margin:auto 20px; + padding:12px; + } + .code{ + background:#555; + color:white; + font-family:Consolas; + font-size:12px; + margin:auto 20px; + padding:20px; + } + .reward{ + background:#383; + color:white; + font-family:Consolas; + font-size:16px; + margin:auto 20px; + padding:15px; + + } + </style> +</head> +<body> + <h1>Quests</h1> + <hr> + <div class="title">Hello there!</div> + <div class="code">In this quest you must find the starting village of ASS</div> + <div class="reward">A starting weapon for the class of your choice</div> +</body> +</html> diff --git a/include/World.h b/include/World.h index e405059..dd133b9 100644 --- a/include/World.h +++ b/include/World.h @@ -1,21 +1,42 @@ -#ifndef WORLD_H
-#define WORLD_H
-
-#include <common.h>
-
-#define HLINE (2.0f/(SCREEN_WIDTH/4))
-
-class World {
-private:
- struct line_t {
- // x = 2.0 (window width) / HLINES
- double start; // Where to change to dirt, going down (y)
- } *line;
- unsigned int lineCount;
-public:
- World(float width);
- void draw(void);
- void detect(vec2 *v,const float width);
-};
-
-#endif // WORLD_H
+<<<<<<< HEAD +#ifndef WORLD_H +#define WORLD_H + +#include <common.h> + +class World { +private: + struct line_t { + // x = 2.0 (window width) / HLINES + float start; // Where to change to dirt, going down (y) + } *line; + unsigned int lineCount; +public: + World(float width); + void draw(void); +}; + +#endif // WORLD_H +======= +#ifndef WORLD_H +#define WORLD_H + +#include <common.h> + +#define HLINE (2.0f/(SCREEN_WIDTH/4)) + +class World { +private: + struct line_t { + // x = 2.0 (window width) / HLINES + double start; // Where to change to dirt, going down (y) + } *line; + unsigned int lineCount; +public: + World(float width); + void draw(void); + void detect(vec2 *v,const float width); +}; + +#endif // WORLD_H +>>>>>>> origin/master diff --git a/include/common.h b/include/common.h index 782ebd6..48a068d 100644 --- a/include/common.h +++ b/include/common.h @@ -1,31 +1,65 @@ -#ifndef COMMON_H
-#define COMMON_H
-
-typedef struct{float x; float y;}vec2;
-
-///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_image.h>
-#include <SDL2/SDL_opengl.h>
-#include <UIClass.h>
-#include <entities.h>
-#include <World.h>
-
-#define SCREEN_WIDTH 1280
-#define SCREEN_HEIGHT 800
-#define FULLSCREEN
-
-
-
-//SDL VARIABLES
-extern SDL_Window *window;
-extern SDL_Surface *renderSurface;
-extern SDL_GLContext mainGLContext;
-
-//WINODWS VARIABLES
-extern bool gameRunning;
-
-#endif // COMMON_H
+<<<<<<< HEAD +#ifndef COMMON_H +#define COMMON_H + +typedef struct{float x; float y;}vec2; + +///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_image.h> +#include <SDL2/SDL_opengl.h> +#include <UIClass.h> +#include <entities.h> +#include <World.h> + +#define SCREEN_WIDTH 1280 +#define SCREEN_HEIGHT 720 +//#define FULLSCREEN + +#define HLINE (2.0f / (SCREEN_WIDTH / 4)) + +//SDL VARIABLES +extern SDL_Window *window; +extern SDL_Surface *renderSurface; +extern SDL_GLContext mainGLContext; + +//WINDOW VARIABLES +extern bool gameRunning; + +#endif // COMMON_H +======= +#ifndef COMMON_H +#define COMMON_H + +typedef struct{float x; float y;}vec2; + +///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_image.h> +#include <SDL2/SDL_opengl.h> +#include <UIClass.h> +#include <entities.h> +#include <World.h> + +#define SCREEN_WIDTH 1280 +#define SCREEN_HEIGHT 800 +#define FULLSCREEN + + + +//SDL VARIABLES +extern SDL_Window *window; +extern SDL_Surface *renderSurface; +extern SDL_GLContext mainGLContext; + +//WINODWS VARIABLES +extern bool gameRunning; + +#endif // COMMON_H +>>>>>>> origin/master diff --git a/include/entities.h b/include/entities.h index 3ecf014..89d9ec3 100644 --- a/include/entities.h +++ b/include/entities.h @@ -1,26 +1,57 @@ -#ifndef ENTITIES_H
-#define ENTITIES_H
-
-#include <common.h>
-
-
-class Entities{
-public:
- float width;
- float height;
- float speed;
- int type;
- vec2 loc;
-
- void spawn(float, float);
-
-
-};
-
-class Player : public Entities{
-public:
- Player();
- ~Player();
-};
-
+<<<<<<< HEAD +#ifndef ENTITIES_H +#define ENTITIES_H + +#include <common.h> + + +class Entities{ +public: + float width; + float height; + float speed; + int type; + vec2 loc; + vec2 loci; + vec2 vel; + vec2 velg; + + void spawn(float, float); + + +}; + +class Player : public Entities{ +public: + Player(); + ~Player(); +}; + +======= +#ifndef ENTITIES_H +#define ENTITIES_H + +#include <common.h> + + +class Entities{ +public: + float width; + float height; + float speed; + int type; + vec2 loc; + + void spawn(float, float); + + +}; + +class Player : public Entities{ +public: + Player(); + ~Player(); +}; + +>>>>>>> origin/master #endif //ENTITIES_H
\ No newline at end of file diff --git a/src/UIClass.cpp b/src/UIClass.cpp index c17b6a7..bf76336 100644 --- a/src/UIClass.cpp +++ b/src/UIClass.cpp @@ -1,22 +1,63 @@ -#include <UIClass.h>
-
-void UIClass::handleEvents(){
- SDL_Event e;
- 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;
- }
- }
-}
+<<<<<<< HEAD +#include <UIClass.h> +extern Player player; + +void UIClass::handleEvents(){ + SDL_Event e; + while(SDL_PollEvent(&e)){ + switch(e.type){ + case SDL_QUIT: + gameRunning=false; + break; + case SDL_KEYDOWN: + switch(e.key.keysym.sym){ + case 27: ///ESCAPE + gameRunning=false; + break; + case SDLK_d: ///D + player.velg.x = 10; + break; + case SDLK_a: ///A + player.velg.x = -10; + break; + default: + break; + } + case SDL_KEYUP: + switch(e.key.keysym.sym){ + /*case SDLK_d: ///D + break; + case SDLK_a: ///A + break;*/ + default: + break; + } + default: + break; + } + } +} +======= +#include <UIClass.h> + +void UIClass::handleEvents(){ + SDL_Event e; + 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; + } + } +} +>>>>>>> origin/master diff --git a/src/World.cpp b/src/World.cpp index 022948f..52cfb40 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1,57 +1,91 @@ -#include <World.h>
-
-World::World(float width){
- unsigned int i;
- double f;
- lineCount=width/HLINE+1;
- if((line=(struct line_t *)calloc(lineCount,sizeof(struct line_t)))==NULL){
- std::cout<<"Failed to allocate memory!"<<std::endl;
- abort();
- }
- line[0].start=(rand()%100)/100.0f-0.8f; // lazy
- if(line[0].start>-0.5f)line[0].start=-0.7f;
- for(i=10;i<lineCount;i+=10){
- line[i].start=((double)(rand()%40+200))/1000.0f-1;
- }
- for(i=0;i<lineCount;i++){
- if(!(i%10)||!i){
- f=line[i+10].start-line[i].start;
- f/=10.0f;
- }else{
- line[i].start=line[i-1].start+f;
- }
- }
-}
-void World::draw(void){
- unsigned int i;
- glBegin(GL_QUADS);
- for(i=0;i<lineCount;i++){
- glColor3ub(0,255,0);
- glVertex2f((HLINE*i)-1 ,line[i].start);
- glVertex2f((HLINE*i)-1+HLINE,line[i].start);
- glVertex2f((HLINE*i)-1+HLINE,line[i].start-HLINE*2);
- glVertex2f((HLINE*i)-1 ,line[i].start-HLINE*2);
- glColor3ub(150,100,50);
- glVertex2f((HLINE*i)-1 ,line[i].start-HLINE*2);
- glVertex2f((HLINE*i)-1+HLINE,line[i].start-HLINE*2);
- glVertex2f((HLINE*i)-1+HLINE,-1);
- glVertex2f((HLINE*i)-1 ,-1);
- }
- glEnd();
-}
-void World::detect(vec2 *v,const float width){
- unsigned int i;
- for(i=0;i<lineCount;i++){
- if(v->y<line[i].start){
- if(v->x>(HLINE*i)-1&&v->x<(HLINE*i)-1+HLINE){
- v->x=(HLINE*i)-1+HLINE;
- }else if(v->x+width>(HLINE*i)-1&&v->x+width<(HLINE*i)-1+HLINE){
- v->x=(HLINE*i)-1-width;
- }else{
- v->y=line[i].start;
- }
- }else if(v->y>line[i].start+HLINE/2){
- v->y-=HLINE/4;
- }
- }
-}
+<<<<<<< HEAD +#include <World.h> + +World::World(float width){ + unsigned int i; + lineCount=width/HLINE+1; + if((line=(struct line_t *)calloc(lineCount,sizeof(struct line_t)))==NULL){ + std::cout<<"Failed to allocate memory!"<<std::endl; + abort(); + } + line[0].start=(rand()%100)/100.0f-1; // lazy + for(i=1;i<lineCount;i++){ + line[i].start=line[i-1].start+(float)((rand()%20)-10)/1000.0f; + } +} +void World::draw(void){ + unsigned int i; + glBegin(GL_QUADS); + for(i=0;i<lineCount;i++){ + glColor3ub(0,255,0); + glVertex2f((HLINE*i)-1 ,line[i].start); + glVertex2f((HLINE*i)-1+HLINE,line[i].start); + glVertex2f((HLINE*i)-1+HLINE,line[i].start-HLINE*2); + glVertex2f((HLINE*i)-1 ,line[i].start-HLINE*2); + glColor3ub(150,100,50); + glVertex2f((HLINE*i)-1 ,line[i].start-HLINE*2); + glVertex2f((HLINE*i)-1+HLINE,line[i].start-HLINE*2); + glVertex2f((HLINE*i)-1+HLINE,-1); + glVertex2f((HLINE*i)-1 ,-1); + } + glEnd(); +} +======= +#include <World.h> + +World::World(float width){ + unsigned int i; + double f; + lineCount=width/HLINE+1; + if((line=(struct line_t *)calloc(lineCount,sizeof(struct line_t)))==NULL){ + std::cout<<"Failed to allocate memory!"<<std::endl; + abort(); + } + line[0].start=(rand()%100)/100.0f-0.8f; // lazy + if(line[0].start>-0.5f)line[0].start=-0.7f; + for(i=10;i<lineCount;i+=10){ + line[i].start=((double)(rand()%40+200))/1000.0f-1; + } + for(i=0;i<lineCount;i++){ + if(!(i%10)||!i){ + f=line[i+10].start-line[i].start; + f/=10.0f; + }else{ + line[i].start=line[i-1].start+f; + } + } +} +void World::draw(void){ + unsigned int i; + glBegin(GL_QUADS); + for(i=0;i<lineCount;i++){ + glColor3ub(0,255,0); + glVertex2f((HLINE*i)-1 ,line[i].start); + glVertex2f((HLINE*i)-1+HLINE,line[i].start); + glVertex2f((HLINE*i)-1+HLINE,line[i].start-HLINE*2); + glVertex2f((HLINE*i)-1 ,line[i].start-HLINE*2); + glColor3ub(150,100,50); + glVertex2f((HLINE*i)-1 ,line[i].start-HLINE*2); + glVertex2f((HLINE*i)-1+HLINE,line[i].start-HLINE*2); + glVertex2f((HLINE*i)-1+HLINE,-1); + glVertex2f((HLINE*i)-1 ,-1); + } + glEnd(); +} +void World::detect(vec2 *v,const float width){ + unsigned int i; + for(i=0;i<lineCount;i++){ + if(v->y<line[i].start){ + if(v->x>(HLINE*i)-1&&v->x<(HLINE*i)-1+HLINE){ + v->x=(HLINE*i)-1+HLINE; + }else if(v->x+width>(HLINE*i)-1&&v->x+width<(HLINE*i)-1+HLINE){ + v->x=(HLINE*i)-1-width; + }else{ + v->y=line[i].start; + } + }else if(v->y>line[i].start+HLINE/2){ + v->y-=HLINE/4; + } + } +} +>>>>>>> origin/master diff --git a/src/entities.cpp b/src/entities.cpp index 5e86b72..1b8861a 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -1,16 +1,39 @@ -#include <entities.h>
-
-void Entities::spawn(float x, float y){
- loc.x = x;
- loc.y = y;
-
-}
-
-Player::Player(){
- width = 24;
- height = 42;
- speed = 1;
- type = 0;
-}
-
+<<<<<<< HEAD +#include <entities.h> + +void Entities::spawn(float x, float y){ + loc.x = x; + loc.y = y; + loci.x = loc.x; + loci.y = loc.y; + vel.x = 0; + vel.y = 0; + velg.x = 0; + velg.y = 0; +} + +Player::Player(){ + width = HLINE * 6; + height = HLINE * 16; + speed = 1; + type = 0; +} + +======= +#include <entities.h> + +void Entities::spawn(float x, float y){ + loc.x = x; + loc.y = y; + +} + +Player::Player(){ + width = 24; + height = 42; + speed = 1; + type = 0; +} + +>>>>>>> origin/master Player::~Player(){}
\ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index b04cb59..e5c2339 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,98 +1,241 @@ -#include <common.h>
-#include <ctime>
-
-SDL_Window *window = NULL;
-SDL_Surface *renderSurface = NULL;
-SDL_GLContext mainGLContext = NULL;
-
-bool gameRunning = true;
-
-UIClass ui;
-Entities *entit1;
-Player player;
-
-int main(int argc,char **argv){
- // Initialize SDL
- if(!SDL_Init(SDL_INIT_VIDEO)){
- atexit(SDL_Quit);
- }else{
- std::cout << "SDL was not able to initialize! Error: " << SDL_GetError() << std::endl;
- return -1;
- }
- // Initialize SDL_image
- if((IMG_Init(IMG_INIT_PNG|IMG_INIT_JPG)&(IMG_INIT_PNG|IMG_INIT_JPG))){
- atexit(IMG_Quit);
- }else{
- std::cout<<"Could not init image libraries!\n"<<std::endl;
- return -1;
- }
- // Create the window
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
- window = SDL_CreateWindow("Independent Study v.0.1 alpha", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL
- #ifdef FULLSCREEN
- | SDL_WINDOW_FULLSCREEN
- #endif // FULLSCREEN
- );
- if(!window){
- std::cout << "The window failed to generate! Error: " << SDL_GetError() << std::endl;
- return -1;
- }
- // Set OpenGL context
- if((mainGLContext = SDL_GL_CreateContext(window))==NULL){
- std::cout << "The OpenGL context failed to initialize! Error: " << SDL_GetError() << std::endl;
- }
- // Setup rand() and OpenGL
- srand(time(NULL));
- glClearColor(.3,.5,.8,0);
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
-
- /**************************
- **** GAMELOOP ****
- **************************/
-
- entit1 = &player;
- entit1->spawn(0,0);
-
- World *w=new World(2);
-
- while(gameRunning){
- ui.handleEvents(); // Handle events
- //a matrix is a blank canvas for the computer to draw on, the matrices are stored in a "stack"
- //GL_PROJECTION has 2 matrices
- //GL_MODELVIEW has 32 matrices
- glMatrixMode(GL_PROJECTION); //set the matrix mode as projection so we can set the ortho size and the camera settings later on
- glPushMatrix(); //push the matrix to the top of the matrix stack
- glLoadIdentity(); //replace the entire matrix stack with the updated GL_PROJECTION mode
- glOrtho(-1,1,-1,1,-1,1); //set the the size of the screen
- glMatrixMode(GL_MODELVIEW); //set the matrix to modelview so we can draw objects
- glPushMatrix(); //push the matrix to the top of the matrix stack
- glLoadIdentity(); //replace the entire matrix stack with the updated GL_MODELVIEW mode
- glPushMatrix(); //basically here we put a blank canvas (new matrix) on the screen to draw on
- glClear(GL_COLOR_BUFFER_BIT); //clear the matrix on the top of the stack
-
- /**************************
- **** RENDER STUFF HERE ****
- **************************/
-
- w->draw();
- glColor3ub(0,0,0);
- glRectf(player.loc.x, player.loc.y, player.loc.x + player.width, player.loc.y + player.height);
-
- /**************************
- **** CLOSE THE LOOP ****
- **************************/
-
- glPopMatrix(); //take the matrix(s) off the stack to pass them to the renderer
- SDL_GL_SwapWindow(window); //give the stack to SDL to render it
- }
-
- /**************************
- **** CLOSE PROGRAM ****
- **************************/
-
- //closes the window and frees resources
- SDL_GL_DeleteContext(mainGLContext);
- SDL_DestroyWindow(window);
- return 0;
-}
+<<<<<<< HEAD +#include <common.h> +#include <ctime> + +SDL_Window *window = NULL; +SDL_Surface *renderSurface = NULL; +SDL_GLContext mainGLContext = NULL; + +bool gameRunning = true; + +const float ticksPerSec = 20; +const float msecPerTick = 1000 / ticksPerSec; +int prevTime = GetTickCount(); +int currentTime = 0; +float deltaTime = 0; + +Entities *entit1; +Player player; +UIClass ui; + +float interpolate(float goal, float current, float dt){ + float difference = goal - current; + if(difference > dt){ + return current + dt;} + if(difference < dt){ + return current - dt;} + return goal; +} + + +World *w=new World(2); +void render(); + +int main(int argc,char **argv){ + //runs start-up procedures + if(!SDL_Init(SDL_INIT_VIDEO)){ + atexit(SDL_Quit); + if(!(IMG_Init(IMG_INIT_PNG|IMG_INIT_JPG)&(IMG_INIT_PNG|IMG_INIT_JPG))){ + std::cout<<"Could not init image libraries!\n"<<std::endl; + return -1; + } + atexit(IMG_Quit); + //Turn on double Buffering + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + //create the window + window = SDL_CreateWindow("Independent Study v.0.1 alpha", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL + #ifdef FULLSCREEN + | SDL_WINDOW_FULLSCREEN + #endif // FULLSCREEN + ); + if(window){ + //set OpenGL context + mainGLContext = SDL_GL_CreateContext(window); + if(mainGLContext == NULL){ + std::cout << "The OpenGL context failed to initialize! Error: " << SDL_GetError() << std::endl; + } + }else{ + std::cout << "The window failed to generate! Error: " << SDL_GetError() << std::endl; + return -1; + } + }else{ + std::cout << "SDL was not able to initialize! Error: " << SDL_GetError() << std::endl; + return -1; + } + srand(time(NULL)); + glClearColor(.3,.5,.8,0); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + + /************************** + **** GAMELOOP **** + **************************/ + + entit1 = &player; + entit1->spawn(4, 0); + + while(gameRunning){ + prevTime = currentTime; + currentTime = GetTickCount(); + deltaTime = currentTime - prevTime; + + if(prevTime + msecPerTick <= GetTickCount()){ //HANDLE ALL LOGIC STUFF HERE + ui.handleEvents(); // Handle events + + player.vel.x = 0; + + std::cout << player.vel.x << std::endl; + std::cout << player.velg.y << std::endl; + std::cout << "d:" << deltaTime << std::endl; + + prevTime = GetTickCount(); + } + //DO ALL RENDERING HERE + player.vel.x = interpolate(player.velg.x, player.vel.x, deltaTime) * .001; + if(player.vel.x > .05) player.vel.x = .05; + if(player.vel.x < -.05) player.vel.x = -.05; + player.loci.x += player.vel.x; + + render(); + + } + + /************************** + **** CLOSE PROGRAM **** + **************************/ + + //closes the window and frees resources + SDL_GL_DeleteContext(mainGLContext); + SDL_DestroyWindow(window); + return 0; +} + +void render(){ + //a matrix is a blank canvas for the computer to draw on, the matrices are stored in a "stack" + //GL_PROJECTION has 2 matrices + //GL_MODELVIEW has 32 matrices + glMatrixMode(GL_PROJECTION); //set the matrix mode as projection so we can set the ortho size and the camera settings later on + glPushMatrix(); //push the matrix to the top of the matrix stack + glLoadIdentity(); //replace the entire matrix stack with the updated GL_PROJECTION mode + glOrtho(-1 + player.loci.x, 1 + player.loci.x , -1, 1, -1,1); //set the the size of the screen + glMatrixMode(GL_MODELVIEW); //set the matrix to modelview so we can draw objects + glPushMatrix(); //push the matrix to the top of the matrix stack + glLoadIdentity(); //replace the entire matrix stack with the updated GL_MODELVIEW mode + glPushMatrix(); //basically here we put a blank canvas (new matrix) on the screen to draw on + glClear(GL_COLOR_BUFFER_BIT); //clear the matrix on the top of the stack + + /************************** + **** RENDER STUFF HERE **** + **************************/ + + w->draw(); + glColor3ub(0,0,0); + glRectf(player.loci.x, player.loci.y, player.loci.x + player.width, player.loci.y + player.height); + + /************************** + **** CLOSE THE LOOP **** + **************************/ + + glPopMatrix(); //take the matrix(s) off the stack to pass them to the renderer + SDL_GL_SwapWindow(window); //give the stack to SDL to render it +} +======= +#include <common.h> +#include <ctime> + +SDL_Window *window = NULL; +SDL_Surface *renderSurface = NULL; +SDL_GLContext mainGLContext = NULL; + +bool gameRunning = true; + +UIClass ui; +Entities *entit1; +Player player; + +int main(int argc,char **argv){ + // Initialize SDL + if(!SDL_Init(SDL_INIT_VIDEO)){ + atexit(SDL_Quit); + }else{ + std::cout << "SDL was not able to initialize! Error: " << SDL_GetError() << std::endl; + return -1; + } + // Initialize SDL_image + if((IMG_Init(IMG_INIT_PNG|IMG_INIT_JPG)&(IMG_INIT_PNG|IMG_INIT_JPG))){ + atexit(IMG_Quit); + }else{ + std::cout<<"Could not init image libraries!\n"<<std::endl; + return -1; + } + // Create the window + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + window = SDL_CreateWindow("Independent Study v.0.1 alpha", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL + #ifdef FULLSCREEN + | SDL_WINDOW_FULLSCREEN + #endif // FULLSCREEN + ); + if(!window){ + std::cout << "The window failed to generate! Error: " << SDL_GetError() << std::endl; + return -1; + } + // Set OpenGL context + if((mainGLContext = SDL_GL_CreateContext(window))==NULL){ + std::cout << "The OpenGL context failed to initialize! Error: " << SDL_GetError() << std::endl; + } + // Setup rand() and OpenGL + srand(time(NULL)); + glClearColor(.3,.5,.8,0); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + + /************************** + **** GAMELOOP **** + **************************/ + + entit1 = &player; + entit1->spawn(0,0); + + World *w=new World(2); + + while(gameRunning){ + ui.handleEvents(); // Handle events + //a matrix is a blank canvas for the computer to draw on, the matrices are stored in a "stack" + //GL_PROJECTION has 2 matrices + //GL_MODELVIEW has 32 matrices + glMatrixMode(GL_PROJECTION); //set the matrix mode as projection so we can set the ortho size and the camera settings later on + glPushMatrix(); //push the matrix to the top of the matrix stack + glLoadIdentity(); //replace the entire matrix stack with the updated GL_PROJECTION mode + glOrtho(-1,1,-1,1,-1,1); //set the the size of the screen + glMatrixMode(GL_MODELVIEW); //set the matrix to modelview so we can draw objects + glPushMatrix(); //push the matrix to the top of the matrix stack + glLoadIdentity(); //replace the entire matrix stack with the updated GL_MODELVIEW mode + glPushMatrix(); //basically here we put a blank canvas (new matrix) on the screen to draw on + glClear(GL_COLOR_BUFFER_BIT); //clear the matrix on the top of the stack + + /************************** + **** RENDER STUFF HERE **** + **************************/ + + w->draw(); + glColor3ub(0,0,0); + glRectf(player.loc.x, player.loc.y, player.loc.x + player.width, player.loc.y + player.height); + + /************************** + **** CLOSE THE LOOP **** + **************************/ + + glPopMatrix(); //take the matrix(s) off the stack to pass them to the renderer + SDL_GL_SwapWindow(window); //give the stack to SDL to render it + } + + /************************** + **** CLOSE PROGRAM **** + **************************/ + + //closes the window and frees resources + SDL_GL_DeleteContext(mainGLContext); + SDL_DestroyWindow(window); + return 0; +} +>>>>>>> origin/master |