diff options
| author | Thomas Guillermo Albers Raviola <thomas@thomaslabs.org> | 2026-01-16 19:38:33 +0100 |
|---|---|---|
| committer | Thomas Guillermo Albers Raviola <thomas@thomaslabs.org> | 2026-01-16 19:38:33 +0100 |
| commit | a90db3b7b6e87e24c789b5db222f1cef92809bde (patch) | |
| tree | 2096abcb1ac1ea970a51e598257186bc4e030b22 /progress/src/shoot.c | |
Initial commit
Diffstat (limited to 'progress/src/shoot.c')
| -rw-r--r-- | progress/src/shoot.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/progress/src/shoot.c b/progress/src/shoot.c new file mode 100644 index 0000000..4edb116 --- /dev/null +++ b/progress/src/shoot.c @@ -0,0 +1,57 @@ +#include "main.h" + +int addBullet(int x, int y, int dx, GameState *gameState, int player) +{ + int found = -1; + int shooting = 0; + for(int i = 0; i < MAX_BULLETS; i++) + { + if(gameState->bala_1[i] == NULL) + { + if(player == 1 && gameState->player1.cargador > 0) + { + found = i; + shooting = 1; + gameState->player1.cargador -= 1; + } + else if(player == 2 && gameState->player2.cargador > 0) + { + found = i; + shooting = 1; + gameState->player2.cargador -= 1; + } + printf("%d/6 - %d/6\n",gameState->player1.cargador, gameState->player2.cargador); + break; + } + } + + if(found >= 0) + { + int i = found; + gameState->bala_1[i] = malloc(sizeof(Bala_player_1)); + gameState->bala_1[i]->x = x; + gameState->bala_1[i]->y = y; + gameState->bala_1[i]->dx = dx; + gameState->bala_1[i]->owner = player; + } + return shooting; +} + +void removeBullet(int i, GameState *gameState) +{ + if(gameState->bala_1[i]) + { + free(gameState->bala_1[i]); + gameState->bala_1[i] = NULL; + } +} + +void processBullet(GameState *gameState) +{ + for(int i = 0; i < MAX_BULLETS; i++) if(gameState->bala_1[i]) + { + gameState->bala_1[i]->x += gameState->bala_1[i]->dx; + if(gameState->bala_1[i]->x < -1000 || gameState->bala_1[i]->x > 1000) + removeBullet(i, gameState); + } +} |
