diff --git a/appwindow.cpp b/appwindow.cpp index 87344a8..5ea50cb 100644 --- a/appwindow.cpp +++ b/appwindow.cpp @@ -29,6 +29,7 @@ AppWindow::AppWindow() m_menu_drawMode.items().push_back(MenuElem("_Texture 1", Gtk::AccelKey("t"), sigc::mem_fun(m_viewer, &Viewer::toggleTexture ) ) ); m_menu_drawMode.items().push_back(MenuElem("_Bump Mapping 1", Gtk::AccelKey("b"), sigc::mem_fun(m_viewer, &Viewer::toggleBumpMapping ) ) ); m_menu_drawMode.items().push_back(MenuElem("_Translucency", Gtk::AccelKey("u"), sigc::mem_fun(m_viewer, &Viewer::toggleTranslucency ) ) ); + m_menu_drawMode.items().push_back(MenuElem("_Move Light Source", Gtk::AccelKey("l"), sigc::mem_fun(m_viewer, &Viewer::toggleMoveLightSource ) ) ); m_menu_buffer.items().push_back(CheckMenuElem("_Double Buffer", Gtk::AccelKey("b"), buffer_slot )); @@ -39,7 +40,7 @@ AppWindow::AppWindow() // Set up the score label scoreLabel.set_text("Score:\t0"); - linesClearedLabel.set_text("Lines Cleared:\t0"); + linesClearedLabel.set_text("Deleted:\t0"); m_viewer.setScoreWidgets(&scoreLabel, &linesClearedLabel); diff --git a/game.cpp b/game.cpp index ca311c0..3b2f964 100644 --- a/game.cpp +++ b/game.cpp @@ -20,7 +20,7 @@ #define OBLOCKCOL 2 #define XCLEARBLOCKCOL 3 #define OCLEARBLOCKCOL 4 -#define COUNTER_SPACE 16 +#define COUNTER_SPACE 17 int lastClearedRow = -1; static const Piece PIECES[] = { Piece( @@ -164,9 +164,10 @@ Game::Game(int width, int height) , stopped_(false) , linesCleared_(0) , score_(0) + , numBlocksCleared(0) + , counter(0) { int sz = board_width_ * (board_height_+4); -counter=0; board_ = new int[ sz ]; std::fill(board_, board_ + sz, -1); generateNewPiece(); @@ -280,7 +281,8 @@ int Game::collapse() int c = (int)clearBarPos; if (c == lastClearedRow) return 0; - + + int numClearedThisPass = 0; for (int r = board_height_ + 2; r>= 0; --r) { if ((get(r, c) == XCLEARBLOCKCOL || get(r, c) == OCLEARBLOCKCOL ) && r != py_) @@ -295,11 +297,14 @@ int Game::collapse() get(r, c) = -1; pullDown(r, c); lastClearedRow = c; + numBlocksCleared++; + score_ += (linesCleared_+10) / 10; + linesCleared_++; + numClearedThisPass++; } } - // Pull pieces down - return 0; + return numClearedThisPass; } void Game::pullDown(int y, int x) @@ -343,15 +348,16 @@ int Game::tick() return -1; } + int returnVal; removePiece(piece_, px_, py_); markBlocksForClearing(); - collapse(); + returnVal = collapse(); moveClearBar(); if (counter < COUNTER_SPACE) { counter++; placePiece(piece_, px_, py_); - return 0; + return returnVal; } counter = 0; @@ -382,9 +388,8 @@ int Game::tick() dropPiece(1); counter = COUNTER_SPACE; } - int rm = 0; generateNewPiece(); - return rm; + return returnVal; } } else @@ -392,7 +397,7 @@ int Game::tick() placePiece(piece_, px_, ny); sy_ = py_; py_ = ny; - return 0; + return returnVal; } } @@ -462,7 +467,7 @@ bool Game::drop() while(true) { --ny; - score_ += 1 + (linesCleared_ / 10); + score_ += 1 + (linesCleared_ / 100); if(!doesPieceFit(piece_, px_, ny)) { break; @@ -528,6 +533,8 @@ bool Game::moveClearBar() { lastClearedRow = board_width_; clearBarPos = 0; + numBlocksCleared = 0; + } clearBarPos += 0.2; } diff --git a/game.hpp b/game.hpp index d129f5b..dc9c1a6 100644 --- a/game.hpp +++ b/game.hpp @@ -181,6 +181,8 @@ void dropShadowPiece(); // Extra stuff int score_, linesCleared_; + int numBlocksCleared; + int numDeleted; double clearBarPos; Viewer *viewer; diff --git a/particle.cpp b/particle.cpp index f30d1a3..8cd5f0c 100644 --- a/particle.cpp +++ b/particle.cpp @@ -1,16 +1,16 @@ #include "particle.hpp" #include -Particle::Particle(Point3D position, float rad, Vector3D vel, float d, int colIndex) +Particle::Particle(Point3D position, float radius, Vector3D velocity, float d, int colIndex, Vector3D acceleration) { pos = position; - radius = rad; - velocity = vel; + rad = radius; + vel = velocity; decay = d; colourIndex = colIndex; // Defaults alpha = 1.f; -// accel = 0.f; + accel = acceleration; } float Particle::getDecay() @@ -25,12 +25,12 @@ Point3D Particle::getPos() float Particle::getRadius() { - return radius; + return rad; } Vector3D Particle::getVelocity() { - return velocity; + return vel; } float Particle::getAlpha() @@ -45,7 +45,8 @@ bool Particle::step(float t) return true; // Move particle forward - pos = pos + t * velocity; + vel = vel + t * accel; + pos = pos + t * vel; // Decay defines how long the particle will be alive for decay -= t; diff --git a/particle.hpp b/particle.hpp index 4a13532..b494b39 100644 --- a/particle.hpp +++ b/particle.hpp @@ -8,7 +8,7 @@ class Particle { public: Particle(); - Particle(Point3D pos, float radius, Vector3D velocity, float decay, int colIndex); + Particle(Point3D pos, float radius, Vector3D velocity, float decay, int colIndex, Vector3D acceleration); virtual ~Particle(); float getDecay(); @@ -25,8 +25,8 @@ class Particle private: float decay; Point3D pos; - float radius; - Vector3D velocity; + float rad; + Vector3D vel; Vector3D accel; float alpha; int colourIndex; diff --git a/viewer.cpp b/viewer.cpp index 5d23aa7..41258fa 100644 --- a/viewer.cpp +++ b/viewer.cpp @@ -10,7 +10,7 @@ #define DEFAULT_GAME_SPEED 50 #define WIDTH 16 #define HEIGHT 10 -int SND_ID_1 = 0; + Viewer::Viewer() { @@ -37,9 +37,9 @@ Viewer::Viewer() clickedButton = false; // loadScreen = false; - + moveLightSource = false; activeTextureId = 0; - loadTexture = false; + loadTexture = true; loadBumpMapping = false; transluceny = false; moveLeft = false; @@ -65,7 +65,7 @@ Viewer::Viewer() // - a depth buffer to avoid things overlapping wrongly // - double-buffered rendering to avoid tearing/flickering // - Multisample rendering to smooth out edges - glconfig = Gdk::GL::Config::create( Gdk::GL::MODE_RGB | + glconfig = Gdk::GL::Config::create( Gdk::GL::MODE_RGBA | Gdk::GL::MODE_DEPTH | Gdk::GL::MODE_DOUBLE | Gdk::GL::MODE_ACCUM | @@ -166,24 +166,9 @@ void Viewer::on_realize() */ glClearColor(1.0, 1.0, 1.0, 1.0); - - square = glGenLists(1); - glNewList(square, GL_COMPILE); - glBegin(GL_QUADS); - glTexCoord2f(0.0f, 0.0f); - glVertex3d(0, 0, 1); - - glTexCoord2f(1.0f, 0.0f); - glVertex3d(1, 0, 1); - - glTexCoord2f(1.0f, 1.0f); - glVertex3d(1, 1, 1); + // Initialize random number generator + srand ( time(NULL) ); - glTexCoord2f(0.0f, 1.0f); - glVertex3d(0, 1, 1); - glEnd(); - glEndList(); - gldrawable->gl_end(); } @@ -358,7 +343,7 @@ bool Viewer::on_expose_event(GdkEventExpose* event) silhouette.clear();*/ - glDisable(GL_DEPTH_TEST); +/* glDisable(GL_DEPTH_TEST); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); glEnable(GL_STENCIL_TEST); @@ -378,7 +363,7 @@ bool Viewer::on_expose_event(GdkEventExpose* event) drawFloor(); glDisable(GL_STENCIL_TEST); - drawReflections(); +*/ /* if (moveRight) { moveRight = false; @@ -389,15 +374,23 @@ bool Viewer::on_expose_event(GdkEventExpose* event) drawMoveBlur(-1); moveLeft = false; }*/ + drawFloor(); + drawReflections(); drawScene(0); drawGrid(); drawParticles(); drawBar(); +/* if (game->counter == 0) + { + pauseGame(); + drawScene(0); + //glAccum(GL_LOAD, 1.f); + glClear(GL_ACCUM_BUFFER_BIT); + drawFallingBox(); + glAccum(GL_RETURN, 1.f); - - -// glEnable(GL_LIGHTING); // Enable Lighting -// glDepthMask(GL_TRUE); // Enable Depth Mask + pauseGame(); + }*/ glColor3f(1.f, 1.f, 0.f); GLUquadricObj *quadratic; @@ -427,7 +420,8 @@ bool Viewer::on_expose_event(GdkEventExpose* event) { pauseGame(); drawScene(0); - glClear(GL_ACCUM_BUFFER_BIT); + glAccum(GL_LOAD, 1.f); +// glClear(GL_ACCUM_BUFFER_BIT); drawFallingBox(); glAccum(GL_RETURN, 1.f); @@ -490,7 +484,7 @@ void Viewer::drawReflections() glPushMatrix(); // glTranslatef(0, 0.1f, -2); glRotatef(90, 1.0, 0, 0); - glTranslatef(0, 1,-1); + glTranslatef(0, 1, 0); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(0.7, 0.0, 0.0, 0.40); /* 40% dark red floor color */ @@ -628,20 +622,17 @@ void Viewer::addParticleBox(float x, float y, int colour) Point3D pos(x, y, 0); float radius = 0.2f; float decay = 2.f; - Vector3D vel(-1, -1, 0); - for (int i = 0;i<5;i++) + float n = 10.f; + for (int i = 0;ipy_ - 2, game->px_ + 1, 7, GL_LINE_LOOP ); drawCube (game->py_ - 2, game->px_ + 2, 7, GL_LINE_LOOP ); glPopMatrix(); -// glAccum(GL_ACCUM, iterFrac); + glAccum(GL_ACCUM, iterFrac); } } @@ -1060,6 +1050,21 @@ bool Viewer::on_button_release_event(GdkEventButton* event) bool Viewer::on_motion_notify_event(GdkEventMotion* event) { double x2x1; + + if (moveLightSource) + { + // See how much we have moved + x2x1 = (event->x - startPos[0]); + if (mouseB1Down) // Rotate x + lightPos[0] += x2x1; + if (mouseB2Down) // Rotate y + lightPos[1] += x2x1; + if (mouseB3Down) // Rotate z + lightPos[2] += x2x1; + + invalidate(); + return true; + } if (shiftIsDown) // Start Scaling { // Store some initial values @@ -1375,10 +1380,16 @@ void Viewer::drawBumpCube(float y, float x, int colourId, GLenum mode, bool mult glVertex3f(vertex_position[0], vertex_position[1], vertex_position[2]); glEnd(); - glBindTexture(GL_TEXTURE_CUBE_MAP, 0); + glActiveTexture(GL_TEXTURE0); +// glBindTexture(GL_TEXTURE_CUBE_MAP, 0); glDisable(GL_TEXTURE_CUBE_MAP); - glBindTexture(GL_TEXTURE_2D, 0); + glActiveTexture(GL_TEXTURE1); +// glBindTexture(GL_TEXTURE_2D, 0); + glDisable(GL_TEXTURE_2D); + + glActiveTexture(GL_TEXTURE2); +// glBindTexture(GL_TEXTURE_2D, 0); glDisable(GL_TEXTURE_2D); } @@ -1455,6 +1466,7 @@ void Viewer::drawCube(float y, float x, int colourId, GLenum mode, bool multiCol if (loadTexture && colourId != 7) { + glActiveTexture(GL_TEXTURE0); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texture[colourId - 1]); } @@ -1485,7 +1497,7 @@ void Viewer::drawCube(float y, float x, int colourId, GLenum mode, bool multiCol glVertex3d(innerXMin + x, innerYMax + y, zMax); glEnd(); -/* // top face + // top face glNormal3d(0, 1, 0); glBegin(mode); @@ -1553,7 +1565,7 @@ void Viewer::drawCube(float y, float x, int colourId, GLenum mode, bool multiCol glVertex3d(innerXMax + x, innerYMax + y, zMin); glTexCoord2f(0.0f, 1.0f); glVertex3d(innerXMin + x, innerYMax + y, zMin); - glEnd();*/ + glEnd(); glBindTexture(GL_TEXTURE_2D, 0); if (transluceny) @@ -1656,7 +1668,7 @@ bool Viewer::gameTick() if (returnVal > 0) { linesStream << game->getLinesCleared(); - linesClearedLabel->set_text("Lines Cleared:\t" + linesStream.str()); + linesClearedLabel->set_text("Deleted:\t" + linesStream.str()); } if (game->getLinesCleared() / 10 > (DEFAULT_GAME_SPEED - gameSpeed) / 50 && gameSpeed > 75) @@ -2038,3 +2050,8 @@ void Viewer::pauseGame() else tickTimer = Glib::signal_timeout().connect(sigc::mem_fun(*this, &Viewer::gameTick), gameSpeed); } + +void Viewer::toggleMoveLightSource() +{ + moveLightSource = !moveLightSource; +} diff --git a/viewer.hpp b/viewer.hpp index eb21e68..f80774f 100644 --- a/viewer.hpp +++ b/viewer.hpp @@ -52,6 +52,7 @@ class Viewer : public Gtk::GL::DrawingArea { void toggleTexture(); void toggleBumpMapping(); void toggleTranslucency(); + void toggleMoveLightSource(); void makeRasterFont(); void printString(const char *s); @@ -200,6 +201,7 @@ class Viewer : public Gtk::GL::DrawingArea { std::vector< Particle *> particles; bool moveLeft; bool moveRight; + bool moveLightSource; }; #endif