merge 2.0

This commit is contained in:
Andreas Neumann 2018-01-25 16:13:17 +01:00
parent 8b8771fd41
commit 15b0846787
7 changed files with 180 additions and 29 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 48 KiB

2
main.c
View File

@ -197,7 +197,7 @@ void INITIALIZE() {
Load_Textures(renderer);
HIGHSCORES_Initialize();
BACKGROUND_Initialize(renderer, width, height);
Settings_Initialize(renderer);
Settings_Initialize(renderer,&scenery);
GAMEOVER_Initialize(renderer);
printf("Initializing finished!\n");
} /* INITIALIZE */

110
old/settings.c Normal file
View File

@ -0,0 +1,110 @@
#include <stdio.h>
#include <stdlib.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <stdbool.h>
#include "settings.h"
#define Slider_height 100
#define Scalar_width 20
#define Bar_width 400
#define round(x) ((int) ((x) + .5))
#define distance(x1,y1,x2,y2) ((int)(sqrt(pow(x2-x1,2)+pow(y2-y1,2))))
SDL_Texture* Settings_Texture;
SDL_Texture* Settings_Return_Button_Texture;
SDL_Rect Settings_rect;
SDL_Rect Settings_Return_Button_rect;
Slider BV;
Slider BS;
Slider BT;
Uint32 Mousestate;
bool Settings_IsInit=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,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);
Settings_Texture = IMG_LoadTexture(renderer, "assets/images/settings_title.png");
Settings_rect = (SDL_Rect){.x = 800, .y = 180, .w=313, .h=100};
Settings_Return_Button_Texture = IMG_LoadTexture(renderer, "assets/images/return_button.png");
Settings_Return_Button_rect = (SDL_Rect){.x = 200, .y = 200, .w=75, .h=75};
Settings_IsInit = true;
}
void Settings_Draw (SDL_Renderer* renderer,Scenery* scenery) {
double x;
scenery->ball.TargetRect.x=900;
scenery->ball.TargetRect.y=700;
SDL_RenderCopy(renderer, Settings_Texture, NULL, &Settings_rect);
SDL_RenderCopy(renderer, Settings_Return_Button_Texture, NULL, &Settings_Return_Button_rect);
Draw_Slider(renderer,&BV);
Draw_Slider(renderer,&BS);
Draw_Slider(renderer,&BT);
Draw_Ballstate(renderer,scenery);
mapping(&x,&BT);
scenery->ball.TextureIndex=round(x);
mapping(&x,&BS);
scenery->ball.TargetRect.w=x;
scenery->ball.TargetRect.h=x;
Settings_Return();
}
void Settings_Deinitialize(){
if(Settings_IsInit){
SDL_DestroyTexture(Settings_Texture);
SDL_DestroyTexture(Settings_Ball_Texture);
Settings_IsInit=false;
}
}
void Draw_Slider(SDL_Renderer* renderer,Slider* beta){
SDL_SetRenderDrawColor(renderer,255,255,255,255);
SDL_RenderDrawRect(renderer,&beta->Bar_rect);
int x,y;
Mousestate=SDL_GetMouseState(&x,&y);
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))){
SDL_RenderFillRect(renderer,&beta->Scalar_rect);
SDL_RenderDrawRect(renderer,&beta->Scalar_rect);
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->Slider_value=(beta->Bar_rect.x+beta->Bar_rect.w-(beta->Scalar_rect.w)/2);
}
else if(x<beta->Bar_rect.x+(beta->Scalar_rect.w)/2){
beta->Scalar_rect.x=beta->Bar_rect.x;
beta->Slider_value=beta->Bar_rect.x+(beta->Scalar_rect.w)/2;
}
else{
beta->Scalar_rect.x=x-(beta->Scalar_rect.w/2);
beta->Slider_value=x;
}
}
else{
SDL_RenderDrawRect(renderer,&beta->Scalar_rect);
}
}
void Draw_Ballstate(SDL_Renderer* renderer,Scenery* scenery){
BALL_Draw(renderer, &(scenery->ball));
}
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;
}
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->Bar_rect = (SDL_Rect){.x=x,.y=y,.w=bw,.h=h};
beta->max=max;
beta->min=min;
beta->Slider_value=(defaultvalue-min)/(max-min)*(bw-sw/2)+x;
}
void Settings_Return(Scenery* scenery){
int x,y;
Mousestate=SDL_GetMouseState(&x,&y);
if((distance(x,y,237,237)<=37)&&(Mousestate & SDL_BUTTON(SDL_BUTTON_LEFT)))
GAME_ChangeState(MainMenu);
}

38
old/settings.h Normal file
View File

