Пример #1
0
void TitleScreenOutputFrame(void)
{
	DrawBackground(&BG, 0);

	HighScoreDisplayDraw(&HSD);

	for (int i = 0; i < MAX_PLAYERS; i++)
	{
		Tex t = GetControlTex(i);
		SDL_Rect dest =
		{
			SCREEN_X((i + 1) * FIELD_WIDTH / (MAX_PLAYERS + 1)) -
				t.W / 2,
			(SCREEN_HEIGHT - t.H) / 2 - SCREEN_X(PLAYER_RADIUS),
			t.W, t.H
		};
		RenderTex(t.T, NULL, &dest);
	}

	for (int i = 0; i < MAX_PLAYERS; i++)
	{
		PlayerDraw(&players[i], 0);
	}

	for (int i = 0; i < MAX_PLAYERS; i++)
	{
		BlockDraw(&blocks[i], 0);
	}

	DrawTitleImg();
	// Draw player icons if winners
	if (!Start)
	{
		const int left =
			(SCREEN_WIDTH - PLAYER_SPRITESHEET_WIDTH * winners) / 2;
		for (int i = 0; i < winners; i++)
		{
			const int playerIndex = winnerIndices[i];
			SDL_Rect src = {
				0, 0, PLAYER_SPRITESHEET_WIDTH, PLAYER_SPRITESHEET_HEIGHT
			};
			SDL_Rect dest =
			{
				left + i * PLAYER_SPRITESHEET_WIDTH,
				SCREEN_HEIGHT * 0.66f,
				src.w, src.h
			};
			RenderTex(PlayerSpritesheets[playerIndex].T, &src, &dest);
		}
	}
	SDL_Color c = { 177, 177, 177, 255 };
	TextRenderCentered(
		font, WelcomeMessage, (int)(SCREEN_HEIGHT * 0.75f), c);

	SDL_RenderPresent(Renderer);
}
Пример #2
0
void BlockDraw(const Block *block, const float y)
{
	const cpVect pos = cpBodyGetPosition(block->Body);
	SDL_Rect src = { 0, 0,  SCREEN_X(block->W), block->T.H };
	SDL_Rect dest =
	{
		(int)SCREEN_X((float)pos.x - block->W / 2),
		(int)(SCREEN_Y((float)pos.y + block->H / 2) - y),
		src.w, src.h
	};
	RenderTex(block->T.T, &src, &dest);
}
Пример #3
0
static void DrawParticleScroll(
	BGParticles *p, const int s,
	const int w, const int h, const int gmin, const int gmax, const int num)
{
	// Remove, draw or add icicles
	int lastY = -1;
	for (int i = 0; i < MAX_PARTICLES; i++)
	{
		if (p->Positions[i].Index == -1)
		{
			// No icicles past this point; generate a new one in its place
			p->Positions[i].X = PARTICLE_RAND_X(w);
			p->Positions[i].Y = PARTICLE_RAND_Y(lastY, gmin, gmax);
			if (p->Positions[i].Y < s + SCREEN_HEIGHT)
			{
				// Always spawn past the bottom
				p->Positions[i].Y = s + SCREEN_HEIGHT;
			}
			p->Positions[i].Index = PARTICLE_RAND_INDEX(num);
		}
		else if (p->Positions[i].Y < s - h)
		{
			// Icicle past screen top, shuffle items forward
			memmove(
				&p->Positions[i],
				&p->Positions[i + 1],
				sizeof p->Positions[i] * (MAX_PARTICLES - i - 1));
			// Make sure to initialise a new one at the end
			if (i < MAX_PARTICLES - 1)
			{
				p->Positions[MAX_PARTICLES - 1].Index = -1;
			}
			i--;
			continue;
		}

		// Draw if in range
		if (p->Positions[i].Y < s + SCREEN_HEIGHT)
		{
			SDL_Rect src = { p->Positions[i].Index * w, 0, w, h };
			SDL_Rect dst = {
				p->Positions[i].X, p->Positions[i].Y - s, src.w, src.h
			};
			RenderTex(p->T.T, &src, &dst);
		}

		lastY = p->Positions[i].Y;
	}
}
Пример #4
0
void TextRenderCentered(
	TTF_Font *font, const char *text, const int startY,
	const SDL_Color c)
{
	int y = startY;
	for (;;)
	{
		// Render the text line-by-line
		const char *nl = strchr(text, '\n');
		char buf[256];
		if (nl != NULL)
		{
			const size_t len = nl - text;
			strncpy(buf, text, len);
			buf[len] = '\0';
		}
		else
		{
			strcpy(buf, text);
		}

		if (strlen(buf) > 0)
		{
			Tex t = LoadText(buf, font, c);
			if (t.T == NULL) return;
			const int x = (SCREEN_WIDTH - t.W) / 2;
			SDL_Rect dest = { x, y, t.W, t.H };
			RenderTex(t.T, NULL, &dest);
			SDL_DestroyTexture(t.T);
		}
		y += TTF_FontHeight(font);

		if (nl == NULL)
		{
			break;
		}
		text = nl + 1;
	}
}