summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/et/et.c91
-rw-r--r--src/et/et.h7
2 files changed, 69 insertions, 29 deletions
diff --git a/src/et/et.c b/src/et/et.c
index 5ef0cd0..30f529f 100644
--- a/src/et/et.c
+++ b/src/et/et.c
@@ -50,16 +50,20 @@
#define ET_HELD_PIECE_HSPACE (-21)
#define ET_HELD_PIECE_VSPACE 4
+#define ET_STATUS_HSPACE ((ET_FRAME_WIDTH * 2) + 6)
+#define ET_STATUS_VSPACE 16
+
#define ET_CURRENT_PIECE_SPEED 1
#define ET_LOCKDOWN_DELAY 2
#define ET_NR_LOCKDOWN_MOVES 15
-#define ET_SCORE_MISSILE 40
-#define ET_SCORE_ALIENS0 30
-#define ET_SCORE_ALIENS12 20
-#define ET_SCORE_ALIENS34 10
-#define ET_SCORE_UFO_BASE 100
+#define ET_SCORE_SOFT_DROP 1
+#define ET_SCORE_HARD_DROP 2
+#define ET_SCORE_SINGLE_LINE 100
+#define ET_SCORE_DOUBLE_LINE 300
+#define ET_SCORE_TRIPLE_LINE 500
+#define ET_SCORE_TETRIS_LINE 800
/*
* Saint Basil's Cathedral by umrain.
@@ -172,7 +176,7 @@
" \\/\\/\\/\\/\\/\\/\\/\\/\\/\\/ \n"
#define ET_NEXT_QUEUE_FRAME_SPRITE \
-" next \n" \
+" NEXT \n" \
"+-------------+\n" \
"| |\n" \
"| |\n" \
@@ -187,7 +191,7 @@
"+-------------+\n"
#define ET_HELD_PIECE_FRAME_SPRITE \
-" hold \n" \
+" HOLD \n" \
"+-------------+\n" \
"| |\n" \
"| |\n" \
@@ -195,7 +199,10 @@
"| |\n" \
"+-------------+\n"
-#define ET_STATUS_SPRITE_FORMAT "SCORE: %08d Lives: %d\n"
+#define ET_STATUS_SPRITE_FORMAT \
+"SCORE: %-8d\n" \
+"LEVEL: %-8d\n" \
+"LINES: %-8d\n"
#define ET_END_TITLE_SPRITE \
" ________ __ _______ ____ _ _________ \n" \
@@ -781,7 +788,10 @@ et_game_update_status(struct et_game *game)
assert(game);
snprintf(game->status_sprite, sizeof(game->status_sprite),
- ET_STATUS_SPRITE_FORMAT, game->score, 0);
+ ET_STATUS_SPRITE_FORMAT, game->score,
+ game->level, game->total_lines);
+
+ eetg_object_update(&game->status);
}
static void
@@ -824,7 +834,7 @@ et_game_end(struct et_game *game)
eetg_world_clear(&game->world);
eetg_world_add(&game->world, &game->end_title, 12, 10, 0);
- eetg_world_add(&game->world, &game->status, 26, 6, 0);
+ eetg_world_add(&game->world, &game->status, 26, 8, 0);
eetg_world_add(&game->world, &game->start, 30, 20, 0);
game->state = ET_STATE_GAME_OVER;
@@ -1046,6 +1056,28 @@ et_game_scan_rows(struct et_game *game)
}
}
}
+
+ if (nr_cleared_rows == 1) {
+ game->score += ET_SCORE_SINGLE_LINE * game->level;
+ game->difficult = false;
+ } else if (nr_cleared_rows == 2) {
+ game->score += ET_SCORE_DOUBLE_LINE * game->level;
+ game->difficult = false;
+ } else if (nr_cleared_rows == 3) {
+ game->score += ET_SCORE_TRIPLE_LINE * game->level;
+ game->difficult = false;
+ } else if (nr_cleared_rows == 4) {
+ game->score += ET_SCORE_TETRIS_LINE * game->level;
+ game->difficult = true;
+ }
+
+ game->total_lines += nr_cleared_rows;
+ game->level_lines += nr_cleared_rows;
+
+ if (game->level_lines >= 10) {
+ game->level++;
+ game->level_lines -= 10;
+ }
}
static void
@@ -1068,17 +1100,22 @@ et_game_reset(struct et_game *game)
game->held_piece = NULL;
game->current_piece = NULL;
game->score = 0;
+ game->total_lines = 0;
game->gravity_counter_reload = ET_FPS / ET_CURRENT_PIECE_SPEED;
game->gravity_counter = game->gravity_counter_reload;
game->lockdown_counter_reload = ET_FPS / ET_LOCKDOWN_DELAY;
game->nr_lockdown_moves = -1;
game->next_index = 0;
game->state = ET_STATE_INTRO;
+ game->level_lines = 0;
game->level = 1;
game->sync_counter_reload = ET_FPS * 2;
game->sync_counter = 1;
game->collisions_ignored = false;
game->current_piece_swapped = false;
+ game->difficult = false;
+
+ et_game_update_status(game);
}
static void
@@ -1102,6 +1139,9 @@ et_game_start(struct et_game *game)
eetg_world_add(&game->world, &game->held_piece_frame,
ET_FRAME_X + ET_HELD_PIECE_HSPACE,
ET_FRAME_Y + ET_HELD_PIECE_VSPACE - 3, 0);
+ eetg_world_add(&game->world, &game->status,
+ ET_FRAME_X + ET_STATUS_HSPACE,
+ ET_FRAME_Y + ET_STATUS_VSPACE, 0);
for (size_t i = 0; i < ARRAY_SIZE(game->next_pieces); i++) {
game->next_pieces[i] = et_game_get_piece_from_bag(game);
@@ -1127,16 +1167,6 @@ et_game_start_lockdown(struct et_game *game, bool nodelay)
}
}
-static void
-et_game_reset_history(struct et_game *game)
-{
- assert(game);
-
- game->score = 0;
-
- et_game_update_status(game);
-}
-
static bool
et_game_process_intro_input(struct et_game *game, char c)
{
@@ -1150,7 +1180,6 @@ et_game_process_intro_input(struct et_game *game, char c)
return false;
}
- et_game_reset_history(game);
et_game_prepare(game);
return false;
@@ -1178,19 +1207,27 @@ et_game_move_current_piece(struct et_game *game, bool nodelay)
if (hit) {
et_game_start_lockdown(game, nodelay);
+ } else if (nodelay) {
+ game->score += ET_SCORE_SOFT_DROP;
}
}
static void
et_game_drop_current_piece(struct et_game *game)
{
- bool hit;
-
assert(game);
- do {
+ for (;;) {
+ bool hit;
+
hit = et_piece_move_down(game->current_piece);
- } while (!hit);
+
+ if (hit) {
+ break;
+ }
+
+ game->score += ET_SCORE_HARD_DROP;
+ }
et_game_start_lockdown(game, true);
}
@@ -1336,10 +1373,9 @@ et_game_init(struct et_game *game, eetg_write_fn write_fn, void *arg)
ET_HELD_PIECE_FRAME_SPRITE);
eetg_object_set_color(&game->held_piece_frame, EETG_COLOR_BLUE);
-#if 0
+ sprintf(game->status_sprite, "\n");
eetg_object_init(&game->status, ET_TYPE_STATUS, game->status_sprite);
eetg_object_set_color(&game->status, EETG_COLOR_RED);
-#endif
eetg_object_init(&game->end_title, ET_TYPE_END_TITLE, ET_END_TITLE_SPRITE);
eetg_object_set_color(&game->end_title, EETG_COLOR_WHITE);
@@ -1363,6 +1399,7 @@ et_game_process(struct et_game *game, int8_t c)
game->sync_counter = game->sync_counter_reload;
}
+ et_game_update_status(game);
eetg_world_render(&game->world, sync);
switch (game->state) {
diff --git a/src/et/et.h b/src/et/et.h
index 0cb314e..c6660d4 100644
--- a/src/et/et.h
+++ b/src/et/et.h
@@ -95,19 +95,22 @@ struct et_game {
struct et_piece *next_pieces[ET_NEXT_QUEUE_SIZE];
struct et_piece *held_piece;
struct et_piece *current_piece;
- unsigned int score;
+ int score;
+ int total_lines;
int8_t gravity_counter_reload;
int8_t gravity_counter;
int8_t lockdown_counter_reload;
int8_t nr_lockdown_moves;
int8_t next_index;
int8_t state;
+ int8_t level_lines;
int8_t level;
int8_t sync_counter_reload;
int8_t sync_counter;
bool collisions_ignored;
bool current_piece_swapped;
- char status_sprite[32];
+ bool difficult;
+ char status_sprite[64];
};
void et_game_init(struct et_game *game, eetg_write_fn write_fn, void *arg);