Included background slider

This commit is contained in:
Andreas Neumann 2018-02-01 13:22:27 +01:00
parent 68f60a866f
commit 4f355f6f6d
6 changed files with 19 additions and 10 deletions

View File

@ -12,6 +12,7 @@
#include "background.h"
#define BG_Path_1 "assets/images/bg/bg1.png"
#define BG_Path_2 "assets/images/bg/bg2.png"
int BACKGROUND_BoxWidth, BACKGROUND_BoxHeight;
int BACKGROUND_TextureCount;
@ -28,6 +29,8 @@ void BACKGROUND_Initialize(SDL_Renderer * renderer, int width, int height){
BACKGROUND_TotalRect = (SDL_Rect) {.x = 0, .y = 0, .w = 1920, .h = 1080 };
BACKGROUND_Textures = malloc(BACKGROUND_TextureCount * sizeof(SDL_Texture *));
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);
printf("Background initialized!\n");
BACKGROUND_IsInit = true;
} else

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 17 KiB

5
main.c
View File

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

View File

@ -30,7 +30,7 @@ SDL_Rect Settings_Skins_rect;
SDL_Rect Return_Button_rect;
SDL_Rect Circle_rect;
Slider BV;
Slider BG;
Slider BS;
Slider BT;
@ -40,7 +40,7 @@ bool Settings_IsInit = false;
bool IsLock=false;
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,1,&BG,0);
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,300,Scalar_width,Bar_width,Slider_height,0,8,&BT,scenery->paddle.TextureIndex);
@ -60,19 +60,20 @@ void Settings_Initialize (SDL_Renderer* renderer,Scenery* scenery) {
Scalar_Button_Texture1 = IMG_LoadTexture(renderer, "assets/images/scalar_button_pressed.png");
Circle_Texture = IMG_LoadTexture(renderer,"assets/images/circle.png");
Circle_rect = (SDL_Rect){.x = 1200, .y = 500, .w=75, .h=75};
Circle_rect = (SDL_Rect){.x = 1250, .y = 500, .w=75, .h=75};
Settings_IsInit = true;
}
void Settings_Draw(SDL_Renderer * renderer, Scenery * scenery) {
void Settings_Draw(SDL_Renderer * renderer, Scenery * scenery,int *backgroundcount) {
double x;
if(!(Mousestate & SDL_BUTTON(SDL_BUTTON_LEFT))){
IsLock=BV.IsLock=BS.IsLock=BT.IsLock=false;
IsLock=BG.IsLock=BS.IsLock=BT.IsLock=false;
}else{
IsLock=true;
}
Draw_Slider(renderer, &BV);
BACKGROUND_Draw(renderer,*backgroundcount);
Draw_Slider(renderer, &BG);
Draw_Slider(renderer, &BS);
Draw_Slider(renderer, &BT);
SDL_RenderCopy(renderer, Settings_Texture, NULL, &Settings_rect);
@ -85,7 +86,7 @@ void Settings_Draw(SDL_Renderer * renderer, Scenery * scenery) {
scenery->ball.TargetRect.w = x;
scenery->ball.TargetRect.h = x;
scenery->ball.Size = ((double)x / 2.0f);
int posx=1200,posy=500;
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;
@ -93,6 +94,9 @@ void Settings_Draw(SDL_Renderer * renderer, Scenery * scenery) {
mapping(&x, &BT);
x = round(x);
scenery->ball.TextureIndex = x;
mapping(&x,&BG);
x=round(x);
*backgroundcount=x;
}
void Settings_Deinitialize(){

View File

@ -10,6 +10,7 @@
#include "breakout.h"
#include "gamestate.h"
#include "main.h"
#include "background.h"
typedef struct sliderstruct {
SDL_Rect Bar_rect;
@ -18,7 +19,7 @@ typedef struct sliderstruct {
double Slider_value,min,max;
} Slider;
void Settings_Draw (SDL_Renderer* renderer,Scenery* scenery);
void Settings_Draw (SDL_Renderer* renderer,Scenery* scenery,int *backgroundcount);
void Draw_Slider(SDL_Renderer* renderer,Slider* beta);