Esempio n. 1
0
bool GameScene::init()
{
	if(Scene::initWithPhysics())
	{
	//	this->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
		this->getPhysicsWorld()->setGravity(Vect(0, -900));

		// Add the background
		auto backgroundLayer = BackgroundLayer::create();
		if(backgroundLayer) 
		{
			this->addChild(backgroundLayer);
		}

		auto statusLayer = StatusLayer::create();

		// Add the main game layer
		auto gameLayer = GameLayer::create();
		if(gameLayer) 
		{
			gameLayer->setPhyWorld(this->getPhysicsWorld());
			gameLayer->setDelegator(statusLayer);
			this->addChild(gameLayer);
		}

		// Add the game status layer to show the score and game status
		if(statusLayer) 
		{
			this->addChild(statusLayer);
		}

		// Add operation layer to control the game
		auto optionLayer = OptionLayer::create();
		if(optionLayer) 
		{
			optionLayer->setDelegator(gameLayer);
			this->addChild(optionLayer);
		}
		return true;
	}
	else 
	{
		return false;
	}
}
Esempio n. 2
0
bool GameScene::init()
{
	if(Scene::initWithPhysics())
	{
		//this->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
		this->getPhysicsWorld()->setGravity(Vect(0,-900));
	}

	//Ìí¼Ó±³¾°
	auto backgroundLayer=BackgroundLayer::create();
	if(backgroundLayer)
	{
		this->addChild(backgroundLayer);
	}
	
	auto statusLayer=StatusLayer::create();

	//Ìí¼ÓÖ÷ÓÎÏ·²ã
	auto gameLayer = GameLayer::create();
	if(gameLayer) 
	{
		gameLayer->setPhyWorld(this->getPhysicsWorld());
		gameLayer->setDelegator(statusLayer);
		this->addChild(gameLayer);
	}

	//Ìí¼ÓÓÎϷ״̬²ã
	if(statusLayer)
	{
		this->addChild(statusLayer);
	}

	//Ìí¼Ó¿ØÖƲã
	auto optionLayer=OptionLayer::create();
	if(optionLayer)
	{
		optionLayer->setDelegator(gameLayer);
		this->addChild(optionLayer);
	}

	return true;
}
Esempio n. 3
0
bool GameScene::init()
{
	bool bRet = false;
	do 
	{
		CC_BREAK_IF(!Scene::initWithPhysics());
		this->getPhysicsWorld()->setGravity(Vect(0, -900));

		auto backgroundLayer = BackgroundLayer::create();
		if(backgroundLayer) {
			this->addChild(backgroundLayer);
		}

		auto statusLayer = StatusLayer::create();
		auto gameLayer = GameLayer::create();
		if(gameLayer) {
			gameLayer->setPhyWorld(this->getPhysicsWorld());
			gameLayer->setDelegator(statusLayer);
			this->addChild(gameLayer);
		}

		if(statusLayer) {
			this->addChild(statusLayer);
		}


		
		auto optionLayer = OptionLayer::create();
		if(optionLayer) {
			optionLayer->setDelegator(gameLayer);
			this->addChild(optionLayer);
		}
		
		bRet = true;
	} while (0);

	return bRet;
}
bool MainScene::init(){
    if(!Scene::init()){
        return false;
    }
    Size visibleSize = Director::getInstance()->getVisibleSize();

    SpriteFrameCache::getInstance()->addSpriteFramesWithFile("newAlwaysShow.plist");
    SpriteFrameCache::getInstance()->addSpriteFramesWithFile("UI/res_fx/normal_bullet.plist");
    SpriteFrameCache::getInstance()->addSpriteFramesWithFile("newCommon.plist");
    SpriteFrameCache::getInstance()->addSpriteFramesWithFile("newBattle.plist");
    SpriteFrameCache::getInstance()->addSpriteFramesWithFile("nopack/qiancengta.plist");//出新英雄的背景
    
    auto btnFrame_normal = Sprite::createWithSpriteFrameName("btn_dibuzhukong_normal.png");
    auto btnFrame_clicked = Sprite::createWithSpriteFrameName("btn_dibuzhukong_highlight.png");
    auto btnFrame_normal2 = Sprite::createWithSpriteFrameName("btn_dibuzhukong_normal.png");
    auto btnFrame_clicked2 = Sprite::createWithSpriteFrameName("btn_dibuzhukong_highlight.png");
    auto btnFrame_normal3 = Sprite::createWithSpriteFrameName("btn_dibuzhukong_normal.png");
    auto btnFrame_clicked3 = Sprite::createWithSpriteFrameName("btn_dibuzhukong_highlight.png");
    auto btnFrame_normal4 = Sprite::createWithSpriteFrameName("btn_dibuzhukong_normal.png");
    auto btnFrame_clicked4 = Sprite::createWithSpriteFrameName("btn_dibuzhukong_highlight.png");
    auto btnFrame_normal5 = Sprite::createWithSpriteFrameName("btn_dibuzhukong_normal.png");
    auto btnFrame_clicked5 = Sprite::createWithSpriteFrameName("btn_dibuzhukong_highlight.png");

    auto liangshan = Sprite::createWithSpriteFrameName("btn_liangshan.png");
    auto zhenrong = Sprite::createWithSpriteFrameName("icon_zhenrong.png");
    auto zhengzhan = Sprite::createWithSpriteFrameName("icon_zhengzhan.png");
    auto xingxia = Sprite::createWithSpriteFrameName("icon_xingxia.png");
    auto shop = Sprite::createWithSpriteFrameName("icon_shangdian.png");
    //加上下边框
    SpriteFrameCache::getInstance()->addSpriteFramesWithFile("gameFrame.plist");
    auto upFrame = Sprite::createWithSpriteFrameName("icon_shanghuabian.png");
    auto downFrame = Sprite::createWithSpriteFrameName("icon_xiahuabian.png");
    downFrame->setPosition(visibleSize.width/2,downFrame->getContentSize().height/2);
    upFrame->setPosition(visibleSize.width/2,visibleSize.height-upFrame->getContentSize().height/2);
    this->addChild(downFrame,2);
    this->addChild(upFrame,2);
    //加入所有底层功能
    auto liangshan2 = Sprite::createWithSpriteFrameName("btn_liangshan.png");
    liangshan2->setScale(0.8f);
    btnFrame_normal->addChild(liangshan);
    btnFrame_clicked->addChild(liangshan2);
    auto btn1 = MenuItemSprite::create(btnFrame_normal,btnFrame_clicked,CC_CALLBACK_1(MainScene::bottomFunction,this));
    
    liangshan->setPosition(btn1->getContentSize().width/2,btn1->getContentSize().height/2);
    liangshan2->setPosition(btn1->getContentSize().width/2,btn1->getContentSize().height/2);
    
    auto zhenrong2 = Sprite::createWithSpriteFrameName("icon_zhenrong.png");
    zhenrong2->setScale(0.8f);
    btnFrame_normal2->addChild(zhenrong);
    btnFrame_clicked2->addChild(zhenrong2);
    auto btn2 = MenuItemSprite::create(btnFrame_normal2,btnFrame_clicked2,CC_CALLBACK_1(MainScene::bottomFunction,this));
    zhenrong->setPosition(btn2->getContentSize().width/2,btn2->getContentSize().height/2);
    zhenrong2->setPosition(btn2->getContentSize().width/2,btn2->getContentSize().height/2);

    auto zhengzhan2 = Sprite::createWithSpriteFrameName("icon_zhengzhan.png");
    zhengzhan2->setScale(0.8f);
    btnFrame_normal3->addChild(zhengzhan);
    btnFrame_clicked3->addChild(zhengzhan2);
    auto btn3 = MenuItemSprite::create(btnFrame_normal3,btnFrame_clicked3,CC_CALLBACK_1(MainScene::bottomFunction,this));
    zhengzhan->setPosition(btn2->getContentSize().width/2,btn2->getContentSize().height/2);
    zhengzhan2->setPosition(btn2->getContentSize().width/2,btn2->getContentSize().height/2);
    
    auto xingxia2 = Sprite::createWithSpriteFrameName("icon_xingxia.png");
    xingxia2->setScale(0.8f);
    btnFrame_normal4->addChild(xingxia);
    btnFrame_clicked4->addChild(xingxia2);
    auto btn4 = MenuItemSprite::create(btnFrame_normal4,btnFrame_clicked4,CC_CALLBACK_1(MainScene::bottomFunction,this));
    xingxia->setPosition(btn2->getContentSize().width/2,btn2->getContentSize().height/2);
    xingxia2->setPosition(btn2->getContentSize().width/2,btn2->getContentSize().height/2);
    
    auto shop2 = Sprite::createWithSpriteFrameName("icon_shangdian.png");
    shop2->setScale(0.8f);
    btnFrame_normal5->addChild(shop);
    btnFrame_clicked5->addChild(shop2);
    auto btn5 = MenuItemSprite::create(btnFrame_normal5,btnFrame_clicked5,CC_CALLBACK_1(MainScene::bottomFunction,this));
    shop->setPosition(btn2->getContentSize().width/2,btn2->getContentSize().height/2);
    shop2->setPosition(btn2->getContentSize().width/2,btn2->getContentSize().height/2);
    
    //liangshan1->setTag(11);
    /*auto menu2 = Menu::create(liangshan1,zhenrong1,zhengzhan1,xingxia1,shop1,NULL);
    menu2->alignItemsHorizontallyWithPadding(0.0f);
    menu2->setPosition(visibleSize.width/2,btn1->getContentSize().height/2+downFrame->getContentSize().height-2);
    this->addChild(menu2);
    */
    menu1 = Menu::create(btn1,btn2,btn3,btn4,btn5,NULL);
    menu1->alignItemsHorizontally();
    menu1->alignItemsHorizontallyWithPadding(0.0f);
    menu1->setPosition(visibleSize.width/2,btn1->getContentSize().height/2+downFrame->getContentSize().height-2);
    this->addChild(menu1,2,MAIN_MENU_TAG);
//底层功能TAG
    btn1->setTag(11);
    btn2->setTag(12);
    btn3->setTag(13);
    btn4->setTag(14);
    btn5->setTag(15);
    
//TO DO....阵型   &   武将列表
    SpriteFrameCache::getInstance()->addSpriteFramesWithFile("more.plist");
    auto zhenxing = Sprite::createWithSpriteFrameName("icon_zhanghaoshezhi.png");
    auto zhenxingitem = MenuItemSprite::create(zhenxing, zhenxing, CC_CALLBACK_1(MainScene::showZhenXing,this));
    auto wujiang = Sprite::createWithSpriteFrameName("icon_tujian.png");
    auto wujiangitem = MenuItemSprite::create(wujiang, wujiang, CC_CALLBACK_1(MainScene::showTeamList,this));
    auto menu4 = Menu::create(zhenxingitem,wujiangitem,NULL);
    menu4->alignItemsHorizontally();
    menu4->setPosition(visibleSize.width/4,194+zhenxing->getContentSize().height);
    this->addChild(menu4,2);
    
//攻城列队
    auto gongcheng = Sprite::createWithSpriteFrameName("icon_bangzhu.png");
    auto gongchengitem = MenuItemSprite::create(gongcheng, gongcheng, CC_CALLBACK_1(MainScene::showGongchengTeam,this));
    auto menu5 = Menu::create(gongchengitem,NULL);
    menu5->setPosition(Vec2::ZERO);
    gongchengitem->setPosition(visibleSize.width/2,194+zhenxing->getContentSize().height);
    this->addChild(menu5,2);

//背景
    auto bg = Sprite::create("building.jpeg");
	bg->setPosition(visibleSize.width/2, visibleSize.height/2);
    this->addChild(bg,1);
    auto topleft = Sprite::createWithSpriteFrameName("bg-banner_top_left.png");
    auto topright = Sprite::createWithSpriteFrameName("bg-banner_top_right.png");
    topleft->setAnchorPoint(Vec2(0,1));
    topright->setAnchorPoint(Vec2(1,1));
    topleft->setPosition(0,visibleSize.height-upFrame->getContentSize().height+2);
    topright->setPosition(visibleSize.width,visibleSize.height-upFrame->getContentSize().height+2);
    this->addChild(topleft,2);
    this->addChild(topright,2);
    
//用户等级,名字,银两,声望------------
    char wenzi[32];
    sprintf(wenzi,"%d",99);
    auto level = Label::createWithTTF(wenzi, "字体/华文新魏.TTF", 24);
    auto name = Label::createWithTTF("十八罗汉", "字体/华文新魏.TTF", 24);
    level->setPosition(40,visibleSize.height-upFrame->getContentSize().height-topleft->getContentSize().height/4);
    name->setPosition(50+name->getContentSize().width/2+30,visibleSize.height-upFrame->getContentSize().height-topleft->getContentSize().height/4);
    this->addChild(level,3,USERLEVEL_TAG);
    this->addChild(name,3,USERNAME_TAG);
    
    sprintf(wenzi,"%d",99999);
    auto money = Label::createWithTTF(wenzi, "字体/华文新魏.TTF", 24);
    money->setPosition(visibleSize.width/2+50+money->getContentSize().width/2,visibleSize.height-upFrame->getContentSize().height-topright->getContentSize().height*3/4);
    this->addChild(money,3,USERMONEY_TAG);
    
    sprintf(wenzi,"%d",99999);
    auto reputation = Label::createWithTTF(wenzi, "字体/华文新魏.TTF", 24);
    reputation->setPosition(visibleSize.width*3/4+50+reputation->getContentSize().width/2,visibleSize.height-upFrame->getContentSize().height-topright->getContentSize().height*3/4);
    this->addChild(reputation,3,USERREPUTATION_TAG);

//抽将功能页面HelloWorldLayer加载,MainLayer没用可以删掉
    //TO DO...抽装备选项
    auto _HelloWorldLayer = HelloWorldLayer::create();
    auto _MainLayer = MainLayer::create();
    if(_HelloWorldLayer){
        _HelloWorldLayer->setDelegator(_MainLayer);
        this->addChild(_HelloWorldLayer,1,HELLOWORLD_LAYER_TAG);
    }
    if(_MainLayer)
        this->addChild(_MainLayer,1);
    
//载入数据-----------------------
    //string dou = FileUtils::getInstance()->fullPathForFilename("wholeheros.db");
    //log("存放路径为%s",dou.c_str());
    //string documentpath1 = FileUtils::getInstance()->fullPathForFilename("UserInfo.db");
    
    log("存放路径为%s",documentpath1.c_str());
    GameStat::getInstance()->readFromUserInfo("Users_Info", documentpath1.c_str());
    GameStat::getInstance()->readFromUserHeros("User_hero", documentpath1.c_str(), 0);

    char sql[1024];
    sprintf(sql, "select * from User_equip where username = \"%s\"", user_name.c_str());//根据用户名读取英雄
    GameStat::getInstance()->readfromEquipInfo("User_equip", documentpath1.c_str(),sql);
    
    //将玩家信息:等级、名字、银两、声望、元宝等从服务器加载
    MainScene::resetUserInfo();
    
//-------------------------------

//载入攻城车
    GongChengType gongcheng1;
    gongcheng1.engname = "gongchengche";
    gongcheng1.type = 1;
    gongcheng1.attack = 210;
    gongcheng1.durable = 4;
    gongcheng1.attack_type = 1;
    gongcheng1.bullet_type = 1;
    GongChengType gongcheng2;
    gongcheng2.engname = "toushiche";
    gongcheng2.type = 1;
    gongcheng2.attack = 240;
    gongcheng2.durable = 3;
    gongcheng2.attack_type = 1;
    gongcheng2.bullet_type = 1;
    
    GongChengType gongcheng3;
    gongcheng3.engname = "paoshiche";
    gongcheng3.type = 1;
    gongcheng3.attack = 260;
    gongcheng3.durable = 3;
    gongcheng3.attack_type = 1;
    gongcheng3.bullet_type = 1;
    GongChengType gongcheng4;
    gongcheng4.engname = "nuche";
    gongcheng4.type = 2;
    
    gongcheng4.attack = 210;
    gongcheng4.durable = 5;
    gongcheng4.attack_type = 1;
    gongcheng4.bullet_type = 2;
    
    GongChengType gongcheng5;
    gongcheng5.engname = "junuche";
    gongcheng5.type = 2;
    gongcheng5.attack = 350;
    gongcheng5.durable = 3;
    gongcheng5.attack_type = 1;
    gongcheng5.bullet_type = 2;
    
    GongChengType gongcheng6;
    gongcheng6.engname = "liannu";
    gongcheng6.type = 2;
    gongcheng6.attack = 200;
    gongcheng6.durable = 5;
    gongcheng6.attack_type = 3;
    gongcheng6.bullet_type = 2;
    GameStat::getInstance()->userqixie.push_back(gongcheng1);
    GameStat::getInstance()->userqixie.push_back(gongcheng2);
    GameStat::getInstance()->userqixie.push_back(gongcheng3);
    GameStat::getInstance()->userqixie.push_back(gongcheng4);
    GameStat::getInstance()->userqixie.push_back(gongcheng5);
    GameStat::getInstance()->userqixie.push_back(gongcheng6);
    
    //敌军守城器械赋值
    GameStat::getInstance()->enemyCompeteQixie[0] = gongcheng6;
    GameStat::getInstance()->enemyCompeteQixie[0].position = 0;
    
    GameStat::getInstance()->enemyCompeteQixie[1] = gongcheng5;
    GameStat::getInstance()->enemyCompeteQixie[1].position = 1;
    
    GameStat::getInstance()->enemyCompeteQixie[2] = gongcheng4;
    GameStat::getInstance()->enemyCompeteQixie[2].position = 2;
    

//进入新手指导
    __NotificationCenter::getInstance()->addObserver(this, callfuncO_selector(MainScene::receive_notice_from_battle), "newPlayer", NULL);//一般是从战斗场景跳回调用
    if(in_newplayer_mode)
        MainScene::newPlayerStart(new_stage);

    return true;
}