void ScenarioTest::doAutoTest()
{
    isStating = false;
    statCount = 0;
    totalStatTime = 0.0f;
    minFrameRate = -1.0f;
    maxFrameRate = -1.0f;
    
    // remove all nodes
    while (_spriteArray.size() > 0) {
        removeSprites();
    }
    while (_parsysArray.size() > 0) {
        removeParticleSystem();
    }
    
    // add nodes
    auto caseInfo = autoTestCounts[autoTestIndex];
    _particleNumber = 0;
    addNewSprites(caseInfo.spriteCount);
    addParticleSystem(caseInfo.particleSystemCount);
    addParticles(caseInfo.particleCount);

    schedule(CC_SCHEDULE_SELECTOR(ScenarioTest::beginStat), DELAY_TIME);
    schedule(CC_SCHEDULE_SELECTOR(ScenarioTest::endStat), DELAY_TIME + STAT_TIME);
}
示例#2
0
void VRope::destroiyRope(){
    if (mJoint != NULL && bodyA != NULL && bodyB != NULL) {
        mWorld->DestroyJoint(mJoint);
        mJoint = NULL;
    }
    
    for(size_t i=0;i<vPoints.size();i++) {
        delete vPoints[i];
	}
    
    vPoints.clear();
    vSticks.clear();
    
    removeSprites();

    numPoints = 0;
    mRopeLength = 0;
}
void ScenarioTest::performTests()
{
    auto listener = EventListenerTouchAllAtOnce::create();
    listener->onTouchesMoved = CC_CALLBACK_2(ScenarioTest::onTouchesMoved, this);
    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);

    _particleNumber = _initParticleNum;

    // get the window size & origin position
    auto s = Director::getInstance()->getVisibleSize();
    auto origin = Director::getInstance()->getVisibleOrigin();

    // add tile map
    _map1 = TMXTiledMap::create("TileMaps/iso-test.tmx");
    _map1->setAnchorPoint( Vec2(0.5, 0.5) );
    _map1->setPosition(origin);
    this->addChild(_map1);

    _map2 = TMXTiledMap::create("TileMaps/iso-test2.tmx");
    _map2->setAnchorPoint( Vec2(0.5, 0.5) );
    _map2->setPosition(origin);
    this->addChild(_map2);

    // add toggle menu item
    MenuItemFont::setFontSize(20);
    _itemToggle = MenuItemToggle::createWithCallback(nullptr,
                                                    MenuItemFont::create( "Add/Remove Sprite" ),
                                                    MenuItemFont::create( "Add/Remove Particle"),
                                                    MenuItemFont::create( "Add/Remove Particle System"),
                                                    nullptr);
    _itemToggle->setAnchorPoint(Vec2(0.0f, 0.5f));
    _itemToggle->setPosition(Vec2(origin.x, origin.y + s.height / 2));

    // add decrease & increase menu item
    MenuItemFont::setFontSize(65);
    auto decrease = MenuItemFont::create(" - ", [&](Ref *sender) {
		int idx = _itemToggle->getSelectedIndex();
        switch (idx) {
        case 0:
            removeSprites();
            break;
        case 1:
            removeParticles();
            break;
        case 2:
            removeParticleSystem();
            break;
        default:
            break;
        }
	});
    decrease->setPosition(Vec2(origin.x + s.width / 2 - 80, origin.y + 80));
    decrease->setColor(Color3B(0,200,20));
    auto increase = MenuItemFont::create(" + ", [&](Ref *sender) {
		int idx = _itemToggle->getSelectedIndex();
        switch (idx) {
        case 0:
            addNewSprites(_spriteStepNum);
            break;
        case 1:
            addParticles(_parStepNum);
            break;
        case 2:
            addParticleSystem(_parsysStepNum);
            break;
        default:
            break;
        }
	});
    increase->setColor(Color3B(0,200,20));
    increase->setPosition(Vec2(origin.x + s.width / 2 + 80, origin.y + 80));
    
    auto menu = Menu::create(_itemToggle, decrease, increase, nullptr);
    menu->setPosition(Vec2(0.0f, 0.0f));
    addChild(menu, 10);

    
    // add tip labels
    _spriteLabel = Label::createWithTTF("Sprites : 0", "fonts/arial.ttf", 15);
    _spriteLabel->setAnchorPoint(Vec2(0.0f, 0.5f));
    addChild(_spriteLabel, 10);
    _spriteLabel->setPosition(Vec2(origin.x, origin.y + s.height/2 + 70));
    
    char str[32] = { 0 };
    sprintf(str, "Particles : %d", _particleNumber);
    _particleLabel = Label::createWithTTF(str, "fonts/arial.ttf", 15);
    _particleLabel->setAnchorPoint(Vec2(0.0f, 0.5f));
    addChild(_particleLabel, 10);
    _particleLabel->setPosition(Vec2(origin.x, origin.y + s.height/2 + 45));
    
    _parsysLabel = Label::createWithTTF("Particle System : 0", "fonts/arial.ttf", 15);
    _parsysLabel->setAnchorPoint(Vec2(0.0f, 0.5f));
    addChild(_parsysLabel, 10);
    _parsysLabel->setPosition(Vec2(origin.x, origin.y + s.height/2 + 20));

    // add sprites
    addNewSprites(_initSpriteNum);
    
    // add particle system
    addParticleSystem(_initParsysNum);
}
示例#4
0
void Scene::resetScene() {
	_vm->_game->clearQuotes();
	removeSprites();
	_spriteSlots.fullRefresh(true);
	_sequences.clear();
}
void GameEngine::run()
{
	spriteVec.push_back(levelVec.at(currentLevel)->getBackground());
	spriteVec.push_back(player);
	bool goOn = true;
	long laps = 0;
	while (goOn) {
		Uint32 nextTick = SDL_GetTicks() + ticks;
		SDL_RenderClear(win->getRen());
		if (initialLoop) {
			textInput();
			initialLoop = false;
		}
		SDL_Event eve2;
		for (size_t i = 0; i < spriteVec.size(); i++) {
			spriteVec.at(i)->draw();
			cd.checkCollisions(spriteVec.at(i));
		}
		removeSprites();
		cd.clearVector();
		for (size_t i = 0; i < textBoxVec.size(); i++) {
			textBoxVec.at(i)->draw();
		}
		if (pointCounter != nullptr) {
			pointCounter->draw();
		}
		SDL_RenderPresent(win->getRen());
		
		if (player == nullptr) {
			playerDied();
		}
		while (SDL_PollEvent(&eve2)) {
			switch (eve2.type) {
			case SDL_QUIT: goOn = false;
				break;
			case SDL_KEYDOWN:
				if (functionMap.count(eve2.key.keysym.sym) != 0) {
					functionMap[eve2.key.keysym.sym]();
				}
				for (size_t i = 0; i < memberFuncVec.size(); i++) {
					memberFuncVec.at(i)->perform(eve2.key.keysym.sym);
				}
				for (size_t i = 0; i < spriteVec.size(); i++) {
					spriteVec.at(i)->draw(eve2);
				}
				break;
			case SDL_KEYUP:
				for (size_t i = 0; i < spriteVec.size(); i++) {
					spriteVec.at(i)->draw(eve2);
				}
				break;
			}
		}
		laps++;
		
		levelVec.at(currentLevel)->spawnWave(this, laps);
		
		deleteSpawns(laps);

		//This is triggered when the level is over:
		if (laps > levelVec.at(currentLevel)->getEndFrame()) {
			SDL_RenderClear(win->getRen());
			for (size_t i = 0; i < spriteVec.size(); i++) {
				if (spriteVec.at(i)->getIsPlayer() == false) {
					spriteVec.at(i)->destroy(); //Prepare every sprite for removal except the player
				}
			}
			removeSprites();
			spriteVec.clear();
			deleteAllSpawns();
			SDL_RenderClear(win->getRen());
			levelSwap(); //Needs to be set by the game programmer
			currentLevel++;
			return this->run();
		}
		if (SDL_GetTicks() < nextTick) {
			SDL_Delay(nextTick - SDL_GetTicks());
		}
	}
}