1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include "editor.h"
#include "floor.h"
#include "logger.h"
#include "raylib.h"
#include "tileset.h"
int main() {
SetTraceLogCallback(SE_Logger);
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
InitWindow(800, 600, "sillyeditor");
SetTargetFPS(60);
SetWindowMinSize(800, 600);
Editor editor = {0};
editor.state.activeTileLayerId = 0;
Tileset* tileset = SE_CreateTileset();
TileFloor* floor = SE_CreateTileFloor(30, 30);
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()) {
SE_UpdateEditor(&editor);
SE_UpdateTileFloor(&editor.state, floor, &camera);
// interact with the map if the mouse is outside build tab
if (GetMousePosition().x < EDITOR_TOOLKIT_X) {
if (GetMouseWheelMove() != 0.0) {
camera.zoom += (int)GetMouseWheelMove();
if (camera.zoom > 6.0f)
camera.zoom = 6.0f;
else if (camera.zoom < 4.0f)
camera.zoom = 4.0f;
}
if (IsMouseButtonDown(MOUSE_BUTTON_MIDDLE)) {
Vector2 mousePos = GetMouseDelta();
camera.target.x -= mousePos.x / 5.0f;
camera.target.y -= mousePos.y / 5.0f;
}
}
BeginDrawing();
ClearBackground(RAYWHITE);
BeginMode2D(camera);
SE_DrawTileFloor(floor, &editor.state, &camera);
// rendering grid
for (int x = 0; x < floor->width; x++) {
for (int y = 0; y < floor->height; y++) {
DrawRectangleLines(x * camera.zoom, y * camera.zoom,
TILE_WIDTH * camera.zoom, TILE_HEIGHT * camera.zoom,
BLACK);
}
}
EndMode2D();
SE_DrawEditor(&editor, tileset);
EndDrawing();
}
SE_UnloadTileFloor(floor);
SE_UnloadTileset(tileset);
CloseWindow();
return 0;
}
|