aboutsummaryrefslogtreecommitdiff
path: root/src/titlescreen.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/titlescreen.c')
-rw-r--r--src/titlescreen.c120
1 files changed, 120 insertions, 0 deletions
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 <stdio.h>
+#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