Merge branch 'dev' of collaborating.tuhh.de:czg6669/breakout into dev
This commit is contained in:
commit
c8ffc7840c
@ -1,6 +1,6 @@
|
|||||||
#ifndef __gamestate_h__
|
#ifndef __gamestate_h__
|
||||||
#define __gamestate_h__
|
#define __gamestate_h__
|
||||||
|
|
||||||
typedef enum gameStateEnum { MainMenu = 1, Game = 2, LevelSelect = 3, Settings = 4, Highscores = 5 } GameState;
|
typedef enum gameStateEnum { MainMenu = 1, Game = 2, LevelSelect = 3, SkinSelect = 4, Settings = 5, Highscores = 6 } GameState;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
45
main.c
45
main.c
@ -13,11 +13,50 @@
|
|||||||
#include "gamestate.h"
|
#include "gamestate.h"
|
||||||
#include "highscores.h"
|
#include "highscores.h"
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
=======
|
||||||
|
#ifndef __nullptr__
|
||||||
|
#define Nullptr(type) (type *)0
|
||||||
|
#endif // __nullptr__
|
||||||
|
|
||||||
|
#define ae "\204"
|
||||||
|
#define oe "\224"
|
||||||
|
#define ue "\201"
|
||||||
|
#define ss "\341"
|
||||||
|
|
||||||
|
// Prototypes
|
||||||
|
void GAME_ChangeState(GameState state);
|
||||||
|
void HandleSDLEvents();
|
||||||
|
void mousePress(SDL_MouseButtonEvent b);
|
||||||
|
void keyPress(SDL_KeyboardEvent b);
|
||||||
|
void toggleFullscreen();
|
||||||
|
void windowChanged(SDL_WindowEvent b);
|
||||||
|
void DrawBackground(SDL_Renderer * renderer);
|
||||||
|
void INITIALIZE();
|
||||||
|
void QUIT();
|
||||||
|
int readIntFromIO(char * m1, char * m2, char * m3, int min, int max);
|
||||||
|
// End Prototypes
|
||||||
|
|
||||||
|
// Default Render Size (Upscaled for bigger monitors)
|
||||||
|
const int width = 1920;
|
||||||
|
const int height = 1080;
|
||||||
|
float XScale = 1.0f, YScale = 1.0f;
|
||||||
|
// End render properties
|
||||||
|
|
||||||
|
int numKeys;
|
||||||
|
const Uint8 * keystate; // TODO: export all this into scenery and enemy waves
|
||||||
|
SDL_Window * window;
|
||||||
|
SDL_Renderer * renderer;
|
||||||
|
SDL_Event event;
|
||||||
|
bool running = true, fullscreen = false;
|
||||||
|
GameState gameState = MainMenu;
|
||||||
|
Scenery scenery;
|
||||||
|
>>>>>>> 04d0cfb994382d9a6e6ebd1bb4ff3aa41b5af2bb
|
||||||
|
|
||||||
int main(int argc, char * args[]){
|
int main(int argc, char * args[]){
|
||||||
printf("Spielbereiche\n\t- 1: Hauptmen"ue "\n\t- 2: Spiel\n\t- 3: Level Select\n\t- 4: Settings\n\t- 5: Highscores\n");
|
//printf("Spielbereiche\n\t- 1: Hauptmen"ue "\n\t- 2: Spiel\n\t- 3: Level Select\n\t- 4: Settings\n\t- 5: Highscores\n");
|
||||||
GAME_ChangeState(readIntFromIO("W"ae "hle einen Spielbereich aus, den du testen m"oe "chtest:", "Fehlerhafte Eingabe!\n", "%d ist kein g"ue "ltiger Spielbereich!\n", 1, 5));
|
//GAME_ChangeState(readIntFromIO("W"ae "hle einen Spielbereich aus, den du testen m"oe "chtest:", "Fehlerhafte Eingabe!\n", "%d ist kein g"ue "ltiger Spielbereich!\n", 1, 5));
|
||||||
INITIALIZE();
|
INITIALIZE();
|
||||||
while (running) { // Gameloop
|
while (running) { // Gameloop
|
||||||
HandleSDLEvents();
|
HandleSDLEvents();
|
||||||
@ -29,6 +68,7 @@ int main(int argc, char * args[]){
|
|||||||
break;
|
break;
|
||||||
case MainMenu:
|
case MainMenu:
|
||||||
// Startmenu_Update(keystate);
|
// Startmenu_Update(keystate);
|
||||||
|
|
||||||
Startmenu_Draw(renderer);
|
Startmenu_Draw(renderer);
|
||||||
break;
|
break;
|
||||||
case Highscores:
|
case Highscores:
|
||||||
@ -77,6 +117,7 @@ void HandleSDLEvents(){
|
|||||||
break;
|
break;
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
mousePress(event.button);
|
mousePress(event.button);
|
||||||
|
button_clicked(event.button);
|
||||||
break;
|
break;
|
||||||
case SDL_WINDOWEVENT:
|
case SDL_WINDOWEVENT:
|
||||||
windowChanged(event.window);
|
windowChanged(event.window);
|
||||||
|
22
startmenu.c
22
startmenu.c
@ -2,6 +2,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <SDL2/SDL_image.h>
|
#include <SDL2/SDL_image.h>
|
||||||
|
#include "gamestate.h"
|
||||||
|
|
||||||
|
|
||||||
SDL_Texture* TITLE_Texture;
|
SDL_Texture* TITLE_Texture;
|
||||||
SDL_Texture* PLAYBUTTON_Texture;
|
SDL_Texture* PLAYBUTTON_Texture;
|
||||||
@ -19,6 +21,10 @@ SDL_Rect SKINSBUTTON_Rect;
|
|||||||
SDL_Rect HIGHSCORESBUTTON_Rect;
|
SDL_Rect HIGHSCORESBUTTON_Rect;
|
||||||
SDL_Rect QUITBUTTON_Rect;
|
SDL_Rect QUITBUTTON_Rect;
|
||||||
|
|
||||||
|
int clickInRect(SDL_MouseButtonEvent b, SDL_Rect* area_rect) {
|
||||||
|
return (((b.x) >= (area_rect->x)) && ((b.x) <= ((area_rect->x) + (area_rect->w))) && ((b.y) >= (area_rect->y)) && ((b.y) <= ((area_rect->y) + (area_rect->h))));
|
||||||
|
}
|
||||||
|
|
||||||
void Load_Textures (SDL_Renderer* renderer) {
|
void Load_Textures (SDL_Renderer* renderer) {
|
||||||
TITLE_Texture = IMG_LoadTexture(renderer, "assets/images/breaking_button.png");
|
TITLE_Texture = IMG_LoadTexture(renderer, "assets/images/breaking_button.png");
|
||||||
TITLE_Rect = (SDL_Rect){.x = 685,.y = 50, .w=550, .h=250};
|
TITLE_Rect = (SDL_Rect){.x = 685,.y = 50, .w=550, .h=250};
|
||||||
@ -51,3 +57,19 @@ void Startmenu_Draw (SDL_Renderer* renderer) {
|
|||||||
SDL_RenderCopy(renderer, HIGHSCORESBUTTON_Texture, NULL, &HIGHSCORESBUTTON_Rect);
|
SDL_RenderCopy(renderer, HIGHSCORESBUTTON_Texture, NULL, &HIGHSCORESBUTTON_Rect);
|
||||||
SDL_RenderCopy(renderer, QUITBUTTON_Texture, NULL, &QUITBUTTON_Rect);
|
SDL_RenderCopy(renderer, QUITBUTTON_Texture, NULL, &QUITBUTTON_Rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void button_clicked(SDL_MouseButtonEvent b) {
|
||||||
|
if(clickInRect(b, &PLAYBUTTON_Rect) == 1) {
|
||||||
|
GAME_ChangeState(Game);
|
||||||
|
} else if (clickInRect(b, &SKINSBUTTON_Rect) == 1) {
|
||||||
|
GAME_ChangeState(SkinSelect);
|
||||||
|
} else if (clickInRect(b, &LEVELBUTTON_Rect) == 1) {
|
||||||
|
GAME_ChangeState(LevelSelect);
|
||||||
|
} else if (clickInRect(b, &SETTINGSBUTTON_Rect) == 1) {
|
||||||
|
GAME_ChangeState(Settings);
|
||||||
|
} else if (clickInRect(b, &HIGHSCORESBUTTON_Rect) == 1) {
|
||||||
|
GAME_ChangeState(Highscores);
|
||||||
|
} else if (clickInRect(b, &QUITBUTTON_Rect) == 1) {
|
||||||
|
GAME_Escape();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -12,4 +12,8 @@ void Load_Textures (SDL_Renderer* renderer);
|
|||||||
|
|
||||||
void Startmenu_Draw (SDL_Renderer* renderer);
|
void Startmenu_Draw (SDL_Renderer* renderer);
|
||||||
|
|
||||||
|
void button_clicked(SDL_MouseButtonEvent b);
|
||||||
|
|
||||||
|
int clickInRect(SDL_MouseButtonEvent b, SDL_Rect* area_rect);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user