Shooting::Shooting(){ gameClock = 0; fpsTimer = GetNowCount(); addHero(); addHero(); addHero(); addHero(); }
void HeroPageScrollView::updateCheck() { int id = getCurrentNodeId(); if(id < cashe || id > size-cashe-1 )return; for(int i = 1 ; i <= cashe ; i++) if(!nodes.count(id - i*direction))addHero(id - i*direction); }
void HeroPageScrollView::setCurrentNode(int nodeId) { content->setPositionX(-nodeId*page.width); for(int i = 0 ; i < cashe*2+1 ; i++) if(nodeId-cashe+i >=0 && nodeId-cashe+i < size)addHero(nodeId-cashe+i); nodes[nodeId]->setOpacity(255); moveTargetId = nodeId; }
bool parseDotaData (char const* dest, char const* path) { MPQARCHIVE map = MPQOpen (path, MPQFILE_READ); if (map == 0) map = MPQOpen (mprintf ("%s%s", warPath, path), MPQFILE_READ); if (map == 0) { if (useropen) MessageBox (NULL, mprintf ("Could not locate %s", path), "Error", MB_OK | MB_ICONHAND); return false; } MPQAddArchive (warloader, map); CProgressDlg* prg = ((CDotAReplayApp*) ::AfxGetApp ())->progress; char title[256]; _splitpath (path, NULL, NULL, title, NULL); prg->SetSupText (mprintf ("Parsing %s", title), 0); prg->SetSubText ("Parsing object data..."); prg->show (); GameData data; LoadGameData (data, warloader, WC3_LOAD_UNITS | WC3_LOAD_ITEMS | WC3_LOAD_ABILITIES); resetData (); bool ok = true; dir = NULL; idir = NULL; reset_id (); int tavernCount = 0; prg->SetSubText ("Parsing taverns and shops...", 40); for (int i = 0; i < data.data[WC3_UNITS]->getNumUnits (); i++) { UnitData* tav = data.data[WC3_UNITS]->getUnit (i); if (tav != NULL) { char const* name = tav->getStringData ("Name"); for (int ti = 0; ti < numTaverns; ti++) { if (!stricmp (taverns[ti].name, name)) { tavernCount++; char const* herolist = tav->getData ("Sellunits"); for (int p = 0; herolist[p];) { static char _id[5]; int idl = 0; for (; idl < 4 && herolist[p]; idl++, p++) _id[idl] = herolist[p]; if (idl == 4) { _id[4] = 0; if (getValue (dir, _id) == 0) { UnitData* hero = data.data[WC3_UNITS]->getUnitById (_id); if (hero) addHero (data.data[WC3_ABILITIES], hero, ti); dir = addString (dir, _id, 1); } } if (herolist[p] == ',') p++; else break; } } } for (int si = 0; si < numShops; si++) { if (!stricmp (shops[si].name, name)) { for (int m = 0; m < 2; m++) { char const* itemlist = tav->getData (m ? "Sellitems" : "Sellunits"); for (int p = 0; itemlist[p];) { static char _id[5]; int idl = 0; for (; idl < 4 && itemlist[p]; idl++, p++) _id[idl] = itemlist[p]; if (idl == 4) { _id[4] = 0; if (getValue (dir, _id) == 0) { UnitData* item = data.data[m ? WC3_ITEMS : WC3_UNITS]->getUnitById (_id); if (item) if (addSoldItem (item)) dir = addString (dir, _id, 1); } } if (itemlist[p] == ',') p++; else break; } } break; } } } } if (tavernCount == 0) { for (int i = 0; i < data.data[WC3_UNITS]->getNumUnits (); i++) { UnitData* tav = data.data[WC3_UNITS]->getUnit (i); if (tav != NULL) { char const* name = tav->getStringData ("Name"); for (int ti = 0; ti < numOldTaverns; ti++) { if (!stricmp (oldTaverns[ti], name)) { char const* herolist = tav->getData ("Sellunits"); for (int p = 0; herolist[p];) { static char _id[5]; int idl = 0; for (; idl < 4 && herolist[p]; idl++, p++) _id[idl] = herolist[p]; if (idl == 4) { _id[4] = 0; if (getValue (dir, _id) == 0) { UnitData* hero = data.data[WC3_UNITS]->getUnitById (_id); if (hero) addHero (data.data[WC3_ABILITIES], hero, ti); dir = addString (dir, _id, 1); } } if (herolist[p] == ',') p++; else break; } } } } } } prg->SetSubText ("Parsing items...", 60); for (int i = 0; i < numItems; i++) { if (items[i].index == 0) continue; if (items[i].type == ITEM_RECIPE) { // parse recipe UnitData* unit = data.data[WC3_ITEMS]->getUnitById (items[i].ids[0]); if (unit == NULL) unit = data.data[WC3_UNITS]->getUnitById (items[i].ids[0]); if (unit) { char const* descr = strstr (unit->getStringData ("Ubertip"), "Requires:"); if (descr && (strstr (descr, "Any of the following") || strstr (descr, "Staff of Wizardry and Blade of Alacrity"))) { // scepter int scepter = items[items[i].realid].ids[0]; int recipe = items[i].ids[0]; int booster = _getItemByName ("Point Booster"); int axe = _getItemByName ("Ogre Axe"); int blade = _getItemByName ("Blade of Alacrity"); int staff = _getItemByName ("Staff of Wizardry"); recipes[numRecipes].recipeid = recipe; recipes[numRecipes].result = scepter; recipes[numRecipes].numsrc = 4; recipes[numRecipes].srcid[0] = recipe; recipes[numRecipes].srccount[0] = 1; recipes[numRecipes].srcid[1] = booster; recipes[numRecipes].srccount[1] = 1; recipes[numRecipes].srcid[2] = axe; recipes[numRecipes].srccount[2] = 1; recipes[numRecipes].srcid[3] = blade; recipes[numRecipes].srccount[3] = 1; numRecipes++; recipes[numRecipes].recipeid = recipe; recipes[numRecipes].result = scepter; recipes[numRecipes].numsrc = 4; recipes[numRecipes].srcid[0] = recipe; recipes[numRecipes].srccount[0] = 1; recipes[numRecipes].srcid[1] = booster; recipes[numRecipes].srccount[1] = 1; recipes[numRecipes].srcid[2] = axe; recipes[numRecipes].srccount[2] = 1; recipes[numRecipes].srcid[3] = staff; recipes[numRecipes].srccount[3] = 1; numRecipes++; recipes[numRecipes].recipeid = recipe; recipes[numRecipes].result = scepter; recipes[numRecipes].numsrc = 4; recipes[numRecipes].srcid[0] = recipe; recipes[numRecipes].srccount[0] = 1; recipes[numRecipes].srcid[1] = booster; recipes[numRecipes].srccount[1] = 1; recipes[numRecipes].srcid[2] = staff; recipes[numRecipes].srccount[2] = 1; recipes[numRecipes].srcid[3] = blade; recipes[numRecipes].srccount[3] = 1; numRecipes++; } else if (descr) { recipes[numRecipes].numsrc = 0; recipes[numRecipes].recipeid = 0; if (items[i].cost) { recipes[numRecipes].srccount[0] = 1; recipes[numRecipes].srcid[0] = items[i].ids[0]; recipes[numRecipes].numsrc = 1; recipes[numRecipes].recipeid = items[i].ids[0]; } recipes[numRecipes].result = items[items[i].realid].ids[0]; int num = 0; int pos = 0; int prev = 0; bool prevOr = false; while (true) { if (descr[pos] == 0 || (descr[pos] == '|' && descr[pos + 1] == 'n')) { if (num) { char* iname = strip_item (descr + prev, pos - prev); int count = 1; bool hasx = false; if (*iname >= '0' && *iname <= '9') { count = atoi (iname); while (*iname && *iname != ' ') { if (*iname == 'x') hasx = true; iname++; } while (*iname == ' ') iname++; } if (count > 1) { int len = (int) strlen (iname); if (len && iname[len - 1] == 's') iname[--len] = 0; } int upgrLen = (int) strlen ("Buy recipe to upgrade ("); if (!stricmp (iname, "or")) prevOr = true; else if (!strnicmp (iname, "Buy recipe to upgrade (", upgrLen)) { int levels = atoi (iname + upgrLen); int iid = items[i].realid; for (int lvl = 2; lvl <= levels; lvl++) { numRecipes++; recipes[numRecipes].numsrc = 2; recipes[numRecipes].srcid[0] = recipes[numRecipes - 1].srcid[0]; recipes[numRecipes].srccount[0] = 1; recipes[numRecipes].srcid[1] = recipes[numRecipes - 1].result; recipes[numRecipes].srccount[1] = 1; items[numItems].ids[0] = new_id (); recipes[numRecipes].result = items[numItems].ids[0]; items[numItems].numIds = 1; sprintf (items[numItems].name, "%s %d", items[iid].name, lvl); strcpy (items[numItems].imgTag, items[iid].imgTag); items[numItems].index = numItems; items[numItems].type = ITEM_COMBO; items[numItems].realid = i; items[numItems].cost = 0; idir = saddString (idir, items[numItems].name, numItems + 1); numItems++; } strcat (items[iid].name, " 1"); idir = saddString (idir, items[iid].name, iid + 1); } else { int cpos = sgetValue (idir, iname) - 1; if (cpos >= 0) { if (prevOr) { memcpy (&recipes[numRecipes + 1], &recipes[numRecipes], sizeof recipes[0]); numRecipes++; recipes[numRecipes].srcid[recipes[numRecipes].numsrc - 1] = items[cpos].ids[0]; recipes[numRecipes].srccount[recipes[numRecipes].numsrc - 1] = count; } else { recipes[numRecipes].srcid[recipes[numRecipes].numsrc] = items[cpos].ids[0]; recipes[numRecipes].srccount[recipes[numRecipes].numsrc] = count; recipes[numRecipes].numsrc++; } prevOr = false; } } } num++; if (descr[pos] == 0) break; pos += 2; prev = pos; } else pos++; } if (recipes[numRecipes].numsrc) numRecipes++; } } } } for (int i = 0; i < data.data[WC3_ITEMS]->getNumUnits (); i++) { UnitData* item = data.data[WC3_ITEMS]->getUnit (i); if (item != NULL) mergeItemName (item); } for (int i = 0; i < data.data[WC3_UNITS]->getNumUnits (); i++) { UnitData* item = data.data[WC3_UNITS]->getUnit (i); if (item != NULL) mergeItemName (item); } prg->SetSubText ("Parsing upgradeable abilities...", 80); for (int i = 0; i < data.data[WC3_ABILITIES]->getNumUnits (); i++) { UnitData* abil = data.data[WC3_ABILITIES]->getUnit (i); if (abil != NULL && !strcmp (abil->getStringData ("code"), "ANeg")) addEngineering (abil); } prg->SetSubText ("Computing recipe costs...", 90); for (int i = 0; i < numRecipes; i++) { int res = getItemById (recipes[i].result)->index; if (res > 0 && items[res].type >= 0) { items[res].cost = 0; items[res].type = -items[res].type; } } for (int maxc = 0; maxc < 20; maxc++) { bool total = true; for (int i = 0; i < numRecipes; i++) { int res = getItemById (recipes[i].result)->index; if (res > 0 && items[res].type < 0) { bool ok = true; items[res].cost = 0; for (int j = 0; j < recipes[i].numsrc; j++) { int comp = getItemById (recipes[i].srcid[j])->index; if (comp > 0) { if (items[comp].type < 0) { ok = false; break; } else items[res].cost += items[comp].cost * recipes[i].srccount[j]; } } if (!ok) total = false; else items[res].type = ITEM_COMBO; } } if (total) break; } //FILE* log = fopen ("recipes.txt", "wt"); //for (int i = 0; i < numRecipes; i++) //{ // int res = getItemById (recipes[i].result)->index; // if (res <= 0) continue; // fprintf (log, "%s =", items[res].name); // for (int j = 0; j < recipes[i].numsrc; j++) // { // int comp = getItemById (recipes[i].srcid[j])->index; // if (comp > 0) // fprintf (log, " %s x%d", items[comp].name, recipes[i].srccount[j]); // } // fprintf (log, "\n"); //} //fclose (log); delete dir; delete idir; MPQRemoveArchive (warloader, map); MPQClose (map); prg->hide (); if (!ok) return false; return saveDotaData (dest); }
bool GameScene::init(){ if (!Layer::init()){ return false; } //此处测试MyMap地图 sGlobal->mapNum = 0; sGlobal->caseNum = 0; MyMap* myMap = MyMap::create(); sGlobal->map = myMap->m_map; sGlobal->myMap = myMap; this->addChild(myMap,5,sGlobal->mapNum); this->addChild(myMap->m_map,6,"map"); ////加载Tiled地图,添加到层中 ////地图是层的child //TMXTiledMap*map = TMXTiledMap::create("scene12test.tmx"); ///*map->setAnchorPoint(Point(0, 0));*/ ///*map->setPosition(Point(0,0));*/ //this->addChild(map,5,"map"); //sGlobal->map = map; ControllerLayer*controllerLayer = ControllerLayer::create(); this->addChild(controllerLayer,20); //测试Hero类,包括对其的添加和动画的正常运行 addHero(myMap->m_map,Point(100,100)); log("这是斜杠n/n,而这是反斜杠n\nhehe"); //此处正式测试菜单 //创建精灵便于getContentSize()函数调用 auto menuLogo = Sprite::create("MenuWhenTouched.png"); Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); auto menuLogoBag = Menu::create(MenuItemImage::create("MenuWhenEased.png", "MenuWhenTouched.png", [&](Object* obj){ //此处切换成菜单层 auto menuLayer = MenuLayer::create();//创建菜单层 this->getParent()->addChild(menuLayer, 10, "tag");//把菜单层添加到游戏场景中 }), NULL); menuLogoBag->setGlobalZOrder(128); //设置位置锚点并添加 menuLogoBag->setAnchorPoint(Point(0, 0)); menuLogoBag->setPosition(Point(menuLogo->getContentSize().width / 2, (visibleSize.height) - (menuLogo->getContentSize().height / 2 + 10))); this->addChild(menuLogoBag, 6); ///*此处测试对话 //TalkLayer* talkLayer = TalkLayer::create(); //this->addChild(talkLayer,60);*/ ////此处测试菜单窗口 //MenuLayer*menuLayer = MenuLayer::create(); //this->addChild(menuLayer, 200); ////此处测试动画 //Sprite*runSp = Sprite::createWithSpriteFrame(SpriteFrame::create("Hero_Down_0.png", Rect(0, 0, 32, 32))); //runSp->setPosition(Point(300, 500)); //this->addChild(runSp,7); ////加载图片帧到缓存池 //SpriteFrameCache*frameCache = SpriteFrameCache::getInstance(); //frameCache->addSpriteFramesWithFile("Hero.plist", "Hero.png"); ////用 AnimationUtil类创建动画 //Animation*animation = AnimationUtil::createWithSingleFrameNameSmall("Hero", "Up", 0.1f, -1); //runSp->runAction(Animate::create(animation)); //auto menu1 = Menu::create(MenuItemImage::create("LoadWhenEased.png", "LoadWhenTouched.png", [&](Object* obj){ // //此处测试切换成菜单层 // /*auto layer2 = Layer::create();*/ // auto layer2 = Layer::create(); // TMXTiledMap*map1 = TMXTiledMap::create("scene13.tmx"); // layer2->addChild(map1); // // this->getParent()->addChild(layer2,10,"tag"); // //此处测试菜单层的删除 // auto menu2 = Menu::create(MenuItemImage::create("LoadWhenEased.png", "LoadWhenTouched.png", [&](Object* obj){ // this->getParent()->removeChildByName("tag"); // }), NULL); // Size size2 = Director::sharedDirector()->getWinSize(); // menu2->setPosition(ccp(size2.width / 4, size2.height / 2)); // layer2->addChild(menu2, 6); //载入按钮 //}), NULL); //Size size = Director::sharedDirector()->getWinSize(); //menu1->setPosition(ccp(size.width / 4, size.height / 3)); //this->addChild(menu1, 6); //载入按钮 /*bool s = sGlobal->load; if (sGlobal->load){ Point loadPosition = Point(CCUserDefault::sharedUserDefault()->getIntegerForKey("heroPositionX"), CCUserDefault::sharedUserDefault()->getIntegerForKey("heroPositionY")); int mapNum = CCUserDefault::sharedUserDefault()->getIntegerForKey("mapNum"); for (int i = 0; i <= 17; i++){ bool a = CCUserDefault::sharedUserDefault()->getBoolForKey((StringUtils::format("bool_%d", i)).c_str()); sGlobal->hero->plot[i] = CCUserDefault::sharedUserDefault()->getBoolForKey((StringUtils::format("bool_%d", i)).c_str()); } this->changeMap(loadPosition, mapNum); sGlobal->load = 0; }*/ return true; }