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.
107 lines
3.6 KiB
107 lines
3.6 KiB
#include "screen.h"
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include "../definitions.h"
|
|
#include "raylib.h"
|
|
#include "../Sprite/sprite.h"
|
|
#include "../Input/inputHandler.h"
|
|
#include "../Entity/entity.h"
|
|
#include "../IsometricMap/isometricMap.h"
|
|
#include "../game.h"
|
|
#include "../Ui/uiContainer.h"
|
|
|
|
void ScreenRenderEmptyScreen(Game *game){
|
|
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->currentScreen);
|
|
}
|
|
|
|
void ScreenRenderExitScreen(Game *game){
|
|
printf("EXIT \n");
|
|
}
|
|
|
|
void ScreenRenderGameScreen(Game *game){
|
|
game->screens[game->currentScreen]->frameCounter += GetFrameTime();
|
|
if(game->screens[game->currentScreen]->frameCounter >= ACT_TIME){
|
|
EntityListActAllEntities(game);
|
|
game->screens[game->currentScreen]->frameCounter = 0;
|
|
}
|
|
// Drawing IsometricMap
|
|
BeginMode2D(*(game->camera)); // Sorgt dafür, dass die Kameraposition beachtet wird
|
|
IsometricMapDraw(game);
|
|
|
|
SpriteListDrawAllSprites(game->sprites, game->map, game->camera);
|
|
|
|
// Draws rect above selected Tile, no need for changing the texture any more
|
|
IsometricMapDrawRectangle((Vector2){game->inputHandler->cursorWorldTile.x * 32, game->inputHandler->cursorWorldTile.y * 32},
|
|
(Vector2){(game->inputHandler->cursorWorldTile.x+1) * 32, (game->inputHandler->cursorWorldTile.y+1) * 32}, RED);
|
|
|
|
EndMode2D();
|
|
|
|
// User Input Handling
|
|
mouseInput(game);
|
|
keyboardInput(game);
|
|
}
|
|
|
|
void ScreenRenderMainMenuScreen(Game *game){
|
|
// hmmmmm
|
|
}
|
|
|
|
void ScreenRenderPauseScreen(Game *game){
|
|
int halfScreenHeight = GetScreenHeight()/2;
|
|
|
|
// Still drawing isometric map, which is not updated atm
|
|
BeginMode2D(*(game->camera)); // Sorgt dafür, dass die Kameraposition beachtet wird
|
|
IsometricMapDraw(game);
|
|
SpriteListDrawAllSprites(game->sprites, game->map, game->camera);
|
|
EndMode2D();
|
|
UiContainerDrawUiContainer(game->screens[game->currentScreen]->uiContainer);
|
|
// 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, (halfScreenHeight/2) - 14, 28, WHITE);
|
|
|
|
// Controls lol
|
|
DrawText("I: Zoom in", 5, halfScreenHeight, 16, WHITE);
|
|
DrawText("K: Zoom out", 5, halfScreenHeight + 16, 16, WHITE);
|
|
DrawText("P: Pause", 5, halfScreenHeight + 32, 16, WHITE);
|
|
DrawText("WASD: Move Camera", 5, halfScreenHeight + 48, 16, WHITE);
|
|
DrawText("ESC: Exit Game", 5, halfScreenHeight + 64, 16, WHITE);
|
|
|
|
if(IsKeyPressed(KEY_P)){
|
|
game->currentScreen = SCREEN_GAME;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Screen * InitScreen(Game *game, int id){
|
|
Screen *screen = malloc(sizeof(Screen));
|
|
|
|
screen->id = id;
|
|
screen->frameCounter = 0;
|
|
|
|
screen->uiContainer = UiContainerInitUiContainerForScreenID(game, id);
|
|
|
|
switch(id){
|
|
case SCREEN_EXIT:
|
|
screen->render = &ScreenRenderExitScreen;
|
|
break;
|
|
case SCREEN_MAINMENU:
|
|
screen->render = &ScreenRenderMainMenuScreen;
|
|
break;
|
|
case SCREEN_OPTIONS:
|
|
screen->render = &ScreenRenderEmptyScreen;
|
|
break;
|
|
case SCREEN_GAME:
|
|
screen->render = &ScreenRenderGameScreen;
|
|
break;
|
|
case SCREEN_PAUSE:
|
|
screen->render = &ScreenRenderPauseScreen;
|
|
break;
|
|
default:
|
|
printf("WARNING: Creating Screen of ID %d (NOT SUPPORTED) \n", id);
|
|
screen->render = &ScreenRenderEmptyScreen;
|
|
break;
|
|
}
|
|
|
|
return screen;
|
|
} |