예제 #1
0
bool LobbyController::init() {
    if (!Layer::init()) {
        return false;
    }
    cocos2d::Size visibleSize = cocos2d::Director::getInstance()->getVisibleSize();
    Vec2 origin = cocos2d::Director::getInstance()->getVisibleOrigin();

    auto background = cocos2d::Sprite::create("data/background.jpg");
    background->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
    
    cocos2d::Size backgroundSize = background->getContentSize();
    background->setScaleX(visibleSize.width / backgroundSize.width);
    background->setScaleY(visibleSize.height / backgroundSize.height);
    this->addChild(background, 0);
    
    auto startButton = cocos2d::MenuItemImage::create(
        "data/Start_Button_0.png",
        "data/Start_Button_Pressed_0.png",
        CC_CALLBACK_1(LobbyController::startGame, this));

    startButton->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
    startButton->setScale(0.8);
    // create menu, it's an autorelease object
    auto menu = cocos2d::Menu::create(startButton, NULL);
    menu->setPosition(Vec2::ZERO);
    this->addChild(menu, 1);
    return true;
}
예제 #2
0
bool MenuScene::init()
{
    if (!Node::init()) {
        return false;
    }
    
    int i = 0;
    auto audio = new Audio();
    auto visibleSize = cocos2d::Director::getInstance()->getVisibleSize();
    
    // *Create menu begin*
	auto computerItem = MenuItemImage::create(Config::File::computerTexture, Config::File::computerTexture, [=](Ref *sender) {
        this->_intoAIScene();
	});

    auto onlineItem = MenuItemImage::create(Config::File::onlineTexture, Config::File::onlineTexture, [=](Ref *sender) {
        if(!_waiting) {
            auto network = new NetworkController();
            _network = network;
            auto connectLayer = Layer::create();
            audio->playItemClickEffect();
            auto connectBg = Sprite::create(Config::File::connectingTexture);
            connectBg->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2));
            connectLayer->addChild(connectBg, 2);
            _waiting = true;
            this->addChild(connectLayer, 3);
        }
    });
    auto aboutItem = MenuItemImage::create(Config::File::aboutTexture, Config::File::aboutTexture, [=](Ref *sender) {
        audio->playItemClickEffect();
    });
    auto exitItem = MenuItemImage::create(Config::File::exitTexture, Config::File::exitTexture, [](Ref *sender) {
		Director::getInstance()->end();
	});
    auto menu = Menu::create(computerItem, onlineItem, aboutItem, exitItem, nullptr);
    // *Create menu end*
    
    auto intoBattleScene = cocos2d::EventListenerCustom::create("intoBattleScene", CC_CALLBACK_1(MenuScene::_intoBattleScene, this));
    
    _bg = Sprite::create(Config::File::menuSceneFrame);
    _bg->setScale(visibleSize.width / _bg->getContentSize().width, visibleSize.height / _bg->getContentSize().height);
    _bg->setPosition(Vec2(visibleSize.width/ 2, visibleSize.height / 2));
    for(const auto &child : menu->getChildren()) {
        float offset = Config::Data::menuItemDistance * i;
        child->setScale(Config::Data::menuItemScale);
        child->setPosition(Vec2(-visibleSize.width / 2 + child->getContentSize().width / 4,
                                Config::Data::menuTopY - offset));
        i++;
    }
    
    this->addChild(menu, 2);
    this->addChild(_bg, 1);
    // add a scheduler to change background fade and zoom. :60fps
    this->schedule(schedule_selector(MenuScene::_inZoom), 1 / 25);
    _eventDispatcher->addEventListenerWithFixedPriority(intoBattleScene, 1);
    return true;
}
예제 #3
0
    void Grid::OnCross(Plane& plane, Plane* old_plane, grid_ptr from, grid_ptr to) {
        // 击毁已有的Plane
        if (NULL != old_plane) {
            float sub_t = 0.0f;
            if (to) {
                using cocos2d::Vec2;
                Vec2 t = Vec2(to->GetPositionX(), to->GetPositionY());
                Vec2 m = Vec2(GetPositionX(), GetPositionY());
                sub_t = t.distance(m) / Config::GetInstance().Plane.FlySpeed;
            }
            // 被击毁飞机回家
            old_plane->GoHome(LGR_KICKOFF, plane.GetActionTime() - sub_t);
        }

    }
예제 #4
0
bool MapController::onTouchMoved(cocos2d::Touch *touch) {
  auto c = touch->getStartLocation();
  auto d = Vec2(touch->getLocation().x, touch->getLocation().y);
  d.subtract(c);
  auto l = d.length();
  d.normalize();
  auto position = touchPositionStarted + d * l * mapScrollSpeed;
  gameLayer->setPosition(position);
  previousTouchPosition = touch->getPreviousLocation();
  previosTime = std::chrono::system_clock::now();
  return true;
}
예제 #5
0
/*!
 @brief コンストラクタ
 
 画像の読み込みを行う。
 */
AKGauge::AKGauge(const char *emptyFileName,
                 const char *fullFileName,
                 int width,
                 int height,
                 bool isHorizontal) :
m_emptyFileName(emptyFileName),
m_fullFileName(fullFileName),
m_imageWidth(width),
m_imageHeight(height),
m_isHorizontal(isHorizontal),
m_percent(0.0f)
{
    // 空画像を読み込む
    m_emptyImage = Sprite::create(m_emptyFileName);
    
    // 自ノードに配置する
    addChild(m_emptyImage, 0);
    
    // 満画像を読み込む
    m_fullImage = Sprite::create(m_fullFileName);
    
    // 自ノードに配置する
    addChild(m_fullImage, 1);
    
    // 水平方向かどうかで画像のアンカーを置く場所を変更する
    if (m_isHorizontal) {
        
        // 水平方向の場合、ゲージがたまるのを満ゲージの幅変更によって表現する。
        // 幅が変わってもx座標を変えなくても良いように左端にアンカーを設定する。
        m_fullImage->setAnchorPoint(Vec2(0.0f, 0.5f));
        m_fullImage->setPosition(Vec2(AKScreenSize::deviceLength(-m_imageWidth / 2.0f), 0.0f));
    }
    else {
        
        // 垂直方向の場合、ゲージがたまるのを満ゲージの高さ変更によって表現する。
        // 幅が変わってもx座標を変えなくても良いように下端にアンカーを設定する。
        m_fullImage->setAnchorPoint(Vec2(0.5f, 0.0f));
        m_fullImage->setPosition(Vec2(0.0f, AKScreenSize::deviceLength(-m_imageHeight / 2.0f)));
    }
}