diff options
| author | ilotterytea <iltsu@alright.party> | 2025-01-31 01:24:39 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-01-31 01:24:39 +0500 |
| commit | ea1c0a112de752ef9dea2d9bfabcbf5ea3254be7 (patch) | |
| tree | 9375f291a759009d6e8ee2d8ab5ea4b3fdce9bb5 /src | |
| parent | a15f24294d5113fec767fb9007d906f534dc0485 (diff) | |
feat: tile rotation
Diffstat (limited to 'src')
| -rw-r--r-- | src/editor.c | 32 | ||||
| -rw-r--r-- | src/editor.h | 2 | ||||
| -rw-r--r-- | src/floor.c | 22 | ||||
| -rw-r--r-- | src/floor.h | 1 |
4 files changed, 54 insertions, 3 deletions
diff --git a/src/editor.c b/src/editor.c index 73164f5..425dc64 100644 --- a/src/editor.c +++ b/src/editor.c @@ -25,6 +25,14 @@ void SE_UpdateEditor(Editor *editor) { state->activeTileLayerId = state->activeTilesetTile->type; SE_LOG_INFO("Changed selected layer"); } + + // update tile rotation + if (IsKeyPressed(KEY_R)) { + state->tileRotation += 90.0f; + if (state->tileRotation >= 360.0f) { + state->tileRotation = 0.0f; + } + } } void drawBuildTab(Editor *editor, Tileset *tileset, int x, int y, int width, @@ -60,6 +68,30 @@ void drawBuildTab(Editor *editor, Tileset *tileset, int x, int y, int width, 24.0f}, selectedTileLabel); + // Drawing rotation + GuiLabel((Rectangle){x + padding * 7.0f, y + padding * 2.0f, + width - padding * 2.0f, 24.0f}, + "Rotation"); + + DrawCircle(x + padding * 7.0f + 10.0f, y + padding * 3.0f + 10.0f, 10.0f, + LIGHTGRAY); + + DrawCircleSector( + (Vector2){x + padding * 7.0f + 10.0f, y + padding * 3.0f + 10.0f}, 10.0f, + 0.0f, editor->state.tileRotation, 4, GRAY); + + int rotationTextLength = + snprintf(NULL, 0, "%.0f", editor->state.tileRotation); + char *rotationText = malloc(rotationTextLength + 1); + snprintf(rotationText, rotationTextLength + 1, "%.0f", + editor->state.tileRotation); + + GuiLabel((Rectangle){x + padding * 7.0f + 25.0f, y + padding * 3.0f, + width - padding * 2.0f, 24.0f}, + rotationText); + + free(rotationText); + // Rendering Rectangle controlBounds = {x + padding, y + padding + 20.0f * 8.0f, width - padding * 2.0f, 200.0f}; diff --git a/src/editor.h b/src/editor.h index b0b0441..9b2cda5 100644 --- a/src/editor.h +++ b/src/editor.h @@ -20,6 +20,8 @@ typedef struct { int activeMainTab; int activeTileLayerId; + float tileRotation; + TilesetTile *activeTilesetTile; EditorCreateBlockState *createBlockState; Rectangle panelView; diff --git a/src/floor.c b/src/floor.c index 22b2718..91dcf86 100644 --- a/src/floor.c +++ b/src/floor.c @@ -9,6 +9,7 @@ Tile *SE_CreateTile(TileLayer *layer, TilesetTile *tilesetTile) { tile->id = layer->tileCount; tile->tilesetTile = tilesetTile; tile->position = (Vector2){0.0f, 0.0f}; + tile->rotation = 0.0f; layer->tiles[layer->tileCount] = tile; layer->tileCount++; @@ -119,6 +120,7 @@ void SE_UpdateTileFloor(EditorState *state, TileFloor *floor, tile->position = pos; } + tile->rotation = state->tileRotation; tile->tilesetTile = state->activeTilesetTile; } @@ -147,7 +149,18 @@ void SE_DrawTileFloor(TileFloor *floor, EditorState *state, Camera2D *camera) { tile->position.y * camera->zoom, camera->zoom, camera->zoom}; - DrawTexturePro(tile->tilesetTile->texture, s, d, (Vector2){0, 0}, 0.0f, + Vector2 o = {0, 0}; + + if (tile->rotation == 90.0f) { + o.y = d.height; + } else if (tile->rotation == 180.0f) { + o.x = d.width; + o.y = d.height; + } else if (tile->rotation == 270.0f) { + o.x = d.width; + } + + DrawTexturePro(tile->tilesetTile->texture, s, d, o, tile->rotation, WHITE); } } @@ -158,8 +171,11 @@ void SE_DrawTileFloor(TileFloor *floor, EditorState *state, Camera2D *camera) { Rectangle s = {0, 0, TILE_WIDTH, TILE_HEIGHT}; Rectangle d = {mousePos.x, mousePos.y, camera->zoom / 2.0f, camera->zoom / 2.0f}; - DrawTexturePro(state->activeTilesetTile->texture, s, d, (Vector2){0, 0}, - 0.0f, WHITE); + + Vector2 o = {d.width / 2.0f, d.height / 2.0f}; + + DrawTexturePro(state->activeTilesetTile->texture, s, d, o, + state->tileRotation, WHITE); } } diff --git a/src/floor.h b/src/floor.h index 4f112fa..ad3b2da 100644 --- a/src/floor.h +++ b/src/floor.h @@ -8,6 +8,7 @@ typedef struct { int id; Vector2 position; + float rotation; TilesetTile *tilesetTile; } Tile; |
