Score calculation added
This commit is contained in:
parent
fc805e5c31
commit
9088047c68
14
breakout.c
14
breakout.c
@ -77,9 +77,11 @@ Scenery BREAKOUT_CreateDefault(){
|
||||
scenery.paddle = PADDLE_CreateDefault();
|
||||
scenery.blocks = malloc(scenery.BlockCount * sizeof(Block));
|
||||
scenery.Frames = 0;
|
||||
scenery.Score = 0;
|
||||
if (!(scenery.blocks)) printf("FATAL! Memory allocation failed!\n");
|
||||
scenery.IsPaused = false;
|
||||
scenery.Lives = 3;
|
||||
scenery.DestroyedBlocks = 0;
|
||||
int index;
|
||||
for (int y = 0; y < 9; y++) {
|
||||
index = 15 * y;
|
||||
@ -92,6 +94,13 @@ Scenery BREAKOUT_CreateDefault(){
|
||||
return scenery;
|
||||
} /* BREAKOUT_CreateDefault */
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// This Function is obsolete! Do not use it!
|
||||
void BREAKOUT_ChangeSize(int width, int height){
|
||||
BREAKOUT_BoxWidth = width;
|
||||
@ -108,6 +117,7 @@ void BREAKOUT_Update(Scenery * scenery, const Uint8 * keystate){
|
||||
return;
|
||||
}
|
||||
(scenery->Frames)++;
|
||||
BREAKOUT_RefreshScore(scenery);
|
||||
if (scenery->IsGameOver) {
|
||||
BALL_ResetPosition(&(scenery->ball));
|
||||
PADDLE_ResetPosition(&(scenery->paddle));
|
||||
@ -138,8 +148,6 @@ void BREAKOUT_Draw(Scenery * scenery, SDL_Renderer * renderer){
|
||||
SDL_Rect target = *rect;
|
||||
target.x = ((BREAKOUT_BoxWidth - (rect->w)) / 2);
|
||||
target.y = ((BREAKOUT_BoxHeight - (rect->h)) / 2);
|
||||
printf("Texture From: %d, %d, %d, %d\n", rect->x, rect->y, rect->w, rect->h);
|
||||
printf("Texture To: %d, %d, %d, %d\n", target.x, target.y, target.w, target.h);
|
||||
SDL_RenderCopy(renderer, GAME_CountdownTexture, rect, &target);
|
||||
}
|
||||
}
|
||||
@ -359,6 +367,8 @@ void BALL_Update(Ball * obj, Scenery * scenery){
|
||||
oldLocation = obj->Location;
|
||||
if (BALL_CollideWithRect(obj, &(blocks[i].TargetRect))) {
|
||||
BLOCK_DealDamage(blocks + i, 1);
|
||||
if (blocks[i].HP <= 0)
|
||||
(scenery->DestroyedBlocks)++;
|
||||
(obj->Location) = VECTOR_Add(oldLocation, (obj->Momentum));
|
||||
BALL_MoveAwayFromBoundaries(obj);
|
||||
RECT_SetTargetPos(&(obj->TargetRect), &(obj->Location));
|
||||
|
@ -39,15 +39,15 @@ typedef struct sceneryStruct {
|
||||
Ball ball;
|
||||
Paddle paddle;
|
||||
Block * blocks;
|
||||
int BlockCount, Lives, StartCountdown;
|
||||
int BlockCount, Lives, StartCountdown, Frames, Score, DestroyedBlocks;
|
||||
bool IsPaused, IsGameOver;
|
||||
int Frames;
|
||||
} Scenery; // Objekt für die Objekte und Eigenschaften einer Szenerie
|
||||
// End Structs
|
||||
|
||||
// Prototypes
|
||||
void BREAKOUT_INITIALIZE(SDL_Renderer * renderer, int width, int height);
|
||||
Scenery BREAKOUT_CreateDefault();
|
||||
int BREAKOUT_RefreshScore(Scenery * scenery);
|
||||
void BREAKOUT_ChangeSize(int width, int height);
|
||||
void BREAKOUT_Update(Scenery * scenery, const Uint8 * keystate);
|
||||
void BREAKOUT_Draw(Scenery * scenery, SDL_Renderer * renderer);
|
||||
@ -65,6 +65,7 @@ SDL_Point BALL_GetCenter(Ball * obj);
|
||||
void BALL_CollideWithBorders(Ball * obj);
|
||||
void BALL_MoveAwayFromBoundaries(Ball * obj);
|
||||
bool BALL_CollideWithPaddle(Ball * obj, Paddle * paddle);
|
||||
void BALL_AdaptSpeedGradient(Ball * obj, int FrameCount);
|
||||
void BALL_Update(Ball * obj, Scenery * scenery);
|
||||
void BALL_DestroyObject(Ball * obj);
|
||||
void BALL_Deinitialize();
|
||||
@ -75,6 +76,7 @@ void PADDLE_Draw(SDL_Renderer * renderer, Paddle * obj);
|
||||
bool KeyPressed(const Uint8 * keystate, Uint8 * keyArray);
|
||||
void INT_Constrain(int * variable, int min, int max);
|
||||
void DOUBLE_Constrain(double * variable, double min, double max);
|
||||
void PADDLE_MoveSmooth(Paddle * obj);
|
||||
void PADDLE_Update(Paddle * obj, const Uint8 * keystate);
|
||||
void PADDLE_DestroyObject(Paddle * obj);
|
||||
void PADDLE_Deinitialize();
|
||||
|
@ -67,7 +67,7 @@ void HIGHSCORES_Deinitialize(){
|
||||
void HIGHSCORES_GenerateTexture(SDL_Renderer * renderer){
|
||||
char * buffer = calloc(100, sizeof(char));
|
||||
int count = 0;
|
||||
char format[20] = "| %-58s | %-10s |";
|
||||
char format[20] = "| %-54s | %-14s |";
|
||||
SDL_Rect Message_rect;
|
||||
SDL_Surface * HIGHSCORES_TableSurface = SDL_CreateRGBSurface(0, 1920, 1080, 32, 0, 0, 0, 0);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user