58 lines
1.4 KiB
C
58 lines
1.4 KiB
C
/*
|
|
** EPITECH PROJECT, 2018
|
|
** task01
|
|
** File description:
|
|
** I do task
|
|
*/
|
|
#include "game/game.h"
|
|
#include "game/core.h"
|
|
|
|
static void collision_player_stone(sfml_t *sfml,
|
|
player_t *player, object_t *object)
|
|
{
|
|
if (object == NULL)
|
|
return;
|
|
if (object->x + 24 >= player->x + 8 && object->x <= player->x + 56
|
|
&& object->y + 24 >= player->y && object->y <= player->y + 32){
|
|
object->y = player->y - 16;
|
|
object->dy = -2;
|
|
player->counter_jump = PLAYER_MAX_JUMP;
|
|
sfml->debug |= 0x02;
|
|
player->dy = 6;
|
|
}
|
|
}
|
|
|
|
static void collision_player_bullet(sfml_t *sfml,
|
|
player_t *player, object_t *object)
|
|
{
|
|
if (object == NULL || object->sleep == BULLET_STOP)
|
|
return;
|
|
if (object->x + 24 >= player->x + 8 && object->x <= player->x + 56
|
|
&& object->y + 24 >= player->y + 8 && object->y <= player->y + 64){
|
|
player->action = PLAYER_DEAD;
|
|
player->dead_counter = 0;
|
|
}
|
|
}
|
|
|
|
void collision_stone(sfml_t *sfml)
|
|
{
|
|
void (*fun[2])(sfml_t*, player_t*, object_t*);
|
|
int i;
|
|
int j;
|
|
|
|
if (sfml->scene->thrower == NULL)
|
|
return;
|
|
i = -1;
|
|
fun[1] = &collision_player_stone;
|
|
fun[0] = &collision_player_bullet;
|
|
while (++i < sfml->scene->level->thrower_counter){
|
|
j = -1;
|
|
while (++j < NB_OBJECT)
|
|
fun[sfml->scene->thrower[i]->action == ID_THROWER_STONE]
|
|
(sfml, sfml->scene->player,
|
|
sfml->scene->thrower[i]->object[j]);
|
|
}
|
|
sfml->scene->player->y += (sfml->debug & 0x02) ? 4 : 0;
|
|
sfml->debug &= ~0x02;
|
|
}
|