Permalink
Browse files

Add 40-line race mode, replacing mode B.

  • Loading branch information...
1 parent cea5c6e commit ba722ce88c90ac5622492ca907164ba748808c50 @nooodl committed Jul 1, 2013
Showing with 58 additions and 6 deletions.
  1. +20 −5 src/draw/draw.c
  2. +1 −1 src/game/game.c
  3. +3 −0 src/game/tetris.c
  4. +2 −0 src/game/tetris.h
  5. +29 −0 src/timer.c
  6. +3 −0 src/timer.h
View
25 src/draw/draw.c
@@ -6,6 +6,7 @@
#include "internal.h"
#include "../textgfx/textgfx.h"
#include "../hiscore.h"
+#include "../timer.h"
#include "../netw/sock.h" /* opponent_name */
char tetrom_colors[7] = {
@@ -23,7 +24,7 @@ void drawbl(int bl, int clr, int x, int y)
int c, i;
setblockcolor(clr%10);
i = clr<10 || textgfx_flags & (TT_BLOCKS | TT_BLOCKS_BG |
- BLACK_BRACKETS);
+ BLACK_BRACKETS);
c = block_chars[i];
while (bl) {
setcurs(x, y);
@@ -134,13 +135,26 @@ void drawpanel_labels(const char *first, int x)
}
}
+int format_time(char *str, int time) {
+ return snprintf(str, 9, "%02d:%02d.%02d",
+ time / 60000,
+ time / 1000 % 60,
+ time / 10 % 100);
+}
+
static void printstat_1p()
{
+ char timer[9];
setattr_normal();
if (!_WHITE_BG)
setattr_bold();
setcurs(1, 2);
- printlong(" %06ld ", player1.score % 1000000);
+ if (game->mode & MODE_BTYPE) {
+ format_time(timer, get_clock() - player1.start_time);
+ printstr(timer);
+ } else {
+ printlong(" %06ld ", player1.score % 1000000);
+ }
setcurs(3, 6);
printint(" %02d ", player1.level);
setcurs(3, 10);
@@ -173,6 +187,7 @@ static void drawpanel_1p()
int h24 = _HEIGHT_24L;
int clr = (player1.level % 6)+1;
int i;
+ char *top_label = (game->mode & MODE_BTYPE) ? " Time" : "Score";
setwcurs(WIN_PANEL, 0, 0);
setblockcolor(clr);
printstr_acs("lqNu", 8);
@@ -181,11 +196,11 @@ static void drawpanel_1p()
if (h24) {
setcurs(0, 12);
putch(LOWLEFT);
- drawpanel_labels("Score", 1);
+ drawpanel_labels(top_label, 1);
} else {
setcurs(0, 13);
printstr_acs("xhNx", 8);
- drawpanel_labels("Score", 1);
+ drawpanel_labels(top_label, 1);
setcurs(2, 13);
printstr(" Next ");
}
@@ -423,7 +438,7 @@ static void upddropmark(int pl, int a, int b, int c, int d)
int clr = BOARD_FRAME_COLOR;
#endif
if (term_height==20 || term_height==24 ||
- pl==2 && game->mode & MODE_NETWORK)
+ pl==2 && game->mode & MODE_NETWORK)
return;
if (game_running)
refreshwin(pl);
View
2 src/game/game.c
@@ -31,7 +31,7 @@ static void initplayer(struct player *p)
{
p->startlevel = 0;
p->height = 0;
- p->lineslimit = 25;
+ p->lineslimit = 40;
p->rotationsys = ROT_CLOCKWISE | ROT_LEFTHAND;
p->score = 0;
}
View
3 src/game/tetris.c
@@ -755,6 +755,8 @@ void setupplayer(struct player *p)
levelup(p);
p->lines = (game->mode & MODE_BTYPE) ? p->lineslimit : 0;
memset(p->bag, 0, 7);
+ p->start_time = get_clock();
+ p->current_time = p->start_time;
}
static int random_piece() {
@@ -876,6 +878,7 @@ static int processinput(int tm, int flags)
int d = 0;
int ret;
upd_screen(1);
+ upd_stat(&player1, 0);
while (d < tm) {
ret = -1;
if (key = getkeypress(tm-d, IN_GAME | SINGLE_PL)) {
View
2 src/game/tetris.h
@@ -62,6 +62,8 @@ struct player {
short mvleft_tm;
short mvright_tm;
char bag[7];
+ int start_time;
+ int current_time;
};
/* game modes */
View
29 src/timer.c
@@ -71,6 +71,35 @@ int gettm(int a)
return b;
}
+int get_clock()
+{
+ int b;
+#if UNIX
+ struct timeval tmv;
+ gettimeofday(&tmv, NULL);
+ b = 1000*(tmv.tv_sec) + tmv.tv_usec/1000;
+#elif WIN32
+ long ms = timeGetTime();
+ b = ms;
+#elif PCTIMER
+ unsigned long ms = pctimer_time(0, pctimer_get_ticks());
+ b = ms;
+#elif ALLEGRO
+ if (!elapsed_tm) {
+ elapsed_tm = 1;
+ install_int(inc_tm, 1);
+ }
+ b = elapsed_tm;
+#elif UCLOCKS_PER_SEC
+ uclock_t ms = uclock() / (UCLOCKS_PER_SEC/1000);
+ b = ms;
+#else
+ clock_t hs = clock() / (CLOCKS_PER_SEC/100.0);
+ b = 10*(hs);
+#endif
+ return b;
+}
+
void sleep_msec(unsigned ms)
{
#if UNIX
View
3 src/timer.h
@@ -8,5 +8,8 @@ void timer_end();
/* get time in milliseconds >= tm */
int gettm(int tm);
+/* get absolute time in milliseconds */
+int get_clock();
+
/* sleep ms milliseconds */
void sleep_msec(unsigned ms);

0 comments on commit ba722ce

Please sign in to comment.