Compare commits

..

10 Commits

Author SHA1 Message Date
Michael Chen
f64af0d0d9 Added some graphics, changed score system for other ball sizes 2018-02-01 17:55:15 +01:00
Michael Chen
eb0341bd3d Merge branch 'devsave' of collaborating.tuhh.de:czg6669/breakout into devsave 2018-02-01 14:49:22 +01:00
Michael Chen
5ae643298f Ohlhus Easter Egg 2018-02-01 14:40:35 +01:00
Andreas Neumann
af575c12ab Added a blue backkground 2018-02-01 14:02:46 +01:00
Andreas Neumann
4f355f6f6d Included background slider 2018-02-01 13:22:27 +01:00
Andreas Neumann
68f60a866f Merge branch 'devsave' of collaborating.tuhh.de:czg6669/breakout into devsave 2018-02-01 12:45:15 +01:00
Andreas Neumann
17ab05f279 Added ball size visualization in settings
Deleted stepslider
2018-02-01 12:44:47 +01:00
Michael Chen
7b31604a55 Fixed collision with paddle at small ball scale 2018-02-01 11:41:12 +01:00
Michael Chen
830e40ca77 Fixed tiny uplaod bug 2018-01-30 14:47:01 +01:00
Michael Chen
d523a3b72e Removed old files 2018-01-30 10:22:11 +01:00
14 changed files with 92 additions and 115 deletions

View File

@ -12,6 +12,9 @@
#include "background.h" #include "background.h"
#define BG_Path_1 "assets/images/bg/bg1.png" #define BG_Path_1 "assets/images/bg/bg1.png"
#define BG_Path_2 "assets/images/bg/bg2.png"
#define BG_Path_3 "assets/images/bg/bg3.png"
#define BG_Path_4 "assets/images/bg/bg4.png"
int BACKGROUND_BoxWidth, BACKGROUND_BoxHeight; int BACKGROUND_BoxWidth, BACKGROUND_BoxHeight;
int BACKGROUND_TextureCount; int BACKGROUND_TextureCount;
@ -24,10 +27,13 @@ void BACKGROUND_Initialize(SDL_Renderer * renderer, int width, int height){
printf("Initializing Background...\n"); printf("Initializing Background...\n");
BACKGROUND_BoxWidth = width; BACKGROUND_BoxWidth = width;
BACKGROUND_BoxHeight = height; BACKGROUND_BoxHeight = height;
BACKGROUND_TextureCount = 1; BACKGROUND_TextureCount = 4;
BACKGROUND_TotalRect = (SDL_Rect) {.x = 0, .y = 0, .w = 1920, .h = 1080 }; BACKGROUND_TotalRect = (SDL_Rect) {.x = 0, .y = 0, .w = 1920, .h = 1080 };
BACKGROUND_Textures = malloc(BACKGROUND_TextureCount * sizeof(SDL_Texture *)); BACKGROUND_Textures = malloc(BACKGROUND_TextureCount * sizeof(SDL_Texture *));
BACKGROUND_Textures[0] = IMG_LoadTexture(renderer, BG_Path_1); BACKGROUND_Textures[0] = IMG_LoadTexture(renderer, BG_Path_1);
BACKGROUND_Textures[1] = IMG_LoadTexture(renderer, BG_Path_2);
BACKGROUND_Textures[2] = IMG_LoadTexture(renderer, BG_Path_3);
BACKGROUND_Textures[3] = IMG_LoadTexture(renderer, BG_Path_4);
printf("Background initialized!\n"); printf("Background initialized!\n");
BACKGROUND_IsInit = true; BACKGROUND_IsInit = true;
} else } else

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 MiB

After

Width:  |  Height:  |  Size: 2.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -1,9 +0,0 @@
sql11.freemysqlhosting.net
3306
sql11215077
EFik49X18z
sql11215077
highscores
score
username
time

View File

