示例#1
0
MainMenuDebug::MainMenuDebug(int id, ResourceCollection& resources, const MainMenuState* state):
	Menu(id, resources, false),
	mState(const_cast<MainMenuState*>(state))
{
	sf::Vector2f width = sf::Vector2f((float)baseWidth, 0.0f);
	sf::Vector2f height = sf::Vector2f(0.0f, (float)baseHeight);

	sf::Texture& buttonTexture = resources.getTexture("Assets/Menu/Button.png");
	sf::Font& font = resources.getFont("Assets/Menu/24Janvier.otf");
	
	sf::Text start("PlatformState", font, 30U);
	addButton(Button(START, width / 2.0f + height / 4.0f, buttonTexture, resources, start));
	
	sf::Text puzzle("PuzzleState", font, 30U);
	addButton(Button(PUZZLE, width / 2.0f + height * (1/4.0f + 1/6.0f), buttonTexture, resources, puzzle));
	
	sf::Text settings("Toggle Fullscreen", font, 30U);
	addButton(Button(FULLSCREEN, width / 2.0f + height * (1/4.0f + 2/6.0f), buttonTexture, resources, settings));
		
	sf::Text exit("Exit", font, 30U);
	addButton(Button(EXIT, width / 2.0f + height * (1/4.0f + 3/6.0f), buttonTexture, resources, exit));
}
示例#2
0
Player::Player(PlatformState& platformState, BoxWorld* world, sf::Vector2f& size, sf::Vector2f& position, ResourceCollection& resource, LightSolver* lightSolver, StatManager& stats)
: Entity(world, size, position)
, mPlatformState(platformState)
, groundCallBack(nullptr)
, leftButton(false)
, rightButton(false)
, downButton(false)
, mResource(resource)
, flashLight(lightSolver->createLight(FLASHLIGHT_SIZE.x, FLASHLIGHT_SIZE.y))
, maskRight(&resource.getTexture("Assets/Shader/mask.png"))
, maskLeft(flipTexture(maskRight))
, activeStreetLight(nullptr)
, collisionFixture(body->GetFixtureList())
, mStats(stats)
, flashLightBody(world->createEntityBody(sf::Vector2f(0.0f, 0.0f), static_cast<sf::Vector2f>(FLASHLIGHT_SIZE), false))
{
	flashLight->setColor(sf::Color(255, 255, 0, 150));
	int group = flashLight->getFilterGroup();
	group |= (1 << 8);
	flashLight->setFilterGroup(group);
	setFilterGroup(getFilterGroup() | (1 << 8));

	setState(PLAYER_STATE::NORMAL);

	/* Walking/run animation */
	auto &walking = mResource.getTexture("Assets/Characters/Stella Left.png");
	sf::Vector2i walkingSize = static_cast<sf::Vector2i>(walking.getSize());
	sf::Vector2i frameSize(256, 256);
	SpriteSheet spritesheet1(frameSize, walkingSize);
	std::vector<sf::IntRect> frames = spritesheet1.getAllFrames();
	mWalking = new Animation(frames,walking);
	
	/* Idle animation */
	auto &idle = mResource.getTexture("Assets/Characters/Stella idle.png");
	sf::Vector2i idleSize = static_cast<sf::Vector2i>(idle.getSize());
	SpriteSheet idleSheet(frameSize,idleSize);
	std::vector<sf::IntRect> idleFrames = idleSheet.getAllFrames();
	mIdle = new Animation(idleFrames,idle);
	
	/* Jump animation */
	auto &jump = mResource.getTexture("Assets/Characters/Stella jump.png");
	sf::Vector2i jumpSize = static_cast<sf::Vector2i>(jump.getSize());
	SpriteSheet jumpSheet(frameSize,jumpSize);
	std::vector<sf::IntRect> jumpFrames = jumpSheet.getAllFrames();
	mJump = new Animation(jumpFrames,jump);

	/* Grab animation */
	auto &grab = mResource.getTexture("Assets/Characters/Stella grab.png");
	sf::Vector2i grabSize = static_cast<sf::Vector2i>(grab.getSize());
	SpriteSheet grabSheet (frameSize, grabSize);
	std::vector<sf::IntRect> grabFrames = grabSheet.getAllFrames();
	mGrab = new Animation(grabFrames,grab);

	/* Fall Animation*/
	auto &fall = mResource.getTexture("Assets/Characters/Stella fall.png");
	sf::Vector2i fallSize = static_cast<sf::Vector2i>(fall.getSize());
	SpriteSheet fallSheet(frameSize, fallSize);
	std::vector<sf::IntRect> fallFrames = jumpSheet.getAllFrames();
	mFall = new Animation(fallFrames,fall);

	/* Hit Animation*/
	auto &hit = mResource.getTexture("Assets/Characters/Stella hit.png");
	sf::Vector2i hitSize = static_cast<sf::Vector2i>(hit.getSize());
	SpriteSheet hitSheet(frameSize, hitSize);
	std::vector<sf::IntRect> hitFrames = hitSheet.getAllFrames();
	mHit = new Animation(hitFrames,hit);

	anime.setAnimation(*mIdle);
	
	updateSpriteOrigin();

	mJumpSound = new sf::Sound;
	mJumpSound->setBuffer(*mResource.getSound("Assets/Sound/Jump.wav"));

	mWalkSound = new sf::Sound;
	mWalkSound->setBuffer(*mResource.getSound("Assets/Sound/Stella_Run_Loop_1.wav"));
	mWalkSound->setVolume(40);

	mHurtSound = new sf::Sound;
	mHurtSound->setBuffer(*mResource.getSound("Assets/Sound/Stella get hurt.wav"));

	setupSensors(position, size);
	body->SetLinearDamping(1.0f);
	/* Set filter for collisions */
	b2Filter filter = collisionFixture->GetFilterData();
	filter.categoryBits = PLAYER;
	//filter.maskBits =ALL, ENEMY_CHASE, ENEMY_ATTACK;
	filter.groupIndex = ALL, ENEMY_CHASE, ENEMY_ATTACK;
	collisionFixture->SetFilterData(filter);
	knockForce = 35;
	toggle = false;
}