add some temporary code for setting a random tetromino

This commit is contained in:
2025-01-27 15:32:05 +01:00
parent 7f00107c7f
commit b698a0e3d1
4 changed files with 48 additions and 3 deletions

View File

@@ -46,6 +46,6 @@ void game_update(GameData* game_data, const uint8_t* keys) {
stop(); stop();
} }
//tmp_set_random(game_data); tmp_set_random(game_data);
tmp_set_all(game_data); //tmp_set_all(game_data);
} }

View File

@@ -1,4 +1,7 @@
#include "placing.h"
#include <stdint.h> #include <stdint.h>
#include <stdlib.h>
#include "../../window/colour.h" #include "../../window/colour.h"
#include "../game.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); 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);
}

View File

@@ -4,7 +4,7 @@
#define SHAPE_WIDTH 4 #define SHAPE_WIDTH 4
#define SHAPE_HEIGHT 4 #define SHAPE_HEIGHT 4
#define TETROMINO_COUNT 7
typedef uint16_t Shape; typedef uint16_t Shape;
enum { enum {
// clang-format off // clang-format off

View File

@@ -10,6 +10,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h>
#include "errors.h" #include "errors.h"
#include "game/game.h" #include "game/game.h"
@@ -42,6 +43,9 @@ static void init(void) {
return; return;
} }
// set a random seed using the system clock
srand(time(NULL));
// initialize audio // initialize audio
// AudioDevice* audio_device = audio_device_init(32000, AUDIO_S16, 1, 4096); // AudioDevice* audio_device = audio_device_init(32000, AUDIO_S16, 1, 4096);
// AudioData audio1 = audio_load_wav(audio_device, "FILE MANE"); // AudioData audio1 = audio_load_wav(audio_device, "FILE MANE");