Skip to content

Commit

Permalink
Fixed start menu. Added 3 buttons, play, disable sound, single skin mode
Browse files Browse the repository at this point in the history
clicking looks to work okay
added 3 new level colour schemes
  • Loading branch information
Krishna committed Mar 28, 2010
1 parent 90d2673 commit c530e56
Show file tree
Hide file tree
Showing 21 changed files with 160 additions and 49 deletions.
Binary file removed 256.bmp
Binary file not shown.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LDFLAGS = $(shell pkg-config --libs gtkmm-2.4 gtkglextmm-1.2 sdl libpng) -lglut
CPPFLAGS = $(shell pkg-config --cflags gtkmm-2.4 gtkglextmm-1.2 sdl libpng)
CXXFLAGS = $(CPPFLAGS) -W -Wall -g
CXX = g++ -m32
MAIN = game488
MAIN = lumines

all: $(MAIN)

Expand Down
5 changes: 5 additions & 0 deletions game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,11 @@ bool Game::moveClearBar()
{
lastClearedRow = board_width_;
clearBarPos = 0;
if (numBlocksCleared > 15)
{
int multiplier = numBlocksCleared / 4;
score_ += multiplier * (numBlocksCleared+10) / 10;
}
numBlocksCleared = 0;

}
Expand Down
Binary file added o7.bmp
Binary file not shown.
Binary file added o8.bmp
Binary file not shown.
Binary file added o9.bmp
Binary file not shown.
Binary file added oLight7.bmp
Binary file not shown.
Binary file added oLight8.bmp
Binary file not shown.
Binary file added oLight9.bmp
Binary file not shown.
Binary file modified playButton.bmp
Binary file not shown.
Binary file modified playButtonClicked.bmp
Binary file not shown.
Binary file added soundOff.bmp
Binary file not shown.
Binary file added soundOn.bmp
Binary file not shown.
199 changes: 151 additions & 48 deletions viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <assert.h>
#include "appwindow.hpp"

#define NUM_TEXTURES 6
#define NUM_TEXTURES 9
#define DEFAULT_GAME_SPEED 50
#define WIDTH 16
#define HEIGHT 10
Expand Down Expand Up @@ -38,7 +38,7 @@ Viewer::Viewer()
rotateAboutZ = false;
clickedButton = false;
//
loadScreen = false;
loadScreen = true;
moveLightSource = false;
activeTextureId = 0;
loadTexture = true;
Expand All @@ -48,6 +48,8 @@ Viewer::Viewer()
moveRight = false;
motionBlur = false;
levelUpAnimation = false;
singleSkinMode = false;
disableSound = false;
// Game starts at a slow pace of 500ms
gameSpeed = DEFAULT_GAME_SPEED;

Expand Down Expand Up @@ -128,15 +130,20 @@ void Viewer::on_realize()
return;

texture = new GLuint[7];
LoadGLTextures("playButton.bmp", playButtonTex);
LoadGLTextures("playButtonClicked.bmp", playButtonClickedTex);
LoadGLTextures("soundOn.bmp", soundOnTex);
LoadGLTextures("soundOff.bmp", soundOffTex);
LoadGLTextures("singleSkinMode.bmp", singleSkinModeTex);
LoadGLTextures("singleSkinModeClicked.bmp", singleSkinModeClickedTex);
LoadGLTextures("x1.bmp", texture[0]);
LoadGLTextures("o1.bmp", texture[1]);
LoadGLTextures("xLight1.bmp", texture[2]);
LoadGLTextures("oLight1.bmp", texture[3]);
LoadGLTextures("black.bmp", texture[4]);
LoadGLTextures("normal.bmp", bumpMap);
LoadGLTextures("floor.bmp", floorTexId);
LoadGLTextures("playButton.bmp", playButtonTex);
LoadGLTextures("playButtonClicked.bmp", playButtonClickedTex);

LoadGLTextures("background.bmp", backgroundTex);
GenNormalizationCubeMap(256, cube);

Expand All @@ -145,7 +152,7 @@ void Viewer::on_realize()
backgroundMusic = sm.LoadSound("lumines.ogg");
moveSound = sm.LoadSound("move.ogg");
turnSound = sm.LoadSound("turn.ogg");
// sm.PlaySound(backgroundMusic);
//sm.PlaySound(backgroundMusic);


