blob: 5810c840949ea46762b318fec0d99f88285bad47 (
plain) (
tree)
|
|
/*
* Copyright (c) 2019-2020, 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;
}
|