Skip to content

Commit

Permalink
Bump mapping can be turned off properly
Browse files Browse the repository at this point in the history
Made particle effect more rnadom looking
Score keeping works
  • Loading branch information
Krishna committed Mar 25, 2010
1 parent 156103a commit e5028f6
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 70 deletions.
3 changes: 2 additions & 1 deletion appwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ));

Expand All @@ -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);

Expand Down
29 changes: 18 additions & 11 deletions game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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_)
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -382,17 +388,16 @@ int Game::tick()
dropPiece(1);
counter = COUNTER_SPACE;
}
int rm = 0;
generateNewPiece();
return rm;
return returnVal;
}
}
else
{
placePiece(piece_, px_, ny);
sy_ = py_;
py_ = ny;
return 0;
return returnVal;
}
}

Expand Down Expand Up @@ -462,7 +467,7 @@ bool Game::drop()
while(true)
{
--ny;
score_ += 1 + (linesCleared_ / 10);
score_ += 1 + (linesCleared_ / 100);
if(!doesPieceFit(piece_, px_, ny))
{
break;
Expand Down Expand Up @@ -528,6 +533,8 @@ bool Game::moveClearBar()
{
lastClearedRow = board_width_;
clearBarPos = 0;
numBlocksCleared = 0;

}
clearBarPos += 0.2;
}
Expand Down
2 changes: 2 additions & 0 deletions game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ void dropShadowPiece();

// Extra stuff
int score_, linesCleared_;
int numBlocksCleared;
int numDeleted;
double clearBarPos;
Viewer *viewer;

Expand Down
15 changes: 8 additions & 7 deletions particle.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#include "particle.hpp"
#include <iostream>

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()
Expand All @@ -25,12 +25,12 @@ Point3D Particle::getPos()

float Particle::getRadius()
{
return radius;
return rad;
}

Vector3D Particle::getVelocity()
{
return velocity;
return vel;
}

float Particle::getAlpha()
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions particle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down
Loading

0 comments on commit e5028f6

Please sign in to comment.