void Arcade::updateClock(float dt){ _time --; auto value = String::createWithFormat("%02i", _time); _clock_label->setString(value->getCString()); _clock_label->setFontFillColor(Color3B(255,255,0)); if(_time < 0 && !_in_combo){ showLosser(); _time_over = true; }else if(_time < getTimeStart() * 0.20){ _clock_label->setColor(Color3B::RED); _clock_label->runAction( Sequence::create( FadeOut::create(0.4f), FadeIn::create(0.4f), NULL ) ); } else if(_time < getTimeStart() * 0.5) { _clock_label->setColor(Color3B::YELLOW); _clock_label->runAction( Sequence::create( FadeOut::create(0.7f), FadeIn::create(0.3f), NULL ) ); } }
/** *Incrementa el tiempo *cambia de color la letras para advertir */ void Arcade::addTime(int time){ _time += time; if(_time >= getTimeStart()) _clock_label->setFontFillColor(Color3B(255,255,255)); else if(_time >= getTimeStart() * 0.5) _clock_label->setFontFillColor(Color3B::YELLOW); else if(_time >= getTimeStart() * 0.20) _clock_label->setFontFillColor(Color3B::RED); _clock_label->setString(String::createWithFormat("%02i", _time)->getCString()); }
iap_common::BodyTrajectoryMsg BodyTrajectory::toROSMsg() { iap_common::BodyTrajectoryMsg msg; msg.time_start = getTimeStart(); msg.time_end = getTimeEnd(); msg.body_id = getBodyId(); msg.acc_rotation_angle = getAccRotationAngle(); msg.max_rotation_angle = getMaxRotationAngle(); msg.rotation_axis_parall = getRotationAxisParallelism(); msg.acc_translation_dist = getAccTranslationDistance(); msg.max_translation_dist = getMaxTranslationDistance(); msg.translation_axis_parall = getTranslationAxisParallelism(); return msg; }
bool Arcade::init(){ if(!Layer::init()){ return false; } //inicial tap_begin = Point::ZERO; visibleSize = Director::getInstance()->getVisibleSize(); origin = Director::getInstance()->getVisibleOrigin(); //dificultad setDelayRollBoard(DELAY_ROLL_BOARD); setDelayBeforeFall(DELAY_BEFORE_FALL); setDelayStopCombo(DELAY_STOP_COMBO); setRandomizeBall(DEFAULT_RANDOMIZE_BALL); setRowsStart(DEFAULT_ROWS_START); //objetivos setGoal(SCORE_WIN); setScoreWin(400); setComboWin(6); _stop = false; _goto_menu = false; _snd_take = String("musica y sonidos/baja.ogg"); _snd_drop = String("musica y sonidos/sube.ogg"); _snd_collide = String("musica y sonidos/choca_perla.ogg"); //set key this->setKeypadEnabled(true); background = Sprite::create("mapas/mapa1.png"); background->setPosition(Point( visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y ) ); this->addChild(background, -10); auto border = Sprite::create("efectos/barraArriba.png"); border->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height - border->getContentSize().height/4 + origin.y)); this->addChild(border, 9999); //iniciale el tablaro //y el populador del tablero board = Board::create(); Node* board_view = board->getView(); this->addChild(board_view); board_view->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); board->attachMatch(CC_CALLBACK_2(Arcade::onMatchSpheres, this)); board->attachFall(CC_CALLBACK_3(Arcade::onFallSpheres, this)); board->attachDropSphere(CC_CALLBACK_1(Arcade::onAnimateExploitSphere, this)); board->attachEndBoard(CC_CALLBACK_1(Arcade::onReachEndBoard,this)); board_populater = new BoardPopulaterRandom(board); board_populater->setStartRows(getRowsStart()); board_populater->populate(); board->setPopulater(board_populater); player = Indian::create(); player->retain(); Node* player_view = player->getView(); this->addChild(player_view); player->jumpTo(3); _score_label = LabelTTF::create("0000","default", 60); this->addChild(_score_label, 99999); _score_label->setPosition(Point(origin.x + _score_label->getContentSize().width, origin.y + visibleSize.height - _score_label->getContentSize().height/2)); //variables de juego setTimeStart(DEFAULT_TIME_START); _time = getTimeStart(); _clock_label = LabelTTF::create(String::createWithFormat("%02i", _time)->getCString(), "default", 60); this->addChild(_clock_label, 99999); _clock_label->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height + origin.y - _clock_label->getContentSize().height/3)); _time_over = false; _score = 0; setScoreCombo(DEFAULT_SCORE_COMBO); setScoreMatch(DEFAULT_SCORE_MATCH); auto dispatcher = Director::getInstance()->getEventDispatcher(); auto listener = EventListenerTouchOneByOne::create(); listener->onTouchBegan = CC_CALLBACK_2(Arcade::onTouchBegan, this); listener->onTouchMoved = CC_CALLBACK_2(Arcade::onTouchMoved, this); listener->onTouchEnded = CC_CALLBACK_2(Arcade::onTouchEnded, this); dispatcher->addEventListenerWithSceneGraphPriority(listener, this); this->schedule(schedule_selector(Arcade::updateBoard), 1.0f); CocosDenshion::SimpleAudioEngine::sharedEngine()->stopBackgroundMusic(true); PLAY_MUSIC("musica y sonidos/juego.ogg"); _time_roll_board.initWithTarget(this, schedule_selector(Arcade::updateRollBoard)); _time_roll_board.setInterval(getDelayRollBoard()); _time_combo.initWithTarget(this, schedule_selector(Arcade::updateCombo)); _time_combo.setInterval(0.5f); _in_combo = false; _time_elapsed_combo = 0; //tutorial help_down = Sprite::create("tutorial/1paso.png"); help_down->retain(); help_up = Sprite::create("tutorial/2paso.png"); help_up->retain(); help_now = NULL; return true; }
double Device::tsToTime(ULong64_t timeStamp) const { return (double)((timeStamp - getTimeStart()) / (double)getClockRate()); }