#include "blocks.h"
#include "logger.h"
+int init_starfield(void);
+void draw_starfield(void);
+
static int init(void);
static void cleanup(void);
static void start(void);
167, 151, 134, 117, 107, 98, 88, 79, 69, 60, 50
};
+static const float blkcolor[][4] = {
+ {1.0, 0.65, 0.0, 1},
+ {0.16, 1.0, 0.4, 1},
+ {0.65, 0.65, 1.0, 1},
+ {1.0, 0.9, 0.1, 1},
+ {0.0, 1.0, 1.0, 1},
+ {1.0, 0.5, 1.0, 1},
+ {1.0, 0.35, 0.2, 1},
+ {0.5, 0.5, 0.5, 1}
+};
+
+#define GAMEOVER_FILL_RATE 50
+
static int init(void)
{
+ if(init_starfield() == -1) {
+ return -1;
+ }
+
if(!(blkmesh = cmesh_alloc()) || cmesh_load(blkmesh, "data/noisecube.obj") == -1) {
error_log("failed to load block mesh\n");
return -1;
static void cleanup(void)
{
cmesh_free(blkmesh);
+ cmesh_free(wellmesh);
+ glDeleteTextures(1, &tex_well);
}
static void start(void)
}
dt = time_msec - prev_tick;
- /*
if(gameover) {
int i, row = PF_ROWS - gameover;
- int *ptr;
+ unsigned int *ptr;
if(dt < GAMEOVER_FILL_RATE) {
return;
if(row >= 0) {
ptr = pfield + row * PF_COLS;
for(i=0; i<PF_COLS; i++) {
- *ptr++ = TILE_GAMEOVER;
+ *ptr++ = PF_VIS | PF_FULL | 7;
}
gameover++;
- prev_tick = msec;
+ prev_tick = time_msec;
}
return;
}
- */
if(num_complines) {
/* lines where completed, we're in blinking mode */
unsigned int *ptr = pfield + complines[i] * PF_COLS;
for(j=0; j<PF_COLS; j++) {
*ptr = (*ptr & ~PF_VIS) | ((blink & 1) << PF_VIS_SHIFT);
+ ptr++;
}
}
return;
static void draw(void)
{
+ const float lpos[] = {-1, 1, 6, 1};
+
glTranslatef(0, 0, -cam_dist);
glRotatef(cam_phi, 1, 0, 0);
glRotatef(cam_theta, 0, 1, 0);
+ glLightfv(GL_LIGHT0, GL_POSITION, lpos);
+
+ draw_starfield();
+
glPushAttrib(GL_ENABLE_BIT);
glBindTexture(GL_TEXTURE_2D, tex_well);
glEnable(GL_TEXTURE_2D);
glPopMatrix();
}
+static const float blkspec[] = {0.85, 0.85, 0.85, 1};
+
static void draw_block(int block, const int *pos, int rot)
{
- int i, pal;
+ int i;
unsigned char *p = blocks[block][rot];
- /*pal = FIRST_BLOCK_PAL + block;*/
+ glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blkcolor[block]);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, blkspec);
+ glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 50.0f);
for(i=0; i<4; i++) {
int x = pos[1] + BLKX(*p);
for(i=0; i<PF_ROWS; i++) {
for(j=0; j<PF_COLS; j++) {
unsigned int val = *sptr++;
- if(val & PF_FULL) {
+
+ glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blkcolor[val & 7]);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, blkspec);
+ glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 50.0f);
+
+ if((val & (PF_FULL | PF_VIS)) == (PF_FULL | PF_VIS)) {
glPushMatrix();
glTranslatef(j, -i, 0);
cmesh_draw(blkmesh);