diff --git a/const_test.c b/const_test.c index b58750a..4c25a80 100644 --- a/const_test.c +++ b/const_test.c @@ -5,9 +5,9 @@ void TestBuildDifficultyBands(CuTest *tc) { buildDifficultyBands(); - CuAssertIntEquals(tc, 10, difficultyBands[0]); - CuAssertIntEquals(tc, 21, difficultyBands[1]); - CuAssertIntEquals(tc, 44, difficultyBands[2]); + CuAssertIntEquals(tc, 30, difficultyBands[0]); + CuAssertIntEquals(tc, 37, difficultyBands[1]); + CuAssertIntEquals(tc, 46, difficultyBands[2]); } void TestBuildHitPointRanges(CuTest *tc) { @@ -15,8 +15,8 @@ void TestBuildHitPointRanges(CuTest *tc) { CuAssertIntEquals(tc, 1, hitPointRanges[0][0]); CuAssertIntEquals(tc, 1, hitPointRanges[1][0]); - CuAssertIntEquals(tc, 2, hitPointRanges[2][0]); - CuAssertIntEquals(tc, 1, hitPointRanges[2][3]); + CuAssertIntEquals(tc, 2, hitPointRanges[4][0]); + CuAssertIntEquals(tc, 1, hitPointRanges[4][3]); } CuSuite *ConstGetSuite() { diff --git a/game.c b/game.c index a0712e6..e4c41c8 100644 --- a/game.c +++ b/game.c @@ -362,8 +362,7 @@ void handleMovement() { &mouseStatus ); calculateTargetAngle( - &rabbitPosition, - &mouseStatus + &rabbitPosition ); } diff --git a/makefile b/makefile index 2732708..58e2557 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 const_test.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 movement.o movement_test.o all: system/system.lib game.exe test .SYMBOLIC diff --git a/movement.c b/movement.c index 66bb54f..f56e284 100644 --- a/movement.c +++ b/movement.c @@ -1,4 +1,5 @@ #include +#include #include #include "game.h" @@ -26,11 +27,11 @@ void captureAndLimitMousePosition( } void calculateTargetAngle( - struct RabbitPosition *pos, - struct MouseStatus *mouseStatus + struct RabbitPosition *pos ) { + int targetX, targetY; float distanceX, distanceY; - float angle; + float angle, fixHypotenuse, fixDistance; // Position the cursor distanceX = pos->mouseDotPosition[0] - pos->rabbitPosition[0]; @@ -45,8 +46,18 @@ void calculateTargetAngle( pos->oldMousePosition[0] = pos->mousePosition[0]; pos->oldMousePosition[1] = pos->mousePosition[1]; - pos->mousePosition[0] = pos->rabbitPosition[0] + distanceX; - pos->mousePosition[1] = pos->rabbitPosition[1] + distanceY; + targetX = pos->rabbitPosition[0] + distanceX; + targetY = pos->rabbitPosition[1] + distanceY; + + if (targetX > (ARENA_WIDTH_TILES - 1) * TILE_SIZE) { + fixDistance = targetX - ((ARENA_WIDTH_TILES - 1) * TILE_SIZE); + fixHypotenuse = fixDistance / sin(angle * DEG2RAD); + targetX = (ARENA_WIDTH_TILES - 1) * TILE_SIZE; + targetY = pos->rabbitPosition[1] + -cos(angle * DEG2RAD) * -fixHypotenuse; + } + + pos->mousePosition[0] = targetX; + pos->mousePosition[1] = targetY; pos->mouseAngle = angle; } diff --git a/movement.h b/movement.h index f0404b4..e1b742f 100644 --- a/movement.h +++ b/movement.h @@ -64,7 +64,7 @@ struct EnemyPosition { int enemyFireDelayStep; }; -void calculateTargetAngle(struct RabbitPosition*, struct MouseStatus*); +void calculateTargetAngle(struct RabbitPosition*); void captureAndLimitMousePosition(struct RabbitPosition*, struct MouseStatus*); void handleRabbitMovement(struct RabbitPosition*, struct KeyboardKeydownState*); void handleEnemyMovement(struct EnemyPosition[], struct RabbitPosition*); diff --git a/movement_test.c b/movement_test.c new file mode 100644 index 0000000..722e789 --- /dev/null +++ b/movement_test.c @@ -0,0 +1,30 @@ +#include "cutest-1.5/CuTest.h" +#include "movement.h" + +#include "const.h" + +void TestCalculateTargetAngle_AgainstRightWall(CuTest *tc) { + struct RabbitPosition rabbitPosition; + + // mouse against very edge + rabbitPosition.mouseDotPosition[0] = 199; + rabbitPosition.mouseDotPosition[1] = 30; + + // rabbit against wall + rabbitPosition.rabbitPosition[0] = 179; + rabbitPosition.rabbitPosition[1] = 80; + + calculateTargetAngle(&rabbitPosition); + + // mouse should not extend (tile width - mouse width) past player + + CuAssertIntEquals(tc, 180, rabbitPosition.mousePosition[0]); + CuAssertIntEquals(tc, 105, rabbitPosition.mousePosition[1]); + CuAssertIntEquals(tc, 21, rabbitPosition.mouseAngle); +} + +CuSuite *MovementGetSuite() { + CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, TestCalculateTargetAngle_AgainstRightWall); + return suite; +} diff --git a/powerup_test.c b/powerup_test.c index 0a0ea77..b39d3d2 100644 --- a/powerup_test.c +++ b/powerup_test.c @@ -10,17 +10,17 @@ void TestDeterminePowerupCooldownTime(CuTest *tc) { srand(1); - CuAssertIntEquals(tc, 18, determinePowerupCooldownTime(0)); - CuAssertIntEquals(tc, 25, determinePowerupCooldownTime(1)); - CuAssertIntEquals(tc, 81, determinePowerupCooldownTime(2)); + CuAssertIntEquals(tc, 38, determinePowerupCooldownTime(0)); + CuAssertIntEquals(tc, 60, determinePowerupCooldownTime(1)); + CuAssertIntEquals(tc, 85, determinePowerupCooldownTime(2)); } void TestDetermineWeaponRounds(CuTest *tc) { srand(1); - CuAssertIntEquals(tc, 18, determineWeaponRounds(0)); - CuAssertIntEquals(tc, 39, determineWeaponRounds(1)); - CuAssertIntEquals(tc, 81, determineWeaponRounds(2)); + CuAssertIntEquals(tc, 53, determineWeaponRounds(0)); + CuAssertIntEquals(tc, 71, determineWeaponRounds(1)); + CuAssertIntEquals(tc, 85, determineWeaponRounds(2)); } @@ -108,7 +108,7 @@ void TestProcessPowerupCooldown_Triggered(CuTest *tc) { CuAssertIntEquals(tc, 0, playerPowerup.willBeInactive); // rand - CuAssertIntEquals(tc, 13, playerPowerup.cooldown); + CuAssertIntEquals(tc, 33, playerPowerup.cooldown); CuAssertIntEquals(tc, 58, playerPowerup.x); CuAssertIntEquals(tc, 178, playerPowerup.y); } diff --git a/spawn_test.c b/spawn_test.c index 754982b..00d49d0 100644 --- a/spawn_test.c +++ b/spawn_test.c @@ -39,17 +39,6 @@ void TestSelectEnemySpawnLocation(CuTest *tc) { CuAssertIntEquals(tc, 91, spawnDetails.spawnY); } -void TestDetermineEnemyHitPointCalculation(CuTest *tc) { - srand(1); - - CuAssertIntEquals(tc, 1, determineEnemyHitPointCalculation(0, 0)); - CuAssertIntEquals(tc, 1, determineEnemyHitPointCalculation(0, 3)); - - CuAssertIntEquals(tc, 1, determineEnemyHitPointCalculation(2, 0)); - CuAssertIntEquals(tc, 1, determineEnemyHitPointCalculation(2, 2)); - CuAssertIntEquals(tc, 2, determineEnemyHitPointCalculation(2, 3)); -} - void TestSpawnEnemy(CuTest *tc) { srand(1); @@ -62,7 +51,7 @@ void TestSpawnEnemy(CuTest *tc) { spawnEnemy(&spawnDetails, &globalGameState); // randomized values - CuAssertIntEquals(tc, 2, enemyPosition.hitPoints); + CuAssertIntEquals(tc, 1, enemyPosition.hitPoints); CuAssertIntEquals(tc, 103, enemyPosition.enemyFireDelayStep); // from spawndetails @@ -76,7 +65,6 @@ void TestSpawnEnemy(CuTest *tc) { CuSuite *SpawnGetSuite() { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, TestSelectEnemySpawnLocation); - SUITE_ADD_TEST(suite, TestDetermineEnemyHitPointCalculation); SUITE_ADD_TEST(suite, TestSpawnEnemy); return suite; } diff --git a/test.c b/test.c index d910539..45fb068 100644 --- a/test.c +++ b/test.c @@ -6,9 +6,11 @@ CuSuite *SpawnGetSuite(); CuSuite *PowerupGetSuite(); CuSuite *CombatGetSuite(); CuSuite *ConstGetSuite(); +CuSuite *MovementGetSuite(); void beforeAll() { buildDifficultyBands(); + buildHitPointRages(); } int RunAllTests(void) { @@ -21,6 +23,7 @@ int RunAllTests(void) { CuSuiteAddSuite(suite, PowerupGetSuite()); CuSuiteAddSuite(suite, CombatGetSuite()); CuSuiteAddSuite(suite, ConstGetSuite()); + CuSuiteAddSuite(suite, MovementGetSuite()); CuSuiteRun(suite); CuSuiteSummary(suite, output);