]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
sword improvements, page threading
authorClyne Sullivan <tullivan99@gmail.com>
Tue, 5 Apr 2016 12:48:29 +0000 (08:48 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Tue, 5 Apr 2016 12:48:29 +0000 (08:48 -0400)
Changelog
include/entities.hpp
include/ui.hpp
main.cpp
src/config.cpp
src/entities.cpp
src/gameplay.cpp
src/inventory.cpp
src/ui.cpp
src/world.cpp

index 29e143d305c8bca2b4736ef6cceaa151c456bbe6..e5c65dec37010b08cda34a558697294b8ee5bc7d 100644 (file)
--- a/Changelog
+++ b/Changelog
        - removed unnecessary cout's
        - began actual storyline work?
        - began actual fighting work
+
+4/5/2016:
+=========
+
+       - worked on item handling stuffs
+       - swords can affect all entities, added knockback
+       - began work with threading pages/triggers
+       - added debug flag for settings.xml
+       - improved particle drawing
index 7c1a25408a5cafdc73f3642a2ae1a092a0adac24..655ecfd53fb328e6c9c8150b51343ca51fed01b7 100644 (file)
@@ -151,10 +151,10 @@ public:
 
        bool near;                              // Causes name to display
        bool canMove;                   // Enables movement
-       bool canJape;                   // Enables world leaving
        bool right,left;                // Direction faced by Entity
        bool alive;
        bool hit;
+       bool forcedMove;
        unsigned char ground;   // Shows how the Entity is grounded (if it is)
 
        /*
index 0ab76dee1e8ed04536db345c3e6c2872fe67aefb..0142f6f4af11006758596a011e857cff3eaa7533 100644 (file)
@@ -154,6 +154,7 @@ namespace ui {
        void merchantBox();
        void closeBox();
        void waitForDialog(void);
+       bool pageExists( void );
 
        void drawPage( std::string path );
        /*
index 4ec723f2d580342e925352b959e48fe0c1eaf190..a3728da99e857287e59fbd2181bc88e71245009a 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -695,18 +695,27 @@ void render() {
                                        getWorldWeatherStr( weather ).c_str()
                                        );
 
-               if(ui::posFlag){
+               if ( ui::posFlag ) {
                        glBegin(GL_LINES);
-                               glColor3ub(255,0,0);
+                               /*glColor3ub(255,0,0);
                                glVertex2i(0,0);
-                               glVertex2i(0,SCREEN_HEIGHT);
+                               glVertex2i(0,SCREEN_HEIGHT);*/
 
-                               glColor3ub(255,255,255);
+                               /*glColor3ub(255,255,255);
                                glVertex2i(player->loc.x + player->width/2,0);
                                glVertex2i(player->loc.x + player->width/2,SCREEN_HEIGHT);
+                               glVertex2i( offset.x - SCREEN_WIDTH / 2, player->loc.y + player->height / 2 );
+                               glVertex2i( offset.x + SCREEN_WIDTH / 2, player->loc.y + player->height / 2 );*/
+
+                               /*glVertex2i( -SCREEN_WIDTH / 2 + offset.x, player->loc.y );
+                               glVertex2i(  SCREEN_WIDTH / 2 + offset.x, player->loc.y );*/
+
+                               glColor3ub(100,100,255);
+                               for ( auto &e : currentWorld->entity ) {
+                                       glVertex2i( player->loc.x + player->width / 2, player->loc.y + player->height / 2 );
+                                       glVertex2i( e->loc.x + e->width / 2, e->loc.y + e->height / 2 );
+                               }
 
-                               glVertex2i(-SCREEN_WIDTH/2+offset.x,player->loc.y);
-                               glVertex2i(SCREEN_WIDTH/2+offset.x, player->loc.y);
                        glEnd();
                }
 
