// Get the current location id of a given player LocationID getLocation(GameView currentView, PlayerID player) { //printf("called getLocation in gameview\n"); switch(player) { case 0: return getPlayerLocation(currentView->Lord_Godalming); case 1: return getPlayerLocation(currentView->Dr_Seward); case 2: return getPlayerLocation(currentView->Van_Helsing); case 3: return getPlayerLocation(currentView->Mina_Harker); case 4: return getPlayerLocation(currentView->Dracula); default: return 0; } }
void GameState::addDodgecoin() { sf::Vector2f newcoin; int random = rand()%100; if (random <= 10) { m_dodgecoin_locations.push_back(sf::Vector2f(rand()%1280,getPlayerLocation().y-1000)); } }
void GameState::addMeteor() { sf::Vector2f newmeteor; int random = rand()%100; if (random <= 5) { m_meteor_locations.push_back(sf::Vector2f(rand()%1280,getPlayerLocation().y-1000)); } }
Geoscape::Geoscape(Career* career) { _career = career; _endOfActivity = false; _requestedActivity = NULL; _passedTime = 0.0f; _blinkingTime = 0.0f; // create geoscape window _geoscape = Gameplay::iGui->createWindow( "Geoscape" ); assert( _geoscape ); _geoscape->getPanel()->setRenderCallback( panelRenderCallback, this ); _moveMap = false; _lastPosIsValid = false; _lastX = _lastY = 0; _currX = _currY = 0; _geoscapeMode = NULL; // create locations if( _career->isHomeDefined() ) { Location* homeLocation = new Location( this, 0 ); _locations.push_back( homeLocation ); if( _career->getHomePlacementFlag() ) { homeLocation->setPlayer( true ); _career->setHomePlacementFlag( false ); } } for( unsigned int i=1; i<database::LocationInfo::getNumRecords(); i++ ) { _locations.push_back( new Location( this, i ) ); } // make market offers for( unsigned int i=0; i<125; i++ ) { Gear marketOffer = generateGear( getCore()->getRandToolkit()->getUniform( 0, 1 ) > 0.75f ); if( marketOffer.isTradeable() ) addGearToMarket( marketOffer ); } // MULTIVERSION ISSUE � // if player is in inaccessible location if( _career->isHomeDefined() ) { Location* location = getPlayerLocation(); if( location && !database::LocationInfo::getRecord( location->getDatabaseId() )->accessible ) { // move player to the dropzone location->setPlayer( false ); getLocation( unsigned int( 0 ) )->setPlayer( true ); }
//start Minigame void GameState::startMini() { m_game_state = STATE_MINI; //setTotalDodgecoins(total_dodgecoins + m_dodgecoins_collected); m_dodgecoins_collected = 0; //m_dodgecoin_locations.clear(); //std::cout << "start mini" <<std::endl; setPlayerMovementDirection (DIRECTION_NONE); setPlayerLocation(sf::Vector2f (50,700)); //ADD COIN for (int i=0; i<10; i++) { sf::Vector2f newcoin; m_dodgecoin_locations.push_back(sf::Vector2f(rand()%1280,getPlayerLocation().y)); } }
void GameState::updateGameState() { // Do nothing if the game is not in playing state if(m_game_state == STATE_MENU) { //s->setBgVolume(0); s->playSound(SOUND_INTRO); } else if (m_game_state == STATE_SHOP) { //s->playSound(SOUND_INTRO); } else if(m_game_state == STATE_PLAYING) { // Update the player location sf::Vector2f delta; switch(m_player_direction) { case DIRECTION_LEFT: delta = sf::Vector2f(-5,0); m_velocity -= gravity/(rocket.aerodynamic/10); break; case DIRECTION_RIGHT: delta = sf::Vector2f(5,0); m_velocity -= gravity/(rocket.aerodynamic/10); break; default: delta = sf::Vector2f(0,0); break; } delta.y -= m_velocity; m_velocity -= gravity; // Apply delta to the player position sf::Vector2f new_location(getPlayerLocation() + delta); // Check if new position is inside the game area if(new_location.x < 0) { new_location.x = 0; } else if(new_location.x + ROBOT_WIDTH >= m_size_x) { new_location.x = m_size_x - ROBOT_WIDTH; } setPlayerLocation(new_location); // Update location if(new_location.y < 0 && m_velocity < 0) { setTotalDodgecoins(total_dodgecoins + m_dodgecoins_collected); m_dodgecoins_collected =0; setPlayerLocation(sf::Vector2f(m_size_x/2-ROBOT_WIDTH/2,m_size_y/2-ROBOT_HEIGHT/2)); // Reset Player Location std::cout << "totalcoins: " << total_dodgecoins <<std::endl; startShop(); } else if ((getPlayerLocation().y/100)*-1 >= 2500 && rocket.coolness >= 9000) // Aus Präsentationsgründen auf 500 gesetzt, normal 2000 { startEnd(); } // Bounding box of the player sf::FloatRect player_box(getPlayerLocation(),sf::Vector2f(ROBOT_WIDTH,ROBOT_HEIGHT)); //ADD COIN addDodgecoin(); //add meteor addMeteor(); std::vector<sf::Vector2f>::iterator s_it; s_it = m_dodgecoin_locations.begin(); // Check for each coin location ... while(s_it != m_dodgecoin_locations.end()) { // ... if the rocket is collecting the coin sf::FloatRect dodgecoin_box(*s_it,sf::Vector2f(COIN_WIDTH,COIN_HEIGHT)); if(dodgecoin_box.intersects(player_box)) { // Remove coin m_dodgecoin_locations.erase(s_it); m_dodgecoins_collected++; } else { // Advance iterator to next coin s_it++; } } s_it = m_meteor_locations.begin(); // Check for each meteor location ... while(s_it != m_meteor_locations.end()) { // ... if the rocket is colliding the meteor sf::FloatRect meteor_box(*s_it,sf::Vector2f(80,80)); if(meteor_box.intersects(player_box)) { // Remove meteor m_meteor_locations.erase(s_it); m_velocity -= 50*gravity; } else { // Advance iterator to next coin s_it++; } } } else if(m_game_state == STATE_MINI) { // Update the player location sf::Vector2f delta; switch(m_player_direction) { case DIRECTION_LEFT: delta = sf::Vector2f(-5,0); break; //std::cout << "leftmini" <<std::endl; case DIRECTION_RIGHT: delta = sf::Vector2f(5,0); break; //std::cout << "rightmini" <<std::endl; case DIRECTION_UP: delta = sf::Vector2f(0,0); break; case DIRECTION_DOWN: delta = sf::Vector2f(0,0); break; default: delta = sf::Vector2f(0,0); break; } // Apply delta to the player position sf::Vector2f new_location(getPlayerLocation() + delta); // Check if new position is inside the game area if(new_location.x >= 0 && new_location.x + ROBOT_WIDTH <= m_size_x) { setPlayerLocation(new_location); // Update location //std::cout << "neue position??" << std::endl; } if(new_location.x >=1200) { setTotalDodgecoins(total_dodgecoins + m_dodgecoins_collected); m_dodgecoins_collected =0; startShop(); } // Bounding box of the player sf::FloatRect player_box(getPlayerLocation(),sf::Vector2f(ROBOT_WIDTH,ROBOT_HEIGHT)); std::vector<sf::Vector2f>::iterator s_it; s_it = m_dodgecoin_locations.begin(); // Check for each coin location ... while(s_it != m_dodgecoin_locations.end()) { // ... if the nils is collecting the coin sf::FloatRect dodgecoin_box(*s_it,sf::Vector2f(COIN_WIDTH,COIN_HEIGHT)); if(dodgecoin_box.intersects(player_box)) { // Remove coin m_dodgecoin_locations.erase(s_it); m_dodgecoins_collected++; //std::cout << "coooooooooooooiiiiin" << std::endl; //setTotalDodgecoins(total_dodgecoins + m_dodgecoins_collected); std::cout << "totalcoins: " << total_dodgecoins <<std::endl; std::cout << "collectedcoins: " << m_dodgecoins_collected <<std::endl; } else { // Advance iterator to next coin s_it++; } } } else if(m_game_state == STATE_CREDITS) { } else if (m_game_state == STATE_END) { } else // Do nothing if the game is not in mini state { return; } //startEnd(); }