void HelloWorld::intersectPlayer() { auto sPlayer = (Sprite*)this->getChildByTag(TAG_SPRITE_PLAYER); Rect rPlayer = Rect(sPlayer->getPositionX() - 10, sPlayer->getPositionY() - 20, 20, 40); //주인공의 충돌박스 설정 for (Sprite* emissile : vEMissile) { Rect rmissile = emissile->getBoundingBox(); //적 미사일 충돌박스 if (rPlayer.intersectsRect(rmissile)) { vEMissile.eraseObject(emissile); this->removeChild(emissile); if (score >= 300) { score -= 300; } else { score = 0; } __String *tempScore = __String::createWithFormat("%i", score); scorelabel->setString(tempScore->getCString()); resetPlayer(); //플레이어가 죽을때 호출 return; } } for (Sprite* eitem : vItem) { Rect ritem = eitem->getBoundingBox(); if (rPlayer.intersectsRect(ritem)) { SimpleAudioEngine::getInstance()->playEffect("ok2.wav"); if (eitem == item1) { if (count == 0) { this->unschedule(schedule_selector(HelloWorld::setMissile)); this->schedule(schedule_selector(HelloWorld::upGradeP2), 0.15f); damage = 2; count = 1; } else if (count == 1) { this->unschedule(schedule_selector(HelloWorld::upGradeP2)); this->unschedule(schedule_selector(HelloWorld::upGradeF2)); this->unschedule(schedule_selector(HelloWorld::upGradeL2)); this->schedule(schedule_selector(HelloWorld::upGradeP3), 0.15f); damage = 3; count = 2; } else if (count == 2) { this->unschedule(schedule_selector(HelloWorld::upGradeP3)); this->unschedule(schedule_selector(HelloWorld::upGradeF3)); this->unschedule(schedule_selector(HelloWorld::upGradeL3)); this->unschedule(schedule_selector(HelloWorld::upGradeF4)); this->unschedule(schedule_selector(HelloWorld::upGradeL4)); this->schedule(schedule_selector(HelloWorld::upGradeP4), 0.15f); damage = 4; count = 2; score += 100; __String *tempScore = __String::createWithFormat("%i", score); scorelabel->setString(tempScore->getCString()); } } else if (eitem == item2) { if (count == 0) { this->unschedule(schedule_selector(HelloWorld::setMissile)); this->schedule(schedule_selector(HelloWorld::upGradeF2), 0.15f); damage = 2; count = 1; } else if (count == 1) { this->unschedule(schedule_selector(HelloWorld::upGradeP2)); this->unschedule(schedule_selector(HelloWorld::upGradeF2)); this->unschedule(schedule_selector(HelloWorld::upGradeL2)); this->schedule(schedule_selector(HelloWorld::upGradeF3), 0.15f); damage = 3; count = 2; } else if (count == 2) { this->unschedule(schedule_selector(HelloWorld::upGradeP3)); this->unschedule(schedule_selector(HelloWorld::upGradeF3)); this->unschedule(schedule_selector(HelloWorld::upGradeL3)); this->unschedule(schedule_selector(HelloWorld::upGradeP4)); this->unschedule(schedule_selector(HelloWorld::upGradeL4)); this->schedule(schedule_selector(HelloWorld::upGradeF4), 0.15f); damage = 4; count = 2; score += 100; __String *tempScore = __String::createWithFormat("%i", score); scorelabel->setString(tempScore->getCString()); } } else if (eitem == item3) { if (count == 0) { this->unschedule(schedule_selector(HelloWorld::setMissile)); this->schedule(schedule_selector(HelloWorld::upGradeL2), 0.15f); damage = 2; count = 1; } else if (count == 1) { this->unschedule(schedule_selector(HelloWorld::upGradeP2)); this->unschedule(schedule_selector(HelloWorld::upGradeF2)); this->unschedule(schedule_selector(HelloWorld::upGradeL2)); this->schedule(schedule_selector(HelloWorld::upGradeL3), 0.15f); damage = 3; count = 2; } else if (count == 2) { this->unschedule(schedule_selector(HelloWorld::upGradeP3)); this->unschedule(schedule_selector(HelloWorld::upGradeF3)); this->unschedule(schedule_selector(HelloWorld::upGradeL3)); this->unschedule(schedule_selector(HelloWorld::upGradeP4)); this->unschedule(schedule_selector(HelloWorld::upGradeF4)); this->schedule(schedule_selector(HelloWorld::upGradeL4), 0.15f); damage = 4; count = 2; score += 100; __String *tempScore = __String::createWithFormat("%i", score); scorelabel->setString(tempScore->getCString()); } } vItem.eraseObject(eitem); this->removeChild(eitem); return; } } }
bool TileButton::handleEvent( SDL_Event e, int &coordI, int &coordJ ) { bool temp = false; //If mouse event happened if( e.type == SDL_MOUSEMOTION || e.type == SDL_MOUSEBUTTONDOWN || e.type == SDL_MOUSEBUTTONUP ) { //Get mouse position int x, y; SDL_GetMouseState( &x, &y ); //Check if mouse is in button bool inside = true; //Mouse is left of the button if( x < getPositionX() ) { inside = false; } //Mouse is right of the button else if( x > getPositionX() + getWidth() ) { inside = false; } //Mouse above the button else if( y < getPositionY() ) { inside = false; } //Mouse below the button else if( y > getPositionY() + getHeight() ) { inside = false; } //Mouse is outside button if( !inside ) { Texture::setTexture(getTextureBase()); } //Mouse is inside button else { //Set mouse over sprite switch( e.type ) { case SDL_MOUSEMOTION: if(getBlocked()) { Texture::setTexture(getTextureMotion()); } break; case SDL_MOUSEBUTTONDOWN: if(getBlocked()) { Texture::setTexture(getTextureDown()); } break; case SDL_MOUSEBUTTONUP: if(getBlocked()) { Texture::setTexture(getTextureUp()); coordI = coordinates.i; coordJ = coordinates.j; temp = true; } break; } } } return temp; }
bool GamePlay::init() { if (!Layer::init()) { return false; } gameState = Ready; visibleSize = Director::getInstance()->getVisibleSize(); getSoundMusic(); //load game AI //init array number and computation int ARRAY_NUMBER[9] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; arrNum = gameAI->randomNumber(ARRAY_NUMBER, SUM_NUM); for (int i = 0; i < SUM_NUM; i++) { arrNUM[i] = arrNum[i]; } char s[SUM_COM] = ""; //TODO change level // arrCOM = gameAI->randomComputation(s, SUM_COM, // GamePlay::instance()->getLevel() >= 2 ? 2 : 3); arrCOM = gameAI->randomComputation(s, SUM_COM, 2); for (int i = 0; i < SUM_COM; i++) { arrCOMPUTATE[i] = arrCOM[i]; } for (int i = 0; i < SUM_COM / 2; i++) { tempResult[i] = INIT_FRAME; } int arr[GamePlay::instance()->getLevel()]; int* arrayLevel = gameAI->randomLessNumber(arr, GamePlay::instance()->getLevel()); //load background auto bg = Sprite::create("background.png"); bg->setAnchorPoint(Vec2(0, 0)); bg->setPosition(Vec2(0, 0)); this->addChild(bg, -1); float rX = visibleSize.width / bg->getContentSize().width; float rY = visibleSize.height / bg->getContentSize().height; bg->setScaleX(rX); bg->setScaleY(rY); //show logo game Sprite *logoGame = Sprite::create("smalllogo.png"); logoGame->setAnchorPoint(Vec2(0.0, 1.0)); logoGame->setPosition(Vec2(PADDING, visibleSize.height - PADDING)); logoGame->setTag(TAG_LOGO); logoGame->setScale(0.6f); this->addChild(logoGame); //load frame ready float baseY = logoGame->getPositionY() - logoGame->getBoundingBox().size.height - PADDING; float baseX = PADDING / 2; for (int i = 0; i < SUM_NUM; i++) { frameReady[i] = Sprite::create("frame.png"); float width = frameReady[i]->getContentSize().width; float height = frameReady[i]->getContentSize().height; frameReady[i]->setTag(TAG_START_READY_POINT + i); frameReady[i]->setPositionX(baseX + 5.0 / 8.0 * i * width + width / 2); if (i % 2 == 0) { frameReady[i]->setPositionY(baseY - height / 2); } else { frameReady[i]->setPositionY(baseY - height); } this->addChild(frameReady[i]); } //create frame play float paddingY = 0; float paddingX = 0; for (int i = 0; i < SUM_NUM; i++) { float baseX = PADDING; framePlay[i] = TouchSprite::create("frame.png"); framePlay[i]->setTag(TAG_FRAME_PLAY + i); paddingX = (visibleSize.width - PADDING * 4 - framePlay[i]->getContentSize().width) / 3.0; framePlay[i]->setPositionX( PADDING + framePlay[i]->getContentSize().width / 2 + paddingX * (i % 3)); float baseY = frameReady[0]->getPositionY(); if (i % 3 == 0) paddingY = paddingX * ((int) i / 3 + 1); framePlay[i]->setPositionY(baseY - paddingY); framePlay[i]->score = 0; framePlay[i]->isFixed = false; for (int j = 0; j < GamePlay::instance()->getLevel(); j++) { if (arrNum[i] == arrayLevel[j]) { framePlay[i]->score = arrNum[i]; //TODO framePlay[i]->isFixed = true; framePlay[i]->setDisplayFrame( SpriteFrame::create( "frame" + std::to_string(arrNum[i]) + ".png", framePlay[i]->getTextureRect())); } } // CCLog("frameplay[%d] = %d", i, framePlay[i]->score); this->addChild(framePlay[i]); } //load number button //TODO std::string name = "number"; MoveTo* actionBy; int k = 0; for (int i = 0; i < SUM_NUM; i++) { numberBtn[i] = TouchSprite::create( name + std::to_string(i + 1) + ".png"); numberBtn[i]->setTag(TAG_NUMBER + i); numberBtn[i]->setPositionY(visibleSize.height + 3 * PADDING); numberBtn[i]->setPositionX(frameReady[i]->getPositionX()); numberBtn[i]->setZOrder(10); numberBtn[i]->isHidden = false; this->addChild(numberBtn[i]); actionBy = MoveTo::create(0.4, frameReady[i]->getPosition()); auto easeAction = EaseBounceInOut::create(actionBy); for (int j = 0; j < GamePlay::instance()->getLevel(); j++) { if ((i + 1) == arrayLevel[j]) { numberBtn[i]->isHidden = true; numberBtn[i]->setVisible(false); } } if (numberBtn[i]->isHidden == false) { auto delay = DelayTime::create(0.2 * (k + 1)); auto sequence = Sequence::create(delay, easeAction, nullptr); numberBtn[i]->runAction(sequence); k++; } } if (frameReady != NULL) { for (int i = 0; i < SUM_NUM; i++) frameReady[i]->setVisible(false); } //create result frame and equal character Sprite* frameEqual[SUM_COM / 2]; Sprite* characterEqual[SUM_COM / 2]; for (int i = 0; i < SUM_COM / 2; i++) { characterEqual[i] = Sprite::create("icon_equal.png"); frameEqual[i] = Sprite::createWithTexture(frameReady[i]->getTexture()); frameEqual[i]->setTag(TAG_FRAME_EQUAL + i); if (i % 2 == 0) { //frame equal frameEqual[i]->setPositionY( framePlay[SUM_NUM - 1]->getPositionY() + paddingX * (2 - (int) i / 2)); frameEqual[i]->setPositionX( framePlay[SUM_NUM - 1]->getPositionX() + paddingX); //character equal characterEqual[i]->setPositionY( framePlay[SUM_NUM - 1]->getPositionY() + paddingX * ((int) i / 2)); characterEqual[i]->setPositionX( framePlay[SUM_NUM - 1]->getPositionX() + paddingX / 2); } else { //frame equal frameEqual[i]->setPositionY( framePlay[SUM_NUM - 1]->getPositionY() - paddingX); frameEqual[i]->setPositionX( framePlay[SUM_NUM - 1]->getPositionX() - paddingX * (2 - (int) i / 2)); //character equal characterEqual[i]->setPositionY( framePlay[SUM_NUM - 1]->getPositionY() - paddingX / 2); characterEqual[i]->setPositionX( framePlay[SUM_NUM - 1]->getPositionX() - paddingX * (2 - (int) i / 2)); } this->addChild(frameEqual[i]); this->addChild(characterEqual[i]); } //position of character computation Sprite* plusSprite = Sprite::create("icon_plus.png"); Sprite* minusSrite = Sprite::create("icon_minus.png"); Sprite* mutiplySprite = Sprite::create("icon_multiply.png"); Sprite* divideSprite = Sprite::create("icon_divide.png"); for (int i = 0; i < SUM_COM; i++) { if (arrCOM[i] == '+') comBtn[i] = Sprite::createWithTexture(plusSprite->getTexture()); else if (arrCOM[i] == '-') comBtn[i] = Sprite::createWithTexture(minusSrite->getTexture()); else if (arrCOM[i] == '*') comBtn[i] = Sprite::createWithTexture(mutiplySprite->getTexture()); else if (arrCOM[i] == '/') comBtn[i] = Sprite::createWithTexture(divideSprite->getTexture()); this->addChild(comBtn[i]); } setPosCharacterBtn(comBtn, framePlay, paddingX); //calculate result result[0] = gameAI->calculate(arrNum[0], arrNum[1], arrNum[2], arrCOM[0], arrCOM[1]); result[1] = gameAI->calculate(arrNum[0], arrNum[3], arrNum[6], arrCOM[2], arrCOM[7]); result[2] = gameAI->calculate(arrNum[3], arrNum[4], arrNum[5], arrCOM[5], arrCOM[6]); result[3] = gameAI->calculate(arrNum[1], arrNum[4], arrNum[7], arrCOM[3], arrCOM[8]); result[4] = gameAI->calculate(arrNum[6], arrNum[7], arrNum[8], arrCOM[10], arrCOM[11]); result[5] = gameAI->calculate(arrNum[2], arrNum[5], arrNum[8], arrCOM[4], arrCOM[9]); gameAI->printArray(result, SUM_COM / 2); //set result to frameEqual for (int i = 0; i < SUM_COM / 2; i++) { resultLabel[i] = LabelTTF::create("00:00", "fonts/hlvgchac.ttf", 48); resultLabel[i]->setColor(Color3B(Color3B::RED)); resultLabel[i]->setString(std::to_string(result[i])); resultLabel[i]->setPosition(frameEqual[i]->getPosition()); this->addChild(resultLabel[i]); } //button pause Sprite* pauseGame = Sprite::create("pauseBtn.png"); Sprite* pauseGame_press = Sprite::create("pauseBtn_press.png"); MenuItemSprite* pauseBtn = MenuItemSprite::create(pauseGame, pauseGame_press, NULL, CC_CALLBACK_0(GamePlay::gamePause, this)); Menu *menuPause = Menu::create(pauseBtn, nullptr); menuPause->setPosition( Vec2( visibleSize.width - PADDING - pauseBtn->getContentSize().width / 2, visibleSize.height - PADDING - pauseBtn->getContentSize().height / 2)); menuPause->setTag(TAG_PAUSE_BTN); this->addChild(menuPause); //time in pause button LabelTTF *currenttime = LabelTTF::create("00:00", "fonts/hlvgchac.ttf", 40); Point timePoint = menuPause->getPosition(); currenttime->setPosition( Vec2(timePoint.x - PADDING * 2, timePoint.y + 7.0 / 4.0 * PADDING)); currenttime->setZOrder(10); currenttime->setColor(Color3B(Color3B::RED)); currenttime->setTag(TAG_LABEL_COUNT_TIME); this->addChild(currenttime); std::string miniModeSprite = getLevelString( GamePlay::instance()->getLevel()); Sprite* miniMode = Sprite::create("mini" + miniModeSprite + ".png"); miniMode->setScale(0.5); miniMode->setPosition( Vec2(currenttime->getPositionX(), currenttime->getPositionY() - currenttime->getContentSize().height - PADDING / 2)); this->addChild(miniMode); //board menu pause boardMenuPause = Sprite::create("board.png"); boardMenuPause->setPosition( Vec2(visibleSize.width / 2, visibleSize.height + boardMenuPause->getContentSize().height / 2 + PADDING)); boardMenuPause->setZOrder(30); this->addChild(boardMenuPause); //button help of menu Sprite* helpbtn = Sprite::create("help1.png"); Sprite* helpbtn_press = Sprite::create("help2.png"); MenuItemSprite* helpBtn = MenuItemSprite::create(helpbtn, helpbtn_press, NULL, CC_CALLBACK_0(GamePlay::gameHelp, this)); Menu *menuHelp = Menu::create(helpBtn, nullptr); menuHelp->setPosition( Vec2(boardMenuPause->getContentSize().width / 2, boardMenuPause->getContentSize().height - helpbtn->getContentSize().height)); boardMenuPause->addChild(menuHelp); //button setting of menu Sprite* setbtn = Sprite::create("settings1.png"); Sprite* setbtn_press = Sprite::create("settings2.png"); MenuItemSprite* setBtn = MenuItemSprite::create(setbtn, setbtn_press, NULL, CC_CALLBACK_0(GamePlay::gameSetting, this)); Menu *menuSetting = Menu::create(setBtn, nullptr); menuSetting->setPosition( Vec2(boardMenuPause->getContentSize().width / 2, menuHelp->getPositionY() - setbtn->getContentSize().height - PADDING)); menuSetting->setTag(TAG_SETTING); boardMenuPause->addChild(menuSetting); //button quit of menu Sprite* quitbtn = Sprite::create("quit1.png"); Sprite* quitbtn_press = Sprite::create("quit2.png"); MenuItemSprite* quitBtn = MenuItemSprite::create(quitbtn, quitbtn_press, NULL, CC_CALLBACK_0(GamePlay::gameQuit, this)); Menu *menuQuit = Menu::create(quitBtn, nullptr); menuQuit->setPosition( Vec2(menuSetting->getPositionX(), menuSetting->getPositionY() - quitbtn->getContentSize().height - PADDING)); menuQuit->setTag(TAG_QUIT); boardMenuPause->addChild(menuQuit); //button replay, resume, share MenuItemImage* resumeBtn = MenuItemImage::create("menu_resume.png", "menu_resume.png", CC_CALLBACK_0(GamePlay::gameResume, this)); auto menuResume = Menu::create(resumeBtn, nullptr); menuResume->setPosition( Vec2(menuSetting->getPositionX(), menuQuit->getPositionY() - resumeBtn->getContentSize().height - PADDING)); boardMenuPause->addChild(menuResume); MenuItemImage* replayBtn = MenuItemImage::create("menu_replay.png", "menu_replay.png", CC_CALLBACK_0(GamePlay::gameReplay, this)); auto menuReplay = Menu::create(replayBtn, nullptr); menuReplay->setPosition( Vec2( menuResume->getPositionX() - resumeBtn->getContentSize().width - PADDING, menuResume->getPositionY())); boardMenuPause->addChild(menuReplay); MenuItemImage* shareBtn = MenuItemImage::create("menu_share.png", "menu_share.png", CC_CALLBACK_0(GamePlay::gameShareCloseMenuPause, this)); auto menuShare = Menu::create(shareBtn, nullptr); menuShare->setPosition( Vec2( menuResume->getPositionX() + resumeBtn->getContentSize().width + PADDING, menuResume->getPositionY())); boardMenuPause->addChild(menuShare); auto event_listener = EventListenerTouchOneByOne::create(); auto dispatcher = Director::getInstance()->getEventDispatcher(); event_listener->setSwallowTouches(true); event_listener->onTouchBegan = CC_CALLBACK_2(GamePlay::onTouchBegan, this); event_listener->onTouchMoved = CC_CALLBACK_2(GamePlay::onTouchMoved, this); event_listener->onTouchEnded = CC_CALLBACK_2(GamePlay::onTouchEnded, this); dispatcher->addEventListenerWithSceneGraphPriority(event_listener, this); this->setKeypadEnabled(true); this->scheduleUpdate(); // this->schedule(schedule_selector(GamePlay::update), 1.0f); gameState = Playing; return true; }
float GameNode::Y() const { return getPositionY(); }
void Lander::update(float dt) { if (_bLandOver || _bLandOK) { return; } if (!_bCtrlByHuman) { if (_tickCount == _vecActions.size()) { _actionFlag = NONE; } else { _actionFlag = _vecActions[_tickCount++]; } switch (_actionFlag) { case 0: break; case 1: rotateLeft(dt); break; case 2: rotateRight(dt); break; case 3: thrust(dt); break; default: break; } if (_actionFlag == 3) { _fire->setVisible(true); } else { _fire->setVisible(false); } } else { if (_actionFlag & ROT_LEFT) { rotateLeft(dt); } if (_actionFlag & ROT_RIGHT) { rotateRight(dt); } if (_actionFlag & THRUST) { thrust(dt); _fire->setVisible(true); } else { _fire->setVisible(false); } } // _velocity.y += GRAVITY * dt; _velocity.y += GRAVITY_PER_TICK; auto pos = getPosition() + _velocity; if (pos.x > CLIENT_WIDTH) { pos.x = 0; } if (pos.x < 0) { pos.x = CLIENT_WIDTH; } setPosition(pos); if (getPositionY() <= _targetPos.y) { _bLandOver = true; calcFitnessScore(); } }
bool GameOverLayer::init(bool win, int stage, int time, int kill, int loss, int newFlight) { if(!Layer::init()) { return false; } //init _stage = stage; std::string fontFile = "DS-Digital.ttf";//"arial.ttf"; int fontSize = 25; auto infoColor = DIY_COLOR_BLUE5; //swallow touches auto listener = EventListenerTouchOneByOne::create(); listener->setSwallowTouches(true); listener->onTouchBegan = [](Touch* touch, Event* event){ return true; }; _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); //panel Size panelSize; if(win) panelSize = Size(s_visibleRect.visibleWidth-60,s_visibleRect.visibleHeight-280); else panelSize = Size(s_visibleRect.visibleWidth-60,s_visibleRect.visibleHeight-450); auto _panel = Scale9Sprite::create("windowBox.png"); _panel->setAnchorPoint(Point::ANCHOR_MIDDLE_TOP); _panel->setPosition(Point(s_visibleRect.center.x,s_visibleRect.top.y + panelSize.height)); _panel->setContentSize(panelSize); this->addChild(_panel); _panel->runAction(MoveTo::create(0.15f,s_visibleRect.top-Point(0,80))); //title TextSprite* title; if(win) { title = TextSprite::create(s_gameStrings.battleInfo->gameovertitle_win.c_str(),s_gameConfig.defaultFontName,32); title->setColor(Color3B::YELLOW); } else { title = TextSprite::create(s_gameStrings.battleInfo->gameovertitle_loss.c_str(),s_gameConfig.defaultFontName,32); title->setColor(Color3B::RED); } title->setAnchorPoint(Point::ANCHOR_MIDDLE); title->setPosition(Point(panelSize.width/2,panelSize.height-90)); _panel->addChild(title,1); //info auto time_label = TextSprite::create(s_gameStrings.battleInfo->gameovertime, "Arial", fontSize); time_label->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT); time_label->setPosition(Point(150,panelSize.height-150)); _panel->addChild(time_label); time = time > 36000?3599:(time/10); int min = time/60; int sec = time - min*60; char p[10]; sprintf(p,"%02d\'%02d\"",min,sec); auto time_content = TextSprite::create(p,fontFile, fontSize); time_content->setColor(infoColor); time_content->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT); time_content->setPosition(Point(320,panelSize.height-150)); _panel->addChild(time_content); auto kill_label = TextSprite::create(s_gameStrings.battleInfo->gameoverkill, "Arial", fontSize); kill_label->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT); kill_label->setPosition(Point(150,panelSize.height-200)); _panel->addChild(kill_label); auto kill_content = TextSprite::create(Value(kill).asString(),fontFile, fontSize); kill_content->setColor(infoColor); kill_content->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT); kill_content->setPosition(Point(320,panelSize.height-200)); _panel->addChild(kill_content); auto loss_label = TextSprite::create(s_gameStrings.battleInfo->gameoverloss, "Arial", fontSize); loss_label->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT); loss_label->setPosition(Point(150,panelSize.height-250)); _panel->addChild(loss_label); auto loss_content = TextSprite::create(Value(loss).asString(), fontFile, fontSize); loss_content->setColor(infoColor); loss_content->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT); loss_content->setPosition(Point(320,panelSize.height-250)); _panel->addChild(loss_content); //rewards if (win) { //init rewards int _gem = s_stageRewards[_stage][0]; int _starboom = s_stageRewards[_stage][1]; int _laser = s_stageRewards[_stage][2]; int _blackhole = s_stageRewards[_stage][3]; auto rewards_label = TextSprite::create(s_gameStrings.battleInfo->gameoverreward, "Arial", fontSize); rewards_label->setColor(Color3B::GRAY); rewards_label->setAnchorPoint(Point::ANCHOR_MIDDLE); rewards_label->setPosition(Point(panelSize.width/2,panelSize.height-300)); _panel->addChild(rewards_label); if(_starboom == 0 && _laser == 0 && _blackhole == 0) { auto icon = Sprite::createWithSpriteFrameName("icon_gem.png"); icon->setPosition(panelSize.width/2-50, panelSize.height/2-10); _panel->addChild(icon); auto label = Label::createWithTTF(Value(_gem).asString().c_str(), s_gameConfig.defaultFontName, fontSize); label->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT); label->setPosition(Point(icon->getPositionX()+icon->getContentSize().width, icon->getPositionY())); label->setColor(Color3B::YELLOW); _panel->addChild(label); } else { auto icon1 = Sprite::createWithSpriteFrameName("icon_gem.png"); icon1->setPosition(panelSize.width/2-130, panelSize.height/2-10); _panel->addChild(icon1); auto label1 = Label::createWithTTF(Value(_gem).asString().c_str(), s_gameConfig.defaultFontName, fontSize); label1->setPosition(icon1->getPositionX()+icon1->getContentSize().width+20, icon1->getPositionY()); label1->setColor(Color3B::YELLOW); _panel->addChild(label1); if (_starboom > 0) { auto icon2 = Sprite::createWithSpriteFrameName("bomb_1_1.png"); icon2->setScale(0.5f);icon2->setRotation(90); icon2->setPosition(panelSize.width/2+50, panelSize.height/2-10); _panel->addChild(icon2); std::string str = "x" + Value(_starboom).asString(); auto label2 = Label::createWithTTF(str.c_str(), s_gameConfig.defaultFontName, fontSize); label2->setPosition(icon2->getPositionX()+icon2->getContentSize().width, icon2->getPositionY()); label2->setColor(infoColor); _panel->addChild(label2); } else if (_laser > 0) { auto icon2 = Sprite::createWithSpriteFrameName("bomb_2_1.png"); icon2->setScale(0.8f);icon2->setRotation(90); icon2->setPosition(panelSize.width/2+50, panelSize.height/2-10); _panel->addChild(icon2); std::string str = "x" + Value(_laser).asString(); auto label2 = Label::createWithTTF(str.c_str(), s_gameConfig.defaultFontName, fontSize); label2->setPosition(icon2->getPositionX()+icon2->getContentSize().width, icon2->getPositionY()); label2->setColor(infoColor); _panel->addChild(label2); } else if (_blackhole > 0) { auto icon2 = Sprite::createWithSpriteFrameName("bomb_3_1.png"); icon2->setScale(0.6f); icon2->setPosition(panelSize.width/2+50, panelSize.height/2); _panel->addChild(icon2); std::string str = "x" + Value(_blackhole).asString(); auto label2 = Label::createWithTTF(str.c_str(), s_gameConfig.defaultFontName, fontSize); label2->setPosition(icon2->getPositionX()+icon2->getContentSize().width, icon2->getPositionY()); label2->setColor(infoColor); _panel->addChild(label2); } } if(newFlight) { auto newflight_label = TextSprite::create(s_gameStrings.battleInfo->gameovernewflight, "Arial", fontSize); newflight_label->setColor(Color3B::GRAY); newflight_label->setAnchorPoint(Point::ANCHOR_MIDDLE); newflight_label->setPosition(Point(panelSize.width/2,panelSize.height-400)); _panel->addChild(newflight_label); char name[30]; sprintf(name,"plain_%d_lv_%d.png",newFlight,1); auto newflight = Sprite::createWithSpriteFrameName(name); newflight->setScale(1.3f); newflight->setAnchorPoint(Point::ANCHOR_MIDDLE); newflight->setPosition(Point(panelSize.width/2,panelSize.height-480)); _panel->addChild(newflight); auto newicon = Sprite::createWithSpriteFrameName("icon_new.png"); newicon->setAnchorPoint(Point::ANCHOR_MIDDLE); newicon->setPosition(newflight->getPosition()+Point(0,-60)); _panel->addChild(newicon); } } if(newFlight) { auto gotosee_menu = MenuItemImageLabel::createWithFrameName("bt_main_0.png", "bt_main_1.png", CC_CALLBACK_1(GameOverLayer::returnBase_callback, this), s_gameStrings.battleInfo->gotosee); gotosee_menu->setAnchorPoint(Point::ANCHOR_MIDDLE); gotosee_menu->setPosition(Point(panelSize.width/2, 60)); auto menu = Menu::create(gotosee_menu, nullptr); menu->setPosition(Point::ZERO); _panel->addChild(menu); return true; } //menu auto returnBase_menu = MenuItemImageLabel::createWithFrameName("bt_main_0.png", "bt_main_1.png", CC_CALLBACK_1(GameOverLayer::returnBase_callback, this), s_gameStrings.battleInfo->returnbase); returnBase_menu->setAnchorPoint(Point::ANCHOR_MIDDLE); returnBase_menu->setPosition(Point(panelSize.width/2, 150)); if (win && s_playerConfig.overstage<50) { auto nextStage_menu = MenuItemImageLabel::createWithFrameName("bt_main_0.png", "bt_main_1.png", CC_CALLBACK_1(GameOverLayer::nextStage_callback, this), s_gameStrings.battleInfo->nextstage); nextStage_menu->setAnchorPoint(Point::ANCHOR_MIDDLE); nextStage_menu->setPosition(Point(panelSize.width/2, 70)); nextStage_menu->setColor(DIY_COLOR_BLUE5); auto menu = Menu::create(returnBase_menu, nextStage_menu, nullptr); menu->setPosition(Point::ZERO); _panel->addChild(menu); } else{ auto restartStage_menu = MenuItemImageLabel::createWithFrameName("bt_main_0.png", "bt_main_1.png", CC_CALLBACK_1(GameOverLayer::restartStage_callback, this), s_gameStrings.battleInfo->restartstage); restartStage_menu->setAnchorPoint(Point::ANCHOR_MIDDLE); restartStage_menu->setPosition(Point(panelSize.width/2, 70)); auto menu = Menu::create(returnBase_menu, restartStage_menu, nullptr); menu->setPosition(Point::ZERO); _panel->addChild(menu); } //this->scheduleOnce(schedule_selector(GameOverLayer::pausegame), 0.5f); return true; }
void SimulatorWin::setupUI() { auto menuBar = player::PlayerProtocol::getInstance()->getMenuService(); // FILE menuBar->addItem("FILE_MENU", tr("File")); menuBar->addItem("EXIT_MENU", tr("Exit"), "FILE_MENU"); // VIEW menuBar->addItem("VIEW_MENU", tr("View")); SimulatorConfig *config = SimulatorConfig::getInstance(); int current = config->checkScreenSize(_project.getFrameSize()); for (int i = 0; i < config->getScreenSizeCount(); i++) { SimulatorScreenSize size = config->getScreenSize(i); std::stringstream menuId; menuId << "VIEWSIZE_ITEM_MENU_" << i; auto menuItem = menuBar->addItem(menuId.str(), size.title.c_str(), "VIEW_MENU"); if (i == current) { menuItem->setChecked(true); } } menuBar->addItem("DIRECTION_MENU_SEP", "-", "VIEW_MENU"); menuBar->addItem("DIRECTION_PORTRAIT_MENU", tr("Portrait"), "VIEW_MENU") ->setChecked(_project.isPortraitFrame()); menuBar->addItem("DIRECTION_LANDSCAPE_MENU", tr("Landscape"), "VIEW_MENU") ->setChecked(_project.isLandscapeFrame()); menuBar->addItem("VIEW_SCALE_MENU_SEP", "-", "VIEW_MENU"); std::vector<player::PlayerMenuItem*> scaleMenuVector; auto scale100Menu = menuBar->addItem("VIEW_SCALE_MENU_100", tr("Zoom Out").append(" (100%)"), "VIEW_MENU"); auto scale75Menu = menuBar->addItem("VIEW_SCALE_MENU_75", tr("Zoom Out").append(" (75%)"), "VIEW_MENU"); auto scale50Menu = menuBar->addItem("VIEW_SCALE_MENU_50", tr("Zoom Out").append(" (50%)"), "VIEW_MENU"); auto scale25Menu = menuBar->addItem("VIEW_SCALE_MENU_25", tr("Zoom Out").append(" (25%)"), "VIEW_MENU"); int frameScale = int(_project.getFrameScale() * 100); if (frameScale == 100) { scale100Menu->setChecked(true); } else if (frameScale == 75) { scale75Menu->setChecked(true); } else if (frameScale == 50) { scale50Menu->setChecked(true); } else if (frameScale == 25) { scale25Menu->setChecked(true); } else { scale100Menu->setChecked(true); } scaleMenuVector.push_back(scale100Menu); scaleMenuVector.push_back(scale75Menu); scaleMenuVector.push_back(scale50Menu); scaleMenuVector.push_back(scale25Menu); menuBar->addItem("REFRESH_MENU_SEP", "-", "VIEW_MENU"); menuBar->addItem("REFRESH_MENU", tr("Refresh"), "VIEW_MENU"); HWND &hwnd = _hwnd; ProjectConfig &project = _project; auto dispatcher = Director::getInstance()->getEventDispatcher(); dispatcher->addEventListenerWithFixedPriority(EventListenerCustom::create("APP.EVENT", [&project, &hwnd, scaleMenuVector](EventCustom* event){ auto menuEvent = dynamic_cast<AppEvent*>(event); if (menuEvent) { rapidjson::Document dArgParse; dArgParse.Parse<0>(menuEvent->getDataString().c_str()); if (dArgParse.HasMember("name")) { string strcmd = dArgParse["name"].GetString(); if (strcmd == "menuClicked") { player::PlayerMenuItem *menuItem = static_cast<player::PlayerMenuItem*>(menuEvent->getUserData()); if (menuItem) { if (menuItem->isChecked()) { return; } string data = dArgParse["data"].GetString(); auto player = player::PlayerProtocol::getInstance(); if ((data == "CLOSE_MENU") || (data == "EXIT_MENU")) { player->quit(); } else if (data == "REFRESH_MENU") { player->relaunch(); } else if (data.find("VIEW_SCALE_MENU_") == 0) // begin with VIEW_SCALE_MENU_ { string tmp = data.erase(0, strlen("VIEW_SCALE_MENU_")); float scale = atof(tmp.c_str()) / 100.0f; project.setFrameScale(scale); auto glview = static_cast<GLViewImpl*>(Director::getInstance()->getOpenGLView()); glview->setFrameZoomFactor(scale); // update scale menu state for (auto &it : scaleMenuVector) { it->setChecked(false); } menuItem->setChecked(true); // update window size RECT rect; GetWindowRect(hwnd, &rect); MoveWindow(hwnd, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top + GetSystemMetrics(SM_CYMENU), FALSE); // fix: can not update window on some windows system ::SendMessage(hwnd, WM_MOVE, NULL, NULL); } else if (data.find("VIEWSIZE_ITEM_MENU_") == 0) // begin with VIEWSIZE_ITEM_MENU_ { string tmp = data.erase(0, strlen("VIEWSIZE_ITEM_MENU_")); int index = atoi(tmp.c_str()); SimulatorScreenSize size = SimulatorConfig::getInstance()->getScreenSize(index); if (project.isLandscapeFrame()) { std::swap(size.width, size.height); } project.setFrameSize(cocos2d::Size(size.width, size.height)); project.setWindowOffset(cocos2d::Vec2(player->getPositionX(), player->getPositionY())); player->openProjectWithProjectConfig(project); } else if (data == "DIRECTION_PORTRAIT_MENU") { project.changeFrameOrientationToPortait(); player->openProjectWithProjectConfig(project); } else if (data == "DIRECTION_LANDSCAPE_MENU") { project.changeFrameOrientationToLandscape(); player->openProjectWithProjectConfig(project); } } } } } }), 1); AppDelegate *app = _app; auto listener = EventListenerCustom::create(kAppEventDropName, [&project, app](EventCustom* event) { AppEvent *dropEvent = dynamic_cast<AppEvent*>(event); if (dropEvent) { string dirPath = dropEvent->getDataString() + "/"; string configFilePath = dirPath + CONFIG_FILE; if (FileUtils::getInstance()->isDirectoryExist(dirPath) && FileUtils::getInstance()->isFileExist(configFilePath)) { // parse config.json ConfigParser::getInstance()->readConfig(configFilePath); project.setProjectDir(dirPath); project.setScriptFile(ConfigParser::getInstance()->getEntryFile()); project.setWritablePath(dirPath); app->setProjectConfig(project); app->reopenProject(); } } }); dispatcher->addEventListenerWithFixedPriority(listener, 1); }
bool EnemyActor::checkIfAtPosition(sf::Vector2i pos_checker) { if ((int) getPositionX() == seek.x && (int) getPositionY() == seek.y) return true; else return false; }
// on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !Layer::init() ) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program // you may modify it. //auto btn = Sprite::create("btn1.jpg"); //btn->setPosition(Point(btn->getContentSize().height + origin.y + 30, btn->getContentSize().height + origin.y)); //this->addChild(btn, 2); auto lname = Label::create("*Nombre","Verdana", 20); lname->setColor(Color3B(108,169,121)); lname->setPosition(Point(lname->getContentSize().width/ 2 + origin.y + 10, visibleSize.height / 2 + origin.y + 30)); this->addChild(lname,2); auto lapellido = Label::create("*Apellido", "Verdana", 20); lapellido->setColor(Color3B(108,169,121)); lapellido->setPosition(Point(lname->getContentSize().width / 2 + origin.y + 10, lname->getPositionY() - (lname->getContentSize().height + 40))); this->addChild(lapellido,2); name = TextField::create(" ___________|", "Verdana", 30); name->setColor(Color3B::BLACK); name->setPosition(Point(name->getContentSize().width + 10, lname->getPositionY())); name->setMaxLengthEnabled(true); name->setMaxLength(10); this->addChild(name,2); apell = TextField::create(" ___________|", "Verdana", 30); apell->setColor(Color3B::BLACK); apell->setPosition(Point(name->getContentSize().width + 10, lapellido->getPositionY())); apell->setMaxLengthEnabled(true); apell->setMaxLength(10); this->addChild(apell,2); // add a "close" icon to exit the progress. it's an autorelease object auto btn = MenuItemImage::create( "btn1.jpg", "btn2.jpg", CC_CALLBACK_1(HelloWorld::Registro, this)); btn->setPosition(Vec2(btn->getContentSize().height + origin.y + 30, btn->getContentSize().height + origin.y)); // create menu, it's an autorelease object auto menu = Menu::create(btn, NULL); menu->setPosition(Vec2::ZERO); this->addChild(menu, 1); ///////////////////////////// // 3. add your codes below... // add a label shows "Hello World" // create and initialize a label auto closeItem = MenuItemImage::create( "x.png", "x.png", CC_CALLBACK_1(HelloWorld::Close, this)); closeItem->setPosition(Point(origin.x + visibleSize.width - closeItem->getContentSize().width/2 , origin.y + closeItem->getContentSize().height/2)); // create menu, it's an autorelease object auto menu2 = Menu::create(closeItem, NULL); menu2->setPosition(Point::ZERO); this->addChild(menu2, 2); // add "HelloWorld" splash screen" auto sprite = Sprite::create("capa.jpg"); // position the sprite on the center of the screen sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); // add the sprite as a child to this layer this->addChild(sprite, 0); return true; }
void SportsLayer::loadNet(){ mark=0; float width=525; float hight=450; this->setContentSize(Size(width,hight)); auto scal8=Scale9Sprite::create("ui_zhuye_daojukuang.png"); scal8->setContentSize(Size(width,hight)); scal8->setPosition(Vec2(getContentSize().width/2,getContentSize().height/2)); addChild(scal8,100); jt1=Sprite::create("ui_zhuye_guanqiamoshi_guanqia_anniu_fanye.png"); jt1->setPosition(Vec2(scal8->getPositionX()-scal8->getContentSize().width/2+jt1->getContentSize().width/2,scal8->getPositionY())); jt1->setRotationSkewY(180.0f); jt1->setVisible(false); scal8->addChild(jt1,100); jt2=Sprite::create("ui_zhuye_guanqiamoshi_guanqia_anniu_fanye.png"); jt2->setPosition(Vec2(scal8->getPositionX()+scal8->getContentSize().width/2-jt1->getContentSize().width/2,scal8->getPositionY()));; jt2->setVisible(true); scal8->addChild(jt2,100); scroll_layer = Layer::create();//创建scrollView中的容器层 scroll_layer->setPosition(Vec2(0,0)); scroll_layer->setAnchorPoint(Vec2(0.0f,0.0f)); scroll_layer->setContentSize(Size(width*2,hight));//设置容器层大小为(600,300) scrollView = ScrollView::create(Size(width,hight),scroll_layer);//创建scrollView,显示窗口大小为(400,300) scrollView->setDelegate(this);//设置委托 scrollView->setContentOffset(Vec2::ZERO);//充当了锚点的作用 scrollView->setTouchEnabled(false); scrollView->setDirection(ScrollView::Direction::HORIZONTAL);//设置滚动方向为水平 scrollView->ignoreAnchorPointForPosition(false); scrollView->setAnchorPoint(Vec2(0.5,0.5)); scrollView->setPosition(scal8->getPosition()); scal8->addChild(scrollView,20); auto biti2=Sprite::create(Biti_imgstr2); biti2->setPosition(Vec2(scal8->getContentSize().width/2,0)); scal8->addChild(biti2,1025); b_label=Label::createWithSystemFont(FX::StringsMap::getValue("wdfzsm"),"Arial",24); b_label->setPosition(Vec2(biti2->getContentSize().width/2,biti2->getContentSize().height/2)); b_label->setColor(Color3B(0,0,0)); biti2->addChild(b_label); auto jj_bg=Sprite::create(Biti_imgstr); jj_bg->setPosition(Vec2(width/2,hight)); addChild(jj_bg,1025); auto jjgz=Label::createWithSystemFont(FX::StringsMap::getValue("jinjiguizhe"),"Arial",30); jjgz->setColor(Color3B(0,0,0)); jjgz->setPosition(Vec2(jj_bg->getContentSize().width/2,jj_bg->getContentSize().height/2)); jj_bg->addChild(jjgz,100); for(int i=0;i<2;i++){ if(i==0){ drowFisrt(scroll_layer,Vec2(width*i+width/2,hight/2)); }else{ drowSecond(scroll_layer,Vec2(width*i+width/2,hight/2)); } } }
void SportsLayer::loadbasic(){ float width=Actual_x*0.8f; float hight=Actual_y*0.8f; Color4B color =Color4B(0,0,0,100); LayerColor *colorLayer1 = LayerColor::create(color); colorLayer1->setContentSize(Size(Actual_x,Actual_y)); addChild(colorLayer1,1); this->setContentSize(colorLayer1->getContentSize()); auto scal8=Scale9Sprite::create("ui_zhuye_daojukuang.png"); scal8->setContentSize(Size(width,hight)); scal8->setPosition(Vec2(getContentSize().width/2,getContentSize().height/2)); colorLayer1->addChild(scal8); jt1=Sprite::create("ui_zhuye_guanqiamoshi_guanqia_anniu_fanye.png"); jt1->setPosition(Vec2(scal8->getPositionX()-scal8->getContentSize().width/2+jt1->getContentSize().width/2,scal8->getPositionY())); jt1->setRotationSkewY(180.0f); jt1->setVisible(false); colorLayer1->addChild(jt1,100); jt2=Sprite::create("ui_zhuye_guanqiamoshi_guanqia_anniu_fanye.png"); jt2->setPosition(Vec2(scal8->getPositionX()+scal8->getContentSize().width/2-jt1->getContentSize().width/2,scal8->getPositionY())); //jt2->setFlippedY(180); jt2->setVisible(true); colorLayer1->addChild(jt2,100); scroll_layer = Layer::create();//创建scrollView中的容器层 scroll_layer->setPosition(Vec2(0,0)); scroll_layer->setAnchorPoint(Vec2(0.0f,0.0f)); scroll_layer->setContentSize(Size(width*2,hight));//设置容器层大小为(600,300) scrollView = ScrollView::create(Size(width,hight),scroll_layer);//创建scrollView,显示窗口大小为(400,300) scrollView->setDelegate(this);//设置委托 scrollView->setContentOffset(Vec2::ZERO);//充当了锚点的作用 scrollView->setTouchEnabled(false); scrollView->setDirection(ScrollView::Direction::HORIZONTAL);//设置滚动方向为水平 scrollView->ignoreAnchorPointForPosition(false); scrollView->setAnchorPoint(Vec2(0.5,0.5)); scrollView->setPosition(scal8->getPosition()); colorLayer1->addChild(scrollView,20); /* text_ts=Label::createWithSystemFont(FX::StringsMap::getValue("shujujiazz"),"Arial",30); text_ts->setColor(Color3B(0,0,0)); text_ts->setPosition(Vec2(getContentSize().width/2,getContentSize().height/2)); colorLayer1->addChild(text_ts,1000); */ auto close=MenuItemImage::create("ui_shangcheng_guanbi.png","ui_shangcheng_guanbi.png",CC_CALLBACK_1(SportsLayer::returnPa,this)); close->setPosition(Vec2(scal8->getPositionX()+scal8->getContentSize().width/2-close->getContentSize().width/2, scal8->getPositionY()+scal8->getContentSize().height/2-close->getContentSize().height/2)); auto menu = Menu::create(close,nullptr); menu->setPosition(Vec2::ZERO); colorLayer1->addChild(menu); for(int i=0;i<2;i++){ if(i==0){ drowSecond(scroll_layer,Vec2(width*i+width/2,hight/2)); }else{ drowFisrt(scroll_layer,Vec2(width*i+width/2,hight/2)); } } }
void Bullet::update(float dt){ float speedX = speed * cos(radian); float speedY = speed * sin(radian); setPosition(getPositionX()+speedX, getPositionY()+speedY); }
void Mogh::checkKeybindings(gen::GameEngine* ge){ std::string anim = ""; SDL_Event eve = ge->getEvents(); if(damaged) anim = "DAMAGED"; else if (eve.key.keysym.sym == SDLK_LEFT) anim = "LEFT"; else if (eve.key.keysym.sym == SDLK_RIGHT) anim = "RIGHT"; else if(eve.key.keysym.sym == SDLK_UP) anim = "BACK"; else if(eve.key.keysym.sym == SDLK_DOWN) anim = "FRONT"; if(anim != ""){ if( getKeyOfCurrentAnimationVector() != anim ){ setCurrentAnimationVector(anim); } Hero::checkKeybindings(ge); } else if(eve.key.keysym.sym == SDLK_SPACE){ if(SDL_GetTicks() > getTimer()){ anim = getKeyOfCurrentAnimationVector(); setCurrentAnimationVector(anim); if (anim != "DAMAGED"){ WaterBullet* p = WaterBullet::createWaterBullet(dynamic_cast<WaterBullet*> (ge->getActiveWorld()->retrieveStoredProjectile("WaterBullet"))); p->setCurrentAnimationVector(anim); int x = 0; int y = 0; int velocity = p->getVelocityX(); // no need to get Y because Mogh is not generic, I know that Xs velocity is the same as Y in this case p->setVelocityX(0); p->setVelocityY(0); if(anim == "LEFT"){ x = getPositionX(); y = getPositionY() + (getHeight() / 2); p->setVelocityX(-velocity); } else if(anim == "RIGHT"){ x = getPositionX() + getWidth(); y = getPositionY() + (getHeight() / 2); p->setVelocityX(velocity); } else if(anim == "FRONT"){ x = getPositionX() + (getWidth()/2); y = getPositionY() + getHeight(); p->setVelocityY(velocity); } else if(anim == "BACK"){ x = getPositionX() + (getWidth()/2); y = getPositionY(); p->setVelocityY(-velocity); } ge->getActiveWorld()->addProjectile(p, x, y); setTimer(SDL_GetTicks() + 500); } } } }
void HelloWorld::intersectEnemy() { //플레이어와 적이 충돌 auto sPlayer = (Sprite*)this->getChildByTag(TAG_SPRITE_PLAYER); Rect rPlayer = Rect(sPlayer->getPositionX() - 10, sPlayer->getPositionY() - 20, 20, 40); //주인공의 충돌박스 설정 for (Sprite* enemy : vEnemy) { Rect renemy = enemy->getBoundingBox(); //적 충돌박스 if (rPlayer.intersectsRect(renemy)) { SimpleAudioEngine::getInstance()->playEffect("explosion.wav"); auto particle = ParticleSystemQuad::create("explosion.plist"); particle->setPosition(enemy->getPosition()); this->addChild(particle); particle->runAction(Sequence::create( DelayTime::create(2.0f), RemoveSelf::create(), NULL)); vEMissile.eraseObject(enemy); //적의 미사일을 지운다. this->removeChild(enemy); resetPlayer(); //플레이어가 죽을때 호출 return; } } for (Sprite* enemy2 : vEnemy2) { Rect renemy = enemy2->getBoundingBox(); //적 충돌박스 if (rPlayer.intersectsRect(renemy)) { SimpleAudioEngine::getInstance()->playEffect("explosion.wav"); auto particle = ParticleSystemQuad::create("explosion.plist"); particle->setPosition(enemy2->getPosition()); this->addChild(particle); particle->runAction(Sequence::create( DelayTime::create(2.0f), RemoveSelf::create(), NULL)); vEMissile.eraseObject(enemy2); //적의 미사일을 지운다. this->removeChild(enemy2); resetPlayer(); //플레이어가 죽을때 호출 return; } } for (Sprite* enemy3 : vMidBoss) { Rect renemy = enemy3->getBoundingBox(); //적 충돌박스 if (rPlayer.intersectsRect(renemy)) { SimpleAudioEngine::getInstance()->playEffect("explosion.wav"); auto particle = ParticleSystemQuad::create("explosion.plist"); particle->setPosition(enemy3->getPosition()); this->addChild(particle); particle->runAction(Sequence::create( DelayTime::create(2.0f), RemoveSelf::create(), NULL)); vEMissile.eraseObject(enemy3); //적의 미사일을 지운다. this->removeChild(enemy3); resetPlayer(); //플레이어가 죽을때 호출 return; } } for (Sprite* enemy4 : vBoss) { Rect renemy = enemy4->getBoundingBox(); //적 충돌박스 if (rPlayer.intersectsRect(renemy)) { SimpleAudioEngine::getInstance()->playEffect("explosion.wav"); auto particle = ParticleSystemQuad::create("explosion.plist"); particle->setPosition(enemy4->getPosition()); this->addChild(particle); particle->runAction(Sequence::create( DelayTime::create(2.0f), RemoveSelf::create(), NULL)); vEMissile.eraseObject(enemy4); //적의 미사일을 지운다. this->removeChild(enemy4); resetPlayer(); //플레이어가 죽을때 호출 return; } } }
void Body::setPositionX(float x) { setPosition(x, getPositionY()); }
bool GameMenu::init() { if (!Layer::init()) { return false; } //加载音效 Tools::preloadMusic(); if (DataModel::isMusic) { if (!CocosDenshion::SimpleAudioEngine::getInstance()->isBackgroundMusicPlaying()) { CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic("music_menu.mp3",true); } } auto winSize = Director::getInstance()->getWinSize(); auto pSprite = Sprite::create("menu_bg.png"); pSprite->setPosition(Vec2(winSize.width/2,winSize.height/2)); this->addChild(pSprite); //主菜单 //--普通模式 auto newgameNormal = Sprite::create("menu_newgame.png"); auto newgamePressed = Sprite::create("menu_newgame.png"); newgamePressed->setScale(1.2f); auto pNewGameItem = MenuItemSprite::create( newgameNormal, newgamePressed, nullptr, CC_CALLBACK_1(GameMenu::menuNewGame,this)); pNewGameItem->setPosition(Vec2(winSize.width-250,winSize.height/2)); pNewGameItem->setAnchorPoint(Vec2::ANCHOR_MIDDLE_LEFT); //--专家模式 auto expertNormal = Sprite::create("menu_expert.png"); auto expertPressed = Sprite::create("menu_expert.png"); expertPressed->setScale(1.2f); auto pExpertItem = MenuItemSprite::create( expertNormal, expertPressed, nullptr, CC_CALLBACK_1(GameMenu::menuExpertGame,this)); pExpertItem->setPosition(Vec2(winSize.width-250,winSize.height/2 - 75)); pExpertItem->setAnchorPoint(Vec2::ANCHOR_MIDDLE_LEFT); //--商店 auto pStoreNormal = Sprite::create("menu_store.png"); auto pStorePressed = Sprite::create("menu_store.png"); pStorePressed->setScale(1.2f); auto pStoreItem = MenuItemSprite::create( pStoreNormal, pStorePressed, nullptr, CC_CALLBACK_1(GameMenu::menuStore,this)); pStoreItem->setPosition(Vec2(winSize.width-250,winSize.height/2 -75*2)); pStoreItem->setAnchorPoint(Vec2::ANCHOR_MIDDLE_LEFT); //--其他 auto pOtherNormal = Sprite::create("menu_setting.png"); auto pOtherPressed = Sprite::create("menu_setting.png"); pOtherPressed->setScale(1.2f); auto pOtherItem = MenuItemSprite::create( pOtherNormal, pOtherPressed, nullptr, CC_CALLBACK_1(GameMenu::menuSystem,this)); pOtherItem->setPosition(Vec2(80,winSize.height-10)); pOtherItem->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT); pMenu = Menu::create(pNewGameItem,pExpertItem,pStoreItem,pOtherItem,nullptr); pMenu->setPosition(Vec2::ZERO); this->addChild(pMenu,1); //--系统 systemBg = Sprite::create("system_bg.png"); systemBg->setPosition(Vec2( pOtherItem->getPositionX()-pOtherItem->getContentSize().width/2, pOtherItem->getPositionY()-pOtherItem->getContentSize().height)); systemBg->setAnchorPoint(Vec2::ANCHOR_MIDDLE_TOP); this->addChild(systemBg); //先隐藏起来 isShowSystem = false; systemBg->setScale(0); //--声音选项 auto soundOff = Sprite::create("sound.png"); auto ban = Sprite::create("ban.png"); ban->setPosition(Vec2(soundOff->getContentSize().width/2,soundOff->getContentSize().height/2)); soundOff->addChild(ban); auto pSubSoundOffItem = MenuItemSprite::create(soundOff,nullptr); auto pSubSoundOpenItem = MenuItemSprite::create(Sprite::create("sound.png"),nullptr); auto pSoundItem = MenuItemToggle::createWithCallback(CC_CALLBACK_0(GameMenu::menuSetSound,this),pSubSoundOffItem,pSubSoundOpenItem,nullptr); pSoundItem->setSelectedIndex(DataModel::isSound); //--音乐开关子选项 auto musicOff = Sprite::create("music.png"); auto musicban = Sprite::create("ban.png"); musicban->setPosition(Vec2(musicOff->getContentSize().width/2,musicOff->getContentSize().height/2)); musicOff->addChild(musicban); auto pSubMusicOffItem = MenuItemSprite::create(musicOff,nullptr); auto pSubMusicOpenItem = MenuItemSprite::create(Sprite::create("music.png"),nullptr); auto pMusicItem = MenuItemToggle::createWithCallback(CC_CALLBACK_0(GameMenu::menuSetMusic,this),pSubMusicOffItem,pSubMusicOpenItem,nullptr); pMusicItem->setSelectedIndex(DataModel::isMusic); //--帮助 auto helpNormalSprite = Sprite::create("menu_help.png"); auto helpPressedSprite = Sprite::create("menu_help.png"); helpPressedSprite->setScale(1.2f); auto pHelpItem = MenuItemSprite::create(helpNormalSprite,helpPressedSprite,CC_CALLBACK_0(GameMenu::menuHelp,this)); //--关于 auto aboutNormal = Sprite::create("menu_about.png"); auto aboutPressed = Sprite::create("menu_about.png"); aboutPressed->setScale(1.2f); auto pAboutItem = MenuItemSprite::create(aboutNormal,aboutPressed,CC_CALLBACK_0(GameMenu::menuAbout,this)); auto pSettingMenu = Menu::create(pSoundItem,pMusicItem,pHelpItem,pAboutItem,nullptr); //排列菜单项 pSettingMenu->alignItemsVerticallyWithPadding(10); pSettingMenu->setPosition(Vec2( systemBg->getContentSize().width/2, systemBg->getContentSize().height/2)); systemBg->addChild(pSettingMenu); return true; }
void InputLayer::buttonsHandle(Vec2 &pos, InputType inputType) { if (inputType == INPUT_BEGAN) { auto iter = _btnButtons.begin(); for ( ; iter != _btnButtons.end(); iter++) { auto button = *iter; auto localPos = button->convertToNodeSpace(pos); auto rect = Rect( button->getPositionX() - button->getContentSize().width * button->getAnchorPoint().x, button->getPositionY() - button->getContentSize().height * button->getAnchorPoint().y, button->getContentSize().width, button->getContentSize().height); rect.origin = Vec2::ZERO; if (rect.containsPoint(localPos)) { _currButton = button; } } } if (_currButton) { auto index = _currButton->getTag(); CCLOG("_currButton tag : %d", index); switch (inputType) { case INPUT_BEGAN: { _currButton->runAction(ScaleTo::create(0.1, _orginScale + 0.2)); if (_target) { _target->buttons(index, InputProtocol::ButtonPress); } break; } case INPUT_MOVED: { break; } case INPUT_ENDED: { _currButton->runAction(ScaleTo::create(0.1, _orginScale)); if (_target) { _target->buttons(index, InputProtocol::ButtonRelease); } break; } case INPUT_CANCELLED: { _currButton->runAction(ScaleTo::create(0.1, _orginScale)); break; } default: break; } } }
void Poker::SelectPkSuoTou(){ //´Ó³öÅÆÖÐÒƳý¸ÃÅÆ m_isSelect = false; this->setPosition(ccp(getPositionX(),getPositionY()-10)); m_gameMain->getArrPlayerOut()->removeObject(this); }
void BBWelcomeScene::createCloud1() { Size visibleSize = Director::getInstance()->getVisibleSize(); int heigt = visibleSize.height; auto cloudSpt = Sprite::create(__String::createWithFormat("map_cloud%d.png", (arc4random() % 3) + 1)->getCString()); cloudSpt->setTag(101); cloudSpt->setPosition(Point(visibleSize.width + cloudSpt->getContentSize().width/2, (arc4random() % heigt) + visibleSize.height/2)); m_cloudLayer->addChild(cloudSpt); cloudSpt->runAction(Sequence::create(MoveTo::create((arc4random() % 10) + 5, Point(-cloudSpt->getContentSize().width/2, cloudSpt->getPositionY())),CallFunc::create([this](){ ((Sprite*)m_cloudLayer->getChildByTag(101))->removeFromParentAndCleanup(true); createCloud1(); }), NULL)); cloudSpt->setScale(BBGameDataManager::getInstance()->getScreenScale()); }
bool KeyInputTestScene::initSkin() { Vec2 origin = Director::getInstance()->getVisibleOrigin(); // add note skin(base) auto skin = Sprite::create("Default Skin(316_720).png"); //skin->setPosition(Vec2(158 + origin.x, visibleSize.height / 2 + origin.y)); skin->setAnchorPoint(Vec2(0, 0)); skin->setPosition(Vec2(origin.x, origin.y)); this->addChild(skin, 0, "skin"); // add note judge line auto skin_line = Sprite::create("Skin Line(720).png"); skin_line->setAnchorPoint(Vec2(0, 0)); skin_line->setPosition(Vec2(skin->getAnchorPointInPoints().x, skin->getAnchorPointInPoints().y + 114)); skin->addChild(skin_line, 1, "skin_line"); // add button image /* 1P SC*/ auto button_1p_sc = Sprite::create("Button SC.png"); button_1p_sc->setAnchorPoint(Vec2(0, 0)); skin->addChild(button_1p_sc, 1, "button_1p_sc"); button_1p_sc->setPosition(Vec2(skin->getAnchorPointInPoints().x, skin->getAnchorPointInPoints().y + 42)); /* 1P KEY 1 */ auto button_1p_1 = Sprite::create("Button Odd.png"); button_1p_1->setAnchorPoint(Vec2(0, 0)); button_1p_sc->addChild(button_1p_1, 1, "button_1p_1"); button_1p_1->setPosition(Vec2(button_1p_sc->getAnchorPointInPoints().x + 65, button_1p_sc->getAnchorPointInPoints().y)); /* 1P KEY 3 */ auto button_1p_3 = Sprite::create("Button Odd.png"); button_1p_3->setAnchorPoint(Vec2(0, 0)); button_1p_1->addChild(button_1p_3, 1, "button_1p_3"); button_1p_3->setPosition(Vec2(button_1p_sc->getAnchorPointInPoints().x + 72, 0)); /* 1P KEY 5 */ auto button_1p_5 = Sprite::create("Button Odd.png"); button_1p_5->setAnchorPoint(Vec2(0, 0)); button_1p_3->addChild(button_1p_5, 1, "button_1p_5"); button_1p_5->setPosition(Vec2(button_1p_sc->getAnchorPointInPoints().x + 72, 0)); /* 1P KEY 7 */ auto button_1p_7 = Sprite::create("Button Odd.png"); button_1p_7->setAnchorPoint(Vec2(0, 0)); button_1p_5->addChild(button_1p_7, 1, "button_1p_7"); button_1p_7->setPosition(Vec2(button_1p_sc->getAnchorPointInPoints().x + 72, 0)); /* 1P KEY 2 */ auto button_1p_2 = Sprite::create("Button Even.png"); button_1p_2->setAnchorPoint(Vec2(0, 0)); button_1p_1->addChild(button_1p_2, 1, "button_1p_2"); button_1p_2->setPosition(Vec2(button_1p_1->getAnchorPointInPoints().x + 38, button_1p_1->getAnchorPointInPoints().y + 16)); /* 1P KEY 4 */ auto button_1p_4 = Sprite::create("Button Even.png"); button_1p_4->setAnchorPoint(Vec2(0, 0)); button_1p_2->addChild(button_1p_4, 1, "button_1p_4"); button_1p_4->setPosition(Vec2(button_1p_2->getAnchorPointInPoints().x + 72, 0)); /* 1P KEY 6 */ auto button_1p_6 = Sprite::create("Button Even.png"); button_1p_6->setAnchorPoint(Vec2(0, 0)); button_1p_4->addChild(button_1p_6, 1, "button_1p_6"); button_1p_6->setPosition(Vec2(button_1p_4->getAnchorPointInPoints().x + 72, 0)); // add pressed note image /* 1P KEY 1 PRESSED */ auto button_1p_1_pressed = Sprite::create("Button Odd Pressed.png"); button_1p_1_pressed->setAnchorPoint(Vec2(0, 0)); skin->addChild(button_1p_1_pressed, 2, "button_1p_1_pressed"); button_1p_1_pressed->setPosition(Vec2( button_1p_sc->getPositionX() + 65, button_1p_sc->getPositionY())); button_1p_1_pressed->setVisible(false); /* 1P KEY 3 PRESSED */ auto button_1p_3_pressed = Sprite::create("Button Odd Pressed.png"); button_1p_3_pressed->setAnchorPoint(Vec2(0, 0)); skin->addChild(button_1p_3_pressed, 2, "button_1p_3_pressed"); button_1p_3_pressed->setPosition(Vec2( button_1p_1_pressed->getPositionX() + 72, button_1p_1_pressed->getPositionY())); button_1p_3_pressed->setVisible(false); /* 1P KEY 5 PRESSED */ auto button_1p_5_pressed = Sprite::create("Button Odd Pressed.png"); button_1p_5_pressed->setAnchorPoint(Vec2(0, 0)); skin->addChild(button_1p_5_pressed, 2, "button_1p_5_pressed"); button_1p_5_pressed->setPosition(Vec2( button_1p_3_pressed->getPositionX() + 72, button_1p_3_pressed->getPositionY())); button_1p_5_pressed->setVisible(false); /* 1P KEY 7 PRESSED */ auto button_1p_7_pressed = Sprite::create("Button Odd Pressed.png"); button_1p_7_pressed->setAnchorPoint(Vec2(0, 0)); skin->addChild(button_1p_7_pressed, 2, "button_1p_7_pressed"); button_1p_7_pressed->setPosition(Vec2( button_1p_5_pressed->getPositionX() + 72, button_1p_5_pressed->getPositionY())); button_1p_7_pressed->setVisible(false); /* 1P KEY 2 PRESSED */ auto button_1p_2_pressed = Sprite::create("Button Even Pressed.png"); button_1p_2_pressed->setAnchorPoint(Vec2(0, 0)); skin->addChild(button_1p_2_pressed, 2, "button_1p_2_pressed"); button_1p_2_pressed->setPosition(Vec2( button_1p_1_pressed->getPositionX() + 38, button_1p_1_pressed->getPositionY() + 16)); button_1p_2_pressed->setVisible(false); /* 1P KEY 4 PRESSED */ auto button_1p_4_pressed = Sprite::create("Button Even Pressed.png"); button_1p_4_pressed->setAnchorPoint(Vec2(0, 0)); skin->addChild(button_1p_4_pressed, 2, "button_1p_4_pressed"); button_1p_4_pressed->setPosition(Vec2( button_1p_2_pressed->getPositionX() + 72, button_1p_2_pressed->getPositionY())); button_1p_4_pressed->setVisible(false); /* 1P KEY 6 PRESSED */ auto button_1p_6_pressed = Sprite::create("Button Even Pressed.png"); button_1p_6_pressed->setAnchorPoint(Vec2(0, 0)); skin->addChild(button_1p_6_pressed, 2, "button_1p_6_pressed"); button_1p_6_pressed->setPosition(Vec2( button_1p_4_pressed->getPositionX() + 72, button_1p_4_pressed->getPositionY())); button_1p_6_pressed->setVisible(false); return true; }
b2Vec2 GameNode::PositionForBox2D() const { return { getPositionX() / kPTMRatio, getPositionY() / kPTMRatio }; }
bool MIRPoliticalLayer::init(KTPauseLayerDelegate *delegate) { if (!KTPauseLayer::init(delegate)) { return false; } //adapt float bgHt; float tableViewHt; if (IS_IPHONE5) { bgHt = 800; tableViewHt = 680; } else if (IS_IPAD) { bgHt = 640; tableViewHt = 520; } else if (IS_IPAD_HD) { bgHt = (640 + 100) * 2; tableViewHt = (520 + 100)* 2; } else { bgHt = 600; tableViewHt = 480; } auto bg = LayerColor::create(MIRCellColor, winSize.width, bgHt); addChild(bg, -1); __Dictionary *root = __Dictionary::createWithContentsOfFile("Financial.plist"); __Array *array = (__Array *)root->objectForKey("political"); for (int i = 0; i < array->count(); i++) { __Dictionary *dict = (__Dictionary *)array->getObjectAtIndex(i); MIRModel *m = new MIRModel(dict); _dataArray.insert(0, m); m->release(); m->update(InvestmentType::POLITICAL, array->count() - 1 - i); } _tableView = TableView::create(this, Size(winSize.width, tableViewHt)); _tableView->setDirection(ScrollView::Direction::VERTICAL); _tableView->setDelegate(this); _tableView->setPosition(Point(0, 120 * _scale)); _tableView->setColor(Color3B(255, 0, 0)); addChild(_tableView); _tableView->reloadData(); auto drawer = DrawNode::create(); drawer->setAnchorPoint(Point::ANCHOR_BOTTOM_LEFT); drawer->setPosition(Point::ZERO); addChild(drawer, 128); auto type = Sprite::create("finantial_item.png"); type->setScaleY(60/type->getContentSize().height); type->setAnchorPoint(Point::ZERO); type->setPosition(Point(0, _tableView->getPositionY() + _tableView->getViewSize().height)); addChild(type); //画线 drawer->drawSegment(type->getPosition(), Point(winSize.width, type->getPositionY()), 0.5, Color4F::WHITE); drawer->drawSegment(Point(0,type->getPositionY() + 60), Point(winSize.width, 60 + type->getPositionY()), 0.5, Color4F::WHITE); const float typeLabelX[4] = {static_cast<float>(0.06 * screenSize.width), static_cast<float>(0.38 * screenSize.width), static_cast<float>(0.6 * screenSize.width), static_cast<float>(0.89 * screenSize.width)}; const char *typeStr[4] = {"项目", "等级", "消耗", "收益"}; for (int i = 0; i < sizeof(typeLabelX)/sizeof(typeLabelX[0]); i++) { Label *typeLabel = Label::createWithTTF(typeStr[i], TITLE_FONT, 24); typeLabel->setPosition(Point(typeLabelX[i], type->getPositionY() + 30)); typeLabel->setColor(MIRBrown); addChild(typeLabel); } auto header = Sprite::create("finantial_item.png"); header->setScaleY(100/type->getContentSize().height); header->setAnchorPoint(Point::ZERO); header->setPosition(Point(0, type->getPositionY() + 60)); addChild(header); auto titleLabel = Label::createWithTTF("海外投资", TITLE_FONT, 30); titleLabel->setPosition(Point(winSize.width/2, header->getPositionY() + 70)); addChild(titleLabel); auto subTitle = Label::createWithTTF("(关闭游戏仍可获得收入)", TITLE_FONT, 26); subTitle->setTextColor(Color4B(MIRBrown)); subTitle->setPosition(Point(winSize.width/2, header->getPositionY() + 26)); addChild(subTitle); MenuItemImage *item = MenuItemImage::create("close_investments.png", "close_investments.png", [=](Ref *sender){ this->playEffect(SOUND_BUTTON); doCancel(); }); item->setPosition(Point(winSize.width - 42, titleLabel->getPositionY())); auto menu = Menu::create(item, NULL); menu->setAnchorPoint(Point::ANCHOR_BOTTOM_LEFT); menu->setPosition(Point::ZERO); addChild(menu); return true; }
/** * Stores the application window settings (size, position, ...). */ void RMainWindow::writeSettings() { RSettings::getQSettings()->setValue("Appearance/Position.X", getPositionX()); RSettings::getQSettings()->setValue("Appearance/Position.Y", getPositionY()); RSettings::getQSettings()->setValue("Appearance/Width", getWidth()); RSettings::getQSettings()->setValue("Appearance/Height", getHeight()); }
void Moon::update (float dt) { if (!_active) return; _vector.y -= GRAVITY; _nextPosition = ccp ( getPositionX() + _vector.x * dt, getPositionY() + _vector.y * dt ); limitSpeeds(); //if hitting sides of screen if (_nextPosition.x < _radius) { _nextPosition.x = _radius ; _vector.x *= -1.0; //I play the same sound as when sun is hit SimpleAudioEngine::sharedEngine()->playEffect("sun_hit.wav"); } if (_nextPosition.x > _screenSize.width - _radius) { _nextPosition.x = _screenSize.width - _radius; _vector.x *= -1.0; SimpleAudioEngine::sharedEngine()->playEffect("sun_hit.wav"); } //rotate moon based on VX this->setRotation (getRotation() + _vector.x * 0.08f); //moon blinks when power is boosting if (_manager->getBoosting()) { _blinkTimer += dt; if (_blinkTimer > _blinkInterval) { _blinkTimer = 0; if (_blinkState == 1) { _blinkState = 0; this->setDisplayFrame ( CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("moon_off.png") ); } else { _blinkState = 1; this->setDisplayFrame ( CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("moon.png") ); } } } else { if (_blinkState == 0 && _manager->getLineEnergy() > 0) { _blinkState = 1; this->setDisplayFrame ( CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("moon.png") ); } } }
void Pipe::SpawnPipe1( cocos2d::Layer *layer ) { CCLOG( "SPAWN PIPE" ); auto topPipe = Sprite::create( "Pipe.png" ); auto bottomPipe = Sprite::create( "Pipe.png" ); auto topPipeBody = PhysicsBody::createBox( topPipe->getContentSize( ) ); auto bottomPipeBody = PhysicsBody::createBox( bottomPipe->getContentSize( ) ); /* auto random = CCRANDOM_0_1( ); if ( random < LOWER_SCREEN_PIPE_THRESHOLD ) { random = LOWER_SCREEN_PIPE_THRESHOLD; } else if ( random > UPPER_SCREEN_PIPE_THRESHOLD ) { random = UPPER_SCREEN_PIPE_THRESHOLD; } auto topPipePosition = ( random * visibleSize.height ) + ( topPipe->getContentSize().height / 2 ); */ topPipeBody->setDynamic( false ); bottomPipeBody->setDynamic( false ); topPipe->setPhysicsBody( topPipeBody ); bottomPipe->setPhysicsBody( bottomPipeBody ); //collision handle topPipeBody->setCollisionBitmask(OBSTACLE_COLLISION_BITMASK); topPipeBody->setContactTestBitmask(true); bottomPipeBody->setCollisionBitmask(OBSTACLE_COLLISION_BITMASK); bottomPipeBody->setContactTestBitmask(true); //topPipe->setPosition( Point( visibleSize.width + topPipe->getContentSize().width + origin.x // ,topPipePosition ) ); //bottomPipe->setPosition( Point( topPipe->getPositionX(), topPipePosition - ( Sprite::create( "Ball.png" )->getContentSize( ).height * PIPE_GAP ) - topPipe->getContentSize().height ) ); // new pipes position //setting the random number between min and max auto minY = origin.y + Sprite::create( "Ball.png" )->getContentSize( ).height/4 - (topPipe->getContentSize().height/2); auto maxY = origin.y - Sprite::create( "Ball.png" )->getContentSize( ).height/4 - Sprite::create( "Ball.png" )->getContentSize( ).height - Sprite::create( "Ball.png" )->getContentSize( ).height/3 + visibleSize.height - topPipe->getContentSize().height/2; //float randNum = rand()% (float)(maxY-minY + 1.0) + minY; float randNum = minY + static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(maxY-minY))); //setting position bottomPipe->setPosition(Point(visibleSize.width + topPipe->getContentSize().width + origin.x ,randNum)); topPipe->setPosition(Point(bottomPipe->getPositionX() ,bottomPipe->getPositionY() + Sprite::create( "Ball.png" )->getContentSize( ).height + (Sprite::create( "Ball.png" )->getContentSize( ).height/3) + (topPipe->getContentSize().height))); // end new pipe possition layer->addChild( topPipe ); layer->addChild( bottomPipe ); auto topPipeAction = MoveBy::create (PIPE_MOVEMENT_SPEED * visibleSize.width, Point(-visibleSize.width * 1.5 , 0)); auto bottomPipeAction = MoveBy::create (PIPE_MOVEMENT_SPEED * visibleSize.width, Point(-visibleSize.width * 1.5 , 0)); topPipe->runAction(topPipeAction); bottomPipe->runAction(bottomPipeAction); }
b2Body * AwardNode::createBody() { return _collDetector->createBoxBody(this, b2_staticBody, getPositionX(), getPositionY(), MAPDATA->getTile_w_in_scene(), MAPDATA->getTile_h_in_scene() ); }
bool CLostScene::init() { if (!Layer::init()) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); auto LostBG = Sprite::create("picture/shibai.jpg"); Size LostBGSize = LostBG->getContentSize(); LostBG->setScaleX(visibleSize.width/LostBGSize.width); LostBG->setScaleY(visibleSize.height/LostBGSize.height); LostBG->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); this->addChild(LostBG); #if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 auto shibai = Label::createWithTTF(Tools::Unicode2Utf8(L"失 败"),"fonts/msyh.ttc",38); #else auto shibai = Label::createWithTTF("失 败","fonts/msyh.ttc",38); #endif shibai->setColor(Color3B(255,0,0)); shibai->setPosition(500,500); this->addChild(shibai); auto again = MenuItemImage::create( "picture/blue1_menu.png", "picture/blue2_menu.png", CC_CALLBACK_1(CLostScene::menuCloseCallback,this)); again->setScale(0.5f); again->setPosition(Vec2(origin.x + visibleSize.width - again->getContentSize().width/2-310 , origin.y + again->getContentSize().height/2+330)); #if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 auto againLable = Label::createWithTTF(Tools::Unicode2Utf8(L"再来一次"),"fonts/msyh.ttc",24); #else auto againLable = Label::createWithTTF("再来一次","fonts/msyh.ttc",24); #endif againLable->setPosition(Vec2(again->getPositionX(),again->getPositionY())); this->addChild(againLable); auto quit = MenuItemImage::create( "picture/blue1_menu.png", "picture/blue2_menu.png", CC_CALLBACK_1(CLostScene::menuCloseCallback1,this)); quit->setScale(0.5f); quit->setPosition(Vec2(origin.x + visibleSize.width - quit->getContentSize().width/2-310 , origin.y + quit->getContentSize().height/2+160)); quit->setPosition(Vec2(origin.x + visibleSize.width - quit->getContentSize().width/2-310 , origin.y + quit->getContentSize().height/2+160)); #if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 auto quitLable = Label::createWithTTF(Tools::Unicode2Utf8(L"退出"),"fonts/msyh.ttc",24); #else auto quitLable = Label::createWithTTF("退出","fonts/msyh.ttc",24); #endif quitLable->setPosition(Vec2(quit->getPositionX(),quit->getPositionY())); this->addChild(quitLable); auto menu = Menu::create(again,quit, NULL); menu->setPosition(Vec2::ZERO); this->addChild(menu, 1); return true; }
Scene* Chapter2Level1::createScene() { // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // some upfront items that we need // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); Size playingSize = Size(visibleSize.width, visibleSize.height - (visibleSize.height/8)); // actual playing size to work with // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // create a scene // 'scene' is an autorelease object // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ auto scene = Scene::create(); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // create a node to hold all of the labels // create the player and score labels // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ int paddingX = 20; int paddingY = 20; auto labelNode = Node::create(); auto player1 = Label::createWithTTF("Player 1", "fonts/Marker Felt.ttf", 32); auto player2 = Label::createWithTTF("Player 2", "fonts/Marker Felt.ttf", 32); auto player1Score = Label::createWithTTF("00000", "fonts/Marker Felt.ttf", 32); auto player2Score = Label::createWithTTF("00000", "fonts/Marker Felt.ttf", 32); labelNode->addChild(player1, -2); labelNode->addChild(player1Score, -1); labelNode->addChild(player2, 1); labelNode->addChild(player2Score, 2); player1->setPosition(Vec2(0 + player1->getContentSize().width / 2 + paddingX, visibleSize.height - player1->getContentSize().height / 2 - paddingY)); player1Score->setPosition(Vec2(0 + player1->getPositionX() + player1->getContentSize().width + paddingX, visibleSize.height - player1->getContentSize().height / 2 - paddingY)); player2Score->setPosition(Vec2(visibleSize.width - player2Score->getContentSize().width / 2 - paddingX, visibleSize.height - player2Score->getContentSize().height / 2 - paddingY)); player2->setPosition(Vec2(player2Score->getPositionX() - player2Score->getContentSize().width - paddingX, visibleSize.height - player2Score->getContentSize().height / 2 - paddingY)); scene->addChild(labelNode, 0); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // create a node to hold non-sprites. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ auto nodeItems = Node::create(); nodeItems->setName("nodeItems"); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // create a path/walkway // depending upon how large the screen is we need to decide how many blocks to lay down. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ auto testSprite = Sprite::create("ZigzagForest_Square.png"); int howMany = std::ceil(visibleSize.width / testSprite->getContentSize().width); int sX = 0; // act as a counter for setPosition x coordinate. int sY = 0; // act as a counter for setPosition y coordinate. playingSize = Size(visibleSize.width, visibleSize.height - testSprite->getContentSize().height); for (int i=0; i < howMany; i++) { auto sprite = Sprite::create("ZigzagForest_Square.png"); sprite->setAnchorPoint(Vec2(0,0)); sprite->setPosition(sX,sY); sX += sprite->getContentSize().width; nodeItems->addChild(sprite, -1); } testSprite = NULL; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // create a few blocks as obstables // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ testSprite = Sprite::create("ZigzagGrass_Mud_Round.png"); // left side blocks sX = visibleSize.width/4 - testSprite->getContentSize().width; sY = playingSize.height/2 - testSprite->getContentSize().height * 2; for (int i=0; i < 3; i++) { auto sprite = Sprite::create("ZigzagGrass_Mud_Round.png"); sprite->setAnchorPoint(Vec2(0,0)); sprite->setPosition(sX,sY); sX += sprite->getContentSize().width; if (i == 1) { sprite->setName("middleBlock1"); } nodeItems->addChild(sprite, 1); } // right side blocks sX = (visibleSize.width/2 + visibleSize.width/4) - testSprite->getContentSize().width; sY = playingSize.height/2 - testSprite->getContentSize().height * 2; for (int i=0; i < 3; i++) { auto sprite = Sprite::create("ZigzagGrass_Mud_Round.png"); sprite->setAnchorPoint(Vec2(0,0)); sprite->setPosition(sX,sY); sX += sprite->getContentSize().width; if (i == 1) { sprite->setName("middleBlock2"); } scene->addChild(sprite, 1); } // center blocks sX = visibleSize.width/2 - testSprite->getContentSize().width; sY = (playingSize.height/2 + playingSize.height/4) - testSprite->getContentSize().height * 2; for (int i=0; i < 3; i++) { auto sprite = Sprite::create("ZigzagGrass_Mud_Round.png"); sprite->setAnchorPoint(Vec2(0,0)); sprite->setPosition(sX,sY); sX += sprite->getContentSize().width; nodeItems->addChild(sprite, 1); } testSprite = NULL; scene->addChild(nodeItems, 1); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // create a node to hold sprites // create a sprite // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ auto spriteNode = Node::create(); spriteNode->setName("spriteNode"); auto sprite1 = Sprite::create("Blue_Front1.png"); sprite1->setAnchorPoint(Vec2(0,0)); sprite1->setPosition(100, (visibleSize.height - playingSize.height)); sprite1->setName("mainSprite"); spriteNode->addChild(sprite1, 1); scene->addChild(spriteNode, 1); //sprite1->scheduleOnce([&](float dt) { // // the local variable "sprite1" will go out of scope, so I have to get it from "this" // auto anode = Director::getInstance()->getRunningScene()->getChildByName("spriteNode"); // auto bnode = anode->getChildByName("mainSprite"); // // //auto moveBy = MoveBy::create(2, Point(400,0)); // // //bnode->runAction(moveBy); //}, 5, "udpate_key"); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // create a node to hold menu // create a menu // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ auto menuNode = Node::create(); menuNode->setName("menuNode"); auto menuItem1 = MenuItemFont::create("Demo Parent/Child"); menuItem1->setFontNameObj("fonts/Marker Felt.ttf"); menuItem1->setFontSizeObj(32); menuItem1->setCallback([&](cocos2d::Ref *sender) { auto anode = Director::getInstance()->getRunningScene()->getChildByName("spriteNode"); auto bnode = anode->getChildByName("mainSprite"); auto cnode = Director::getInstance()->getRunningScene()->getChildByName("nodeItems"); auto dnode = cnode->getChildByName("middleBlock1"); // add a few more sprites auto sprite1 = Sprite::create("LightBlue_Front1.png"); sprite1->setAnchorPoint(Vec2(0,0)); sprite1->setName("childSprite1"); bnode->addChild(sprite1, 1); sprite1->setPosition(dnode->getPositionX(), dnode->getPositionY()); auto sprite2 = Sprite::create("White_Front1.png"); sprite2->setAnchorPoint(Vec2(0,0)); sprite2->setName("childSprite2"); bnode->addChild(sprite2, 1); sprite2->setPosition(dnode->getPositionX() - dnode->getContentSize().width * 3, dnode->getPositionY()); // hide the menu option auto ynode = Director::getInstance()->getRunningScene()->getChildByName("menuNode"); auto znode = ynode->getChildByName("menu"); znode->removeFromParentAndCleanup(true); // schedule an action after 3 seconds bnode->scheduleOnce([&](float dt) { auto anode = Director::getInstance()->getRunningScene()->getChildByName("spriteNode"); auto bnode = anode->getChildByName("mainSprite"); bnode->setRotation(40.0f); auto delay = DelayTime::create(4.0f); bnode->runAction(delay); bnode->setScale(2.0f); // You could also use an Action and Sequence combination to do this. //auto rotateBy = RotateBy::create(2, 40.0f); //auto scaleBy = ScaleTo::create(2, 2.0f); //auto seq = Sequence::create(rotateBy, scaleBy, NULL); //bnode->runAction(seq); }, 3, "udpate_key"); }); auto menuItemGoBack = MenuItemFont::create("Go Back"); menuItemGoBack->setFontNameObj("fonts/Marker Felt.ttf"); menuItemGoBack->setFontSizeObj(54); menuItemGoBack->setPosition(menuItemGoBack->getPositionX() + 400, menuItemGoBack->getPositionY()-300); menuItemGoBack->setCallback([&](Ref *sender) { //Director::getInstance()->replaceScene(Chapter2::createScene()); Director::getInstance()->replaceScene(TransitionFlipX::create(0.5, Chapter2::createScene()/*, Color3B(0, 255, 255)*/)); }); auto menu = Menu::create(menuItem1,menuItemGoBack, NULL); menu->setName("menu"); menuNode->addChild(menu, 1); menu->setPosition(visibleSize.width / 2, visibleSize.height - menuItem1->getContentSize().height * 2); scene->addChild(menuNode, 2); // return the scene return scene; }
void GamePlay::gameSetting() { if (onSound) CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect( "sound/button.mp3"); boardMenuPause->setVisible(false); boardMenuSetting = Sprite::create("board.png"); boardMenuSetting->setPosition( Vec2(visibleSize.width / 2, visibleSize.height / 2)); boardMenuSetting->setZOrder(30); this->addChild(boardMenuSetting); float haflHeight = boardMenuSetting->getContentSize().height / 2; float haflWidth = boardMenuSetting->getContentSize().width / 2; MenuItemImage* closeBtn = MenuItemImage::create("menu_closeBtn.png", "menu_closeBtn.png", CC_CALLBACK_0(GamePlay::gameCloseMenuSetting, this)); auto menuClose = Menu::create(closeBtn, nullptr); menuClose->setZOrder(40); menuClose->setPosition( Vec2(haflWidth * 2 - closeBtn->getContentSize().width - PADDING, haflHeight * 2 - closeBtn->getContentSize().height - PADDING)); boardMenuSetting->addChild(menuClose); Sprite* sound = Sprite::create("sound.png"); sound->setPosition( Vec2(4 * PADDING + sound->getContentSize().width / 2, menuClose->getPositionY() - closeBtn->getContentSize().height - 2 * PADDING)); sound->setZOrder(40); boardMenuSetting->addChild(sound); //button on/of sound MenuItemImage* onSoundBtn = MenuItemImage::create("onbutton.png", "onbutton.png", CC_CALLBACK_0(GamePlay::gameOnSound, this)); auto menuOnSound = Menu::create(onSoundBtn, nullptr); menuOnSound->setZOrder(40); menuOnSound->setPosition( Vec2(haflWidth / 2 + PADDING, sound->getPositionY() - 2 * PADDING - onSoundBtn->getContentSize().height)); boardMenuSetting->addChild(menuOnSound); MenuItemImage* offSoundBtn = MenuItemImage::create("offbutton.png", "offbutton.png", CC_CALLBACK_0(GamePlay::gameOffSound, this)); auto menuOffSound = Menu::create(offSoundBtn, nullptr); menuOffSound->setZOrder(40); menuOffSound->setPosition( Vec2(haflWidth * 3 / 2 - PADDING, menuOnSound->getPositionY())); boardMenuSetting->addChild(menuOffSound); //stick sound stickSound = Sprite::create("stick.png"); stickSound->setZOrder(50); stickSound->setTag(TAG_STICK_SOUND); stickSound->setPositionY(menuOnSound->getPositionY()); boardMenuSetting->addChild(stickSound); this->posOnX = menuOnSound->getPositionX() - onSoundBtn->getContentSize().width / 4 - PADDING / 2; this->posOffX = menuOffSound->getPositionX() - offSoundBtn->getContentSize().width / 4 - PADDING / 2; if (onSound == true) { stickSound->setPositionX(this->posOnX); } else { stickSound->setPositionX(this->posOffX); } Sprite* music = Sprite::create("music.png"); music->setZOrder(40); music->setPosition( Vec2(sound->getPositionX(), sound->getPositionY() - 3 * music->getContentSize().height)); boardMenuSetting->addChild(music); //button on/of music MenuItemImage* onMusicBtn = MenuItemImage::create("onbutton.png", "onbutton.png", CC_CALLBACK_0(GamePlay::gameOnMusic, this)); auto menuOnMusic = Menu::create(onMusicBtn, nullptr); menuOnMusic->setZOrder(40); menuOnMusic->setPosition( Vec2(menuOnSound->getPositionX(), music->getPositionY() - 2 * PADDING - onMusicBtn->getContentSize().height)); boardMenuSetting->addChild(menuOnMusic); MenuItemImage* offMusicBtn = MenuItemImage::create("offbutton.png", "offbutton.png", CC_CALLBACK_0(GamePlay::gameOffMusic, this)); auto menuOffMusic = Menu::create(offMusicBtn, nullptr); menuOffMusic->setZOrder(40); menuOffMusic->setPosition( Vec2(haflWidth * 3 / 2 - PADDING, menuOnMusic->getPositionY())); boardMenuSetting->addChild(menuOffMusic); //stick sound stickMusic = Sprite::create("stick.png"); stickMusic->setZOrder(50); stickMusic->setTag(TAG_STICK_MUSIC); stickMusic->setPositionY(menuOnMusic->getPositionY()); boardMenuSetting->addChild(stickMusic); if (onMusic == true) { stickMusic->setPositionX(this->posOnX); } else { stickMusic->setPositionX(this->posOffX); } //volumn setting /*cocos2d::extension::ControlSlider* slider = cocos2d::extension::ControlSlider::create("sliderTrack2.png", "sliderProgress2.png", "sliderThumb.png"); slider->setPosition(200, 200); slider->setMinimumValue(0); slider->setMaximumValue(100); slider->setValue(50); slider->addTargetWithActionForControlEvents(this, cccontrol_selector(IntroView::valueChangedCallback), cocos2d::extension::Control::EventType::VALUE_CHANGED); addChild(slider); void IntroView::valueChangedCallback(Ref* sender, cocos2d::extension::Control::EventType evnt) { float value = static_cast<cocos2d::extension::ControlSlider*>(sender)->getValue(); CCLOG(std::to_string(value).c_str()); }*/ }
bool HelloWorld::init() { if ( !Layer::init() ) { return false; } CReadFile::getInstance()->init(); Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); auto closeItem = MenuItemImage::create( "picture/blue1_menu.png", "picture/blue2_menu.png" , CC_CALLBACK_1(HelloWorld::menuCloseCallback, this)); closeItem->setScale(0.3f); closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2-310 , origin.y + closeItem->getContentSize().height/2+160)); auto closeItem1 = MenuItemImage::create( "picture/blue1_menu.png", "picture/blue2_menu.png", CC_CALLBACK_1(HelloWorld::menuCloseCallback1, this)); closeItem1->setScale(0.5f); closeItem1->setPosition(Vec2(origin.x + visibleSize.width - closeItem1->getContentSize().width/2-310 , origin.y + closeItem1->getContentSize().height/2+330)); auto SetMenu = MenuItemImage::create( "picture/shezhi2_cover.png", "picture/shezhi1_cover.png", CC_CALLBACK_1(HelloWorld::menuCloseCallback3, this)); SetMenu->setScale(0.8f); SetMenu->setPosition(Vec2(origin.x + visibleSize.width - SetMenu->getContentSize().width/2-390 , origin.y + SetMenu->getContentSize().height/2+260)); auto menu = Menu::create(closeItem,closeItem1,SetMenu, NULL); menu->setPosition(Vec2::ZERO); this->addChild(menu, 1); #if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 auto label = Label::createWithTTF(Tools::Unicode2Utf8(L"开始游戏"), "fonts/msyh.ttc", 24); #else auto label = Label::createWithTTF("开始游戏", "fonts/msyh.ttc", 24); #endif label->setPosition(Vec2(closeItem1->getPositionX(), closeItem1->getPositionY())); label->setScale(0.8f); this->addChild(label, 1); #if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 auto label1 = Label::createWithTTF(Tools::Unicode2Utf8(L"退出"), "fonts/msyh.ttc", 24); #else auto label1 = Label::createWithTTF("退出", "fonts/msyh.ttc", 24); #endif label1->setPosition(Vec2(closeItem->getPositionX(), closeItem->getPositionY())); label1->setScale(0.8f); this->addChild(label1,1); auto sprite = Sprite::create("picture/shumabaobei.jpg"); Size sprSize = sprite->getContentSize(); sprite->setScaleX(visibleSize.width/sprSize.width); sprite->setScaleY(visibleSize.height/sprSize.height); sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); this->addChild(sprite, 0); auto logo = Sprite::create("picture/logo.png"); Size logoSize = logo->getContentSize(); auto spark = Sprite::create("picture/spark.png"); spark->setPosition(-logoSize.width,0); auto clippingNode = ClippingNode::create(); clippingNode->setPosition(500,560); this->addChild(clippingNode); clippingNode->setAlphaThreshold(0.05f); clippingNode->setContentSize(logoSize); clippingNode->setStencil(logo); clippingNode->addChild(logo,1); clippingNode->addChild(spark,2); auto moveAction = MoveTo::create(2.0f,Vec2(logoSize.width,0)); auto moveBackAction = MoveTo::create(2.0f,Vec2(-logoSize.width,0)); spark->runAction(RepeatForever::create(Sequence::create(moveAction,moveBackAction,NULL))); if (CReadFile::getInstance()->getshuomingkg()) { CReadFile::getInstance()->setshuomingkg(false); CSound::getInstance()->playBG("Butter-Fly.mp3",CSound::getInstance()->getIsPlay()); CSound::getInstance()->setIsPlay(true); auto shuominglayer = LayerColor::create(Color4B(120,120,120,200)); #if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 auto wenzi = Label::createWithTTF(Tools::Unicode2Utf8(L"欢迎来到宝库设计的数码宝贝记忆消除游戏"),"fonts/msyh.ttc", 28); #else auto wenzi = Label::createWithTTF("欢迎来到宝库设计的数码宝贝记忆消除游戏","fonts/msyh.ttc", 28); #endif wenzi->setMaxLineWidth(460); wenzi->setLineBreakWithoutSpace(true); wenzi->setPosition(480,520); wenzi->setColor(ccc3(0,0,0)); shuominglayer->runAction(FadeOut::create(5)); wenzi->runAction(FadeOut::create(3)); shuominglayer->addChild(wenzi,2); this->addChild(shuominglayer,2); } return true; }