Beispiel #1
0
void		SpriteManager::loadSpriteManager(const std::string & name, SpritesLoader & sp)
{
  this->_name = name;
  this->_sp = sp.getSpriteByName(name);
  for (std::map<std::string, Animation* >::const_iterator it = this->_sp->getAnimations().begin();it != this->_sp->getAnimations().end();++it)
    {
      if (this->_defaultAnim.empty())
	this->_defaultAnim = it->first;
      this->_framesPos[it->first] = 0;
      this->_loopEnd[it->first] = false;
    }
}
Beispiel #2
0
SpriteManager::SpriteManager(const std::string & name, SpritesLoader & sp)
  : _name(name), _sp(sp.getSpriteByName(name)), _posWindowX(0), _posWindowY(0), _scaleX(1.0), _scaleY(1.0), _isAnimEnd(false)
{
  for (std::map<std::string, Animation* >::const_iterator it = this->_sp->getAnimations().begin();it != this->_sp->getAnimations().end();++it)
    {
      if (this->_defaultAnim.empty())
	this->_defaultAnim = it->first;
      this->_framesPos[it->first] = 0;
      this->_loopEnd[it->first] = false;
    }
  this->_color.push_back(255);
  this->_color.push_back(255);
  this->_color.push_back(255);
  this->_color.push_back(255);
}
bool LevelScenePopUp::init()
{
    /*if ( !CCLayer::init() )
    {
        return false;
    }*/
    Level* current_level = _parent->getLevel();
    //Get the size of the screen we can see
    CCSize visibleSize = ADScreen::getVisibleSize();
    //Get the screen start of cordinates
    CCPoint origin = ADScreen::getOrigin();
    float scaled = ADScreen::getScaleFactor();

    //Create the sheet
    //_sheet_menu = CCNode::create();
    //this->addChild(_sheet_menu);
    _sheet_menu = this;
    SpritesLoader spl = GraphicsManager::getLoaderFor(_sheet_menu,
                                                      "level/level_end_menu.plist",
                                                      "level/level_end_menu.png");
    spl->inject(true);
    CCSprite* sheet = spl->loadSprite("sheet-horizontal.png");
    //const unsigned int ELEMENTS_LAYER=100;
    //sheet->setVisible(false);

    //Create the zone for menu
    float banner_padding = 15/scaled;
    float zone_margin = 0;

    CCSize menu_zone_size(sheet->getContentSize());
    float free_space = (visibleSize.height - menu_zone_size.height*1.1)/2;
    float max_space = free_space * 1.8;
    float move_up = 0;
    CCSize banner_size(visibleSize.width*0.9, max_space - banner_padding);

//    _pause_banner = ads::AdsManager::getInstance().getBanner(banner_size);
//    if(_pause_banner)
//    {
//        _parent->getParentScene()->addChild(_pause_banner);
//        _pause_banner->setAnchorPoint(ccp(0.5,0));
//        _pause_banner->setPosition(origin.x + visibleSize.width/2,
//                                   origin.y + banner_padding);
//        //_pause_banner->showAds();

//        float banner_height = _pause_banner->getContentSize().height + banner_padding;
//        if(banner_height > free_space)
//            move_up = banner_height - free_space;
//        zone_margin = move_up;
//    }


    _sheet_target_position = ccp(visibleSize.width/2+origin.x,
                                (visibleSize.height-zone_margin)/2+zone_margin+origin.y);
    _sheet_menu->setPosition(ccp(_sheet_target_position.x,
                                 _sheet_target_position.y-visibleSize.height));
    _sheet_menu->setContentSize(menu_zone_size);
    _sheet_menu->setAnchorPoint(ccp(0.5,0.5));
    _sheet_menu->runAction(CCMoveTo::create(0.2f, _sheet_target_position));

    //sheet->setRotation(-90);
    sheet->setAnchorPoint(ccp(0,0));
    //sheet->removeFromParent();

    //Place buttons
    CCMenu* menu = CCMenu::create();
    menu->setPosition(sheet->getPosition());
    menu->setAnchorPoint(ccp(0,0));
    menu->setContentSize(menu_zone_size);
    _sheet_menu->addChild(menu);

    //CCSprite* next_level_image = CCSprite::create("level/next_level.png");
    CCSprite* next_level_image = CCSprite::create("level/next_level_background.png");

    CCSize image_size = next_level_image->getContentSize();
    float design_scale = 1;

    ADMenuItem *first_button = 0;
    if(current_level->getLevelState() == Level::Crown)
    {
        //CCSprite* levels = CCSprite::create("level/levels.png");
        CCSprite* levels = CCSprite::create("level/levels_background.png");
        first_button = ADMenuItem::create(levels);
        CONNECT(first_button->signalOnClick,
                this, &LevelScenePopUp::onLevels);
    }
    else
    {
        //CCSprite* find_more_image = CCSprite::create("level/find_more.png");
        CCSprite* find_more_image = CCSprite::create("level/find_more_background.png");
        first_button = ADMenuItem::create(find_more_image);
        CONNECT(first_button->signalOnClick,
                this, &LevelScenePopUp::onFindMoreSolutions);
    }
    //TODO: change if it is necessary x coordinate to 102
    first_button->setPosition(ccp(100*design_scale/scaled+image_size.width/2,
                                  53*design_scale/scaled+image_size.height/2));

    ADMenuItem *next_level = ADMenuItem::create(next_level_image);
    CONNECT(next_level->signalOnClick,
            this, &LevelScenePopUp::onNextLevel);

    next_level->setPosition(ccp(600*design_scale/scaled,
                                53*design_scale/scaled+image_size.height/2));
    menu->addChild(next_level);
    menu->addChild(first_button);

    //Add label
    //    CCSprite* title = 0;
    //    if(current_level->getLevelState() == Level::OneStamp)
    //        title = spl->loadSprite("good.png");
    //    else if(current_level->getLevelState() == Level::TwoStamps)
    //        title = spl->loadSprite("perfect.png");
    //    else
    //        title = spl->loadSprite("excellent.png");

    //    title->setPosition(ccp(409*design_scale/scaled, 445*design_scale/scaled));
    const Solutions& all_found_solutions = _parent->getLevel()->getFoundSolutions();
    Solutions last_solution(1, _solution);
    DisplaySolution* solution = DisplaySolution::create(CCSize(371/scaled, 90/scaled),
                                                        _parent->getLevel(),
                                                        last_solution,
                                                        last_solution);
    unsigned int stamp_ID = 0;
    for(unsigned int i=0; i<all_found_solutions.size(); ++i)
    {
        if(all_found_solutions[i] == _solution)
        {
            stamp_ID = i;
            break;
        }
    }

    this->addChild(solution);
    solution->setAnchorPoint(ccp(0.5f,0.5f));
    solution->setPosition(ccp(409*design_scale/scaled, 445*design_scale/scaled));


    std::vector<CCSprite*> stamps;


    const Stamps level_stamps = current_level->getLevelStamps();
    unsigned int stamps_number = current_level->getSolutions().size();
    CCNode* stamps_zone = 0;
    float max_stamps_zone_width = 605*design_scale/scaled;
    float max_stamps_zone_height = 160*design_scale/scaled;

    if(stamps_number)
    {
        stamps.reserve(stamps_number);
        stamps_zone = CCNode::create();
        SpritesLoader stamps_spl = GraphicsManager::getLoaderFor(stamps_zone,
                                                                 "level/stamps.plist",
                                                                 "level/stamps.png");

        stamps_zone->setContentSize(CCSize(max_stamps_zone_width,
                                           max_stamps_zone_height));
        stamps_zone->setPosition(ccp(414*design_scale/scaled, 289*design_scale/scaled));
        stamps_zone->setAnchorPoint(ccp(0.5f, 0.5f));
        _sheet_menu->addChild(stamps_zone);


        unsigned int level_max_solutions = stamps_number;
        CCSize stamp_size;
        //stamp_size.width *= 0.7f;
        float stamps_scale = 0;

        CCSize new_stamp_size;

        float new_width = new_stamp_size.width * level_max_solutions;
        float new_height = new_stamp_size.height;

        float h_disp = 0;
        float v_dist = 0;

        _crown = 0;

        for(unsigned int i=0; i<stamps_number; ++i)
        {
            CCSprite* sp = 0;
            if(i < level_stamps.size())
            {
                const Stamp& stamp = level_stamps[i];
                sp = stamps_spl->loadSprite(stamp.getFileName().c_str());
                stamps.push_back(sp);
                sp->setRotation(stamp.getRotation());

                if(i == 0)
                {
                    stamp_size = stamps[0]->getContentSize();
                    //stamp_size.width *= 0.7f;
                    stamps_scale = MIN(max_stamps_zone_height / stamp_size.height,
                                             max_stamps_zone_width / stamp_size.width / level_max_solutions);

                    new_stamp_size = CCSize(stamp_size.width * stamps_scale,
                                          stamp_size.height * stamps_scale);

                    new_width = new_stamp_size.width * level_max_solutions;
                    new_height = new_stamp_size.height;

                    h_disp = (max_stamps_zone_width - new_width + new_stamp_size.width) / 2;
                    v_dist = (max_stamps_zone_height - new_height + new_stamp_size.height) / 2;
                }



                sp->setPosition(ccp(h_disp + i * new_stamp_size.width,
                                    v_dist));

                if(stamp.newStamp())
                {
                    if(current_level->getLevelState() == Level::Crown)
                    {
                        //Add crown to last stamp
                        CCSprite* spc = stamps_spl->loadSprite("crown_st.png");
                        spc->setScale(stamps_scale);
                        spc->setPosition(sp->getPosition());

                        spc->setAnchorPoint(ccp(0.5, 0));
                        if(i == stamp_ID)
                        {
                            spc->runAction(getNewStampAction(stamps_scale));
                        }
                        _crown = spc;
                    }
                }
                if(i == stamp_ID)
                {
                    sp->runAction(getNewStampAction(stamps_scale));
                }

            }
            else
            {
                sp = stamps_spl->loadSprite("empty_stamp.png");
                sp->setPosition(ccp(h_disp + i * new_stamp_size.width,
                                    v_dist));

                stamps.push_back(sp);
            }

            sp->setScale(stamps_scale);

        }

    }
    //_parent->setVisible(false);
    _parent->sleep();

    //Tutorial::getInstance()->onSolutionFound(this);

    return true;
}
Beispiel #4
0
    void onCreate(CCNode *parent)
    {

        CCSize size = parent->getContentSize();
        float x_middle = size.width / 2;
        float vertical = size.height * 0.25f;

        CCLabelTTF* label = CCLabelTTF::create(_("SelectColection.BuyFullVerdionPopUp.BuyTitle"),
                                               Fonts::getFontName(),
                                               62);
        label->setFontSize(48);
        label->setPosition(ccp(x_middle, size.height*0.85f));
        parent->addChild(label);

        //add 3 stars
        SpritesLoader spl = GraphicsManager::getLoaderFor(parent,
                                                          "level-end/big_stars.plist",
                                                          "level-end/big_stars.png");
        spl->inject();
        CCSprite* stars_spr = spl->loadSprite("big_stars_3.png");
        stars_spr->setScale(0.75f);
        stars_spr->setPosition(ccp(x_middle, size.height*0.65f));


        //add "or" text
        CCLabelTTF* or_text = CCLabelTTF::create(_("SelectColection.BuyFullVerdionPopUp.OrText"),
                                               Fonts::getFontName(),
                                               40);
        or_text->setPosition(ccp(x_middle, size.height*0.5f));
        parent->addChild(or_text);

        /**
         * @brief menu_spl
         */
        SpritesLoader menu_spl = GraphicsManager::getLoaderFor(0,
                                                               "collection-menu/collection_button.plist",
                                                               "collection-menu/collection_button.png");
        MenuSpriteBatch* menu = MenuSpriteBatch::create(menu_spl);
        menu->setPosition(ccp(0,0));
        menu->setAnchorPoint(ccp(0,0));
        menu->setContentSize(size);
        parent->addChild(menu);

        CCSprite* parent_rgb = (CCSprite*)parent->getChildByTag(123);
        if(parent_rgb)
            parent_rgb->setColor(GameInfo::getInstance()->getNegativeColor());

        CCSprite* coll_button = menu_spl->loadSprite("collection_button.png");

        //coll_button->setScale(coll_button->getContentSize().width/
        //           parent->getContentSize().width*0.6);
        AnimatedMenuItem *buy_item = AnimatedMenuItem::create(
                    coll_button,
                    this, menu_selector(Me::onBuy));
        buy_item->setPosition(ccp(size.width*0.5,
                                  vertical));
        buy_item->setBaseScale(coll_button->getContentSize().width/
                               parent->getContentSize().width*0.8);

        std::string text = _("SelectColection.BuyFullVerdionPopUp.Yes");
        std::string price = ADInApp::getProduct("unlock_full")->getPrice();
        std::string button_buy_text = text +'\n' + price;
        CCLabelTTF * buy_text = CCLabelTTF::create(button_buy_text.c_str(),
                                                          Fonts::getFontName(),
                                                          45);
        buy_text->setColor(ccc3(255,255,255));
        buy_text->setPosition(ccp(buy_item->getContentSize().width/2,
                                  buy_item->getContentSize().height/2));
        buy_item->addChild(buy_text);
        menu->menu()->addChild(buy_item);
    }
