void Level1::onHit(ofVec2f const & point) { (void)point; if (_lastBeatCheck) { newScore(lang("Doucement !", "Slow down!"), SCORE_MULTIPLE_HIT, _ribbon.getHead() + ofVec2f(130, -20), COLOR_YELLOW, _period); } else { const TimePoint now = ofGetElapsedTimeMillis(); long long int difference = (long long int)now - (long long int)_lastBeat; if (difference >= (long long int)_period / 2) difference -= (long long int)_period; int score = SCORE_FUNCTION((double)(difference) / (double)(_period * 0.5)); if (std::abs(difference) < _period*0.05) { score += SCORE_PERFECT_BONUS; newScore(lang("Super !", "Great!"), score, _ribbon.getHead() + ofVec2f(130, -20), COLOR_BLUE, _period); } else if (std::abs(difference) >= _period*0.05 && std::abs(difference) < _period*0.20) { newScore(lang("Bien !", "Good!"), score, _ribbon.getHead() + ofVec2f(130, -20), COLOR_GREEN, _period); } else if (std::abs(difference) >= _period*0.20) { newScore(lang("Pas mal !", "Not bad!"), score, _ribbon.getHead() + ofVec2f(130, -20), COLOR_ORANGE, _period); } _lastBeatCheck = true; } }
void UDKBlueprintFunctionLibrary::SaveNewScoreToLadder(const FString& PlayerName, int32 Score) { UDKSaveGame* saveGame = Cast<UDKSaveGame>(UGameplayStatics::LoadGameFromSlot(FSaveSlotNames::LadderBoardSlot.SlotName, FSaveSlotNames::LadderBoardSlot.UserIndex)); if (saveGame) { FDKScoreLadder newScore(PlayerName, Score); saveGame->LadderScore.Add(newScore); //sort so highest score will be on top. saveGame->LadderScore.Sort(); //save over existing save file. UGameplayStatics::SaveGameToSlot(saveGame, FSaveSlotNames::LadderBoardSlot.SlotName, FSaveSlotNames::LadderBoardSlot.UserIndex); //we can also implement some kind of limiter to prevent from having to many scores. //if (Num() > 10) //Sort() //RemoveLowest //add new //Sort(); } else { UDKSaveGame* newSaveGame = Cast<UDKSaveGame>(UGameplayStatics::CreateSaveGameObject(UDKSaveGame::StaticClass())); FDKScoreLadder newScore(PlayerName, Score); newSaveGame->LadderScore.Add(newScore); UGameplayStatics::SaveGameToSlot(newSaveGame, FSaveSlotNames::LadderBoardSlot.SlotName, FSaveSlotNames::LadderBoardSlot.UserIndex); } }
void Startcenter::updateRecentScores() { QFileInfoList fil = mscore->recentScores(); QFileInfo newScore(":/data/Create_New_Score.mscz"); fil.prepend(newScore); recentPage->setScores(fil); recentPage->selectFirst(); }
void Startcenter::loadScore(QString s) { if (s.endsWith("Create_New_Score.mscz")) { newScore(); } else { mscore->openScore(s); close(); } }
void Startcenter::updateRecentScores() { QFileInfoList fil = mscore->recentScores(); if (fil.size() == 0) { QFileInfo gettingStartedScore(":/data/Getting_Started.mscz"); fil.prepend(gettingStartedScore); } QFileInfo newScore(":/data/Create_New_Score.mscz"); fil.prepend(newScore); recentPage->setScores(fil); recentPage->selectFirst(); }
void GameWidget::checkGameOver() { for(int x = 0; x < grid_size; x++) { for(int y = 0; y < grid_size; y++) { QList<Box> connected; getConnectedBubbles(Box(x,y), connected); if(connected.size() > 1) return; //found cluster, continue game } } //assertion: no connected bubbles left in grid emit newScore(score); restart(); }
void Playground::startNewGame() { qsrand(QDateTime::currentDateTime().toTime_t()); score = 0; for(int i = 0; i < colors; i++) colorCounts[i] = 0; fillBubbles(); gameOver = false; lastMove.type = -1; while (!moves.empty()) { moves.pop(); } status = RUNNING; repaint(); emit newScore(score); }
void game_init() { disable_irq(MOUSE_IRQ); disable_irq(KBD_IRQ); // loading screen char **mapsBG[] = {LOADING_BOARD}; Sprite *loadingBG = newSprite(0, 0, mapsBG, sizeof(mapsBG)/sizeof(char*)); drawSpriteBG(loadingBG, base); srand(time(NULL)); mapsBG[0] = BG; spriteBG = newSprite(0, 0, mapsBG, sizeof(mapsBG)/sizeof(char*)); mapsBG[0] = HELP_BOARD; helpBoard = newSprite(0, 0, mapsBG, sizeof(mapsBG)/sizeof(char*)); mapsBG[0] = SCORE_BOARD; scoreBoard = newSprite(0, 0, mapsBG, sizeof(mapsBG)/sizeof(char*)); helpButton = newButton(0, 160, HELP_OVER); exitButton = newButton(196, 40, EXIT_OVER); hammer = newHammer(); numPCs = NUM_PCS; cscreens = malloc(NUM_PCS * sizeof(CScreen)); cscreens[0] = newCScreen(241, 367, 0); cscreens[1] = newCScreen(435, 363, 0); cscreens[2] = newCScreen(626, 363, 0); cscreens[3] = newCScreen(388, 224, 1); cscreens[4] = newCScreen(532, 216, 1); cscreens[5] = newCScreen(672, 209, 1); score = newScore(); highScores = readHighScores(); state = PLAYING; enable_irq(KBD_IRQ); enable_irq(MOUSE_IRQ); }
void Playground::refresh() { lastMove.prevPos.clear(); int emptyColumn = 0; for(int x = columns - 1; x >= 0; x--) { int emptyElement = 0; for(int y = rows - 1; y >= 0; y--) { if(bubbles[x][y] == -1) emptyElement++; else if(emptyElement > 0) { position oldPos; oldPos.x = x; oldPos.y = y; lastMove.prevPos[x][y + emptyElement] = oldPos; bubbles[x][y + emptyElement] = bubbles[x][y]; bubbles[x][y] = -1; } } if(bubbles[x][rows - 1] == -1) emptyColumn++; else if(emptyColumn > 0) { for(int y = rows - 1; y >= 0; y--) { position oldPos; try { oldPos = lastMove.prevPos.at(x).at(y); lastMove.prevPos.at(x).erase(y); } catch (const std::out_of_range& oor) { oldPos.x = x; oldPos.y = y; } lastMove.prevPos[x + emptyColumn][y] = oldPos; bubbles[x + emptyColumn][y] = bubbles[x][y]; bubbles[x][y] = -1; } } } for(int x = emptyColumn - 1; x > -1; x--) for(int y = 0; y < rows; y++) createBlock(x, y); moves.top().prevPos = lastMove.prevPos; repaint(); emit newScore(score); }
void Highscore::AddToHighscore(std::string name, int score) { HighscoreData newScore(name, score); bool isInserted = false; for(unsigned int i = 0; i < m_highscore.size(); i++) { if(newScore.Score > m_highscore[i].Score) { m_highscore.insert(m_highscore.begin() + i, newScore); isInserted = true; break; } } if(isInserted) { return; } if(m_highscore.size() < m_highscoreSize) { m_highscore.push_back(newScore); } }
void Playground::oneStepBack() { if(lastMove.type == -1) return; for(std::map<int, std::map<int, position> >::iterator iter1 = lastMove.prevPos.begin(); iter1 != lastMove.prevPos.end(); iter1++) { for(std::map<int, position>::iterator iter2 = iter1->second.begin(); iter2 != iter1->second.end(); iter2++) { //colorCounts[bubbles[iter2->second.x][iter2->second.y]]--; bubbles[iter2->second.x][iter2->second.y] = bubbles[iter1->first][iter2->first]; bubbles[iter1->first][iter2->first] = -1; } } for(int i = 0; i < lastMove.bubbles.size(); i++) { bubbles[lastMove.bubbles[i].x][lastMove.bubbles[i].y] = lastMove.type; } colorCounts[lastMove.type] += lastMove.bubbles.size(); score -= lastMove.points; moves.pop(); if(!moves.empty()) lastMove = moves.top(); else lastMove.type = -1; repaint(); emit newScore(score); }
//////////////////////////////////////////////////////////// /// Entry point of application /// /// \return Application exit code /// //////////////////////////////////////////////////////////// int main() { srand((unsigned)time(0)); bool spaceIsPressed = false; bool finishedEnteringName = false; bool savedToFile = false; sf::Clock clock; float currentTime, deathTime = 0.0f; sf::String whatever; whatever.SetPosition(300, 300); sf::String youMadeIt("You made it to the high score list! Enter your name:"); youMadeIt.SetPosition(300, 275); std::string inputString; initHighScores(highScoreList); sf::String highScoreString(convertScoresToString(highScoreList)); bool gameOver = false; sf::Music backgroundMusic; if ( !backgroundMusic.OpenFromFile("Music/02 - Salt In The Wounds.ogg")) return -9; backgroundMusic.Play(); // Create the main rendering window sf::RenderWindow App(sf::VideoMode(1280, 720, 32), "Space Invaders!"); App.UseVerticalSync(true); // Load the sprite image from a file sf::Image PlayerImage; if (!PlayerImage.LoadFromFile("Images/player.psd")) return EXIT_FAILURE; sf::Sprite Player(PlayerImage); Player.SetPosition(200.f, 100.f); Player.SetCenter(32.f, 32.f); sf::Image BackgroundImage; if ( !BackgroundImage.LoadFromFile("Images/space.psd")) return -1; sf::Sprite Background(BackgroundImage); std::vector<sf::Sprite> missiles; sf::Image MissileImage; if ( !MissileImage.LoadFromFile("Images/Missle.psd")) return -1; std::vector<Enemy> enemies; if ( !EnemyImage.LoadFromFile("Images/Bad Guy!.psd")) return -2; createWave(enemies); std::vector<sf::Sprite> enemyMissiles; if ( !EnemyMissileSprite.LoadFromFile("Images/BadGuyMissile.psd") ) return -3; sf::String help("Use WASD to move and change your direction.\nUse the arrow keys to move without changing your direction.\nPress space to fire."); help.SetSize(16.0f); help.SetColor(sf::Color::Red); help.SetPosition(848, 0); // Start game loop while (App.IsOpened()) { // Process events sf::Event Event; while (App.GetEvent(Event)) { // Close window : exit if (Event.Type == sf::Event::Closed) App.Close(); if (Event.Key.Code == sf::Key::F1) { sf::Image Screen = App.Capture(); Screen.SaveToFile("screenshot.png"); } if ( gameOver && score > getLastScore(highScoreList)) { if (Event.Type == sf::Event::TextEntered) { char c = Event.Text.Unicode; if (c == 8)//8 is backspace { if (inputString.size() > 0)//check that there is something to delete { inputString.erase(inputString.end() - 1);//delete the last character } } else if (c < 128 && c > 31)//pretty much anything you want should be between 31 and 128 { inputString.push_back(c); } } whatever.SetText(inputString); } } // Get elapsed time float ElapsedTime = App.GetFrameTime(); currentTime = clock.GetElapsedTime(); if ( !gameOver ) { // Move the sprite if ((App.GetInput().IsKeyDown(sf::Key::A) || App.GetInput().IsKeyDown(sf::Key::Left)) && Player.GetPosition().x > 32) { Player.Move(-250 * ElapsedTime, 0); } if ((App.GetInput().IsKeyDown(sf::Key::D) || App.GetInput().IsKeyDown(sf::Key::Right)) && Player.GetPosition().x < 300) { Player.Move( 250 * ElapsedTime, 0); } if ((App.GetInput().IsKeyDown(sf::Key::W) || App.GetInput().IsKeyDown(sf::Key::Up)) && Player.GetPosition().y > 32) { Player.Move(0, -250 * ElapsedTime); } if ((App.GetInput().IsKeyDown(sf::Key::S) || App.GetInput().IsKeyDown(sf::Key::Down)) && Player.GetPosition().y < 688) { Player.Move(0, 250 * ElapsedTime); } //rotate the sprite if (App.GetInput().IsKeyDown(sf::Key::A)) { Player.SetRotation(180); } if (App.GetInput().IsKeyDown(sf::Key::D) ) { Player.SetRotation(0); } if (App.GetInput().IsKeyDown(sf::Key::W) ) { Player.SetRotation(90); } if (App.GetInput().IsKeyDown(sf::Key::S) ) { Player.SetRotation(270); } if ( !App.GetInput().IsKeyDown(sf::Key::Space) ) { spaceIsPressed = false; } if ( App.GetInput().IsKeyDown(sf::Key::Space) && !spaceIsPressed) { sf::Sprite Missile(MissileImage); Missile.SetPosition(Player.GetPosition()); Missile.SetRotation(Player.GetRotation()); missiles.push_back(Missile); spaceIsPressed = true; } makeEnemiesShoot(enemies, enemyMissiles); moveMissiles(missiles, ElapsedTime); moveEnemyMissiles(enemyMissiles, ElapsedTime); checkMissiles(missiles); checkMissiles(enemyMissiles); if ( !enemiesInPlace ) moveEnemiesIn(enemies, ElapsedTime); testCollisions(enemies, missiles); if ( checkCollisions(Player, enemyMissiles) ) { // Player has been hit! Clear the screen of missiles, reset his position, and decrease the lives lives--; enemyMissiles.clear(); Player.SetPosition(200.0f, 32.0f); deathTime = clock.GetElapsedTime(); if ( lives < 0 ) gameOver = true; } if ( getAliveEnemies(enemies) == 0 ) createWave(enemies); } else { if ( App.GetInput().IsKeyDown(sf::Key::Escape) ) App.Close(); if ( App.GetInput().IsKeyDown(sf::Key::Return)) finishedEnteringName = true; } std::string sStats; std::stringstream out; out<< "Lives: "; if ( lives < 0) out<< "Dead"; else out<< lives; out << " Score: " << score; sStats = out.str(); sf::String StringStats(sStats); StringStats.SetPosition(10,680); // Clear screen App.Clear(); // Display sprite in our window App.Draw(Background); for ( unsigned int i = 0; i < missiles.size(); i++ ) App.Draw(missiles.at(i)); if ( !gameOver ) App.Draw(Player); for ( unsigned int i = 0; i < enemies.size(); i++) if ( enemies.at(i).isAlive() ) App.Draw(enemies.at(i).getSprite()); for ( unsigned int i = 0; i < enemyMissiles.size(); i++ ) App.Draw(enemyMissiles.at(i)); App.Draw(StringStats); App.Draw(help); if ( currentTime - deathTime < 1.0f && clock.GetElapsedTime() > 1.0f) { sf::String deathInfo("You've been killed!"); deathInfo.SetPosition(360, 0); App.Draw(deathInfo); } if ( gameOver ) { sf::String gameOverString("Game Over! You lose! Press Esc to quit."); std::string scoreMsg; if ( score == 0 ) scoreMsg = "Wow you suck"; else if ( score < 750 ) { scoreMsg = "You're getting there! Better luck next time."; } else { scoreMsg = "You died, but you died after killing a lot of people. Good job!"; } sf::String ScoreMsg(scoreMsg); gameOverString.SetPosition(350, 600); ScoreMsg.SetPosition(350, 625); App.Draw(gameOverString); App.Draw(ScoreMsg); App.Draw(highScoreString); if ( score > getLastScore(highScoreList) && !finishedEnteringName ) { App.Draw(youMadeIt); App.Draw(whatever); } if ( finishedEnteringName && !savedToFile) { if ( score > getLastScore(highScoreList)) { for ( unsigned int i = 0; i < highScoreList.size(); i++ ) { Score temp = highScoreList.at(i); if ( score > temp.Getscore()) { //add the new score before this one Score newScore(inputString, score); highScoreList.insert(highScoreList.begin()+i, newScore); highScoreList.erase(highScoreList.end()-1); break; } } saveScoresToFile(highScoreList); highScoreString.SetText(convertScoresToString(highScoreList)); savedToFile = true; } } } // Display window contents on screen App.Display(); } return EXIT_SUCCESS; }