]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Documented things, updated DEBUG_printf()
authordrumsetmonkey <abelleisle@roadrunner.com>
Tue, 13 Oct 2015 04:22:57 +0000 (00:22 -0400)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Tue, 13 Oct 2015 04:22:57 +0000 (00:22 -0400)
include/common.h
include/entities.h
main.cpp
src/common.cpp
src/entities.cpp
src/ui.cpp

index b57999dab17f325898a887c98bd2fda616a4e3ed..7df147f0b99403ad124cbf28b8d2487355e91d54 100644 (file)
@@ -24,14 +24,14 @@ enum _TYPE { //these are the main types of entities
 enum GENDER{
        MALE,
        FEMALE,
-       NONE
+       NONE 
 };
 
 #include <Quest.h>
 #include <entities.h>
 
-#define SCREEN_WIDTH  640
-#define SCREEN_HEIGHT 480
+#define SCREEN_WIDTH  1280
+#define SCREEN_HEIGHT 720
 //#define FULLSCREEN
 
 #define HLINE 3                                                                //base unit of the world
@@ -53,6 +53,8 @@ extern Mix_Music *music;
 extern Mix_Chunk *horn;
 
 GLuint loadTexture(const char *fileName);
-void   DEBUG_printf(const char *s,...);
+void DEBUG_prints(const char* file, int line, const char *s,...);
+
+#define DEBUG_printf( message, ...) DEBUG_prints(__FILE__, __LINE__, message, __VA_ARGS__) //IF THERE IS NO VA_ARGS AT THE END OF A CALL, SUBSTITUTE IT WITH [ NULL ]
 
 #endif // COMMON_H
index 833ebe1cb7676ab5a946b37eb44ab231bb2f6b9c..ecfe539285e0993287f43e239188badf0be7a463 100644 (file)
@@ -95,14 +95,4 @@ ENTITY TYPES
 |
 2 MOBS
 |->1 Skirl
-
-
-
-
-
-
-
-
-
-
 **/
\ No newline at end of file
index a220e2c401a522d62899ac76aa439024137342d1..145df6e006532ff5d423d2775cf5435a69a34ef7 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -107,6 +107,7 @@ int main(int argc, char *argv[]){
        if( music == NULL ){
                printf( "Failed to load beat music! SDL_mixer Error: %s\n", Mix_GetError() );
        }
+       Mix_VolumeMusic(15);
        Mix_PlayMusic( music, -1 );
        
        bgImage=loadTexture("assets/bg.png");
@@ -234,24 +235,28 @@ void render(){
 void logic(){
        ui::handleEvents();
        currentWorld->detect(player);
+        //loops through whole entity stack
        for(int i=0;i<=entity.size();i++){
+                //only loops through entities that are alive
                if(entity[i]->alive){
+                        //only loops through entities with type NPCT
                        if(entity[i]->type == NPCT){
-                               entity[i]->wander((rand()%120 + 30), &entity[i]->vel);
+                               entity[i]->wander((rand()%120 + 30), &entity[i]->vel); //makes the villager wander
+                               //makes sure the entity is close to the player, and the mouse cursor is over the NPC
                                if( pow((entity[i]->loc.x - player->loc.x),2) + pow((entity[i]->loc.y - player->loc.y),2) <= pow(40*HLINE,2)){
                                        if(mx >= entity[i]->loc.x && mx <= entity[i]->loc.x + entity[i]->width && my >= entity[i]->loc.y && my <= entity[i]->loc.y + entity[i]->width){
-                                               entity[i]->near=true;
+                                               entity[i]->near=true; //sets near to true so we can toggle names later
                                                if(SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(SDL_BUTTON_RIGHT)){
-                                                       entity[i]->interact();
+                                                       entity[i]->interact(); //interacts with the NPCS
                                                        //std::cout <<"["<<i<<"] -> "<< entity[i]->name << ", " << (std::string)(entity[i]->gender == MALE ? "Male" : "Female") << std::endl;
                                                        //Mix_PlayChannel( -1, horn, 0);
                                                }
                                        }else entity[i]->near=false;
                                }
                        }if(entity[i]->type == MOBT){
-                               entity[i]->wander(90,&entity[i]->vel);
+                               entity[i]->wander((rand()%240 + 15),&entity[i]->vel);
                        }
                }
        }
        loops++;
-}
+}
\ No newline at end of file
index 7a51b4e2c46932759293f2a3eee805272909b96e..80488eb30c87913e61d8b049f2adf306d04316f6 100644 (file)
@@ -4,32 +4,29 @@ GLuint loadTexture(const char *fileName){
        SDL_Surface *image = IMG_Load(fileName);
 
        if(!image)return 0;
+       #ifdef DEBUG
+               DEBUG_printf("Loaded image file: %s\n", fileName);
+       #endif // DEBUG
+       unsigned object = 0; //creates a new unsigned variable for the texture
 
-       //SDL_DisplayFormatAlpha(image);
+       glGenTextures(1, &object); //turns "object" into a texture
+       glBindTexture(GL_TEXTURE_2D, object); //binds "object" to the top of the stack
 
-       unsigned object(0);
+       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //sets the "min" filter
+       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //the the "max" filter of the stack
 
-       glGenTextures(1, &object);
+       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); //Wrap the texture to the matrix
+       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); //Wrap the texutre to the matrix
 
-       glBindTexture(GL_TEXTURE_2D, object);
-
-       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
-       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-
-       glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image->w, image->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels);
-
-       //Free surface
-       SDL_FreeSurface(image);
+       glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image->w, image->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels); //sets the texture to the image file loaded above
 
