aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/entities.cpp45
-rw-r--r--src/gameplay.cpp39
-rw-r--r--src/main.cpp82
-rw-r--r--src/ui.cpp6
4 files changed, 83 insertions, 89 deletions
diff --git a/src/entities.cpp b/src/entities.cpp
index bd0cc67..85ba538 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -21,50 +21,35 @@ void Entity::spawn(float x, float y){ //spawns the entity you pass to it based o
}
void Entity::draw(void){ //draws the entities
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D,texture);
- glBegin(GL_QUADS);
+ glPushMatrix();
if(type==NPCT){
if(gender == MALE){
glColor3ub(255,255,255);
- glTexCoord2i(0,1);glVertex2i(loc.x, loc.y);
- glTexCoord2i(1,1);glVertex2i(loc.x + width, loc.y);
- glTexCoord2i(1,0);glVertex2i(loc.x + width, loc.y + height);
- glTexCoord2i(0,0);glVertex2i(loc.x, loc.y + height);
}else if(gender == FEMALE){
glColor3ub(255,105,180);
- glTexCoord2i(0,1);glVertex2i(loc.x, loc.y);
- glTexCoord2i(1,1);glVertex2i(loc.x + width, loc.y);
- glTexCoord2i(1,0);glVertex2i(loc.x + width, loc.y + height);
- glTexCoord2i(0,0);glVertex2i(loc.x, loc.y + height);
}
- }
- if(type==PLAYERT){
- if(right==true){
- glTexCoord2i(0,1);glVertex2i(loc.x, loc.y);
- glTexCoord2i(1,1);glVertex2i(loc.x + width, loc.y);
- glTexCoord2i(1,0);glVertex2i(loc.x + width, loc.y + height);
- glTexCoord2i(0,0);glVertex2i(loc.x, loc.y + height);
- }if(left==true){
- glRotatef(180.0f, 0.0f, 0.0f, 1.0f);
- glScalef(-1.0f,1.0f,1.0f);
- glTexCoord2i(0,1);glVertex2i(loc.x, loc.y);
- glTexCoord2i(1,1);glVertex2i(loc.x + width, loc.y);
- glTexCoord2i(1,0);glVertex2i(loc.x + width, loc.y + height);
- glTexCoord2i(0,-0);glVertex2i(loc.x, loc.y + height);
+ if(NPCp(this)->aiFunc.size()){
+ glColor3ub(255,255,0);
+ glRectf(loc.x+width/3,loc.y+height,loc.x+width*2/3,loc.y+height+width/3);
}
-
- }else{
+ }
+ if(left){
+ glScalef(-1.0f,1.0f,1.0f);
+ glTranslatef(0-width-loc.x*2,0,0);
+ }
+ glMatrixMode(GL_TEXTURE);
+ glLoadIdentity();
+ glEnable(GL_TEXTURE_2D);
+ glBindTexture(GL_TEXTURE_2D,texture);
+ glBegin(GL_QUADS);
glTexCoord2i(0,1);glVertex2i(loc.x, loc.y);
glTexCoord2i(1,1);glVertex2i(loc.x + width, loc.y);
glTexCoord2i(1,0);glVertex2i(loc.x + width, loc.y + height);
glTexCoord2i(0,0);glVertex2i(loc.x, loc.y + height);
- }
glEnd();
glDisable(GL_TEXTURE_2D);
glMatrixMode(GL_MODELVIEW);
+ glPopMatrix();
if(near){
ui::setFontSize(14);
ui::putText(loc.x,loc.y-ui::fontSize-HLINE/2,"%s",name);
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index 9331828..b6b939a 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -9,21 +9,26 @@ extern std::vector<NPC>npc;
extern std::vector<Structures *>build;
extern Player *player;
-int giveTestQuest(NPC *speaker){
- ui::dialogBox(speaker->name,"Here, have a quest!");
- player->qh.assign("Test");
+extern void mainLoop(void);
+
+int compTestQuest(NPC *speaker){
+ ui::dialogBox(speaker->name,"Ooo, that's a nice quest you got there. Lemme finish that for you ;).");
+ player->qh.finish("Test",player);
return 0;
}
-int compTestQuest(NPC *speaker){
- if(player->qh.hasQuest("Test")){
- ui::dialogBox(speaker->name,"Ooo, that's a nice quest you got there. Lemme finish that for you ;).");
- player->qh.finish("Test",player);
- return 0;
- }else{
- ui::dialogBox(speaker->name,"You need to get a quest from %s first.",entity[1]->name);
- return 1;
+int giveTestQuest(NPC *speaker){
+ static bool done=false;
+ if(!done){
+ ui::dialogBox(speaker->name,"Here, have a quest!");
+ player->qh.assign("Test");
+ done=true;
}
+ /*while(ui::dialogBoxExists){
+ mainLoop();
+ }*/
+ NPCp(entity[2])->addAIFunc(compTestQuest);
+ return 0;
}
void initEverything(void){
@@ -51,18 +56,8 @@ void initEverything(void){
iw->generate(200);
build[0]->inside=iw;
+ NPCp(entity[1])->addAIFunc(giveTestQuest);
for(i=0;i<entity.size()+1;i++){
entity[i]->inWorld=test;
- switch(i){
- case 1:
- NPCp(entity[i])->addAIFunc(giveTestQuest);
- entity[i]->inv->addItem(TEST_ITEM,3);
- break;
- case 2:
- NPCp(entity[i])->addAIFunc(compTestQuest);
- break;
- default:
- break;
- }
}
}
diff --git a/src/main.cpp b/src/main.cpp
index 9b16085..fdb7d32 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -13,10 +13,6 @@ SDL_Surface *renderSurface = NULL;
SDL_GLContext mainGLContext = NULL;
bool gameRunning = true;
-unsigned int tickCount = 0,
- prevTime = 0,
- currentTime = 0,
- deltaTime = 0;
World *currentWorld=NULL;
Player *player;
@@ -35,6 +31,7 @@ extern void initEverything(void);
void logic();
void render();
+void mainLoop(void);
unsigned int millis(void){
std::chrono::system_clock::time_point now=std::chrono::system_clock::now();
@@ -113,20 +110,8 @@ int main(int argc, char *argv[]){
**** GAMELOOP ****
**************************/
- currentTime=millis();
while(gameRunning){
- prevTime = currentTime;
- currentTime = millis();
- deltaTime = currentTime - prevTime;
-
- if(prevTime + MSEC_PER_TICK >= millis()){
- logic();
- prevTime = millis();
- }
-
- player->loc.y+=player->vel.y*deltaTime;
- player->loc.x+=(player->vel.x*player->speed)*deltaTime;
- render();
+ mainLoop();
}
/**************************
@@ -140,6 +125,49 @@ int main(int argc, char *argv[]){
return 0;
}
+static unsigned int fps=0;
+static float debugY=0;
+
+unsigned int deltaTime=0;
+
+void mainLoop(void){
+ static unsigned int debugDiv=0;
+ static unsigned int tickCount = 0,
+ prevTime = 0,
+ currentTime = 0,
+ deltatime = 0;
+ unsigned int i;
+
+ if(!currentTime)currentTime=millis();
+ prevTime = currentTime;
+ currentTime = millis();
+ deltatime = currentTime - prevTime;
+ deltaTime = deltatime;
+
+ if(prevTime + MSEC_PER_TICK >= millis()){
+ logic();
+ prevTime = millis();
+ }
+
+ player->loc.y+=player->vel.y*deltatime;
+ player->loc.x+=(player->vel.x*player->speed)*deltatime;
+ for(int i=0;i<=entity.size();i++){
+ entity[i]->loc.x += entity[i]->vel.x * deltatime;
+ entity[i]->loc.y += entity[i]->vel.y * deltatime;
+ if(entity[i]->vel.x<0)entity[i]->left=true;
+ if(entity[i]->vel.x>0)entity[i]->left=false;
+ }
+
+ if(++debugDiv==20){
+ fps=1000/deltatime;
+ debugDiv=0;
+ }else if(!(debugDiv%10)){
+ debugY = player->loc.y;
+ }
+
+ render();
+}
+
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
@@ -168,25 +196,9 @@ void render(){
ui::draw(); // Draw any UI elements if they need to be
if(ui::debug){
- static unsigned int debugDiv=0;
- static int fps,d;
- static float rndy; // variable to round the player y-coord so it is easier to read
- if(++debugDiv==20){
- fps=1000/deltaTime;
- d=deltaTime;
- debugDiv=0;
- }else if(debugDiv%10==0){
- rndy = player->loc.y;
- }
ui::setFontSize(16);
- ui::putText(player->loc.x-SCREEN_WIDTH/2,SCREEN_HEIGHT-ui::fontSize,"FPS: %d\nD: %d G:%d\nRes: %ux%u\nE: %d\nPOS: (x)%+.2f\n (y)%+.2f\nQc: %u",
- fps,d,player->ground,SCREEN_WIDTH,SCREEN_HEIGHT,entity.size(),player->loc.x,rndy,player->qh.current.size());
- }
-
- for(int i=0;i<=entity.size();i++){
- //entity[i]->draw();
- entity[i]->loc.x += entity[i]->vel.x * deltaTime;
- entity[i]->loc.y += entity[i]->vel.y * deltaTime;
+ ui::putText(player->loc.x-SCREEN_WIDTH/2,SCREEN_HEIGHT-ui::fontSize,"FPS: %d\nG:%d\nRes: %ux%u\nE: %d\nPOS: (x)%+.2f\n (y)%+.2f\nQc: %u",
+ fps,player->ground,SCREEN_WIDTH,SCREEN_HEIGHT,entity.size(),player->loc.x,debugY,player->qh.current.size());
}
/**************************
diff --git a/src/ui.cpp b/src/ui.cpp
index 80ecc69..cd5de15 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -12,12 +12,12 @@ static FT_Library ftl; // Variables for the FreeType library and stuff
static FT_Face ftf;
static GLuint ftex;
-static bool dialogBoxExists=false;
static char *dialogBoxText;
namespace ui {
vec2 mouse;
bool debug=false;
+ bool dialogBoxExists=false;
unsigned int fontSize;
/*
* initFonts(), setFontFace(), and setFontSize() are pretty self-explanatory
@@ -184,6 +184,7 @@ namespace ui {
*/
case SDL_KEYDOWN:
if(SDL_KEY==SDLK_ESCAPE)gameRunning=false; // Exit the game with ESC
+ if(!dialogBoxExists){
if(SDL_KEY==SDLK_a){ // Move left
left=true;
player->vel.x=-.15;
@@ -212,8 +213,9 @@ namespace ui {
}
if(SDL_KEY==SDLK_i)currentWorld=currentWorld->goWorldBack(player); // Go back a layer if possible
if(SDL_KEY==SDLK_k)currentWorld=currentWorld->goWorldFront(player); // Go forward a layer if possible
+ if(SDL_KEY==SDLK_LSHIFT)player->speed = 3; // Sprint
+ }
if(SDL_KEY==SDLK_F3)debug^=true;
- if(SDL_KEY==SDLK_LSHIFT)player->speed = 3;
break;
/*
KEYUP