@ -0,0 +1,38 @@
#ifndef __Settings__
#define __Settings__
#include <stdio.h>
#include <stdlib.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <stdbool.h>
#include <math.h>
#include "breakout.h"
#include "gamestate.h"
#include "main.h"
typedef struct sliderstruct {
SDL_Rect Bar_rect;
SDL_Rect Scalar_rect;
double Slider_value,min,max;
} Slider;
void Settings_Draw (SDL_Renderer* renderer,Scenery* scenery);
void Draw_Slider(SDL_Renderer* renderer,Slider* beta);
void Draw_Ballstate(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 Settings_Deinitialize();
void mapping(double *x,Slider* beta);
void Settings_Return();
#endif

View File

@ -4,13 +4,13 @@
#include <SDL2/SDL_image.h>
#include <stdbool.h>
#include "breakout.h"
#include "settings.h"
#define Slider_height 100
#define Scalar_width 20
#define Bar_width 400
#define round(x) ((int)((x) + .5))
#define distance(x1,y1,x2,y2) ((int)(sqrt(pow(x2-x1,2)+pow(y2-y1,2))))
SDL_Texture * Settings_Texture;
SDL_Texture * Settings_Ball_Texture;
@ -26,12 +26,14 @@ Slider BV;
Slider BS;
Slider BT;
Uint32 Mousestate;
bool Settings_IsInit = false;
void Settings_Initialize (SDL_Renderer* renderer) {
Initialize_Slider(400,300,Scalar_width,Bar_width,Slider_height,1,2,&BV);
Initialize_Slider(400,500,Scalar_width,Bar_width,Slider_height,10.0f,20.0f,&BS);
Initialize_Slider(400,700,Scalar_width,Bar_width,Slider_height,0,8,&BT);
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,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);
Settings_Texture = IMG_LoadTexture(renderer, "assets/images/settings_title.png");
Settings_rect = (SDL_Rect){.x = 647, .y = 50, .w=626, .h=200};
@ -41,7 +43,7 @@ void Settings_Initialize (SDL_Renderer* renderer) {
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_rect = (SDL_Rect){.x = 30, .y = 30, .w=261, .h=100};
Return_Button_rect = (SDL_Rect){.x = 200, .y = 200, .w=75, .h=75};
Settings_IsInit = true;
}
@ -50,17 +52,18 @@ void Settings_Draw(SDL_Renderer * renderer, Scenery * scenery) {
double x;
SDL_RenderCopy(renderer, Settings_Texture, NULL, &Settings_rect);
SDL_RenderCopy(renderer, Settings_Ball_Texture, NULL, &Settings_Ball_rect);
SDL_RenderCopy(renderer, Settings_Skins_Texture, NULL, &Settings_Skins_rect);
SDL_RenderCopy(renderer, Return_Button_Texture, NULL, &Return_Button_rect);
SDL_RenderCopy(renderer, Settings_Skins_Texture, NULL, &Settings_Skins_rect);
BALL_DrawTexture(renderer, &Settings_Ball_rect, scenery->ball.TextureIndex);
Settings_Return();
Draw_Slider(renderer, &BV);
Draw_Slider(renderer, &BS);
Draw_Slider(renderer, &BT);
//Draw_Ballstate(renderer, scenery);
BALL_DrawTexture(renderer, &Settings_Ball_rect, scenery->ball.TextureIndex);
mapping(&x, &BS);
scenery->ball.Speed = x;
scenery->ball.TargetRect.w = x;
scenery->ball.TargetRect.h = x;
scenery->ball.Size = ((double)x / 2.0f);
mapping(&x, &BT);
x = round(x);
scenery->ball.TextureIndex = x;
@ -78,7 +81,7 @@ void Draw_Slider(SDL_Renderer * renderer, Slider * beta){
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_RenderDrawRect(renderer, &beta->Bar_rect);
int x, y;
Uint32 Mousestate = SDL_GetMouseState(&x, &y);
Mousestate = SDL_GetMouseState(&x, &y);
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))) {
SDL_RenderFillRect(renderer, &beta->Scalar_rect);
SDL_RenderDrawRect(renderer, &beta->Scalar_rect);
@ -97,18 +100,21 @@ void Draw_Slider(SDL_Renderer * renderer, Slider * beta){
}
} /* Draw_Slider */
void Draw_Ballstate(SDL_Renderer * renderer, Scenery * scenery){
BALL_Draw(renderer, &(scenery->ball));
}
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;
}
void Initialize_Slider(int x, int y, int sw, int bw, int h, double min, double max, Slider * beta){
beta->Scalar_rect = (SDL_Rect) {.x = x, .y = y, .w = sw, .h = h };
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->Bar_rect = (SDL_Rect) {.x = x, .y = y, .w = bw, .h = h };
beta->max = max;
beta->min = min;
beta->Slider_value = x + beta->Scalar_rect.w / 2;
beta->Slider_value = (defaultvalue-min)/(max-min)*(bw-sw/2)+x;
}
void Settings_Return(){
int x,y;
Mousestate=SDL_GetMouseState(&x,&y);
if((distance(x,y,237,237)<=37)&&(Mousestate & SDL_BUTTON(SDL_BUTTON_LEFT)))
GAME_ChangeState(MainMenu);
}

View File

@ -8,6 +8,8 @@
#include <SDL2/SDL_image.h>
#include <stdbool.h>
#include "breakout.h"
#include "gamestate.h"
#include "main.h"
typedef struct sliderstruct {
SDL_Rect Bar_rect;
@ -20,14 +22,14 @@ void Settings_Draw (SDL_Renderer* renderer,Scenery* scenery);
void Draw_Slider(SDL_Renderer* renderer,Slider* beta);
void Draw_Ballstate(SDL_Renderer* renderer,Scenery* scenery);
void Settings_Initialize (SDL_Renderer* renderer,Scenery* scenery);
void Settings_Initialize (SDL_Renderer* renderer);
void Initialize_Slider(int x,int y,int sw,int bw,int h,double min,double max,Slider* beta);
void Initialize_Slider(int x,int y,int sw,int bw,int h,double min,double max,Slider* beta,double defaultvalue);
void Settings_Deinitialize();
void mapping(double *x,Slider* beta);
void Settings_Return();
#endif

View File

@ -65,9 +65,4 @@ void button_clicked(SDL_MouseButtonEvent b, GameState gameState) {
GAME_Escape();
}
}
if (gameState == Settings) {
if (clickInRect(b, &Return_Button_rect) == 1) {
GAME_ChangeState(MainMenu);
}
}
}