func Initialize() { AddEffect("DefMana", nil, 1, 4, nil); InitTeamExclusiveChamps(2); InitScoreboard(); team_score = CreateArray(2); var fx = AddEffect("CheckWipf", this, 1, 5, this); fx.counter = resetTime; var pos = GameCall("LeftGoalPos"); leftgoal = CreateObject(Dummy, pos[0], pos[1], -1); leftgoal.Visibility = VIS_All; var fxl = AddEffect("GoalCheck", leftgoal, 1, 1, this, nil, 1, 2); fxl.teamid = 1; fxl.enemy = 2; leftshield_params = GameCall("LeftShieldParams"); leftshield = CreateObject(PortalWall,leftshield_params[0], leftshield_params[1],-1); pos = GameCall("RightGoalPos"); rightgoal = CreateObject(Dummy, pos[0], pos[1], -1); rightgoal.Visibility = VIS_All; var fxr = AddEffect("GoalCheck", rightgoal, 1, 1, this, nil, 2, 1); fxr.teamid = 2; fxr.enemy = 1; rightshield_params = GameCall("RightShieldParams"); rightshield = CreateObject(PortalWall,rightshield_params[0],rightshield_params[1],-1); SpawnBall(); ScheduleCall(this, "Set", 80); }
void Board::Restart() { needCheckLines_ = false; needSpawnBalls_ = false; gameOver_ = false; for (int i = 0; i < height_; i++) { for (int j = 0; j < width_; j++) { if (board_[i][j]) { board_[i][j]->GetNode()->Remove(); board_[i][j] = nullptr; } } } selectedBall_ = nullptr; LoadRecord(); for (int i = 0; i < numAddBalls_; i++) SpawnBall(); if (difficulty_ <= D_NORMAL) { for (int i = 0; i < numAddBalls_; i++) CreateBall(true); } score_ = 0; }
void GameManager::Start() { mBallVelocity = new mw2_Vector2(); mPaddleSpeed = 600; mBallSpeed = 400; mIsBallLost = false; mBallSpawnDirection = -1; mWinCondition = 0; mScore1 = 0; mScore2 = 0; mBallSpawnAngles[0] = 15; mBallSpawnAngles[1] = 30; mBallSpawnAngles[2] = -15; mBallSpawnAngles[3] = -30; mBallSpawnAngles[4] = -45; mBallSpawnAngles[5] = 45; mw2_Scene* scene = mw2_Application::GetScene(); mPaddle1 = scene->FindObject("paddle1"); mPaddle2 = scene->FindObject("paddle2"); mBall = scene->FindObject("ball"); mBall_line = (mw2_Circle*) scene->FindObject("ball_line"); mBall_fill = (mw2_Circle*) scene->FindObject("ball_fill"); mScoreText1 = (mw2_Text*) scene->FindObject("scoreText1"); mScoreText2 = (mw2_Text*) scene->FindObject("scoreText2"); mPaddleSize = ((mw2_Rect*) scene->FindObject("p1_fill"))->mSize; mTopDownMargin = ((mw2_Image*) scene->FindObject("bg_back"))->mSize->y /2; mLeftRightMargin = ((mw2_Image*) scene->FindObject("bg_back"))->mSize->x /2; mBallRadius = ((mw2_Circle*) scene->FindObject("ball_fill"))->mRadius; mFillColor1 = ((mw2_Rect*) scene->FindObject("p1_fill"))->mColor; mFillColor2 = ((mw2_Rect*) scene->FindObject("p2_fill"))->mColor; mLineColor1 = ((mw2_Rect*) scene->FindObject("p1_line"))->mColor; mLineColor2 = ((mw2_Rect*) scene->FindObject("p2_line"))->mColor; mPaddleSound = new mw2_Audio( mw2_Resources::GetSound("sound_paddle") ); mBoundarySound = new mw2_Audio( mw2_Resources::GetSound("sound_boundary") ); mLostSound = new mw2_Audio( mw2_Resources::GetSound("sound_lost") ); mMusicSound = new mw2_Audio( mw2_Resources::GetSound("sound_music") ); mMusicSound->PlayLoop(); mWinCondition = mw2_Globals::GetInt("WinCondition"); SpawnBall(); }
void Board::Init(Difficulty difficulty) { SetDifficulty(difficulty); node_->SetPosition(Vector3(0.0f, 0.0f, Max(width_, height_) * 2.8f)); needCheckLines_ = false; needSpawnBalls_ = false; gameOver_ = false; score_ = 0; record_ = 0; board_.Resize(height_); cells_.Resize(height_); for (int i = 0; i < height_; i++) { board_[i].Resize(width_); cells_[i].Resize(width_); for (int j = 0; j < width_; j++) { Node* cellNode = node_->CreateChild(); Cell* cell = cellNode->CreateComponent<Cell>(); Vector3 targetPos = IV2ToV3(IntVector2(j, i)); Vector3 startPos = Vector3(Random(-50.0f, 50.0f), Random(-50.0f, 50.0f), Random(-50.0f, 50.0f)); cell->Init(startPos, targetPos, IntVector2(j, i)); cells_[i][j] = cell; } } for (int i = 0; i < numAddBalls_; i++) SpawnBall(); if (difficulty_ <= D_NORMAL) { for (int i = 0; i < numAddBalls_; i++) CreateBall(true); } InitSelection(); LoadRecord(); }
void Board::Update(float timeStep) { if (gameOver_) { if (score_ > record_) { record_ = score_; SaveRecord(); } Restart(); return; } selectionNode_->Rotate(Quaternion(0.0f, timeStep * 50, 0.0f)); if (Path::GetTotalCount() > 0) return; if (needCheckLines_) { if (CheckLines()) { needSpawnBalls_ = false; } needCheckLines_ = false; // может быть что поле полностью занято, новых шаров спанить не надо и ходить некуда // не работает чот gameOver_ = true; for (int i = 0; i < height_; i++) { for (int j = 0; j < width_; j++) { if (!board_[i][j] || board_[i][j]->GetBallState() == BS_GHOST) { gameOver_ = false; break; } } } if (gameOver_) return; } if (needSpawnBalls_) { for (int i = 0; i < numAddBalls_; i++) { if (!SpawnBall()) { gameOver_ = true; return; } } if (difficulty_ <= D_NORMAL) { for (int i = 0; i < numAddBalls_; i++) CreateBall(true); } needSpawnBalls_ = false; } UIElement* uiRoot = GetSubsystem<UI>()->GetRoot(); Text* t = static_cast<Text*>(uiRoot->GetChild("Score", true)); t->SetText("Score: " + String(score_)); t = static_cast<Text*>(uiRoot->GetChild("Colors", true)); t->SetText("Colors: " + String(numColors_)); t = static_cast<Text*>(uiRoot->GetChild("LineLength", true)); t->SetText("Line length: " + String(lineLength_)); t = static_cast<Text*>(uiRoot->GetChild("Record", true)); t->SetText("Record: " + String(record_)); // нужно выбрасывать шары если после уделаения линий поле пустое }
void GameManager::Update(float deltaTime) { // player control if (mw2_Input::GetKey(mw2_Input::Key::W)) { mPaddle1->TranslateWorld( new mw2_Vector2(0, - mPaddleSpeed * deltaTime) ); } if (mw2_Input::GetKey(mw2_Input::Key::S)) { mPaddle1->TranslateWorld( new mw2_Vector2(0, mPaddleSpeed * deltaTime) ); } if (mw2_Input::GetKey(mw2_Input::Key::ARROW_UP)) { mPaddle2->TranslateWorld( new mw2_Vector2(0, - mPaddleSpeed * deltaTime) ); } if (mw2_Input::GetKey(mw2_Input::Key::ARROW_DOWN)) { mPaddle2->TranslateWorld( new mw2_Vector2(0, mPaddleSpeed * deltaTime) ); } // clamp paddle position mw2_Vector2* p1 = mPaddle1->WorldPosition(); p1->y = Clamp(p1->y, - mTopDownMargin + mPaddleSize->y /2, mTopDownMargin - mPaddleSize->y /2); mPaddle1->WorldPosition(p1); mw2_Vector2* p2 = mPaddle2->WorldPosition(); p2->y = Clamp(p2->y, - mTopDownMargin + mPaddleSize->y /2, mTopDownMargin - mPaddleSize->y /2); mPaddle2->WorldPosition(p2); // ball position update mBall->TranslateWorld( *mBallVelocity * (deltaTime * mBallSpeed) ); // check top-bottom margins if (mBall->WorldPosition()->y + mBallRadius >= mTopDownMargin) { mBallVelocity->y = - abs(mBallVelocity->y); mBoundarySound->PlayOnce(); } if (mBall->WorldPosition()->y - mBallRadius <= - mTopDownMargin) { mBallVelocity->y = abs(mBallVelocity->y); mBoundarySound->PlayOnce(); } // check paddle collision if (!mIsBallLost && mBall->WorldPosition()->x - mBallRadius <= mPaddle1->WorldPosition()->x + mPaddleSize->x /2) { if (mPaddle1->WorldPosition()->y + mPaddleSize->y / 2 >= mBall->WorldPosition()->y && mBall->WorldPosition()->y >= mPaddle1->WorldPosition()->y - mPaddleSize->y / 2) { // ball hits paddle 1 mBallVelocity->x = abs(mBallVelocity->x); mPaddleSound->PlayOnce(); mBall_fill->mColor = mFillColor1; mBall_line->mColor = mLineColor1; } else if (mBall->WorldPosition()->x < mPaddle1->WorldPosition()->x + mPaddleSize->x / 2) { mIsBallLost = true; mLostSound->PlayOnce(); } } if (!mIsBallLost && mBall->WorldPosition()->x + mBallRadius >= mPaddle2->WorldPosition()->x - mPaddleSize->x /2) { if (mPaddle2->WorldPosition()->y + mPaddleSize->y / 2 >= mBall->WorldPosition()->y && mBall->WorldPosition()->y >= mPaddle2->WorldPosition()->y - mPaddleSize->y / 2) { // ball hits paddle 2 mBallVelocity->x = - abs(mBallVelocity->x); mPaddleSound->PlayOnce(); mBall_fill->mColor = mFillColor2; mBall_line->mColor = mLineColor2; } else if (mBall->WorldPosition()->x > mPaddle2->WorldPosition()->x - mPaddleSize->x / 2) { mIsBallLost = true; mLostSound->PlayOnce(); } } // check left-right boundaries if (mBall->WorldPosition()->x + mBallRadius >= mLeftRightMargin) { mBallSpawnDirection = -1; mScore1 += 1; SpawnBall(); } if (mBall->WorldPosition()->x - mBallRadius <= - mLeftRightMargin) { mBallSpawnDirection = 1; mScore2 += 1; SpawnBall(); } // update scores mScoreText1->mText = PrettyScore(mScore1); mScoreText2->mText = PrettyScore(mScore2); // check game over if (mScore1 == mWinCondition) { mw2_Globals::SetString("winner", "1"); mw2_Application::LoadScene( new EndScene(), new EndManager() ); } if (mScore2 == mWinCondition) { mw2_Globals::SetString("winner", "2"); mw2_Application::LoadScene( new EndScene(), new EndManager() ); } // check for R-restart or ESC-exit if (mw2_Input::GetKeyOnce(mw2_Input::Key::R)) { mw2_Application::LoadScene( new StartScene(), new StartManager() ); } if (mw2_Input::GetKeyOnce(mw2_Input::Key::ESC)) { mw2_Application::Exit(); } }