diff --git a/src/cacatris.h b/src/cacatris.h index 1bd9ad5..2168ad1 100644 --- a/src/cacatris.h +++ b/src/cacatris.h @@ -49,7 +49,7 @@ typedef struct piece_t_ { } piece_t; -void infos_populate(cucul_canvas_t *); +void infos_populate(cucul_canvas_t *, unsigned int score); void playfield_draw(cucul_canvas_t *); void put_piece(unsigned int, unsigned int, unsigned int, unsigned int); void remove_piece(unsigned int id, unsigned int x, unsigned int y, unsigned int rot); diff --git a/src/main.c b/src/main.c index b5687e9..7dd4862 100644 --- a/src/main.c +++ b/src/main.c @@ -20,7 +20,9 @@ int main(int argc, char *argv[]) unsigned long long int curTime = 0; unsigned int speed = 32; unsigned int fixed_y = 0; - + unsigned char lost = 0; + unsigned int score = 0; + unsigned int lines = 0; field = cucul_create_canvas(0, 0); infos = cucul_create_canvas(0, 0); @@ -79,6 +81,14 @@ int main(int argc, char *argv[]) } } + if(lost) continue; + + + if(y==0 && has_landed(current_piece, x ,y, rotation)) { + lost = 1; + continue; + } + if(left) { if(movable(current_piece, x-1, y, rotation)) @@ -89,6 +99,14 @@ int main(int argc, char *argv[]) if(movable(current_piece, x+1, y, rotation)) x++; } + if(down) + { + while((movable(current_piece, x-1, y, rotation)) && (!has_landed(current_piece, x-1, y, rotation))) + { + fixed_y+=speed; + y = fixed_y>>8; + } + } if(!last_has_landed) { @@ -110,7 +128,7 @@ int main(int argc, char *argv[]) /* Populate info canvas */ - infos_populate(infos); + infos_populate(infos, score); /* Draw everything on playfield */ put_piece(current_piece, x ,y, rotation); playfield_draw(field); @@ -136,8 +154,12 @@ int main(int argc, char *argv[]) old_y = 0; } + lines = maybe_remove_line(); + if(lines) + { + score += (lines*40); - maybe_remove_line(); + } if(!baseTime) { @@ -153,16 +175,20 @@ int main(int argc, char *argv[]) } -void infos_populate(cucul_canvas_t *inf) +void infos_populate(cucul_canvas_t *inf, unsigned int score) { unsigned int i; + char scoreline[1024]; + + sprintf(scoreline, " Score : %05d ", score); + cucul_set_color(inf, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); cucul_putstr(inf, 0, 0," =Cacatris= "); cucul_putstr(inf, 0, 1," Arrows : move "); cucul_putstr(inf, 0, 2," Space : pouf "); cucul_putstr(inf, 0, 3," __________________ "); cucul_putstr(inf, 0, 4," "); - cucul_putstr(inf, 0, 5," Score : NXXXX "); + cucul_putstr(inf, 0, 5,scoreline); cucul_putstr(inf, 0, 6," Time : XX:XX "); for(i = 6; i < cucul_get_canvas_height(inf); i++) @@ -286,13 +312,15 @@ unsigned char maybe_remove_line(void) { int x, v=0; unsigned char *p = &playfield[(FIELD_HEIGHT-1)*FIELD_WIDTH]; + int ret = 0; for(x = 0; x < FIELD_WIDTH ; x++) if(*p++) v++; if(v==FIELD_WIDTH) { memmove(&playfield[FIELD_WIDTH], playfield, (FIELD_HEIGHT-1)*FIELD_WIDTH); - return 1; + ret += maybe_remove_line(); + return ret; } return 0; }