fix: crash when dragging out of the window
This commit is contained in:
parent
a65050fbb3
commit
6f3e302e09
9
game.c
9
game.c
|
@ -220,9 +220,10 @@ void init(struct image canvas) {
|
||||||
void draw( struct image canvas, struct image texture, size_t xpos, size_t ypos, bool vertical) {
|
void draw( struct image canvas, struct image texture, size_t xpos, size_t ypos, bool vertical) {
|
||||||
for (size_t y = 0; y < texture.height; y++) {
|
for (size_t y = 0; y < texture.height; y++) {
|
||||||
for (size_t x = 0; x < texture.width; x++) {
|
for (size_t x = 0; x < texture.width; x++) {
|
||||||
size_t canvas_y = vertical ? x : y;
|
int canvas_y = (vertical ? x : y) + ypos;
|
||||||
size_t canvas_x = vertical ? y : x;
|
int canvas_x = (vertical ? y : x) + xpos;
|
||||||
canvas.buf[(ypos + canvas_y) * canvas.width + xpos + canvas_x] = texture.buf[y * texture.width + x];
|
if (canvas_x < 0 || canvas_x >= (int) canvas.width - 1 || canvas_y < 0 || canvas_y >= (int) canvas.height - 1) continue;
|
||||||
|
canvas.buf[canvas_y * canvas.width + canvas_x] = texture.buf[y * texture.width + x];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -280,7 +281,7 @@ void render(struct image canvas) {
|
||||||
|
|
||||||
// active
|
// active
|
||||||
if (has_active) {
|
if (has_active) {
|
||||||
draw(canvas, red_and_peach_dominoes[active.back.val][active.front.val], CLAMP(mouse_x + active.front.x, 0, canvas.width), CLAMP(mouse_y + active.front.y, 0, canvas.height), active.front.vertical);
|
draw(canvas, red_and_peach_dominoes[active.back.val][active.front.val], mouse_x + active.front.x, mouse_y + active.front.y, active.front.vertical);
|
||||||
}
|
}
|
||||||
|
|
||||||
// character
|
// character
|
||||||
|
|
Loading…
Reference in a new issue