You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
4.3 KiB
122 lines
4.3 KiB
#include "raylib.h"
|
|
#include "string.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include "Sprite/sprite.h"
|
|
#include "Input/inputHandler.h"
|
|
#include "Entity/entity.h"
|
|
#include "raymath.h"
|
|
#include "IsometricMap/isometricMap.h"
|
|
#include "game.h"
|
|
#include "Ui/screenIDs.h"
|
|
#include "Ui/button.h"
|
|
#include "Ui/uiContainer.h"
|
|
#include "Ui/debug.h"
|
|
|
|
// TODO: Variable die den Maus Input freigibt solange nichts mit der Maus gemacht wurde
|
|
// Sobald ein Button gedrückt wurde in diesem Frame oder rect gezogen wird oder so ist sind Maus Funktionen gesperrt
|
|
// verhindert Spawnen von entities wenn man UI Elemente Drückt etc
|
|
// Alternativ: Flag MouseOnHUD, aber nicht so universal einsetzbar, löst nur meine Probleme mit dem Spawnen bei klicks aufs HUD
|
|
|
|
int main(){
|
|
|
|
InitWindow(1280, 720, "basic window");
|
|
|
|
Game *game = GameInit();
|
|
|
|
// Hides the operating systems own cursor
|
|
HideCursor();
|
|
|
|
//SetTargetFPS(60);
|
|
|
|
|
|
while(!WindowShouldClose()){
|
|
|
|
// Moving cursor Sprite to Mouse Pos
|
|
game->cursorSprite->x = GetMousePosition().x;
|
|
game->cursorSprite->y = GetMousePosition().y;
|
|
|
|
BeginDrawing(); // Drawing ist grundsätzlich immer aktiviert
|
|
ClearBackground(RAYWHITE); // Screen wird in jedem Frame gecleared
|
|
switch(game->screen){ // Screenspecific Code
|
|
case SCREEN_EXIT:
|
|
printf("EXIT \n");
|
|
return 0;
|
|
case SCREEN_MAINMENU:
|
|
// MainMenu hat aktuell nur paar Buttons, die unten gedrawed werden
|
|
break;
|
|
case SCREEN_OPTIONS:
|
|
printf("OPTIONS \n");
|
|
return 0;
|
|
case SCREEN_GAME:
|
|
|
|
// Updating Sprites
|
|
EntityListActAllEntities(game);
|
|
|
|
// Drawing IsometricMap
|
|
BeginMode2D(*(game->camera)); // Sorgt dafür, dass die Kameraposition beachtet wird
|
|
IsometricMapDraw(game);
|
|
EndMode2D();
|
|
|
|
// User Input Handling
|
|
mouseInput(game);
|
|
keyboardInput(game->inputHandler, game->camera);
|
|
|
|
|
|
if(IsKeyPressed(KEY_P)){
|
|
game->screen = SCREEN_PAUSE;
|
|
}
|
|
|
|
break;
|
|
case SCREEN_PAUSE:
|
|
|
|
// Still drawing isometric map, which is not updated atm
|
|
BeginMode2D(*(game->camera)); // Sorgt dafür, dass die Kameraposition beachtet wird
|
|
IsometricMapDraw(game);
|
|
EndMode2D();
|
|
|
|
// darkened background + "Paused" Text
|
|
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), (Color){0, 0, 0, 150});
|
|
int textWidthHalf = MeasureText("Paused", 28) / 2;
|
|
DrawText("Paused", GetScreenWidth()/2 - textWidthHalf, GetScreenHeight()/4 - 14, 28, WHITE);
|
|
|
|
// Controls lol
|
|
DrawText("I: Zoom in", 5, GetScreenHeight()/2, 16, WHITE);
|
|
DrawText("K: Zoom out", 5, GetScreenHeight()/2 + 16, 16, WHITE);
|
|
DrawText("P: Pause", 5, GetScreenHeight()/2 + 32, 16, WHITE);
|
|
DrawText("WASD: Move Camera", 5, GetScreenHeight()/2 + 48, 16, WHITE);
|
|
DrawText("ESC: Exit Game", 5, GetScreenHeight()/2 + 64, 16, WHITE);
|
|
|
|
if(IsKeyPressed(KEY_P)){
|
|
game->screen = SCREEN_GAME;
|
|
}
|
|
break;
|
|
default:
|
|
printf("\n\n\n\n\n\n Wir haben ein problematisches Problem! Die Screen-ID [%d] ist nicht definiert. Hmmpf... früher bescheid wisse!\n\n\n\n\n\n", game->screen);
|
|
return 1;
|
|
break;
|
|
}
|
|
|
|
// Drawen wir einfach immer den UI Container vom aktuellen Screen? Aktuell hat ja jeder Screen einen, es sollte also keine Probleme geben
|
|
// Kann man natürlich auch noch oben in die einzelnen Cases schieben falls es mal Probleme machen sollte
|
|
UiContainerUpdateUiContainer(game->UiContainers[game->screen], game);
|
|
UiContainerDrawUiContainer(game->UiContainers[game->screen]);
|
|
|
|
|
|
// Dinge die grundsätzlich immer gedrawed werden sollen
|
|
// Debug Menu, FPS anzeige, Cursor
|
|
DebugDraw(game);
|
|
DrawFPS(GetScreenWidth() - 95, 10);
|
|
DrawSpriteToScreen(game->cursorSprite);
|
|
EndDrawing();
|
|
|
|
|
|
|
|
}
|
|
|
|
CloseWindow();
|
|
|
|
return 0;
|
|
|
|
}
|