]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Worked on the new texture library
authordrumsetmonkey <abelleisle@roadrunner.com>
Fri, 23 Oct 2015 12:44:55 +0000 (08:44 -0400)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Fri, 23 Oct 2015 12:44:55 +0000 (08:44 -0400)
include/Texture.h
include/entities.h
main.cpp
src/Texture.cpp
src/entities.cpp
src/gameplay.cpp

index 45c8df1271f86713d4de55c231f126859fe9d46e..5a0834873ea488f942ad61aa0776728617fa2ad7 100644 (file)
@@ -12,10 +12,11 @@ public:
        Texturec(uint amt, ...);
        void bindNext();
        void bindPrev();
+       void bind(int);
 
        GLuint *image;
-private:
        int texState;
+private:
 
 };
 
index 43e744ece81dd2ece7556273dfaae458ff3b5b41..47f7f55b4eef3c49e1d41a51e97dab693715c45a 100644 (file)
@@ -94,7 +94,7 @@ public:
 };
 class Mob : public Entity{
 public:
-       Mob();
+       Mob(int);
        void wander(int, vec2*);
 };
 
index 373dbea80d0d0f7387708893523ec27dbb4378ab..5c80ebdc17c7bc67d7735a872142f3aa518a5ced 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -320,19 +320,18 @@ int main(int argc, char *argv[]){
        /*
         *      TODO - Initialize shaders n' stuff
        */
-
-       /*
        
+       /*
        GLuint fragShader;
-       GLuint shaderProgram;
+       GLuint shaderProgram;6da
 
        const GLchar *shaderSource = "shader.frag";
        GLint bufferln = GL_FALSE;
 
        shaderProgram = glCreateProgram();
        fragShader = glCreateShader(GL_FRAGMENT_SHADER);
-       
-       glShaderSource(fragShader, 1, &shaderSource, NULL);
+               
+       glShaderSource(fragShader, 1, shaderSource, NULL);
        glCompileShader(fragShader);
        glGetShaderiv(fragShader, GL_COMPILE_STATUS, &bufferln);
        
@@ -343,11 +342,9 @@ int main(int argc, char *argv[]){
        glAttachShader(shaderProgram, fragShader);
        glLinkProgram(shaderProgram);
        glValidateProgram(shaderProgram);
-
+       */
        //glEnable(GL_DEPTH_TEST);
        //glEnable(GL_MULTISAMPLE);
-       
-       */
 
        /*
         *      Open the names file containing potential names for NPCs and store it in the names file
@@ -595,7 +592,7 @@ void render(){
                
                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: %d\nG:%d\nRes: %ux%u\nE: %d\nPOS: (x)%+.2f\n     (y)%+.2f\nQc: %u\nTS:%d\n",
                                        fps,
                                        player->ground,
                                        SCREEN_WIDTH,                           // Window dimensions
@@ -603,7 +600,8 @@ void render(){
                                        entity.size(),                          // Size of entity array
                                        player->loc.x,                          // The player's x coordinate
                                        debugY,                                         // The player's y coordinate
-                                       player->qh.current.size()       // Active quest count
+                                       player->qh.current.size(),      // Active quest count
+                                       player->tex->texState
                                        );
                                        
        }
index 93a3792a7d470b81e81bcaedc4129e3eafde914d..0d677017829bd8e01ebe59042287fb4de9e4f099 100644 (file)
@@ -35,6 +35,15 @@ Texturec::Texturec(uint amt, ...){
        va_end(fNames);
 }
 
+void Texturec::bind(int bn){
+       texState = bn;
+       glBindTexture(GL_TEXTURE_2D, image[texState]);
+}
+
 void Texturec::bindNext(){
-       //glBindTexture(GL_TEXTURE_2D);
+       bind(++texState);
+}
+
+void Texturec::bindPrev(){
+       bind(--texState);
 }
\ No newline at end of file
index 6d2b58c8b29764c4a3258bdd848869372111c8ce..1f45e4092218cfab0f646524477eeb819f9c92a1 100644 (file)
@@ -37,7 +37,7 @@ Player::Player(){ //sets all of the player specific traits on object creation
        ground = false;
        near = true;
        inv = new Inventory(PLAYER_INV_SIZE);
-       tex = new Texturec(3, "assets/player.png", "assets/player1.png", "assets/player2.png");
+       tex = new Texturec(3, "assets/player1.png", "assets/player.png", "assets/player2.png");
 }
 
 NPC::NPC(){    //sets all of the NPC specific traits on object creation
@@ -61,16 +61,20 @@ Structures::Structures(){ //sets the structure type
        tex = new Texturec(1,"assets/house1.png");
 }
 
-Mob::Mob(){
+Mob::Mob(int sub){
        width = HLINE * 10;
        height = HLINE * 8;
        speed = 1;
        type = MOBT; //sets type to MOB
-       subtype = 1; //SKIRL
+       subtype = sub; //SKIRL
        alive = true;
        canMove = true;
        near = false;
-       tex = new Texturec(2, "assets/rabbit.png", "assets/rabbit.png1");
+       if(subtype == 1){//RABBIT
+               tex = new Texturec(2, "assets/rabbit.png", "assets/rabbit1.png");
+       }else if(subtype == 2){//BIRD
+               //add bird textures and bird things
+       }
        inv = new Inventory(NPC_INV_SIZE);
 }
 
@@ -102,43 +106,45 @@ void Entity::draw(void){          //draws the entities
                        if(up){
                                texState+=1;
                                if(texState==2)up=false;
+                               tex->bindNext();
                        }else if(!up){
                                texState-=1;
                                if(texState==0)up=true;
+                               tex->bindPrev();
                        }
                }
                if(ground == 0){
-                       glBindTexture(GL_TEXTURE_2D, tex->image[0]);
+                       tex->bind(0);
                }else if(vel.x != 0){
                        switch(texState){
                                case 0:
-                                       glBindTexture(GL_TEXTURE_2D,tex->image[1]);
+                                       tex->bind(0);
                                break;
                                case 1:
-                                       glBindTexture(GL_TEXTURE_2D,tex->image[0]);
+                                       tex->bind(1);
                                break;
                                case 2:
-                                       glBindTexture(GL_TEXTURE_2D,tex->image[2]);
+                                       tex->bind(2);
                                break;
                        }
                }
                else{
-                       glBindTexture(GL_TEXTURE_2D,tex->image[0]);
+                       tex->bind(1);
                }
        }else if(type == MOBT){
                switch(subtype){
                        case 1: //RABBIT
                                if(ground == 0){
-                                       glBindTexture(GL_TEXTURE_2D, tex->image[1]);
+                                       tex->bind(1);
                                }else if(ground == 1){
-                                       glBindTexture(GL_TEXTURE_2D, tex->image[0]);                                    
+                                       tex->bind(0);
                                }
                                break;
                        default:
                        break;
                }
        }else{
-               glBindTexture(GL_TEXTURE_2D,tex->image[0]);
+               tex->bind(0);
        }
        glColor3ub(255,255,255);
        glBegin(GL_QUADS);
index 3b9b8192ac69762f99850da61256275fe9a242d1..f9d2578b0803b04d6e3a34ddb9d0e64aff642b17 100644 (file)
@@ -51,8 +51,8 @@ void initEverything(void){
        iw->generate(200);
        build[0]->inside=iw;
 
-       entity.push_back(new Mob()); //create a new entity of NPC type
-       mob.push_back(Mob()); //create new NPC
+       entity.push_back(new Mob(1)); //create a new entity of NPC type
+       mob.push_back(Mob(1)); //create new NPC
        entity[entity.size()] = &mob[mob.size()-1]; //set the new entity to have the same traits as an NPC
        entity[entity.size()-1]->spawn(200,100); //sets the position of the villager around the village
        entity.pop_back();