start on constraining mouse pointer correctly
This commit is contained in:
parent
a9ec7c7eac
commit
a144f4fc47
10
const_test.c
10
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() {
|
||||
|
3
game.c
3
game.c
@ -362,8 +362,7 @@ void handleMovement() {
|
||||
&mouseStatus
|
||||
);
|
||||
calculateTargetAngle(
|
||||
&rabbitPosition,
|
||||
&mouseStatus
|
||||
&rabbitPosition
|
||||
);
|
||||
}
|
||||
|
||||
|
2
makefile
2
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
|
||||
|
||||
|
21
movement.c
21
movement.c
@ -1,4 +1,5 @@
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
@ -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*);
|
||||
|
30
movement_test.c
Normal file
30
movement_test.c
Normal file
@ -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;
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
14
spawn_test.c
14
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;
|
||||
}
|
||||
|
3
test.c
3
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);
|
||||
|
Loading…
Reference in New Issue
Block a user