Exemple #1
0
void renderTitle(double elapsedTime, const ResourceLoader& resources)
{
	auto tMain = resources.getTextures().getMainTitleTexture();
	auto tSub = resources.getTextures().getSubTitleTexture();
	auto tSpace = resources.getTextures().getSpacePressTexture();

	auto main_y = elapsedTime < 1000 ? (elapsedTime / 1000.0) * (Window::Height() / 4.0f * 2.0f) - Window::Height() / 4.0f : Window::Height() / 4.0f;
	auto sub_y = 0.0;
	auto sub_angle = 0.0;
	auto main_w = tMain.size.x;

	if (elapsedTime < 1500) sub_y = -Window::Height() / 4.0f;
	else if (elapsedTime < 2500) sub_y = EaseOut(Easing::Bounce, (elapsedTime - 1500) / 1000.0) * (Window::Height() / 4.0f * 2.0f) - Window::Height() / 4.0f + 24.0f;
	else sub_y = Window::Height() / 4.0f + 24.0f;

	if (elapsedTime < 3000) sub_angle = 0.0;
	else if (elapsedTime < 3200) sub_angle = ((elapsedTime - 3000) / 200) * 5.0f;
	else sub_angle = 5.0f;

	tMain.draw(Vec2((Window::Width() - main_w) / 2.0f, main_y));
	tSub.rotateAt(Vec2(0.0f, tSub.size.y), Math::Radians(sub_angle)).draw(Vec2((Window::Width() + main_w) / 2.0f, sub_y));

	if (elapsedTime >= 4000)
	{
		if (Math::Fmod(elapsedTime, 1000.0) < 500.0)
		{
			tSpace.draw(Vec2((Window::Width() - tSpace.size.x) / 2.0, Window::Height() / 4.0 * 3.0));
		}
	}
}
Exemple #2
0
void renderPlayer(double viewOffset, double playerAngle, const Vec2& playerPos, const ResourceLoader& resources)
{
	// player render
	auto tPlayer = resources.getTextures().getPlayerTexture().scale(2);
	auto tPlayerBody = resources.getTextures().getPlayerBodyTexture().scale(2);

	tPlayer.rotateAt(Vec2(12, 8) * 2, Math::Radians(playerAngle)).draw((playerPos - Vec2(12 + viewOffset, 8)) * 2);
	tPlayerBody.rotateAt(Vec2(12, 13) * 2, Math::Radians(playerAngle)).draw((playerPos - Vec2(12 + viewOffset, 18)) * 2);
}
Exemple #3
0
void renderBackgrounds(double viewLeft, const ResourceLoader& resources)
{
	// render background
	auto tBehindSun = resources.getTextures().getBackgroundTextureBehindSun().scale(2);
	auto tSun = resources.getTextures().getBackgroundSunTexture().scale(2);
	auto tFrontSun = resources.getTextures().getBackgroundTextureFrontSun().scale(2);

	auto map_offset_slow = Math::Fmod(viewLeft * 0.1f, Map::instance().width() * 8.0);
	auto map_offset_slowest = Math::Fmod(viewLeft * 0.05f, 320.0 + 96.0);

	tBehindSun.draw(Vec2(int(-map_offset_slow), 0.0f) * 2);
	tBehindSun.draw(Vec2(int(320.0f - map_offset_slow), 0.0f) * 2);
	tSun.draw(Vec2(int(320.0f - map_offset_slowest) * 2, Window::Height() / 3.0));
	tFrontSun.draw(Vec2(int(-map_offset_slow), 0.0f) * 2);
	tFrontSun.draw(Vec2(int(320.0f - map_offset_slow), 0.0f) * 2);
}
Exemple #4
0
void renderMap(double viewOffset, const ResourceLoader& resources)
{
	// map
	Map::instance().render([&](int x, int y, int d)
	{
		resources.getTextures().getMapchipTexture(d)
			.scale(2).draw(Vec2(Math::Floor(x * 16.0f - Math::Fmod(viewOffset, Map::instance().width() * 8.0)), y * 16.0f) * 2);
	});
}
Exemple #5
0
void renderBuildingLayers(Array<BuildingLayer>& layer1, Array<BuildingLayer2>& layer2, const ResourceLoader& resources)
{
	// building layers
	auto tBuildingLayer1 = resources.getTextures().getBackgroundBuildingTexture(0).scale(2);
	auto tBuildingLayer2 = resources.getTextures().getBackgroundBuildingTexture(1).scale(2);

	for (auto& o : layer1)
	{
		o.move(Vec2(-2.5f * 0.3f, 0.0));
		tBuildingLayer1.draw(o.getPos() * 2);
		if (o.getPos().x < -320.0) o.die();
	}
	Erase_if(layer1, [](const BuildingLayer& l){ return l.hasDeadObject(); });
	for (auto& o : layer2)
	{
		o.move(Vec2(-2.5f * 0.5f, 0.0));
		tBuildingLayer2.draw(o.getPos() * 2);
		if (o.getPos().x < -320.0) o.die();
	}
	Erase_if(layer2, [](const BuildingLayer2& l){ return l.hasDeadObject(); });
}
Exemple #6
0
bool renderHurdlesAndHitTest(double viewOffset, const Vec2& mychar_pos, Array<HurdleObject>& objects, const ResourceLoader& resources)
{
	auto tHurdle = resources.getTextures().getHurdleTexture(0).scale(2);

	auto isDead = false;
	// hurdles
	for (auto& o : objects)
	{
		// hit test between player
		if (Math::Abs(o.getPos().x - mychar_pos.x) <= 12 && Math::Abs(o.getPos().y - mychar_pos.y) <= (8 + 8))
		{
			// hit
			isDead = true;
		}
		tHurdle.draw((o.getPos() - Vec2(8 + viewOffset, 4)) * 2);
		if (o.getPos().x < viewOffset - 8) o.die();
	}
	auto itr = std::remove_if(std::begin(objects), std::end(objects), [](const HurdleObject& o){ return o.hasDeadObject(); });
	objects.erase(itr, std::end(objects));

	return isDead;
}