From 2e1a7e73fd538204b61b0f6713e5035af1c4dd65 Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Mon, 29 Aug 2016 23:44:15 +0200 Subject: [PATCH] add IsOnCharacter helper function --- src/character.c | 7 +++++++ src/character.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/src/character.c b/src/character.c index bd82e13..32a0cfa 100644 --- a/src/character.c +++ b/src/character.c @@ -231,3 +231,10 @@ SYMBOL_EXPORT int GetCharacterY(struct Game *game, struct Character *character) SYMBOL_EXPORT float GetCharacterAngle(struct Game *game, struct Character *character) { return character->angle; } + +SYMBOL_EXPORT bool IsOnCharacter(struct Game *game, struct Character *character, int x, int y) { + int x1 = GetCharacterX(game, character), y1 = GetCharacterY(game, character); + int x2 = x1 + al_get_bitmap_width(character->bitmap), y2 = y1 + al_get_bitmap_height(character->bitmap); + + return ((x >= x1) && (x <= x2) && (y >= y1) && (y <= y2)); +} diff --git a/src/character.h b/src/character.h index c603933..76bfb3d 100644 --- a/src/character.h +++ b/src/character.h @@ -82,4 +82,6 @@ int GetCharacterX(struct Game *game, struct Character *character); int GetCharacterY(struct Game *game, struct Character *character); float GetCharacterAngle(struct Game *game, struct Character *character); +bool IsOnCharacter(struct Game *game, struct Character *character, int x, int y); + #endif