@@ -759,16 +768,18 @@ void logic(){
        if ( player->loc.y < 0 )
                gameRunning = false;
 
-       for ( auto &e : currentWorld->entity ) {
-               if ( player->inv->usingi ) {
+       if ( player->inv->usingi ) {
+               for ( auto &e : currentWorld->entity ) {
                        e->hit = false;
 
-                       std::cout << "bang" << std::endl;
-
                        if ( player->inv->usingi && !e->hit &&
                                 player->inv->detectCollision( { e->loc.x, e->loc.y }, { e->loc.x + e->width, e->loc.y + e->height} ) ) {
                                e->health -= 25;
                                e->hit = true;
+                               e->forcedMove = true;
+                               e->vel.x = 0.5f * (player->left ? -1 : 1);
+                               e->vel.y = 0.2f;
+                               break;
                                //for(int r = 0; r < (rand()%5);r++)
                                //      currentWorld->addParticle(rand()%HLINE*3 + n->loc.x - .05f,n->loc.y + n->height*.5, HLINE,HLINE, -(rand()%10)*.01,((rand()%4)*.001-.002), {(rand()%75+10)/100.0f,0,0}, 10000);
                                //if ( e->health <= 0 ) {
@@ -776,9 +787,9 @@ void logic(){
                                //      currentWorld->addParticle(rand()%HLINE*3 + n->loc.x - .05f,n->loc.y + n->height*.5, HLINE,HLINE, -(rand()%10)*.01,((rand()%10)*.01-.05), {(rand()%75)+10/100.0f,0,0}, 10000);
                        }
                }
+               player->inv->usingi = false;
        }
 
-
        /*
         *      Entity logic: This loop finds every entity that is alive and in the current world. It then
         *      basically runs their AI functions depending on what type of entity they are. For NPCs,
index 2ee13d45ab1beb543638b3425cf5672d7a0069b9..b8a483d39e8b3aa49332606e9f01d50f8a125bbc 100644 (file)
@@ -60,6 +60,10 @@ namespace config {
 
                ui::initFonts();
                ui::setFontFace(xml.FirstChildElement("font")->Attribute("path"));
+
+               if ( xml.FirstChildElement("debug") )
+                       ui::debug = ui::posFlag = true;
+
                config::update();
        }
 
index 4fd21fd568bc6797e18e3466cd5a54fd9d3eae5d..5470245a77d1cd6efb2c64c602aba4bd55b32691 100644 (file)
@@ -86,6 +86,7 @@ void Entity::spawn(float x, float y){ //spawns the entity you pass to it based o
        //canMove       = true;
        ground  = false;
        hit     = false;
+       forcedMove = false;
 
        ticksToUse = 0;
 
@@ -389,7 +390,12 @@ NOPE:
        glDisable(GL_TEXTURE_2D);
        glMatrixMode(GL_MODELVIEW);
        glPopMatrix();
-       if(near)ui::putStringCentered(loc.x+width/2,loc.y-ui::fontSize-HLINE/2,name);
+       if ( near )
+               ui::putStringCentered(loc.x+width/2,loc.y-ui::fontSize-HLINE/2,name);
+       if ( health != maxHealth ) {
+               glColor3ub(150,0,0); glRectf( loc.x, loc.y + height, loc.x + width, loc.y + height + HLINE * 2 );
+               glColor3ub(255,0,0); glRectf( loc.x, loc.y + height, loc.x + width * ( health / maxHealth ), loc.y + height + HLINE * 2 );
+       }
 }
 
 /**
@@ -401,6 +407,9 @@ wander( int timeRun )
 {
        static int direction;
 
+       if ( forcedMove )
+               return;
+
        if ( followee ) {
                if ( loc.x < followee->loc.x - 40 )
                        direction = 1;
@@ -473,6 +482,10 @@ void NPC::interact(){ //have the npc's interact back to the player
 
 void Merchant::wander(int timeRun){
        static int direction;
+
+       if ( forcedMove )
+               return;
+
        if ( ticksToUse == 0 ) {
                ticksToUse = timeRun;
 
@@ -600,6 +613,9 @@ void Mob::wander(int timeRun){
        static unsigned int heya=0,hi=0;
        static bool YAYA = false;
 
+       if ( forcedMove )
+               return;
+
        if ( followee ) {
                if ( loc.x < followee->loc.x - 40 )
                        direction = 1;
@@ -667,11 +683,12 @@ void Mob::wander(int timeRun){
                   ui::mouse.y > loc.y - width / 2       &&
                   ui::mouse.y < loc.y + width * 1.5 &&
                   SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT)){
-                       if(speed != 666){
+                       std::thread([this]{hey(this);}).detach();
+                       /*if(speed != 666){
                                speed = 666;
                                hey(this);
                                speed = 0;
-                       }
+                       }*/
                }
                break;
        default:
index 351cf0f155f71559a54157d3219cb638c1bdb4bc..ce514a4c28629ca832d61e4a24e3f2f8fb307d22 100644 (file)
@@ -219,16 +219,19 @@ CONT:
 }
 
 void commonPageFunc( Mob *callee ){
-       static bool lock = false;
-
-       if ( !lock ) {
-               lock = true;
+       //static bool lock = false;
 
+       /*if ( !lock ) {
+               lock = true;*/
+       if ( !ui::dialogBoxExists ) {
+               std::cout<<"begin\n";
                ui::drawPage( callee->heyid );
-               ui::waitForDialog();
+               while( ui::pageExists() );
+               std::cout<<"done\n";
+               //ui::waitForDialog();
 
-               callee->alive = false;
-               lock = false;
+               callee->health = 0;
+               //lock = false;
        }
 }
 
@@ -267,7 +270,7 @@ void commonTriggerFunc(Mob *callee){
 
                ui::toggleBlackFast();
 
-               callee->alive = false;
+               callee->health = 0;
                lock = false;
        }
 }
index 14ccfd0623a1baa13a1e8724cc019b65963b001c..521b6957d879a633a50bbe20c0ff46396086f654 100644 (file)
@@ -522,6 +522,8 @@ void Inventory::draw(void){
 }
 
 void itemDraw(Player *p,uint id){
+       static unsigned char inc = 0;
+
        itemLoc.y = p->loc.y+(p->height/3);
        itemLoc.x = p->left?p->loc.x:p->loc.x+p->width;
        glPushMatrix();
@@ -540,9 +542,16 @@ void itemDraw(Player *p,uint id){
                                p->inv->usingi = false;
                        }
                }
-       }else hangle = 0.0f;
+       } else
+               hangle = 0;
+
        if ( p->inv->usingi )
