Made the titlescreens use prepareTitleScreen()
This commit is contained in:
parent
8971d37dac
commit
2cca8be0df
37
Spacewar.c
37
Spacewar.c
|
@ -120,23 +120,11 @@ int main(int argc, char ** argv)
|
|||
{
|
||||
playerOne.joystick = NULL;
|
||||
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:
|
||||
while(!inputSelected)
|
||||
{
|
||||
|
@ -157,21 +145,10 @@ int main(int argc, char ** argv)
|
|||
}
|
||||
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:
|
||||
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;
|
||||
SpacewarTitlescreen titlescreen = prepareTitleScreen(window, renderer, "./Images/Starfield.png",
|
||||
"./Images/Title.png", font,
|
||||
"Press Enter or Button 0 on your joystick to play.");
|
||||
|
||||
// Load all joysticks:
|
||||
int joystickListLength = SDL_NumJoysticks();
|
||||
|
|
|
@ -35,18 +35,23 @@ SpacewarTitlescreen prepareTitleScreen(SDL_Window * window, SDL_Renderer * rende
|
|||
newTitleScreen.titleRectangle = calloc(1, sizeof(SDL_Rect));
|
||||
newTitleScreen.textRectangle = 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, &newTitleScreen.textRectangle->w, NULL);
|
||||
SDL_QueryTexture(newTitleScreen.titleTexture, NULL, NULL, NULL, &newTitleScreen.titleRectangle->h);
|
||||
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, &newTitleScreen.starfieldRectangle->w, NULL);
|
||||
|
||||
return newTitleScreen;
|
||||
}
|
||||
|
||||
void drawTitleScreen(SpacewarTitlescreen * titlescreen)
|
||||
{
|
||||
// Get the current size of the window:
|
||||
int width = 0, height = 0;
|
||||
printf("%p\n", titlescreen->window);
|
||||
SDL_GetWindowSize(titlescreen->window, &width, &height);
|
||||
|
||||
// Position the elements on-screen:
|
||||
|
|
Loading…
Reference in New Issue