int main() { #ifdef _DEBUG //メモリリークの検出(_DEBUGが定義されていた場合のみ有効です。) int tmpDbgFlag; tmpDbgFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); //tmpDbgFlag |= _CRTDBG_DELAY_FREE_MEM_DF; tmpDbgFlag |= _CRTDBG_ALLOC_MEM_DF; tmpDbgFlag |= _CRTDBG_LEAK_CHECK_DF; _CrtSetDbgFlag(tmpDbgFlag); //_CrtSetBreakAlloc(45109); #endif Ghost* g = new Ghost; cout << g->request("OnBoot") << endl; cout << g->request("OnDoubleClick") << endl; //cout << ghost.request("OnNadeCopy") << endl; delete g; return 0; }
/*! constructor from another Ghost * * \param g ghost * */ template <typename S> inline Ghost(const Ghost<dim,S> & g) { for (size_t i = 0 ; i < dim ; i++) { this->setLow(i,g.getLow(i)); this->setHigh(i,g.getHigh(i)); } }
void InvertDirectionMessage::execute(Logic* logic){ std::vector<Entity*> entityVector = logic->getEntityVector(); for(unsigned int i = 0; i < entityVector.size(); i++){ Entity *currentEntity = entityVector[i]; if(currentEntity->getType() == GHOST){ Ghost *currentGhost = static_cast<Ghost*>(currentEntity); currentGhost->invertTravelDirection(); currentGhost->move(0, 1); } } }
void WorldGenerator::AddGhost( float _x, float _y, D3DXVECTOR3 _dest, int _mod ) { Ghost* ghost = new Ghost( mGFS->quadtree ); mGFS->mGhost.push_back( ghost ); ghost->pacM = mGFS->mPacMan; ghost->temp = _dest; ghost->mModel = mResources->getModel( _mod ); ghost->mPosition = D3DXVECTOR3( _x, 0, _y ); ghost->Initialize( md3dManager ); }
/*! \brief Calculate parameters for the symmetric cell list * * \param[in] dom Simulation domain * \param[out] cd_sm This cell-decomposer is set according to the needed division * \param[in] g Ghost part extension * \param[out] pad required padding for the cell-list * * \return the processor bounding box */ template<unsigned int dim, typename St> static inline void cl_param_calculateSym(const Box<dim,St> & dom, CellDecomposer_sm<dim,St,shift<dim,St>> & cd_sm, Ghost<dim,St> g, size_t & pad) { size_t div[dim]; for (size_t i = 0 ; i < dim ; i++) div[i] = (dom.getHigh(i) - dom.getLow(i)) / g.getHigh(i); g.magnify(1.013); pad = 1; cd_sm.setDimensions(dom,div,pad); }
void CameraDefend::Update() { dotAngle += 5; if (dotAngle > 359) dotAngle = 0; Ghost* ghost = getGameState()->getGhost(); if (ghost != NULL && ghost->isAttackDefendable() && !(ghost->getAttack() == NULL || ghost->getAttack()->isOver())) { if (!active) { reinit(); } active = true; getFightTutorial()->triggerTutorial(TUTORIAL_DEFEND); } else { active = false; } }
/*! \brief Calculate parameters for the symmetric cell list * * \param[in] dom Simulation domain * \param[output] cd_sm This cell-decomposer is set according to the needed division * \param[in] g Ghost dimensions * \param[output] pad required padding for the cell-list * * \return the processor bounding box */ template<unsigned int dim, typename St> static inline void cl_param_calculateSym(const Box<dim,St> & dom, CellDecomposer_sm<dim,St,shift<dim,St>> & cd_sm, Ghost<dim,St> g, St r_cut, size_t & pad) { size_t div[dim]; for (size_t i = 0 ; i < dim ; i++) div[i] = (dom.getHigh(i) - dom.getLow(i)) / r_cut; g.magnify(1.013); // Calculate the maximum padding for (size_t i = 0 ; i < dim ; i++) { size_t tmp = std::ceil(fabs(g.getLow(i)) / r_cut); pad = (pad > tmp)?pad:tmp; tmp = std::ceil(fabs(g.getHigh(i)) / r_cut); pad = (pad > tmp)?pad:tmp; } cd_sm.setDimensions(dom,div,pad); }
void CameraDefend::Motion(int32 x, int32 y, uint32 id) { if (!isActive()) return; Ghost* ghost = getGameState()->getGhost(); CIwFVec2 drawEnd = CIwFVec2(x, y); bool dotsCollideWithDrawing = (dotCollides(&dotVertsTopLeftLeft, &dotVertsSizeLeft, touch[id]->drawStart) && dotCollides(&dotVertsTopLeftRight, &dotVertsSizeRight, drawEnd)) || (dotCollides(&dotVertsTopLeftRight, &dotVertsSizeRight, touch[id]->drawStart) && dotCollides(&dotVertsTopLeftLeft, &dotVertsSizeLeft, drawEnd)); if (dotsCollideWithDrawing) { active = false; if (ghost->getAttack() != NULL) defended = true; ghost->getAttack()->setDefended(); /*IwTrace(GHOST_HUNTER, ("Player defend drawing %s; coords %.0f.%.0f to %.0f.%.0f - dot left coord %.0f.%.0f right coord %.0f.%.0f", dotsCollideWithDrawing ? "accpeted" : "rejected", drawStart.x, drawStart.y, drawEnd.x, drawEnd.y, defendVertsLeft[0].x, defendVertsLeft[0].y, defendVertsRight[0].x, defendVertsRight[0].y));*/ } }
void Ghost::updateEvent(double secsElapsed) { if (!mTarget) newTarget(); //check if we caught them if (mTarget && distanceSq(pos(), mTarget->pos()) < 9.0) { mTarget->remove(); Ghost* victim = new Ghost(mTarget->pos(), world()); victim->setVelocity(mTarget->velocity()); ++mKillCount; if (mKillCount % 3 == 0) new DormantGhostPortal(pos(), world()); newTarget(); } newTargetTimer += secsElapsed; if (newTargetTimer > 30) newTarget(); assert(mTarget || !(mPursue->isOn())); Actor::updateEvent(secsElapsed); }
int main() { int scale = 3; int counter = 0; int counter2 = 0; int currentDirection = 0; int ballIndex = 0; int score = 0; int outOfBoxCounter = 0; const int maxBallCount = 245; bool wait = true; int positionGhost = 280; bool pinkOutBox = false; Clock boxClock; Clock introClock; Clock afraidClock; enum Status { Stopped, Paused, Playing }; sf::RenderWindow window(sf::VideoMode(224 * scale, 288 *scale), "Pacman"); window.setFramerateLimit(30); //*************************************************** sf::Texture whiteGhost; if (!whiteGhost.loadFromFile("Images/whiteGhost.png")) { cout << "Error\n"; } //pinky: std::vector<Ghost>::iterator ghostIter; std::vector<Ghost> ghostArray; Ghost pink; sf::IntRect rectPinkSprite(0, 0, 24, 24); sf::Texture pinkText; if (!pinkText.loadFromFile("Images/redGhost.png")) { std::cout << "Error\n"; } pink.sprite.setTexture(pinkText); pink.sprite2.setTexture(whiteGhost); pink.sprite.setTextureRect(rectPinkSprite); pink.sprite2.setTextureRect(rectPinkSprite); pink.setPosition(positionGhost, 410); ghostArray.push_back(pink); Ghost inky; sf::IntRect rectInkySprite(0, 0, 24, 24); sf::Texture inkyText; inky.setPosition(positionGhost + 30, 410); if (!inkyText.loadFromFile("Images/blueGhost2.png")) { std::cout << "Error\n"; } inky.sprite.setTexture(inkyText); inky.sprite2.setTexture(whiteGhost); inky.sprite2.setTextureRect(rectInkySprite); inky.sprite.setTextureRect(rectInkySprite); ghostArray.push_back(inky); Ghost blinky; sf::IntRect rectBlinkySprite(0, 0, 24, 24); sf::Texture blinkyText; blinky.setPosition(positionGhost + 60, 410); if (!blinkyText.loadFromFile("Images/pinkGhost.png")) { std::cout << "Error\n"; } blinky.sprite.setTexture(blinkyText); blinky.sprite2.setTexture(whiteGhost); blinky.sprite2.setTextureRect(rectBlinkySprite); blinky.sprite.setTextureRect(rectBlinkySprite); ghostArray.push_back(blinky); Ghost clyde; sf::IntRect rectClydeSprite(0, 0, 24, 24); sf::Texture clydeText; clyde.setPosition(positionGhost + 90, 410); if (!clydeText.loadFromFile("Images/orangeGhost.png")) { std::cout << "Error\n"; } clyde.sprite.setTexture(clydeText); clyde.sprite2.setTexture(whiteGhost); clyde.sprite2.setTextureRect(rectClydeSprite); clyde.sprite.setTextureRect(rectClydeSprite); ghostArray.push_back(clyde); //**************************************************** //*************************************************** //Loading in Map to position the walls std::ifstream fin; fin.open("level.txt"); int val; if (fin.fail()) { cout << "Error couldn't load file" << endl; } //*************************************************** //balls: Ball ball; std::vector<Ball>::iterator ballIter; std::vector<Ball> ballArray; sf::IntRect rectBallSprite(0, 0, 24, 24); sf::Texture ballText; sf::Texture largePalletText; if (!ballText.loadFromFile("Images/pellets.png")) { std::cout << "Error\n"; } if (!largePalletText.loadFromFile("Images/largePellet.png")) { std::cout << "Error\n"; } //*************************************************** // Setting up the tile that represent the walls //Positioning the walls in the map std::vector<Tile>::const_iterator tileIter; std::vector<Tile> tileArray; Tile tile; sf::Vector2i Grid(28 * scale, 36 * scale); for (int y = 0; y < 36; y++) { for (int x = 0; x < 28; x++) { fin >> val; cout << val; if (val == 1) { tile.update(x, y); tileArray.push_back(tile); } //setting coordinates for 250 ball objects in array if (((y >= 4 && y < 12) || (y >= 12 && (x == 6 || x == 21)) || (y >= 23 && y < 34)) && (val == 0) && (ballIndex < maxBallCount)) { ball.setXYPosition(x * 24 + 3, y * 24 + 3); ball.sprite.setTexture(ballText); ball.sprite.setTextureRect(rectBallSprite); ball.setLargePellet(false); ballArray.push_back(ball); ballIndex++; } else if (val == 3) { ball.setXYPosition(x * 24 + 3, y * 24 + 3); ball.sprite.setTexture(largePalletText); ball.sprite.setTextureRect(rectBallSprite); ball.setLargePellet(true); ballArray.push_back(ball); ballIndex++; } } } //Setting up the walls for when pacman goes through the tunnel tile.update(-1, 16); tileArray.push_back(tile); tile.update(28, 16); tileArray.push_back(tile); tile.update(-1, 18); tileArray.push_back(tile); tile.update(28, 18); tileArray.push_back(tile); fin.close(); //**************************************************** //Background Setup: sf::Texture background; if (!background.loadFromFile("Images/pacmanMap.png")) { std::cout << "Error\n"; } sf::Sprite map(background); map.scale(scale, scale); //****************************************************** //Loading up the waka waka sound sf::SoundBuffer playsiren; if (!playsiren.loadFromFile("Sound/Pacman_Siren.wav")) { std::cout << "Couldn't load sound file.\n"; } Sound siren; siren.setBuffer(playsiren); //****************************************************** //Loading up the starting music sf::SoundBuffer buffer; if (!buffer.loadFromFile("Sound/PacmanIntro.wav")) { std::cout << "Couldn't load sound file.\n"; } Sound introMusic; introMusic.setBuffer(buffer); //******************************************************* //Loading up the waka waka sound sf::SoundBuffer wakaWaka; if (!wakaWaka.loadFromFile("Sound/Pacman_Waka_WakaV2.wav")) { std::cout << "Couldn't load sound file.\n"; } Sound waka; waka.setBuffer(wakaWaka); //******************************************************** //Player setup and Loading up the pacman image //Setting up the demensions of the sprite sf::IntRect rectSourceSprite(0, 0, 24, 24); Player player; sf::Texture pacText; if ( !pacText.loadFromFile( "Images/pacmanDirections.png" ) ) { std::cout << "Error\n"; } player.sprite.setTexture(pacText); player.sprite.setTextureRect(rectSourceSprite); //******************************************************** //Lives sf::IntRect rectLiveSprite(24, 0, 24, 24); sf::Sprite live1; live1.setTexture(pacText); live1.setTextureRect(rectLiveSprite); live1.setOrigin(-600, -45); sf::Sprite live2; live2.setTexture(pacText); live2.setTextureRect(rectLiveSprite); live2.setOrigin(-624, -45); //******************************************************** sf::IntRect recCherrieSprite(0, 0, 24, 24); sf::Texture cherrieText; if (!cherrieText.loadFromFile("Images/Cherrie2.png")) { std::cout << "Error\n"; } Character cherrie; cherrie.sprite.setTexture(cherrieText); cherrie.sprite.setTextureRect(recCherrieSprite); cherrie.sprite.setOrigin(-100, -90); //******************************************************** //Set Tiles to Grid sf::Texture setGridTexture; sf::Sprite setGridSprite; setGridSprite.setTexture(setGridTexture); setGridSprite.setColor(sf::Color::Black); //******************************************************* //Creating a Grid //Creating a Texture and a sprite sf::RectangleShape tempGridSpriteOutline; tempGridSpriteOutline.setOutlineColor(sf::Color::White); tempGridSpriteOutline.setOutlineThickness(0.5); tempGridSpriteOutline.setFillColor(sf::Color::Transparent); tempGridSpriteOutline.setSize(sf::Vector2f(8 * scale, 8 * scale)); sf::Font font; if (!font.loadFromFile("pacfont.ttf")) { cout << "fail" << endl; } sf::Font font2; if (!font2.loadFromFile("consola.ttf")) { cout << "fail" << endl; } sf::Text text; text.setFont(font); text.setString("score"); text.setCharacterSize(43); text.setColor(sf::Color::White); text.setOrigin(-40, 0); Menu menu(window.getSize().x, window.getSize().y); Gameover gameover(window.getSize().x, window.getSize().y); while (window.isOpen()) { sf::Event event; while (window.pollEvent(event) || menu.getIsMenuOn()) { if (event.type == sf::Event::Closed) window.close(); //******************************************************************** //Creating the menu if (menu.getIsMenuOn()) { window.clear(); menu.draw(window); window.display(); switch (event.type) { case sf::Event::KeyReleased: switch (event.key.code) { case sf::Keyboard::Up: menu.moveUp(); break; case sf::Keyboard::Down: menu.moveDown(); break; case sf::Keyboard::Return: switch (menu.getPressedItem()) { case 0: wait = true; introMusic.play(); introClock.restart(); menu.setIsMenuOn(false); break; case 1: window.close(); break; } } } }// end of menu if statement } // of event for loop //*********************************************************************** //Display the gameover screen once the player runs out of lives if (player.getLives() <= 1) { sf::RenderWindow window2(sf::VideoMode(224 * scale, 288 * scale), "Game Over"); while (window2.isOpen()) { window.close(); while (window2.pollEvent(event)) { if (event.type == sf::Event::Closed) window2.close(); //******************************************************************** //Creating the menu //window2.clear(); gameover.draw(window2); window2.display(); } } } window.clear(); //drawing background window.draw(map); // this font is for the number, since the other font i downloaded didnt have numbers in it sf::Text mytext; mytext.setFont(font2);//set the object to the new text std::stringstream ss;//converts a interger into a string ss << score; mytext.setString(ss.str().c_str()); mytext.setColor(sf::Color::White); mytext.setCharacterSize(55); mytext.setOrigin(-80, 0); window.draw(mytext); //window.draw(cherrie.sprite); //Draw Grid for (int i = 0; i < Grid.x; i++) { for (int j = 0; j < Grid.y; j++) { tempGridSpriteOutline.setPosition(i * 8 * scale, j * 8 * scale); //window.draw(tempGridSpriteOutline); } } counter = 0; //****************************************************** //Draws tiles throughout the map for (tileIter = tileArray.begin(); tileIter != tileArray.end(); tileIter++) { //window.draw(tileArray[counter].rect); counter++; } //*************************************************** //Allows the player to move player.updateMovement(); player.update(); //***************************************************** //This gets the ghost out of the box at the start of the game. for (ghostIter = ghostArray.begin(); ghostIter < ghostArray.end(); ghostIter++) { if (outOfBoxCounter < 4) { switch (outOfBoxCounter) { case (0) : if (boxClock.getElapsedTime().asSeconds() > 4 && boxClock.getElapsedTime().asSeconds() < 4.6 && !ghostArray[outOfBoxCounter].getOutOfBox()) { ghostArray[outOfBoxCounter].setDirec(2); } else if (boxClock.getElapsedTime().asSeconds() > 4.6 && boxClock.getElapsedTime().asSeconds() < 4.7 && !pinkOutBox) { ghostArray[outOfBoxCounter].setDirec(4); //ghostArray[outOfBoxCounter].setOutOfBox(true); boxClock.restart(); outOfBoxCounter++; } break; case(1) : if (boxClock.getElapsedTime().asSeconds() > 4 && boxClock.getElapsedTime().asSeconds() < 4.2 && !ghostArray[outOfBoxCounter].getOutOfBox()) { ghostArray[outOfBoxCounter].setDirec(2); } else if (boxClock.getElapsedTime().asSeconds() > 4.2 && boxClock.getElapsedTime().asSeconds() < 4.4 && !pinkOutBox) { ghostArray[outOfBoxCounter].setDirec(4); //ghostArray[outOfBoxCounter].setOutOfBox(true); boxClock.restart(); outOfBoxCounter++; } break; case(2) : if (boxClock.getElapsedTime().asSeconds() > 4 && boxClock.getElapsedTime().asSeconds() < 4.2 && !ghostArray[outOfBoxCounter].getOutOfBox()) { ghostArray[outOfBoxCounter].setDirec(3); } else if (boxClock.getElapsedTime().asSeconds() > 4.2 && boxClock.getElapsedTime().asSeconds() < 4.4 && !pinkOutBox) { ghostArray[outOfBoxCounter].setDirec(4); //ghostArray[outOfBoxCounter].setOutOfBox(true); boxClock.restart(); outOfBoxCounter++; } break; case(3) : if (boxClock.getElapsedTime().asSeconds() > 4 && boxClock.getElapsedTime().asSeconds() < 4.5 && !ghostArray[outOfBoxCounter].getOutOfBox()) { ghostArray[outOfBoxCounter].setDirec(3); } else if (boxClock.getElapsedTime().asSeconds() > 4.5 && boxClock.getElapsedTime().asSeconds() < 4.7 && !pinkOutBox) { ghostArray[outOfBoxCounter].setDirec(4); //ghostArray[outOfBoxCounter].setOutOfBox(true); boxClock.restart(); outOfBoxCounter++; } break; } } } //************************************************* //Tunnel mirror if (player.rect.getPosition().x <= -14) { //cout << "Out of the box" << endl; player.rect.setPosition(682, player.rect.getPosition().y); } else if (player.rect.getPosition().x >= 680) { player.rect.setPosition(-15, player.rect.getPosition().y); } //*************************************************** // Wall detection when player collides with a wall counter = 0; for (tileIter = tileArray.begin(); tileIter != tileArray.end(); tileIter++) { if ((player.sprite.getPosition().x >= 300 && player.sprite.getPosition().x <= 360) && (player.sprite.getPosition().y <= 370 && player.sprite.getPosition().y >= 351) && player.getDirection() == 2) { if (player.getDirection() == 2) { player.rect.move(0, -7); break; } } if (player.rect.getGlobalBounds().intersects(tileArray[counter].rect.getGlobalBounds())) { //cout << "Wall HIT AT: "<< tileArray[counter].rect.getPosition().x << "," << tileArray[counter].rect.getPosition().y << endl; currentDirection = player.getDirection(); switch (currentDirection) { case 1: player.rect.move(0, 3); break; case 2: player.rect.move(0, -3); break; case 3: player.rect.move(3, 0); break; case 4: player.rect.move(-3, 0); break; default: break; } } counter++; }//end for loop //******************************************************************** //Changes the direction of the ghost once it hits a wall. counter = 0; counter2 = 0; bool hit = false; for (ghostIter = ghostArray.begin(); ghostIter != ghostArray.end(); ghostIter++) { ghostArray[counter].setHitWall(false); ghostArray[counter].isDownDirectBlock = false; ghostArray[counter].isUpDirectBlock = false; ghostArray[counter].isLeftDirectBlock = false; ghostArray[counter].isRightDirectBlock = false; for (tileIter = tileArray.begin(); tileIter != tileArray.end(); tileIter++) { if(ghostArray[counter].dirRect.getGlobalBounds().intersects(tileArray[counter2].rect.getGlobalBounds())) { ghostArray[counter].setHitWall(true); if (ghostArray[counter].rect.getGlobalBounds().intersects(tileArray[counter2].rect.getGlobalBounds()) && ghostArray[counter].getOutOfBox()) { //cout << "Wall hit" << counter << endl; //currentDirection = player.getDirection(); switch (ghostArray[counter].getDirection2()) { case 1: ghostArray[counter].rect.move(0, -3); //ghostArray[counter].setDirec(4); break; case 2: ghostArray[counter].rect.move(-3, 0); //ghostArray[counter].setDirec(3); break; case 3: ghostArray[counter].rect.move(3, 0); //ghostArray[counter].setDirec(2); break; case 4: ghostArray[counter].rect.move(0, 3); //ghostArray[counter].setDirec(1); break; default: break; } } } if (ghostArray[counter].upRect.getGlobalBounds().intersects(tileArray[counter2].rect.getGlobalBounds()) && (ghostArray[counter].dirRect.getGlobalBounds().intersects(tileArray[counter2].rect.getGlobalBounds()))) { ghostArray[counter].isUpDirectBlock = true; ghostArray[counter].setOutOfBox(true); hit = true; //ghostArray[counter].rect.move(0, 3); } if (ghostArray[counter].downRect.getGlobalBounds().intersects(tileArray[counter2].rect.getGlobalBounds()) && (/*ghostArray[counter].rect.getGlobalBounds().intersects(tileArray[counter2].rect.getGlobalBounds())) &&*/ ghostArray[counter].getOutOfBox())) { ghostArray[counter].isDownDirectBlock = true; //ghostArray[counter].rect.move(0, -3); } if (ghostArray[counter].rightRect.getGlobalBounds().intersects(tileArray[counter2].rect.getGlobalBounds()) && (/*ghostArray[counter].rect.getGlobalBounds().intersects(tileArray[counter2].rect.getGlobalBounds())) &&*/ ghostArray[counter].getOutOfBox())) { ghostArray[counter].isRightDirectBlock = true; //ghostArray[counter].rect.move(-3, 0); } if (ghostArray[counter].leftRect.getGlobalBounds().intersects(tileArray[counter2].rect.getGlobalBounds()) && (/*ghostArray[counter].rect.getGlobalBounds().intersects(tileArray[counter2].rect.getGlobalBounds())) &&*/ ghostArray[counter].getOutOfBox())) { ghostArray[counter].isLeftDirectBlock = true; //ghostArray[counter].rect.move(3, 0); } ghostArray[counter].update(); if (ghostArray[counter].getOutOfBox() && ghostArray[counter].getHitWall()) { //cout << "Wall hit" << endl; ghostArray[counter].randomMovement(); } counter2++; }//end inside for loop /* window.draw(ghostArray[counter].rect); window.draw(ghostArray[counter].upRect); window.draw(ghostArray[counter].downRect); window.draw(ghostArray[counter].leftRect); window.draw(ghostArray[counter].rightRect); window.draw(ghostArray[counter].dirRect); */ counter2 = 0; counter++; }// end for loop //*************************************************** //This where the ghost are allowed to move. counter = 0; for (ghostIter = ghostArray.begin(); ghostIter != ghostArray.end(); ghostIter++) { ghostArray[counter].moving1(); counter++; } //*************************************************** // If the ghost are blue and eaten by pacman, then the ghost are placed back inside the box counter = 0; if (ghostArray[0].getIsAfraid()) { for (ghostIter = ghostArray.begin(); ghostIter != ghostArray.end(); ghostIter++) { //send the ghost back inside the box if (player.sprite.getGlobalBounds().intersects(ghostArray[counter].sprite.getGlobalBounds())) { ghostArray[counter].setOutOfBox(false); ghostArray[counter].setPosition(positionGhost + 60, 410); score = score + 100; break; } counter++; } } //*************************************************** //player touches ghost decrease the lifes by one int counter = 0; for (ghostIter = ghostArray.begin(); ghostIter != ghostArray.end(); ghostIter++) { //decrements lives if pacman hits ghost if (player.sprite.getGlobalBounds().intersects(ghostArray[counter].sprite.getGlobalBounds()) && !ghostArray[counter].getIsAfraid()) { player.sprite.setPosition(sf::Vector2f(14 * 24, 20 * 24 + 4)); player.rect.setPosition(sf::Vector2f(14 * 24, 20 * 24 + 4)); if (player.getLives() == 2) { live1.setOrigin(30, 0); player.setLives(player.getLives() - 1); } //player.sprite.setOrigin(14 * 24, 20 * 24 + 4); else if (player.getLives()> 1) { live2.setOrigin(30, 0); //player.sprite.setOrigin(14 * 24, 20 * 24 + 4); player.setLives(player.getLives() - 1); } } counter++; } //GameOver Display if (player.getLives() <= 0) { window.close(); window.clear(); gameover.draw(window); window.display(); }// end of menu if statement //*************************************************** // If player intersects with ball: counter = 0; counter2 = 0; for (ballIter = ballArray.begin(); ballIter != ballArray.end(); ballIter++) { if (player.rect.getGlobalBounds().intersects(ballArray[counter].rect.getGlobalBounds())) { ballArray[counter].setIsShowing(false); //Turn the ghost blue if the pacman eats a large pallet if (ballArray[counter].getIsLargePellet()) { afraidClock.restart(); for (ghostIter = ghostArray.begin(); ghostIter != ghostArray.end(); ghostIter++) { ghostArray[counter2].setIsAfraid(true); counter2++; } counter2 = 0; } if (introClock.getElapsedTime().asSeconds() >= 0.41)//introClock restarts { waka.play(); //siren.stop(); introClock.restart(); } score++; } counter++; }// end for loop //This deletes the ball from the map counter = 0; for (ballIter = ballArray.begin(); ballIter != ballArray.end(); ballIter++) { if (!ballArray[counter].getIsShowing()) { ballArray.erase(ballIter); break; } counter++; }// end for loop //************************************************** //************************************************** //reset ghost to their original sprite once time runs out counter = 0; if (afraidClock.getElapsedTime().asSeconds() > 8.0) { for (ghostIter = ghostArray.begin(); ghostIter != ghostArray.end(); ghostIter++) { ghostArray[counter].setIsAfraid(false); counter++; } } //************************************************** // If the siren is paused, unpause it if (siren.getStatus() == 0 && introClock.getElapsedTime().asSeconds() > 0.47) { siren.play(); } //*************************************************** //cherrie if (player.rect.getGlobalBounds().intersects(cherrie.sprite.getGlobalBounds())) { score += 100; cherrie.sprite.setPosition(-100, -50); } //ball drawn to screen: counter = 0; for (ballIter = ballArray.begin(); ballIter != ballArray.end(); ballIter++) { if (ballArray[counter].getIsShowing() == true) { window.draw(ballArray[counter].sprite); ballArray[counter].update(); //window.draw(ballArray[ix].rect); } counter ++; } //************************************************************** //window.draw(player.rect2); //drawing the player sprite window.draw(player.sprite); //drawint the lives window.draw(live1); window.draw(live2); window.draw(cherrie.sprite); //window.draw(player.rect); //cout << "Player position: " << player.rect.getPosition().x << ", " << player.rect.getPosition().y << endl; //**************************************************************** //Draws ghost to the screen. If they are afraid then the blue sprite shows up instead counter = 0; for (ghostIter = ghostArray.begin(); ghostIter != ghostArray.end(); ghostIter++) { if (!ghostArray[counter].getIsAfraid()) { window.draw(ghostArray[counter].sprite); } else { window.draw(ghostArray[counter].sprite2); } //window.draw(ghostArray[counter].rect); counter++; } //********************************************************* //********************************************************* window.display(); while (introClock.getElapsedTime().asSeconds() <= 4.0 && wait) { boxClock.restart(); } if (introClock.getElapsedTime().asSeconds() >= 4.1 && wait) { siren.setLoop(true); siren.play(); } wait = false; if (player.getLives() < 1) { introClock.restart(); while (introClock.getElapsedTime().asSeconds() < 6.0) { gameover.draw(window); window.display(); } wait = true; } //cout << ballArray.size() << endl; } return 0; }
void Logic::processGhostMovement(Ghost &ghost, Maze &maze) { if(ghost.getWay().size() == 0) return; if(ghost.isPointReached()) ghost.iter = 0; int X = 0; int Y = 0; //_movingVector.setXY(0,0); if(ghost.iter != ghost.getWay().size() -1) { ghost.setIsPointReached(false); if(ghost.getWay()[ghost.iter]->direction == Direction::UP || ghost.getWay()[ghost.iter]->direction == Direction::LEFT) { X = ghost.getBoundingBox().bottom.x; Y = ghost.getBoundingBox().bottom.y; } else if(ghost.getWay()[ghost.iter]->direction == Direction::DOWN || ghost.getWay()[ghost.iter]->direction == Direction::RIGHT) { X = ghost.getBoundingBox().top.x; Y = ghost.getBoundingBox().top.y; } if(X != ghost.getWay()[ghost.iter + 1]->m_x || Y != ghost.getWay()[ghost.iter + 1]->m_y) { switch(ghost.getWay()[ghost.iter]->direction) { case Direction::UP: ghost.setDirection(Direction::UP); break; case Direction::DOWN: ghost.setDirection(Direction::DOWN); break; case Direction::LEFT: ghost.setDirection(Direction::LEFT); break; case Direction::RIGHT: ghost.setDirection(Direction::RIGHT); break; } } else { ++ghost.iter; ghost.setPosition(X,Y); } } if(ghost.getPosition().x == ghost.getWay()[ghost.getWay().size() - 1]->m_x && ghost.getPosition().y == ghost.getWay()[ghost.getWay().size() - 1]->m_y) { ghost.setIsPointReached(true); } if(ghost.getPosition() == ghost.getDestinationPoint()) { ghost.setDirection(Direction::STOP); } ghost.setMovingVector(); }
void renderGhost() { if (!getGameState()->getPlayer()->isReady()) { return; } IwGxLightingOff(); Ghost *ghost = getGameState()->getGhost(); CIwFVec3 ghostPosition(0, 0, ghost->getDistance()); double ghostRotation = rad(ghost->getRotation()); // Place the markers on the edge of the compass radius // rotated to their correct bearing to current location ghostMatrix->SetRotY(rad(ghost->getBearing())); ghostMatrix->SetTrans(ghostMatrix->RotateVec(ghostPosition)); ghostMatrix->PostRotateY(ghostRotation); IwGxSetModelMatrix(ghostMatrix); if (ghost->pollAnimCaptured()) { ghost_Player->PlayAnim(ghost_Anims[GHOST_ANIM_CAPTURED], 1, 0, BLEND_DURATION); } else if (ghost->pollAnimAgro()) { ghost_Player->PlayAnim(ghost_Anims[GHOST_ANIM_AGRO], 1, 0, BLEND_DURATION); } else if (ghost->pollAnimDodge()) { ghost_Player->PlayAnim(ghost_Anims[GHOST_ANIM_DODGE], 1, 0, BLEND_DURATION); } else if (ghost->pollAnimAttack()) { ghost_Player->PlayAnim(ghost_Anims[GHOST_ANIM_ATTACK], 1, 0, BLEND_DURATION); } IwGxLightingAmbient(true); IwGxSetLightType(0, IW_GX_LIGHT_AMBIENT); int sinceHit = clock() - ghost->getHitTime(); CIwColour colAmbient; if (sinceHit < GHOST_HIT_LENGTH) { int halfAnimation = GHOST_HIT_LENGTH/2; float animState = (float) sinceHit / halfAnimation; if (animState > 1) { animState = 2 - animState; } colAmbient.Set(0xff, 0xff*(1-animState), 0xff*(1-animState), 0xff); } else { // The default state that displays the image as it is colAmbient.Set(0xff, 0xff, 0xff, 0xff); } IwGxSetLightCol(0, &colAmbient); IwGxSetScreenSpaceSlot(1); IwAnimSetSkelContext(ghost_Player->GetSkel()); IwAnimSetSkinContext(ghost_Skin); ghost_Model->Render(); //outline the face under the cursor if (clickX > 0 && clickY > 0) { int32 faceID = ghostCollision->GetFaceUnderCursor(clickX, clickY); if (faceID != -1) { getGameState()->getGhost()->tapped(); clickX = clickY = -1; } else { clickX = clickY = -1; } } // Tidier to reset these IwAnimSetSkelContext(NULL); IwAnimSetSkinContext(NULL); if (ghost->isFound() && !ghost->isDead()) { ghostCollision->RenderEctoplasmaBar((float)ghost->getEctoplasm() / GHOST_MAX_ECTOPLASM, ghostRotation); } }
void myGame::resetGame() { ghosts.clear(); dots.clear(); //create patterns Pattern* ghostPattern1 = new Pattern(1); ghostPattern1->addStep(0, "CAMP", 40, [&] (Entity* e) { Ghost* myself = static_cast<Ghost*>(e) ; int waypoint = myself->targetWaypoint ; VECTOR2 center = *myself->getCenter() ; float left_edge = myself->getX(); float right_edge = myself->getX() + myself->getWidth()*myself->getScale(); float top_edge = myself->getY(); float bottom_edge = myself->getY() + myself->getHeight()*myself->getScale(); VECTOR2 currentWaypoint = waypointSet1[waypoint] ; if( currentWaypoint.x > left_edge && currentWaypoint.x < right_edge && currentWaypoint.y > top_edge && currentWaypoint.y < bottom_edge) myself->targetWaypoint++ ; if( myself->targetWaypoint > 3) myself->targetWaypoint = 0 ; myself->waypointTrack(waypointSet1[waypoint]); myself->vectorTrack(&player, 180); }) ; Pattern* ghostPattern2 = new Pattern(1); ghostPattern2->addStep(0, "CAMP", 40, [&] (Entity* e) { Ghost* myself = static_cast<Ghost*>(e) ; int waypoint = myself->targetWaypoint ; VECTOR2 center = *myself->getCenter() ; float left_edge = myself->getX(); float right_edge = myself->getX() + myself->getWidth()*myself->getScale(); float top_edge = myself->getY(); float bottom_edge = myself->getY() + myself->getHeight()*myself->getScale(); VECTOR2 currentWaypoint = waypointSet2[waypoint] ; if( currentWaypoint.x > left_edge && currentWaypoint.x < right_edge && currentWaypoint.y > top_edge && currentWaypoint.y < bottom_edge) myself->targetWaypoint++ ; if( myself->targetWaypoint > 3) myself->targetWaypoint = 0 ; myself->waypointTrack(waypointSet2[waypoint]); myself->vectorTrack(&player, 180); }) ; //create entities // ghost 1 Ghost* ghost1 = new Ghost() ; if (!ghost1->initialize(this, ghostNS::WIDTH, ghostNS::HEIGHT, 4, &allTM)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing ghost entity")); ghost1->setX(0); ghost1->setY(0); ghosts.add(ghost1, new Pattern(ghostPattern1)); // ghost 2 Ghost* ghost2 = new Ghost() ; if (!ghost2->initialize(this, ghostNS::WIDTH, ghostNS::HEIGHT, 4, &allTM)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing ghost entity")); ghost2->setX(GAME_WIDTH - ghostNS::WIDTH*ghostNS::SCALE); ghost2->setY(GAME_HEIGHT - ghostNS::HEIGHT*ghostNS::SCALE); ghost2->setCurrentFrame(1); ghosts.add(ghost2, new Pattern(ghostPattern2)); // dots rows = 4 ; cols = 5 ; for(int i = 0; i < rows; ++i) { for(int j = 0; j < cols; ++j) { Dot* newDot = new Dot() ; if (!newDot->initialize(this, dotNS::WIDTH, dotNS::HEIGHT, 4, &allTM)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing dot entity")); newDot->setX( ((GAME_WIDTH/cols)*j) + 50); newDot->setY( ((GAME_HEIGHT/rows)*i) + 50); newDot->setScale(dotNS::SCALE); dots.add(newDot); } } dotsRemaining = rows * cols ; }
void CameraDefend::Render() { if (defended) { IwGxLightingOff(); animMatSuccess->SetModulateMode(CIwMaterial::MODULATE_NONE); animMatSuccess->SetAlphaMode(CIwMaterial::ALPHA_BLEND); IwGxSetMaterial(animMatSuccess); IwGxSetUVStream(anim_uvs_success); IwGxSetVertStreamScreenSpace(animVertsLeftSuccess, 4); IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4); IwGxSetVertStreamScreenSpace(animVertsRightSuccess, 4); IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4); if (animMatSuccess->GetAnimCelID() == animMatSuccess->GetAnimCelNum() - 1) { defended = false; } } else { animMatSuccess->SetAnimCelID(0); } if (!isActive()) return; { Ghost* ghost = getGameState()->getGhost(); GhostAttack* attack = (ghost != NULL) ? ghost->getAttack() : NULL; if (attack != NULL && ((attack->getInterval() < 750 && attack->getInterval() > 600) || (attack->getInterval() < 400 && attack->getInterval() > 250))) { dotTexture = dotTextureRed; } else { dotTexture = dotTextureGreen; } } Iw2DSetAlphaMode(IW_2D_ALPHA_NONE); Iw2DSetTransformMatrix(CIwFMat2D::g_Identity); CIwFMat2D rot; rot.SetRot(rad(dotAngle), CIwFVec2( dotVertsTopLeftLeft.x + dotVertsSizeLeft.x/2, dotVertsTopLeftLeft.y + dotVertsSizeLeft.y/2)); Iw2DSetTransformMatrix(rot); Iw2DDrawImage(dotTexture, dotVertsTopLeftLeft, dotVertsSizeLeft); rot.SetRot(rad(dotAngle), CIwFVec2( dotVertsTopLeftRight.x + dotVertsSizeRight.x/2, dotVertsTopLeftRight.y + dotVertsSizeRight.y/2)); Iw2DSetTransformMatrix(rot); Iw2DDrawImage(dotTexture, dotVertsTopLeftRight, dotVertsSizeRight); bool isDrwaing = true; for (int i = 0; i < DEFEND_TOUCHES_MAX; i++) { // Is any touch drawing? if (touch[i]->drawing) break; if (i == DEFEND_TOUCHES_MAX - 1) { isDrwaing = false; animMat->SetAnimCelID(0); } } if (isDrwaing) { IwGxLightingOff(); animMat->SetModulateMode(CIwMaterial::MODULATE_NONE); animMat->SetAlphaMode(CIwMaterial::ALPHA_BLEND); IwGxSetMaterial(animMat); IwGxSetUVStream(anim_uvs); IwGxSetVertStreamScreenSpace(animVertsLeft, 4); IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4); IwGxSetVertStreamScreenSpace(animVertsRight, 4); IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4); } }