+1
include/keraforge/world.h
+1
include/keraforge/world.h
+27
src/main.c
+27
src/main.c
···
62
62
kf_tiles.color[1] = BROWN;
63
63
kf_tiles.color[2] = GRAY;
64
64
kf_tiles.collide[2] = true;
65
+
kf_tiles.count = 3;
65
66
66
67
if (!DirectoryExists("data"))
67
68
MakeDirectory("data");
···
113
114
cam = (Camera2D){{GetScreenWidth() / 2.0f, GetScreenHeight() / 2.0f}, {0, 0}, 0, 2};
114
115
while (!WindowShouldClose())
115
116
{
117
+
if (IsWindowResized())
118
+
{
119
+
cam.offset.x = GetScreenWidth() / 2.0f;
120
+
cam.offset.y = GetScreenHeight() / 2.0f;
121
+
}
122
+
116
123
player->tick(world, player);
117
124
118
125
Vector2 v = GetScreenToWorld2D(GetMousePosition(), cam);
···
125
132
BeginMode2D(cam);
126
133
kf_world_draw(world, cam);
127
134
if (select.x < world->width && select.y < world->height)
135
+
{
136
+
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
137
+
{
138
+
kf_tileid_t *t = kf_world_gettile(world, select.x, select.y);
139
+
if (++(*t) >= kf_tiles.count)
140
+
*t = 0;
141
+
}
142
+
else if (IsMouseButtonPressed(MOUSE_BUTTON_RIGHT))
143
+
{
144
+
kf_tileid_t *t = kf_world_gettile(world, select.x, select.y);
145
+
if (--(*t) >= kf_tiles.count)
146
+
*t = 0;
147
+
}
148
+
else if (IsMouseButtonDown(MOUSE_BUTTON_MIDDLE))
149
+
{
150
+
kf_tileid_t *t = kf_world_gettile(world, select.x, select.y);
151
+
if (*t)
152
+
*t = 0;
153
+
}
128
154
DrawRectangleLines(select.x * KF_TILE_SIZE_PX, select.y * KF_TILE_SIZE_PX, KF_TILE_SIZE_PX, KF_TILE_SIZE_PX, WHITE);
155
+
}
129
156
player->draw(world, player);
130
157
EndMode2D();
131
158