Setup testing environment to update the screen as well so the player movement testing works

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent 3073b1b85a
commit 0105a968cb
  1. BIN
      C++ProjectTemplate
  2. 41
      SeasonI.h
  3. 44
      main.cpp
  4. 78
      test/test.cpp

Binary file not shown.

@ -58,22 +58,22 @@ class SeasonI:public PixelGameEngine{
void HandleRollingCounters(int i,int(&counter)[4][3],int(&display)[4][3],Entity*member,int maxVal,int currentVal,int targetVal,bool pp=false); void HandleRollingCounters(int i,int(&counter)[4][3],int(&display)[4][3],Entity*member,int maxVal,int currentVal,int targetVal,bool pp=false);
void HandleBattle(); void HandleBattle();
void HandleCutscenes(); void HandleCutscenes();
bool TabHeld(); bool TabHeld();
bool UpPressed(); bool UpPressed();
bool DownPressed(); bool DownPressed();
bool LeftPressed(); bool LeftPressed();
bool RightPressed(); bool RightPressed();
bool BackPressed(); bool BackPressed();
bool UpHeld(); bool UpHeld();
bool DownHeld(); bool DownHeld();
bool LeftHeld(); bool LeftHeld();
bool RightHeld(); bool RightHeld();
bool BackHeld(); bool BackHeld();
bool UpReleased(); bool UpReleased();
bool DownReleased(); bool DownReleased();
bool LeftReleased(); bool LeftReleased();
bool RightReleased(); bool RightReleased();
bool BackReleased(); bool BackReleased();
bool PlayerCanMove(); bool PlayerCanMove();
bool NPCCanMove(); bool NPCCanMove();
void UpdatePlayerTrail(vd2d newMovement,Direction newFacingDir); void UpdatePlayerTrail(vd2d newMovement,Direction newFacingDir);
@ -145,10 +145,11 @@ class SeasonI:public PixelGameEngine{
TILE GetSafeTileData(std::vector<std::vector<TILE*>>&data); TILE GetSafeTileData(std::vector<std::vector<TILE*>>&data);
char GetTileDegreeSafely(std::vector<std::vector<TILE*>>&data); char GetTileDegreeSafely(std::vector<std::vector<TILE*>>&data);
//When using for testing, make sure you RELEASE the key when you are done! //When using for testing, make sure you RELEASE the key when you are done!
void PressTestKey(Key k); void PressTestKey(Key k);
void ReleaseTestKey(Key k); void ReleaseTestKey(Key k);
void PressTestKeyAndRun(Key k); void PressTestKeyAndRun(Key k);
void ResetTestKeys(); void ResetTestKeys();
void SetupGameDrawing();
}; };
extern SeasonI*GAME; extern SeasonI*GAME;
#endif #endif

