diff options
Diffstat (limited to 'rectangles.c')
-rwxr-xr-x | rectangles.c | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/rectangles.c b/rectangles.c index 70a0c86..98de222 100755 --- a/rectangles.c +++ b/rectangles.c @@ -12,10 +12,17 @@ #define GRID_H (int) (SCREEN_W / TILESIZE); #define GRID_W (int) (SCREEN_H / TILESIZE); -const Rectangle EMPTY_RECT = (Rectangle) {0, 0, 0, 0}; - Rectangle rectangles[RECT_COUNT]; +Rectangle RECTANGLE_TYPES[] = { + (Rectangle){0, 0, 0, 0}, + (Rectangle){0, 0, TILESIZE, TILESIZE}, + (Rectangle){0, 0, TILESIZE/2.0, TILESIZE}, + (Rectangle){0, 0, TILESIZE, TILESIZE/2.0}, + (Rectangle){TILESIZE/2.0, 0, TILESIZE/2.0, TILESIZE}, + (Rectangle){0, TILESIZE/2.0, TILESIZE, TILESIZE/2.0}, +}; + void draw_grid() { // vertical lines for (int x = 0; x < SCREEN_W; x += TILESIZE) { @@ -31,7 +38,20 @@ int rect_valid(Rectangle rect) { return rect.width || rect.height; } +int rect_type(Rectangle rect) { + if (!rect_valid(rect)) + return 0; + + if (rect.width == TILESIZE / 2.0) { + return (int) rect.x % TILESIZE == 0 ? 2 : 4; + } + + if (rect.height == TILESIZE / 2.0) { + return (int) rect.y % TILESIZE == 0 ? 3 : 5; + } + return 1; +} int rects_touch_y(Rectangle rect_a, Rectangle rect_b) { return rect_a.x == rect_b.x && rect_a.width == rect_b.width && @@ -131,11 +151,17 @@ int draw(int *mode) { Rectangle rectangle = (Rectangle){gridx * TILESIZE, gridy * TILESIZE, TILESIZE, TILESIZE}; if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) { - *mode = !rect_valid(rectangles[rect_index]); + *mode = (rect_type(rectangles[rect_index]) + 1) + % (sizeof(RECTANGLE_TYPES)/sizeof(Rectangle)); } + printf("mode is [%d]\n", *mode); + if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) { - rectangles[rect_index] = *mode ? rectangle : EMPTY_RECT; + Rectangle rectangle = RECTANGLE_TYPES[*mode]; + rectangle.x += gridx * TILESIZE; + rectangle.y += gridy * TILESIZE; + rectangles[rect_index] = rectangle; } EndDrawing(); |