コード例 #1
0
bool Wallbreaker::checkBrick(Entity& entity, int i, int j, const sf::Vector2f& old_pos)
{
	if (i >= 0 && i < LevelManager::NB_BRICK_LINES && j >= 0 && j < LevelManager::NB_BRICK_COLS)
	{
		Brick& brick = m_level.getBrick(i, j);
		if (brick.isActive())
		{
			entity.onBrickHit(brick, old_pos);

			if (!brick.isActive())
			{
				// Randomly create a new power-up
				if (math::rand(0, 9) == 0)
				{
					PowerUp* powerup = PowerUp::createRandom();
					powerup->setPosition(brick.getPosition());
					addEntity(powerup);
				}
				// Update remaining bricks counter
				--m_remaining_bricks;
				m_hud.setBrickCount(m_remaining_bricks);
				// Upgrade score
				++m_score;
				m_hud.setScore(m_score);
				if (m_score > Settings::highscore)
				{
					Settings::highscore = m_score;
					m_hud.setHighscore(Settings::highscore);
				}
			}
			return true;
		}
	}
	return false;
}
コード例 #2
0
void EndlessWorld::extendFlat()
{
	//flat
	cpVect verts[] = {
		cpv(koniec - dodatek - G_odlegloscmiedzyBramkami, -2000),
		cpv(koniec - dodatek - G_odlegloscmiedzyBramkami, 0),
		cpv(koniec, 0),
		cpv(koniec, -2000),
	};
	cpSpaceRemoveStaticShape(gravitySpace, floor);
	floor = cpPolyShapeNew(floorBody, 4, verts, cpvzero);
	floor->e = 0;//elastycznosc;
	floor->u = 0.1f;//friction
	floor->collision_type = COLLISIONTYPEFLOOR;
	cpShapeSetLayers(floor, CPFLOORCOLIDER);
	cpSpaceAddStaticShape(gravitySpace, floor);
	flatsprite->setTextureRect(Rect(verts[0].x, verts[1].y, abs(verts[3].x), flatsprite->getTexture()->getContentSize().height));
	bottomSpr->setPositionX(koniec - dodatek - G_odlegloscmiedzyBramkami);
	//chkpts
	if (isEndless())
	{
		for (int i = koniec - dodatek; i <= koniec; i += G_odlegloscmiedzyBramkami)
		{
			auto chkpt = Chcekpoint::create(this, &orderedOpponents, R_SPRITE_checkpoint);
			chkpt->setPosition(i, floor->bb.t);
			modifyGate(chkpt);
			rotationLayer->addChild(chkpt);
		}
	}
	//POWERUPS
	for (int j = koniec - dodatek + G_powerUpOdleglos + random(0,G_powerUpOdlegloscVar); j <= koniec; j += G_powerUpOdleglos + random(0,G_powerUpOdlegloscVar))
	{
		int wysokosc = 2.5f * Sprite::createWithSpriteFrameName(R_Box[1])->getContentSize().height;
		PowerUp *pwrup = PowerUp::create(&orderedOpponents);
		pwrup->setPosition(Vec2(j, floor->bb.t + wysokosc));
		rotationLayer->addChild(pwrup);
	}
}
コード例 #3
0
void EndlessWorld::setMinGates(int number)
{
	minliczbabramek = number;
	int bramki = minliczbabramek;
	if (isEndless()) bramki = G_endlessGateNumber;
	for (int i = 1; i <= bramki; i++)
	{
		auto chkpt = Chcekpoint::create(this, &orderedOpponents, R_SPRITE_checkpoint);
		chkpt->setPosition(floor->bb.l + i*G_odlegloscmiedzyBramkami, floor->bb.t);
		rotationLayer->addChild(chkpt);
		if (i == minliczbabramek) chkpt->setIsLast(true);
		modifyGate(chkpt);
	}
	//POWER UPY
	
	for (int odl = G_powerUpOdleglos + random(0,G_powerUpOdlegloscVar); odl <= koniec; odl += G_powerUpOdleglos + random(0,G_powerUpOdlegloscVar))
	{
		int wysokosc = 2.5f * Sprite::createWithSpriteFrameName(R_Box[1])->getContentSize().height;
		PowerUp *pwrup = PowerUp::create(&orderedOpponents);
		pwrup->setPosition(Vec2(odl, floor->bb.t + wysokosc));
		rotationLayer->addChild(pwrup);
	}
}
コード例 #4
0
ファイル: PowerUp.cpp プロジェクト: HoekWax/cosmoscroll
void PowerUp::dropRandom(const sf::Vector2f& position)
{
	PowerUp* powerup = new PowerUp((Type) math::rand(0, PowerUp::_COUNT - 1));
	powerup->setPosition(position);
	EntityManager::getInstance().addEntity(powerup);
}