void CivController::placeFirstHuman() { Coord startLoc; do { startLoc = m_World.map().getRandomCoord(); } while (!m_World.map()(startLoc).isPassable()); addHuman(startLoc); }
void TitleScene::update(float dt) { auto human = (Sprite *)this->getChildByTag(1); if (human->getActionByTag(1)) { return; } this->removeChildByTag(1); addHuman(); }
// on "init" you need to initialize your instance bool TitleScene::init() { ////////////////////////////// // 1. super init first if (!Layer::init()) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); //ボタン作成 auto closeItem = MenuItemImage::create( "teach.png", "Onbutton.png", CC_CALLBACK_1(TitleScene::menuCloseCallback, this)); closeItem->setPosition(Vec2(origin.x + visibleSize.width / 2 , origin.y + closeItem->getContentSize().height / 3 )); closeItem->setRotation(90); closeItem->setScale(0.6); // create menu, it's an autorelease object auto menu = Menu::create(closeItem, NULL); menu->setPosition(Vec2::ZERO); this->addChild(menu, 1); auto label = LabelTTF::create("7thVoice", "Arial", 56); // position the label on the center of the screen label->setPosition(Vec2(origin.x + visibleSize.width / 2, origin.y + visibleSize.height - label->getContentSize().height)); // add the label as a child to this layer this->addChild(label, 1); auto buttonlabel = LabelTTF::create("Push State", "Arial", 56); buttonlabel->setPosition(Vec2(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 3.5)); this->addChild(buttonlabel, 1); // add "TitleScene" splash screen" auto sprite = Sprite::create("class01.png"); // 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); addHuman(); this->schedule(schedule_selector(TitleScene::update)); this->scheduleUpdate(); return true; }