From b9b74e88028f81e7b169a5e168102138e8c2c46c Mon Sep 17 00:00:00 2001 From: yzrh Date: Sat, 10 Oct 2020 17:16:14 +0000 Subject: Initial commit. --- src/collision.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/collision.c (limited to 'src/collision.c') diff --git a/src/collision.c b/src/collision.c new file mode 100644 index 0000000..5810c84 --- /dev/null +++ b/src/collision.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2019-2020, yzrh + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include + +#include "screen.h" +#include "renderer.h" + +bool +collision(int *a, int *b) +{ + if (a[0] < b[0] + b[2] && + a[0] + a[2] > b[0] && + a[1] < b[1] + b[3] && + a[1] + a[3] > b[1]) + return 1; + return 0; +} + +bool +collision_block(int *a, int *b) +{ + return collision( + (int[]) {a[0], a[1], SCREEN_UNIT, SCREEN_UNIT}, + (int[]) {b[0], b[1], SCREEN_UNIT, SCREEN_UNIT}); +} + +bool +collision_bound(float x, float y, Snake_Text *message) +{ + if (x > message->pos.x && + x < message->pos.x + message->pos.w && + y > message->pos.y && + y < message->pos.y + message->pos.h) + return 1; + return 0; +} -- cgit v1.2.3