// // Acorn.cpp // // // Created by Matthew Pick on 12/7/14. // // #include "Acorn.h" #include #include #include #include using namespace std; const float EXPLODE_Y_RADIUS = .15; const float EXPLODE_X_RADIUS = .08; const int START_EXPLODE_COUNTER = 10; const float Y_TRANSLATE = .07; Acorn::Acorn(float xPos, float yPos, int tex, int acornExplodeTex){ centerX = xPos; centerY = yPos; acornTex = tex; explodeTex = acornExplodeTex; explode = false; dead = false; explodeCounter = START_EXPLODE_COUNTER; } void Acorn::translateAcorn(){ centerY += Y_TRANSLATE; // cout << "in translate " << centerY << endl; } bool Acorn::isDead(){ return dead; } void Acorn::draw(){ GLuint tex = -1; float xRad; float yRad; if (!explode){ xRad = X_RADIUS; yRad = Y_RADIUS; tex = acornTex; } else { // draw exploded if (explodeCounter == 0) dead = true; else explodeCounter--; xRad = EXPLODE_X_RADIUS; yRad = EXPLODE_Y_RADIUS; // xRad = X_RADIUS; // yRad = Y_RADIUS; tex = explodeTex; } glEnable(GL_TEXTURE_2D); glEnable(GL_ALPHA_TEST); glBindTexture(GL_TEXTURE_2D, tex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glColor4f(1, 1, 1, 1); glBegin(GL_QUADS); glTexCoord2d(0, 0); glVertex2f(centerX-xRad, centerY-yRad); glTexCoord2d(0,1); glVertex2f(centerX-xRad, centerY+yRad); glTexCoord2d(1,1); glVertex2f(centerX+xRad, centerY+yRad); glTexCoord2d(1,0); glVertex2f(centerX+xRad, centerY-yRad); glEnd(); glDisable(GL_TEXTURE_2D); glDisable(GL_ALPHA_TEST); if (!explode) translateAcorn(); }