diff --git a/src/game/game.c b/src/game/game.c index 919bf59..f5bc2b0 100644 --- a/src/game/game.c +++ b/src/game/game.c @@ -46,6 +46,6 @@ void game_update(GameData* game_data, const uint8_t* keys) { stop(); } - //tmp_set_random(game_data); - tmp_set_all(game_data); + tmp_set_random(game_data); + //tmp_set_all(game_data); } diff --git a/src/game/tetromino/placing.c b/src/game/tetromino/placing.c index fd77ecf..82e63e5 100644 --- a/src/game/tetromino/placing.c +++ b/src/game/tetromino/placing.c @@ -1,4 +1,7 @@ +#include "placing.h" + #include +#include #include "../../window/colour.h" #include "../game.h" @@ -34,3 +37,41 @@ void tmp_set_all(GameData* game_data) { set_shape(game_data->row, TETROMINO_T, COLOUR_MAGENTA, 5, 16); } + +void tmp_set_random(GameData* game_data) { + uint32_t x = rand() % TETROMINO_COUNT; + Shape shape = 0; + Colour colour = {0}; + switch (x) { + case 0: + shape = TETROMINO_I; + colour = COLOUR_CYAN; + break; + case 1: + shape = TETROMINO_J; + colour = COLOUR_BLUE; + break; + case 2: + shape = TETROMINO_L; + colour = COLOUR_ORANGE; + break; + case 3: + shape = TETROMINO_O; + colour = COLOUR_YELLOW; + break; + case 4: + shape = TETROMINO_S; + colour = COLOUR_RED; + break; + case 5: + shape = TETROMINO_T; + colour = COLOUR_MAGENTA; + break; + case 6: + shape = TETROMINO_Z; + colour = COLOUR_GREEN; + break; + } + + set_shape(game_data->row, shape, colour, 1, 1); +} diff --git a/src/game/tetromino/shapes.h b/src/game/tetromino/shapes.h index 2bd6209..0b2613c 100644 --- a/src/game/tetromino/shapes.h +++ b/src/game/tetromino/shapes.h @@ -4,7 +4,7 @@ #define SHAPE_WIDTH 4 #define SHAPE_HEIGHT 4 - +#define TETROMINO_COUNT 7 typedef uint16_t Shape; enum { // clang-format off diff --git a/src/main.c b/src/main.c index 8c4ebb0..5710099 100644 --- a/src/main.c +++ b/src/main.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "errors.h" #include "game/game.h" @@ -42,6 +43,9 @@ static void init(void) { return; } + // set a random seed using the system clock + srand(time(NULL)); + // initialize audio // AudioDevice* audio_device = audio_device_init(32000, AUDIO_S16, 1, 4096); // AudioData audio1 = audio_load_wav(audio_device, "FILE MANE");