Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
487b668ebf | ||
|
09ab6dd027 | ||
|
c6608cd3e0 | ||
|
21012dbc70 |
Binary file not shown.
Before Width: | Height: | Size: 140 KiB |
Binary file not shown.
Before Width: | Height: | Size: 219 KiB |
Binary file not shown.
Before Width: | Height: | Size: 271 KiB |
BIN
bin/assets/images/return_button.png
Normal file
BIN
bin/assets/images/return_button.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 48 KiB |
Binary file not shown.
Before Width: | Height: | Size: 222 KiB |
208
breakout.c
208
breakout.c
@ -9,26 +9,16 @@
|
|||||||
|
|
||||||
#include "breakout.h"
|
#include "breakout.h"
|
||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
#include "gamestate.h"
|
|
||||||
#include "gameover.h"
|
|
||||||
#include "main.h"
|
|
||||||
|
|
||||||
extern float XScale, YScale;
|
extern float XScale, YScale;
|
||||||
extern int width, height;
|
|
||||||
|
|
||||||
#define BALL_TexturePath "assets/images/ball.png"
|
#define BALL_TexturePath "assets/images/ball.png"
|
||||||
#define PADDLE_TexturePath "assets/images/paddle.png"
|
#define PADDLE_TexturePath "assets/images/paddle.png"
|
||||||
#define BLOCK_TexturePath "assets/images/spritesheet.png"
|
#define BLOCK_TexturePath "assets/images/spritesheet.png"
|
||||||
#define BRAEKOUT_CountdownTexturePath "assets/images/text.png"
|
#define BRAEKOUT_CountdownTexturePath "assets/images/text.png"
|
||||||
#define BRAEKOUT_PausedTexturePath "assets/images/paused.png"
|
|
||||||
#define BALL_MinSpeed 8.0f
|
#define BALL_MinSpeed 8.0f
|
||||||
#define BALL_MaxSpeed 25.0f
|
#define BALL_MaxSpeed 50.0f
|
||||||
#define BALL_AccelerationTime 10000
|
#define BALL_AccelerationTime 18000
|
||||||
#define PADDLE_MaxSize 300
|
|
||||||
#define PADDLE_MinSize 50
|
|
||||||
#define PADDLE_AccelerationTime 18000
|
|
||||||
#define BREAKOUT_LiveHUDSize 35
|
|
||||||
#define BREAKOUT_LiveHUDMargin 8
|
|
||||||
|
|
||||||
#ifndef __nullptr__
|
#ifndef __nullptr__
|
||||||
#define Nullptr(type) (type *)0
|
#define Nullptr(type) (type *)0
|
||||||
@ -37,15 +27,15 @@ extern int width, height;
|
|||||||
float PADDLE_SmoothFactor = 0.1f;
|
float PADDLE_SmoothFactor = 0.1f;
|
||||||
int BLOCK_TextureCount = 24;
|
int BLOCK_TextureCount = 24;
|
||||||
int BALL_TextureCount = 9;
|
int BALL_TextureCount = 9;
|
||||||
int BREAKOUT_CountdownTextureCount = 4;
|
int GAME_CountdownTextureCount = 4;
|
||||||
int PADDLE_TextureCount = 9;
|
int PADDLE_TextureCount = 9;
|
||||||
|
int BREAKOUT_BoxWidth, BREAKOUT_BoxHeight;
|
||||||
SDL_Texture * BALL_Texture;
|
SDL_Texture * BALL_Texture;
|
||||||
SDL_Texture * BREAKOUT_CountdownTexture;
|
SDL_Texture * GAME_CountdownTexture;
|
||||||
SDL_Texture * PADDLE_Texture;
|
SDL_Texture * PADDLE_Texture;
|
||||||
SDL_Texture * BLOCK_Texture;
|
SDL_Texture * BLOCK_Texture;
|
||||||
SDL_Texture * BREAKOUT_PausedTexture;
|
|
||||||
SDL_Rect * BALL_SourceRects;
|
SDL_Rect * BALL_SourceRects;
|
||||||
SDL_Rect * BREAKOUT_CountdownSourceRects;
|
SDL_Rect * GAME_CountdownSourceRects;
|
||||||
SDL_Rect * PADDLE_SourceRects;
|
SDL_Rect * PADDLE_SourceRects;
|
||||||
SDL_Rect * BLOCK_SourceRects;
|
SDL_Rect * BLOCK_SourceRects;
|
||||||
Uint8 * PADDLE_MoveLeftKeys, * PADDLE_MoveRightKeys;
|
Uint8 * PADDLE_MoveLeftKeys, * PADDLE_MoveRightKeys;
|
||||||
@ -54,41 +44,29 @@ bool BALL_IsInit = false;
|
|||||||
bool PADDLE_IsInit = false;
|
bool PADDLE_IsInit = false;
|
||||||
bool BLOCK_IsInit = false;
|
bool BLOCK_IsInit = false;
|
||||||
|
|
||||||
void BREAKOUT_INITIALIZE(SDL_Renderer * renderer){
|
void BREAKOUT_INITIALIZE(SDL_Renderer * renderer, int width, int height){
|
||||||
if (!BREAKOUT_IsInit) {
|
if (!BREAKOUT_IsInit) {
|
||||||
printf("Initializing Game...\n");
|
printf("Initializing Game...\n");
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
|
BREAKOUT_BoxWidth = width;
|
||||||
|
BREAKOUT_BoxHeight = height;
|
||||||
BALL_Initialize(renderer);
|
BALL_Initialize(renderer);
|
||||||
PADDLE_Initialize(renderer);
|
PADDLE_Initialize(renderer);
|
||||||
BLOCK_Initialize(renderer);
|
BLOCK_Initialize(renderer);
|
||||||
BREAKOUT_CountdownTexture = IMG_LoadTexture(renderer, BRAEKOUT_CountdownTexturePath);
|
GAME_CountdownTexture = IMG_LoadTexture(renderer, BRAEKOUT_CountdownTexturePath);
|
||||||
if (!BREAKOUT_CountdownTexture) printf("Countdown texture failed to load!\n");
|
if (!GAME_CountdownTexture) printf("Coutndown texture failed to load!\n");
|
||||||
BREAKOUT_PausedTexture = IMG_LoadTexture(renderer, BRAEKOUT_PausedTexturePath);
|
GAME_CountdownTextureCount = 4;
|
||||||
if (!BREAKOUT_PausedTexture) printf("Paused texture failed to load!\n");
|
GAME_CountdownSourceRects = (SDL_Rect *)malloc(GAME_CountdownTextureCount * sizeof(SDL_Rect));
|
||||||
BREAKOUT_CountdownTextureCount = 4;
|
if (!GAME_CountdownSourceRects) printf("FATAL! Memory allocation failed!\n");
|
||||||
BREAKOUT_CountdownSourceRects = (SDL_Rect *)malloc(BREAKOUT_CountdownTextureCount * sizeof(SDL_Rect));
|
GAME_CountdownSourceRects[0] = (SDL_Rect) {.x = 1, .y = 668, .w = 1000, .h = 732 };
|
||||||
if (!BREAKOUT_CountdownSourceRects) printf("FATAL! Memory allocation failed!\n");
|
GAME_CountdownSourceRects[1] = (SDL_Rect) {.x = 1, .y = 1, .w = 242, .h = 665 };
|
||||||
BREAKOUT_CountdownSourceRects[0] = (SDL_Rect) {.x = 1, .y = 668, .w = 1000, .h = 732 };
|
GAME_CountdownSourceRects[2] = (SDL_Rect) {.x = 245, .y = 1, .w = 443, .h = 665 };
|
||||||
BREAKOUT_CountdownSourceRects[1] = (SDL_Rect) {.x = 1, .y = 1, .w = 242, .h = 665 };
|
GAME_CountdownSourceRects[3] = (SDL_Rect) {.x = 690, .y = 1, .w = 443, .h = 665 };
|
||||||
BREAKOUT_CountdownSourceRects[2] = (SDL_Rect) {.x = 245, .y = 1, .w = 443, .h = 665 };
|
|
||||||
BREAKOUT_CountdownSourceRects[3] = (SDL_Rect) {.x = 690, .y = 1, .w = 443, .h = 665 };
|
|
||||||
printf("Game initialized!\n");
|
printf("Game initialized!\n");
|
||||||
BREAKOUT_IsInit = true;
|
BREAKOUT_IsInit = true;
|
||||||
} else printf("Game is already initialized!\n");
|
} else printf("Game is already initialized!\n");
|
||||||
} /* BREAKOUT_INITIALIZE */
|
} /* BREAKOUT_INITIALIZE */
|
||||||
|
|
||||||
void BREAKOUT_TogglePause(Scenery * scenery){
|
|
||||||
(scenery->IsPaused) = !(scenery->IsPaused);
|
|
||||||
printf("Game was %s!\n", ( (scenery->IsPaused) ? "paused" : "unpaused"));
|
|
||||||
}
|
|
||||||
|
|
||||||
void BREAKOUT_KeyPressed(Scenery * scenery, SDL_KeyboardEvent * b){
|
|
||||||
if ((b->keysym).scancode == SDL_SCANCODE_ESCAPE) {
|
|
||||||
printf("Escape was pressed ingame! Toggle Pause...\n");
|
|
||||||
BREAKOUT_TogglePause(scenery);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Scenery BREAKOUT_CreateDefault(){
|
Scenery BREAKOUT_CreateDefault(){
|
||||||
Scenery scenery;
|
Scenery scenery;
|
||||||
|
|
||||||
@ -116,36 +94,30 @@ Scenery BREAKOUT_CreateDefault(){
|
|||||||
return scenery;
|
return scenery;
|
||||||
} /* BREAKOUT_CreateDefault */
|
} /* BREAKOUT_CreateDefault */
|
||||||
|
|
||||||
void BREAKOUT_IncreaseScoreBy(Scenery * scenery, int scoreInc){
|
|
||||||
(scenery->Score) += scoreInc;
|
int BREAKOUT_RefreshScore(Scenery * scenery){
|
||||||
|
(scenery->Score) = (int)round((double)(scenery->Frames) * 0.005f * ((scenery->ball).Speed) + (double)(50 * (scenery->DestroyedBlocks)));
|
||||||
|
printf("Score: %d\n", (scenery->Score));
|
||||||
|
return (scenery->Score);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TEXTURE_RenderCenteredSpriteSheet(SDL_Renderer * renderer, SDL_Texture * texture, SDL_Rect * srcRect, float Scale){
|
// This Function is obsolete! Do not use it!
|
||||||
SDL_Rect target;
|
void BREAKOUT_ChangeSize(int width, int height){
|
||||||
|
BREAKOUT_BoxWidth = width;
|
||||||
target.w = (int)roundf(((float)(srcRect->w)) * Scale);
|
BREAKOUT_BoxHeight = height;
|
||||||
target.h = (int)roundf(((float)(srcRect->h)) * Scale);
|
|
||||||
target.x = ((width - (target.w)) / 2);
|
|
||||||
target.y = ((height - (target.h)) / 2);
|
|
||||||
SDL_RenderCopy(renderer, texture, srcRect, &target);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TEXTURE_RenderCentered(SDL_Renderer * renderer, SDL_Texture * texture, float Scale){
|
|
||||||
int w, h;
|
|
||||||
SDL_Rect target;
|
|
||||||
|
|
||||||
SDL_QueryTexture(texture, NULL, NULL, &w, &h);
|
|
||||||
target.w = (int)roundf(((float)w) * Scale);
|
|
||||||
target.h = (int)roundf(((float)h) * Scale);
|
|
||||||
target.x = ((width - (target.w)) / 2);
|
|
||||||
target.y = ((height - (target.h)) / 2);
|
|
||||||
SDL_RenderCopy(renderer, texture, NULL, &target);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BREAKOUT_Update(Scenery * scenery, const Uint8 * keystate){
|
void BREAKOUT_Update(Scenery * scenery, const Uint8 * keystate){
|
||||||
if (scenery->IsPaused) return;
|
if (scenery->IsPaused) {
|
||||||
if ((scenery->StartCountdown)-- > 0) return;
|
// Render "Paused"
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ((scenery->StartCountdown)-- > 0) {
|
||||||
|
// Render "Countdown"
|
||||||
|
return;
|
||||||
|
}
|
||||||
(scenery->Frames)++;
|
(scenery->Frames)++;
|
||||||
|
BREAKOUT_RefreshScore(scenery);
|
||||||
if (scenery->IsGameOver) {
|
if (scenery->IsGameOver) {
|
||||||
BALL_ResetPosition(&(scenery->ball));
|
BALL_ResetPosition(&(scenery->ball));
|
||||||
PADDLE_ResetPosition(&(scenery->paddle));
|
PADDLE_ResetPosition(&(scenery->paddle));
|
||||||
@ -153,12 +125,12 @@ void BREAKOUT_Update(Scenery * scenery, const Uint8 * keystate){
|
|||||||
scenery->IsGameOver = false;
|
scenery->IsGameOver = false;
|
||||||
scenery->Frames = 0;
|
scenery->Frames = 0;
|
||||||
if (--(scenery->Lives) <= 0)
|
if (--(scenery->Lives) <= 0)
|
||||||
GAME_ChangeState(GameOver);
|
printf("Game over, no lives left!\n");
|
||||||
else
|
else
|
||||||
printf("Oh oh, only %d lives left!\n", scenery->Lives);
|
printf("Oh oh, only %d lives left!\n", scenery->Lives);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PADDLE_Update(&(scenery->paddle), scenery, keystate); // Update paddle before ball because paddle is not static!
|
PADDLE_Update(&(scenery->paddle), keystate); // Update paddle before ball because paddle is not static!
|
||||||
BALL_Update(&(scenery->ball), scenery);
|
BALL_Update(&(scenery->ball), scenery);
|
||||||
for (int i = 0; i < (scenery->BlockCount); i++) {
|
for (int i = 0; i < (scenery->BlockCount); i++) {
|
||||||
BLOCK_Update((scenery->blocks) + i);
|
BLOCK_Update((scenery->blocks) + i);
|
||||||
@ -171,40 +143,25 @@ void BREAKOUT_Draw(Scenery * scenery, SDL_Renderer * renderer){
|
|||||||
}
|
}
|
||||||
BALL_Draw(renderer, &(scenery->ball));
|
BALL_Draw(renderer, &(scenery->ball));
|
||||||
PADDLE_Draw(renderer, &(scenery->paddle));
|
PADDLE_Draw(renderer, &(scenery->paddle));
|
||||||
SCORE_DrawHUD(renderer, scenery);
|
if ((scenery->StartCountdown) > 0) { // ! Render Z-Layer !
|
||||||
BREAKOUT_DrawLivesHUD(renderer, scenery);
|
SDL_Rect * rect = GAME_CountdownSourceRects + (((scenery->StartCountdown) - 1) / 60);
|
||||||
if (scenery->IsPaused) {
|
SDL_Rect target = *rect;
|
||||||
TEXTURE_RenderCentered(renderer, BREAKOUT_PausedTexture, 0.5f);
|
target.x = ((BREAKOUT_BoxWidth - (rect->w)) / 2);
|
||||||
} else if ((scenery->StartCountdown) > 0) { // ! Render Z-Layer !
|
target.y = ((BREAKOUT_BoxHeight - (rect->h)) / 2);
|
||||||
TEXTURE_RenderCenteredSpriteSheet(renderer, BREAKOUT_CountdownTexture, (BREAKOUT_CountdownSourceRects + (((scenery->StartCountdown) - 1) / 60)), 1.0f);
|
SDL_RenderCopy(renderer, GAME_CountdownTexture, rect, &target);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void BREAKOUT_DrawLivesHUD(SDL_Renderer * renderer, Scenery * scenery){
|
|
||||||
SDL_Rect tmpRect;
|
|
||||||
|
|
||||||
tmpRect.y = BREAKOUT_LiveHUDMargin;
|
|
||||||
tmpRect.w = BREAKOUT_LiveHUDSize;
|
|
||||||
tmpRect.h = BREAKOUT_LiveHUDSize;
|
|
||||||
tmpRect.x = width - BREAKOUT_LiveHUDMargin;
|
|
||||||
|
|
||||||
for (int i = 0; i < (scenery->Lives); i++) {
|
|
||||||
tmpRect.x -= (BREAKOUT_LiveHUDSize + BREAKOUT_LiveHUDMargin);
|
|
||||||
BALL_DrawTexture(renderer, &tmpRect, (scenery->ball).TextureIndex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BREAKOUT_DEINITIALIZE(){
|
void BREAKOUT_DEINITIALIZE(){
|
||||||
if (BREAKOUT_IsInit) {
|
if (BREAKOUT_IsInit) {
|
||||||
printf("De-initializing Game...\n");
|
printf("De-initializing Game...\n");
|
||||||
SDL_DestroyTexture(BREAKOUT_CountdownTexture);
|
SDL_DestroyTexture(GAME_CountdownTexture);
|
||||||
SDL_DestroyTexture(BREAKOUT_PausedTexture);
|
|
||||||
free(PADDLE_MoveLeftKeys);
|
free(PADDLE_MoveLeftKeys);
|
||||||
free(PADDLE_MoveRightKeys);
|
free(PADDLE_MoveRightKeys);
|
||||||
free(BALL_SourceRects);
|
free(BALL_SourceRects);
|
||||||
free(PADDLE_SourceRects);
|
free(PADDLE_SourceRects);
|
||||||
free(BLOCK_SourceRects);
|
free(BLOCK_SourceRects);
|
||||||
free(BREAKOUT_CountdownSourceRects);
|
free(GAME_CountdownSourceRects);
|
||||||
BALL_Deinitialize();
|
BALL_Deinitialize();
|
||||||
PADDLE_Deinitialize();
|
PADDLE_Deinitialize();
|
||||||
BLOCK_Deinitialize();
|
BLOCK_Deinitialize();
|
||||||
@ -245,33 +202,27 @@ void BALL_Initialize(SDL_Renderer * renderer){
|
|||||||
} /* BALL_Initialize */
|
} /* BALL_Initialize */
|
||||||
|
|
||||||
Ball BALL_CreateDefault(){
|
Ball BALL_CreateDefault(){
|
||||||
|
double rotation = (double)(rand() % 360);
|
||||||
|
|
||||||
return (Ball) {
|
return (Ball) {
|
||||||
.Location = (Vector) {.x = (width / 2) - 15, .y = height - 132 },
|
.Location = (Vector) {.x = BREAKOUT_BoxWidth / 2 - 15, .y = BREAKOUT_BoxHeight - 132 },
|
||||||
.Momentum = (Vector) {.x = 0.0f, .y = BALL_MinSpeed },
|
.Momentum = (Vector) {.x = 0.0f, .y = 15.0f },
|
||||||
.TargetRect = (SDL_Rect) {.x = width / 2 - 15, .y = height - 130, .w = 30, .h = 30 },
|
.TargetRect = (SDL_Rect) {.x = BREAKOUT_BoxWidth / 2 - 15, .y = BREAKOUT_BoxHeight - 130, .w = 30, .h = 30 },
|
||||||
.Size = 15.0f,
|
.Size = 15.0f,
|
||||||
.Rotation = 0,
|
.Rotation = rotation,
|
||||||
.RotationValue = 9,
|
.RotationValue = 5,
|
||||||
.TextureIndex = 0,
|
.TextureIndex = 0,
|
||||||
.Speed = 15.0f
|
.Speed = 15.0f
|
||||||
}; // Objekt für die Eigenschaften des Balls
|
}; // Objekt für die Eigenschaften des Balls
|
||||||
}
|
}
|
||||||
|
|
||||||
void BALL_ResetPosition(Ball * obj){
|
void BALL_ResetPosition(Ball * obj){
|
||||||
(obj->Location).x = width / 2 - 15;
|
(obj->Location).x = BREAKOUT_BoxWidth / 2 - 15;
|
||||||
(obj->Location).y = height - 130;
|
(obj->Location).y = BREAKOUT_BoxHeight - 130;
|
||||||
RECT_SetTargetPos(&(obj->TargetRect), &(obj->Location));
|
RECT_SetTargetPos(&(obj->TargetRect), &(obj->Location));
|
||||||
(obj->Momentum) = VECTOR_GetScaledDirectionalUnitVector(0.0f, (obj->Speed));
|
(obj->Momentum) = VECTOR_GetScaledDirectionalUnitVector(0.0f, (obj->Speed));
|
||||||
}
|
}
|
||||||
|
|
||||||
void BALL_DrawTexture(SDL_Renderer * renderer, SDL_Rect * dstRect, int index){
|
|
||||||
if (index > BALL_TextureCount || index < 0) {
|
|
||||||
printf("Ball with unkown texture index %d aus [0,...,%d]\n", index, (BALL_TextureCount - 1));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SDL_RenderCopy(renderer, BALL_Texture, BALL_SourceRects + index, dstRect);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BALL_Draw(SDL_Renderer * renderer, Ball * obj){
|
void BALL_Draw(SDL_Renderer * renderer, Ball * obj){
|
||||||
// printf("Ball drawn at (%d|%d)!\n", (obj->TargetRect).x, (obj->TargetRect).x);
|
// printf("Ball drawn at (%d|%d)!\n", (obj->TargetRect).x, (obj->TargetRect).x);
|
||||||
SDL_RenderCopyEx(renderer, BALL_Texture, BALL_SourceRects + (obj->TextureIndex), &(obj->TargetRect), obj->Rotation, NULL, SDL_FLIP_NONE);
|
SDL_RenderCopyEx(renderer, BALL_Texture, BALL_SourceRects + (obj->TextureIndex), &(obj->TargetRect), obj->Rotation, NULL, SDL_FLIP_NONE);
|
||||||
@ -357,7 +308,7 @@ SDL_Point BALL_GetCenter(Ball * obj){
|
|||||||
void BALL_CollideWithBorders(Ball * obj){
|
void BALL_CollideWithBorders(Ball * obj){
|
||||||
if ((obj->Location).y < 0.0f)
|
if ((obj->Location).y < 0.0f)
|
||||||
(obj->Momentum).y = -(obj->Momentum).y;
|
(obj->Momentum).y = -(obj->Momentum).y;
|
||||||
if ((obj->Location).x < 0.0f || (obj->Location).x > width - (2 * (obj->Size)))
|
if ((obj->Location).x < 0.0f || (obj->Location).x > BREAKOUT_BoxWidth - (2 * (obj->Size)))
|
||||||
(obj->Momentum).x = -(obj->Momentum).x;
|
(obj->Momentum).x = -(obj->Momentum).x;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -366,7 +317,7 @@ void BALL_MoveAwayFromBoundaries(Ball * obj){
|
|||||||
((obj->Location).y)++;
|
((obj->Location).y)++;
|
||||||
while (((obj->Location).x) < 0)
|
while (((obj->Location).x) < 0)
|
||||||
((obj->Location).x)++;
|
((obj->Location).x)++;
|
||||||
while ((((obj->Location).x) + ((obj->Size) * 2)) > width)
|
while ((((obj->Location).x) + ((obj->Size) * 2)) > BREAKOUT_BoxWidth)
|
||||||
((obj->Location).x)--;
|
((obj->Location).x)--;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -416,19 +367,16 @@ void BALL_Update(Ball * obj, Scenery * scenery){
|
|||||||
oldLocation = obj->Location;
|
oldLocation = obj->Location;
|
||||||
if (BALL_CollideWithRect(obj, &(blocks[i].TargetRect))) {
|
if (BALL_CollideWithRect(obj, &(blocks[i].TargetRect))) {
|
||||||
BLOCK_DealDamage(blocks + i, 1);
|
BLOCK_DealDamage(blocks + i, 1);
|
||||||
if (blocks[i].HP <= 0) {
|
if (blocks[i].HP <= 0)
|
||||||
(scenery->DestroyedBlocks)++;
|
(scenery->DestroyedBlocks)++;
|
||||||
BREAKOUT_IncreaseScoreBy(scenery, (int)round((((scenery->ball).Speed) * ((scenery->ball).Speed) / 5.0f)));
|
|
||||||
}
|
|
||||||
(obj->Location) = VECTOR_Add(oldLocation, (obj->Momentum));
|
(obj->Location) = VECTOR_Add(oldLocation, (obj->Momentum));
|
||||||
BALL_MoveAwayFromBoundaries(obj);
|
BALL_MoveAwayFromBoundaries(obj);
|
||||||
RECT_SetTargetPos(&(obj->TargetRect), &(obj->Location));
|
RECT_SetTargetPos(&(obj->TargetRect), &(obj->Location));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((obj->Location).y > height) { // Collide with box boundaries
|
if ((obj->Location).y > BREAKOUT_BoxHeight) // Collide with box boundaries
|
||||||
scenery->IsGameOver = true;
|
scenery->IsGameOver = true;
|
||||||
printf("Ball called game_over!\n");
|
else BALL_CollideWithBorders(obj);
|
||||||
} else BALL_CollideWithBorders(obj);
|
|
||||||
RECT_SetTargetPos(&(obj->TargetRect), &(obj->Location));
|
RECT_SetTargetPos(&(obj->TargetRect), &(obj->Location));
|
||||||
} /* BALL_Update */
|
} /* BALL_Update */
|
||||||
|
|
||||||
@ -468,8 +416,10 @@ void PADDLE_Initialize(SDL_Renderer * renderer){
|
|||||||
} /* PADDLE_Initialize */
|
} /* PADDLE_Initialize */
|
||||||
|
|
||||||
Paddle PADDLE_CreateDefault(){
|
Paddle PADDLE_CreateDefault(){
|
||||||
|
int defaultpaddlewidth = 300;
|
||||||
|
|
||||||
return (Paddle) {
|
return (Paddle) {
|
||||||
.TargetRect = (SDL_Rect) {.x = (width - PADDLE_MaxSize) / 2, .y = height - 100, .w = PADDLE_MaxSize, .h = 30 },
|
.TargetRect = (SDL_Rect) {.x = (BREAKOUT_BoxWidth - defaultpaddlewidth) / 2, .y = BREAKOUT_BoxHeight - 100, .w = defaultpaddlewidth, .h = 30 },
|
||||||
.TextureIndex = 0,
|
.TextureIndex = 0,
|
||||||
.Speed = 10,
|
.Speed = 10,
|
||||||
.SteeringAngle = 40.0f,
|
.SteeringAngle = 40.0f,
|
||||||
@ -478,16 +428,8 @@ Paddle PADDLE_CreateDefault(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PADDLE_ResetPosition(Paddle * obj){
|
void PADDLE_ResetPosition(Paddle * obj){
|
||||||
(obj->TargetRect).x = (width - ((obj->TargetRect).w)) / 2;
|
(obj->TargetRect).x = (BREAKOUT_BoxWidth - ((obj->TargetRect).w)) / 2;
|
||||||
(obj->TargetRect).y = height - 100;
|
(obj->TargetRect).y = BREAKOUT_BoxHeight - 100;
|
||||||
}
|
|
||||||
|
|
||||||
void PADDLE_DrawTexture(SDL_Renderer * renderer, SDL_Rect * dstRect, int index){
|
|
||||||
if (index > PADDLE_TextureCount || index < 0) {
|
|
||||||
printf("Paddle with unkown texture index %d aus [0,...,%d]\n", index, (PADDLE_TextureCount - 1));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SDL_RenderCopy(renderer, PADDLE_Texture, PADDLE_SourceRects + index, dstRect);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PADDLE_Draw(SDL_Renderer * renderer, Paddle * obj){
|
void PADDLE_Draw(SDL_Renderer * renderer, Paddle * obj){
|
||||||
@ -525,15 +467,7 @@ void PADDLE_MoveSmooth(Paddle * obj){
|
|||||||
(obj->TargetRect).x = paddleXMid - (int)roundf((float)(paddleXMid - mouseX) * PADDLE_SmoothFactor) - halfPaddle;
|
(obj->TargetRect).x = paddleXMid - (int)roundf((float)(paddleXMid - mouseX) * PADDLE_SmoothFactor) - halfPaddle;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PADDLE_AdaptSpeedGradient(Paddle * obj, int FrameCount){
|
void PADDLE_Update(Paddle * obj, const Uint8 * keystate){
|
||||||
if (FrameCount > PADDLE_AccelerationTime)
|
|
||||||
return;
|
|
||||||
(obj->TargetRect).w = PADDLE_MaxSize - (((double)FrameCount / (double)PADDLE_AccelerationTime) * (PADDLE_MaxSize - PADDLE_MinSize));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void PADDLE_Update(Paddle * obj, Scenery * scenery, const Uint8 * keystate){
|
|
||||||
PADDLE_AdaptSpeedGradient(obj, (scenery->Frames));
|
|
||||||
bool leftKeyPressed, rightKeyPressed;
|
bool leftKeyPressed, rightKeyPressed;
|
||||||
|
|
||||||
switch (obj->Mode) {
|
switch (obj->Mode) {
|
||||||
@ -554,7 +488,7 @@ void PADDLE_Update(Paddle * obj, Scenery * scenery, const Uint8 * keystate){
|
|||||||
printf("Unknown Paddle Control Mode: %d!\n", obj->Mode);
|
printf("Unknown Paddle Control Mode: %d!\n", obj->Mode);
|
||||||
break;
|
break;
|
||||||
} /* switch */
|
} /* switch */
|
||||||
INT_Constrain(&((obj->TargetRect).x), 0, (width - ((obj->TargetRect).w)));
|
INT_Constrain(&((obj->TargetRect).x), 0, (BREAKOUT_BoxWidth - ((obj->TargetRect).w)));
|
||||||
} /* PADDLE_Update */
|
} /* PADDLE_Update */
|
||||||
|
|
||||||
void PADDLE_DestroyObject(Paddle * obj){
|
void PADDLE_DestroyObject(Paddle * obj){
|
||||||
@ -613,14 +547,6 @@ Block BLOCK_CreateDefault() {
|
|||||||
}; // Objekt für die Eigenschaften des Balls
|
}; // Objekt für die Eigenschaften des Balls
|
||||||
}
|
}
|
||||||
|
|
||||||
void BLOCK_DrawTexture(SDL_Renderer * renderer, SDL_Rect * dstRect, int index){
|
|
||||||
if (index > BLOCK_TextureCount || index < 0) {
|
|
||||||
printf("Block with unkown texture index %d aus [0,...,%d]\n", index, (BLOCK_TextureCount - 1));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SDL_RenderCopy(renderer, BLOCK_Texture, BLOCK_SourceRects + index, dstRect);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BLOCK_Draw(SDL_Renderer * renderer, Block * obj){
|
void BLOCK_Draw(SDL_Renderer * renderer, Block * obj){
|
||||||
if ((obj->HP) > 0) {
|
if ((obj->HP) > 0) {
|
||||||
// printf("Block drawn at (%d|%d)!\n", (obj->TargetRect).x, (obj->TargetRect).y);
|
// printf("Block drawn at (%d|%d)!\n", (obj->TargetRect).x, (obj->TargetRect).y);
|
||||||
|
16
breakout.h
16
breakout.h
@ -45,22 +45,17 @@ typedef struct sceneryStruct {
|
|||||||
// End Structs
|
// End Structs
|
||||||
|
|
||||||
// Prototypes
|
// Prototypes
|
||||||
void BREAKOUT_INITIALIZE(SDL_Renderer * renderer);
|
void BREAKOUT_INITIALIZE(SDL_Renderer * renderer, int width, int height);
|
||||||
void BREAKOUT_TogglePause(Scenery * scenery);
|
|
||||||
void BREAKOUT_KeyPressed(Scenery * scenery, SDL_KeyboardEvent * b);
|
|
||||||
Scenery BREAKOUT_CreateDefault();
|
Scenery BREAKOUT_CreateDefault();
|
||||||
void BREAKOUT_IncreaseScoreBy(Scenery * scenery, int scoreInc);
|
int BREAKOUT_RefreshScore(Scenery * scenery);
|
||||||
void TEXTURE_RenderCenteredSpriteSheet(SDL_Renderer * renderer, SDL_Texture * texture, SDL_Rect * srcRect, float Scale);
|
void BREAKOUT_ChangeSize(int width, int height);
|
||||||
void TEXTURE_RenderCentered(SDL_Renderer * renderer, SDL_Texture * texture, float Scale);
|
|
||||||
void BREAKOUT_Update(Scenery * scenery, const Uint8 * keystate);
|
void BREAKOUT_Update(Scenery * scenery, const Uint8 * keystate);
|
||||||
void BREAKOUT_Draw(Scenery * scenery, SDL_Renderer * renderer);
|
void BREAKOUT_Draw(Scenery * scenery, SDL_Renderer * renderer);
|
||||||
void BREAKOUT_DrawLivesHUD(SDL_Renderer * renderer, Scenery * scenery);
|
|
||||||
void BREAKOUT_DEINITIALIZE();
|
void BREAKOUT_DEINITIALIZE();
|
||||||
void BREAKOUT_DestroyObject(Scenery * scenery);
|
void BREAKOUT_DestroyObject(Scenery * scenery);
|
||||||
void BALL_Initialize(SDL_Renderer * renderer);
|
void BALL_Initialize(SDL_Renderer * renderer);
|
||||||
Ball BALL_CreateDefault();
|
Ball BALL_CreateDefault();
|
||||||
void BALL_ResetPosition(Ball * obj);
|
void BALL_ResetPosition(Ball * obj);
|
||||||
void BALL_DrawTexture(SDL_Renderer * renderer, SDL_Rect * dstRect, int index);
|
|
||||||
void BALL_Draw(SDL_Renderer * renderer, Ball * obj);
|
void BALL_Draw(SDL_Renderer * renderer, Ball * obj);
|
||||||
bool BALL_CollideWithRect(Ball * obj, SDL_Rect * rect);
|
bool BALL_CollideWithRect(Ball * obj, SDL_Rect * rect);
|
||||||
bool RECT_Collide(SDL_Rect * rect1, SDL_Rect * rect2);
|
bool RECT_Collide(SDL_Rect * rect1, SDL_Rect * rect2);
|
||||||
@ -77,19 +72,16 @@ void BALL_Deinitialize();
|
|||||||
void PADDLE_Initialize(SDL_Renderer * renderer);
|
void PADDLE_Initialize(SDL_Renderer * renderer);
|
||||||
Paddle PADDLE_CreateDefault();
|
Paddle PADDLE_CreateDefault();
|
||||||
void PADDLE_ResetPosition(Paddle * obj);
|
void PADDLE_ResetPosition(Paddle * obj);
|
||||||
void PADDLE_DrawTexture(SDL_Renderer * renderer, SDL_Rect * dstRect, int index);
|
|
||||||
void PADDLE_Draw(SDL_Renderer * renderer, Paddle * obj);
|
void PADDLE_Draw(SDL_Renderer * renderer, Paddle * obj);
|
||||||
bool KeyPressed(const Uint8 * keystate, Uint8 * keyArray);
|
bool KeyPressed(const Uint8 * keystate, Uint8 * keyArray);
|
||||||
void INT_Constrain(int * variable, int min, int max);
|
void INT_Constrain(int * variable, int min, int max);
|
||||||
void DOUBLE_Constrain(double * variable, double min, double max);
|
void DOUBLE_Constrain(double * variable, double min, double max);
|
||||||
void PADDLE_MoveSmooth(Paddle * obj);
|
void PADDLE_MoveSmooth(Paddle * obj);
|
||||||
void PADDLE_AdaptSpeedGradient(Paddle * obj, int FrameCount);
|
void PADDLE_Update(Paddle * obj, const Uint8 * keystate);
|
||||||
void PADDLE_Update(Paddle * obj, Scenery * scenery, const Uint8 * keystate);
|
|
||||||
void PADDLE_DestroyObject(Paddle * obj);
|
void PADDLE_DestroyObject(Paddle * obj);
|
||||||
void PADDLE_Deinitialize();
|
void PADDLE_Deinitialize();
|
||||||
void BLOCK_Initialize(SDL_Renderer * renderer);
|
void BLOCK_Initialize(SDL_Renderer * renderer);
|
||||||
Block BLOCK_CreateDefault() ;
|
Block BLOCK_CreateDefault() ;
|
||||||
void BLOCK_DrawTexture(SDL_Renderer * renderer, SDL_Rect * dstRect, int index);
|
|
||||||
void BLOCK_Draw(SDL_Renderer * renderer, Block * obj);
|
void BLOCK_Draw(SDL_Renderer * renderer, Block * obj);
|
||||||
void BLOCK_DealDamage(Block * obj, int dmg);
|
void BLOCK_DealDamage(Block * obj, int dmg);
|
||||||
void BLOCK_Update(Block * obj);
|
void BLOCK_Update(Block * obj);
|
||||||
|
155
gameover.c
155
gameover.c
@ -1,155 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <math.h>
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include <SDL2/SDL_image.h>
|
|
||||||
#include <SDL2/SDL_ttf.h>
|
|
||||||
|
|
||||||
#include "gameover.h"
|
|
||||||
#include "gamestate.h"
|
|
||||||
#include "main.h"
|
|
||||||
|
|
||||||
#define GAMEOVER_TexturePath "assets/images/gameover.png"
|
|
||||||
#define GAMEOVER_NumbersTexturePath "assets/images/numbers.png"
|
|
||||||
#define GAMEOVER_ScoreTexturePath "assets/images/yourscore.png"
|
|
||||||
#define GAMEOVER_HUDScale 16.0f
|
|
||||||
#define GAMEOVER_Scale 4.0f
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <math.h>
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include <SDL2/SDL_image.h>
|
|
||||||
#include <SDL2/SDL_ttf.h>
|
|
||||||
|
|
||||||
#include "breakout.h"
|
|
||||||
#include "vector.h"
|
|
||||||
#include "background.h"
|
|
||||||
|
|
||||||
int GAMEOVER_HUDMargin = 5;
|
|
||||||
SDL_Texture * GAMEOVER_Texture;
|
|
||||||
SDL_Texture * GAMEOVER_Numbers;
|
|
||||||
SDL_Texture * GAMEOVER_ScoreTexture;
|
|
||||||
SDL_Rect * GAMEOVER_NumberRects;
|
|
||||||
SDL_Rect GAMEOVER_TargetRect;
|
|
||||||
SDL_Rect GAMEOVER_ScoreTargetRect;
|
|
||||||
SDL_Rect GAMEOVER_HUDScoreTargetRect;
|
|
||||||
int * GAMEOVER_Digits;
|
|
||||||
bool GAMEOVER_IsInit = false;
|
|
||||||
|
|
||||||
void GAMEOVER_Initialize(SDL_Renderer * renderer){
|
|
||||||
if (!GAMEOVER_IsInit) {
|
|
||||||
printf("Initializing Gameover...\n");
|
|
||||||
GAMEOVER_Texture = IMG_LoadTexture(renderer, GAMEOVER_TexturePath);
|
|
||||||
if (!GAMEOVER_Texture) printf("Gameover Texture couldn't be loaded!\n");
|
|
||||||
GAMEOVER_Numbers = IMG_LoadTexture(renderer, GAMEOVER_NumbersTexturePath);
|
|
||||||
if (!GAMEOVER_Numbers) printf("Gameover Numbers couldn't be loaded!\n");
|
|
||||||
GAMEOVER_ScoreTexture = IMG_LoadTexture(renderer, GAMEOVER_ScoreTexturePath);
|
|
||||||
if (!GAMEOVER_ScoreTexture) printf("Gameover Score Texture couldn't be loaded!\n");
|
|
||||||
int w, h;
|
|
||||||
SDL_QueryTexture(GAMEOVER_Texture, NULL, NULL, &w, &h);
|
|
||||||
w /= 2;
|
|
||||||
h /= 2;
|
|
||||||
GAMEOVER_TargetRect.x = ((1920 - w) / 2);
|
|
||||||
GAMEOVER_TargetRect.y = 50;
|
|
||||||
GAMEOVER_TargetRect.w = w;
|
|
||||||
GAMEOVER_TargetRect.h = h;
|
|
||||||
GAMEOVER_NumberRects = calloc(10, sizeof(SDL_Rect));
|
|
||||||
if (!GAMEOVER_NumberRects) printf("FATAL: Memory Allocation Failed!\n");
|
|
||||||
GAMEOVER_NumberRects[0] = (SDL_Rect) {.x = 446, .y = 668, .w = 442, .h = 665 };
|
|
||||||
GAMEOVER_NumberRects[1] = (SDL_Rect) {.x = 1299, .y = 1335, .w = 242, .h = 665 };
|
|
||||||
GAMEOVER_NumberRects[2] = (SDL_Rect) {.x = 1, .y = 1, .w = 443, .h = 665 };
|
|
||||||
GAMEOVER_NumberRects[3] = (SDL_Rect) {.x = 1, .y = 668, .w = 443, .h = 665 };
|
|
||||||
GAMEOVER_NumberRects[4] = (SDL_Rect) {.x = 1, .y = 1335, .w = 443, .h = 665 };
|
|
||||||
GAMEOVER_NumberRects[5] = (SDL_Rect) {.x = 446, .y = 1, .w = 443, .h = 665 };
|
|
||||||
GAMEOVER_NumberRects[6] = (SDL_Rect) {.x = 891, .y = 1, .w = 443, .h = 665 };
|
|
||||||
GAMEOVER_NumberRects[7] = (SDL_Rect) {.x = 890, .y = 1335, .w = 407, .h = 665 };
|
|
||||||
GAMEOVER_NumberRects[8] = (SDL_Rect) {.x = 446, .y = 1335, .w = 442, .h = 665 };
|
|
||||||
GAMEOVER_NumberRects[9] = (SDL_Rect) {.x = 890, .y = 668, .w = 442, .h = 665 };
|
|
||||||
GAMEOVER_ScoreTargetRect.y = 450;
|
|
||||||
GAMEOVER_ScoreTargetRect.h = 183;
|
|
||||||
GAMEOVER_ScoreTargetRect.w = 1000;
|
|
||||||
GAMEOVER_HUDScoreTargetRect = (SDL_Rect) {.x = GAMEOVER_HUDMargin, .y = GAMEOVER_HUDMargin, .w = 250, .h = 46 };
|
|
||||||
GAMEOVER_Digits = malloc(25 * sizeof(int));
|
|
||||||
printf("Gameover initialized!\n");
|
|
||||||
GAMEOVER_IsInit = true;
|
|
||||||
} else
|
|
||||||
printf("Gameover already initialized!\n");
|
|
||||||
} /* GAMEOVER_Initialize */
|
|
||||||
|
|
||||||
void GAMEOVER_Draw(SDL_Renderer * renderer, Scenery * scenery){
|
|
||||||
int i, count;
|
|
||||||
|
|
||||||
SDL_RenderCopy(renderer, GAMEOVER_Texture, NULL, &GAMEOVER_TargetRect);
|
|
||||||
GAMEOVER_GetDigits((scenery->Score), &count);
|
|
||||||
int totalWidth = GAMEOVER_ScoreTargetRect.w;
|
|
||||||
for (i = (count - 1); i >= 0; i--) {
|
|
||||||
totalWidth += (int)roundf((float)GAMEOVER_NumberRects[i].w / GAMEOVER_Scale);
|
|
||||||
}
|
|
||||||
GAMEOVER_ScoreTargetRect.x = ((1920 - totalWidth) / 2);
|
|
||||||
SDL_RenderCopy(renderer, GAMEOVER_ScoreTexture, NULL, &GAMEOVER_ScoreTargetRect);
|
|
||||||
int xOffset = GAMEOVER_ScoreTargetRect.x + GAMEOVER_ScoreTargetRect.w;
|
|
||||||
SDL_Rect target;
|
|
||||||
target.y = 450;
|
|
||||||
for (i = (count - 1); i >= 0; i--) {
|
|
||||||
target.x = xOffset;
|
|
||||||
target.h = (int)roundf((float)(GAMEOVER_NumberRects[GAMEOVER_Digits[i]].h) / GAMEOVER_Scale);
|
|
||||||
target.w = (int)roundf((float)(GAMEOVER_NumberRects[GAMEOVER_Digits[i]].w) / GAMEOVER_Scale);
|
|
||||||
SDL_RenderCopy(renderer, GAMEOVER_Numbers, (GAMEOVER_NumberRects + GAMEOVER_Digits[i]), &target);
|
|
||||||
xOffset += target.w;
|
|
||||||
}
|
|
||||||
} /* GAMEOVER_Draw */
|
|
||||||
|
|
||||||
void GAMEOVER_GetDigits(int input, int * digitCount){
|
|
||||||
int score = input;
|
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
while (score != 0) {
|
|
||||||
GAMEOVER_Digits[(count++)] = (score % 10);
|
|
||||||
score /= 10;
|
|
||||||
}
|
|
||||||
if (count == 0) {
|
|
||||||
count = 1;
|
|
||||||
GAMEOVER_Digits[0] = 0;
|
|
||||||
}
|
|
||||||
*digitCount = count;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SCORE_DrawHUD(SDL_Renderer * renderer, Scenery * scenery){
|
|
||||||
int i, count;
|
|
||||||
|
|
||||||
GAMEOVER_GetDigits((scenery->Score), &count);
|
|
||||||
int totalWidth = GAMEOVER_HUDScoreTargetRect.w;
|
|
||||||
for (i = (count - 1); i >= 0; i--) {
|
|
||||||
totalWidth += (int)roundf((float)GAMEOVER_NumberRects[i].w / GAMEOVER_HUDScale);
|
|
||||||
}
|
|
||||||
GAMEOVER_HUDScoreTargetRect.x = GAMEOVER_HUDMargin;
|
|
||||||
SDL_RenderCopy(renderer, GAMEOVER_ScoreTexture, NULL, &GAMEOVER_HUDScoreTargetRect);
|
|
||||||
int xOffset = GAMEOVER_HUDScoreTargetRect.x + GAMEOVER_HUDScoreTargetRect.w;
|
|
||||||
SDL_Rect target;
|
|
||||||
target.y = GAMEOVER_HUDMargin;
|
|
||||||
for (i = (count - 1); i >= 0; i--) {
|
|
||||||
target.x = xOffset;
|
|
||||||
target.h = (int)roundf((float)(GAMEOVER_NumberRects[GAMEOVER_Digits[i]].h) / GAMEOVER_HUDScale);
|
|
||||||
target.w = (int)roundf((float)(GAMEOVER_NumberRects[GAMEOVER_Digits[i]].w) / GAMEOVER_HUDScale);
|
|
||||||
SDL_RenderCopy(renderer, GAMEOVER_Numbers, (GAMEOVER_NumberRects + GAMEOVER_Digits[i]), &target);
|
|
||||||
xOffset += target.w;
|
|
||||||
}
|
|
||||||
} /* SCORE_DrawHUD */
|
|
||||||
|
|
||||||
void GAMEOVER_Deinitialize(){
|
|
||||||
if (GAMEOVER_IsInit) {
|
|
||||||
printf("De-initializing Gameover...\n");
|
|
||||||
free(GAMEOVER_Digits);
|
|
||||||
SDL_DestroyTexture(GAMEOVER_Texture);
|
|
||||||
SDL_DestroyTexture(GAMEOVER_ScoreTexture);
|
|
||||||
SDL_DestroyTexture(GAMEOVER_Numbers);
|
|
||||||
printf("Gameover de-initialized!\n");
|
|
||||||
GAMEOVER_IsInit = false;
|
|
||||||
} else
|
|
||||||
printf("Gameover already de-initialized!\n");
|
|
||||||
}
|
|
25
gameover.h
25
gameover.h
@ -1,25 +0,0 @@
|
|||||||
#ifndef __gameover_h__
|
|
||||||
#define __gameover_h__
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <math.h>
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include <SDL2/SDL_image.h>
|
|
||||||
#include <SDL2/SDL_ttf.h>
|
|
||||||
|
|
||||||
#include "gameover.h"
|
|
||||||
#include "gamestate.h"
|
|
||||||
#include "main.h"
|
|
||||||
|
|
||||||
// Prototypes
|
|
||||||
void GAMEOVER_Initialize(SDL_Renderer * renderer);
|
|
||||||
void GAMEOVER_Draw(SDL_Renderer * renderer, Scenery * scenery);
|
|
||||||
void GAMEOVER_GetDigits(int input, int * digitCount);
|
|
||||||
void SCORE_DrawHUD(SDL_Renderer * renderer, Scenery * scenery);
|
|
||||||
void GAMEOVER_Deinitialize();
|
|
||||||
// End Prototypes
|
|
||||||
|
|
||||||
#endif // __gameover_h__
|
|
@ -1,6 +1,6 @@
|
|||||||
#ifndef __gamestate_h__
|
#ifndef __gamestate_h__
|
||||||
#define __gamestate_h__
|
#define __gamestate_h__
|
||||||
|
|
||||||
typedef enum gameStateEnum { MainMenu = 1, Game = 2, LevelSelect = 3, SkinSelect = 4, Settings = 5, Highscores = 6 , GameOver = 7 } GameState;
|
typedef enum gameStateEnum { MainMenu = 1, Game = 2, LevelSelect = 3, SkinSelect = 4, Settings = 5, Highscores = 6 } GameState;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
29
highscores.c
29
highscores.c
@ -9,7 +9,6 @@
|
|||||||
#include "highscores.h"
|
#include "highscores.h"
|
||||||
|
|
||||||
#define HIGHSCORES_FontFile "assets/fonts/monofur.ttf"
|
#define HIGHSCORES_FontFile "assets/fonts/monofur.ttf"
|
||||||
#define HIGHSCORES_OutputFilePath "output.txt"
|
|
||||||
|
|
||||||
int HIGHSCORES_EntriesGot = 0;
|
int HIGHSCORES_EntriesGot = 0;
|
||||||
User * HIGHSCORES_UserList;
|
User * HIGHSCORES_UserList;
|
||||||
@ -104,32 +103,6 @@ void HIGHSCORES_DrawText(char * text, SDL_Rect * Message_rect){
|
|||||||
tempSurface = TTF_RenderText_Solid(HIGHSCORES_FontFamily, text, HIGHSCORES_FontColor);
|
tempSurface = TTF_RenderText_Solid(HIGHSCORES_FontFamily, text, HIGHSCORES_FontColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HIGHSCORES_UploadScore(char * username, int score){
|
|
||||||
char buffer[200];
|
|
||||||
char * line = NULL;
|
|
||||||
size_t len = 0;
|
|
||||||
ssize_t read;
|
|
||||||
char * name, * scorestring;
|
|
||||||
|
|
||||||
sprintf(buffer, "bhi upload %s %s %d", HIGHSCORES_OutputFilePath, username, score);
|
|
||||||
printf("BHI called with \"%s\"\n", buffer);
|
|
||||||
printf("Call BHI interface:\n");
|
|
||||||
system(buffer);
|
|
||||||
printf("BHI interface quit!\nBHI output handling...\n");
|
|
||||||
FILE * fp = fopen(HIGHSCORES_OutputFilePath, "r");
|
|
||||||
if (fp == NULL) {
|
|
||||||
fclose(fp);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if ((read = getline(&line, &len, fp)) != -1)
|
|
||||||
if (line[0] == '0') {
|
|
||||||
fclose(fp);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
fclose(fp);
|
|
||||||
return true;
|
|
||||||
} /* HIGHSCORES_UploadScore */
|
|
||||||
|
|
||||||
void HIGHSCORES_ReloadList(){
|
void HIGHSCORES_ReloadList(){
|
||||||
printf("Call BHI interface:\n");
|
printf("Call BHI interface:\n");
|
||||||
system("bhi top output.txt");
|
system("bhi top output.txt");
|
||||||
@ -148,7 +121,7 @@ void HIGHSCORES_ReloadList(){
|
|||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
return;
|
return;
|
||||||
if ((read = getline(&line, &len, fp)) != -1)
|
if ((read = getline(&line, &len, fp)) != -1)
|
||||||
if (line[0] == '0')
|
if (line[0] == 0)
|
||||||
return;
|
return;
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
while ((read = getline(&line, &len, fp)) != -1) {
|
while ((read = getline(&line, &len, fp)) != -1) {
|
||||||
|
@ -14,7 +14,6 @@ void HIGHSCORES_Draw(SDL_Renderer * renderer);
|
|||||||
void HIGHSCORES_Deinitialize();
|
void HIGHSCORES_Deinitialize();
|
||||||
void HIGHSCORES_GenerateTexture(SDL_Renderer * renderer);
|
void HIGHSCORES_GenerateTexture(SDL_Renderer * renderer);
|
||||||
void HIGHSCORES_DrawText(char * text, SDL_Rect * Message_rect);
|
void HIGHSCORES_DrawText(char * text, SDL_Rect * Message_rect);
|
||||||
bool HIGHSCORES_UploadScore(char * username, int score);
|
|
||||||
void HIGHSCORES_ReloadList();
|
void HIGHSCORES_ReloadList();
|
||||||
// End Prototypes
|
// End Prototypes
|
||||||
|
|
||||||
|
23
main.c
23
main.c
@ -12,7 +12,6 @@
|
|||||||
#include "startmenu.h"
|
#include "startmenu.h"
|
||||||
#include "gamestate.h"
|
#include "gamestate.h"
|
||||||
#include "highscores.h"
|
#include "highscores.h"
|
||||||
#include "gameover.h"
|
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "background.h"
|
#include "background.h"
|
||||||
|
|
||||||
@ -56,15 +55,12 @@ int main(int argc, char * args[]){
|
|||||||
HIGHSCORES_Draw(renderer);
|
HIGHSCORES_Draw(renderer);
|
||||||
break;
|
break;
|
||||||
case Settings:
|
case Settings:
|
||||||
Settings_Draw(renderer, &scenery);
|
Settings_Draw(renderer,&scenery);
|
||||||
break;
|
|
||||||
case GameOver:
|
|
||||||
GAMEOVER_Draw(renderer, &scenery);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("Unknow state was updated: %d\n", gameState);
|
printf("Unknow state was updated: %d\n", gameState);
|
||||||
break;
|
break;
|
||||||
} /* switch */
|
}
|
||||||
SDL_RenderPresent(renderer);
|
SDL_RenderPresent(renderer);
|
||||||
fps_frames++;
|
fps_frames++;
|
||||||
if (fps_lasttime < SDL_GetTicks() - 1000) {
|
if (fps_lasttime < SDL_GetTicks() - 1000) {
|
||||||
@ -138,14 +134,6 @@ void keyPress(SDL_KeyboardEvent b){ // Debug prop
|
|||||||
printf("Key pressed: ID is %d\n", b.keysym.scancode);
|
printf("Key pressed: ID is %d\n", b.keysym.scancode);
|
||||||
if (b.keysym.scancode == SDL_SCANCODE_F11 || b.keysym.scancode == SDL_SCANCODE_5) {
|
if (b.keysym.scancode == SDL_SCANCODE_F11 || b.keysym.scancode == SDL_SCANCODE_5) {
|
||||||
toggleFullscreen();
|
toggleFullscreen();
|
||||||
} else {
|
|
||||||
switch (gameState) {
|
|
||||||
case Game:
|
|
||||||
BREAKOUT_KeyPressed(&scenery, &b);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,23 +176,20 @@ void INITIALIZE() {
|
|||||||
|
|
||||||
window = SDL_CreateWindow("BreakING", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL);
|
window = SDL_CreateWindow("BreakING", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL);
|
||||||
SDL_SetWindowResizable(window, true);
|
SDL_SetWindowResizable(window, true);
|
||||||
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
|
|
||||||
printf("Window was created!\n");
|
printf("Window was created!\n");
|
||||||
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
||||||
printf("Renderer was created!\n");
|
printf("Renderer was created!\n");
|
||||||
BREAKOUT_INITIALIZE(renderer);
|
BREAKOUT_INITIALIZE(renderer, width, height);
|
||||||
scenery = BREAKOUT_CreateDefault();
|
scenery = BREAKOUT_CreateDefault();
|
||||||
Load_Textures(renderer);
|
Load_Textures(renderer);
|
||||||
HIGHSCORES_Initialize();
|
HIGHSCORES_Initialize();
|
||||||
BACKGROUND_Initialize(renderer, width, height);
|
BACKGROUND_Initialize(renderer, width, height);
|
||||||
Settings_Initialize(renderer);
|
Settings_Initialize(renderer,&scenery);
|
||||||
GAMEOVER_Initialize(renderer);
|
|
||||||
printf("Initializing finished!\n");
|
printf("Initializing finished!\n");
|
||||||
} /* INITIALIZE */
|
} /* INITIALIZE */
|
||||||
|
|
||||||
void QUIT(){
|
void QUIT(){
|
||||||
printf("De-initializing started...\n");
|
printf("De-initializing started...\n");
|
||||||
GAMEOVER_Deinitialize();
|
|
||||||
BACKGROUND_Deinitialize();
|
BACKGROUND_Deinitialize();
|
||||||
Settings_Deinitialize();
|
Settings_Deinitialize();
|
||||||
HIGHSCORES_Deinitialize();
|
HIGHSCORES_Deinitialize();
|
||||||
|
3
main.h
3
main.h
@ -15,9 +15,6 @@
|
|||||||
#include "startmenu.h"
|
#include "startmenu.h"
|
||||||
#include "gamestate.h"
|
#include "gamestate.h"
|
||||||
#include "highscores.h"
|
#include "highscores.h"
|
||||||
#include "gameover.h"
|
|
||||||
#include "settings.h"
|
|
||||||
#include "background.h"
|
|
||||||
|
|
||||||
#ifndef __nullptr__
|
#ifndef __nullptr__
|
||||||
#define Nullptr(type) (type *)0
|
#define Nullptr(type) (type *)0
|
||||||
|
125
settings.c
125
settings.c
@ -9,89 +9,102 @@
|
|||||||
#define Slider_height 100
|
#define Slider_height 100
|
||||||
#define Scalar_width 20
|
#define Scalar_width 20
|
||||||
#define Bar_width 400
|
#define Bar_width 400
|
||||||
#define round(x) ((int)((x) + .5))
|
#define round(x) ((int) ((x) + .5))
|
||||||
|
#define distance(x1,y1,x2,y2) ((int)(sqrt(pow(x2-x1,2)+pow(y2-y1,2))))
|
||||||
|
|
||||||
SDL_Texture * Settings_Texture;
|
SDL_Texture* Settings_Texture;
|
||||||
SDL_Texture * Settings_Ball_Texture;
|
SDL_Texture* Settings_Return_Button_Texture;
|
||||||
|
|
||||||
SDL_Rect Settings_rect;
|
SDL_Rect Settings_rect;
|
||||||
SDL_Rect Settings_Ball_rect;
|
SDL_Rect Settings_Return_Button_rect;
|
||||||
Slider BV;
|
Slider BV;
|
||||||
Slider BS;
|
Slider BS;
|
||||||
Slider BT;
|
Slider BT;
|
||||||
|
Uint32 Mousestate;
|
||||||
|
bool Settings_IsInit=false;
|
||||||
|
|
||||||
bool Settings_IsInit = false;
|
void Settings_Initialize (SDL_Renderer* renderer,Scenery* scenery) {
|
||||||
|
Initialize_Slider(400,300,Scalar_width,Bar_width,Slider_height,1,2,&BV,1.5);
|
||||||
void Settings_Initialize (SDL_Renderer* renderer) {
|
Initialize_Slider(400,500,Scalar_width,Bar_width,Slider_height,30,100,&BS,scenery->ball.TargetRect.w);
|
||||||
Initialize_Slider(400,300,Scalar_width,Bar_width,Slider_height,1,2,&BV);
|
Initialize_Slider(400,700,Scalar_width,Bar_width,Slider_height,0,8,&BT,scenery->ball.TextureIndex);
|
||||||
Initialize_Slider(400,500,Scalar_width,Bar_width,Slider_height,10.0f,20.0f,&BS);
|
|
||||||
Initialize_Slider(400,700,Scalar_width,Bar_width,Slider_height,0,1,&BT);
|
|
||||||
Settings_Texture = IMG_LoadTexture(renderer, "assets/images/settings_title.png");
|
Settings_Texture = IMG_LoadTexture(renderer, "assets/images/settings_title.png");
|
||||||
Settings_rect = (SDL_Rect){.x = 800, .y = 130, .w=470, .h=150};
|
Settings_rect = (SDL_Rect){.x = 800, .y = 180, .w=313, .h=100};
|
||||||
Settings_Ball_Texture = IMG_LoadTexture(renderer, "assets/images/ball.png");
|
Settings_Return_Button_Texture = IMG_LoadTexture(renderer, "assets/images/return_button.png");
|
||||||
Settings_Ball_rect = (SDL_Rect){.x = 1200, .y = 300, .w=100, .h=100};
|
Settings_Return_Button_rect = (SDL_Rect){.x = 200, .y = 200, .w=75, .h=75};
|
||||||
Settings_IsInit = true;
|
Settings_IsInit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings_Draw(SDL_Renderer * renderer, Scenery * scenery) {
|
void Settings_Draw (SDL_Renderer* renderer,Scenery* scenery) {
|
||||||
double x;
|
double x;
|
||||||
|
scenery->ball.TargetRect.x=900;
|
||||||
|
scenery->ball.TargetRect.y=700;
|
||||||
SDL_RenderCopy(renderer, Settings_Texture, NULL, &Settings_rect);
|
SDL_RenderCopy(renderer, Settings_Texture, NULL, &Settings_rect);
|
||||||
SDL_RenderCopy(renderer, Settings_Ball_Texture, NULL, &Settings_Ball_rect);
|
SDL_RenderCopy(renderer, Settings_Return_Button_Texture, NULL, &Settings_Return_Button_rect);
|
||||||
Draw_Slider(renderer, &BV);
|
Draw_Slider(renderer,&BV);
|
||||||
Draw_Slider(renderer, &BS);
|
Draw_Slider(renderer,&BS);
|
||||||
Draw_Slider(renderer, &BT);
|
Draw_Slider(renderer,&BT);
|
||||||
Draw_Ballstate(renderer, scenery);
|
Draw_Ballstate(renderer,scenery);
|
||||||
mapping(&x, &BS);
|
mapping(&x,&BT);
|
||||||
scenery->ball.Speed = x;
|
scenery->ball.TextureIndex=round(x);
|
||||||
mapping(&x, &BT);
|
mapping(&x,&BS);
|
||||||
x = round(x);
|
scenery->ball.TargetRect.w=x;
|
||||||
scenery->ball.TextureIndex = x;
|
scenery->ball.TargetRect.h=x;
|
||||||
|
Settings_Return();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings_Deinitialize(){
|
void Settings_Deinitialize(){
|
||||||
if (Settings_IsInit) {
|
if(Settings_IsInit){
|
||||||
SDL_DestroyTexture(Settings_Texture);
|
SDL_DestroyTexture(Settings_Texture);
|
||||||
SDL_DestroyTexture(Settings_Ball_Texture);
|
SDL_DestroyTexture(Settings_Ball_Texture);
|
||||||
Settings_IsInit = false;
|
Settings_IsInit=false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Draw_Slider(SDL_Renderer * renderer, Slider * beta){
|
void Draw_Slider(SDL_Renderer* renderer,Slider* beta){
|
||||||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
SDL_SetRenderDrawColor(renderer,255,255,255,255);
|
||||||
SDL_RenderDrawRect(renderer, &beta->Bar_rect);
|
SDL_RenderDrawRect(renderer,&beta->Bar_rect);
|
||||||
int x, y;
|
int x,y;
|
||||||
Uint32 Mousestate = SDL_GetMouseState(&x, &y);
|
Mousestate=SDL_GetMouseState(&x,&y);
|
||||||
if (y <= ((beta->Bar_rect.y) + (beta->Bar_rect.h)) && y >= (beta->Bar_rect.y) && x <= (beta->Bar_rect.w + beta->Bar_rect.x) && x >= (beta->Bar_rect.x) && (Mousestate & SDL_BUTTON(SDL_BUTTON_LEFT))) {
|
if(y<=((beta->Bar_rect.y)+(beta->Bar_rect.h))&&y>=(beta->Bar_rect.y)&&x<=(beta->Bar_rect.w+beta->Bar_rect.x)&&x>=(beta->Bar_rect.x)&&(Mousestate & SDL_BUTTON(SDL_BUTTON_LEFT))){
|
||||||
SDL_RenderFillRect(renderer, &beta->Scalar_rect);
|
SDL_RenderFillRect(renderer,&beta->Scalar_rect);
|
||||||
SDL_RenderDrawRect(renderer, &beta->Scalar_rect);
|
SDL_RenderDrawRect(renderer,&beta->Scalar_rect);
|
||||||
if (x > (beta->Bar_rect.x + beta->Bar_rect.w - (beta->Scalar_rect.w) / 2)) {
|
if(x>(beta->Bar_rect.x+beta->Bar_rect.w-(beta->Scalar_rect.w)/2)){
|
||||||
beta->Scalar_rect.x = (beta->Bar_rect.x + beta->Bar_rect.w - (beta->Scalar_rect.w));
|
beta->Scalar_rect.x=(beta->Bar_rect.x+beta->Bar_rect.w-(beta->Scalar_rect.w));
|
||||||
beta->Slider_value = (beta->Bar_rect.x + beta->Bar_rect.w - (beta->Scalar_rect.w) / 2);
|
beta->Slider_value=(beta->Bar_rect.x+beta->Bar_rect.w-(beta->Scalar_rect.w)/2);
|
||||||
} else if (x < beta->Bar_rect.x + (beta->Scalar_rect.w) / 2) {
|
|
||||||
beta->Scalar_rect.x = beta->Bar_rect.x;
|
|
||||||
beta->Slider_value = beta->Bar_rect.x + (beta->Scalar_rect.w) / 2;
|
|
||||||
} else {
|
|
||||||
beta->Scalar_rect.x = x - (beta->Scalar_rect.w / 2);
|
|
||||||
beta->Slider_value = x;
|
|
||||||
}
|
}
|
||||||
} else {
|
else if(x<beta->Bar_rect.x+(beta->Scalar_rect.w)/2){
|
||||||
SDL_RenderDrawRect(renderer, &beta->Scalar_rect);
|
beta->Scalar_rect.x=beta->Bar_rect.x;
|
||||||
|
beta->Slider_value=beta->Bar_rect.x+(beta->Scalar_rect.w)/2;
|
||||||
}
|
}
|
||||||
} /* Draw_Slider */
|
else{
|
||||||
|
beta->Scalar_rect.x=x-(beta->Scalar_rect.w/2);
|
||||||
|
beta->Slider_value=x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
SDL_RenderDrawRect(renderer,&beta->Scalar_rect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Draw_Ballstate(SDL_Renderer * renderer, Scenery * scenery){
|
void Draw_Ballstate(SDL_Renderer* renderer,Scenery* scenery){
|
||||||
BALL_Draw(renderer, &(scenery->ball));
|
BALL_Draw(renderer, &(scenery->ball));
|
||||||
}
|
}
|
||||||
|
|
||||||
void mapping(double * x, Slider * beta){
|
void mapping(double *x,Slider* beta){
|
||||||
*x = ((beta->max - beta->min) / (beta->Bar_rect.w - (beta->Scalar_rect.w))) * (beta->Slider_value - beta->Bar_rect.x - beta->Scalar_rect.w / 2) + beta->min;
|
*x=((beta->max-beta->min)/(beta->Bar_rect.w-(beta->Scalar_rect.w)))*(beta->Slider_value-beta->Bar_rect.x-beta->Scalar_rect.w/2)+beta->min;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Initialize_Slider(int x, int y, int sw, int bw, int h, double min, double max, Slider * beta){
|
void Initialize_Slider(int x,int y,int sw,int bw,int h,double min,double max,Slider* beta,double defaultvalue){
|
||||||
beta->Scalar_rect = (SDL_Rect) {.x = x, .y = y, .w = sw, .h = h };
|
beta->Scalar_rect = (SDL_Rect){.x=(defaultvalue-min)/(max-min)*(bw-sw/2)+x,.y=y,.w=sw,.h=h};
|
||||||
beta->Bar_rect = (SDL_Rect) {.x = x, .y = y, .w = bw, .h = h };
|
beta->Bar_rect = (SDL_Rect){.x=x,.y=y,.w=bw,.h=h};
|
||||||
beta->max = max;
|
beta->max=max;
|
||||||
beta->min = min;
|
beta->min=min;
|
||||||
beta->Slider_value = x + beta->Scalar_rect.w / 2;
|
beta->Slider_value=(defaultvalue-min)/(max-min)*(bw-sw/2)+x;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Settings_Return(Scenery* scenery){
|
||||||
|
int x,y;
|
||||||
|
Mousestate=SDL_GetMouseState(&x,&y);
|
||||||
|
if((distance(x,y,237,237)<=37)&&(Mousestate & SDL_BUTTON(SDL_BUTTON_LEFT)))
|
||||||
|
GAME_ChangeState(MainMenu);
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,10 @@
|
|||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <SDL2/SDL_image.h>
|
#include <SDL2/SDL_image.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <math.h>
|
||||||
#include "breakout.h"
|
#include "breakout.h"
|
||||||
|
#include "gamestate.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
typedef struct sliderstruct {
|
typedef struct sliderstruct {
|
||||||
SDL_Rect Bar_rect;
|
SDL_Rect Bar_rect;
|
||||||
@ -22,12 +25,14 @@ void Draw_Slider(SDL_Renderer* renderer,Slider* beta);
|
|||||||
|
|
||||||
void Draw_Ballstate(SDL_Renderer* renderer,Scenery* scenery);
|
void Draw_Ballstate(SDL_Renderer* renderer,Scenery* scenery);
|
||||||
|
|
||||||
void Settings_Initialize (SDL_Renderer* renderer);
|
void Settings_Initialize (SDL_Renderer* renderer,Scenery* scenery);
|
||||||
|
|
||||||
void Initialize_Slider(int x,int y,int sw,int bw,int h,double min,double max,Slider* beta);
|
void Initialize_Slider(int x,int y,int sw,int bw,int h,double min,double max,Slider* beta,double defaultvalue);
|
||||||
|
|
||||||
void Settings_Deinitialize();
|
void Settings_Deinitialize();
|
||||||
|
|
||||||
void mapping(double *x,Slider* beta);
|
void mapping(double *x,Slider* beta);
|
||||||
|
|
||||||
|
void Settings_Return();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
20
startmenu.c
20
startmenu.c
@ -9,6 +9,8 @@ extern float XScale, YScale;
|
|||||||
|
|
||||||
SDL_Texture * TITLE_Texture;
|
SDL_Texture * TITLE_Texture;
|
||||||
SDL_Texture * PLAYBUTTON_Texture;
|
SDL_Texture * PLAYBUTTON_Texture;
|
||||||
|
SDL_Texture * SKINSBUTTON_Texture;
|
||||||
|
SDL_Texture * LEVELBUTTON_Texture;
|
||||||
SDL_Texture * SETTINGSBUTTON_Texture;
|
SDL_Texture * SETTINGSBUTTON_Texture;
|
||||||
SDL_Texture * HIGHSCORESBUTTON_Texture;
|
SDL_Texture * HIGHSCORESBUTTON_Texture;
|
||||||
SDL_Texture * QUITBUTTON_Texture;
|
SDL_Texture * QUITBUTTON_Texture;
|
||||||
@ -16,6 +18,8 @@ SDL_Texture * QUITBUTTON_Texture;
|
|||||||
SDL_Rect TITLE_Rect;
|
SDL_Rect TITLE_Rect;
|
||||||
SDL_Rect PLAYBUTTON_Rect;
|
SDL_Rect PLAYBUTTON_Rect;
|
||||||
SDL_Rect SETTINGSBUTTON_Rect;
|
SDL_Rect SETTINGSBUTTON_Rect;
|
||||||
|
SDL_Rect LEVELBUTTON_Rect;
|
||||||
|
SDL_Rect SKINSBUTTON_Rect;
|
||||||
SDL_Rect HIGHSCORESBUTTON_Rect;
|
SDL_Rect HIGHSCORESBUTTON_Rect;
|
||||||
SDL_Rect QUITBUTTON_Rect;
|
SDL_Rect QUITBUTTON_Rect;
|
||||||
|
|
||||||
@ -32,10 +36,16 @@ void Load_Textures(SDL_Renderer * renderer) {
|
|||||||
TITLE_Rect = (SDL_Rect) {.x = 685, .y = 50, .w = 550, .h = 250 };
|
TITLE_Rect = (SDL_Rect) {.x = 685, .y = 50, .w = 550, .h = 250 };
|
||||||
|
|
||||||
PLAYBUTTON_Texture = IMG_LoadTexture(renderer, "assets/images/play_button.png");
|
PLAYBUTTON_Texture = IMG_LoadTexture(renderer, "assets/images/play_button.png");
|
||||||
PLAYBUTTON_Rect = (SDL_Rect) {.x = 772, .y = 420, .w = 376, .h = 214 };
|
PLAYBUTTON_Rect = (SDL_Rect) {.x = 497, .y = 400, .w = 313, .h = 178 };
|
||||||
|
|
||||||
|
SKINSBUTTON_Texture = IMG_LoadTexture(renderer, "assets/images/skins_button.png");
|
||||||
|
SKINSBUTTON_Rect = (SDL_Rect) {.x = 1110, .y = 400, .w = 313, .h = 178 };
|
||||||
|
|
||||||
|
LEVELBUTTON_Texture = IMG_LoadTexture(renderer, "assets/images/level_button.png");
|
||||||
|
LEVELBUTTON_Rect = (SDL_Rect) {.x = 497, .y = 700, .w = 313, .h = 178 };
|
||||||
|
|
||||||
SETTINGSBUTTON_Texture = IMG_LoadTexture(renderer, "assets/images/settings_button.png");
|
SETTINGSBUTTON_Texture = IMG_LoadTexture(renderer, "assets/images/settings_button.png");
|
||||||
SETTINGSBUTTON_Rect = (SDL_Rect) {.x = 772, .y = 720, .w = 376, .h = 214 };
|
SETTINGSBUTTON_Rect = (SDL_Rect) {.x = 1110, .y = 700, .w = 313, .h = 178 };
|
||||||
|
|
||||||
HIGHSCORESBUTTON_Texture = IMG_LoadTexture(renderer, "assets/images/highscores_button.png");
|
HIGHSCORESBUTTON_Texture = IMG_LoadTexture(renderer, "assets/images/highscores_button.png");
|
||||||
HIGHSCORESBUTTON_Rect = (SDL_Rect) {.x = 1557, .y = 120, .w = 313, .h = 178 };
|
HIGHSCORESBUTTON_Rect = (SDL_Rect) {.x = 1557, .y = 120, .w = 313, .h = 178 };
|
||||||
@ -47,6 +57,8 @@ void Load_Textures(SDL_Renderer * renderer) {
|
|||||||
void Startmenu_Draw(SDL_Renderer * renderer) {
|
void Startmenu_Draw(SDL_Renderer * renderer) {
|
||||||
SDL_RenderCopy(renderer, TITLE_Texture, NULL, &TITLE_Rect);
|
SDL_RenderCopy(renderer, TITLE_Texture, NULL, &TITLE_Rect);
|
||||||
SDL_RenderCopy(renderer, PLAYBUTTON_Texture, NULL, &PLAYBUTTON_Rect);
|
SDL_RenderCopy(renderer, PLAYBUTTON_Texture, NULL, &PLAYBUTTON_Rect);
|
||||||
|
SDL_RenderCopy(renderer, SKINSBUTTON_Texture, NULL, &SKINSBUTTON_Rect);
|
||||||
|
SDL_RenderCopy(renderer, LEVELBUTTON_Texture, NULL, &LEVELBUTTON_Rect);
|
||||||
SDL_RenderCopy(renderer, SETTINGSBUTTON_Texture, NULL, &SETTINGSBUTTON_Rect);
|
SDL_RenderCopy(renderer, SETTINGSBUTTON_Texture, NULL, &SETTINGSBUTTON_Rect);
|
||||||
SDL_RenderCopy(renderer, HIGHSCORESBUTTON_Texture, NULL, &HIGHSCORESBUTTON_Rect);
|
SDL_RenderCopy(renderer, HIGHSCORESBUTTON_Texture, NULL, &HIGHSCORESBUTTON_Rect);
|
||||||
SDL_RenderCopy(renderer, QUITBUTTON_Texture, NULL, &QUITBUTTON_Rect);
|
SDL_RenderCopy(renderer, QUITBUTTON_Texture, NULL, &QUITBUTTON_Rect);
|
||||||
@ -56,6 +68,10 @@ void button_clicked(SDL_MouseButtonEvent b, GameState gameState) {
|
|||||||
if (gameState == MainMenu) {
|
if (gameState == MainMenu) {
|
||||||
if (clickInRect(b, &PLAYBUTTON_Rect) == 1) {
|
if (clickInRect(b, &PLAYBUTTON_Rect) == 1) {
|
||||||
GAME_ChangeState(Game);
|
GAME_ChangeState(Game);
|
||||||
|
} else if (clickInRect(b, &SKINSBUTTON_Rect) == 1) {
|
||||||
|
GAME_ChangeState(SkinSelect);
|
||||||
|
} else if (clickInRect(b, &LEVELBUTTON_Rect) == 1) {
|
||||||
|
GAME_ChangeState(LevelSelect);
|
||||||
} else if (clickInRect(b, &SETTINGSBUTTON_Rect) == 1) {
|
} else if (clickInRect(b, &SETTINGSBUTTON_Rect) == 1) {
|
||||||
GAME_ChangeState(Settings);
|
GAME_ChangeState(Settings);
|
||||||
} else if (clickInRect(b, &HIGHSCORESBUTTON_Rect) == 1) {
|
} else if (clickInRect(b, &HIGHSCORESBUTTON_Rect) == 1) {
|
||||||
|
Loading…
Reference in New Issue
Block a user