add colour selection based on ID

This commit is contained in:
2025-01-27 16:19:07 +01:00
parent 1097c6e09d
commit 2dbdc5ac40
3 changed files with 25 additions and 2 deletions

View File

@@ -39,7 +39,12 @@ void tmp_set_all(GameData* game_data) {
} }
void tmp_set_random(GameData* game_data) { void tmp_set_random(GameData* game_data) {
uint32_t x = rand() % TETROMINO_COUNT; ShapeId id = rand() % TETROMINO_COUNT;
//set_shape(game_data->row, shape, colour, 1, 1); static int finished = 0;
if (finished)
return;
finished = 1;
set_shape(game_data->row, shape_from_id(id), colour_from_id(id), 1, 1);
} }

View File

@@ -1,5 +1,7 @@
#include "shapes.h" #include "shapes.h"
#include "../../window/colour.h"
/* 0 1 2 3 */ /* 0 1 2 3 */
#define TET_SHAPE_O ((Shape)0xCC00) // 1100 1100 0000 0000 the O tetromino with no rotation #define TET_SHAPE_O ((Shape)0xCC00) // 1100 1100 0000 0000 the O tetromino with no rotation
#define TET_SHAPE_I ((Shape)0x8888) // 1000 1000 1000 1000 the I tetromino with no rotation #define TET_SHAPE_I ((Shape)0x8888) // 1000 1000 1000 1000 the I tetromino with no rotation
@@ -38,3 +40,16 @@ Shape shape_from_id(ShapeId id) {
// first 3 bits is the shape type, the rest is rotation data // first 3 bits is the shape type, the rest is rotation data
return shapes[id & 7][id >> 3]; return shapes[id & 7][id >> 3];
} }
Colour colour_from_id(ShapeId id) {
switch (id & 7) {
case TETROMINO_O: return COLOUR_YELLOW;
case TETROMINO_I: return COLOUR_CYAN;
case TETROMINO_S: return COLOUR_RED;
case TETROMINO_Z: return COLOUR_GREEN;
case TETROMINO_T: return COLOUR_MAGENTA;
case TETROMINO_L: return COLOUR_ORANGE;
case TETROMINO_J: return COLOUR_BLUE;
default: return COLOUR_NONE;
}
}

View File

@@ -1,6 +1,8 @@
#pragma once #pragma once
#include <stdint.h> #include <stdint.h>
#include "../../window/colour.h"
typedef uint16_t Shape; typedef uint16_t Shape;
typedef uint8_t ShapeRow; typedef uint8_t ShapeRow;
@@ -33,3 +35,4 @@ static inline _Bool is_set(ShapeRow row, uint8_t index) {
} }
Shape shape_from_id(ShapeId id); Shape shape_from_id(ShapeId id);
Colour colour_from_id(ShapeId id);