Beispiel #5
0
bool LevelStop::init()
{
    //Get the size of the screen we can see
    CCSize visibleSize = ADScreen::getVisibleSize();
    //Get the screen start of cordinates
    CCPoint origin = ADScreen::getOrigin();
    float scaled = ADScreen::getScaleFactor();

    _sheet_target_position = ccp(visibleSize.width/2+origin.x,
                                 visibleSize.height/2+origin.y);

    _sheet_menu=this;
    SpritesLoader spl = GraphicsManager::getLoaderFor(
                this,
                "sheet_menu.plist",
                "sheet_menu.png");
    spl->inject(true);
    CCSprite* sheet = spl->loadSprite("pop_up_paper.png");


    sheet->setPosition(ccp(visibleSize.width/2+origin.x,
                           visibleSize.height/2+origin.y));

    int size_font =45;

    ///////////////////////////////////////////

    CCLabelTTF* resume = CCLabelTTF::create(_("menu.resume"),
                       ADLanguage::getFontName(),
                       size_font);
    resume->setColor(GameInfo::COLOR_DARK_BLUE);
    ADMenuItem* resume_button = ADMenuItem::create(resume);
    CONNECT(resume_button->signalOnClick,
            this, &LevelStop::onResume);

    ///////////////////////////////////////////

    CCLabelTTF* restart = CCLabelTTF::create(_("menu.restart"),
                       ADLanguage::getFontName(),
                       size_font);
    restart->setColor(GameInfo::COLOR_DARK_BLUE);

    ADMenuItem* restart_button = ADMenuItem::create(restart);
    CONNECT(restart_button->signalOnClick,
            this, &LevelStop::onRestart);

    ///////////////////////////////////////////

    CCLabelTTF* skip_level = CCLabelTTF::create(_("menu.skip_level"),
                       ADLanguage::getFontName(),
                       size_font);
    skip_level->setColor(GameInfo::COLOR_DARK_BLUE);

    ADMenuItem* skip_button = ADMenuItem::create(skip_level);
    CONNECT(skip_button->signalOnClick,
            this, &LevelStop::onSkipLevel);

    ///////////////////////////////////////////

    CCLabelTTF* found_solutions = CCLabelTTF::create(_("menu.found_solutions"),
                       ADLanguage::getFontName(),
                       size_font*0.85f);
    found_solutions->setColor(GameInfo::COLOR_DARK_BLUE);
    ADMenuItem* found_solutions_button = ADMenuItem::create(found_solutions);
    CONNECT(found_solutions_button->signalOnClick,
            this, &LevelStop::onFoundSolutions);

    ///////////////////////////////////////////

    CCLabelTTF* levels = CCLabelTTF::create(_("menu.levels"),
                       ADLanguage::getFontName(),
                       size_font);
    levels->setColor(GameInfo::COLOR_RED);
    ADMenuItem* levels_button = ADMenuItem::create(levels);
    CONNECT(levels_button->signalOnClick,
            this, &LevelStop::onLevels);


    CCMenu* menu = CCMenu::create();
    // menu->setPosition(ccp(visibleSize.width/2+origin.x,
    //visibleSize.height/2+origin.y+scaled/20));

    menu->addChild(resume_button);
    menu->addChild(restart_button);
    menu->addChild(skip_button);
    menu->addChild(found_solutions_button);
    menu->addChild(levels_button);

    this->addChild(menu);

    menu->alignItemsVerticallyWithPadding(30/scaled);
    menu->setPosition(ccp(visibleSize.width/2 + origin.x,
                          visibleSize.height/2 + origin.y - 20/scaled));




    this->setPosition(ccp(this->getPosition().x,
                          this->getPositionY()+visibleSize.height));

    //CCSize visibleSize = ADScreen::getVisibleSize();
    this->runAction(
                CCMoveTo::create(
                    0.15f,
                    ccp(this->getPositionX(),
                        this->getPositionY()- visibleSize.height))
                );
    return true;
}