summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2019-04-23 23:15:08 -0400
committerAndrew Opalach <andrew@akon.city> 2019-04-23 23:15:08 -0400
commitab5a70d3b5769ee1f3e1f1bf380c6839915aaf15 (patch)
treee9f79597859bd28ce1603ef39026b06325ea2ca3 /core/src
parent10835bc09f0979a6bf1c8b1ead2658f48b28b76f (diff)
downloadcetris-ab5a70d3b5769ee1f3e1f1bf380c6839915aaf15.tar.gz
cetris-ab5a70d3b5769ee1f3e1f1bf380c6839915aaf15.tar.bz2
cetris-ab5a70d3b5769ee1f3e1f1bf380c6839915aaf15.zip
adjust some stuff from the Tetris guidelines
Diffstat (limited to 'core/src')
-rw-r--r--core/src/cetris.c42
-rw-r--r--core/src/matrix.c2
2 files changed, 39 insertions, 5 deletions
diff --git a/core/src/cetris.c b/core/src/cetris.c
index 4e404d6..d8eda2f 100644
--- a/core/src/cetris.c
+++ b/core/src/cetris.c
@@ -21,8 +21,10 @@ static void add_score(cetris_game* g, u8 lines);
/* LEVEL DROP SPEED VALUES */
+// https://tetris.fandom.com/wiki/Tetris_Worlds
+// TODO: Make this more accurate
static const u32 level_drop_delay[20] = {
- 48, 43, 38, 33, 28, 23, 18, 13, 8, 6, 5, 5, 5, 4, 4, 4, 3, 3, 3, 3
+ 60, 48, 37, 28, 21, 16, 11, 8, 6, 4, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1
};
/* GAME FUNCTIONS */
@@ -57,7 +59,12 @@ void init_piece_queue(cetris_game* g) {
g->piece_queue[i].lock_tick = 0;
g->piece_queue[i].locked = false;
g->piece_queue[i].ghost_y = 0;
- g->piece_queue[i].pos = (vec2){CETRIS_INITIAL_X, CETRIS_INITIAL_Y - CETRIS_INITIAL_Y_OFFSET};
+
+ /* Pieces should spawn so that on the first down
+ * tick the bottom row will show. Values here are adjusted
+ * for the default 4x4 matricies for each piece */
+ g->piece_queue[i].pos.x = 3;
+ g->piece_queue[i].pos.y = (i == I) ? 17 : 16;
}
}
@@ -123,6 +130,10 @@ void next_piece(cetris_game* g) {
}
g->current_index++;
+ if (!g->game_over) {
+ move_current(g, DOWN);
+ }
+
if (g->current_index >= 7) {
g->current_index = 0;
shuffle_queue(g);
@@ -234,7 +245,7 @@ void add_score(cetris_game* g, u8 lines) {
/* MOVEMENT FUNCTIONS */
-void move_piece(cetris_game* g, input_t move) {
+void move_piece(cetris_game* g, input_t move, bool hold) {
if (!g->held_moves[move]) {
switch (move) {
case LEFT:
@@ -254,7 +265,7 @@ void move_piece(cetris_game* g, input_t move) {
break;
}
}
- g->held_moves[move] = true;
+ if (hold) g->held_moves[move] = true;
}
void stop_holding(cetris_game* g, input_t move) {
@@ -264,3 +275,26 @@ void stop_holding(cetris_game* g, input_t move) {
g->das_repeat = 0;
} else if (move == USER_DOWN) g->down_move_tick = 0;
}
+
+void reset_tetrimino(tetrimino* t) {
+ t->r = INIT;
+ t->pos.x = 3;
+ t->pos.y = (t->t == I) ? 17 : 16;
+ t->ghost_y = 0;
+}
+
+void hold_piece(cetris_game* g) {
+ if (g->piece_held) {
+ tetrimino tmp = g->current;
+ g->current = g->held;
+ g->held = tmp;
+ } else {
+ g->held = g->current;
+ reset_tetrimino(&g->held);
+ g->piece_held = true;
+ next_piece(g);
+ }
+ update_board(g);
+}
+
+
diff --git a/core/src/matrix.c b/core/src/matrix.c
index caae107..d4597a7 100644
--- a/core/src/matrix.c
+++ b/core/src/matrix.c
@@ -255,7 +255,7 @@ void rotate_matrix(cetris_game* g, bool clockwise) {
/* check for tspin */
if (g->current.t == T) {
bool did_tspin = true;
- for (int i = 1; i < 5; i++) {
+ for (u8 i = 1; i < 5; i++) {
g->current.pos.x += basic_movements[i].x;
g->current.pos.y += basic_movements[i].y;