blob: 66f710a6de8124028ae94facda45d5fb24916379 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
/*
* Copyright (c) 2019-2021, yzrh <yzrh@noema.org>
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdbool.h>
#include <SDL2/SDL.h>
#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;
}
|