+       SDL_FreeSurface(image); //Free surface
        return object;
 }
 
-void DEBUG_printf(const char *s,...){
+void DEBUG_prints(const char* file, int line, const char *s,...){
        va_list args;
-       printf("%s:%u: ",__FILE__,__LINE__);
+       printf("%s:%d: ",file,line);
        va_start(args,s);
        vprintf(s,args);
        va_end(args);
index 565c369e023c818829c7a83e9e15f9ca1687e618..a7bbff5694a31787c0584cbddf4799c8dd3a3123 100644 (file)
@@ -20,6 +20,61 @@ void Entity::spawn(float x, float y){        //spawns the entity you pass to it based o
        getName();
 }
 
+Player::Player(){ //sets all of the player specific traits on object creation
+       width = HLINE * 10;
+       height = HLINE * 16;
+       speed = 1;
+       type = PLAYERT; //set type to player
+       subtype = 5;
+       alive = true;
+       ground = false;
+       near = true;
+       texture[0] = loadTexture("assets/player.png");
+       texture[1] = loadTexture("assets/player1.png");
+       texture[2] = loadTexture("assets/player2.png");
+       inv = new Inventory(PLAYER_INV_SIZE);
+}
+
+NPC::NPC(){    //sets all of the NPC specific traits on object creation
+       width = HLINE * 10;
+       height = HLINE * 16;
+       speed = 1;
+       type = NPCT; //sets type to npc
+       subtype = 0;
+       alive = true;
+       canMove = true;
+       near = false;
+       texture[0] = loadTexture("assets/NPC.png");
+       texture[1] = 0;
+       texture[2] = 0;
+       inv = new Inventory(NPC_INV_SIZE);
+}
+
+Structures::Structures(){ //sets the structure type
+       type = STRUCTURET;
+       speed = 0;
+       alive = true;
+       near = false;
+       texture[0] = loadTexture("assets/house1.png");
+       texture[1] = 0;
+       texture[2] = 0;
+}
+
+Mob::Mob(){
+       width = HLINE * 10;
+       height = HLINE * 8;
+       speed = 1;
+       type = MOBT; //sets type to MOB
+       subtype = 1; //SKIRL
+       alive = true;
+       canMove = true;
+       near = false;
+       texture[0] = loadTexture("assets/NPC.png");
+       texture[1] = 0;
+       texture[2] = 0;
+       inv = new Inventory(NPC_INV_SIZE);
+}
+
 void Entity::draw(void){               //draws the entities
        glPushMatrix();
        if(type==NPCT){
@@ -120,40 +175,10 @@ void Entity::getName(){
        free(bufs);
 }
 
-Player::Player(){ //sets all of the player specific traits on object creation
-       width = HLINE * 10;
-       height = HLINE * 16;
-       speed = 1;
-       type = PLAYERT; //set type to player
-       subtype = 5;
-       alive = true;
-       ground = false;
-       near = true;
-       texture[0] = loadTexture("assets/player.png");
-       texture[1] = loadTexture("assets/player1.png");
-       texture[2] = loadTexture("assets/player2.png");
-       inv = new Inventory(PLAYER_INV_SIZE);
-}
-
 void Player::interact(){ //the function that will cause the player to search for things to interact with
        
 }
 
-NPC::NPC(){    //sets all of the NPC specific traits on object creation
-       width = HLINE * 10;
-       height = HLINE * 16;
-       speed = 1;
-       type = NPCT; //sets type to npc
-       subtype = 0;
-       alive = true;
-       canMove = true;
-       near = false;
-       texture[0] = loadTexture("assets/NPC.png");
-       texture[1] = 0;
-       texture[2] = 0;
-       inv = new Inventory(NPC_INV_SIZE);
-}
-
 void NPC::wander(int timeRun, vec2 *v){ //this makes the entites wander about
        static int direction;   //variable to decide what direction the entity moves
        if(ticksToUse == 0){
@@ -161,6 +186,7 @@ void NPC::wander(int timeRun, vec2 *v){ //this makes the entites wander about
                v->x = .008*HLINE;      //sets the inital velocity of the entity
                direction = (getRand() % 3 - 1);        //sets the direction to either -1, 0, 1
                                                                                        //this lets the entity move left, right, or stay still
+               if(direction==0)ticksToUse*=2;
                v->x *= direction;      //changes the velocity based off of the direction
        }
        ticksToUse--; //removes one off of the entities timer
@@ -182,16 +208,6 @@ void NPC::interact(){ //have the npc's interact back to the player
        }
 }
 
-Structures::Structures(){ //sets the structure type
-       type = STRUCTURET;
-       speed = 0;
-       alive = true;
-       near = false;
-       texture[0] = loadTexture("assets/house1.png");
-       texture[1] = 0;
-       texture[2] = 0;
-}
-
 unsigned int Structures::spawn(_TYPE t, float x, float y){ //spawns a structure based off of type and coords
        loc.x = x;
        loc.y = y;
@@ -215,36 +231,23 @@ unsigned int Structures::spawn(_TYPE t, float x, float y){ //spawns a structure
                return entity.size();
        }
 }
-Mob::Mob(){
-       width = HLINE * 10;
-       height = HLINE * 8;
-       speed = 1;
-       type = MOBT; //sets type to MOB
-       subtype = 1; //SKIRL
-       alive = true;
-       canMove = true;
-       near = false;
-       texture[0] = loadTexture("assets/NPC.png");
-       texture[1] = 0;
-       texture[2] = 0;
-       inv = new Inventory(NPC_INV_SIZE);
-}
 
 void Mob::wander(int timeRun, vec2* v){
        if(subtype == 1){ //SKIRL
                static int direction;   //variable to decide what direction the entity moves
                if(ticksToUse == 0){
                        ticksToUse = timeRun;
-                       if(ground && direction != 0){
-                               v->y=.08;
-                               loc.y+=HLINE*1;
-                               ground=false;
-                               v->x = .008*HLINE;      //sets the inital velocity of the entity
-                       }
                        direction = (getRand() % 3 - 1);        //sets the direction to either -1, 0, 1
                                                                                                //this lets the entity move left, right, or stay still
+                       if(direction==0)ticksToUse/=2;
                        v->x *= direction;      //changes the velocity based off of the direction
                }
+               if(ground && direction != 0){
+                       v->y=.15;
+                       loc.y+=HLINE*.25;
+                       ground=false;
+                       v->x = (.07*HLINE)*direction;   //sets the inital velocity of the entity
+               }
                ticksToUse--; //removes one off of the entities timer
        }
 }
\ No newline at end of file
index 68601d80c09b195d506bcd4f22034e8369ba817b..25b792b6a47d2e3fa5edd25c31ce34b2a2a36770 100644 (file)
@@ -29,7 +29,7 @@ namespace ui {
                }
                fontSize=12; // to be safe
 #ifdef DEBUG
-               DEBUG_printf("Initialized FreeType2.\n");
+               DEBUG_printf("Initialized FreeType2.\n",NULL);
 #endif // DEBUG
        }
        void setFontFace(const char *ttf){