// Sphere for particles
Expand Down Expand Up @@ -268,23 +275,10 @@ bool Viewer::on_expose_event(GdkEventExpose* event)
// it appear centered in the window.
glTranslated(-7.5, -10.0, 7.0);

// Create one light source
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
//glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
// Define properties of light
float ambientLight0[] = { 0.1f, 0.1f, 0.1f, 1.0f };
float diffuseLight0[] = { 0.8f, 0.8f, 0.8f, 1.0f };
float specularLight0[] = { 0.6f, 0.6f, 0.6f, 1.0f };

glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight0);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight0);
glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight0);
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);

if (loadScreen)
{
drawBackground();
drawFloor();
drawStartScreen(false, playButtonTex);

// We pushed a matrix onto the PROJECTION stack earlier, we
Expand All @@ -297,13 +291,27 @@ bool Viewer::on_expose_event(GdkEventExpose* event)
// just drew. This should only be done if double buffering is enabled.
if (doubleBuffer)
gldrawable->swap_buffers();
else
glFlush();


gldrawable->gl_end();

return true;
}

// Create one light source
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
//glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
// Define properties of light
float ambientLight0[] = { 0.1f, 0.1f, 0.1f, 1.0f };
float diffuseLight0[] = { 0.8f, 0.8f, 0.8f, 1.0f };
float specularLight0[] = { 0.6f, 0.6f, 0.6f, 1.0f };

glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight0);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight0);
glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight0);
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);


