dos-vga-arena-shooter-game/powerup.c

47 lines
1.5 KiB
C
Raw Normal View History

#include <stdlib.h>
#include "game.h"
#include "movement.h"
#include "powerup.h"
#include "const.h"
// powerup should spawn every other difficulty band
// so the first spawn should happen somewhere 10 + (20 * rand())
int determinePowerupCooldownTime(int difficulty) {
if (difficulty > MAX_DIFFICULTY) exit(1);
return difficultyBands[difficulty] + rand() % difficultyBands[difficulty];
}
// if every shot lands, you should run out slightly before the next powerup
// should be available
// so for the first rounds should be difficulty(1) + difficulty(2) % rand() or so
int determineShotgunRounds(int difficulty) {
if (difficulty > MAX_DIFFICULTY) exit(1);
return difficultyBands[difficulty] +
difficultyBands[difficulty] / 2 +
rand() % (difficultyBands[difficulty] / 2);
}
void processPowerupCooldown(
struct PlayerPowerup *playerPowerup,
struct GlobalGameState *globalGameState,
struct RabbitWeaponry *rabbitWeaponry,
int killCount
) {
if (playerPowerup->isActive) return;
if (rabbitWeaponry->currentWeapon != WEAPON_TYPE_SINGLE_SHOT_GUN) return;
playerPowerup->cooldown -= killCount;
if (playerPowerup->cooldown <= 0) {
playerPowerup->x = TILE_SIZE + rand() % ((ARENA_WIDTH_TILES - 2) * TILE_SIZE);
playerPowerup->y = TILE_SIZE + rand() % ((ARENA_HEIGHT_TILES - 2) * TILE_SIZE);
playerPowerup->isActive = 1;
playerPowerup->willBeInactive = 0;
playerPowerup->cooldown = determinePowerupCooldownTime(globalGameState->difficulty);
}
}