]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
readded readme, fixed world handling w/ interpolation
authorClyne Sullivan <tullivan99@gmail.com>
Tue, 29 Sep 2015 12:09:06 +0000 (08:09 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Tue, 29 Sep 2015 12:09:06 +0000 (08:09 -0400)
include/common.h
src/entities.cpp
src/main.cpp
src/ui.cpp
src/world.cpp

index 1210adbaf42fbf48b9c30c313b25f930b81571c7..4f7ba4802b3511aee7dee57cdf01aa58204c246c 100644 (file)
 #include <SDL2/SDL_opengl.h>
 
 typedef struct { float x; float y; } vec2; 
-enum _TYPE {STRUCTURET = -1, PLAYERT = 0, NPCT = 1}; //these are the main types of entities
+
+enum _TYPE { //these are the main types of entities
+       STRUCTURET = -1,
+       PLAYERT    = 0,
+       NPCT       = 1
+};
 
 #include <entities.h>
 
@@ -27,11 +32,7 @@ enum _TYPE {STRUCTURET = -1, PLAYERT = 0, NPCT = 1}; //these are the main types
 template<typename T, size_t N>                                         //this fuction returns the size of any array
 int eAmt(T (&)[N]){return N;}
 
-//SDL VARIABLES
-extern SDL_Window    *window;
-extern SDL_Surface   *renderSurface;
-extern SDL_GLContext  mainGLContext;
-
 extern bool gameRunning;
+extern unsigned int deltaTime;
 
 #endif // COMMON_H
index a7737b3ebd33fc2f8af18245b96d3e8434ee2413..b33f2260493e755e092a8e8b248270e83b3576b3 100644 (file)
@@ -90,6 +90,7 @@ unsigned int Structures::spawn(_TYPE t, float x, float y){ //spawns a structure
                        entity[entity.size()] = &npc[npc.size()-1]; //set the new entity to have the same traits as an NPC
                        entity[entity.size()-1]->spawn(loc.x + (float)(i - 5),100); //sets the position of the villager around the village
                }
+               entity.pop_back();
                return entity.size();
        }
 }
index 2dc511281d3e47d25c2b1895a20991c080293b13..ef2a7bc70d206cc798cfede600c5526a467743dd 100644 (file)
@@ -13,10 +13,10 @@ SDL_Surface   *renderSurface = NULL;
 SDL_GLContext  mainGLContext = NULL;
 
 bool gameRunning = true;
-static unsigned int tickCount   = 0,
-                                       prevTime    = 0,
-                                       currentTime = 0,
-                                       deltaTime   = 0;
+unsigned int tickCount   = 0,
+                        prevTime    = 0,
+                        currentTime = 0,
+                        deltaTime   = 0;
 
 World *currentWorld=NULL;
 Player *player;
index ababe3efb37a8b775381a08fcf847fa142b40d59..13b898d7d5578ace6b4928e67e797ac5688a12aa 100644 (file)
@@ -157,8 +157,8 @@ namespace ui {
                                if(SDL_KEY==SDLK_w)currentWorld=currentWorld->goInsideStructure(player);
                                if(SDL_KEY==SDLK_SPACE){                                                                                        // Jump
                                        if(player->ground){
-                                               player->vel.y=.25;
-                                               //player->loc.y+=HL
+                                               player->vel.y=.5;
+                                               player->loc.y+=HLINE*2;
                                                player->ground=false;
                                        }
                                }
index 9f60a4aac76109006abf2523af9f4df34cf1b5a9..7d27e17033664273b5e21f5c2de5b0aa2006586a 100644 (file)
@@ -131,7 +131,7 @@ void World::singleDetect(Entity *e){
                        for(i=0;i<platform.size();i++){
                                if(((e->loc.x+e->width>platform[i].p1.x)&(e->loc.x+e->width<platform[i].p2.x))||
                                   ((e->loc.x<platform[i].p2.x)&(e->loc.x>platform[i].p1.x))){
-                                       if(e->loc.y>platform[i].p2.y-HLINE&&e->loc.y<platform[i].p2.y){
+                                       if(e->loc.y>platform[i].p1.y&&e->loc.y<platform[i].p2.y){
                                                if(e->vel.y<0){
                                                        e->vel.y=0;
                                                        e->loc.y=platform[i].p2.y;
@@ -141,7 +141,7 @@ void World::singleDetect(Entity *e){
                                        }
                                }
                        }
-                       e->vel.y-=.01;
+                       e->vel.y-=.001*deltaTime;
                }else{
                        e->vel.y=0;
                        e->ground=true;