Added some graphics, changed score system for other ball sizes

This commit is contained in:
Michael Chen 2018-02-01 17:55:15 +01:00
parent eb0341bd3d
commit f64af0d0d9
5 changed files with 74 additions and 70 deletions

View File

@ -13,6 +13,8 @@
#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_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;
@ -25,12 +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 = 2; 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[1] = IMG_LoadTexture(renderer, BG_Path_2);
// BACKGROUND_Textures[2] = IMG_LoadTexture(renderer, BG_Path_3); 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.

After

Width:  |  Height:  |  Size: 1.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

View File

@ -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

@ -13,7 +13,7 @@ extern float XScale, YScale;
#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)))) #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_Ball_Texture;
@ -37,42 +37,43 @@ Slider BT;
Uint32 Mousestate; Uint32 Mousestate;
bool Settings_IsInit = false; 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,0,1,&BG,0); Initialize_Slider(400, 300, Scalar_width, Bar_width, Slider_height, 0, 3, &BG, 0);
Initialize_Slider(400,500,Scalar_width,Bar_width,Slider_height,10,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_Slider(400,300,Scalar_width,Bar_width,Slider_height,0,8,&BT,scenery->paddle.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 };
Settings_Ball_rect = (SDL_Rect){.x = 1200, .y = 700, .w=90, .h=90}; Settings_Ball_rect = (SDL_Rect) {.x = 1200, .y = 700, .w = 90, .h = 90 };
Settings_Skins_Texture = IMG_LoadTexture(renderer, "assets/images/skins_button.png"); Settings_Skins_Texture = IMG_LoadTexture(renderer, "assets/images/skins_button.png");
Settings_Skins_rect = (SDL_Rect){.x = 50, .y = 710, .w=315, .h=70}; Settings_Skins_rect = (SDL_Rect) {.x = 50, .y = 710, .w = 315, .h = 70 };
Return_Button_Texture = IMG_LoadTexture(renderer, "assets/images/return_button.png"); Return_Button_Texture = IMG_LoadTexture(renderer, "assets/images/return_button.png");
Return_Button_rect = (SDL_Rect){.x = 200, .y = 200, .w=75, .h=75}; Return_Button_rect = (SDL_Rect) {.x = 200, .y = 200, .w = 75, .h = 75 };
Bar_Texture = IMG_LoadTexture(renderer, "assets/images/bar_texture.png"); Bar_Texture = IMG_LoadTexture(renderer, "assets/images/bar_texture.png");
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");
Circle_Texture = IMG_LoadTexture(renderer,"assets/images/circle.png"); Circle_Texture = IMG_LoadTexture(renderer, "assets/images/circle.png");
Circle_rect = (SDL_Rect){.x = 1250, .y = 500, .w=75, .h=75}; 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,int *backgroundcount) { void Settings_Draw(SDL_Renderer * renderer, Scenery * scenery, int * backgroundcount) {
double x; double x;
if(!(Mousestate & SDL_BUTTON(SDL_BUTTON_LEFT))){
IsLock=BG.IsLock=BS.IsLock=BT.IsLock=false; if (!(Mousestate & SDL_BUTTON(SDL_BUTTON_LEFT))) {
}else{ IsLock = BG.IsLock = BS.IsLock = BT.IsLock = false;
IsLock=true; } else {
IsLock = true;
} }
BACKGROUND_Draw(renderer,*backgroundcount); BACKGROUND_Draw(renderer, *backgroundcount);
Draw_Slider(renderer, &BG); Draw_Slider(renderer, &BG);
Draw_Slider(renderer, &BS); Draw_Slider(renderer, &BS);
Draw_Slider(renderer, &BT); Draw_Slider(renderer, &BT);
@ -86,18 +87,18 @@ void Settings_Draw(SDL_Renderer * renderer, Scenery * scenery,int *backgroundcou
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; int posx = 1250, posy = 500;
Circle_rect.x=posx-0.5*Circle_rect.w; Circle_rect.x = posx - 0.5 * Circle_rect.w;
Circle_rect.y=posy+0.5*(100-Circle_rect.w); Circle_rect.y = posy + 0.5 * (100 - Circle_rect.w);
Circle_rect.w=x; Circle_rect.w = x;
Circle_rect.h=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); mapping(&x, &BG);
x=round(x); x = round(x);
*backgroundcount=x; *backgroundcount = x;
} } /* Settings_Draw */
void Settings_Deinitialize(){ void Settings_Deinitialize(){
if (Settings_IsInit) { if (Settings_IsInit) {
@ -120,12 +121,12 @@ void Draw_Slider(SDL_Renderer * renderer, Slider * beta){
Mousestate = SDL_GetMouseState(&x, &y); Mousestate = SDL_GetMouseState(&x, &y);
x = round((float)x / XScale); x = round((float)x / XScale);
y = round((float)y / YScale); y = round((float)y / YScale);
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)))||beta->IsLock) { 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))) || beta->IsLock) {
if(!IsLock){ if (!IsLock) {
beta->IsLock=true; beta->IsLock = true;
IsLock=true; IsLock = true;
} }
if(beta->IsLock){ if (beta->IsLock) {
SDL_RenderCopy(renderer, Scalar_Button_Texture1, NULL, &beta->Scalar_rect); SDL_RenderCopy(renderer, Scalar_Button_Texture1, NULL, &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));
@ -149,21 +150,21 @@ 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,double defaultvalue){ 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 = (defaultvalue-min)/(max-min)*(bw-sw/2)+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 = (defaultvalue-min)/(max-min)*(bw-sw/2)+x; 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;
Mousestate=SDL_GetMouseState(&x,&y); Mousestate = SDL_GetMouseState(&x, &y);
x = round((float)x / XScale); x = round((float)x / XScale);
y = round((float)y / YScale); y = round((float)y / YScale);
if((distance(x,y,237,237)<=37)&&(Mousestate & SDL_BUTTON(SDL_BUTTON_LEFT))) if ((distance(x, y, 237, 237) <= 37) && (Mousestate & SDL_BUTTON(SDL_BUTTON_LEFT)))
GAME_ChangeState(MainMenu); GAME_ChangeState(MainMenu);
} }
} }