+               inc = 10;
+
+       if ( inc ) {
+               inc--;
                p->inv->useItem();
+       }
 
        glUseProgram(shaderProgram);
        glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);
@@ -564,25 +573,31 @@ void itemDraw(Player *p,uint id){
        glUseProgram(0);
 }
 
-int Inventory::useItem(void){
+int Inventory::useItem( void )
+{
        static bool up = false;
-       if(!invHover){
-
-               if(itemMap[items[sel].id]->type == "Sword"){
-
-                       if(swing){
-                               if(!player->left){
-                                       if(hangle==-15){up=true;Mix_PlayChannel(2,swordSwing,0);}
-                                       if(up)hangle-=.75*deltaTime;
-                                       if(hangle<=-90)hangle=-14;
-                               }else{
-                                       if(hangle==15){up=true;Mix_PlayChannel(2,swordSwing,0);}
-                                       if(up)hangle+=.75*deltaTime;
-                                       if(hangle>=90)hangle=14;
+
+       if ( !invHover ) {
+               if ( itemMap[items[sel].id]->type == "Sword" ) {
+                       if ( swing ) {
+                               int dir = player->left ? 1 : -1;
+
+                               if ( hangle == 15 * dir ) {
+                                       up = true;
+                                       Mix_PlayChannel( 2, swordSwing, 0 );
                                }
-                       }else if(!swing){
-                               swing=true;
-                               Mix_PlayChannel(2,swordSwing,0);
+
+                               if ( up )
+                                       hangle += 0.325f * dir * deltaTime;
+
+                               if ( !player->left ) {
+                                       if ( hangle <= -90 )
+                                               hangle = -14;
+                               } else if ( hangle >= 90 )
+                                               hangle = 14;
+                       } else {
+                               swing = true;
+                               Mix_PlayChannel( 2, swordSwing, 0 );
                        }
                }else if(itemMap[items[sel].id]->type == "Cooked Food"){
                        player->health += itemMap[items[sel].id]->attribValue;
@@ -601,7 +616,6 @@ bool Inventory::detectCollision(vec2 one, vec2 two){
        if(items.empty() || !items[sel].count)
                return false;
        if(itemMap[items[sel].id]->type == "Sword"){
-               std::cout<<"Collision???"<<std::endl;
                while(i<itemMap[items[sel].id]->height){
                        xc = itemLoc.x; yc = itemLoc.y;
                        xc += float(i) * cos((hangle+90)*PI/180);
index 69ff7e3581158a62c261fc148f9dcbf40bd47516..c9f91abd0d6ea6e31572d3d45b1703ea9f9af482 100644 (file)
@@ -632,6 +632,11 @@ namespace ui {
 
        void drawPage( std::string path ) {
                pageTex = Texture::loadTexture( path );
+               std::cout<<"page set\n";
+       }
+
+       bool pageExists( void ) {
+               return pageTex;
        }
 
        void draw(void){
@@ -641,6 +646,8 @@ namespace ui {
 
                if ( pageTex ) {
 
+                       std::cout<<"page draw\n";
+
                        glEnable( GL_TEXTURE_2D);
                        glBindTexture( GL_TEXTURE_2D, pageTex );
                        glBegin( GL_QUADS );
@@ -1204,6 +1211,7 @@ namespace ui {
                unsigned char i;
 
                if ( pageTex ) {
+                       std::cout<<"rip page\n";
                        glDeleteTextures( 1, &pageTex );
                        pageTex = 0;
                        return;
@@ -1280,7 +1288,12 @@ EXIT:
                                break;
 
                        case SDL_MOUSEBUTTONUP:
-                               if(ig) {
+
+                               // right click advances dialog
+                               if ( ( e.button.button & SDL_BUTTON_RIGHT ) && (dialogBoxExists | pageTex) )
+                                       dialogAdvance();
+
+                               if ( ig ) {
                                        ig->vel.x = (fr.x - mouse.x) / 50.0f;
                                        ig->vel.y = (fr.y - mouse.y) / 50.0f;
                                        ig = NULL;
@@ -1289,9 +1302,7 @@ EXIT:
 
                        // mouse clicks
                        case SDL_MOUSEBUTTONDOWN:
-                               // right click advances dialog
-                               if ( ( e.button.button & SDL_BUTTON_RIGHT ) && (dialogBoxExists | pageTex) )
-                                       dialogAdvance();
+
                                // left click uses item
                                if ( ( e.button.button & SDL_BUTTON_LEFT ) && !dialogBoxExists )
                                        player->inv->usingi = true;
@@ -1397,9 +1408,6 @@ EXIT:
                                                } else if( (tmp = currentWorld->goInsideStructure( player )) != currentWorld )
                                                                currentWorld = tmp;
                                                break;
-                                       case SDLK_i:
-                                               player->health -= 5;
-                                               break;
                                        case SDLK_LSHIFT:
                                                if(debug){
                                                        Mix_PlayChannel(1,sanic,-1);
@@ -1410,12 +1418,6 @@ EXIT:
                                        case SDLK_LCTRL:
                                                player->speed = .5;
                                                break;
-                                       case SDLK_F3:
-                                               debug ^= true;
-                                               break;
-                                       case SDLK_b:
-                                               if(debug)posFlag ^= true;
-                                               break;
                                        case SDLK_e:
                                                edown=true;
                                                if(!heyOhLetsGo){
@@ -1447,7 +1449,10 @@ EXIT:
                                        player->save();
                                        return;
                                }
-                               switch(SDL_KEY){
+                               switch ( SDL_KEY ) {
+                               case SDLK_F3:
+                                       debug ^= true;
+                                       break;
                                case SDLK_z:
                                        weather = WorldWeather::Snowy;
                                        break;
@@ -1497,23 +1502,15 @@ EXIT:
                                case SDLK_f:
                                        currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y},{1.0f,1.0f,1.0f});
                                        break;
-                               case SDLK_g:
-                                       //currentWorld->addStructure(LAMP_POST, player->loc.x, player->loc.y, NULL);
-                                       break;
-                               case SDLK_h:
-                                       //currentWorld->addStructure(TOWN_HALL, player->loc.x, player->loc.y, NULL);
-                                       break;
-                               case SDLK_j:
-                                       //currentWorld->addStructure(FOUNTAIN, player->loc.x, player->loc.y, NULL);
-                                       break;
-                               case SDLK_v:
-                                       //currentWorld->addVillage(player->loc.x, player->loc.y, 5, 10, 100, NULL);
-                                       break;
                                case SDLK_b:
-                                       currentWorld->addStructure(FIRE_PIT, player->loc.x, player->loc.y, "", "");
-                                       currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y},{1.0f,1.0f,1.0f});
-                                       currentWorld->light.back().follow(currentWorld->build.back());
-                                       currentWorld->light.back().makeFlame();
+                                       if ( debug )
+                                               posFlag ^= true;
+                                       else {
+                                               currentWorld->addStructure(FIRE_PIT, player->loc.x, player->loc.y, "", "");
+                                               currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y},{1.0f,1.0f,1.0f});
+                                               currentWorld->light.back().follow(currentWorld->build.back());
+                                               currentWorld->light.back().makeFlame();
+                                       }
                                        break;
                                case SDLK_F12:
                                        // Make the BYTE array, factor of 3 because it's RBG.
index e009f78ceb65ebd8b4d27b5484bbc9712e4ff1b9..f7e909672fd1f934ff44114615d2af03956e32b1 100644 (file)
@@ -718,7 +718,9 @@ singleDetect( Entity *e )
         *      Kill any dead entities.
        */
 
-       if ( !e->alive || e->health <= 0 ) {
+       if ( e->alive && e->health <= 0 ) {
+        e->alive = false;
+        e->health = 0;
                for ( i = 0; i < entity.size(); i++) {
                        if ( entity[i] == e ){
                                switch ( e->type ) {
@@ -776,6 +778,15 @@ singleDetect( Entity *e )
 
        // handle only living entities
        if ( e->alive ) {
+
+        // forced movement gravity
+        if ( e->forcedMove ) {
+            if ( e->vel.x > .0005 || e->vel.x < -.0005 )
+                e->vel.x *= .6;
+            else
+                e->forcedMove = false;
+        }
+
                if ( e->type == MOBT && Mobp(e)->subtype == MS_TRIGGER )
                        return;