Merge branch 'devsave' of collaborating.tuhh.de:czg6669/breakout into devsave

This commit is contained in:
Michael Chen 2018-01-26 10:40:30 +01:00
commit 396c8f7ddc
7 changed files with 83 additions and 17 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 542 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -19,6 +19,12 @@ SDL_Texture * Settings_Texture;
SDL_Texture * Settings_Ball_Texture; SDL_Texture * Settings_Ball_Texture;
SDL_Texture * Settings_Skins_Texture; SDL_Texture * Settings_Skins_Texture;
SDL_Texture * Return_Button_Texture; SDL_Texture * Return_Button_Texture;
SDL_Texture * Bar_Texture;
SDL_Texture * Scalar_Button_Texture0;
SDL_Texture * Scalar_Button_Texture1;
SDL_Texture * L_Arrow_Texture;
SDL_Texture * R_Arrow_Texture;
SDL_Rect Settings_rect; SDL_Rect Settings_rect;
SDL_Rect Settings_Ball_rect; SDL_Rect Settings_Ball_rect;
@ -28,15 +34,18 @@ SDL_Rect Return_Button_rect;
Slider BV; Slider BV;
Slider BS; Slider BS;
Slider BT; Slider BT;
Stepslider SBT;
Uint32 Mousestate; Uint32 Mousestate;
bool Settings_IsInit = false; bool Settings_IsInit = 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,1,2,&BV,1.5);
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,30,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);
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};
@ -48,21 +57,33 @@ void Settings_Initialize (SDL_Renderer* renderer,Scenery* scenery) {
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");
Scalar_Button_Texture0 = IMG_LoadTexture(renderer, "assets/images/scalar_button_unpressed.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" );
L_Arrow_Texture = IMG_LoadTexture(renderer, "assets/images/l_arrow_button.png" );
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;
if(!(Mousestate & SDL_BUTTON(SDL_BUTTON_LEFT))){
IsLock=BV.IsLock=BS.IsLock=BT.IsLock=false;
}else{
IsLock=true;
}
// Draw_Slider(renderer, &BV);
Draw_Slider(renderer, &BS);
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);
BALL_DrawTexture(renderer, &Settings_Ball_rect, scenery->ball.TextureIndex); BALL_DrawTexture(renderer, &Settings_Ball_rect, scenery->ball.TextureIndex);
Settings_Return(); Settings_Return();
Draw_Slider(renderer, &BV);
Draw_Slider(renderer, &BS);
Draw_Slider(renderer, &BT);
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;
@ -76,20 +97,29 @@ 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);
SDL_DestroyTexture(Bar_Texture);
SDL_DestroyTexture(Return_Button_Texture);
SDL_DestroyTexture(Settings_Skins_Texture);
SDL_DestroyTexture(Scalar_Button_Texture0);
SDL_DestroyTexture(Scalar_Button_Texture1);
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_RenderCopy(renderer, Bar_Texture, NULL, &beta->Bar_rect);
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 (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)))||beta->IsLock) {
SDL_RenderFillRect(renderer, &beta->Scalar_rect); if(!IsLock){
SDL_RenderDrawRect(renderer, &beta->Scalar_rect); beta->IsLock=true;
IsLock=true;
}
if(beta->IsLock){
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));
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);
@ -101,10 +131,20 @@ void Draw_Slider(SDL_Renderer * renderer, Slider * beta){
beta->Slider_value = x; beta->Slider_value = x;
} }
} else { } else {
SDL_RenderDrawRect(renderer, &beta->Scalar_rect); SDL_RenderCopy(renderer, Scalar_Button_Texture0, NULL, &beta->Scalar_rect);
}
} else {
SDL_RenderCopy(renderer, Scalar_Button_Texture0, NULL, &beta->Scalar_rect);
} }
} /* 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;
} }
@ -117,11 +157,23 @@ 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){
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);
}
} }

View File

@ -14,18 +14,32 @@
typedef struct sliderstruct { typedef struct sliderstruct {
SDL_Rect Bar_rect; SDL_Rect Bar_rect;
SDL_Rect Scalar_rect; SDL_Rect Scalar_rect;
bool IsLock;
double Slider_value,min,max; double Slider_value,min,max;
} Slider; } Slider;
typedef struct stepsliderstruct {
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 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);