]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
gettin' there
authorClyne Sullivan <tullivan99@gmail.com>
Sat, 19 Sep 2015 01:25:04 +0000 (21:25 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Sat, 19 Sep 2015 01:25:04 +0000 (21:25 -0400)
Makefile
include/common.h
src/main.cpp

index 70f15c7394e732a9ee299f3f3ccea8a402c9483b..a78377ab2e930672cad49ebefefdba9cfa19bdd1 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
 FLAGS_LINUX = -lGL                 -lSDL2_image\r
 FLAGS_WIN32 = -lopengl32 -lmingw32 -lSDL2_Image\r
-FLAGS = -m32 -std=c++11 -Iinclude -lSDL2main -lSDL2\r
+FLAGS = -m32 -std=c++11 -Iinclude -Iinclude/freetype2 -lSDL2main -lSDL2 -lfreetype\r
 \r
 all:\r
        @g++ src/*.cpp -o main $(FLAGS_LINUX) $(FLAGS)\r
index 362b1f95044e4bcc69cbcf7427db3117ea5bab77..c147d888ea9cb65768ba892c70111019353284e2 100644 (file)
@@ -9,15 +9,27 @@
 #include <SDL2/SDL_image.h>
 #include <SDL2/SDL_opengl.h>
 
+typedef struct { float x; float y; } vec2;
+
+#include <entities.h>
+
 #define SCREEN_WIDTH  1280
 #define SCREEN_HEIGHT 720
 //#define FULLSCREEN
 
 #define HLINE 2
 
+#define initRand(s) srand(s)
+#define getRand()      rand()
+
+template<typename T, size_t N>
+int eAmt(T (&)[N]){return N;}
+
 //SDL VARIABLES
 extern SDL_Window    *window;
 extern SDL_Surface   *renderSurface;
 extern SDL_GLContext  mainGLContext;
 
+extern bool gameRunning;
+
 #endif // COMMON_H
index 8c78eabbd68c30b19fff4c0b55585130ec2de55b..5d578aafba0a191a55c32121547425b40bfe3754 100644 (file)
@@ -1,4 +1,7 @@
 #include <common.h>
+#include <world.h>
+#include <ui.h>
+#include <entities.h>
 #include <cstdio>
 #include <chrono>
 
@@ -8,6 +11,9 @@ SDL_GLContext  mainGLContext = NULL;
 
 bool gameRunning = true;
 
+World *currentWorld=NULL;
+Player *player;
+
 void logic();
 void render();
 
@@ -17,20 +23,21 @@ unsigned int millis(void){
 }
 
 int main(int argc, char *argv[]){
-       //runs start-up procedures
+       // Initialize SDL
     if(SDL_Init(SDL_INIT_VIDEO)){
                std::cout << "SDL was not able to initialize! Error: " << SDL_GetError() << std::endl;
                return -1;
        }
     atexit(SDL_Quit);
+    // Initialize SDL_image
     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
+       // Turn on double buffering
     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
-    //create the window
+    // Create the window
     window = SDL_CreateWindow("Independent Study v.0.2 alpha", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL
                               #ifdef FULLSCREEN
                               | SDL_WINDOW_FULLSCREEN
@@ -48,6 +55,11 @@ int main(int argc, char *argv[]){
         return -1;
     }
 
+       ui::initFonts();
+       ui::setFontFace("ttf/VCR_OSD_MONO_1.001.ttf");
+       ui::setFontSize(16);
+       initRand(millis()); // fix
+
        glViewport(0,0,SCREEN_WIDTH, SCREEN_HEIGHT);
        glClearColor(.3,.5,.8,0);
        glEnable(GL_BLEND);
@@ -58,6 +70,11 @@ int main(int argc, char *argv[]){
        ****     GAMELOOP      ****
        **************************/
 
+       World *test=new World(SCREEN_WIDTH/2);
+       currentWorld=test;
+       player=new Player();
+       player->spawn(0,100);
+
        while(gameRunning){
                render();
                logic();
@@ -80,7 +97,7 @@ void render(){
        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(0,SCREEN_WIDTH,0,SCREEN_HEIGHT,-1,1);
+       glOrtho(player->loc.x-SCREEN_WIDTH/2,player->loc.x+SCREEN_WIDTH/2,0,SCREEN_HEIGHT,-1,1);
        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
@@ -91,6 +108,10 @@ void render(){
        **** RENDER STUFF HERE ****
        **************************/
 
+       currentWorld->draw(&player->loc);
+       player->draw();
+       //ui::putString(0,0,"Hello");
+
        /**************************
        ****  CLOSE THE LOOP   ****
        **************************/
@@ -100,17 +121,9 @@ void render(){
 }
 
 void logic(){
-       SDL_Event e;
-       while(SDL_PollEvent(&e)){
-               switch(e.type){
-               case SDL_QUIT:
-                       gameRunning=false;
-                       break;
-               case SDL_KEYDOWN:
-                       if(e.key.keysym.sym==SDLK_ESCAPE)gameRunning=false;
-                       break;
-               default:
-                       break;
-               }
-       }
+       ui::handleEvents();
+       currentWorld->detect(&player->loc,&player->vel,player->width);
+       player->loc.y+=player->vel.y;
+       player->loc.x+=player->vel.x;
+       std::cout<<"("<<player->loc.x<<","<<player->loc.y<<")"<<std::endl;
 }