void Ajustes::cambiarSonido(float positionX,bool fondo){ float min = 0.0; float max = 0.0; if(!fondo){ min = barraEfectos->getPositionX()-((barraEfectos->getContentSize().width*escala)/2); max = barraEfectos->getPositionX()+((barraEfectos->getContentSize().width*escala)/2); }else{ min = barraMusica->getPositionX()-((barraMusica->getContentSize().width*escala)/2); max = barraMusica->getPositionX()+((barraMusica->getContentSize().width*escala)/2); } float maxOriginal = max-min; float valorOriginal = positionX-min; float porcentaje = (floorf((100*valorOriginal)/maxOriginal))/100; UserDefault *preferencias = UserDefault::getInstance(); if(positionX>min&&positionX<max){ if(!fondo){ btEfectos->setPositionX(positionX); Configuracion::volumenEfectos = porcentaje; CocosDenshion::SimpleAudioEngine::getInstance()->setEffectsVolume(Configuracion::volumenEfectos); preferencias->setFloatForKey("volEfectos", porcentaje); }else{ btMusica->setPositionX(positionX); Configuracion::volumenMusica = porcentaje; CocosDenshion::SimpleAudioEngine::getInstance()->setBackgroundMusicVolume(Configuracion::volumenMusica); preferencias->setFloatForKey("volMusica", porcentaje); } } }
void NegiSprite::setSprite() { this->setPosition(Vec2(WINSIZE.width/2, WINSIZE.height/2)); float setLine = 3.0; UserDefault *userDef = UserDefault::getInstance(); userDef->setFloatForKey("SetLine", setLine); userDef->flush(); }
void BookSprite::setSprite() { Size visibleSize = WINSIZE; Vec2 origin = Director::getInstance()->getVisibleOrigin(); this->setPosition(Vec2(WINSIZE.width/1.4, WINSIZE.height/2)); float setLine = 2.2; UserDefault *userDef = UserDefault::getInstance(); userDef->setFloatForKey("SetLine", setLine); userDef->flush(); }
bool GameScene::onContactBegin(PhysicsContact& contact) { auto bodyA = contact.getShapeA()->getBody(); auto bodyB = contact.getShapeB()->getBody(); distanceFromHook = player->getPosition().distance(contact.getShapeA()->getBody()->getPosition()); if ((bodyA->getCategoryBitmask() & bodyB->getCollisionBitmask()) == 0 || (bodyB->getCategoryBitmask() & bodyA->getCollisionBitmask()) == 0) { // Player hits goal if (bodyA->getTag() == PLAYER && bodyB->getTag() == GOAL) { CocosDenshion::SimpleAudioEngine::sharedEngine()->stopBackgroundMusic(); if (!Constant::soundMuted) { CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("Sounds/Goal/IndianWarChant 6077_99.mp3"); } UserDefault *def = UserDefault::getInstance(); def->getFloatForKey(Constant::mapname.c_str(), highscore); if (timeMilliseconds < highscore || highscore == 0) { highscore = timeMilliseconds; def->setFloatForKey(Constant::mapname.c_str(), highscore); } this->GoToLevelMenuScene(this); return false; } if (bodyB->getTag() == PLAYER && bodyA->getTag() == GOAL) { this->GoToLevelMenuScene(this); return false; } // Hook hits player, cancel if (bodyA->getTag() == PLAYER && bodyB->getTag() == HOOK) { return false; } if (bodyB->getTag() == PLAYER && bodyA->getTag() == HOOK) { return false; } // RayBox hits player, cancel if (bodyA->getTag() == PLAYER && bodyB->getTag() == RAYCASTCOLLISIONBOX) { return false; } if (bodyB->getTag() == PLAYER && bodyA->getTag() == RAYCASTCOLLISIONBOX) { return false; } // RayBox hits spikes, cancel if (bodyA->getTag() == SPIKE && bodyB->getTag() == RAYCASTCOLLISIONBOX) { sprite->stopAllActions(); return false; } if (bodyB->getTag() == SPIKE && bodyA->getTag() == RAYCASTCOLLISIONBOX) { sprite->stopAllActions(); return false; } // Player hits spikes, suffer agonizing death. if (bodyA->getTag() == SPIKE && bodyB->getTag() == PLAYER) { this->RestartScene(this); return false; } if (bodyB->getTag() == SPIKE && bodyA->getTag() == PLAYER) { this->RestartScene(this); return false; } // // RayBox hits metal, cancel if (bodyA->getTag() == RAYCASTCOLLISIONBOX && bodyB->getTag() == METAL) { sprite->stopAllActions(); return false; } if (bodyB->getTag() == RAYCASTCOLLISIONBOX && bodyA->getTag() == METAL) { sprite->stopAllActions(); return false; } if (sprite) { // RayBox hits tiles if (player->isTouchHold) { if (bodyA->getTag() == RAYCASTCOLLISIONBOX && bodyB->getTag() == TILE) { sprite->stopAllActions(); boxHitPos = bodyA->getPosition(); player->getPlayer()->stopAllActions(); player->Fleng(); player->isHooked = true; return true; } else if (bodyB->getTag() == RAYCASTCOLLISIONBOX && bodyA->getTag() == TILE) { sprite->stopAllActions(); boxHitPos = bodyA->getPosition(); player->getPlayer()->stopAllActions(); player->isHooked = true; player->Fleng(); return true; } } } } return true; }