void ThrownArrow::update(std::vector<std::shared_ptr<GameObject>>* worldMap) { arrowMovement(); if(isCollidingWithMonster(worldMap)){ if(!((Monster*)collidingMonster.get())->isInvincible) destroyGameObject(worldMap); ((Monster*)collidingMonster.get())->takeDamage(arrowStrength, worldMap,arrowDir); std::shared_ptr<GameObject> temp = findPlayer(worldMap); Player* player = (Player*)temp.get(); player->arrowIsActive = false; } else if(isOutsideRoomBound(position)){ destroyGameObject(worldMap); std::shared_ptr<GameObject> temp = findPlayer(worldMap); Player* player = (Player*)temp.get(); player->arrowIsActive = false; } }
void DungeonMap::update(std::vector<std::shared_ptr<GameObject>>* Worldmap) { if (isCollidingWithPlayer(Worldmap)){ Player* player = (Player*)findPlayer(Worldmap).get(); Sound::playSound(GameSound::NewInventoryItem); player->inventory->playerBar->hasDungeonMap = true; destroyGameObject(Worldmap); } }
void destroyPlayer(GameObject* player){ if(player != NULL){ destroyGameObject(player); } }
void ThrownBomb::update(std::vector<std::shared_ptr<GameObject>>* worldMap) { currentFrame++; if (currentFrame > maxFrame){ createBombEffect(); destroyGameObject(worldMap); Sound::playSound(GameSound::BombExplose); } }
void Stalfos::processDeath(std::vector<std::shared_ptr<GameObject>>* worldMap){ Point pt(position.x + (width / 4), position.y + (height / 4)); std::shared_ptr<GameObject> add = std::make_shared<DeathEffect>(pt); Static::toAdd.push_back(add); destroyGameObject(worldMap); Sound::playSound(GameSound::SoundType::EnemyKill); dropItemOnDeath(); std::cout << "Stalfos Destroyed"; }
void Triforce::update(std::vector<std::shared_ptr<GameObject>>* Worldmap) { sprite.setPosition(position.x, position.y); if (isCollidingWithPlayer(Worldmap) && !isObtained) { Player* tmp = ((Player*)findPlayer(Worldmap).get()); position.y = tmp->position.y - Global::TileHeight; position.x = tmp->position.x; tmp->isObtainingItem = true; tmp->sprite.setPosition(tmp->position.x, tmp->position.y); Sound::stopSound(GameSound::Underworld); Sound::playSound(GameSound::NewInventoryItem); Sound::playSound(GameSound::Triforce); tmp->inventory->playerBar->healPlayerToFull(); if (tmp->inventory->playerBar->currentDungeon == DungeonLevel::ONE) tmp->inventory->hasDungeon1Triforce = true; isObtained = true; } if (isObtained){ currentFrame++; if (currentFrame > maxFrame){ Player* temp = ((Player*)findPlayer(Worldmap).get()); temp->isObtainingItem = false; Sound::playSound(GameSound::OverWorld); //previousWorld must be same as current room when moving to overworld layer otherwise the player //wont be moved to the correct vector and game will crash when looking for player in the new layer. temp->prevWorldX = temp->position.y / Global::roomHeight; temp->prevWorldY = temp->position.x / Global::roomWidth; temp->currentLayer = Layer::OverWorld; temp->prevLayer = Layer::Dungeon; temp->position = getReturnPointForPlayerLeavingDungeon(temp->inventory->playerBar->currentDungeon); temp->worldX = temp->position.y / Global::roomHeight; temp->worldY = temp->position.x / Global::roomWidth; float inventoryNewX = temp->worldY*Global::roomHeight; float inventoryNewY = temp->worldX*Global::roomWidth; temp->inventory->playerBar->currentDungeon = DungeonLevel::NONE; temp->inventory->setInventoryPosition(Point(inventoryNewX, inventoryNewY)); temp->inventory->playerBar->setPlayerBar(Point(inventoryNewX, inventoryNewY)); for (int i = 0; i < temp->walkingAnimation.size(); i++) { temp->walkingAnimation[i]->sprite.setPosition(temp->position.x, temp->position.y); temp->attackAnimation[i]->sprite.setPosition(temp->position.x, temp->position.y); temp->movePlayerToNewVector = true; } Global::gameView.setCenter(temp->worldY*Global::roomWidth + Global::SCREEN_WIDTH / 2, temp->worldX*Global::roomHeight + Global::SCREEN_HEIGHT / 2); destroyGameObject(Worldmap); } } }
void WoodSwordPickUp::update(std::vector<std::shared_ptr<GameObject>>* Worldmap) { sprite.setPosition(position.x, position.y); if(isCollidingWithPlayer(Worldmap) && !isObtained) { Player* tmp = ((Player*)findPlayer(Worldmap).get()); position.y = tmp->position.y-Global::TileHeight; position.x = tmp->position.x; tmp->inventory->playerBar->mySword = SwordType::WoodSword; tmp->isObtainingItem = true; tmp->sprite.setPosition(tmp->position.x, tmp->position.y); Sound::playSound(GameSound::NewItem); Sound::playSound(GameSound::NewInventoryItem); isObtained = true; } if(isObtained){ currentFrame++; if(currentFrame > maxFrame){ Player* tmp = ((Player*)findPlayer(Worldmap).get()); tmp->isObtainingItem = false; deleteNpcFromCurrentRoom(Worldmap); destroyGameObject(Worldmap); } } }
void ThrownBoomrang::destroyBoomerang(std::vector<std::shared_ptr<GameObject>>* worldMap){ Sound::stopSound(GameSound::Boomerang); destroyGameObject(worldMap); Player* temp =(Player*)findPlayer(worldMap).get(); temp->boomerangIsActive = false; }