aboutsummaryrefslogtreecommitdiff
path: root/progress/src/bulletCollision.c
blob: d6c52c54de2b4d3c0491c802c42fb591efaa88d1 (plain)
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
#include "main.h"

void bulletCollision(GameState *gameState)
{
    int p1_x = gameState->player1.x, p1_y = gameState->player1.y;
    int p1_w = gameState->player1.w, p1_h = gameState->player1.h;

    int p2_x = gameState->player2.x, p2_y = gameState->player2.y;
    int p2_w = gameState->player2.w, p2_h = gameState->player2.h;

    for(int i = 0; i < MAX_BULLETS; i++) if(gameState->bala_1[i])
    {
        if(gameState->bala_1[i]->x > p1_x && gameState->bala_1[i]->x < p1_x + p1_w
           && gameState->bala_1[i]->y > p1_y && gameState->bala_1[i]->y < p1_y + p1_h && gameState->bala_1[i]->owner == 2)
        {
            if(gameState->player1.muerto == 1){}
            else
                printf("player1 muerto\n");
                gameState->player1.muerto = 1;
        }
        else if(gameState->bala_1[i]->x > p2_x && gameState->bala_1[i]->x < p2_x + p2_w
           && gameState->bala_1[i]->y > p2_y && gameState->bala_1[i]->y < p2_y + p2_h && gameState->bala_1[i]->owner == 1)
        {
            if(gameState->player2.muerto == 1){}
            else
                printf("player2 muerto\n");
                gameState->player2.muerto = 1;

        }
    }
}