mirror of https://git.sr.ht/~kikoodx/sle
Mouse update code, place and erase tile
This commit is contained in:
parent
28f40ac97e
commit
8fee3bcf26
|
@ -28,8 +28,10 @@ void level_draw(struct Level level, Texture2D tileset)
|
|||
}
|
||||
}
|
||||
|
||||
void editor_mouse_draw(int x, int y) {
|
||||
void editor_mouse_draw(int x, int y)
|
||||
{
|
||||
const int tx = x * TILE_WIDTH + draw_offset_x;
|
||||
const int ty = y * TILE_HEIGHT + draw_offset_y;
|
||||
DrawRectangle(tx, ty, TILE_WIDTH, TILE_HEIGHT, overring_tile_color);
|
||||
DrawRectangle(tx, ty, TILE_WIDTH, TILE_HEIGHT,
|
||||
overring_tile_color);
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
#include <sys/wait.h>
|
||||
|
||||
static void init_mouse(void);
|
||||
static void update_mouse(int *mouse_x, int *mouse_y, struct Level level,
|
||||
struct SharedData *shared_data);
|
||||
|
||||
int editing_area_main(int argc, char **argv,
|
||||
struct SharedData *shared_data)
|
||||
|
@ -37,8 +39,8 @@ int editing_area_main(int argc, char **argv,
|
|||
|
||||
while (!WindowShouldClose()) {
|
||||
/* update */
|
||||
mouse_x = GetMouseX();
|
||||
mouse_y = GetMouseY();
|
||||
update_mouse(&mouse_x, &mouse_y, level,
|
||||
shared_data);
|
||||
|
||||
/* draw */
|
||||
BeginDrawing();
|
||||
|
@ -75,7 +77,38 @@ int editing_area_main(int argc, char **argv,
|
|||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
static void init_mouse(void) {
|
||||
static void init_mouse(void)
|
||||
{
|
||||
SetMouseOffset(-draw_offset_x, -draw_offset_y);
|
||||
SetMouseScale(1.0 / (TILE_WIDTH * EDITOR_SCALE), 1.0 / (TILE_HEIGHT * EDITOR_SCALE));
|
||||
SetMouseScale(1.0 / (TILE_WIDTH * EDITOR_SCALE),
|
||||
1.0 / (TILE_HEIGHT * EDITOR_SCALE));
|
||||
}
|
||||
|
||||
static void update_mouse(int *mouse_x, int *mouse_y, struct Level level,
|
||||
struct SharedData *shared_data)
|
||||
{
|
||||
const bool left_click = IsMouseButtonDown(0);
|
||||
const bool right_click = IsMouseButtonDown(1);
|
||||
|
||||
/* update mouse position */
|
||||
*mouse_x = GetMouseX();
|
||||
*mouse_y = GetMouseY();
|
||||
if (*mouse_x < 0)
|
||||
*mouse_x = 0;
|
||||
if (*mouse_y < 0)
|
||||
*mouse_y = 0;
|
||||
if (*mouse_x >= level.width)
|
||||
*mouse_x = level.width - 1;
|
||||
if (*mouse_y >= level.height)
|
||||
*mouse_y = level.height - 1;
|
||||
|
||||
/* set tile */
|
||||
if (left_click) {
|
||||
level.data[*mouse_x + *mouse_y * level.width] =
|
||||
shared_data->selected_tile;
|
||||
}
|
||||
/* remove tile */
|
||||
if (right_click) {
|
||||
level.data[*mouse_x + *mouse_y * level.width] = 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue