From de29b11a88dbdd3af0824e59b51528b91ee73c54 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Thu, 30 Nov 2017 22:49:38 +0100 Subject: First commit. Version works on Linux (keyboard only, not configurable) --- src/titlescreen.c | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 src/titlescreen.c (limited to 'src/titlescreen.c') diff --git a/src/titlescreen.c b/src/titlescreen.c new file mode 100644 index 0000000..4369ac4 --- /dev/null +++ b/src/titlescreen.c @@ -0,0 +1,120 @@ +#include "titlescreen.h" +#include "game.h" +#include +#include "text.h" + +int tempsave = 0; +int cursor = 0; + +#ifdef _SDL +extern char savename[4096]; +#else +#define savename "data/save.tmp" +#endif + +void titleScreenSetup(); + +int titleScreenStep(); +void titleScreenDraw(); + +int titleScreen() +{ + titleScreenSetup(); + + char loop = 1; + int result = -1; + + while (PHL_MainLoop() && loop == 1) + { + //Get input + PHL_ScanInput(); + + //Titlescreen step + result = titleScreenStep(); + + //Draw titlescreen + PHL_StartDrawing(); + + titleScreenDraw(); + + if (result != -1) { + loop = 0; + //Force screen to black + PHL_DrawRect(0, 0, 640, 480, PHL_NewRGB(0, 0, 0)); + } + + PHL_EndDrawing(); + } + + return result; +} + +void titleScreenSetup() +{ + cursor = 0; + + //Move cursor if save file exists + if ( fileExists("map/018.map") ) { + cursor = 1; + } + + //Check if temp save file exists + tempsave = 0; + if ( fileExists(savename) ) { + tempsave = 1; + cursor = 1; + } +} + +int titleScreenStep() +{ + //Move cursor + if (btnDown.pressed == 1 || btnSelect.pressed == 1) { + cursor += 1; + if (cursor > 2) { + cursor = 0; + } + PHL_PlaySound(sounds[sndPi01], 1); + } + + if (btnUp.pressed == 1) { + cursor -= 1; + if (cursor < 0) { + cursor = 2; + } + PHL_PlaySound(sounds[sndPi01], 1); + } + + //Selection + if (btnAccept.pressed == 1 || btnStart.pressed == 1) { + PHL_PlaySound(sounds[sndOk], 1); + return cursor; + } + + return -1; +} + +void titleScreenDraw() +{ + //Blackdrop + PHL_DrawRect(0, 0, 640, 480, PHL_NewRGB(0, 0, 0)); + + if (tempsave == 0) { + //Title image + PHL_DrawSurfacePart(168, 72, 0, 0, 304, 168, images[imgTitle01]); + }else{ + //Save error message + drawTextCentered(saveError[0], 320, 80); + drawTextCentered(saveError[1], 320, 80 + 50); + drawTextCentered(saveError[2], 320, 80 + 96); + } + + //Cursor + PHL_DrawSurfacePart(228, 264 + (cursor * 32), 4, 176, 184, 32, images[imgTitle01]); + + //Text + PHL_DrawTextBold("NEW GAME", 256, 272, YELLOW); + PHL_DrawTextBold("LOAD GAME", 248, 304, YELLOW); + PHL_DrawTextBold("EXIT", 288, 336, YELLOW); + PHL_DrawTextBold("(C) 2011 E.HASHIMOTO", 160, 400, WHITE); +} \ No newline at end of file -- cgit v1.2.3