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 HandleBattle();
void HandleCutscenes();
bool TabHeld();
bool UpPressed();
bool DownPressed();
bool LeftPressed();
bool RightPressed();
bool BackPressed();
bool UpHeld();
bool DownHeld();
bool LeftHeld();
bool RightHeld();
bool BackHeld();
bool UpReleased();
bool DownReleased();
bool LeftReleased();
bool RightReleased();
bool BackReleased();
bool TabHeld();
bool UpPressed();
bool DownPressed();
bool LeftPressed();
bool RightPressed();
bool BackPressed();
bool UpHeld();
bool DownHeld();
bool LeftHeld();
bool RightHeld();
bool BackHeld();
bool UpReleased();
bool DownReleased();
bool LeftReleased();
bool RightReleased();
bool BackReleased();
bool PlayerCanMove();
bool NPCCanMove();
void UpdatePlayerTrail(vd2d newMovement,Direction newFacingDir);
@ -145,10 +145,11 @@ class SeasonI:public PixelGameEngine{
TILE GetSafeTileData(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!
void PressTestKey(Key k);
void ReleaseTestKey(Key k);
void PressTestKeyAndRun(Key k);
void ResetTestKeys();
void PressTestKey(Key k);
void ReleaseTestKey(Key k);
void PressTestKeyAndRun(Key k);
void ResetTestKeys();
void SetupGameDrawing();
};
extern SeasonI*GAME;
#endif

@ -1236,29 +1236,12 @@ void SeasonI::LoadEncounter(Map*map,vd2d pos,int chance,int id,bool successful)
bool SeasonI::OnUserUpdate(float fElapsedTime)
{
elapsedTime+=fElapsedTime;
while (elapsedTime>TARGET_RATE) {
while (elapsedTime>=TARGET_RATE) {
elapsedTime-=TARGET_RATE;
updateGame();
}
keyUpdates();
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);
SetupGameDrawing();
drawGame();
return true;
}
@ -5628,7 +5611,28 @@ void SeasonI::ResetTestKeys() {
void SeasonI::PressTestKeyAndRun(Key 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

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

Loading…
Cancel
Save