@ -1236,29 +1236,12 @@ void SeasonI::LoadEncounter(Map*map,vd2d pos,int chance,int id,bool successful)
bool SeasonI::OnUserUpdate(float fElapsedTime) bool SeasonI::OnUserUpdate(float fElapsedTime)
{ {
elapsedTime+=fElapsedTime; elapsedTime+=fElapsedTime;
while (elapsedTime>TARGET_RATE) { while (elapsedTime>=TARGET_RATE) {
elapsedTime-=TARGET_RATE; elapsedTime-=TARGET_RATE;
updateGame(); updateGame();
} }
keyUpdates(); keyUpdates();
SetDrawTarget(nullptr); SetupGameDrawing();
Clear(BLANK);
SetDrawTarget(layer::COLLISION);
if (EDITING_LAYER!=layer::COLLISION) {
Clear(MAGENTA);
} else {
Clear(BLANK);
}
SetDrawTarget(layer::HIGH);
Clear(BLANK);
SetDrawTarget(layer::DYNAMIC);
Clear(BLANK);
SetDrawTarget(layer::GROUND);
Clear(BLANK);
SetDrawTarget(layer::SUPPORT_GROUND);
Clear(BLANK);
SetDrawTarget(layer::BACKGROUND);
Clear(BLANK);
drawGame(); drawGame();
return true; return true;
} }
@ -5628,7 +5611,28 @@ void SeasonI::ResetTestKeys() {
void SeasonI::PressTestKeyAndRun(Key k) { void SeasonI::PressTestKeyAndRun(Key k) {
PressTestKey(k); PressTestKey(k);
updateGame(); OnUserUpdate(1/60.f);
}
void SeasonI::SetupGameDrawing(){
SetDrawTarget(nullptr);
Clear(BLANK);
SetDrawTarget(layer::COLLISION);
if (EDITING_LAYER!=layer::COLLISION) {
Clear(MAGENTA);
} else {
Clear(BLANK);
}
SetDrawTarget(layer::HIGH);
Clear(BLANK);
SetDrawTarget(layer::DYNAMIC);
Clear(BLANK);
SetDrawTarget(layer::GROUND);
Clear(BLANK);
SetDrawTarget(layer::SUPPORT_GROUND);
Clear(BLANK);
SetDrawTarget(layer::BACKGROUND);
Clear(BLANK);
} }
#ifndef TEST_SUITE #ifndef TEST_SUITE

@ -49,7 +49,7 @@ int testCount=0;
int MAX_ITERATIONS=1000; int MAX_ITERATIONS=1000;
int iterations=0; int iterations=0;
enum KeyIdentifier{ enum class KeyIdentifier{
UP, UP,
RIGHT, RIGHT,
DOWN, DOWN,
@ -195,6 +195,13 @@ void TestSpriteInitialized(std::vector<std::string> sprList) {
} }
bool SeasonI::OnUserCreate(){ bool SeasonI::OnUserCreate(){
srand(time(NULL));
GAME=this;
for (int i=1;i<7;i++) {
CreateLayer();
EnableLayer(i,true);
}
SetPixelMode(Pixel::ALPHA);
GAME_STATE=GameState::TEST_GAME; GAME_STATE=GameState::TEST_GAME;
Test("We start in the TEST_GAME state", Test("We start in the TEST_GAME state",
GAME_STATE==GameState::TEST_GAME); GAME_STATE==GameState::TEST_GAME);
@ -361,12 +368,12 @@ bool SeasonI::OnUserCreate(){
CurrentCutscene!=nullptr); CurrentCutscene!=nullptr);
Test("Current Action should not be updated yet", Test("Current Action should not be updated yet",
CurrentAction==ActionType::NONE); CurrentAction==ActionType::NONE);
updateGame(); OnUserUpdate(1/60.f);
Test("HandleCutscenes should get called in updateGame(), updating the current action", Test("HandleCutscenes should get called in updateGame(), updating the current action",
CurrentAction!=ActionType::NONE); CurrentAction!=ActionType::NONE);
int startFrame=frameCount; int startFrame=frameCount;
TestWhile("Cutscene should complete entirely",CurrentAction!=ActionType::NONE) { TestWhile("Cutscene should complete entirely",CurrentAction!=ActionType::NONE) {
updateGame(); OnUserUpdate(1/60.f);
} }
std::cout<<"Frame Count: "<<(frameCount-startFrame)<<std::endl; std::cout<<"Frame Count: "<<(frameCount-startFrame)<<std::endl;
Test("Cutscene is now finished", Test("Cutscene is now finished",
@ -417,17 +424,19 @@ bool SeasonI::OnUserCreate(){
Test("No cutscene is playing", Test("No cutscene is playing",
CurrentCutscene==nullptr); CurrentCutscene==nullptr);
StartCutscene(FeatureTestCutscene); StartCutscene(FeatureTestCutscene);
updateGame(); OnUserUpdate(1/60.f);
Test("Current action should be fading", Test("Current action should be fading",
CurrentAction==ActionType::FADE); CurrentAction==ActionType::FADE);
double previous_fade_value=CUTSCENE_FADE_VALUE; double previous_fade_value=CUTSCENE_FADE_VALUE;
updateGame(); OnUserUpdate(1/60.f);
Test("Fading causes CUTSCENE_FADE_VALUE to increase", Test("Fading causes CUTSCENE_FADE_VALUE to increase",
CUTSCENE_FADE_VALUE>previous_fade_value); CUTSCENE_FADE_VALUE>previous_fade_value);
Test("There should be no objects in the game", Test("There should be no objects in the game",
OBJECTS.size()==0); OBJECTS.size()==0);
Test("Player should not be able to move during a cutscene",
!PlayerCanMove());
TestWhile("Fade out should finish",CurrentAction==ActionType::FADE) { TestWhile("Fade out should finish",CurrentAction==ActionType::FADE) {
updateGame(); OnUserUpdate(1/60.f);
} }
Test("When faded out, CUTSCENE_FADE_VALUE should be 255", Test("When faded out, CUTSCENE_FADE_VALUE should be 255",
CUTSCENE_FADE_VALUE==255); CUTSCENE_FADE_VALUE==255);
@ -437,21 +446,21 @@ bool SeasonI::OnUserCreate(){
OBJECTS.size()==3); OBJECTS.size()==3);
Test("Cutscene objects should have the temp flag set", Test("Cutscene objects should have the temp flag set",
OBJECTS[0]->temp&&OBJECTS[1]->temp&&OBJECTS[2]->temp); OBJECTS[0]->temp&&OBJECTS[1]->temp&&OBJECTS[2]->temp);
updateGame(); OnUserUpdate(1/60.f);
Test("Next cutscene action should be Fade back in", Test("Next cutscene action should be Fade back in",
CurrentAction==ActionType::FADE); CurrentAction==ActionType::FADE);
previous_fade_value=CUTSCENE_FADE_VALUE; previous_fade_value=CUTSCENE_FADE_VALUE;
updateGame(); OnUserUpdate(1/60.f);
Test("Fading in causes CUTSCENE_FADE_VALUE to decrease", Test("Fading in causes CUTSCENE_FADE_VALUE to decrease",
CUTSCENE_FADE_VALUE<previous_fade_value); CUTSCENE_FADE_VALUE<previous_fade_value);
TestWhile("Fade in should finish",CurrentAction==ActionType::FADE) { TestWhile("Fade in should finish",CurrentAction==ActionType::FADE) {
updateGame(); OnUserUpdate(1/60.f);
} }
Test("Next cutscene action should be setting a flag when the cutscene ends", Test("Next cutscene action should be setting a flag when the cutscene ends",
CurrentAction==ActionType::SET_FLAG_WHEN_CUTSCENE_ENDS); CurrentAction==ActionType::SET_FLAG_WHEN_CUTSCENE_ENDS);
Test("Ending cutscene flag is stored properly with proper flag and value", Test("Ending cutscene flag is stored properly with proper flag and value",
CurrentCutscene->GetEndingCutsceneFlag()==Flag::TEST_FLAG3&&CurrentCutscene->GetEndingCutsceneVal()); CurrentCutscene->GetEndingCutsceneFlag()==Flag::TEST_FLAG3&&CurrentCutscene->GetEndingCutsceneVal());
updateGame(); OnUserUpdate(1/60.f);
Test("Next cutscene action should be setting a flag on the spot", Test("Next cutscene action should be setting a flag on the spot",
CurrentAction==ActionType::SET_FLAG); CurrentAction==ActionType::SET_FLAG);
Test("Test Flag 2 should now be set", Test("Test Flag 2 should now be set",
@ -461,7 +470,7 @@ bool SeasonI::OnUserCreate(){
cameraPos={0,0}; cameraPos={0,0};
Test("Camera position should be {0,0}", Test("Camera position should be {0,0}",
cameraPos.x==0&&cameraPos.y==0); cameraPos.x==0&&cameraPos.y==0);
updateGame(); OnUserUpdate(1/60.f);
Test("Next cutscene action should be panning the camera", Test("Next cutscene action should be panning the camera",
CurrentAction==ActionType::PAN_CAMERA); CurrentAction==ActionType::PAN_CAMERA);
Test("Camera position should be moving towards {128,128}", Test("Camera position should be moving towards {128,128}",
@ -469,20 +478,20 @@ bool SeasonI::OnUserCreate(){
Test("Temporary cutscene object 1 is at position {136,136}", Test("Temporary cutscene object 1 is at position {136,136}",
CurrentCutscene->GetCutsceneObjects()[1]->GetPos().x==136&&CurrentCutscene->GetCutsceneObjects()[1]->GetPos().y==136); CurrentCutscene->GetCutsceneObjects()[1]->GetPos().x==136&&CurrentCutscene->GetCutsceneObjects()[1]->GetPos().y==136);
TestWhile("Panning Camera should finish",CurrentAction==ActionType::PAN_CAMERA) { TestWhile("Panning Camera should finish",CurrentAction==ActionType::PAN_CAMERA) {
updateGame(); OnUserUpdate(1/60.f);
} }
Test("Camera position should be {128,128}", Test("Camera position should be {128,128}",
cameraPos.x==128&&cameraPos.y==128); cameraPos.x==128&&cameraPos.y==128);
Test("Next cutscene action is the async cutscene object movement", Test("Next cutscene action is the async cutscene object movement",
CurrentAction==ActionType::MOVE_CUTSCENE_OBJ_ASYNC); CurrentAction==ActionType::MOVE_CUTSCENE_OBJ_ASYNC);
vd2d prevCutsceneObjPosition=CurrentCutscene->GetCutsceneObjects()[1]->GetPos(); vd2d prevCutsceneObjPosition=CurrentCutscene->GetCutsceneObjects()[1]->GetPos();
updateGame(); OnUserUpdate(1/60.f);
Test("Cutscene object is moving towards {80,64}", Test("Cutscene object is moving towards {80,64}",
CurrentCutscene->GetCutsceneObjects()[1]->GetPos().x<prevCutsceneObjPosition.x&&CurrentCutscene->GetCutsceneObjects()[1]->GetPos().y<prevCutsceneObjPosition.y); CurrentCutscene->GetCutsceneObjects()[1]->GetPos().x<prevCutsceneObjPosition.x&&CurrentCutscene->GetCutsceneObjects()[1]->GetPos().y<prevCutsceneObjPosition.y);
vd2d prevCameraPos=cameraPos; vd2d prevCameraPos=cameraPos;
Test("Due to async actions, next cutscene action should be Pan Camera Async", Test("Due to async actions, next cutscene action should be Pan Camera Async",
CurrentAction==ActionType::PAN_CAMERA_ASYNC); CurrentAction==ActionType::PAN_CAMERA_ASYNC);
updateGame(); OnUserUpdate(1/60.f);
Test("Camera is moving towards {64,0}", Test("Camera is moving towards {64,0}",
prevCameraPos.x>cameraPos.x&&prevCameraPos.y>cameraPos.y); prevCameraPos.x>cameraPos.x&&prevCameraPos.y>cameraPos.y);
Test("Due to async actions, next cutscene action should be Dialog Box Async", Test("Due to async actions, next cutscene action should be Dialog Box Async",
@ -493,20 +502,20 @@ bool SeasonI::OnUserCreate(){
GetAnyKeyPress(H); GetAnyKeyPress(H);
Test("Pressing any key should close the message box", Test("Pressing any key should close the message box",
!messageBoxVisible); !messageBoxVisible);
updateGame(); OnUserUpdate(1/60.f);
Test("Next cutscene action should be Modify Object 0", Test("Next cutscene action should be Modify Object 0",
CurrentAction==ActionType::MODIFY_OBJECT); CurrentAction==ActionType::MODIFY_OBJECT);
Test("Cutscene Object 0 is now size {5,5}", Test("Cutscene Object 0 is now size {5,5}",
CurrentCutscene->GetCutsceneObjects()[0]->GetScale().x==5&&CurrentCutscene->GetCutsceneObjects()[0]->GetScale().y==5); CurrentCutscene->GetCutsceneObjects()[0]->GetScale().x==5&&CurrentCutscene->GetCutsceneObjects()[0]->GetScale().y==5);
updateGame(); OnUserUpdate(1/60.f);
Test("Next cutscene action should be Move Cutscene Object 1", Test("Next cutscene action should be Move Cutscene Object 1",
CurrentAction==ActionType::MOVE_CUTSCENE_OBJ); CurrentAction==ActionType::MOVE_CUTSCENE_OBJ);
prevCutsceneObjPosition=CurrentCutscene->GetCutsceneObjects()[1]->GetPos(); prevCutsceneObjPosition=CurrentCutscene->GetCutsceneObjects()[1]->GetPos();
updateGame(); OnUserUpdate(1/60.f);
Test("Cutscene Object 1 is moving towards position {320,64}", Test("Cutscene Object 1 is moving towards position {320,64}",
CurrentCutscene->GetCutsceneObjects()[1]->GetPos().x>prevCutsceneObjPosition.x&&CurrentCutscene->GetCutsceneObjects()[1]->GetPos().y==prevCutsceneObjPosition.y); CurrentCutscene->GetCutsceneObjects()[1]->GetPos().x>prevCutsceneObjPosition.x&&CurrentCutscene->GetCutsceneObjects()[1]->GetPos().y==prevCutsceneObjPosition.y);
TestWhile("Move Cutscene Object should finish",CurrentAction==ActionType::MOVE_CUTSCENE_OBJ) { TestWhile("Move Cutscene Object should finish",CurrentAction==ActionType::MOVE_CUTSCENE_OBJ) {
updateGame(); OnUserUpdate(1/60.f);
} }
Test("Cutscene Object 1 should be at position {320,64}", Test("Cutscene Object 1 should be at position {320,64}",
CurrentCutscene->GetCutsceneObjects()[1]->GetPos().x==320&&CurrentCutscene->GetCutsceneObjects()[1]->GetPos().y==64); CurrentCutscene->GetCutsceneObjects()[1]->GetPos().x==320&&CurrentCutscene->GetCutsceneObjects()[1]->GetPos().y==64);
@ -521,21 +530,21 @@ bool SeasonI::OnUserCreate(){
Test("Pressing a key should close the message box", Test("Pressing a key should close the message box",
!messageBoxVisible); !messageBoxVisible);
int prevDestructionCount=OBJECT_DESTRUCTION_COUNT; int prevDestructionCount=OBJECT_DESTRUCTION_COUNT;
updateGame(); OnUserUpdate(1/60.f);
Test("Next cutscene action should be loading a map", Test("Next cutscene action should be loading a map",
CurrentAction==ActionType::LOAD_MAP); CurrentAction==ActionType::LOAD_MAP);
Test("Current Map should now be TWOSON", Test("Current Map should now be TWOSON",
CURRENT_MAP==MAPS[MapName::TWOSON]); CURRENT_MAP==MAPS[MapName::TWOSON]);
Test("All temporary objects should now be destroyed", Test("All temporary objects should now be destroyed",
OBJECT_DESTRUCTION_COUNT-3==prevDestructionCount); OBJECT_DESTRUCTION_COUNT-3==prevDestructionCount);
updateGame(); OnUserUpdate(1/60.f);
Test("Next action should be moving player objects", Test("Next action should be moving player objects",
CurrentAction==ActionType::MOVE_PLAYER_OBJS); CurrentAction==ActionType::MOVE_PLAYER_OBJS);
Test("All player objects should now be at position {16,16}", Test("All player objects should now be at position {16,16}",
PARTY_MEMBER_OBJ[0]->GetPos().x==16&&PARTY_MEMBER_OBJ[0]->GetPos().y==16); PARTY_MEMBER_OBJ[0]->GetPos().x==16&&PARTY_MEMBER_OBJ[0]->GetPos().y==16);
Test("Next cutscene action should be cleanup", Test("Next cutscene action should be cleanup",
CurrentCutscene->CurrentAction()==ActionType::CLEANUP); CurrentCutscene->CurrentAction()==ActionType::CLEANUP);
updateGame(); OnUserUpdate(1/60.f);
Test("All cutscene and action variables should be cleaned up", Test("All cutscene and action variables should be cleaned up",
CurrentCutscene==nullptr&& CurrentCutscene==nullptr&&
CurrentAction==ActionType::NONE); CurrentAction==ActionType::NONE);
@ -544,16 +553,16 @@ bool SeasonI::OnUserCreate(){
PressTestKey(k.k); PressTestKey(k.k);
Test(k.keyName+" key is pressed", Test(k.keyName+" key is pressed",
GetKeyPressed(*this,k)); GetKeyPressed(*this,k));
updateGame(); OnUserUpdate(1/60.f);
Test(k.keyName+" key is no longer pressed", Test(k.keyName+" key is no longer pressed",
!GetKeyPressed(*this,k)); !GetKeyPressed(*this,k));
Test(k.keyName+" key is held down", Test(k.keyName+" key is held down",
GetKeyHeld(*this,k)); GetKeyHeld(*this,k));
updateGame(); OnUserUpdate(1/60.f);
Test(k.keyName+" key is still held down", Test(k.keyName+" key is still held down",
GetKeyHeld(*this,k)); GetKeyHeld(*this,k));
for (int i=0;i<50;i++) { for (int i=0;i<50;i++) {
updateGame(); OnUserUpdate(1/60.f);
} }
Test(k.keyName+" key is still held down after multiple updates", Test(k.keyName+" key is still held down after multiple updates",
GetKeyHeld(*this,k)); GetKeyHeld(*this,k));
@ -562,7 +571,7 @@ bool SeasonI::OnUserCreate(){
!GetKeyHeld(*this,k)); !GetKeyHeld(*this,k));
Test(k.keyName+" key is released", Test(k.keyName+" key is released",
GetKeyReleased(*this,k)); GetKeyReleased(*this,k));
updateGame(); OnUserUpdate(1/60.f);
Test(k.keyName+" key is no longer released", Test(k.keyName+" key is no longer released",
!GetKeyReleased(*this,k)); !GetKeyReleased(*this,k));
} }
@ -596,12 +605,31 @@ bool SeasonI::OnUserCreate(){
keyUpdates(); keyUpdates();
} }
ResetTestKeys(); ResetTestKeys();
SetDrawTarget(nullptr);
GetDrawTarget()->GetData()[0].a=4;
} }
GAME_STATE=GameState::GAME_WORLD;
Test("Player can move when there is no cutscene and the game is in a normal state",
PlayerCanMove());
GAME_STATE=GameState::TEST_GAME;
Test("Player cannot move during testing",
!PlayerCanMove());
SetGameFlag(Flag::INTRO_COMPLETED,true);
GAME_STATE=GameState::GAME_WORLD;
vd2d prevPlayerPos = PARTY_MEMBER_OBJ[0]->GetPos();
CenterCameraOnPlayer();
PressTestKeyAndRun(RIGHT);
Test("Player has moved to the right",
PARTY_MEMBER_OBJ[0]->GetPos().x>prevPlayerPos.x&&PARTY_MEMBER_OBJ[0]->GetPos().y==prevPlayerPos.y);
return true; return true;
} }
bool SeasonI::OnUserUpdate(float fElapsedTime) bool SeasonI::OnUserUpdate(float fElapsedTime)
{ {
updateGame();
keyUpdates();
SetupGameDrawing();
drawGame();
return true; return true;
} }

Loading…
Cancel
Save