summaryrefslogtreecommitdiff
path: root/noncore/games/sfcave-sdl/help.cpp
authorandyq <andyq>2003-01-20 23:11:56 (UTC)
committer andyq <andyq>2003-01-20 23:11:56 (UTC)
commit92419b025aa5d82bb7592281af5505ff931c2e58 (patch) (unidiff)
tree374ee9ca86ef716ce388c8a28e38261f6a04ce7a /noncore/games/sfcave-sdl/help.cpp
parent02090d2e63ad8398c0a8a9f1fb895a9c6e42514b (diff)
downloadopie-92419b025aa5d82bb7592281af5505ff931c2e58.zip
opie-92419b025aa5d82bb7592281af5505ff931c2e58.tar.gz
opie-92419b025aa5d82bb7592281af5505ff931c2e58.tar.bz2
Initial Revision
Diffstat (limited to 'noncore/games/sfcave-sdl/help.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/sfcave-sdl/help.cpp237
1 files changed, 237 insertions, 0 deletions
diff --git a/noncore/games/sfcave-sdl/help.cpp b/noncore/games/sfcave-sdl/help.cpp
new file mode 100644
index 0000000..91c62da
--- a/dev/null
+++ b/noncore/games/sfcave-sdl/help.cpp
@@ -0,0 +1,237 @@
1#include "SDL.h"
2#include "constants.h"
3
4#include "font.h"
5#include "help.h"
6#include "sfcave.h"
7#include "starfield.h"
8
9Help :: Help( SFCave *p )
10{
11 parent = p;
12 stars = new StarField( false, 200 );
13
14 loadText();
15
16 init();
17}
18
19Help :: ~Help()
20{
21 delete stars;
22}
23
24void Help :: handleKeys( SDL_KeyboardEvent &key )
25{
26 if ( key.type == SDL_KEYDOWN )
27 {
28 if ( key.keysym.sym == SDLK_SPACE )
29 parent->changeState( STATE_MENU );
30 else if ( key.keysym.sym == SDLK_DOWN )
31 textSpeed = 5;
32 else if ( key.keysym.sym == SDLK_UP )
33 {
34 if ( textSpeed > 0 )
35 textSpeed = 0;
36 else textSpeed = 1;
37 }
38
39 }
40 else if ( key.type == SDL_KEYUP )
41 {
42 if ( key.keysym.sym == SDLK_DOWN )
43 textSpeed = 1;
44 }
45}
46void Help :: init()
47{
48 startPos = 320;
49 currLine = 0;
50 textSpeed = 1;
51
52 // Create our coloured font
53 FontHandler :: changeColor( FONT_HELP_FONT, 0, 0, 255 );
54}
55
56void Help :: draw( SDL_Surface *screen )
57{
58 stars->draw( screen );
59
60
61 list<string>::iterator it = textList.begin();
62
63 // Move to start of text
64 for ( int i = 0 ; i < currLine && it != textList.end() ; ++i )
65 it++;
66
67 int pos = startPos;
68 while ( pos < 320 && it != textList.end() )
69 {
70 // get next line
71 string text = *it;
72
73 // draw text
74 FontHandler::draw( screen, FONT_COLOURED_TEXT, text.c_str(), -1, pos );
75 pos += FontHandler::FontHeight( FONT_COLOURED_TEXT );
76 it ++;
77 }
78
79}
80
81void Help :: update()
82{
83 stars->move();
84
85 startPos -= textSpeed;
86 if ( startPos <= -FontHandler::FontHeight( FONT_COLOURED_TEXT ) )
87 {
88 startPos = 0;
89 currLine ++;
90
91 if ( currLine > textList.size() )
92 {
93 startPos = 320;
94 currLine = 0;
95 }
96 }
97
98}
99
100void Help :: loadText()
101{
102 textList.push_back( "SFCave" );
103 textList.push_back( "Written By AndyQ" );
104 textList.push_back( "" );
105 textList.push_back( "Instructions" );
106 textList.push_back( "To return to the menu" );
107 textList.push_back( "press the space or " );
108 textList.push_back( "middle button." );
109 textList.push_back( "" );
110 textList.push_back( "To speed up the text" );
111 textList.push_back( "hold the down button" );
112 textList.push_back( "(releasing will return" );
113 textList.push_back( "to normal speed)" );
114 textList.push_back( "" );
115 textList.push_back( "" );
116 textList.push_back( "SFCave is a flying game" );
117 textList.push_back( "writtin originally for the" );
118 textList.push_back( "Sharp Zaurus." );
119 textList.push_back( "" );
120 textList.push_back( "The aim is to stay alive" );
121 textList.push_back( "for as long as possible," );
122 textList.push_back( "and get the highest score" );
123 textList.push_back( "you can." );
124 textList.push_back( "" );
125 textList.push_back( "There are currently three" );
126 textList.push_back( "game types - SFCave," );
127 textList.push_back( "Gates, and Fly." );
128 textList.push_back( "" );
129 textList.push_back( "SFCave is a remake of" );
130 textList.push_back( "the classic SFCave game." );
131 textList.push_back( "Fly through the cavern" );
132 textList.push_back( "avoiding all the blocks" );
133 textList.push_back( "that just happen to be" );
134 textList.push_back( "hanging in mid-air" );
135 textList.push_back( "" );
136 textList.push_back( "Gates is similar to" );
137 textList.push_back( "SFCave but instead of" );
138 textList.push_back( "avoiding blocks you must" );
139 textList.push_back( "fly through gates without" );
140 textList.push_back( "crashing." );
141 textList.push_back( "" );
142 textList.push_back( "Fly is a different kettle of" );
143 textList.push_back( "fish altogether. Instead," );
144 textList.push_back( "you are flying in the " );
145 textList.push_back( "open air above a" );
146 textList.push_back( "scrolling landscape and" );
147 textList.push_back( "the aim is to fly as close" );
148 textList.push_back( "to the land as possible." );
149 textList.push_back( "The closer to the land" );
150 textList.push_back( "you fly the more points" );
151 textList.push_back( "you score. But beware," );
152 textList.push_back( "fly too high above the" );
153 textList.push_back( "land and points get" );
154 textList.push_back( "deducted." );
155 textList.push_back( "" );
156 textList.push_back( "How to play" );
157 textList.push_back( "Press the space or middle" );
158 textList.push_back( "button (Zaurus only) to " );
159 textList.push_back( "apply thrust (makes you" );
160 textList.push_back( "go up) and release it" );
161 textList.push_back( "to go down." );
162 textList.push_back( "" );
163 textList.push_back( "Have fun" );
164 textList.push_back( "AndyQ" );
165}
166
167// Test
168#ifdef DEBUG_HELP
169SDL_Surface *screen;
170Help *help;
171
172void go()
173{
174 FontHandler :: init();
175
176 /* Initialize SDL */
177 if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
178 {
179 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
180 exit(1);
181 }
182 atexit(SDL_Quit);
183
184 int videoflags = SDL_SWSURFACE ;
185
186 if ( (screen=SDL_SetVideoMode(240, 320,32,videoflags)) == NULL )
187 {
188 fprintf(stderr, "Couldn't set %ix%i video mode: %s\n",240,320,SDL_GetError());
189 exit(2);
190 }
191
192 help = new Help();
193
194 bool done = false;
195 while ( !done )
196 {
197 SDL_FillRect( screen, 0, 0 );
198 help->draw( screen );
199 help->update( );
200
201 SDL_Flip( screen );
202
203 SDL_Delay( 10 );
204
205 SDL_Event event;
206 while ( SDL_PollEvent(&event) )
207 {
208 switch (event.type)
209 {
210 case SDL_KEYDOWN:
211 // Escape keypress quits the app
212 if ( event.key.keysym.sym != SDLK_ESCAPE )
213 {
214 break;
215 }
216 case SDL_QUIT:
217 done = 1;
218 break;
219 default:
220 break;
221 }
222 }
223 }
224 }
225
226
227
228
229#ifdef __cplusplus
230extern "C"
231#endif
232int main( int argc, char *argv[] )
233{
234 go();
235}
236
237#endif