Pause Menu added and smal debug view

main
Jan 3 years ago
parent 67a0aecfa6
commit 2ff46e2582

@ -12,7 +12,8 @@
"buttons.h": "c",
"string.h": "c",
"uicontainer.h": "c",
"button.h": "c"
"button.h": "c",
"cstdio": "c"
},
"C_Cpp.errorSquiggles": "disabled"
}

@ -1,6 +1,6 @@
CC = gcc
FLAGS = -lraylib -lGL -lm -lpthread -ldl -lrt -lX11
OBJS = main.o sprite.o inputHandler.o isometricMap.o list.o game.o textureatlas.o animation.o animationHandler.o bucket.o mergeSort.o button.o uiContainer.o
OBJS = main.o sprite.o inputHandler.o isometricMap.o list.o game.o textureatlas.o animation.o animationHandler.o bucket.o mergeSort.o button.o uiContainer.o debug.o
spiel: $(OBJS)
$(CC) -o spiel $(OBJS) $(FLAGS)
@ -44,5 +44,8 @@ button.o: Ui/button.c
uiContainer.o: Ui/uiContainer.c
$(CC) -c Ui/uiContainer.c $(FLAGS)
debug.o: Ui/debug.c
$(CC) -c Ui/debug.c $(FLAGS)
clean:
rm *.o spiel

@ -32,6 +32,10 @@ void ButtonExecuteButton(Button *button, Game *game){
game->screen = SCREEN_GAME;
}
break;
case BUTTON_ID_EXIT:
// wahrscheinlich kein guter stil, es muss noch zeug freigegeben werden oder soos... keine Ahnung
exit(1);
break;
}
}

@ -12,6 +12,7 @@
#define BUTTON_STATE_RELEASED 3
#define BUTTON_ID_CONTINUE 0
#define BUTTON_ID_EXIT 1
typedef struct Button{
Texture2D textures[4]; // [0]: Normal [1]: Hovered [2]: Pressed [3]: Released
@ -22,6 +23,7 @@ typedef struct Button{
int id;
} Button;
// Textures: [0]: Normal [1]: Hovered [2]: Pressed [3]: Released
Button * ButtonInitButton(Texture2D textures[4], Vector2 *position, char *text, int textLEN, int id);
// executes the logic of one button of certain id - huge switch?

@ -0,0 +1,29 @@
#include "debug.h"
#include "../game.h"
#include "uiContainer.h"
#include "string.h"
#include <stdio.h>
#include "../Input/inputHandler.h"
void DebugDraw(Game *game, UiContainer *uiContainer){
// Platz für bis zu 10 Strings der Länge 40
char strings[10][41];
int lineamount = 0;
sprintf(strings[lineamount++], "Screen: %d", game->screen);
sprintf(strings[lineamount++], "MouseScreenX: %d", GetMouseX());
sprintf(strings[lineamount++], "MouseScreenY: %d", GetMouseY());
sprintf(strings[lineamount++], "MouseWorldX: %d", (int)game->inputHandler->cursorWorldPos.x);
sprintf(strings[lineamount++], "MouseWorldY: %d", (int)game->inputHandler->cursorWorldPos.y);
DrawRectangleLines(0, 0, 200, lineamount * DEBUG_FONT_SIZE + 5, (Color){0, 0, 0, 255});
DrawRectangle(0, 0, 200, lineamount * DEBUG_FONT_SIZE + 5, (Color){0, 0, 0, 150});
int counter = 0;
while(counter < lineamount){
DrawText(strings[counter], 2, counter * DEBUG_FONT_SIZE + 2, DEBUG_FONT_SIZE, RED);
counter++;
}
}

@ -0,0 +1,11 @@
#ifndef DEBUG_H_
#define DEBUG_H_
#include "../game.h"
#include "uiContainer.h"
#define DEBUG_FONT_SIZE 18
void DebugDraw(Game *game, UiContainer *uiContainer);
#endif

@ -12,12 +12,22 @@ UiContainer * UiContainerInitPauseUiContainer(){
LoadTexture("assets/button_hovered.png"), //HOVERED
LoadTexture("assets/button_pressed.png"), //PRESSED
LoadTexture("assets/button_pressed.png")}; //RELEASED
Vector2 position = (Vector2){GetScreenWidth()/2 - textures[0].width/2, GetScreenHeight()/2 + 150};
Vector2 position = (Vector2){GetScreenWidth()/2 - textures[0].width/2, GetScreenHeight()/2 - 300};
Button *continuebutton = ButtonInitButton(textures, &position, "Continue", 9, BUTTON_ID_CONTINUE);
uiContainer->buttons[0] = continuebutton;
uiContainer->buttonCounter = 1;
Texture2D textures2[4] = { LoadTexture("assets/button.png"), //DEFAULT
LoadTexture("assets/button_hovered.png"), //HOVERED
LoadTexture("assets/button_pressed.png"), //PRESSED
LoadTexture("assets/button_pressed.png")}; //RELEASED
Vector2 position2 = (Vector2){GetScreenWidth()/2 - textures[0].width/2, GetScreenHeight()/2 - 50};
Button *exitButton = ButtonInitButton(textures2, &position2, "EXIT", 5, BUTTON_ID_EXIT);
uiContainer->buttons[1] = exitButton;
uiContainer->buttonCounter = 2;
// Methode funktioniert wieso auch immer auch ohne dieses return. C returned Implizit odder was O_o
return uiContainer;
}

@ -13,6 +13,7 @@
#include "Ui/screenIDs.h"
#include "Ui/button.h"
#include "Ui/uiContainer.h"
#include "Ui/debug.h"
int main(){
@ -35,6 +36,7 @@ int main(){
game->cursorSprite->x = GetMousePosition().x;
game->cursorSprite->y = GetMousePosition().y;
BeginDrawing();
switch(game->screen){
case SCREEN_EXIT:
return 0;
@ -49,7 +51,6 @@ int main(){
ListActAllSprites(game);
ClearBackground(RAYWHITE);
BeginDrawing();
BeginMode2D(*(game->camera));
@ -58,17 +59,12 @@ int main(){
IsometricMapDraw(game);
EndMode2D();
DrawSpriteToScreen(game->cursorSprite);
// User Input Handling
mouseInput(game);
keyboardInput(game->inputHandler, game->camera);
DrawFPS(GetScreenWidth() - 95, 10);
EndDrawing();
if(IsKeyPressed(KEY_P)){
game->screen = SCREEN_PAUSE;
}
@ -77,9 +73,6 @@ int main(){
case SCREEN_PAUSE:
ClearBackground(RAYWHITE);
BeginDrawing();
BeginMode2D(*(game->camera));
IsometricMapDraw(game);
EndMode2D();
@ -91,10 +84,10 @@ int main(){
UiContainerUpdateUiContainer(pauseScreenUiContainer, game);
UiContainerDrawUiContainer(pauseScreenUiContainer);
DebugDraw(game, pauseScreenUiContainer);
DrawSpriteToScreen(game->cursorSprite);
DrawFPS(GetScreenWidth() - 95, 10);
EndDrawing();
if(IsKeyPressed(KEY_P)){
game->screen = SCREEN_GAME;
@ -105,6 +98,10 @@ int main(){
return 1;
break;
}
BeginDrawing();
DebugDraw(game, pauseScreenUiContainer);
DrawFPS(GetScreenWidth() - 95, 10);
EndDrawing();

Loading…
Cancel
Save