Added a textured black hole indicator.

This commit is contained in:
Barra Ó Catháin 2023-03-25 16:25:49 +00:00
parent 2cca8be0df
commit 093b3b901a
3 changed files with 13 additions and 17 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -101,12 +101,6 @@ int main(int argc, char ** argv)
int keyCount = 0; int keyCount = 0;
const uint8_t * keyboardState = SDL_GetKeyboardState(&keyCount); const uint8_t * keyboardState = SDL_GetKeyboardState(&keyCount);
// Load the title screen:
SDL_Texture * titleTexture = IMG_LoadTexture(renderer, "./Images/Title.png");
SDL_Rect titleRect;
SDL_QueryTexture(titleTexture, NULL, NULL, NULL, &titleRect.h);
SDL_QueryTexture(titleTexture, NULL, NULL, &titleRect.w, NULL);
SDL_Texture * starfieldTexture = IMG_LoadTexture(renderer, "./Images/Starfield.png"); SDL_Texture * starfieldTexture = IMG_LoadTexture(renderer, "./Images/Starfield.png");
SDL_Rect starfieldRect; SDL_Rect starfieldRect;
SDL_QueryTexture(starfieldTexture, NULL, NULL, NULL, &starfieldRect.h); SDL_QueryTexture(starfieldTexture, NULL, NULL, NULL, &starfieldRect.h);
@ -205,13 +199,14 @@ int main(int argc, char ** argv)
// Load in all of our textures: // Load in all of our textures:
SDL_Texture * blackHoleTexture, * idleTexture, * acceleratingTexture, * clockwiseTexture, * anticlockwiseTexture, SDL_Texture * blackHoleTexture, * idleTexture, * acceleratingTexture, * clockwiseTexture, * anticlockwiseTexture,
* currentTexture, * acceleratingTexture2; * currentTexture, * acceleratingTexture2, *blackHolePointerTexture;
idleTexture = IMG_LoadTexture(renderer, "./Images/Ship-Idle.png"); idleTexture = IMG_LoadTexture(renderer, "./Images/Ship-Idle.png");
blackHoleTexture = IMG_LoadTexture(renderer, "./Images/Black-Hole.png"); blackHoleTexture = IMG_LoadTexture(renderer, "./Images/Black-Hole.png");
clockwiseTexture = IMG_LoadTexture(renderer, "./Images/Ship-Clockwise.png"); clockwiseTexture = IMG_LoadTexture(renderer, "./Images/Ship-Clockwise.png");
acceleratingTexture = IMG_LoadTexture(renderer, "./Images/Ship-Accelerating.png"); acceleratingTexture = IMG_LoadTexture(renderer, "./Images/Ship-Accelerating.png");
anticlockwiseTexture = IMG_LoadTexture(renderer, "./Images/Ship-Anticlockwise.png"); anticlockwiseTexture = IMG_LoadTexture(renderer, "./Images/Ship-Anticlockwise.png");
blackHolePointerTexture = IMG_LoadTexture(renderer, "./Images/Black-Hole-Pointer.png");
acceleratingTexture2 = IMG_LoadTexture(renderer, "./Images/Ship-Accelerating-Frame-2.png"); acceleratingTexture2 = IMG_LoadTexture(renderer, "./Images/Ship-Accelerating-Frame-2.png");
currentTexture = acceleratingTexture; currentTexture = acceleratingTexture;
@ -221,6 +216,11 @@ int main(int argc, char ** argv)
SDL_QueryTexture(blackHoleTexture, NULL, NULL, NULL, &blackHoleRectangle.h); SDL_QueryTexture(blackHoleTexture, NULL, NULL, NULL, &blackHoleRectangle.h);
SDL_QueryTexture(blackHoleTexture, NULL, NULL, &blackHoleRectangle.w, NULL); SDL_QueryTexture(blackHoleTexture, NULL, NULL, &blackHoleRectangle.w, NULL);
SDL_Rect blackHolePointerRectangle;
blackHolePointerRectangle.x = 0;
blackHolePointerRectangle.y = 0;
blackHolePointerRectangle.w = 128;
blackHolePointerRectangle.h = 128;
lastFrameTime = SDL_GetPerformanceCounter(); lastFrameTime = SDL_GetPerformanceCounter();
thisFrameTime = SDL_GetPerformanceCounter(); thisFrameTime = SDL_GetPerformanceCounter();
@ -347,13 +347,10 @@ int main(int argc, char ** argv)
SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255); SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
// Draw a line representing the direction of the star: // Draw a line representing the direction of the star:
normalizeXYVector(&shipA.gravity); blackHolePointerRectangle.x = width/2 - (shipA.velocity.xComponent * 15) - (blackHolePointerRectangle.w / 2);
multiplyXYVector(&shipA.gravity, 100); blackHolePointerRectangle.y = height/2 - (shipA.velocity.yComponent * 15) - (blackHolePointerRectangle.h / 2);
SDL_RenderDrawLine(renderer, SDL_RenderCopyEx(renderer, blackHolePointerTexture, NULL, &blackHolePointerRectangle,
width/2 - (shipA.velocity.xComponent * 15), angleBetweenVectors(&shipA.gravity, &upVector) + 90, NULL, 0);
height/2 - (shipA.velocity.yComponent * 15),
(width/2 - (shipA.velocity.xComponent * 15)) + shipA.gravity.xComponent,
((height/2) - (shipA.velocity.yComponent * 15)) + shipA.gravity.yComponent);
// Present the rendered graphics: // Present the rendered graphics:
SDL_RenderPresent(renderer); SDL_RenderPresent(renderer);

View File

@ -51,7 +51,6 @@ 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: