add IsOnCharacter helper function

This commit is contained in:
Sebastian Krzyszkowiak 2016-08-29 23:44:15 +02:00
parent 40cdf33bb8
commit 2e1a7e73fd
2 changed files with 9 additions and 0 deletions

View file

@ -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));
}

View file

@ -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