break;
case 1:
newblock = initblock (block->height, block->width);
+ newblock->color = block->color;
for (i = 0; i < block->width; i++) {
for (j = 0; j < block->height; j++) {
*getcell (newblock, block->height - 1 - j, i) = *getcell (block, i, j);
break;
case 2:
newblock = initblock (block->width, block->height);
+ newblock->color = block->color;
for (i = 0; i < block->width; i++) {
for (j = 0; j < block->height; j++) {
*getcell (newblock, block->width - 1 - i, block->height - 1 - j) = *getcell (block, i, j);
break;
case 3:
newblock = initblock (block->height, block->width);
+ newblock->color = block->color;
for (i = 0; i < block->width; i++) {
for (j = 0; j < block->height; j++) {
*getcell (newblock, j, block->width - 1 - i) = *getcell (block, i, j);
#include <stdlib.h>
#include <string.h>
#include <time.h>
+#include <sys/time.h>
#include "constant.h"
#include "debug.h"
return ret;
}
+void setendtime (struct timeval *t, int s)
+{
+ gettimeofday (t, NULL);
+ t->tv_usec += s * 1000l;
+ t->tv_sec += t->tv_usec / 1000000l;
+ t->tv_usec = t->tv_usec % 1000000l;
+}
+
+int isovertime (struct timeval *t)
+{
+ struct timeval _c;
+ struct timeval *c = &_c;
+ gettimeofday (c, NULL);
+ return ((t->tv_sec < c->tv_sec) || ((t->tv_sec == c->tv_sec) && ( t->tv_usec < c->tv_usec)));
+}
+
/* main function */
int main (int argc, char *argv[])
{
/* event loop */
int mode = 0;
- int speed = 255;
+ int speed = 5000;
int rot = 0;
int stop = 0;
+ struct timeval tend = {0, 0};
while (!stop) {
boardwindow (board);
//sprintf (msg, "Get ready player One");
break;
case 1:
- halfdelay (speed);
+ halfdelay (10);
rotateblock (cblock, rot);
+ if (isovertime (&tend)) {
+ yblock++;
+ if (yblock + cblock->height >= board->height) {
+ freeblock (cblock);
+ current = next;
+ cblock = copyblock (blocks + current);
+ xblock = (board->width - cblock->width) / 2;
+ yblock = 0;
+ next = rand () % nb_blocks;
+ }
+ setendtime (&tend, speed);
+ }
displayblock (board, cblock, xblock, yblock);
rot = 0;
+sprintf (msg, "%ld/%06ld\n", tend.tv_sec, tend.tv_usec);
break;
}
msgwindow (msg, xmsg, ymsg, lmsg);
case '\n':
case '\r':
case 'c':
+ yblock = board->height - cblock->height;
break;
case KEY_LEFT:
case 'j':
+ xblock--;
break;
case KEY_DOWN:
case 'k':
+ yblock++;
break;
case KEY_RIGHT:
case 'l':
+ xblock++;
break;
case KEY_UP:
case ' ':
break;
case 'p':
mode = (mode == 0) ? 1 : 0;
+ if (mode == 1) {
+ setendtime (&tend, speed);
+ }
break;
case KEY_ESC:
case 'q':