aboutsummaryrefslogtreecommitdiff
path: root/src/titlescreen.c
blob: 328dd8f45e2f1ef8dc48f6fa098f60cd3d6a5ac2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "titlescreen.h"
#include "game.h"
#include <stdio.h>
#include "text.h"

int tempsave = 0;
int cursor = 0;

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(savemap) ) {
		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);
}