summary refs log tree commit diff stats
path: root/titlestate.cpp
blob: 2b85fbed45924a09712624705e41340d999cfa1d (plain) (blame)
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include "titlestate.h"
#include "util.h"
#include "gamestate.h"
#include "hslist.h"

State* TitleState::operator() (SDL_Window* window, SDL_Renderer* renderer)
{
	SDL_Texture* background = loadImage(renderer, "resources/title.bmp");
	SDL_Texture* pointer = loadImage(renderer, "resources/pointer.bmp");
	int selection = 0;
	SDL_Event e;
	
	for (;;)
	{
		SDL_RenderClear(renderer);
		SDL_RenderCopy(renderer, background, NULL, NULL);
		applyTexture(renderer, pointer, 136, selection==0?316:(selection==1?350:(selection==2?381:417)));
		SDL_RenderPresent(renderer);
		
		while (SDL_PollEvent(&e))
		{
			if (e.type == SDL_QUIT)
			{
				return NULL;
			} else if (e.type == SDL_KEYDOWN)
			{
				if ((e.key.keysym.sym == SDLK_UP) && (selection != 0))
				{
					selection--;
				} else if ((e.key.keysym.sym == SDLK_DOWN) && (selection != 3))
				{
					selection++;
				} else if (e.key.keysym.sym == SDLK_RETURN)
				{
					switch (selection)
					{
						case 0: return new GameState();
						case 1: return new HowToPlayState();
						case 2: return new ChooseHighscoreListState();
						case 3:	return NULL;
					}
				}
			}
		}
	}
}

State* HowToPlayState::operator() (SDL_Window* window, SDL_Renderer* renderer)
{
	SDL_Texture* background = loadImage(renderer, "resources/htp1.bmp");
	SDL_Texture* pointer = loadImage(renderer, "resources/pointer.bmp");
	int selection = 0;
	SDL_Event e;
	
	for (;;)
	{
		SDL_RenderClear(renderer);
		SDL_RenderCopy(renderer, background, NULL, NULL);
		applyTexture(renderer, pointer, selection==0?74:216, 430);
		SDL_RenderPresent(renderer);
		
		while (SDL_PollEvent(&e))
		{
			if (e.type == SDL_QUIT)
			{
				return NULL;
			} else if (e.type == SDL_KEYDOWN)
			{
				if ((e.key.keysym.sym == SDLK_LEFT) && (selection != 0))
				{
					selection--;
				} else if ((e.key.keysym.sym == SDLK_RIGHT) && (selection != 1))
				{
					selection++;
				} else if (e.key.keysym.sym == SDLK_RETURN)
				{
					switch (selection)
					{
						case 0:
							return new HowToPlayPageTwoState();

							break;
						case 1:
							return new TitleState();
					}
				}
			}
		}
	}
}

State* HowToPlayPageTwoState::operator() (SDL_Window* window, SDL_Renderer* renderer)
{
	SDL_Texture* background = loadImage(renderer, "resources/htp2.bmp");
	SDL_Texture* pointer = loadImage(renderer, "resources/pointer.bmp");
	int selection = 0;
	SDL_Event e;
	
	for (;;)
	{
		SDL_RenderClear(renderer);
		SDL_RenderCopy(renderer, background, NULL, NULL);
		applyTexture(renderer, pointer, selection==0?45:238, 430);
		SDL_RenderPresent(renderer);
		
		while (SDL_PollEvent(&e))
		{
			if (e.type == SDL_QUIT)
			{
				return NULL;
			} else if (e.type == SDL_KEYDOWN)
			{
				if ((e.key.keysym.sym == SDLK_LEFT) && (selection != 0))
				{
					selection--;
				} else if ((e.key.keysym.sym == SDLK_RIGHT) && (selection != 1))
				{
					selection++;
				} else if (e.key.keysym.sym == SDLK_RETURN)
				{
					switch (selection)
					{
						case 0:
							return new HowToPlayState();

							break;
						case 1:
							return new TitleState();
					}
				}
			}
		}
	}
}