@ -457,10 +457,10 @@ void BALL_MoveAwayFromBoundaries(Ball * obj){
bool BALL_CollideWithPaddle(Ball * obj, Paddle * paddle){ bool BALL_CollideWithPaddle(Ball * obj, Paddle * paddle){
if (RECT_Collide(&(obj->TargetRect), &(paddle->TargetRect))) { if (RECT_Collide(&(obj->TargetRect), &(paddle->TargetRect))) {
Vector ballCenter = BALL_GetCenter(obj); Vector ballCenter = BALL_GetCenter(obj);
if (ballCenter.y > (paddle->TargetRect).y) // if the ball hits the paddle from the sides (or the bottom (?)) if ((ballCenter.x) > ((paddle->TargetRect).x) || (ballCenter.x) < ((paddle->TargetRect).x + (paddle->TargetRect).w)) // if the ball hits the paddle from the sides (or the bottom (?))
BALL_CollideWithRect(obj, &(paddle->TargetRect));
else
BALL_SteerMomentum(obj, paddle); // Sets it to unit vector! BALL_SteerMomentum(obj, paddle); // Sets it to unit vector!
else
BALL_CollideWithRect(obj, &(paddle->TargetRect));
// Following assumes that the paddle position was udated before the ball was updated // Following assumes that the paddle position was udated before the ball was updated
while (RECT_Collide(&(obj->TargetRect), &(paddle->TargetRect))) { // Move away from rect in small steps while (RECT_Collide(&(obj->TargetRect), &(paddle->TargetRect))) { // Move away from rect in small steps
(obj->Location) = VECTOR_Add((obj->Location), (obj->Momentum)); (obj->Location) = VECTOR_Add((obj->Location), (obj->Momentum));
@ -511,7 +511,7 @@ void BALL_Update(Ball * obj, Scenery * scenery){
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))); BREAKOUT_IncreaseScoreBy(scenery, (int)round((15.0f / ((scenery->ball).Size)) * (((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);

View File

@ -135,6 +135,7 @@ void GAMEOVER_MouseClicked(SDL_MouseButtonEvent b, Scenery * scenery){
GAME_ChangeState(Highscores); GAME_ChangeState(Highscores);
} else if (clickInRect(b, &GAMEOVER_RestartButtonRect)) { } else if (clickInRect(b, &GAMEOVER_RestartButtonRect)) {
printf("Restart was called from gameover!\n"); printf("Restart was called from gameover!\n");
GAMEOVER_UploadState = Initial;
GAME_Restart(); GAME_Restart();
GAME_ChangeState(Game); GAME_ChangeState(Game);
} }

5
main.c
View File

@ -42,6 +42,7 @@ Scenery scenery;
Mix_Music * MenuLoop; Mix_Music * MenuLoop;
char * Username; char * Username;
char * Password; char * Password;
int background=0;
int main(int argc, char * args[]){ int main(int argc, char * args[]){
AttemptLogin(); AttemptLogin();
@ -57,7 +58,7 @@ int main(int argc, char * args[]){
switch (gameState) { switch (gameState) {
case Game: case Game:
BREAKOUT_Update(&scenery, keystate); BREAKOUT_Update(&scenery, keystate);
BACKGROUND_Draw(renderer, 0); BACKGROUND_Draw(renderer, background);
BREAKOUT_Draw(&scenery, renderer); BREAKOUT_Draw(&scenery, renderer);
break; break;
case MainMenu: case MainMenu:
@ -68,7 +69,7 @@ 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,&background);
break; break;
case GameOver: case GameOver:
GAMEOVER_Draw(renderer, &scenery); GAMEOVER_Draw(renderer, &scenery);

View File

@ -22,19 +22,17 @@ SDL_Texture * Return_Button_Texture;
SDL_Texture * Bar_Texture; SDL_Texture * Bar_Texture;
SDL_Texture * Scalar_Button_Texture0; SDL_Texture * Scalar_Button_Texture0;
SDL_Texture * Scalar_Button_Texture1; SDL_Texture * Scalar_Button_Texture1;
SDL_Texture * L_Arrow_Texture; SDL_Texture * Circle_Texture;
SDL_Texture * R_Arrow_Texture;
SDL_Rect Settings_rect; SDL_Rect Settings_rect;
SDL_Rect Settings_Ball_rect; SDL_Rect Settings_Ball_rect;
SDL_Rect Settings_Skins_rect; SDL_Rect Settings_Skins_rect;
SDL_Rect Return_Button_rect; SDL_Rect Return_Button_rect;
SDL_Rect Circle_rect;
Slider BV; Slider BG;
Slider BS; Slider BS;
Slider BT; Slider BT;
Stepslider SBT;
Uint32 Mousestate; Uint32 Mousestate;
@ -42,10 +40,10 @@ bool Settings_IsInit = false;
bool IsLock = false; bool IsLock = false;
void Settings_Initialize(SDL_Renderer * renderer, Scenery * scenery) { void Settings_Initialize(SDL_Renderer * renderer, Scenery * scenery) {
// Initialize_Slider(400,300,Scalar_width,Bar_width,Slider_height,1,2,&BV,1.5); Initialize_Slider(400, 300, Scalar_width, Bar_width, Slider_height, 0, 3, &BG, 0);
Initialize_Slider(400,500,Scalar_width,Bar_width,Slider_height,30,100,&BS,scenery->ball.TargetRect.w); Initialize_Slider(400, 500, Scalar_width, Bar_width, Slider_height, 10, 100, &BS, scenery->ball.TargetRect.w);
Initialize_Slider(400, 700, Scalar_width, Bar_width, Slider_height, 0, 8, &BT, scenery->ball.TextureIndex); Initialize_Slider(400, 700, Scalar_width, Bar_width, Slider_height, 0, 8, &BT, scenery->ball.TextureIndex);
Initialize_Stepslider(400,300,Scalar_width,Bar_width,Slider_height,0,8,&SBT,scenery->ball.TextureIndex); // Initialize_Slider(400,300,Scalar_width,Bar_width,Slider_height,0,8,&BT,scenery->paddle.TextureIndex);
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 = 647, .y = 50, .w = 626, .h = 200 }; Settings_rect = (SDL_Rect) {.x = 647, .y = 50, .w = 626, .h = 200 };
@ -61,37 +59,46 @@ void Settings_Initialize (SDL_Renderer* renderer,Scenery* scenery) {
Scalar_Button_Texture0 = IMG_LoadTexture(renderer, "assets/images/scalar_button_unpressed.png"); Scalar_Button_Texture0 = IMG_LoadTexture(renderer, "assets/images/scalar_button_unpressed.png");
Scalar_Button_Texture1 = IMG_LoadTexture(renderer, "assets/images/scalar_button_pressed.png"); Scalar_Button_Texture1 = IMG_LoadTexture(renderer, "assets/images/scalar_button_pressed.png");
R_Arrow_Texture = IMG_LoadTexture(renderer, "assets/images/r_arrow_button.png" ); Circle_Texture = IMG_LoadTexture(renderer, "assets/images/circle.png");
L_Arrow_Texture = IMG_LoadTexture(renderer, "assets/images/l_arrow_button.png" ); Circle_rect = (SDL_Rect) {.x = 1250, .y = 500, .w = 75, .h = 75 };
Settings_IsInit = true; Settings_IsInit = true;
} } /* Settings_Initialize */
void Settings_Draw(SDL_Renderer * renderer, Scenery * scenery) { void Settings_Draw(SDL_Renderer * renderer, Scenery * scenery, int * backgroundcount) {
double x; double x;
if (!(Mousestate & SDL_BUTTON(SDL_BUTTON_LEFT))) { if (!(Mousestate & SDL_BUTTON(SDL_BUTTON_LEFT))) {
IsLock=BV.IsLock=BS.IsLock=BT.IsLock=false; IsLock = BG.IsLock = BS.IsLock = BT.IsLock = false;
} else { } else {
IsLock = true; IsLock = true;
} }
// Draw_Slider(renderer, &BV); BACKGROUND_Draw(renderer, *backgroundcount);
Draw_Slider(renderer, &BG);
Draw_Slider(renderer, &BS); Draw_Slider(renderer, &BS);
Draw_Slider(renderer, &BT); Draw_Slider(renderer, &BT);
Draw_Stepslider(renderer, &SBT);
SDL_RenderCopy(renderer, Settings_Texture, NULL, &Settings_rect); SDL_RenderCopy(renderer, Settings_Texture, NULL, &Settings_rect);
SDL_RenderCopy(renderer, Return_Button_Texture, NULL, &Return_Button_rect); SDL_RenderCopy(renderer, Return_Button_Texture, NULL, &Return_Button_rect);
SDL_RenderCopy(renderer, Settings_Skins_Texture, NULL, &Settings_Skins_rect); SDL_RenderCopy(renderer, Settings_Skins_Texture, NULL, &Settings_Skins_rect);
SDL_RenderCopy(renderer, Circle_Texture, NULL, &Circle_rect);
BALL_DrawTexture(renderer, &Settings_Ball_rect, scenery->ball.TextureIndex); BALL_DrawTexture(renderer, &Settings_Ball_rect, scenery->ball.TextureIndex);
Settings_Return(); Settings_Return();
mapping(&x, &BS); mapping(&x, &BS);
scenery->ball.TargetRect.w = x; scenery->ball.TargetRect.w = x;
scenery->ball.TargetRect.h = x; scenery->ball.TargetRect.h = x;
scenery->ball.Size = ((double)x / 2.0f); scenery->ball.Size = ((double)x / 2.0f);
int posx = 1250, posy = 500;
Circle_rect.x = posx - 0.5 * Circle_rect.w;
Circle_rect.y = posy + 0.5 * (100 - Circle_rect.w);
Circle_rect.w = x;
Circle_rect.h = x;
mapping(&x, &BT); mapping(&x, &BT);
x = round(x); x = round(x);
scenery->ball.TextureIndex = x; scenery->ball.TextureIndex = x;
} mapping(&x, &BG);
x = round(x);
*backgroundcount = x;
} /* Settings_Draw */
void Settings_Deinitialize(){ void Settings_Deinitialize(){
if (Settings_IsInit) { if (Settings_IsInit) {
@ -102,6 +109,7 @@ void Settings_Deinitialize(){
SDL_DestroyTexture(Settings_Skins_Texture); SDL_DestroyTexture(Settings_Skins_Texture);
SDL_DestroyTexture(Scalar_Button_Texture0); SDL_DestroyTexture(Scalar_Button_Texture0);
SDL_DestroyTexture(Scalar_Button_Texture1); SDL_DestroyTexture(Scalar_Button_Texture1);
SDL_DestroyTexture(Circle_Texture);
Settings_IsInit = false; Settings_IsInit = false;
} }
} }
@ -138,13 +146,6 @@ void Draw_Slider(SDL_Renderer * renderer, Slider * beta){
} }
} /* Draw_Slider */ } /* Draw_Slider */
void Draw_Stepslider(SDL_Renderer* renderer,Stepslider* beta){
SDL_RenderCopy(renderer, Bar_Texture, NULL, &beta->Bar_rect);
SDL_RenderCopy(renderer, Scalar_Button_Texture0, NULL, &beta->Scalar_rect);
SDL_RenderCopy(renderer, L_Arrow_Texture, NULL, &beta->L_Arrow_rect);
SDL_RenderCopy(renderer, R_Arrow_Texture, NULL, &beta->R_Arrow_rect);
}
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;
} }
@ -157,16 +158,6 @@ void Initialize_Slider(int x, int y, int sw, int bw, int h, double min, double m
beta->Slider_value = (defaultvalue - min) / (max - min) * (bw - sw / 2) + x; beta->Slider_value = (defaultvalue - min) / (max - min) * (bw - sw / 2) + x;
} }
void Initialize_Stepslider(int x,int y,int sw,int bw,int h,double min,double max,Stepslider* beta,double defaultvalue){
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->L_Arrow_rect = (SDL_Rect) {.x = x-30-h, .y = y, .w = h, .h = h };
beta->R_Arrow_rect = (SDL_Rect) {.x = x+bw+30, .y = y, .w = h, .h = h };
beta->max = max;
beta->min = min;
beta->Slider_value = (defaultvalue-min)/(max-min)*(bw-sw/2)+x;
}
void Settings_Return(){ void Settings_Return(){
if (!IsLock) { if (!IsLock) {
int x, y; int x, y;

View File

@ -10,6 +10,7 @@
#include "breakout.h" #include "breakout.h"
#include "gamestate.h" #include "gamestate.h"
#include "main.h" #include "main.h"
#include "background.h"
typedef struct sliderstruct { typedef struct sliderstruct {
SDL_Rect Bar_rect; SDL_Rect Bar_rect;
@ -18,28 +19,14 @@ typedef struct sliderstruct {
double Slider_value,min,max; double Slider_value,min,max;
} Slider; } Slider;
typedef struct stepsliderstruct { void Settings_Draw (SDL_Renderer* renderer,Scenery* scenery,int *backgroundcount);
SDL_Rect Bar_rect;
SDL_Rect Scalar_rect;
SDL_Rect L_Arrow_rect;
SDL_Rect R_Arrow_rect;
bool IsLock;
double Slider_value,min,max;
} Stepslider;
void Settings_Draw (SDL_Renderer* renderer,Scenery* scenery);
void Draw_Slider(SDL_Renderer* renderer,Slider* beta); void Draw_Slider(SDL_Renderer* renderer,Slider* beta);
void Draw_Stepslider(SDL_Renderer* renderer,Stepslider* beta);
void Settings_Initialize (SDL_Renderer* renderer,Scenery* scenery); 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,double defaultvalue); void Initialize_Slider(int x,int y,int sw,int bw,int h,double min,double max,Slider* beta,double defaultvalue);
void Initialize_Stepslider(int x,int y,int sw,int bw,int h,double min,double max,Stepslider* beta,double defaultvalue);
void Settings_Deinitialize(); void Settings_Deinitialize();
void mapping(double *x,Slider* beta); void mapping(double *x,Slider* beta);