From 4867a16e51c4dc17534e5d6601ea9cb8924ef7f9 Mon Sep 17 00:00:00 2001 From: jylam Date: Thu, 28 Sep 2006 08:29:45 +0000 Subject: [PATCH] * Scoring and levels implementation (following standard Tetris(c)(tm) rules) git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/cacatris/trunk@1125 92316355-f0b4-4df1-b90c-862c8a59935f --- src/cacatris.h | 12 +++++++++++- src/main.c | 38 +++++++++++++++++++++++++------------- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/cacatris.h b/src/cacatris.h index 15d0d56..6259473 100644 --- a/src/cacatris.h +++ b/src/cacatris.h @@ -29,6 +29,16 @@ #define FIELD_CANVAS_WIDTH 20 #define FIELD_CANVAS_HEIGHT 20 +#define LEVEL_COUNT 11 + +unsigned int points[LEVEL_COUNT*4] = { + 40, 80, 120, 160, 200, 240, 280, 320, 360, 400, 440, + 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, + 300, 600, 900, 1200, 1500, 1800, 2100, 2400, 2700, 3000, 3300, + 1200, 2400, 3600, 4800, 6000, 7200, 8400, 9600, 10800, 12000, 13200 +}; + + unsigned char playfield[FIELD_WIDTH*FIELD_HEIGHT]; static cucul_canvas_t *field, *infos, *screen; @@ -49,7 +59,7 @@ typedef struct piece_t_ { } piece_t; -void infos_populate(cucul_canvas_t *, unsigned int score); +void infos_populate(cucul_canvas_t *, unsigned int score, unsigned char level); 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 c536e28..d9bbcea 100644 --- a/src/main.c +++ b/src/main.c @@ -23,6 +23,8 @@ int main(int argc, char *argv[]) unsigned char lost = 0; unsigned int score = 0; unsigned int lines = 0; + unsigned char level = 0; + unsigned char total_lines = 0; field = cucul_create_canvas(0, 0); infos = cucul_create_canvas(0, 0); @@ -128,7 +130,7 @@ int main(int argc, char *argv[]) /* Populate info canvas */ - infos_populate(infos, score); + infos_populate(infos, score, level); /* Draw everything on playfield */ put_piece(current_piece, x ,y, rotation); playfield_draw(field); @@ -157,8 +159,15 @@ int main(int argc, char *argv[]) lines = maybe_remove_line(); if(lines) { - score += (lines*40); - + score += points[level+(lines-1)*LEVEL_COUNT]; + total_lines += lines; + if(total_lines >=10 && level<=10) + { + level++; + total_lines = 0; + speed+=2; + memset(playfield, 0, FIELD_WIDTH*FIELD_HEIGHT); + } } if(!baseTime) @@ -175,23 +184,26 @@ int main(int argc, char *argv[]) } -void infos_populate(cucul_canvas_t *inf, unsigned int score) +void infos_populate(cucul_canvas_t *inf, unsigned int score, unsigned char level) { unsigned int i; char scoreline[1024]; + char levelline[1024]; sprintf(scoreline, " Score : %05d ", score); + sprintf(levelline, " Level : %02d ", level); 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,scoreline); - cucul_putstr(inf, 0, 6," Time : XX:XX "); - - for(i = 6; i < cucul_get_canvas_height(inf); i++) + 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, levelline); + cucul_putstr(inf, 0, 6, scoreline); + cucul_putstr(inf, 0, 7, " Time : XX:XX "); + + for(i = 7; i < cucul_get_canvas_height(inf); i++) { cucul_putstr(inf, 0, i," "); }