diff options
author | drumsetmonkey <abelleisle@roadrunner.com> | 2015-10-13 00:22:57 -0400 |
---|---|---|
committer | drumsetmonkey <abelleisle@roadrunner.com> | 2015-10-13 00:22:57 -0400 |
commit | bd80f4081451e6ef25b763d5f74891075936fdd0 (patch) | |
tree | 1046b1355f2658243fd4be11aa0e19488ba2e8a3 | |
parent | 01a31f374b953b9d40548f8369289a8c6dc48b77 (diff) |
Documented things, updated DEBUG_printf()
-rw-r--r-- | include/common.h | 10 | ||||
-rw-r--r-- | include/entities.h | 10 | ||||
-rw-r--r-- | main.cpp | 15 | ||||
-rw-r--r-- | src/common.cpp | 31 | ||||
-rw-r--r-- | src/entities.cpp | 123 | ||||
-rw-r--r-- | src/ui.cpp | 2 |
6 files changed, 94 insertions, 97 deletions
diff --git a/include/common.h b/include/common.h index b57999d..7df147f 100644 --- a/include/common.h +++ b/include/common.h @@ -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 diff --git a/include/entities.h b/include/entities.h index 833ebe1..ecfe539 100644 --- a/include/entities.h +++ b/include/entities.h @@ -95,14 +95,4 @@ ENTITY TYPES | 2 MOBS |->1 Skirl - - - - - - - - - - **/
\ No newline at end of file @@ -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 diff --git a/src/common.cpp b/src/common.cpp index 7a51b4e..80488eb 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -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); diff --git a/src/entities.cpp b/src/entities.cpp index 565c369..a7bbff5 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -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 @@ -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){ |