more tests, tuning difficulty

This commit is contained in:
John Bintz 2024-03-01 07:55:01 -05:00
parent 64de129fc4
commit 6e15ee3d82
13 changed files with 146 additions and 48 deletions

View File

@ -1,4 +1,4 @@
#!/bin/sh
wmake clean && wmake test && dosbox-x -nolog test.exe
wmake clean && wmake test && dosbox-x -c 132x60 -nolog test.exe

View File

@ -375,8 +375,6 @@ int handleEnemyBulletToRabbitCollisions(
return hitCount;
}
#define KNOCKBACK_DISTANCE (3)
void knockbackEnemy(
struct EnemyPosition *enemy,
int angle
@ -464,6 +462,8 @@ int handleRabbitToPowerupCollision(
struct RabbitPosition *rabbitPosition,
struct PlayerPowerup *playerPowerup
) {
struct CompiledSpriteRender *which;
if (!playerPowerup->isActive) return 0;
rabbit.x = rabbitPosition->rabbitPosition[0];
@ -472,17 +472,17 @@ int handleRabbitToPowerupCollision(
switch (playerPowerup->type) {
case POWERUP_TYPE_SHOTGUN:
shotgun.x = playerPowerup->x;
shotgun.y = playerPowerup->y;
populateTargetCollision(&shotgun);
which = &shotgun;
break;
case POWERUP_TYPE_SHIELD_KILLER:
shieldKiller.x = playerPowerup->x;
shieldKiller.y = playerPowerup->y;
populateTargetCollision(&shieldKiller);
which = &shieldKiller;
break;
}
which->x = playerPowerup->x;
which->y = playerPowerup->y;
populateTargetCollision(which);
return isCollision();
}
@ -507,7 +507,7 @@ void handleEnemyKills(
struct PlayerPowerup *playerPowerup,
struct RabbitWeaponry *rabbitWeaponry
) {
int i, hadKill, currentKillCount;
int i, currentKillCount;
currentKillCount = processEnemyKillStates(enemyPosition);
@ -516,15 +516,15 @@ void handleEnemyKills(
globalGameState->kills += currentKillCount;
processPowerupCooldown(
playerPowerup,
globalGameState,
rabbitWeaponry,
currentKillCount
);
if (currentKillCount > 0) {
processPowerupCooldown(
playerPowerup,
globalGameState,
rabbitWeaponry,
currentKillCount
);
if (hadKill) {
for (i = 0; i < 10; ++i) {
for (i = 0; i < MAX_DIFFICULTY; ++i) {
if (globalGameState->kills > difficultyBands[i]) {
globalGameState->difficulty = i + 1;
}

View File

@ -52,7 +52,8 @@ int handleRabbitToPowerupCollision(
void handleEnemyKills(
struct EnemyPosition enemyPosition[],
struct GlobalGameState *globalGameState,
struct PlayerPowerup *playerPowerup
struct PlayerPowerup *playerPowerup,
struct RabbitWeaponry *rabbitWeaponry
);
void fireCurrentWeaponOnce(struct RabbitWeaponry*);

61
const.c
View File

@ -1,7 +1,30 @@
#include "system/vga.h"
#include "const.h"
int difficultyBands[MAX_DIFFICULTY] = { 10, 20, 30, 50, 80, 130, 210, 340, 550, 890 };
int difficultyBands[MAX_DIFFICULTY];
int hitPointRanges[MAX_DIFFICULTY][4] = {
{ 1, 1, 1, 1 },
{ 1, 1, 1, 1 },
{ 1, 1, 1, 2 },
{ 1, 1, 1, 2 },
{ 1, 1, 2, 2 },
{ 1, 2, 2, 2 },
{ 1, 2, 2, 2 },
{ 1, 2, 2, 3 },
{ 1, 2, 2, 3 },
{ 1, 2, 3, 3 },
{ 1, 2, 3, 3 },
{ 1, 2, 3, 3 },
{ 1, 2, 3, 3 },
{ 1, 2, 3, 3 },
{ 1, 2, 3, 3 },
{ 1, 2, 3, 3 },
{ 1, 2, 3, 3 },
{ 1, 2, 3, 3 },
{ 1, 2, 3, 3 },
{ 1, 2, 3, 3 }
};
struct SpriteBounds bounds;
// TODO: centralize these outside of game.c
@ -12,3 +35,39 @@ struct CompiledSpriteRender rabbit,
enemyBullet,
shotgun,
shieldKiller;
void buildDifficultyBands() {
int i;
float current = BASE_KILLS;
for (i = 0; i < MAX_DIFFICULTY; ++i) {
difficultyBands[i] = (int)current;
current *= KILLS_NEEDED_FOR_NEXT_LEVEL_MULTIPLIER;
}
}
void buildHitPointRages() {
int currentRange[4] = { 1, 1, 1, 1 };
int i, j, countOfCurrent = 0, tmp;
for (i = 0; i < MAX_DIFFICULTY; ++i) {
for (j = 0; j < 4; ++j) {
hitPointRanges[i][j] = currentRange[j];
}
countOfCurrent++;
if (countOfCurrent == 2) {
countOfCurrent = 0;
currentRange[3]++;
for (j = 3; j > 0; --j) {
if (currentRange[j] > currentRange[j - 1]) {
tmp = currentRange[j - 1];
currentRange[j - 1] = currentRange[j];
currentRange[j] = tmp;
}
}
}
}
};

18
const.h
View File

@ -12,7 +12,7 @@
#define RABBIT_MOTION_DRAG (2)
#define RABBIT_MOTION_ACCELERATION (5)
#define RABBIT_MOTION_MAX_SPEED (12)
#define RABBIT_MOTION_MAX_SPEED (10)
#define RABBIT_MOTION_VELOCITY_DECAY (5)
#define RABBIT_BULLET_LIMIT (9)
@ -55,9 +55,20 @@
#define POWERUP_RESPAWN_COOLDOWN_PER_LEVEL (10)
#define SHOTGUN_ROUNDS_PER_LEVEL (25)
#define MAX_DIFFICULTY (10)
#define MAX_DIFFICULTY (20)
#define BASE_KILLS (10)
#define KILLS_NEEDED_FOR_NEXT_LEVEL_MULTIPLIER (2.1)
#define WEAPON_TYPE_SINGLE_SHOT_GUN (0)
#define WEAPON_TYPE_SPREAD_SHOT_GUN (1)
#define POWERUP_TYPE_SHOTGUN (0)
#define POWERUP_TYPE_SHIELD_KILLER (1)
#define KNOCKBACK_DISTANCE (3)
extern int difficultyBands[];
extern int hitPointRanges[MAX_DIFFICULTY][4];
extern struct SpriteBounds bounds;
extern struct CompiledSpriteRender rabbit,
@ -68,4 +79,7 @@ extern struct CompiledSpriteRender rabbit,
shotgun,
shieldKiller;
void buildDifficultyBands();
void buildHitPointRages();
#endif

27
const_test.c Normal file
View File

@ -0,0 +1,27 @@
#include "cutest-1.5/CuTest.h"
#include "const.h"
#include <stdio.h>
void TestBuildDifficultyBands(CuTest *tc) {
buildDifficultyBands();
CuAssertIntEquals(tc, 10, difficultyBands[0]);
CuAssertIntEquals(tc, 21, difficultyBands[1]);
CuAssertIntEquals(tc, 44, difficultyBands[2]);
}
void TestBuildHitPointRanges(CuTest *tc) {
buildHitPointRages();
CuAssertIntEquals(tc, 1, hitPointRanges[0][0]);
CuAssertIntEquals(tc, 1, hitPointRanges[1][0]);
CuAssertIntEquals(tc, 2, hitPointRanges[2][0]);
CuAssertIntEquals(tc, 1, hitPointRanges[2][3]);
}
CuSuite *ConstGetSuite() {
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, TestBuildDifficultyBands);
SUITE_ADD_TEST(suite, TestBuildHitPointRanges);
return suite;
}

8
game.c
View File

@ -318,6 +318,9 @@ int setupGame() {
installKeyboardHandler();
initializeDrawBuffer();
buildDifficultyBands();
buildHitPointRages();
setupWallSprites();
setupRabbitSprites();
setupRabbitBullets();
@ -481,7 +484,8 @@ int main(void) {
handleEnemyKills(
enemyPosition,
&globalGameState,
&playerPowerup
&playerPowerup,
&rabbitWeaponry
);
sprintf(buffer, "Hit: %d", globalGameState.kills);
@ -492,6 +496,8 @@ int main(void) {
renderStringToDrawBuffer(buffer, 1, 0, 210, 40);
sprintf(buffer, "Cool: %d ", playerPowerup.cooldown);
renderStringToDrawBuffer(buffer, 1, 0, 210, 50);
sprintf(buffer, "Wpn: %d ", rabbitWeaponry.currentWeapon);
renderStringToDrawBuffer(buffer, 1, 0, 210, 60);
waitStartVbl();
copyDrawBufferToDisplay();

View File

@ -1,5 +1,5 @@
obj = sprites.o game.o bmpload.o arena.o movement.o combat.o spawn.o const.o powerup.o
test_obj = test.o spawn.o spawn_test.o powerup.o powerup_test.o const.o combat.o combat_test.o
test_obj = test.o spawn.o spawn_test.o powerup.o powerup_test.o const.o const_test.o combat.o combat_test.o
all: system/system.lib game.exe test .SYMBOLIC

View File

@ -18,18 +18,12 @@ struct RabbitPosition {
int mouseAngle;
};
#define WEAPON_TYPE_SINGLE_SHOT_GUN (0)
#define WEAPON_TYPE_SPREAD_SHOT_GUN (1)
struct RabbitWeaponry {
char cooldown;
char currentWeapon;
int currentWeaponRemainingRounds;
};
#define POWERUP_TYPE_SHOTGUN (0)
#define POWERUP_TYPE_SHIELD_KILLER (1)
struct PlayerPowerup {
int x, y;
int cooldown;

View File

@ -1,3 +1,4 @@
#include <stdio.h>
#include <stdlib.h>
#include "game.h"

View File

@ -11,16 +11,16 @@ void TestDeterminePowerupCooldownTime(CuTest *tc) {
srand(1);
CuAssertIntEquals(tc, 18, determinePowerupCooldownTime(0));
CuAssertIntEquals(tc, 38, determinePowerupCooldownTime(1));
CuAssertIntEquals(tc, 33, determinePowerupCooldownTime(2));
CuAssertIntEquals(tc, 25, determinePowerupCooldownTime(1));
CuAssertIntEquals(tc, 81, determinePowerupCooldownTime(2));
}
void TestDetermineShotgunRounds(CuTest *tc) {
srand(1);
CuAssertIntEquals(tc, 18, determineShotgunRounds(0));
CuAssertIntEquals(tc, 38, determineShotgunRounds(1));
CuAssertIntEquals(tc, 48, determineShotgunRounds(2));
CuAssertIntEquals(tc, 39, determineShotgunRounds(1));
CuAssertIntEquals(tc, 81, determineShotgunRounds(2));
}

15
spawn.c
View File

@ -17,21 +17,8 @@ struct SpawnPointRange spawnPointRanges[4] = {
{ .left = TILE_SIZE - 8, .width = TILE_SIZE, .top = TILE_SIZE * 4, .height = TILE_SIZE * 2 },
};
int HIT_POINT_RANGES[10][4] = {
{ 1, 1, 1, 1 },
{ 1, 1, 1, 1 },
{ 1, 1, 1, 2 },
{ 1, 1, 1, 2 },
{ 1, 1, 2, 2 },
{ 1, 2, 2, 2 },
{ 1, 2, 2, 2 },
{ 1, 2, 2, 3 },
{ 1, 2, 2, 3 },
{ 1, 2, 3, 3 }
};
int determineEnemyHitPointCalculation(int difficulty, int roll) {
return HIT_POINT_RANGES[difficulty][roll];
return hitPointRanges[difficulty][roll];
}
void selectEnemySpawnLocation(

9
test.c
View File

@ -1,17 +1,26 @@
#include "const.h"
#include "cutest-1.5/CuTest.h"
#include <stdio.h>
CuSuite *SpawnGetSuite();
CuSuite *PowerupGetSuite();
CuSuite *CombatGetSuite();
CuSuite *ConstGetSuite();
void beforeAll() {
buildDifficultyBands();
}
int RunAllTests(void) {
CuString *output = CuStringNew();
CuSuite *suite = CuSuiteNew();
beforeAll();
CuSuiteAddSuite(suite, SpawnGetSuite());
CuSuiteAddSuite(suite, PowerupGetSuite());
CuSuiteAddSuite(suite, CombatGetSuite());
CuSuiteAddSuite(suite, ConstGetSuite());
CuSuiteRun(suite);
CuSuiteSummary(suite, output);