if (!motionBlur)
{
Expand Down Expand Up @@ -1036,23 +1044,28 @@ bool Viewer::on_button_press_event(GdkEventButton* event)
mouseDownPos[1] = event->y;
if (loadScreen)
{
GLuint buff[128] = {0};
GLuint buff[16] = {0};
GLint hits, view[4];

glSelectBuffer(128,buff);
glSelectBuffer(16,buff);
glRenderMode(GL_SELECT);

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glTranslated(-3.0, 5.0, -30.0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslated(-5.0, -12.0, 0.0);
glInitNames();
glPushName(0);
drawStartScreen(true, playButtonTex);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glGetIntegerv(GL_VIEWPORT,view);
gluPickMatrix(event->x, view[3] - event->y, 1, 1, view);
gluPerspective(40.0, (GLfloat)get_width()/(GLfloat)get_height(), 0.1, 1000.0);
glTranslated(-3.0, 5.0, -30.0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslated(-7.5, -10.0, 7.0);
glInitNames();
glPushName(0);
drawStartScreen(true, playButtonTex);
glPopName();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glFlush();
Expand All @@ -1066,8 +1079,55 @@ bool Viewer::on_button_press_event(GdkEventButton* event)

if (hits > 0)
{
clickedButton = true;
playButtonTex = playButtonClickedTex;
GLuint names, *ptr, minZ,*ptrNames, numberOfNames;

printf ("hits = %d\n", hits);
ptr = (GLuint *) buff;
minZ = 0xffffffff;
for (unsigned int i = 0; i < hits; i++)
{
names = *ptr;
ptr++;
if (*ptr < minZ)
{
numberOfNames = names;
minZ = *ptr;
ptrNames = ptr+2;
}

ptr += names+2;
}

printf ("The closest hit names are ");
ptr = ptrNames;
for (unsigned int j = 0; j < numberOfNames; j++,ptr++)
{
printf ("%d ", *ptr);
}
ptr--;
printf ("Tex ids are %d\t%d\t%d", playButtonTex, soundOnTex,singleSkinModeTex);
if (*ptr == playButtonTex)
{
playButtonTex = playButtonClickedTex;
clickedButton = true;
}
else if (*ptr == soundOnTex)
{
GLuint temp;
temp = soundOnTex;
soundOnTex = soundOffTex;
soundOffTex = temp;
disableSound = !disableSound;
}
else if (*ptr == singleSkinModeTex)
{
GLuint temp;
temp = singleSkinModeTex;
singleSkinModeTex = singleSkinModeClickedTex;
singleSkinModeClickedTex = temp;
clickedButton = true;
singleSkinMode = true;
}
drawStartScreen(false, playButtonClickedTex);
invalidate();
}
Expand Down Expand Up @@ -1721,10 +1781,14 @@ bool Viewer::on_key_press_event( GdkEventKey *ev )
if (gameOver)
return true;

if (ev->keyval == GDK_Left || ev->keyval == GDK_Right)
sm.PlaySound(moveSound);
else if (ev->keyval == GDK_Up || ev->keyval == GDK_Down)
sm.PlaySound(turnSound);
if (loadScreen || !disableSound)
{
if (ev->keyval == GDK_Left || ev->keyval == GDK_Right)
sm.PlaySound(moveSound);
else if (ev->keyval == GDK_Up || ev->keyval == GDK_Down)
sm.PlaySound(turnSound);
}


int r, c;
r = game->py_;
Expand Down Expand Up @@ -1760,7 +1824,7 @@ bool Viewer::gameTick()
scoreStream << game->getScore();
scoreLabel->set_text("Score:\t" + scoreStream.str());

if (cubesDeletedBeforeTick/100 < cubesDeletedAfterTick/100)
if (!singleSkinMode && cubesDeletedBeforeTick/100 < cubesDeletedAfterTick/100)
{
int level = cubesDeletedAfterTick/100 + 1;
if (level > NUM_TEXTURES)
Expand Down Expand Up @@ -1791,7 +1855,7 @@ bool Viewer::gameTick()
}


if (game->getClearBarPos() >= WIDTH && game->numBlocksCleared > 5)
if (game->getClearBarPos() >= WIDTH && game->numBlocksCleared > 15)
{
animatables.clear();
readFile("headHappy.txt");
Expand Down Expand Up @@ -1897,19 +1961,58 @@ bool Viewer::moveClearBar()
void Viewer::drawStartScreen(bool pick, GLuint texId)
{
if (pick)
glPushName(1);
glPushName(playButtonTex);

glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texId);
glBindTexture(GL_TEXTURE_2D, playButtonTex);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex3d(8, 8, 0);
glTexCoord2f(1.0f, 0.0f);
glVertex3d(12, 8, 0);
glTexCoord2f(1.0f, 1.0f);
glVertex3d(12, 10, 0);
glTexCoord2f(0.0f, 1.0f);
glVertex3d(8, 10, 0);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
if (pick)
{
glPopName();
glPushName(soundOnTex);
}

glBindTexture(GL_TEXTURE_2D, soundOnTex);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex3d(8, 5, 0);
glTexCoord2f(1.0f, 0.0f);
glVertex3d(12, 5, 0);
glTexCoord2f(1.0f, 1.0f);
glVertex3d(12, 7, 0);
glTexCoord2f(0.0f, 1.0f);
glVertex3d(8, 7, 0);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
if (pick)
{
glPopName();
glPushName(singleSkinModeTex);
}

glBindTexture(GL_TEXTURE_2D, singleSkinModeTex);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex3d(5, 3, 1);
glVertex3d(8, 2, 0);
glTexCoord2f(1.0f, 0.0f);
glVertex3d(13, 3, 1);
glVertex3d(12, 2, 0);
glTexCoord2f(1.0f, 1.0f);
glVertex3d(13, 7, 1);
glVertex3d(12, 4, 0);
glTexCoord2f(0.0f, 1.0f);
glVertex3d(5, 7, 1);
glVertex3d(8, 4, 0);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);

Expand Down
3 changes: 3 additions & 0 deletions viewer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ class Viewer : public Gtk::GL::DrawingArea {
float planeNormal[4];
bool drawingShadow;
GLuint cube, bumpMap, floorTexId, playButtonTex, playButtonClickedTex, backgroundTex;
GLuint soundOnTex, soundOffTex, singleSkinModeTex, singleSkinModeClickedTex;
bool clickedButton;
std::vector< std::pair<Point3D, Point3D> > silhouette;
std::vector< Particle *> particles;
Expand All @@ -210,6 +211,8 @@ class Viewer : public Gtk::GL::DrawingArea {
bool moveLightSource;
bool motionBlur;
bool levelUpAnimation;
bool disableSound;
bool singleSkinMode;
GLUquadricObj *particleSphere;

struct Animatable{
Expand Down
Binary file added x7.bmp
Binary file not shown.
Binary file added x8.bmp
Binary file not shown.
Binary file added x9.bmp
Binary file not shown.
Binary file added xLight7.bmp
Binary file not shown.
Binary file added xLight8.bmp
Binary file not shown.
Binary file added xLight9.bmp
Binary file not shown.

0 comments on commit c530e56

Please sign in to comment.