PLIB 1.8.5+ r2173 from http://plib.svn.sourceforge.net/svnroot/plib/trunk
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
# src/
|
||||
|
||||
bindir=$(prefix)/games
|
||||
|
||||
bin_PROGRAMS = ttt3d
|
||||
|
||||
ttt3d_SOURCES = \
|
||||
ttt3d.cxx gfx.cxx material.cxx gui.cxx status.cxx sound.cxx \
|
||||
cell.cxx puzzle.cxx game.cxx \
|
||||
p3d.h gfx.h gui.h material.h status.h sound.h \
|
||||
cell.h puzzle.h level.h game.h
|
||||
|
||||
@@ -0,0 +1,291 @@
|
||||
/*
|
||||
This file is part of TTT3D - Steve's 3D TicTacToe Player.
|
||||
Copyright (C) 2001 Steve Baker
|
||||
|
||||
TTT3D is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TTT3D is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with TTT3D; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: cell.cxx 1465 2002-08-30 14:05:59Z wolfram_kuss $
|
||||
*/
|
||||
|
||||
|
||||
#include "p3d.h"
|
||||
#include <plib/ssgAux.h>
|
||||
|
||||
static ssgBranch *wire_cube = NULL ;
|
||||
static ssgBranch * X_cube = NULL ;
|
||||
static ssgBranch * O_cube = NULL ;
|
||||
|
||||
|
||||
ssgTransform *makeGround ()
|
||||
{
|
||||
ssgTransform *ground = new ssgTransform () ;
|
||||
|
||||
sgVec4 *colour = new sgVec4 [ 1 ] ;
|
||||
sgVec3 *normal = new sgVec3 [ 1 ] ;
|
||||
sgVec2 *tcoord = new sgVec2 [ 4 ] ;
|
||||
sgVec3 *scoord = new sgVec3 [ 4 ] ;
|
||||
|
||||
sgSetVec4 ( colour[0], 1, 1, 1, 1 ) ;
|
||||
|
||||
sgSetVec2 ( tcoord [ 0 ], 0, 0 ) ;
|
||||
sgSetVec2 ( tcoord [ 1 ], 25, 0 ) ;
|
||||
sgSetVec2 ( tcoord [ 2 ], 25, 25 ) ;
|
||||
sgSetVec2 ( tcoord [ 3 ], 0, 25 ) ;
|
||||
|
||||
sgSetVec3 ( normal [ 0 ], 0, 0, 1 ) ;
|
||||
|
||||
sgSetVec3 ( scoord [ 0 ], -60, -60, -5.6f ) ;
|
||||
sgSetVec3 ( scoord [ 1 ], 60, -60, -5.6f ) ;
|
||||
sgSetVec3 ( scoord [ 2 ], 60, 60, -5.6f ) ;
|
||||
sgSetVec3 ( scoord [ 3 ], -60, 60, -5.6f ) ;
|
||||
|
||||
ssgVTable *vt1 = new ssgVTable ( (GLenum) GL_TRIANGLE_FAN,
|
||||
4, scoord,
|
||||
1, normal,
|
||||
4, tcoord,
|
||||
1, colour ) ;
|
||||
|
||||
vt1 -> setState ( ground_gst ) ; ground -> addKid ( vt1 ) ;
|
||||
|
||||
colour = new sgVec4 [ 1 ] ;
|
||||
normal = new sgVec3 [ 1 ] ;
|
||||
tcoord = new sgVec2 [ 6 ] ;
|
||||
scoord = new sgVec3 [ 6 ] ;
|
||||
|
||||
sgSetVec4 ( colour[0], 1, 1, 1, 1 ) ;
|
||||
|
||||
sgSetVec2 ( tcoord [ 0 ], 0, 0 ) ;
|
||||
sgSetVec2 ( tcoord [ 1 ], 1, 0 ) ;
|
||||
sgSetVec2 ( tcoord [ 2 ], 1, 1 ) ;
|
||||
sgSetVec2 ( tcoord [ 3 ], 0, 1 ) ;
|
||||
sgSetVec2 ( tcoord [ 4 ], 1, 1 ) ;
|
||||
sgSetVec2 ( tcoord [ 5 ], 1, 0 ) ;
|
||||
|
||||
sgSetVec3 ( normal [ 0 ], 0, 0, 1 ) ;
|
||||
|
||||
sgSetVec3 ( scoord [ 0 ], -2, -2, -2.5 ) ;
|
||||
sgSetVec3 ( scoord [ 1 ], 1, -2, -2.5 ) ;
|
||||
sgSetVec3 ( scoord [ 2 ], 1, 1, -2.5 ) ;
|
||||
sgSetVec3 ( scoord [ 3 ], -2, 1, -2.5 ) ;
|
||||
sgSetVec3 ( scoord [ 4 ], 1, 1, -2.5 ) ;
|
||||
sgSetVec3 ( scoord [ 5 ], 1, -2, -2.5 ) ;
|
||||
|
||||
vt1 = new ssgVTable ( (GLenum) GL_TRIANGLE_FAN,
|
||||
6, scoord,
|
||||
1, normal,
|
||||
6, tcoord,
|
||||
1, colour ) ;
|
||||
|
||||
vt1 -> setState ( ctrls_gst ) ; ground -> addKid ( vt1 ) ;
|
||||
|
||||
return ground ;
|
||||
} ;
|
||||
|
||||
ssgTransform *makeBlueWireCube()
|
||||
{
|
||||
ssgTransform *sel_cube = new ssgTransform () ;
|
||||
|
||||
sgVec4 *colour = new sgVec4 [ 1 ] ;
|
||||
sgVec3 *normal = new sgVec3 [ 1 ] ;
|
||||
sgVec2 *tcoord = new sgVec2 [ 1 ] ;
|
||||
sgVec3 *scoord = new sgVec3 [ 8 ] ;
|
||||
|
||||
sgSetVec4 ( colour[0], 1, 0, 1, 1 ) ;
|
||||
sgSetVec3 ( normal[0], 1, 0, 0 ) ;
|
||||
sgSetVec2 ( tcoord[0], 0, 0 ) ;
|
||||
|
||||
sgSetVec3 ( scoord [ 0 ], -0.5, -0.5, -0.5 ) ;
|
||||
sgSetVec3 ( scoord [ 1 ], -0.5, -0.5, 0.5 ) ;
|
||||
sgSetVec3 ( scoord [ 2 ], 0.5, -0.5, 0.5 ) ;
|
||||
sgSetVec3 ( scoord [ 3 ], 0.5, -0.5, -0.5 ) ;
|
||||
|
||||
sgSetVec3 ( scoord [ 4 ], -0.5, 0.5, -0.5 ) ;
|
||||
sgSetVec3 ( scoord [ 5 ], -0.5, 0.5, 0.5 ) ;
|
||||
sgSetVec3 ( scoord [ 6 ], 0.5, 0.5, 0.5 ) ;
|
||||
sgSetVec3 ( scoord [ 7 ], 0.5, 0.5, -0.5 ) ;
|
||||
|
||||
unsigned short *sindex = new unsigned short [ 7 ] ;
|
||||
unsigned short *cindex = new unsigned short [ 1 ] ;
|
||||
unsigned short *nindex = new unsigned short [ 1 ] ;
|
||||
unsigned short *tindex = new unsigned short [ 1 ] ;
|
||||
|
||||
sindex [ 0 ] = 0 ;
|
||||
sindex [ 1 ] = 1 ;
|
||||
sindex [ 2 ] = 2 ;
|
||||
sindex [ 3 ] = 6 ;
|
||||
sindex [ 4 ] = 7 ;
|
||||
sindex [ 5 ] = 3 ;
|
||||
sindex [ 6 ] = 2 ;
|
||||
|
||||
cindex [ 0 ] = 0 ;
|
||||
nindex [ 0 ] = 0 ;
|
||||
tindex [ 0 ] = 0 ;
|
||||
|
||||
ssgVTable *vt1 = new ssgVTable ( (GLenum) GL_LINE_STRIP,
|
||||
7, sindex, scoord,
|
||||
1, nindex, normal,
|
||||
1, tindex, tcoord,
|
||||
1, cindex, colour ) ;
|
||||
|
||||
sindex = new unsigned short [ 5 ] ;
|
||||
|
||||
sindex [ 0 ] = 3 ;
|
||||
sindex [ 1 ] = 0 ;
|
||||
sindex [ 2 ] = 4 ;
|
||||
sindex [ 3 ] = 5 ;
|
||||
sindex [ 4 ] = 1 ;
|
||||
|
||||
ssgVTable *vt2 = new ssgVTable ( (GLenum) GL_LINE_STRIP,
|
||||
5, sindex, scoord,
|
||||
1, nindex, normal,
|
||||
1, tindex, tcoord,
|
||||
1, cindex, colour ) ;
|
||||
|
||||
sindex = new unsigned short [ 2 ] ;
|
||||
|
||||
sindex [ 0 ] = 5 ;
|
||||
sindex [ 1 ] = 6 ;
|
||||
|
||||
ssgVTable *vt3 = new ssgVTable ( (GLenum) GL_LINE_STRIP,
|
||||
2, sindex, scoord,
|
||||
1, nindex, normal,
|
||||
1, tindex, tcoord,
|
||||
1, cindex, colour ) ;
|
||||
|
||||
sindex = new unsigned short [ 2 ] ;
|
||||
|
||||
sindex [ 0 ] = 4 ;
|
||||
sindex [ 1 ] = 7 ;
|
||||
|
||||
ssgVTable *vt4 = new ssgVTable ( (GLenum) GL_LINE_STRIP,
|
||||
2, sindex, scoord,
|
||||
1, nindex, normal,
|
||||
1, tindex, tcoord,
|
||||
1, cindex, colour ) ;
|
||||
|
||||
vt1 -> setState ( default_gst ) ; sel_cube -> addKid ( vt1 ) ;
|
||||
vt2 -> setState ( default_gst ) ; sel_cube -> addKid ( vt2 ) ;
|
||||
vt3 -> setState ( default_gst ) ; sel_cube -> addKid ( vt3 ) ;
|
||||
vt4 -> setState ( default_gst ) ; sel_cube -> addKid ( vt4 ) ;
|
||||
|
||||
return sel_cube ;
|
||||
}
|
||||
|
||||
|
||||
static void makeWireCube()
|
||||
{
|
||||
wire_cube = new ssgBranch () ;
|
||||
|
||||
sgVec4 *colour = new sgVec4 [ 1 ] ;
|
||||
sgVec3 *normal = new sgVec3 [ 1 ] ;
|
||||
sgVec2 *tcoord = new sgVec2 [ 1 ] ;
|
||||
sgVec3 *scoord = new sgVec3 [ 4 ] ;
|
||||
|
||||
sgSetVec4 ( colour[0], 1.0, 1.0, 0.0, 0.7f ) ;
|
||||
sgSetVec3 ( normal[0], 1, 0, 0 ) ;
|
||||
sgSetVec2 ( tcoord[0], 0, 0 ) ;
|
||||
|
||||
sgSetVec3 ( scoord [ 0 ], -0.5, -0.5, -0.5 ) ;
|
||||
sgSetVec3 ( scoord [ 1 ], -0.5, 0.5, -0.5 ) ;
|
||||
sgSetVec3 ( scoord [ 2 ], 0.5, 0.5, -0.5 ) ;
|
||||
sgSetVec3 ( scoord [ 3 ], 0.5, -0.5, -0.5 ) ;
|
||||
|
||||
unsigned short *sindex = new unsigned short [ 4 ] ;
|
||||
unsigned short *cindex = new unsigned short [ 1 ] ;
|
||||
unsigned short *nindex = new unsigned short [ 1 ] ;
|
||||
unsigned short *tindex = new unsigned short [ 1 ] ;
|
||||
|
||||
sindex [ 0 ] = 0 ;
|
||||
sindex [ 1 ] = 1 ;
|
||||
sindex [ 2 ] = 2 ;
|
||||
sindex [ 3 ] = 3 ;
|
||||
|
||||
cindex [ 0 ] = 0 ;
|
||||
nindex [ 0 ] = 0 ;
|
||||
tindex [ 0 ] = 0 ;
|
||||
|
||||
ssgVTable *vt = new ssgVTable ( (GLenum) GL_LINE_LOOP,
|
||||
4, sindex, scoord, 1, nindex, normal,
|
||||
1, tindex, tcoord, 1, cindex, colour ) ;
|
||||
|
||||
vt -> setState ( default_gst ) ;
|
||||
wire_cube -> addKid ( vt ) ;
|
||||
}
|
||||
|
||||
|
||||
static ssgBranch *X ()
|
||||
{
|
||||
ssgaCube *XXX = new ssgaCube () ;
|
||||
|
||||
XXX -> setSize ( 0.5 ) ;
|
||||
XXX -> setKidState ( X_gst ) ;
|
||||
|
||||
return XXX ;
|
||||
}
|
||||
|
||||
|
||||
static ssgBranch *O ()
|
||||
{
|
||||
ssgaSphere *OOO = new ssgaSphere ( 300 ) ;
|
||||
|
||||
OOO -> setSize ( 0.7f ) ;
|
||||
OOO -> setKidState ( O_gst ) ;
|
||||
|
||||
return OOO ;
|
||||
}
|
||||
|
||||
|
||||
static void makeXcube ()
|
||||
{
|
||||
X_cube = new ssgBranch () ;
|
||||
X_cube -> addKid ( X () ) ;
|
||||
}
|
||||
|
||||
|
||||
static void makeOcube ()
|
||||
{
|
||||
O_cube = new ssgBranch () ;
|
||||
O_cube -> addKid ( O () ) ;
|
||||
}
|
||||
|
||||
|
||||
Cell::Cell ( int x, int y, int z, int size )
|
||||
{
|
||||
if ( wire_cube == NULL ) makeWireCube() ;
|
||||
if ( X_cube == NULL ) makeXcube () ;
|
||||
if ( O_cube == NULL ) makeOcube () ;
|
||||
|
||||
sgSetCoord ( &c, (float)x - (float) size / 2.0f + 0.5f,
|
||||
(float)y - (float) size / 2.0f + 0.5f,
|
||||
(float)z - (float) size / 2.0f + 0.5f, 0,0,0 ) ;
|
||||
|
||||
posn = new ssgTransform ( & c ) ;
|
||||
cell = new ssgSelector () ;
|
||||
|
||||
posn -> addKid ( cell ) ;
|
||||
|
||||
/* Don't change the order of these without changing the defines */
|
||||
|
||||
cell -> addKid ( wire_cube ) ;
|
||||
cell -> addKid ( X_cube ) ;
|
||||
cell -> addKid ( O_cube ) ;
|
||||
|
||||
what = WIRE_CELL ;
|
||||
cell -> selectStep ( what ) ;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
This file is part of TTT3D - Steve's 3D TicTacToe Player.
|
||||
Copyright (C) 2001 Steve Baker
|
||||
|
||||
TTT3D is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TTT3D is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with TTT3D; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: cell.h 1427 2002-08-18 00:09:46Z ude $
|
||||
*/
|
||||
|
||||
|
||||
ssgTransform *makeBlueWireCube() ;
|
||||
ssgTransform *makeGround() ;
|
||||
|
||||
#define WIRE_CELL 0
|
||||
#define X_CELL 1
|
||||
#define O_CELL 2
|
||||
|
||||
class Cell
|
||||
{
|
||||
sgCoord c ;
|
||||
ssgTransform *posn ;
|
||||
ssgSelector *cell ;
|
||||
int what ;
|
||||
|
||||
public:
|
||||
|
||||
Cell ( int x, int y, int z, int size ) ;
|
||||
|
||||
ssgBranch *getSSG () { return posn ; }
|
||||
|
||||
int get () { return what ; }
|
||||
|
||||
void set ( int n )
|
||||
{
|
||||
what = n ;
|
||||
cell -> selectStep ( n ) ;
|
||||
}
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
@@ -0,0 +1,483 @@
|
||||
/*
|
||||
This file is part of TTT3D - Steve's 3D TicTacToe Player.
|
||||
Copyright (C) 2001 Steve Baker
|
||||
|
||||
TTT3D is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TTT3D is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with TTT3D; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: game.cxx 1427 2002-08-18 00:09:46Z ude $
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include "game.h"
|
||||
|
||||
static char board [4][4][4] ;
|
||||
static int last_x = -1 ;
|
||||
static int last_y = -1 ;
|
||||
static int last_z = -1 ;
|
||||
|
||||
#define NUM_ROWS ( 3 * 16 + 3 * 8 + 4 )
|
||||
|
||||
static char *row [ NUM_ROWS ][ 4 ] ;
|
||||
static char rowptr [ 4 ][ 4 ][ 4 ][ 8 ] ;
|
||||
static char rowptrctr [ 4 ][ 4 ][ 4 ] ;
|
||||
|
||||
|
||||
static void setupRowArray ()
|
||||
{
|
||||
int x, y, z;
|
||||
|
||||
for ( x = 0 ; x < 4 ; x++ )
|
||||
for ( y = 0 ; y < 4 ; y++ )
|
||||
for ( z = 0 ; z < 4 ; z++ )
|
||||
{
|
||||
rowptrctr [ x ][ y ][ z ] = 0 ;
|
||||
|
||||
for ( int i = 0 ; i < 8 ; i++ )
|
||||
rowptr [ x ][ y ][ z ][ i ] = 127 ;
|
||||
}
|
||||
|
||||
int r = 0 ;
|
||||
|
||||
/* 16 Z axis rows */
|
||||
|
||||
for ( x = 0 ; x < 4 ; x++ )
|
||||
for ( y = 0 ; y < 4 ; y++ )
|
||||
{
|
||||
for ( z = 0 ; z < 4 ; z++ )
|
||||
{
|
||||
row [ r ][ z ] = & board [ x ][ y ][ z ] ;
|
||||
rowptr [ x ][ y ][ z ][ rowptrctr[x][y][z]++ ] = r ;
|
||||
}
|
||||
r++ ;
|
||||
}
|
||||
|
||||
/* 16 Y axis rows */
|
||||
|
||||
for ( x = 0 ; x < 4 ; x++ )
|
||||
for ( z = 0 ; z < 4 ; z++ )
|
||||
{
|
||||
for ( y = 0 ; y < 4 ; y++ )
|
||||
{
|
||||
row [ r ][ y ] = & board [ x ][ y ][ z ] ;
|
||||
rowptr [ x ][ y ][ z ][ rowptrctr[x][y][z]++ ] = r ;
|
||||
}
|
||||
|
||||
r++ ;
|
||||
}
|
||||
|
||||
/* 16 Y axis rows */
|
||||
|
||||
for ( z = 0 ; z < 4 ; z++ )
|
||||
for ( y = 0 ; y < 4 ; y++ )
|
||||
{
|
||||
for ( x = 0 ; x < 4 ; x++ )
|
||||
{
|
||||
row [ r ][ x ] = & board [ x ][ y ][ z ] ;
|
||||
rowptr [ x ][ y ][ z ][ rowptrctr[x][y][z]++ ] = r ;
|
||||
}
|
||||
|
||||
r++ ;
|
||||
}
|
||||
|
||||
/* 8 xy plane diagonals */
|
||||
|
||||
for ( z = 0 ; z < 4 ; z++ )
|
||||
{
|
||||
int xy;
|
||||
|
||||
for ( xy = 0 ; xy < 4 ; xy++ )
|
||||
{
|
||||
row [ r ][ xy ] = & board [ xy ][ xy ][ z ] ;
|
||||
rowptr [ xy ][ xy ][ z ][ rowptrctr[xy][xy][z]++ ] = r ;
|
||||
}
|
||||
|
||||
r++ ;
|
||||
|
||||
for ( xy = 0 ; xy < 4 ; xy++ )
|
||||
{
|
||||
row [ r ][ xy ] = & board [ xy ][ 3 - xy ][ z ] ;
|
||||
rowptr [ xy ][3-xy][ z ][ rowptrctr[xy][3-xy][z]++ ] = r ;
|
||||
}
|
||||
|
||||
r++ ;
|
||||
}
|
||||
|
||||
/* 8 xz plane diagonals */
|
||||
|
||||
for ( y = 0 ; y < 4 ; y++ )
|
||||
{
|
||||
int xz;
|
||||
|
||||
for ( xz = 0 ; xz < 4 ; xz++ )
|
||||
{
|
||||
row [ r ][ xz ] = & board [ xz ][ y ][ xz ] ;
|
||||
rowptr [ xz ][ y ][ xz ][ rowptrctr[xz][y][xz]++ ] = r ;
|
||||
}
|
||||
|
||||
r++ ;
|
||||
|
||||
for ( xz = 0 ; xz < 4 ; xz++ )
|
||||
{
|
||||
row [ r ][ xz ] = & board [ xz ][ y ][ 3 - xz ] ;
|
||||
rowptr [ xz ][ y ][3-xz][ rowptrctr[xz][y][3-xz]++ ] = r ;
|
||||
}
|
||||
|
||||
r++ ;
|
||||
}
|
||||
|
||||
/* 8 yz plane diagonals */
|
||||
|
||||
for ( x = 0 ; x < 4 ; x++ )
|
||||
{
|
||||
int yz;
|
||||
for ( yz = 0 ; yz < 4 ; yz++ )
|
||||
{
|
||||
row [ r ][ yz ] = & board [ x ][ yz ][ yz ] ;
|
||||
rowptr [ x ][ yz ][ yz ][ rowptrctr[x][yz][yz]++ ] = r ;
|
||||
}
|
||||
|
||||
r++ ;
|
||||
|
||||
for ( yz = 0 ; yz < 4 ; yz++ )
|
||||
{
|
||||
row [ r ][ yz ] = & board [ x ][ yz ][ 3 - yz ] ;
|
||||
rowptr [ x ][ yz ][3-yz][ rowptrctr[x][yz][3-yz]++ ] = r ;
|
||||
}
|
||||
|
||||
r++ ;
|
||||
}
|
||||
|
||||
/* 4 grand diagonals. */
|
||||
|
||||
int xyz;
|
||||
for ( xyz = 0 ; xyz < 4 ; xyz++ )
|
||||
{
|
||||
row [ r ][ xyz ] = & board [ xyz ][ xyz ][ xyz ] ;
|
||||
rowptr [ xyz ][ xyz ][ xyz ][ rowptrctr[xyz][xyz][xyz]++ ] = r ;
|
||||
}
|
||||
|
||||
r++ ;
|
||||
|
||||
for ( xyz = 0 ; xyz < 4 ; xyz++ )
|
||||
{
|
||||
row [ r ][ xyz ] = & board [ xyz ][ xyz ][ 3-xyz ] ;
|
||||
rowptr [ xyz ][ xyz ][ 3-xyz ][ rowptrctr[xyz][xyz][3-xyz]++ ] = r ;
|
||||
}
|
||||
|
||||
r++ ;
|
||||
|
||||
for ( xyz = 0 ; xyz < 4 ; xyz++ )
|
||||
{
|
||||
row [ r ][ xyz ] = & board [ xyz ][ 3-xyz ][ xyz ] ;
|
||||
rowptr [ xyz ][ 3-xyz ][ xyz ][ rowptrctr[xyz][3-xyz][xyz]++ ] = r ;
|
||||
}
|
||||
|
||||
r++ ;
|
||||
|
||||
for ( xyz = 0 ; xyz < 4 ; xyz++ )
|
||||
{
|
||||
row [ r ][ xyz ] = & board [ xyz ][ 3-xyz ][ 3-xyz ] ;
|
||||
rowptr [ xyz ][ 3-xyz ][ 3-xyz ][ rowptrctr[xyz][3-xyz][3-xyz]++ ] = r ;
|
||||
}
|
||||
|
||||
r++ ;
|
||||
|
||||
if ( r != NUM_ROWS )
|
||||
{
|
||||
fprintf ( stderr, "%d rows?!?\n", r ) ;
|
||||
exit ( 1 ) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void clearBoard ()
|
||||
{
|
||||
for ( int x = 0 ; x < 4 ; x++ )
|
||||
for ( int y = 0 ; y < 4 ; y++ )
|
||||
for ( int z = 0 ; z < 4 ; z++ )
|
||||
board [ x ][ y ][ z ] = ' ' ;
|
||||
}
|
||||
|
||||
|
||||
/*void printBoard ( int winrow )
|
||||
{
|
||||
int x, y, z;
|
||||
|
||||
for ( int i = 0 ; i < 50 ; i++ )
|
||||
printf ( "\n" ) ;
|
||||
|
||||
printf ( " ~~~ 3D TicTacToe ~~~\n" ) ;
|
||||
printf ( " by Steve Baker\n");
|
||||
printf ( "\n" ) ;
|
||||
printf ( "\n" ) ;
|
||||
|
||||
for ( y = 0 ; y < 4 ; y++ )
|
||||
{
|
||||
for ( z = 0 ; z < 4 ; z++ )
|
||||
{
|
||||
for ( x = 0 ; x < 4 ; x++ )
|
||||
{
|
||||
printf ( " " ) ;
|
||||
|
||||
if ( x != 3 )
|
||||
printf ( "|" ) ;
|
||||
}
|
||||
printf ( " " ) ;
|
||||
}
|
||||
printf ( "\n" ) ;
|
||||
|
||||
for ( z = 0 ; z < 4 ; z++ )
|
||||
{
|
||||
for ( x = 0 ; x < 4 ; x++ )
|
||||
{
|
||||
int q ;
|
||||
|
||||
for ( q = 0 ; q < 4 ; q++ )
|
||||
if ( row[winrow][q] == & board[x][y][z] )
|
||||
break ;
|
||||
|
||||
if ( ( x == last_x && y == last_y && z == last_z ) ||
|
||||
q < 4 )
|
||||
printf ( "*%c*", board [ x ][ y ][ z ] ) ;
|
||||
else
|
||||
printf ( " %c ", board [ x ][ y ][ z ] ) ;
|
||||
|
||||
if ( x != 3 )
|
||||
printf ( "|" ) ;
|
||||
}
|
||||
printf ( " " ) ;
|
||||
}
|
||||
printf ( "\n" ) ;
|
||||
|
||||
for ( z = 0 ; z < 4 ; z++ )
|
||||
{
|
||||
for ( x = 0 ; x < 4 ; x++ )
|
||||
{
|
||||
if ( board [ x ][ y ][ z ] == ' ' )
|
||||
{
|
||||
if ( y != 3 )
|
||||
{
|
||||
if ( x+y*4+z*16+1 < 10 )
|
||||
printf ( "_%d_", x + y * 4 + z * 16 + 1 ) ;
|
||||
else
|
||||
printf ( "%2d_", x + y * 4 + z * 16 + 1 ) ;
|
||||
}
|
||||
else
|
||||
printf ( "%2d ", x + y * 4 + z * 16 + 1 ) ;
|
||||
}
|
||||
else
|
||||
if ( y != 3 )
|
||||
printf ( "___" ) ;
|
||||
else
|
||||
printf ( " " ) ;
|
||||
|
||||
if ( x != 3 )
|
||||
printf ( "|" ) ;
|
||||
}
|
||||
printf ( " " ) ;
|
||||
}
|
||||
printf ( "\n" ) ;
|
||||
}
|
||||
|
||||
printf ( "\n" ) ;
|
||||
printf ( "\n" ) ;
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
static int value [4][4] = /* Value of 1000000 means play here to win. */
|
||||
{
|
||||
{ 1, 3,10, 1000000 }, /* No enemy, 0,1,2,3 of ours */
|
||||
{ 2, 0, 0, 0 }, /* One enemy, 0,1,2,3 of ours */
|
||||
{ 20, 0, 0, 0 }, /* Two enemy, 0,1,2,3 of ours */
|
||||
{ 1000, 0, 0, 0 }, /* Three enemy, 0,1,2,3 of ours */
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
static int win = STILL_PLAYING ;
|
||||
|
||||
|
||||
static int countRow ( int r )
|
||||
{
|
||||
int x = 0 ;
|
||||
int o = 0 ;
|
||||
|
||||
for ( int i = 0 ; i < 4 ; i++ )
|
||||
{
|
||||
if ( *(row[r][i]) == 'X' ) x++ ;
|
||||
if ( *(row[r][i]) == 'O' ) o++ ;
|
||||
}
|
||||
|
||||
if ( x == 4 ) { /* printBoard (r) ; */
|
||||
printf ( "** Human wins! **\n\n" ) ;
|
||||
win = HUMAN_WIN ;
|
||||
return 0 ; }
|
||||
|
||||
if ( o == 4 ) { /* printBoard (r) ; */
|
||||
printf ( "** Computer wins! **\n\n" ) ;
|
||||
win = COMPUTER_WIN ;
|
||||
return 0 ; }
|
||||
|
||||
return value [ x ][ o ] ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*int getLoc ( char *msg )
|
||||
{
|
||||
|
||||
while ( 1 )
|
||||
{
|
||||
int res = -1 ;
|
||||
char s [ 21 ] ;
|
||||
|
||||
printf ( "%s\n[1..64]: ", msg ) ;
|
||||
fgets ( s, 20, stdin ) ;
|
||||
|
||||
char *p = s ;
|
||||
|
||||
while ( *p == ' ' || *p == '\t' ) p++ ;
|
||||
|
||||
if ( isdigit ( *p ) )
|
||||
{
|
||||
res = atoi ( p ) - 1 ;
|
||||
|
||||
if ( res >= 0 && res <= 63 && board[res%4][(res%16)/4][res/16] == ' ' )
|
||||
return res ;
|
||||
|
||||
if ( res >= 0 && res <= 63 )
|
||||
printf ( "You can't play there - it's already taken!\n" ) ;
|
||||
else
|
||||
printf ( "Please enter a number in the range 0 to 63.\n" ) ;
|
||||
}
|
||||
else
|
||||
printf ( "Please type a NUMBER in the range 0 to 63.\n" ) ;
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
void game_init ()
|
||||
{
|
||||
win = STILL_PLAYING ;
|
||||
setupRowArray () ;
|
||||
clearBoard () ;
|
||||
}
|
||||
|
||||
|
||||
char get_board_entry ( int x, int y, int z )
|
||||
{
|
||||
return board[x][y][z] ;
|
||||
}
|
||||
|
||||
|
||||
int game_update ( int x, int y, int z )
|
||||
{
|
||||
int q;
|
||||
|
||||
if ( win != STILL_PLAYING )
|
||||
game_init () ;
|
||||
|
||||
/* printBoard (-1) ; */
|
||||
|
||||
board[x][y][z] = 'X' ;
|
||||
|
||||
int rc = rowptrctr[x][y][z] ;
|
||||
|
||||
for ( q = 0 ; q < rc ; q++ )
|
||||
{
|
||||
int r = rowptr[x][y][z][q] ;
|
||||
|
||||
countRow ( r ) ; /* Just to check for a win! */
|
||||
|
||||
if ( win != STILL_PLAYING )
|
||||
return win ;
|
||||
}
|
||||
|
||||
int best = -1 ;
|
||||
int best_sum = 0 ;
|
||||
|
||||
for ( int p = 0 ; p < 64 ; p++ )
|
||||
{
|
||||
x = p % 4 ;
|
||||
y = (p % 16)/4 ;
|
||||
z = p/16 ;
|
||||
|
||||
if ( board[x][y][z] != ' ' )
|
||||
continue ;
|
||||
|
||||
rc = rowptrctr[x][y][z] ;
|
||||
|
||||
int sum = 0 ;
|
||||
|
||||
for ( int q = 0 ; q < rc ; q++ )
|
||||
{
|
||||
int r = rowptr[x][y][z][q] ;
|
||||
|
||||
sum += countRow ( r ) ; /* Just to check for a win! */
|
||||
|
||||
if ( win != STILL_PLAYING )
|
||||
{
|
||||
board[x][y][z] = 'O' ;
|
||||
return win ;
|
||||
}
|
||||
}
|
||||
|
||||
if ( sum >= best_sum )
|
||||
{
|
||||
best = p ;
|
||||
best_sum = sum ;
|
||||
}
|
||||
}
|
||||
|
||||
if ( best == -1 )
|
||||
{
|
||||
/* printBoard (-1) ; */
|
||||
printf ( "** It's a draw! **\n\n" ) ;
|
||||
return DRAWN_GAME ;
|
||||
}
|
||||
|
||||
x = best % 4 ;
|
||||
y = (best % 16)/4 ;
|
||||
z = best/16 ;
|
||||
|
||||
board[x][y][z] = 'O' ;
|
||||
|
||||
last_x = x ;
|
||||
last_y = y ;
|
||||
last_z = z ;
|
||||
|
||||
rc = rowptrctr[x][y][z] ;
|
||||
|
||||
for ( q = 0 ; q < rc ; q++ )
|
||||
{
|
||||
int r = rowptr[x][y][z][q] ;
|
||||
|
||||
countRow ( r ) ; /* Just to check for a win! */
|
||||
|
||||
if ( win != STILL_PLAYING )
|
||||
return win ;
|
||||
}
|
||||
|
||||
return STILL_PLAYING ;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
This file is part of TTT3D - Steve's 3D TicTacToe Player.
|
||||
Copyright (C) 2001 Steve Baker
|
||||
|
||||
TTT3D is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TTT3D is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with TTT3D; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: game.h 1427 2002-08-18 00:09:46Z ude $
|
||||
*/
|
||||
|
||||
|
||||
#define STILL_PLAYING 0
|
||||
#define HUMAN_WIN 1
|
||||
#define COMPUTER_WIN 2
|
||||
#define DRAWN_GAME 3
|
||||
|
||||
void game_init () ;
|
||||
char get_board_entry ( int x, int y, int z ) ;
|
||||
int game_update ( int x, int y, int z ) ;
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
This file is part of TTT3D - Steve's 3D TicTacToe Player.
|
||||
Copyright (C) 2001 Steve Baker
|
||||
|
||||
TTT3D is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TTT3D is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with TTT3D; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: gfx.cxx 1465 2002-08-30 14:05:59Z wolfram_kuss $
|
||||
*/
|
||||
|
||||
|
||||
#include "p3d.h"
|
||||
|
||||
static unsigned int lastGLUTKeystroke = 0 ;
|
||||
|
||||
static void getGLUTSpecialKeystroke ( int key, int, int )
|
||||
{
|
||||
lastGLUTKeystroke = 256 + key ;
|
||||
}
|
||||
|
||||
static void getGLUTKeystroke ( unsigned char key, int, int )
|
||||
{
|
||||
lastGLUTKeystroke = key ;
|
||||
}
|
||||
|
||||
int getGLUTKeystroke ()
|
||||
{
|
||||
int k = lastGLUTKeystroke ;
|
||||
lastGLUTKeystroke = 0 ;
|
||||
return k ;
|
||||
}
|
||||
|
||||
static void reshape ( int w, int h )
|
||||
{
|
||||
glViewport ( 0, 0, w, h ) ;
|
||||
}
|
||||
|
||||
static void initWindow ( int w, int h )
|
||||
{
|
||||
int fake_argc = 1 ;
|
||||
char *fake_argv[3] ;
|
||||
|
||||
fake_argv[0] = "TTT3D" ;
|
||||
fake_argv[1] = "TTT3D by Steve Baker." ;
|
||||
fake_argv[2] = NULL ;
|
||||
|
||||
glutInitWindowPosition ( 0, 0 ) ;
|
||||
glutInitWindowSize ( w, h ) ;
|
||||
glutInit ( &fake_argc, fake_argv ) ;
|
||||
glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ) ;
|
||||
glutCreateWindow ( fake_argv[1] ) ;
|
||||
glutDisplayFunc ( ttt3dMainLoop ) ;
|
||||
glutKeyboardFunc ( getGLUTKeystroke ) ;
|
||||
glutSpecialFunc ( getGLUTSpecialKeystroke ) ;
|
||||
glutReshapeFunc ( reshape ) ;
|
||||
#ifndef WIN32
|
||||
glutIdleFunc ( glutPostRedisplay ) ;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
GFX::GFX ()
|
||||
{
|
||||
initWindow ( 640, 480 ) ;
|
||||
|
||||
ssgInit () ;
|
||||
|
||||
static int firsttime = 1 ;
|
||||
|
||||
if ( firsttime )
|
||||
{
|
||||
firsttime = 0 ;
|
||||
initMaterials () ;
|
||||
}
|
||||
|
||||
ssgSetFOV ( 75.0f, 0.0f ) ;
|
||||
ssgSetNearFar ( 0.01f, 10.0f ) ;
|
||||
|
||||
sgCoord cam ;
|
||||
sgSetVec3 ( cam.xyz, 0, 0, 0 ) ;
|
||||
sgSetVec3 ( cam.hpr, 0, 0, 0 ) ;
|
||||
ssgSetCamera ( & cam ) ;
|
||||
}
|
||||
|
||||
|
||||
void GFX::update ()
|
||||
{
|
||||
sgVec3 sunposn ;
|
||||
sgVec4 skycol ;
|
||||
sgVec4 white = { 1.0, 1.0, 1.0, 1.0 } ;
|
||||
|
||||
sgSetVec3 ( sunposn, -0.2f, -0.5f, 0.2f ) ;
|
||||
|
||||
sgSetVec4 ( skycol, 0.4f, 0.4f, 0.8f, 1.0f ) ;
|
||||
|
||||
ssgGetLight ( 0 ) -> setPosition ( sunposn ) ;
|
||||
ssgGetLight ( 0 ) -> setColour ( GL_AMBIENT , white ) ;
|
||||
ssgGetLight ( 0 ) -> setColour ( GL_DIFFUSE , white ) ;
|
||||
ssgGetLight ( 0 ) -> setColour ( GL_SPECULAR, white ) ;
|
||||
|
||||
/* Clear the screen */
|
||||
|
||||
glClearColor ( skycol[0], skycol[1], skycol[2], skycol[3] ) ;
|
||||
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ;
|
||||
|
||||
glEnable ( GL_DEPTH_TEST ) ;
|
||||
|
||||
glFogf ( GL_FOG_DENSITY, 3.0f / 100.0f ) ;
|
||||
glFogfv( GL_FOG_COLOR , skycol ) ;
|
||||
glFogf ( GL_FOG_START , 0.0 ) ;
|
||||
glFogi ( GL_FOG_MODE , GL_EXP ) ;
|
||||
glHint ( GL_FOG_HINT , GL_NICEST ) ;
|
||||
|
||||
sgCoord cam ;
|
||||
sgSetVec3 ( cam.xyz, 0, 0, 0 ) ;
|
||||
sgSetVec3 ( cam.hpr, 0, 0, 0 ) ;
|
||||
ssgSetCamera ( & cam ) ;
|
||||
|
||||
glEnable ( GL_FOG ) ;
|
||||
ssgCullAndDraw ( scene ) ;
|
||||
glDisable ( GL_FOG ) ;
|
||||
}
|
||||
|
||||
|
||||
void GFX::done ()
|
||||
{
|
||||
glutPostRedisplay () ;
|
||||
glutSwapBuffers () ;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
This file is part of TTT3D - Steve's 3D TicTacToe Player.
|
||||
Copyright (C) 2001 Steve Baker
|
||||
|
||||
TTT3D is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TTT3D is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with TTT3D; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: gfx.h 1427 2002-08-18 00:09:46Z ude $
|
||||
*/
|
||||
|
||||
|
||||
class GFX
|
||||
{
|
||||
public:
|
||||
|
||||
GFX () ;
|
||||
void update () ;
|
||||
void done () ;
|
||||
} ;
|
||||
|
||||
@@ -0,0 +1,246 @@
|
||||
/*
|
||||
This file is part of TTT3D - Steve's 3D TicTacToe Player.
|
||||
Copyright (C) 2001 Steve Baker
|
||||
|
||||
TTT3D is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TTT3D is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with TTT3D; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: gui.cxx 1465 2002-08-30 14:05:59Z wolfram_kuss $
|
||||
*/
|
||||
|
||||
|
||||
#include "p3d.h"
|
||||
#include "plib/pu.h"
|
||||
|
||||
static int mouse_x ;
|
||||
static int mouse_y ;
|
||||
static int mouse_dx = 0 ;
|
||||
static int mouse_dy = 0 ;
|
||||
static int mouse_buttons = 0 ;
|
||||
|
||||
fntTexFont *font ;
|
||||
|
||||
static void motionfn ( int x, int y )
|
||||
{
|
||||
mouse_x = x ;
|
||||
mouse_y = y ;
|
||||
mouse_dx += mouse_x - 320 ;
|
||||
mouse_dy += mouse_y - 240 ;
|
||||
puMouse ( x, y ) ;
|
||||
}
|
||||
|
||||
static void mousefn ( int button, int updown, int x, int y )
|
||||
{
|
||||
mouse_x = x ;
|
||||
mouse_y = y ;
|
||||
|
||||
if ( updown == GLUT_DOWN )
|
||||
mouse_buttons |= (1<<button) ;
|
||||
else
|
||||
mouse_buttons &= ~(1<<button) ;
|
||||
|
||||
mouse_dx += mouse_x - 320 ;
|
||||
mouse_dy += mouse_y - 240 ;
|
||||
|
||||
puMouse ( button, updown, x, y ) ;
|
||||
|
||||
if ( updown == GLUT_DOWN )
|
||||
hide_status () ;
|
||||
}
|
||||
|
||||
static void credits_cb ( puObject * )
|
||||
{
|
||||
hide_status () ;
|
||||
credits () ;
|
||||
}
|
||||
|
||||
static void versions_cb ( puObject * )
|
||||
{
|
||||
hide_status () ;
|
||||
versions () ;
|
||||
}
|
||||
|
||||
static void about_cb ( puObject * )
|
||||
{
|
||||
hide_status () ;
|
||||
about () ;
|
||||
}
|
||||
|
||||
static void help_cb ( puObject * )
|
||||
{
|
||||
hide_status () ;
|
||||
help () ;
|
||||
}
|
||||
|
||||
|
||||
static void music_off_cb ( puObject * ) { sound->disable_music () ; }
|
||||
static void music_on_cb ( puObject * ) { sound->enable_music () ; }
|
||||
static void sfx_off_cb ( puObject * ) { sound->disable_sfx () ; }
|
||||
static void sfx_on_cb ( puObject * ) { sound->enable_sfx () ; }
|
||||
|
||||
static void exit_cb ( puObject * )
|
||||
{
|
||||
fprintf ( stderr, "Exiting TTT3D.\n" ) ;
|
||||
exit ( 1 ) ;
|
||||
}
|
||||
|
||||
/* Menu bar entries: */
|
||||
|
||||
static char *exit_submenu [] = { "Exit", NULL } ;
|
||||
static puCallback exit_submenu_cb [] = { exit_cb, NULL } ;
|
||||
|
||||
static char *sound_submenu [] = { "Turn off Music", "Turn off Sounds", "Turn on Music", "Turn on Sounds", NULL } ;
|
||||
static puCallback sound_submenu_cb [] = { music_off_cb, sfx_off_cb, music_on_cb, sfx_on_cb, NULL } ;
|
||||
|
||||
static char *help_submenu [] = { "Versions...", "Credits...", "About...", "Help", NULL } ;
|
||||
static puCallback help_submenu_cb [] = { versions_cb, credits_cb, about_cb, help_cb, NULL } ;
|
||||
|
||||
|
||||
|
||||
GUI::GUI ()
|
||||
{
|
||||
hidden = TRUE ;
|
||||
mouse_x = 320 ;
|
||||
mouse_y = 240 ;
|
||||
|
||||
glutMouseFunc ( mousefn ) ;
|
||||
glutMotionFunc ( motionfn ) ;
|
||||
glutPassiveMotionFunc ( motionfn ) ;
|
||||
|
||||
ssgInit () ;
|
||||
puInit () ;
|
||||
|
||||
font = new fntTexFont ;
|
||||
font -> load ( "fonts/sorority.txf" ) ;
|
||||
puFont ff ( font, 15 ) ;
|
||||
puSetDefaultFonts ( ff, ff ) ;
|
||||
puSetDefaultStyle ( PUSTYLE_SMALL_SHADED ) ;
|
||||
puSetDefaultColourScheme ( 0.8f, 0.8f, 0.8f, 0.6f ) ;
|
||||
|
||||
/* Make the menu bar */
|
||||
|
||||
main_menu_bar = new puMenuBar () ;
|
||||
|
||||
main_menu_bar -> add_submenu ( "Exit" , exit_submenu , exit_submenu_cb ) ;
|
||||
main_menu_bar -> add_submenu ( "Sound", sound_submenu, sound_submenu_cb ) ;
|
||||
main_menu_bar -> add_submenu ( "Help" , help_submenu , help_submenu_cb ) ;
|
||||
|
||||
main_menu_bar -> close () ;
|
||||
main_menu_bar -> hide () ;
|
||||
}
|
||||
|
||||
|
||||
void GUI::show ()
|
||||
{
|
||||
hide_status () ;
|
||||
hidden = FALSE ;
|
||||
main_menu_bar -> reveal () ;
|
||||
}
|
||||
|
||||
void GUI::hide ()
|
||||
{
|
||||
hidden = TRUE ;
|
||||
hide_status () ;
|
||||
main_menu_bar -> hide () ;
|
||||
}
|
||||
|
||||
void GUI::update ()
|
||||
{
|
||||
int score = 0 ; /* INSERT SCORE-GETTER HERE */
|
||||
|
||||
keyboardInput () ;
|
||||
drawStatusText ( score ) ;
|
||||
|
||||
glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
|
||||
glAlphaFunc ( GL_GREATER, 0.1f ) ;
|
||||
glEnable ( GL_BLEND ) ;
|
||||
|
||||
puDisplay () ;
|
||||
}
|
||||
|
||||
|
||||
void GUI::keyboardInput ()
|
||||
{
|
||||
int c = getGLUTKeystroke () ;
|
||||
|
||||
if ( c <= 0 )
|
||||
return ;
|
||||
|
||||
switch ( c )
|
||||
{
|
||||
case 0x1B /* Escape */ :
|
||||
case 0x03 /* Control-C */ : exit ( 0 ) ;
|
||||
|
||||
case 'h' : hide_status () ; help () ; return ;
|
||||
|
||||
case ' ' : if ( isHidden () )
|
||||
{
|
||||
sound->playSfx ( SOUND_WHO_ELSE ) ;
|
||||
show () ;
|
||||
}
|
||||
else
|
||||
{
|
||||
sound->playSfx ( SOUND_UGH ) ;
|
||||
hide () ;
|
||||
}
|
||||
return ;
|
||||
|
||||
case 'r' :
|
||||
case 'R' : startLevel () ; return ;
|
||||
|
||||
case (256+GLUT_KEY_LEFT ) : spinLeft () ; return ;
|
||||
case (256+GLUT_KEY_RIGHT ) : spinRight () ; return ;
|
||||
case (256+GLUT_KEY_UP ) : spinUp () ; return ;
|
||||
case (256+GLUT_KEY_DOWN ) : spinDown () ; return ;
|
||||
case (256+GLUT_KEY_PAGE_UP ) : zoomIn () ; return ;
|
||||
case (256+GLUT_KEY_PAGE_DOWN ) : zoomOut () ; return ;
|
||||
|
||||
default : /* DO NOTHING */ break ;
|
||||
}
|
||||
|
||||
if ( game_state == GAME_DEBRIEF )
|
||||
{
|
||||
switch ( c )
|
||||
{
|
||||
case 'r' :
|
||||
case 'R' : startLevel () ; return ;
|
||||
default : /* DO NOTHING */ break ;
|
||||
}
|
||||
}
|
||||
|
||||
if ( game_state == GAME_RUNNING )
|
||||
{
|
||||
switch ( c )
|
||||
{
|
||||
case 'r' :
|
||||
case 'R' : startLevel () ; return ;
|
||||
|
||||
case '\n':
|
||||
case '\r': makeMove () ; return ;
|
||||
|
||||
case 'a' : puzzle->cursor_up () ; return ;
|
||||
case 'z' : puzzle->cursor_down () ; return ;
|
||||
case 's' : puzzle->cursor_in () ; return ;
|
||||
case 'd' : puzzle->cursor_out () ; return ;
|
||||
case 'x' : puzzle->cursor_left () ; return ;
|
||||
case 'c' : puzzle->cursor_right () ; return ;
|
||||
|
||||
default : /* DO NOTHING */ break ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
This file is part of TTT3D - Steve's 3D TicTacToe Player.
|
||||
Copyright (C) 2001 Steve Baker
|
||||
|
||||
TTT3D is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TTT3D is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with TTT3D; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: gui.h 1427 2002-08-18 00:09:46Z ude $
|
||||
*/
|
||||
|
||||
|
||||
class GUI
|
||||
{
|
||||
class puMenuBar *main_menu_bar ;
|
||||
|
||||
int hidden ;
|
||||
|
||||
public:
|
||||
|
||||
GUI () ;
|
||||
void update () ;
|
||||
void show () ;
|
||||
void hide () ;
|
||||
int isHidden () { return hidden ; }
|
||||
|
||||
void keyboardInput () ;
|
||||
} ;
|
||||
|
||||
|
||||
int getGLUTKeystroke () ;
|
||||
|
||||
extern fntTexFont *font ;
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
This file is part of TTT3D - Steve's 3D TicTacToe Player.
|
||||
Copyright (C) 2001 Steve Baker
|
||||
|
||||
TTT3D is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TTT3D is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with TTT3D; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: level.h 1427 2002-08-18 00:09:46Z ude $
|
||||
*/
|
||||
|
||||
|
||||
class Level
|
||||
{
|
||||
int number ;
|
||||
char *intro ;
|
||||
} ;
|
||||
|
||||
|
||||
#define GAME_INTRO 0
|
||||
#define GAME_RUNNING 1
|
||||
#define GAME_DEBRIEF 2
|
||||
#define GAME_START_OF_DAY 3
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
This file is part of TTT3D - Steve's 3D TicTacToe Player.
|
||||
Copyright (C) 2001 Steve Baker
|
||||
|
||||
TTT3D is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TTT3D is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with TTT3D; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: material.cxx 1465 2002-08-30 14:05:59Z wolfram_kuss $
|
||||
*/
|
||||
|
||||
|
||||
#include "p3d.h"
|
||||
|
||||
ssgSimpleState *default_gst, *O_gst, *X_gst, *ground_gst, *ctrls_gst ;
|
||||
|
||||
static Material gs_setup [] =
|
||||
{
|
||||
/* gst texture_map clamp, trans,aref,light,frctn,0 */
|
||||
{ &default_gst, "", FALSE, TRUE , 0.0f, FALSE, 1.0, 0 },
|
||||
{ & ground_gst, "images/ground.rgb", FALSE, FALSE, 0.2f, FALSE, 1.0, 0 },
|
||||
{ & ctrls_gst, "images/controls.rgb",FALSE, TRUE , 0.2f, FALSE, 1.0, 0 },
|
||||
{ & X_gst, "images/X.rgb" , FALSE, FALSE, 0.2f, TRUE , 1.0, 0 },
|
||||
{ & O_gst, "images/O.rgb" , FALSE, FALSE, 0.2f, TRUE , 1.0, 0 },
|
||||
{ NULL, "", FALSE, FALSE, 0.0, FALSE, 1.0, 0 }
|
||||
} ;
|
||||
|
||||
|
||||
void Material::install ( int index )
|
||||
{
|
||||
*gst = new ssgSimpleState ;
|
||||
|
||||
(*gst) -> ref () ;
|
||||
(*gst) -> setExternalPropertyIndex ( index ) ;
|
||||
|
||||
if ( texture_map [ 0 ] != '\0' )
|
||||
{
|
||||
(*gst) -> setTexture ( texture_map, !clamp_tex, !clamp_tex ) ;
|
||||
(*gst) -> enable ( GL_TEXTURE_2D ) ;
|
||||
}
|
||||
else
|
||||
(*gst) -> disable ( GL_TEXTURE_2D ) ;
|
||||
|
||||
if ( lighting )
|
||||
(*gst) -> enable ( GL_LIGHTING ) ;
|
||||
else
|
||||
(*gst) -> disable ( GL_LIGHTING ) ;
|
||||
|
||||
(*gst) -> setShadeModel ( GL_SMOOTH ) ;
|
||||
(*gst) -> disable ( GL_COLOR_MATERIAL ) ;
|
||||
(*gst) -> enable ( GL_CULL_FACE ) ;
|
||||
(*gst) -> setColourMaterial ( GL_AMBIENT_AND_DIFFUSE ) ;
|
||||
(*gst) -> setMaterial ( GL_AMBIENT, 0.3f, 0.3f, 0.3f, 1 ) ;
|
||||
(*gst) -> setMaterial ( GL_DIFFUSE, 1, 1, 1, 1 ) ;
|
||||
(*gst) -> setMaterial ( GL_EMISSION, 0, 0, 0, 1 ) ;
|
||||
(*gst) -> setMaterial ( GL_SPECULAR, 0, 0, 0, 1 ) ;
|
||||
(*gst) -> setShininess ( 0 ) ;
|
||||
|
||||
if ( transparency )
|
||||
{
|
||||
(*gst) -> setTranslucent () ;
|
||||
(*gst) -> enable ( GL_ALPHA_TEST ) ;
|
||||
(*gst) -> setAlphaClamp ( alpha_ref ) ;
|
||||
(*gst) -> enable ( GL_BLEND ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
(*gst) -> setOpaque () ;
|
||||
(*gst) -> disable ( GL_BLEND ) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static ssgState *getAppState ( char *fname )
|
||||
{
|
||||
if ( fname == NULL || fname[0] == '\0' )
|
||||
return gs_setup [ 0 ] . getState() ;
|
||||
|
||||
char *fn ;
|
||||
|
||||
/* Remove all leading path information. */
|
||||
|
||||
for ( fn = & fname [ strlen ( fname ) - 1 ] ; fn != fname &&
|
||||
*fn != '/' ; fn-- )
|
||||
/* Search back for a '/' */ ;
|
||||
|
||||
if ( *fn == '/' )
|
||||
fn++ ;
|
||||
|
||||
char basename [ 1024 ] ;
|
||||
|
||||
strcpy ( basename, fn ) ;
|
||||
|
||||
/* Remove last trailing extension. */
|
||||
|
||||
for ( fn = & basename [ strlen ( basename ) - 1 ] ; fn != basename &&
|
||||
*fn != '.' ; fn-- )
|
||||
/* Search back for a '.' */ ;
|
||||
|
||||
if ( *fn == '.' )
|
||||
*fn = '\0' ;
|
||||
|
||||
for ( int i = 0 ; ! gs_setup [ i ] . isNull () ; i++ )
|
||||
{
|
||||
char *fname2 = gs_setup [ i ] . getTexFname () ;
|
||||
|
||||
if ( fname2 != NULL && fname2[0] != '\0' )
|
||||
{
|
||||
char *fn2 ;
|
||||
|
||||
/* Remove all leading path information. */
|
||||
|
||||
for ( fn2 = & fname2 [ strlen ( fname2 ) -1 ] ; fn2 != fname2 &&
|
||||
*fn2 != '/' ; fn2-- )
|
||||
/* Search back for a '/' */ ;
|
||||
|
||||
if ( *fn2 == '/' )
|
||||
fn2++ ;
|
||||
|
||||
char basename2 [ 1024 ] ;
|
||||
|
||||
strcpy ( basename2, fn2 ) ;
|
||||
|
||||
/* Remove last trailing extension. */
|
||||
|
||||
for ( fn2 = & basename2 [ strlen ( basename2 ) - 1 ] ; fn2 != basename2 &&
|
||||
*fn2 != '.' ; fn2-- )
|
||||
/* Search back for a '.' */ ;
|
||||
|
||||
if ( *fn2 == '.' )
|
||||
*fn2 = '\0' ;
|
||||
|
||||
if ( strcmp ( basename, basename2 ) == 0 )
|
||||
return gs_setup [ i ] . getState() ;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void initMaterials ()
|
||||
{
|
||||
for ( int i = 0 ; ! gs_setup [ i ] . isNull () ; i++ )
|
||||
gs_setup [ i ] . install ( i ) ;
|
||||
|
||||
ssgSetAppStateCallback ( getAppState ) ;
|
||||
}
|
||||
|
||||
|
||||
/*Material *getMaterial ( ssgState *s )
|
||||
{
|
||||
return & ( gs_setup [ s -> getExternalPropertyIndex () ] ) ;
|
||||
}
|
||||
|
||||
|
||||
Material *getMaterial ( ssgLeaf *l )
|
||||
{
|
||||
return getMaterial ( l -> getState () ) ;
|
||||
}*/
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
This file is part of TTT3D - Steve's 3D TicTacToe Player.
|
||||
Copyright (C) 2001 Steve Baker
|
||||
|
||||
TTT3D is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TTT3D is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with TTT3D; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: material.h 1427 2002-08-18 00:09:46Z ude $
|
||||
*/
|
||||
|
||||
|
||||
struct Material
|
||||
{
|
||||
public:
|
||||
ssgSimpleState **gst ;
|
||||
|
||||
char *texture_map ;
|
||||
int clamp_tex ;
|
||||
int transparency ;
|
||||
float alpha_ref ;
|
||||
int lighting ;
|
||||
float friction ;
|
||||
unsigned int flags ;
|
||||
|
||||
int isNull () { return gst == NULL ; } ;
|
||||
void install ( int index ) ;
|
||||
|
||||
ssgState *getState () { return *gst ; }
|
||||
char *getTexFname () { return texture_map ; }
|
||||
} ;
|
||||
|
||||
|
||||
void initMaterials () ;
|
||||
/*Material *getMaterial ( ssgState *s ) ;
|
||||
Material *getMaterial ( ssgLeaf *l ) ;*/
|
||||
|
||||
extern ssgSimpleState *default_gst, *O_gst, *X_gst, *ground_gst, *ctrls_gst ;
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
This file is part of TTT3D - Steve's 3D TicTacToe Player.
|
||||
Copyright (C) 2001 Steve Baker
|
||||
|
||||
TTT3D is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TTT3D is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with TTT3D; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: p3d.h 1687 2002-09-15 17:54:09Z ude $
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <math.h>
|
||||
|
||||
#include <plib/ssg.h>
|
||||
|
||||
#ifdef FREEGLUT_IS_PRESENT
|
||||
# include <GL/freeglut.h>
|
||||
#else
|
||||
# ifdef __APPLE__
|
||||
# include <GLUT/glut.h>
|
||||
# else
|
||||
# include <GL/glut.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include <plib/sl.h>
|
||||
#include <plib/fnt.h>
|
||||
|
||||
#ifndef M_PI
|
||||
# define M_PI 3.14159265
|
||||
#endif
|
||||
|
||||
#include "game.h"
|
||||
|
||||
class GFX ;
|
||||
class GUI ;
|
||||
class SoundSystem ;
|
||||
class Puzzle ;
|
||||
class Cell ;
|
||||
class Level ;
|
||||
|
||||
extern GFX *gfx ;
|
||||
extern GUI *gui ;
|
||||
extern SoundSystem *sound ;
|
||||
extern Puzzle *puzzle ;
|
||||
extern Level level ;
|
||||
|
||||
extern int game_state ;
|
||||
|
||||
extern ssgRoot *scene ;
|
||||
//extern const char *ttt3d_datadir ;
|
||||
|
||||
void startLevel () ;
|
||||
void makeMove () ;
|
||||
void ttt3dMainLoop () ;
|
||||
void initMaterials () ;
|
||||
|
||||
#include "level.h"
|
||||
#include "gfx.h"
|
||||
#include "gui.h"
|
||||
#include "material.h"
|
||||
#include "status.h"
|
||||
#include "sound.h"
|
||||
#include "cell.h"
|
||||
#include "puzzle.h"
|
||||
|
||||
void spinUp () ;
|
||||
void spinDown () ;
|
||||
void spinLeft () ;
|
||||
void spinRight () ;
|
||||
void zoomIn () ;
|
||||
void zoomOut () ;
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
This file is part of TTT3D - Steve's 3D TicTacToe Player.
|
||||
Copyright (C) 2001 Steve Baker
|
||||
|
||||
TTT3D is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TTT3D is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with TTT3D; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: puzzle.cxx 1427 2002-08-18 00:09:46Z ude $
|
||||
*/
|
||||
|
||||
|
||||
#include "p3d.h"
|
||||
|
||||
static int size[3] ;
|
||||
|
||||
|
||||
Puzzle::Puzzle ()
|
||||
{
|
||||
size[0] = 4 ;
|
||||
size[1] = 4 ;
|
||||
size[2] = 4 ;
|
||||
|
||||
sgSetCoord ( &pos, 0, 0, 0, 0, 0, 0 ) ;
|
||||
|
||||
ground = makeGround () ;
|
||||
selector = makeBlueWireCube () ;
|
||||
|
||||
spin = new ssgTransform ( &pos ) ;
|
||||
spin -> addKid ( ground ) ;
|
||||
spin -> addKid ( selector ) ;
|
||||
|
||||
sel [ 0 ] = 0 ;
|
||||
sel [ 1 ] = 0 ;
|
||||
sel [ 2 ] = 0 ;
|
||||
|
||||
for ( int x = 0 ; x < size [ 0 ] ; x++ )
|
||||
for ( int y = 0 ; y < size [ 1 ] ; y++ )
|
||||
for ( int z = 0 ; z < size [ 2 ] ; z++ )
|
||||
{
|
||||
cell[x][y][z] = new Cell ( x, y, z, size[0] ) ;
|
||||
spin -> addKid ( cell[x][y][z]->getSSG() ) ;
|
||||
}
|
||||
|
||||
reset () ;
|
||||
}
|
||||
|
||||
|
||||
void Puzzle::reset ()
|
||||
{
|
||||
cursor ( 0, 0, 0 ) ;
|
||||
sgSetCoord ( &pos, 0, 0, 0, 0, 0, 0 ) ;
|
||||
|
||||
for ( int x = 0 ; x < size [ 0 ] ; x++ )
|
||||
for ( int y = 0 ; y < size [ 1 ] ; y++ )
|
||||
for ( int z = 0 ; z < size [ 2 ] ; z++ )
|
||||
cell[x][y][z]->set(WIRE_CELL) ;
|
||||
|
||||
setGameState ( STILL_PLAYING ) ;
|
||||
game_init () ;
|
||||
}
|
||||
|
||||
|
||||
void Puzzle::update ()
|
||||
{
|
||||
static int flasher = 0 ;
|
||||
sgCoord spos ;
|
||||
sgSetVec3 ( spos.hpr, 0, 0, 0 ) ;
|
||||
|
||||
flasher++ ;
|
||||
if ( flasher > 5 )
|
||||
sgSetVec3 ( spos.xyz, (float)sel[0] - (float)size[0]/2.0f + 0.51f,
|
||||
(float)sel[1] - (float)size[1]/2.0f + 0.51f,
|
||||
(float)sel[2] - (float)size[2]/2.0f + 0.51f ) ;
|
||||
else
|
||||
sgSetVec3 ( spos.xyz, 1000000, 1000000, 1000000 ) ;
|
||||
|
||||
if ( flasher > 60 )
|
||||
flasher = 0 ;
|
||||
|
||||
selector -> setTransform ( & spos ) ;
|
||||
}
|
||||
|
||||
|
||||
Puzzle::~Puzzle ()
|
||||
{
|
||||
delete spin ;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
This file is part of TTT3D - Steve's 3D TicTacToe Player.
|
||||
Copyright (C) 2001 Steve Baker
|
||||
|
||||
TTT3D is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TTT3D is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with TTT3D; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: puzzle.h 1427 2002-08-18 00:09:46Z ude $
|
||||
*/
|
||||
|
||||
|
||||
#define MAX_GRID 4
|
||||
|
||||
|
||||
class Puzzle
|
||||
{
|
||||
sgCoord pos ;
|
||||
|
||||
int sel [ 3 ] ;
|
||||
|
||||
ssgTransform *spin ;
|
||||
ssgTransform *selector ;
|
||||
ssgTransform *ground ;
|
||||
|
||||
Cell *cell [ MAX_GRID ][ MAX_GRID ][ MAX_GRID ] ;
|
||||
|
||||
int game_state ;
|
||||
|
||||
public:
|
||||
Puzzle () ;
|
||||
~Puzzle () ;
|
||||
|
||||
void reset () ;
|
||||
void update () ;
|
||||
|
||||
int getGameState () { return game_state ; }
|
||||
void setGameState ( int gs ) { game_state = gs ; }
|
||||
|
||||
int gameOver () { return game_state != STILL_PLAYING ; }
|
||||
|
||||
void cursor ( int x, int y, int z )
|
||||
{
|
||||
sel[0] = x & 3 ;
|
||||
sel[1] = y & 3 ;
|
||||
sel[2] = z & 3 ;
|
||||
}
|
||||
|
||||
int getCx () { return sel[0] ; }
|
||||
int getCy () { return sel[1] ; }
|
||||
int getCz () { return sel[2] ; }
|
||||
|
||||
void step_up () { pos . xyz [ 1 ] += 0.5f ; spin->setTransform(&pos); }
|
||||
void step_down () { pos . xyz [ 1 ] -= 0.5f ; spin->setTransform(&pos); }
|
||||
void spin_up () { pos . hpr [ 2 ] += 5.0f ; spin->setTransform(&pos); }
|
||||
void spin_down () { pos . hpr [ 2 ] -= 5.0f ; spin->setTransform(&pos); }
|
||||
void spin_left () { pos . hpr [ 0 ] -= 5.0f ; spin->setTransform(&pos); }
|
||||
void spin_right () { pos . hpr [ 0 ] += 5.0f ; spin->setTransform(&pos); }
|
||||
|
||||
void cursor_up () { cursor(sel[0],sel[1],sel[2]+1) ; }
|
||||
void cursor_down () { cursor(sel[0],sel[1],sel[2]-1) ; }
|
||||
void cursor_in () { cursor(sel[0],sel[1]+1,sel[2]) ; }
|
||||
void cursor_out () { cursor(sel[0],sel[1]-1,sel[2]) ; }
|
||||
void cursor_left () { cursor(sel[0]-1,sel[1],sel[2]) ; }
|
||||
void cursor_right () { cursor(sel[0]+1,sel[1],sel[2]) ; }
|
||||
|
||||
void put_empty() { cell[sel[0]][sel[1]][sel[2]]->set(WIRE_CELL) ; }
|
||||
void put_X () { cell[sel[0]][sel[1]][sel[2]]->set( X_CELL) ; }
|
||||
void put_O () { cell[sel[0]][sel[1]][sel[2]]->set( O_CELL) ; }
|
||||
|
||||
void put_empty ( int x, int y, int z ) { cell[x][y][z] -> set (WIRE_CELL);}
|
||||
void put_X ( int x, int y, int z ) { cell[x][y][z] -> set ( X_CELL) ; }
|
||||
void put_O ( int x, int y, int z ) { cell[x][y][z] -> set ( O_CELL) ; }
|
||||
|
||||
ssgTransform *getSSG () { return spin ; }
|
||||
} ;
|
||||
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
This file is part of TTT3D - Steve's 3D TicTacToe Player.
|
||||
Copyright (C) 2001 Steve Baker
|
||||
|
||||
TTT3D is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TTT3D is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with TTT3D; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: sound.cxx 1427 2002-08-18 00:09:46Z ude $
|
||||
*/
|
||||
|
||||
|
||||
#include "p3d.h"
|
||||
|
||||
struct Sound
|
||||
{
|
||||
const char *fname ;
|
||||
slSample *s ;
|
||||
} ;
|
||||
|
||||
|
||||
static Sound sfx [] =
|
||||
{
|
||||
{ "wavs/ahooga.wav" , NULL },
|
||||
{ "wavs/clap.wav" , NULL },
|
||||
{ "wavs/frog.wav" , NULL },
|
||||
{ "wavs/glasbk.wav" , NULL },
|
||||
{ "wavs/pop.wav" , NULL },
|
||||
{ "wavs/ugh.wav" , NULL },
|
||||
{ "wavs/who_else.wav" , NULL },
|
||||
{ NULL, NULL }
|
||||
} ;
|
||||
|
||||
static int music_off = FALSE ;
|
||||
static int sfx_off = FALSE ;
|
||||
|
||||
void SoundSystem::disable_music ()
|
||||
{
|
||||
sched -> stopMusic () ;
|
||||
sched -> update () ; /* Ugh! Nasty Kludge! */
|
||||
sched -> update () ; /* Ugh! Nasty Kludge! */
|
||||
|
||||
music_off = TRUE ;
|
||||
}
|
||||
|
||||
|
||||
void SoundSystem::change_track ( const char *fname )
|
||||
{
|
||||
if ( fname == NULL )
|
||||
fname = "" ;
|
||||
|
||||
if ( strcmp ( fname, current_track ) != 0 )
|
||||
{
|
||||
strcpy ( current_track, fname ) ;
|
||||
|
||||
if ( ! music_off )
|
||||
enable_music () ;
|
||||
}
|
||||
}
|
||||
|
||||
void SoundSystem::enable_music ()
|
||||
{
|
||||
sched -> stopMusic () ;
|
||||
|
||||
if ( current_track [ 0 ] != '\0' )
|
||||
sched -> loopMusic ( current_track ) ;
|
||||
|
||||
music_off = FALSE ;
|
||||
}
|
||||
|
||||
|
||||
void SoundSystem::disable_sfx () { sfx_off = TRUE ; }
|
||||
void SoundSystem:: enable_sfx () { sfx_off = FALSE ; }
|
||||
|
||||
|
||||
|
||||
void SoundSystem::playSfx ( int sfx_num )
|
||||
{
|
||||
if ( ! sfx_off )
|
||||
sched -> playSample ( sfx[sfx_num].s, 1, SL_SAMPLE_MUTE, 2, NULL ) ;
|
||||
}
|
||||
|
||||
|
||||
SoundSystem::SoundSystem ()
|
||||
{
|
||||
sched = new slScheduler ;
|
||||
|
||||
setSafetyMargin () ;
|
||||
|
||||
for ( Sound *currsfx = &(sfx[0]) ; currsfx -> fname != NULL ; currsfx++ )
|
||||
currsfx -> s = new slSample ( currsfx -> fname, sched ) ;
|
||||
|
||||
enable_sfx () ;
|
||||
change_track ( "" ) ;
|
||||
enable_music () ;
|
||||
}
|
||||
|
||||
|
||||
void SoundSystem::update ()
|
||||
{
|
||||
/*
|
||||
Comment this next line out if the
|
||||
sound causes big glitches on your
|
||||
IRIX machine!
|
||||
*/
|
||||
|
||||
sched -> update () ;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
This file is part of TTT3D - Steve's 3D TicTacToe Player.
|
||||
Copyright (C) 2001 Steve Baker
|
||||
|
||||
TTT3D is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TTT3D is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with TTT3D; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: sound.h 1427 2002-08-18 00:09:46Z ude $
|
||||
*/
|
||||
|
||||
|
||||
#define SOUND_AHOOGA 0
|
||||
#define SOUND_CLAP 1
|
||||
#define SOUND_FROG 2
|
||||
#define SOUND_GLASBK 3
|
||||
#define SOUND_POP 4
|
||||
#define SOUND_UGH 5
|
||||
#define SOUND_WHO_ELSE 6
|
||||
|
||||
class SoundSystem
|
||||
{
|
||||
char current_track [ 256 ] ;
|
||||
slScheduler *sched ;
|
||||
|
||||
public:
|
||||
SoundSystem () ;
|
||||
|
||||
void update () ;
|
||||
void playSfx ( int sound ) ;
|
||||
|
||||
void setSafetyMargin ( float t = 0.25 )
|
||||
{
|
||||
sched -> setSafetyMargin ( t ) ;
|
||||
}
|
||||
|
||||
void change_track ( const char *fname ) ;
|
||||
void disable_music () ;
|
||||
void enable_music () ;
|
||||
|
||||
void disable_sfx () ;
|
||||
void enable_sfx () ;
|
||||
} ;
|
||||
|
||||
@@ -0,0 +1,358 @@
|
||||
/*
|
||||
This file is part of TTT3D - Steve's 3D TicTacToe Player.
|
||||
Copyright (C) 2001 Steve Baker
|
||||
|
||||
TTT3D is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TTT3D is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with TTT3D; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: status.cxx 2100 2006-11-03 22:31:54Z fayjf $
|
||||
*/
|
||||
|
||||
|
||||
#include "p3d.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
#define MAX_STRING 30
|
||||
#define MAX_STRING_LENGTH 256
|
||||
|
||||
static int displayed_score = 0 ;
|
||||
|
||||
static fntRenderer *text = NULL ;
|
||||
|
||||
char debug_strings [ MAX_STRING ][ MAX_STRING_LENGTH ] ;
|
||||
/*int next_string = 0 ;
|
||||
int stats_enabled = FALSE ;*/
|
||||
|
||||
static int about_timer = 99999 ;
|
||||
static int versions_timer = 99999 ;
|
||||
static int credits_timer = 99999 ;
|
||||
static int intro_timer = 0 ;
|
||||
static int help_timer = 99999 ;
|
||||
|
||||
void hide_status () { versions_timer = credits_timer =
|
||||
intro_timer = help_timer = about_timer = 99999 ; }
|
||||
void about () { about_timer = 0 ; }
|
||||
void credits () { credits_timer = 0 ; }
|
||||
void versions () { versions_timer = 0 ; }
|
||||
void help () { help_timer = 0 ; }
|
||||
|
||||
static void drawText ( const char *str, int sz, int x, int y )
|
||||
{
|
||||
text -> setFont ( font ) ;
|
||||
text -> setPointSize ( (float)sz ) ;
|
||||
|
||||
text -> begin () ;
|
||||
text -> start2f ( (float)x, (float)y ) ;
|
||||
text -> puts ( str ) ;
|
||||
text -> end () ;
|
||||
}
|
||||
|
||||
|
||||
static void drawInverseDropShadowText ( const char *str, int sz, int x, int y )
|
||||
{
|
||||
glColor4f ( 1.0f, 1.0f, 1.0f, 1.0f ) ;
|
||||
drawText ( str, sz, x, y ) ;
|
||||
glColor4f ( 0.0f, 0.0f, 0.0f, 1.0f ) ;
|
||||
drawText ( str, sz, x+1, y+1 ) ;
|
||||
}
|
||||
|
||||
|
||||
static void drawDropShadowText ( const char *str, int sz, int x, int y )
|
||||
{
|
||||
glColor4f ( 0.0f, 0.0f, 0.0f, 1.0f ) ;
|
||||
|
||||
drawText ( str, sz, x, y ) ;
|
||||
|
||||
glColor4f ( 1.0f, 1.0f, 1.0f, 1.0f ) ;
|
||||
|
||||
drawText ( str, sz, x+1, y+1 ) ;
|
||||
}
|
||||
|
||||
|
||||
static void drawHelpText ()
|
||||
{
|
||||
drawDropShadowText ( "Press SPACE to toggle the menu.", 18, 70, 400 ) ;
|
||||
drawDropShadowText ( "Press ESCAPE to exit the game.", 18, 70, 370 ) ;
|
||||
drawDropShadowText ( "Use arrow keys and PgUp,PgDown,Home,End,Ins", 18, 70, 340 ) ;
|
||||
drawDropShadowText ( " or Del to move the grid around.", 18, 70, 310 ) ;
|
||||
drawDropShadowText ( "Move the current pipe with A,S,Z,W,E,X", 18, 70, 280 ) ;
|
||||
}
|
||||
|
||||
|
||||
static void drawTitleText ()
|
||||
{
|
||||
drawDropShadowText ( "TTT3D", 20, 70, 400 ) ;
|
||||
drawDropShadowText ( "By Steve Baker", 12, 170, 385 ) ;
|
||||
}
|
||||
|
||||
|
||||
static void drawIntroText ()
|
||||
{
|
||||
drawTitleText () ;
|
||||
|
||||
if ( intro_timer & 8 )
|
||||
drawDropShadowText ( "Press SPACE bar for menu.",
|
||||
15, 10, 430 ) ;
|
||||
}
|
||||
|
||||
|
||||
static const char *aboutText [] =
|
||||
{
|
||||
" Yada, yada, yada.",
|
||||
NULL
|
||||
} ;
|
||||
|
||||
|
||||
static void drawVersionsText ()
|
||||
{
|
||||
char str [ 256 ] ;
|
||||
|
||||
#ifdef VERSION
|
||||
sprintf ( str, "TTT3D: Version: %s", VERSION ) ;
|
||||
#else
|
||||
sprintf ( str, "TTT3D: Unknown Version." ) ;
|
||||
#endif
|
||||
drawDropShadowText ( str, 15, 20, 250 ) ;
|
||||
|
||||
sprintf ( str, "PLIB Version: %s", ssgGetVersion() ) ;
|
||||
drawDropShadowText ( str, 15, 20, 225 ) ;
|
||||
|
||||
sprintf ( str, "OpenGL Version: %s", glGetString ( GL_VERSION ) ) ;
|
||||
drawDropShadowText ( str, 15, 20, 200 ) ;
|
||||
|
||||
sprintf ( str, "OpenGL Vendor: %s", glGetString ( GL_VENDOR ) ) ;
|
||||
drawDropShadowText ( str, 15, 20, 175 ) ;
|
||||
|
||||
sprintf ( str, "OpenGL Renderer: %s", glGetString ( GL_RENDERER ) ) ;
|
||||
|
||||
if ( strlen ( str ) > 50 )
|
||||
{
|
||||
int l = strlen ( str ) ;
|
||||
int ll = 0 ;
|
||||
|
||||
for ( int i = 0 ; i < l ; i++, ll++ )
|
||||
{
|
||||
if ( ll > 40 && str[i] == ' ' )
|
||||
{
|
||||
str[i] = '\n' ;
|
||||
ll = 0 ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
drawDropShadowText ( str, 15, 20, 150 ) ;
|
||||
|
||||
if ( versions_timer & 8 )
|
||||
drawDropShadowText ( "Press SPACE to continue",
|
||||
15, 10, 430 ) ;
|
||||
}
|
||||
|
||||
|
||||
static void drawAboutText ()
|
||||
{
|
||||
drawTitleText () ;
|
||||
|
||||
for ( int i = 0 ; aboutText [ i ] != NULL ; i++ )
|
||||
drawDropShadowText ( aboutText [ i ],
|
||||
10, 40, 230 - 10 * i ) ;
|
||||
|
||||
if ( about_timer & 8 )
|
||||
drawDropShadowText ( "Press SPACE to continue",
|
||||
15, 10, 430 ) ;
|
||||
}
|
||||
|
||||
|
||||
static const char *creditsText [] =
|
||||
{
|
||||
" Steve Baker - Coding, design, bug insertion.",
|
||||
NULL
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
static void drawCreditsText ()
|
||||
{
|
||||
drawTitleText () ;
|
||||
|
||||
drawDropShadowText ( "Credits:",
|
||||
20, 70, 250 ) ;
|
||||
|
||||
for ( int i = 0 ; creditsText [ i ] != NULL ; i++ )
|
||||
drawDropShadowText ( creditsText [ i ],
|
||||
12, 100, 230 - 12 * i ) ;
|
||||
|
||||
if ( credits_timer & 8 )
|
||||
drawDropShadowText ( "Press SPACE to continue",
|
||||
15, 10, 430 ) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void drawScore ()
|
||||
{
|
||||
if ( displayed_score > 0 )
|
||||
{
|
||||
char str [ 20 ] ;
|
||||
sprintf ( str, "%9d", displayed_score ) ;
|
||||
drawDropShadowText ( str, 18, 500, 410 ) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void drawInGameScore ()
|
||||
{
|
||||
char str [ 50 ] ;
|
||||
|
||||
sprintf ( str, "TicTacToe 3D" ) ;
|
||||
drawInverseDropShadowText ( str, 18, 360, 460 ) ;
|
||||
|
||||
sprintf ( str, "A,Z : Move UP or DOWN" ) ;
|
||||
drawDropShadowText ( str, 18, 360, 420 ) ;
|
||||
sprintf ( str, "S,D,X,C : Move Sideways" ) ;
|
||||
drawDropShadowText ( str, 18, 360, 400 ) ;
|
||||
sprintf ( str, "Enter : Play at cursor" ) ;
|
||||
drawDropShadowText ( str, 18, 360, 380 ) ;
|
||||
sprintf ( str, "Arrow Keys : Spin Board" ) ;
|
||||
drawDropShadowText ( str, 18, 360, 360 ) ;
|
||||
|
||||
sprintf ( str, "Four in a row to win" ) ;
|
||||
drawInverseDropShadowText ( str, 18, 60, 420 ) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void drawGameOverText ( int score )
|
||||
{
|
||||
static int timer = 0 ;
|
||||
|
||||
displayed_score = score ;
|
||||
|
||||
drawTitleText () ;
|
||||
drawScore () ;
|
||||
|
||||
glColor4f ( (float)sin ( (float)timer/5.1f ) / 2.0f + 0.5f,
|
||||
(float)sin ( (float)timer/6.3f ) / 2.0f + 0.5f,
|
||||
(float)sin ( (float)timer/7.2f ) / 2.0f + 0.5f, 0.5 ) ;
|
||||
|
||||
|
||||
switch ( puzzle -> getGameState () )
|
||||
{
|
||||
case STILL_PLAYING : break ;
|
||||
|
||||
case HUMAN_WIN : drawText ( "YOU" , 50, 220, 230 ) ;
|
||||
drawText ( "WON!", 50, 150, 180 ) ;
|
||||
break ;
|
||||
|
||||
case COMPUTER_WIN : drawText ( "YOU" , 50, 220, 230 ) ;
|
||||
drawText ( "LOSE!", 50, 150, 180 ) ;
|
||||
break ;
|
||||
|
||||
case DRAWN_GAME : drawText ( "ITS A", 50, 220, 230 ) ;
|
||||
drawText ( "DRAW!", 50, 150, 180 ) ;
|
||||
break ;
|
||||
}
|
||||
|
||||
if ( timer++ & 8 )
|
||||
{
|
||||
drawDropShadowText ( "Press R to reset and play again", 15, 10, 30 ) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void drawGameIntroText ()
|
||||
{
|
||||
static int timer = 0 ;
|
||||
|
||||
if ( timer++ & 8 )
|
||||
drawDropShadowText ( "Press S to start", 15, 10, 430 ) ;
|
||||
|
||||
if ( help_timer++ < 400 )
|
||||
drawHelpText () ;
|
||||
else
|
||||
if ( intro_timer++ < 400 )
|
||||
drawIntroText () ;
|
||||
else
|
||||
if ( credits_timer++ < 1600 )
|
||||
drawCreditsText () ;
|
||||
else
|
||||
if ( about_timer++ < 1600 )
|
||||
drawAboutText () ;
|
||||
else
|
||||
if ( versions_timer++ < 1600 )
|
||||
drawVersionsText () ;
|
||||
}
|
||||
|
||||
|
||||
static void drawGameRunningText ( int score )
|
||||
{
|
||||
displayed_score = score ;
|
||||
drawInGameScore () ;
|
||||
|
||||
glColor4f ( 0.6f, 0.0f, 0.6f, 1.0f ) ;
|
||||
|
||||
if ( help_timer++ < 400 )
|
||||
drawHelpText () ;
|
||||
else
|
||||
if ( credits_timer++ < 1600 )
|
||||
drawCreditsText () ;
|
||||
else
|
||||
if ( about_timer++ < 1600 )
|
||||
drawAboutText () ;
|
||||
else
|
||||
if ( versions_timer++ < 1600 )
|
||||
drawVersionsText () ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void drawStatusText ( int score )
|
||||
{
|
||||
if ( text == NULL )
|
||||
text = new fntRenderer () ;
|
||||
|
||||
glMatrixMode ( GL_MODELVIEW ) ;
|
||||
glPushMatrix () ;
|
||||
glLoadIdentity () ;
|
||||
|
||||
glMatrixMode ( GL_PROJECTION ) ;
|
||||
glPushMatrix () ;
|
||||
glLoadIdentity () ;
|
||||
|
||||
glPushAttrib ( GL_ENABLE_BIT | GL_LIGHTING_BIT ) ;
|
||||
glDisable ( GL_DEPTH_TEST ) ;
|
||||
glDisable ( GL_LIGHTING ) ;
|
||||
glDisable ( GL_FOG ) ;
|
||||
glDisable ( GL_CULL_FACE ) ;
|
||||
glDisable ( GL_ALPHA_TEST ) ;
|
||||
glEnable ( GL_BLEND ) ;
|
||||
|
||||
glOrtho ( 0, 640, 0, 480, 0, 100 ) ;
|
||||
|
||||
switch ( game_state )
|
||||
{
|
||||
case GAME_INTRO : drawGameIntroText () ; break ;
|
||||
case GAME_DEBRIEF : drawGameOverText ( score ) ; break ;
|
||||
case GAME_RUNNING : drawGameRunningText ( score ) ; break ;
|
||||
}
|
||||
|
||||
glPopAttrib () ;
|
||||
glPopMatrix () ;
|
||||
glMatrixMode ( GL_MODELVIEW ) ;
|
||||
glPopMatrix () ;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
This file is part of TTT3D - Steve's 3D TicTacToe Player.
|
||||
Copyright (C) 2001 Steve Baker
|
||||
|
||||
TTT3D is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TTT3D is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with TTT3D; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: status.h 1427 2002-08-18 00:09:46Z ude $
|
||||
*/
|
||||
|
||||
|
||||
void drawStatusText ( int score ) ;
|
||||
|
||||
/*void stPrintf ( char *fmt, ... ) ;
|
||||
void stToggle () ;*/
|
||||
|
||||
//void memorial () ;
|
||||
void about () ;
|
||||
void credits () ;
|
||||
void versions () ;
|
||||
void help () ;
|
||||
void hide_status () ;
|
||||
|
||||
/*double read_time_of_day () ;
|
||||
void start_stopwatch () ;
|
||||
|
||||
extern int time_out ;*/
|
||||
@@ -0,0 +1,286 @@
|
||||
/*
|
||||
This file is part of TTT3D - Steve's 3D TicTacToe Player.
|
||||
Copyright (C) 2001 Steve Baker
|
||||
|
||||
TTT3D is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TTT3D is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with TTT3D; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: ttt3d.cxx 1480 2002-08-31 08:05:49Z wolfram_kuss $
|
||||
*/
|
||||
|
||||
|
||||
#include "p3d.h"
|
||||
#include <signal.h>
|
||||
|
||||
#if defined(WIN32) && !defined(__CYGWIN__)
|
||||
# include <io.h>
|
||||
# include <direct.h>
|
||||
|
||||
# define access _access
|
||||
# define chdir _chdir
|
||||
# define F_OK 04
|
||||
#endif
|
||||
|
||||
static const char *ttt3d_datadir = NULL ;
|
||||
GFX *gfx = NULL ;
|
||||
GUI *gui = NULL ;
|
||||
SoundSystem *sound = NULL ;
|
||||
ssgRoot *scene = NULL ;
|
||||
static ssgTransform *spin = NULL ;
|
||||
Puzzle *puzzle = NULL ;
|
||||
static float spin_rot = 0.0f ;
|
||||
static float spin_alt = 0.0f ;
|
||||
static float spin_pit = 0.0f ;
|
||||
static float zoom = 60.0f ;
|
||||
int game_state = GAME_START_OF_DAY ;
|
||||
|
||||
Level level ;
|
||||
|
||||
static void banner ()
|
||||
{
|
||||
printf ( "\n\n" ) ;
|
||||
printf ( " TTT3D.\n" ) ;
|
||||
printf ( "\n" ) ;
|
||||
printf ( " / / \n" ) ;
|
||||
printf ( " ____/____/____\n" ) ;
|
||||
printf ( " / / \n" ) ;
|
||||
printf ( " ____/____/____ \n" ) ;
|
||||
printf ( " / / \n" ) ;
|
||||
printf ( " / / \n" ) ;
|
||||
printf ( "\n" ) ;
|
||||
printf ( " by Steve Baker\n" ) ;
|
||||
printf ( " <sjbaker1@airmail.net>\n" ) ;
|
||||
printf ( "\n\n" ) ;
|
||||
}
|
||||
|
||||
static void cmdline_help ()
|
||||
{
|
||||
banner () ;
|
||||
|
||||
printf ( "Usage:\n\n" ) ;
|
||||
printf ( " ttt3d [OPTIONS]...\n\n" ) ;
|
||||
printf ( "Options:\n" ) ;
|
||||
printf ( " -h, --help Display this help message.\n" ) ;
|
||||
printf ( " -D, --datadir DIR Load the game data from DIR defaults\n" ) ;
|
||||
printf ( " to /usr/local/share/games/ttt3d\n" ) ;
|
||||
printf ( "\n" ) ;
|
||||
}
|
||||
|
||||
|
||||
int main ( int argc, char **argv )
|
||||
{
|
||||
for ( int i = 1 ; i < argc ; i++ )
|
||||
{
|
||||
if ( argv[i][0] == '-' )
|
||||
switch ( argv[i][1] )
|
||||
{
|
||||
case '-' :
|
||||
{
|
||||
if ( strcmp ( & argv[i][2], "help" ) == 0 )
|
||||
{
|
||||
cmdline_help () ;
|
||||
exit ( 0 ) ;
|
||||
}
|
||||
}
|
||||
break ;
|
||||
|
||||
case 'h' : case 'H' : cmdline_help () ; exit ( 0 ) ;
|
||||
default : break ;
|
||||
}
|
||||
}
|
||||
|
||||
/* Set tux_aqfh_datadir to the correct directory */
|
||||
|
||||
if ( ttt3d_datadir == NULL )
|
||||
{
|
||||
if ( getenv ( "TTT3D_DATADIR" ) != NULL )
|
||||
ttt3d_datadir = getenv ( "TTT3D_DATADIR" ) ;
|
||||
else
|
||||
if ( access ( "data/levels.dat", F_OK ) == 0 )
|
||||
ttt3d_datadir = "." ;
|
||||
else
|
||||
if ( access ( "../data/levels.dat", F_OK ) == 0 )
|
||||
ttt3d_datadir = ".." ;
|
||||
else
|
||||
#ifdef TTT3D_DATADIR
|
||||
ttt3d_datadir = TTT3D_DATADIR ;
|
||||
#else
|
||||
ttt3d_datadir = "/usr/local/share/games/ttt3d" ;
|
||||
#endif
|
||||
}
|
||||
|
||||
fprintf ( stderr, "Data files will be fetched from: '%s'\n",
|
||||
ttt3d_datadir ) ;
|
||||
|
||||
if ( chdir ( ttt3d_datadir ) == -1 )
|
||||
{
|
||||
fprintf ( stderr, "Couldn't chdir() to '%s'.\n", ttt3d_datadir ) ;
|
||||
exit ( 1 ) ;
|
||||
}
|
||||
|
||||
banner () ;
|
||||
|
||||
gfx = new GFX ;
|
||||
|
||||
sound = new SoundSystem ;
|
||||
sound -> change_track ( "mods/mfarmer.mod" ) ;
|
||||
|
||||
gui = new GUI ;
|
||||
|
||||
scene = new ssgRoot ;
|
||||
spin = new ssgTransform ;
|
||||
scene -> addKid ( spin ) ;
|
||||
|
||||
puzzle = new Puzzle () ;
|
||||
|
||||
spin -> addKid ( puzzle -> getSSG () ) ;
|
||||
spinLeft () ;
|
||||
|
||||
signal ( 11, SIG_DFL ) ;
|
||||
glutMainLoop () ;
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void spinPuzzle ()
|
||||
{
|
||||
sgMat4 rot, pit, final ;
|
||||
|
||||
sgMakeRotMat4 ( rot, spin_rot, 0, 0 ) ;
|
||||
sgMakeRotMat4 ( pit, 0, spin_pit, 0 ) ;
|
||||
sgMultMat4 ( final, pit, rot ) ;
|
||||
sgSetVec3 ( final[3], 0, 8, 0 /* spin_alt */ ) ;
|
||||
|
||||
spin -> setTransform ( final ) ;
|
||||
}
|
||||
|
||||
void spinUp ()
|
||||
{
|
||||
spin_alt -= 0.4f ;
|
||||
spin_pit += 3.5f ;
|
||||
spinPuzzle () ;
|
||||
}
|
||||
|
||||
void spinDown ()
|
||||
{
|
||||
spin_alt += 0.4f ;
|
||||
spin_pit -= 3.5f ;
|
||||
spinPuzzle () ;
|
||||
}
|
||||
|
||||
void spinRight ()
|
||||
{
|
||||
spin_rot += 4.4f ;
|
||||
spinPuzzle () ;
|
||||
}
|
||||
|
||||
void spinLeft ()
|
||||
{
|
||||
spin_rot -= 4.4f ;
|
||||
spinPuzzle () ;
|
||||
}
|
||||
|
||||
void zoomIn ()
|
||||
{
|
||||
zoom *= 1.1f ;
|
||||
|
||||
if ( zoom > 160 ) zoom = 160 ;
|
||||
|
||||
ssgSetFOV ( zoom, zoom * 3.0f/4.0f ) ;
|
||||
}
|
||||
|
||||
void zoomOut ()
|
||||
{
|
||||
if ( zoom < 6 ) zoom = 6 ;
|
||||
|
||||
zoom /= 1.1f ;
|
||||
|
||||
ssgSetFOV ( zoom, zoom * 3.0f/4.0f ) ;
|
||||
}
|
||||
|
||||
|
||||
void startLevel ()
|
||||
{
|
||||
game_state = GAME_RUNNING ;
|
||||
puzzle -> reset () ;
|
||||
puzzle -> update () ;
|
||||
sound -> playSfx ( SOUND_CLAP ) ;
|
||||
}
|
||||
|
||||
|
||||
void makeMove ()
|
||||
{
|
||||
if ( get_board_entry ( puzzle->getCx(),
|
||||
puzzle->getCy(),
|
||||
puzzle->getCz() ) != ' ' )
|
||||
sound->playSfx ( SOUND_FROG ) ;
|
||||
else
|
||||
{
|
||||
int res = game_update ( puzzle->getCx(),
|
||||
puzzle->getCy(),
|
||||
puzzle->getCz() ) ;
|
||||
|
||||
for ( int x = 0 ; x < 4 ; x++ )
|
||||
for ( int y = 0 ; y < 4 ; y++ )
|
||||
for ( int z = 0 ; z < 4 ; z++ )
|
||||
switch ( get_board_entry ( x, y, z ) )
|
||||
{
|
||||
case ' ' : puzzle->put_empty ( x, y, z ) ; break ;
|
||||
case 'X' : puzzle->put_X ( x, y, z ) ; break ;
|
||||
case 'O' : puzzle->put_O ( x, y, z ) ; break ;
|
||||
default : puzzle->put_empty ( x, y, z ) ; break ;
|
||||
}
|
||||
|
||||
puzzle->setGameState ( res ) ;
|
||||
|
||||
sound->playSfx ( SOUND_POP ) ;
|
||||
|
||||
if ( res == HUMAN_WIN )
|
||||
sound->playSfx ( SOUND_CLAP ) ;
|
||||
else
|
||||
if ( res == COMPUTER_WIN )
|
||||
sound->playSfx ( SOUND_GLASBK ) ;
|
||||
else
|
||||
if ( res == DRAWN_GAME )
|
||||
sound->playSfx ( SOUND_AHOOGA ) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ttt3dMainLoop ()
|
||||
{
|
||||
switch ( game_state )
|
||||
{
|
||||
case GAME_START_OF_DAY : startLevel () ; break ;
|
||||
case GAME_INTRO : startLevel () ; break ;
|
||||
case GAME_DEBRIEF : break ;
|
||||
|
||||
case GAME_RUNNING :
|
||||
if ( puzzle->gameOver () )
|
||||
game_state = GAME_DEBRIEF ;
|
||||
break ;
|
||||
}
|
||||
|
||||
glLineWidth ( 2 ) ;
|
||||
puzzle -> update () ;
|
||||
gfx -> update () ;
|
||||
gui -> update () ;
|
||||
sound -> update () ;
|
||||
gfx -> done () ; /* Swap buffers! */
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user