Made the titlescreens use prepareTitleScreen()

This commit is contained in:
Barra Ó Catháin 2023-03-25 15:25:32 +00:00
parent 8971d37dac
commit 2cca8be0df
2 changed files with 12 additions and 30 deletions

View File

@ -120,23 +120,11 @@ int main(int argc, char ** argv)
{ {
playerOne.joystick = NULL; playerOne.joystick = NULL;
bool inputSelected = false; bool inputSelected = false;
SDL_Surface * text = TTF_RenderText_Blended(font, "Press Enter to play.", white);
SDL_Rect textDestination = {0, 0, text->w, text->h};
SDL_Texture * textTexture = SDL_CreateTextureFromSurface(renderer, text);
// Prep the titlescreen struct:
SpacewarTitlescreen titlescreen;
titlescreen.starfieldTexture = starfieldTexture;
titlescreen.starfieldRectangle = &starfieldRect;
titlescreen.xScroll = 0;
titlescreen.window = window;
titlescreen.renderer = renderer;
titlescreen.titleRectangle = &titleRect;
titlescreen.titleTexture = titleTexture;
titlescreen.textTexture = textTexture;
titlescreen.textRectangle = &textDestination;
int scrollX = 0, titleAlpha = 0, textAlpha = 0; // Prep the titlescreen struct:
SpacewarTitlescreen titlescreen = prepareTitleScreen(window, renderer, "./Images/Starfield.png",
"./Images/Title.png", font, "Press Enter to play.");
// Render the title text: // Render the title text:
while(!inputSelected) while(!inputSelected)
{ {
@ -157,21 +145,10 @@ int main(int argc, char ** argv)
} }
else else
{ {
SDL_Surface * text = TTF_RenderText_Blended(font, "Press Button 0 on your controller, or press enter.", white);
SDL_Rect textDestination = {0, 0, text->w, text->h};
SDL_Texture * textTexture = SDL_CreateTextureFromSurface(renderer, text);
// Prep the titlescreen struct: // Prep the titlescreen struct:
SpacewarTitlescreen titlescreen; SpacewarTitlescreen titlescreen = prepareTitleScreen(window, renderer, "./Images/Starfield.png",
titlescreen.starfieldTexture = starfieldTexture; "./Images/Title.png", font,
titlescreen.starfieldRectangle = &starfieldRect; "Press Enter or Button 0 on your joystick to play.");
titlescreen.xScroll = 0;
titlescreen.window = window;
titlescreen.renderer = renderer;
titlescreen.titleRectangle = &titleRect;
titlescreen.titleTexture = titleTexture;
titlescreen.textTexture = textTexture;
titlescreen.textRectangle = &textDestination;
// Load all joysticks: // Load all joysticks:
int joystickListLength = SDL_NumJoysticks(); int joystickListLength = SDL_NumJoysticks();

View File

@ -35,18 +35,23 @@ SpacewarTitlescreen prepareTitleScreen(SDL_Window * window, SDL_Renderer * rende
newTitleScreen.titleRectangle = calloc(1, sizeof(SDL_Rect)); newTitleScreen.titleRectangle = calloc(1, sizeof(SDL_Rect));
newTitleScreen.textRectangle = calloc(1, sizeof(SDL_Rect)); newTitleScreen.textRectangle = calloc(1, sizeof(SDL_Rect));
newTitleScreen.starfieldRectangle = calloc(1, sizeof(SDL_Rect)); newTitleScreen.starfieldRectangle = calloc(1, sizeof(SDL_Rect));
// Set the rects to the size of the textures:
SDL_QueryTexture(newTitleScreen.textTexture, NULL, NULL, NULL, &newTitleScreen.textRectangle->h); SDL_QueryTexture(newTitleScreen.textTexture, NULL, NULL, NULL, &newTitleScreen.textRectangle->h);
SDL_QueryTexture(newTitleScreen.textTexture, NULL, NULL, &newTitleScreen.textRectangle->w, NULL); SDL_QueryTexture(newTitleScreen.textTexture, NULL, NULL, &newTitleScreen.textRectangle->w, NULL);
SDL_QueryTexture(newTitleScreen.titleTexture, NULL, NULL, NULL, &newTitleScreen.titleRectangle->h); SDL_QueryTexture(newTitleScreen.titleTexture, NULL, NULL, NULL, &newTitleScreen.titleRectangle->h);
SDL_QueryTexture(newTitleScreen.titleTexture, NULL, NULL, &newTitleScreen.titleRectangle->w, NULL); SDL_QueryTexture(newTitleScreen.titleTexture, NULL, NULL, &newTitleScreen.titleRectangle->w, NULL);
SDL_QueryTexture(newTitleScreen.starfieldTexture, NULL, NULL, NULL, &newTitleScreen.starfieldRectangle->h); SDL_QueryTexture(newTitleScreen.starfieldTexture, NULL, NULL, NULL, &newTitleScreen.starfieldRectangle->h);
SDL_QueryTexture(newTitleScreen.starfieldTexture, NULL, NULL, &newTitleScreen.starfieldRectangle->w, NULL); SDL_QueryTexture(newTitleScreen.starfieldTexture, NULL, NULL, &newTitleScreen.starfieldRectangle->w, NULL);
return newTitleScreen;
} }
void drawTitleScreen(SpacewarTitlescreen * titlescreen) void drawTitleScreen(SpacewarTitlescreen * titlescreen)
{ {
// Get the current size of the window: // Get the current size of the window:
int width = 0, height = 0; int width = 0, height = 0;
printf("%p\n", titlescreen->window);
SDL_GetWindowSize(titlescreen->window, &width, &height); SDL_GetWindowSize(titlescreen->window, &width, &height);
// Position the elements on-screen: // Position the elements on-screen: