diff options
| author | ilotterytea <iltsu@alright.party> | 2025-01-18 21:22:32 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-01-18 21:22:32 +0500 |
| commit | 6c4ecd35da17e07b743d4ef75e234383317d22ac (patch) | |
| tree | 48e702ed1324f8526750d7dd90db464c2bb4742e /src/main.c | |
| parent | f0284723a2e53b004777a71ad46cc4b75ed566ca (diff) | |
feat: new editor (wip) + using Camera2D
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 62 |
1 files changed, 21 insertions, 41 deletions
@@ -1,6 +1,6 @@ #include <stddef.h> -#include <stdlib.h> +#include "editor.h" #include "level.h" #include "raylib.h" @@ -9,57 +9,37 @@ int main() { InitWindow(800, 600, "sillyeditor"); SetTargetFPS(60); - int gridSize = 32; - Level *level = SE_CreateLevel(30, 30); + Editor editor = {level, {}}; - // creating a dummy side - Side *side = malloc(sizeof(Side)); - side->a = (Point){1, 1}; - side->b = (Point){3, 4}; - level->sides[0] = side; + Camera2D camera = {0}; + camera.target = (Vector2){0.0f, 0.0f}; + camera.offset = (Vector2){0.0f, 0.0f}; + camera.rotation = 0.0f; + camera.zoom = 4.0f; while (!WindowShouldClose()) { - // Change the grid size if (GetMouseWheelMove() != 0.0) { - gridSize += (int)(GetMouseWheelMove() * 4.0); - } - - BeginDrawing(); - ClearBackground(RAYWHITE); - DrawText("hi world!", GetScreenWidth() / 2 - 16 * 4, - GetScreenHeight() / 2 - 16, 32, BLACK); - - SE_RenderLevel(level, gridSize); + camera.zoom += (int)GetMouseWheelMove(); - // Drawing grid - for (int x = 0; x <= level->width; x++) { - DrawLine(x * gridSize, 0, x * gridSize, GetScreenHeight(), LIGHTGRAY); + if (camera.zoom > 6.0f) + camera.zoom = 6.0f; + else if (camera.zoom < 4.0f) + camera.zoom = 4.0f; } - for (int y = 0; y <= level->height; y++) { - DrawLine(0, y * gridSize, GetScreenWidth(), y * gridSize, LIGHTGRAY); + if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) { + Vector2 mousePos = GetMouseDelta(); + camera.target.x -= mousePos.x / 5.0f; + camera.target.y -= mousePos.y / 5.0f; } - // Drawing points - for (int x = 0; x < level->width; x++) { - for (int y = 0; y < level->height; y++) { - Color color = GRAY; - - for (int i = 0; i < level->height * level->width; i++) { - Side *side = level->sides[i]; - if (side == NULL) continue; - - if ((x == side->a.x && y == side->a.y) || - (x == side->b.x && y == side->b.y)) { - color = RED; - break; - } - } + BeginDrawing(); + ClearBackground(RAYWHITE); - DrawCircle(x * gridSize, y * gridSize, 4, color); - } - } + BeginMode2D(camera); + SE_DrawEditor(&editor, &camera); + EndMode2D(); EndDrawing(); } |
