#include "raylib.h" #include #include #include #define SCREEN_WIDTH 800 #define SCREEN_HEIGHT 600 #define MATRIX_WIDTH 10 #define MATRIX_HEIGHT 40 #define BLOCK_SIZE 25 #define FALL_TICK 0.5 enum Phases { GENERATION, FALL, LOCK, PATTERN, MARK, ITERATE, ANIMATE, ELIMINATE, COMPLETE } game_phase; #include "tetromino.h" struct { int pos_x; int pos_y; int rotation; int type; } current_piece; struct Color matrix[MATRIX_WIDTH][MATRIX_HEIGHT]; int piece_queue[2][TETROMINO_COUNT] = { {0, 1, 2, 3, 4, 5, 6}, {0, 1, 2, 3, 4, 5, 6} }; int current_bag = 0; int current_piece_index = 0; void render_matrix(void); void make_bag(int *bag); void render_matrix(void) { /* top left matrix corner */ int matrix_start_x = (SCREEN_WIDTH/2 - (MATRIX_WIDTH * BLOCK_SIZE)) / 2; int matrix_start_y = (SCREEN_HEIGHT - (3 * MATRIX_HEIGHT / 2 * BLOCK_SIZE)) / 2; /* top left queue corner */ int queue_start_x = (SCREEN_WIDTH/2 + BLOCK_SIZE); int queue_start_y = (SCREEN_HEIGHT - (3 * MATRIX_HEIGHT / 2 * BLOCK_SIZE)) / 2; /* draw matrix background */ DrawRectangle( matrix_start_x - 1 ,matrix_start_y + (MATRIX_HEIGHT/2 * BLOCK_SIZE) - 1 ,MATRIX_WIDTH * BLOCK_SIZE + 2 ,MATRIX_HEIGHT/2 * BLOCK_SIZE + 2 ,GRAY ); /* draw blocks from matrix */ for (int y = 0; y < 40; y++) { for (int x = 0; x < 10; x++) { DrawRectangle( (x * BLOCK_SIZE) + matrix_start_x + 1 ,(y * BLOCK_SIZE) + matrix_start_y + 1 ,BLOCK_SIZE - 2 ,BLOCK_SIZE - 2 ,matrix[x][y] ); } } /* draw current piece */ for (int i = 0; i < tetrominos[current_piece.type].size; i++) { for (int j = 0; j < tetrominos[current_piece.type].size; j++) { if (tetrominos[current_piece.type].directions[current_piece.rotation][i][j]) { DrawRectangle( matrix_start_x + ((current_piece.pos_x + j-2) * BLOCK_SIZE) + 1 ,matrix_start_y + ((current_piece.pos_y + i-2) * BLOCK_SIZE) + 1 ,BLOCK_SIZE - 2 ,BLOCK_SIZE - 2 ,tetrominos[current_piece.type].color ); } } } // draw queue // STUB (void)queue_start_x; (void)queue_start_y; } void shuffle_bag(int *bag) { for (int i = 0; i < TETROMINO_COUNT; i++) { int r = i + rand() / (RAND_MAX / (TETROMINO_COUNT - i) + 1); int t = bag[r]; bag[r] = bag[i]; bag[i] = t; } } void generation_phase(void) { // bag generation if (current_piece_index > TETROMINO_COUNT) { current_piece_index = 0; shuffle_bag(piece_queue[current_bag]); current_bag = !current_bag; } // set current piece current_piece.type = piece_queue[current_bag][current_piece_index++]; current_piece.rotation = NORTH; current_piece.pos_x = 5; current_piece.pos_y = 20; } int main(void) { //srand(time(NULL)); InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "~turnipGod's Tetris"); // set all blocks to white for (int y = 0; y < 40; y++) { for (int x = 0; x < 10; x++) { matrix[x][y] = WHITE; } } shuffle_bag(piece_queue[0]); generation_phase(); while (!WindowShouldClose()) { BeginDrawing(); ClearBackground(WHITE); render_matrix(); EndDrawing(); } CloseWindow(); return 0; }