summaryrefslogtreecommitdiff
path: root/noncore/games/sfcave-sdl/help.cpp
blob: 0a7924be78a8f4a9e5169d1b6e57cfaf00a1241b (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#include <SDL/SDL.h>
#include "constants.h"

#include "font.h"
#include "help.h"
#include "sfcave.h"
#include "starfield.h"

Help :: Help( SFCave *p )
{
    parent = p;
   	stars = new StarField( false, 200 );

    loadText();

    init();
}

Help :: ~Help()
{
    delete stars;
}

void Help :: handleKeys( SDL_KeyboardEvent &key )
{
	if ( key.type == SDL_KEYDOWN )
	{
        if ( key.keysym.sym == SDLK_SPACE )
            parent->changeState( STATE_MENU );
        else if ( key.keysym.sym == SDLK_DOWN )
            textSpeed = 5;
        else if ( key.keysym.sym == SDLK_UP )
        {
            if ( textSpeed > 0 )
                textSpeed = 0;
            else textSpeed = 1;
        }

	}
	else if ( key.type == SDL_KEYUP )
	{
        if ( key.keysym.sym == SDLK_DOWN )
            textSpeed = 1;
    }
}
void Help :: init()
{
	startPos = 320;
	currLine = 0;
	textSpeed = 1;

	// Create our coloured font
	FontHandler :: changeColor( FONT_HELP_FONT, 0, 0, 255 );
}

void Help :: draw( SDL_Surface *screen )
{
    stars->draw( screen );

	list<string>::iterator it = textList.begin();

	// Move to start of text
	for ( int i = 0 ; i < currLine && it != textList.end() ; ++i )
		it++;

	int pos = startPos;
	while ( pos < 320 && it != textList.end() )
	{
		// get next line
		string text = *it;

		// draw text
		FontHandler::draw( screen, FONT_COLOURED_TEXT, text.c_str(), -1, pos );
		pos += FontHandler::FontHeight( FONT_COLOURED_TEXT );
		it ++;
	}

}

void Help :: update()
{
    stars->move();

	startPos -= textSpeed;
	if ( startPos <= -FontHandler::FontHeight( FONT_COLOURED_TEXT ) )
	{
		startPos = 0;
		currLine ++;

		if ( currLine > textList.size() )
		{
			startPos = 320;
			currLine = 0;
		}
	}

}

void Help :: loadText()
{
	textList.push_back( "SFCave" );
	textList.push_back( "Written By AndyQ" );
	textList.push_back( "" );
	textList.push_back( "Instructions" );
	textList.push_back( "To return to the menu" );
	textList.push_back( "press the space or " );
	textList.push_back( "middle button." );
	textList.push_back( "" );
	textList.push_back( "To speed up the text" );
	textList.push_back( "hold the down button" );
	textList.push_back( "(releasing will return" );
	textList.push_back( "to normal speed)" );
	textList.push_back( "" );
	textList.push_back( "" );
	textList.push_back( "SFCave is a flying game" );
	textList.push_back( "writtin originally for the" );
	textList.push_back( "Sharp Zaurus." );
	textList.push_back( "" );
	textList.push_back( "The aim is to stay alive" );
	textList.push_back( "for as long as possible," );
	textList.push_back( "and get the highest score" );
	textList.push_back( "you can." );
	textList.push_back( "" );
	textList.push_back( "There are currently three" );
	textList.push_back( "game types - SFCave," );
	textList.push_back( "Gates, and Fly." );
	textList.push_back( "" );
	textList.push_back( "SFCave is a remake of" );
	textList.push_back( "the classic SFCave game." );
	textList.push_back( "Fly through the cavern" );
	textList.push_back( "avoiding all the blocks" );
	textList.push_back( "that just happen to be" );
	textList.push_back( "hanging in mid-air" );
	textList.push_back( "" );
	textList.push_back( "Gates is similar to" );
	textList.push_back( "SFCave but instead of" );
	textList.push_back( "avoiding blocks you must" );
	textList.push_back( "fly through gates without" );
	textList.push_back( "crashing." );
	textList.push_back( "" );
	textList.push_back( "Fly is a different kettle of" );
	textList.push_back( "fish altogether. Instead," );
	textList.push_back( "you are flying in the " );
	textList.push_back( "open air above a" );
	textList.push_back( "scrolling landscape and" );
	textList.push_back( "the aim is to fly as close" );
	textList.push_back( "to the land as possible." );
	textList.push_back( "The closer to the land" );
	textList.push_back( "you fly the more points" );
	textList.push_back( "you score. But beware," );
	textList.push_back( "fly too high above the" );
	textList.push_back( "land and points get" );
	textList.push_back( "deducted." );
	textList.push_back( "" );
	textList.push_back( "How to play" );
	textList.push_back( "Press the space or middle" );
	textList.push_back( "button (Zaurus only) to " );
	textList.push_back( "apply thrust (makes you" );
	textList.push_back( "go up) and release it" );
	textList.push_back( "to go down." );
	textList.push_back( "" );
	textList.push_back( "Have fun" );
	textList.push_back( "AndyQ" );
}

// Test
#ifdef DEBUG_HELP
SDL_Surface *screen;
Help *help;

void go()
{
	FontHandler :: init();

	/* Initialize SDL */
	if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
	{
		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
		exit(1);
	}
	atexit(SDL_Quit);

	int videoflags = SDL_SWSURFACE ;

 	if ( (screen=SDL_SetVideoMode(240, 320,32,videoflags)) == NULL )
 	{
 		fprintf(stderr, "Couldn't set %ix%i video mode: %s\n",240,320,SDL_GetError());
 		exit(2);
 	}

	help = new Help();

	bool done = false;
	while ( !done )
	{
		SDL_FillRect( screen, 0, 0 );
		help->draw( screen );
		help->update( );

 		SDL_Flip( screen );

		SDL_Delay( 10 );

		SDL_Event event;
		while ( SDL_PollEvent(&event) )
		{
			switch (event.type)
			{
				case SDL_KEYDOWN:
					// Escape keypress quits the app
					if ( event.key.keysym.sym != SDLK_ESCAPE )
					{
						break;
					}
				case SDL_QUIT:
					done = 1;
					break;
				default:
					break;
			}
		}
 	}
 }




#ifdef __cplusplus
extern "C"
#endif
int main( int argc, char *argv[] )
{
	go();
}

#endif