diff --git a/bin/test b/bin/test index 4f297bb..8fb96ad 100755 --- a/bin/test +++ b/bin/test @@ -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 diff --git a/combat.c b/combat.c index d18b0c7..0b70c63 100644 --- a/combat.c +++ b/combat.c @@ -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; } diff --git a/combat.h b/combat.h index f2952c9..083b237 100644 --- a/combat.h +++ b/combat.h @@ -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*); diff --git a/const.c b/const.c index a30a6c3..3f87dfd 100644 --- a/const.c +++ b/const.c @@ -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; + } + } + } + } +}; diff --git a/const.h b/const.h index 4ef80d0..c3a9741 100644 --- a/const.h +++ b/const.h @@ -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 diff --git a/const_test.c b/const_test.c new file mode 100644 index 0000000..b58750a --- /dev/null +++ b/const_test.c @@ -0,0 +1,27 @@ +#include "cutest-1.5/CuTest.h" +#include "const.h" +#include + +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; +} diff --git a/game.c b/game.c index 7f7cce1..a453a60 100644 --- a/game.c +++ b/game.c @@ -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(); diff --git a/makefile b/makefile index 7c9a192..2732708 100644 --- a/makefile +++ b/makefile @@ -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 diff --git a/movement.h b/movement.h index 4416d7e..f0404b4 100644 --- a/movement.h +++ b/movement.h @@ -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; diff --git a/powerup.c b/powerup.c index 290af5d..a690b55 100644 --- a/powerup.c +++ b/powerup.c @@ -1,3 +1,4 @@ +#include #include #include "game.h" diff --git a/powerup_test.c b/powerup_test.c index 1ee6e66..e6e1563 100644 --- a/powerup_test.c +++ b/powerup_test.c @@ -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)); } diff --git a/spawn.c b/spawn.c index 22eff90..b0e61b4 100644 --- a/spawn.c +++ b/spawn.c @@ -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( diff --git a/test.c b/test.c index e4d78ad..d910539 100644 --- a/test.c +++ b/test.c @@ -1,17 +1,26 @@ +#include "const.h" #include "cutest-1.5/CuTest.h" #include 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);