Untitled
unknown
plain_text
2 months ago
6.5 kB
5
Indexable
class Level2CatSceneController : public SceneController { public: Transition backgroundNoText; Transition backgroundTextInstruction; Transition backgroundChoice; Transition backgroundMiddle; Character aralyn; Character cat; Scene level2CatScene; bool hasArrivedInMiddle = false; bool hasAccepted = false; bool hasRejected = false; bool isInCat = true; bool shouldContinueFromMiddle = false; bool showChoice = false; int rendersUntilProceed = 0; Level2CatSceneController() {} Level2CatSceneController(Scene* scene) : SceneController(scene) {} void setup() override { if (this->status != SceneController::Status::NOT_STARTED) return; std::string str; string standAnimationFilePaths[6] = { "Images\\mainCharacter\\stand\\Sprite-0001.png", "Images\\mainCharacter\\stand\\Sprite-0002.png", "Images\\mainCharacter\\stand\\Sprite-0003.png", "Images\\mainCharacter\\stand\\Sprite-0004.png", "Images\\mainCharacter\\stand\\Sprite-0005.png", "Images\\mainCharacter\\stand\\Sprite-0006.png", }; Animation aralynStandAnimation(standAnimationFilePaths, 6, 50, true); aralynStandAnimation.id = "stand"; string mainCharacterRunRightFilenames[12] = { "Images\\mainCharacter\\runright1.png", "Images\\mainCharacter\\runright2.png", "Images\\mainCharacter\\runright3.png", "Images\\mainCharacter\\runright4.png", "Images\\mainCharacter\\runright5.png", "Images\\mainCharacter\\runright6.png", "Images\\mainCharacter\\runright7.png", "Images\\mainCharacter\\runright8.png", "Images\\mainCharacter\\runright9.png", "Images\\mainCharacter\\runright10.png", "Images\\mainCharacter\\runright11.png", "Images\\mainCharacter\\runright12.png" }; Animation aralynRunRightAnimation(mainCharacterRunRightFilenames, 12, 50, true); // aralyn er running animation - se animatin header file aralynRunRightAnimation.id = "run"; string mainCharacterAttackFilenames[6] = { "Images\\mainCharacter\\attack2\\1.png", "Images\\mainCharacter\\attack2\\2.png", "Images\\mainCharacter\\attack2\\3.png", "Images\\mainCharacter\\attack2\\4.png", "Images\\mainCharacter\\attack2\\5.png", "Images\\mainCharacter\\attack2\\6.png", }; Animation aralynAttackAnimation(mainCharacterAttackFilenames, 6, 50, true); // aralyn er attack animaton -- see animathin header file aralynAttackAnimation.id = "attack"; string mainCharacterDeathFilenames[1] = { "Images\\mainCharacter\\death\\death-01.png" }; Animation aralynDeathAnimation(mainCharacterDeathFilenames, 1, 50, false); // aralyn er daeth animaton -- see animathin header file aralyn = Character(Position(20, 30), Dimension(50, 100), "Aralyn Main", "Images\\mainCharacter\\runright1.png", aralynStandAnimation, aralynRunRightAnimation, aralynAttackAnimation, aralynDeathAnimation); string backgroundFrameFilePaths[1] = { "Images\\cat\\catSegment1.png", }; string catstandAnimationFilePaths[6] = { "Images\\cat\\idle0.png", "Images\\cat\\idle1.png", "Images\\cat\\idle2.png", "Images\\cat\\idle3.png", "Images\\cat\\idle4.png", "Images\\cat\\idle5.png", }; Animation catStandAnimation(catstandAnimationFilePaths, 6, 100, true); catStandAnimation.id = "stand"; string catRunRightAnimationFilePaths[6] = { "Images\\cat\\move0.png", "Images\\cat\\move1.png", "Images\\cat\\move2.png", "Images\\cat\\move3.png", "Images\\cat\\move4.png", "Images\\cat\\move5.png", }; Animation catRunRightAnimation(catRunRightAnimationFilePaths, 6, 300, true); // cat er run animaton -- see animathin header file catRunRightAnimation.id = "run"; cat = Character(Position(400, 30), Dimension(50, 100), "cat", "Images\\cat\\idle().png", catStandAnimation, catRunRightAnimation, catStandAnimation, catStandAnimation); Animation gameBackgroundAnimation(backgroundFrameFilePaths, 1, 500, false); backgroundMiddle = Transition(Position(0, 0), Dimension(800, 600), "Level 1: Fight Scene Background", gameBackgroundAnimation); cat.setTargetCharacter(&aralyn); cat.chase(); this->scene->addSceneObject(backgroundMiddle); this->scene->addSceneObject(aralyn); this->scene->addSceneObject(cat); setStatus(SceneController::Status::RUNNING); } void beforeRender() { if (!hasAccepted) { if (!hasArrivedInMiddle && cat.position.x <= 300) { hasArrivedInMiddle = true; cat.stand(); scene->clear(); scene->addSceneObject(backgroundTextInstruction); scene->addSceneObject(aralyn); scene->addSceneObject(cat); } else if (!shouldContinueFromMiddle && hasArrivedInMiddle && ++rendersUntilProceed == 500) { shouldContinueFromMiddle = true; scene->clear(); scene->addSceneObject(backgroundNoText); scene->addSceneObject(aralyn); scene->addSceneObject(cat); } else if (!showChoice && shouldContinueFromMiddle && cat.isTargetClose()) { showChoice = true; scene->clear(); scene->addSceneObject(backgroundChoice); scene->addSceneObject(aralyn); scene->addSceneObject(cat); } else if (hasRejected) { if (cat.position.x >= 700) { onSuccess(""); } else { cat.runRight(*scene); } } } } void afterRender() { // scene render er pore kono kichu korte hoile eta use } void onKeyDown(int key, boolean isSpecial) override { if (isSpecial) { if (key == GLUT_KEY_RIGHT) { } else if (key == GLUT_KEY_LEFT) { } else if (key == GLUT_KEY_UP) { } return; } if (key == 'a' || key == 'A') { } } void onKeyUp(int key, boolean isSpecial) override { if (isSpecial) { if (key == GLUT_KEY_RIGHT) { } else if (key == GLUT_KEY_LEFT) { } if (key == GLUT_KEY_PAGE_DOWN) { hasAccepted = true; } if (key == GLUT_KEY_PAGE_UP) { hasRejected = true; } return; } if (key == 'a' || key == 'A') aralyn.stand(); } void onMouseClick(int button, int state, int x, int y) override { if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { if (isInCat) { scene = &level2CatScene; isInCat = false; } else { setStatus(SceneController::Status::NOT_STARTED); onSuccess(""); } } } void onMouseMove(int x, int y) override {} };
Editor is loading...
Leave a Comment