[Tux4kids-commits] r185 - in tuxtype/trunk: . tuxtype
dbruce-guest at alioth.debian.org
dbruce-guest at alioth.debian.org
Thu Jun 7 18:54:49 UTC 2007
Author: dbruce-guest
Date: 2007-06-07 18:54:49 +0000 (Thu, 07 Jun 2007)
New Revision: 185
Modified:
tuxtype/trunk/ChangeLog
tuxtype/trunk/tuxtype/alphabet.c
tuxtype/trunk/tuxtype/audio.c
tuxtype/trunk/tuxtype/funcs.h
tuxtype/trunk/tuxtype/gettext.c
tuxtype/trunk/tuxtype/globals.h
tuxtype/trunk/tuxtype/laser.c
tuxtype/trunk/tuxtype/loaders.c
tuxtype/trunk/tuxtype/main.c
tuxtype/trunk/tuxtype/pause.c
tuxtype/trunk/tuxtype/playgame.c
tuxtype/trunk/tuxtype/practice.c
tuxtype/trunk/tuxtype/scripting.c
tuxtype/trunk/tuxtype/setup.c
tuxtype/trunk/tuxtype/theme.c
tuxtype/trunk/tuxtype/titlescreen.c
Log:
code cleanup - most importantly, function prototypes now provided for all functions.
Modified: tuxtype/trunk/ChangeLog
===================================================================
--- tuxtype/trunk/ChangeLog 2007-05-29 21:53:02 UTC (rev 184)
+++ tuxtype/trunk/ChangeLog 2007-06-07 18:54:49 UTC (rev 185)
@@ -1,3 +1,17 @@
+07 Jun 2007
+[ David Bruce]
+ - Code cleanup - funcs.h revised, unneeded "extern" keywords for
+ function prototypes removed, prototypes rearranged into alpha-
+ betical order
+ - All functions now have function prototypes, either in funcs.h or
+ local function prototypes with explicit static scope.
+ - const keyword added to pointer function args when appropriate,
+ usually char* args.
+ - Renaming of some functions and variables to make capitalization
+ more internally consistent (e.g. ALLCAPS means constant or other
+ preprocessor macro, CamelCase means globally visible, while
+ local_functions() use lowercase connected by underscores).
+
29 May 2007
[ David Bruce]
- Fixed vertical alignment problem with certain non-US characters
Modified: tuxtype/trunk/tuxtype/alphabet.c
===================================================================
--- tuxtype/trunk/tuxtype/alphabet.c 2007-05-29 21:53:02 UTC (rev 184)
+++ tuxtype/trunk/tuxtype/alphabet.c 2007-06-07 18:54:49 UTC (rev 185)
@@ -30,45 +30,29 @@
/* Used for word list functions (see below): */
static int WORD_qty;
-wchar_t WORDS[MAX_NUM_WORDS][MAX_WORD_SIZE + 1];
-wchar_t unicode_chars_used[MAX_UNICODES]; // List of distinct letters in list
+wchar_t word_list[MAX_NUM_WORDS][MAX_WORD_SIZE + 1];
+wchar_t char_list[MAX_UNICODES]; // List of distinct letters in list
static int num_chars_used = 0; // Number of different letters in word list
/* These are the arrays for the red and white letters: */
uni_glyph char_glyphs[MAX_UNICODES];
/* Local function prototypes: */
-void WORDS_scan_chars(void);
-int add_unicode(wchar_t uc);
-void print_keymap(void);
+static void gen_char_list(void);
+static int add_char(wchar_t uc);
+static void print_keymap(void);
+static void set_letters(unsigned char* t);
+static void show_letters(void);
+static void clear_keyboard(void);
-/* --- setup the alphabet --- */
-void set_letters(unsigned char *t) {
- int i;
+/*****************************************************/
+/* */
+/* "Public" Functions */
+/* */
+/*****************************************************/
- ALPHABET_SIZE = 0;
- for (i=0; i<256; i++)
- ALPHABET[i]=0;
- for (i=0; i<strlen(t); i++)
- if (t[i]!=' ') {
- ALPHABET[(int)t[i]]=1;
- ALPHABET_SIZE++;
- }
-}
-void clear_keyboard( void ) {
- int i,j;
-
- ALPHABET_SIZE = 0;
- for (i=0; i<256; i++) {
- ALPHABET[i]=0;
- for (j=0; j<10; j++)
- FINGER[i][j]=0;
- KEYMAP[i]=i;
- }
-}
-
void LoadKeyboard( void ) {
unsigned char fn[FNLEN];
int l;
@@ -135,7 +119,9 @@
fprintf( stderr, "Error finding file for keyboard setup!\n" );
}
-SDL_Surface* black_outline(unsigned char *t, TTF_Font *font, SDL_Color *c) {
+
+SDL_Surface* BlackOutline(const unsigned char *t, TTF_Font *font, const SDL_Color *c)
+{
SDL_Surface* out = NULL;
SDL_Surface* black_letters = NULL;
SDL_Surface* white_letters = NULL;
@@ -145,7 +131,7 @@
if (!t || !font || !c)
{
- fprintf(stderr, "black_outline(): invalid ptr parameter, returning.");
+ fprintf(stderr, "BlackOutline(): invalid ptr parameter, returning.");
return NULL;
}
@@ -153,7 +139,7 @@
if (!black_letters)
{
- fprintf (stderr, "Warning - black_outline() could not create image for %s\n", t);
+ fprintf (stderr, "Warning - BlackOutline() could not create image for %s\n", t);
return NULL;
}
@@ -196,7 +182,8 @@
/* This version takes a single wide character and renders it with the */
/* Unicode glyph versions of the SDL_ttf functions: */
-SDL_Surface* black_outline_wchar(wchar_t t, TTF_Font *font, SDL_Color *c) {
+SDL_Surface* BlackOutline_wchar(wchar_t t, TTF_Font *font, const SDL_Color *c)
+{
SDL_Surface* out = NULL;
SDL_Surface* black_letters = NULL;
SDL_Surface* white_letters = NULL;
@@ -206,7 +193,7 @@
if (!font || !c)
{
- fprintf(stderr, "black_outline_wchar(): invalid ptr parameter, returning.");
+ fprintf(stderr, "BlackOutline_wchar(): invalid ptr parameter, returning.");
return NULL;
}
@@ -214,7 +201,7 @@
if (!black_letters)
{
- fprintf (stderr, "Warning - black_outline_wchar() could not create image for %lc\n", t);
+ fprintf (stderr, "Warning - BlackOutline_wchar() could not create image for %lc\n", t);
return NULL;
}
@@ -255,10 +242,11 @@
}
-
-void show_letters( void ) {
- int i, l=0;
- SDL_Surface *abit;
+/* FIXME dead code but could be useful*/
+static void show_letters(void)
+{
+ int i, l = 0;
+ SDL_Surface* abit;
SDL_Rect dst;
int stop = 0;
unsigned char t[255];
@@ -269,7 +257,7 @@
t[l] = 0;
- abit = black_outline(t, font, &white);
+ abit = BlackOutline(t, font, &white);
dst.x = 320 - (abit->w / 2);
dst.y = 275;
@@ -280,7 +268,7 @@
SDL_FreeSurface(abit);
- abit = black_outline("Alphabet Set To:", font, &white);
+ abit = BlackOutline("Alphabet Set To:", font, &white);
dst.x = 320 - (abit->w / 2);
dst.y = 200;
dst.w = abit->w;
@@ -303,9 +291,12 @@
SDL_FreeSurface(abit);
}
+
+/* FIXME won't handle Unicode chars beyond 255
/* --- get a letter --- */
-unsigned char get_letter(void) {
- static int last = -1; // we don't want to return same letter twice in a row
+wchar_t GetLetter(void)
+{
+ static int last = -1; // we don't want to return same letter twice in a row
int letter;
do {
letter = rand() % 255;
@@ -322,57 +313,64 @@
-/* WORDS_init: clears the number of words
+/* ClearWordList: clears the number of words
*/
-void WORDS_init( void ) {
- WORD_qty = 0;
+void ClearWordList(void)
+{
+ int i;
+ for (i = 0; i < WORD_qty; i++)
+ {
+ word_list[i][0] = '\0';
+ }
+ WORD_qty = 0;
}
-/* WORDS_use_alphabet: setups the WORDS so that it really
- * returns a LETTER when WORDS_get() is called
+/* UseAlphabet(): setups the word_list so that it really
+ * returns a LETTER when GetWord() is called
*/
-void WORDS_use_alphabet( void ) {
+void UseAlphabet(void)
+{
int i;
- LOG("Entering WORDS_use_alphabet()\n");
+ LOG("Entering UseAlphabet()\n");
WORD_qty = 0;
/* This totally mucks up i18n abilities :( */
for (i=65; i<90; i++)
{
if (ALPHABET[i]) {
- WORDS[WORD_qty][0] = (unsigned char)i;
- WORDS[WORD_qty][1] = '\0';
+ word_list[WORD_qty][0] = (unsigned char)i;
+ word_list[WORD_qty][1] = '\0';
WORD_qty++;
DEBUGCODE { fprintf(stderr, "Adding %c\n", (unsigned char)i); }
}
}
/* Make sure list is terminated with null character */
- WORDS[WORD_qty][0] = '\0';
+ word_list[WORD_qty][0] = '\0';
/* Make list of all unicode characters used in word list: */
- WORDS_scan_chars();
+ gen_char_list();
DOUT(WORD_qty);
- LOG("Leaving WORDS_use_alphabet()\n");
+ LOG("Leaving UseAlphabet()\n");
}
-/* WORDS_get: returns a random word that wasn't returned
+/* GetWord: returns a random word that wasn't returned
* the previous time (unless there is only 1 word!!!)
*/
-wchar_t* WORDS_get( void )
+wchar_t* GetWord(void)
{
static int last_choice = -1;
int choice;
- LOG("Entering WORDS_get()\n");
+ LOG("Entering GetWord()\n");
DEBUGCODE { fprintf(stderr, "WORD_qty is: %d\n", WORD_qty); }
/* Now count list to make sure WORD_qty is correct: */
WORD_qty = 0;
- while (WORDS[WORD_qty][0] != '\0')
+ while (word_list[WORD_qty][0] != '\0')
{
WORD_qty++;
}
@@ -404,19 +402,19 @@
last_choice = choice;
/* NOTE need %S rather than %s because of wide characters */
- DEBUGCODE { fprintf(stderr, "Selected word is: %S\n", WORDS[choice]); }
+ DEBUGCODE { fprintf(stderr, "Selected word is: %S\n", word_list[choice]); }
- return WORDS[choice];
+ return word_list[choice];
}
-/* WORDS_use: adds the words from a given wordlist
+/* GenerateWordList(): adds the words from a given wordlist
* it ignores any words too long or that has bad
* character (such as #)
*/
-void WORDS_use(char *wordFn)
+void GenerateWordList(const char* wordFn)
{
int j;
unsigned char temp_word[FNLEN];
@@ -424,7 +422,7 @@
FILE* wordFile=NULL;
- DEBUGCODE { fprintf(stderr, "Entering WORDS_use() for file: %s\n", wordFn); }
+ DEBUGCODE { fprintf(stderr, "Entering GenerateWordList() for file: %s\n", wordFn); }
WORD_qty = 0;
@@ -436,7 +434,7 @@
{
fprintf(stderr, "ERROR: could not load wordlist: %s\n", wordFn );
fprintf(stderr, "Using ALPHABET instead\n");
- WORDS_use_alphabet( );
+ UseAlphabet( );
return;
}
@@ -481,24 +479,24 @@
/* If we make it to here, OK to add word: */
/* NOTE we have to add one to the length argument to get */
/* mbstowcs() to reliably include the terminating null. */
- mbstowcs(WORDS[WORD_qty], temp_word, strlen(temp_word) + 1);
+ mbstowcs(word_list[WORD_qty], temp_word, strlen(temp_word) + 1);
WORD_qty++;
}
/* Make sure list is terminated with null character */
- WORDS[WORD_qty][0] = '\0';
+ word_list[WORD_qty][0] = '\0';
DOUT(WORD_qty);
if (WORD_qty == 0)
- WORDS_use_alphabet( );
+ UseAlphabet( );
fclose(wordFile);
/* Make list of all unicode characters used in word list: */
- WORDS_scan_chars();
+ gen_char_list();
- LOG("Leaving WORDS_use()\n");
+ LOG("Leaving GenerateWordList()\n");
}
@@ -509,7 +507,7 @@
/* Now that the words are stored internally as wchars, we use the */
/* Unicode glyph version of black_outline(): */
-int RenderLetters(TTF_Font* letter_font)
+int RenderLetters(const TTF_Font* letter_font)
{
wchar_t t;
int i;
@@ -523,9 +521,9 @@
/* The following will supercede the old code: */
i = num_chars_used = 0;
- while (unicode_chars_used[i] != '\0')
+ while (char_list[i] != '\0')
{
- t = unicode_chars_used[i];
+ t = char_list[i];
if(TTF_GlyphMetrics(font, t, NULL , NULL, NULL,
&maxy, NULL) == -1)
@@ -541,8 +539,8 @@
}
char_glyphs[i].unicode_value = t;
- char_glyphs[i].white_glyph = black_outline_wchar(t, font, &white);
- char_glyphs[i].red_glyph = black_outline_wchar(t, font, &red);
+ char_glyphs[i].white_glyph = BlackOutline_wchar(t, font, &white);
+ char_glyphs[i].red_glyph = BlackOutline_wchar(t, font, &red);
char_glyphs[i].max_y = maxy;
i++;
@@ -613,10 +611,10 @@
/* Since SDL drawing just uses the upper left corner, but text needs to be drawn relative to */
/* the glyph origin (i.e. the lower left corner for a character that doesn't go below */
/* the baseline), we need to convert them - basically just subtracting the max_y, which is */
-/* the glyph's height above the baseline. So - 'x' and 'y' before the function should be */
-/* the coords where the *origin* is supposed to be, and after the function they will contain */
-/* the coords where the upper left of this particular glyph needs to be to put the origin */
-/* in the right place. OK? */
+/* the glyph's height above the baseline. */
+/* So - 'x' and 'y' before the function should be the coords where the *origin* is supposed */
+/* to be, and after the function they will contain the correct coords for blitting of the */
+/* glypg. OK? */
int GetGlyphCoords(wchar_t t, int* x, int* y)
{
int i;
@@ -630,7 +628,7 @@
{
/* Didn't find character: */
fprintf(stderr, "Could not find glyph for unicode character %lc\n", t);
- return 1;
+ return 0;
}
/* Set "upper left" coordinates for blitting (currently, don't need to */
@@ -647,21 +645,21 @@
/* Creates a list of distinct Unicode characters in */
-/* the WORDS[][] list (so the program knows what */
+/* word_list[][] (so the program knows what */
/* needs to be rendered for the games) */
-void WORDS_scan_chars(void)
+static void gen_char_list(void)
{
int i, j;
i = j = 0;
- unicode_chars_used[0] = '\0';
+ char_list[0] = '\0';
- while (WORDS[i][0] != '\0' && i < MAX_NUM_WORDS)
+ while (word_list[i][0] != '\0' && i < MAX_NUM_WORDS)
{
j = 0;
- while (WORDS[i][j]!= '\0' && j < MAX_WORD_SIZE)
+ while (word_list[i][j]!= '\0' && j < MAX_WORD_SIZE)
{
- add_unicode(WORDS[i][j]);
+ add_char(word_list[i][j]);
j++;
}
@@ -670,27 +668,66 @@
DEBUGCODE
{
- fprintf(stderr, "unicode_chars_used = %S\n", unicode_chars_used);
+ fprintf(stderr, "char_list = %S\n", char_list);
}
}
+
+/* FIXME this function is currently dead code */
+/* --- setup the alphabet --- */
+static void set_letters(unsigned char *t) {
+ int i;
+
+ ALPHABET_SIZE = 0;
+ for (i=0; i<256; i++)
+ ALPHABET[i]=0;
+
+ for (i=0; i<strlen(t); i++)
+ if (t[i]!=' ') {
+ ALPHABET[(int)t[i]]=1;
+ ALPHABET_SIZE++;
+ }
+}
+
+
+/* For debugging purposes: */
+static void print_keymap(void)
+{
+ int i;
+
+ for(i = 0; i < 256; i++)
+ {
+ fprintf(stderr, "i = %d\t(int)KEYMAP[i] = %d\tKEYMAP[i] = %lc\t",
+ i, KEYMAP[i], KEYMAP[i]);
+ if(isupper(i) && !islower(i))
+ fprintf(stderr, "Upper\n");
+ if(!isupper(i) && islower(i))
+ fprintf(stderr, "Lower\n");
+ if(isupper(i) && islower(i))
+ fprintf(stderr, "Both\n");
+ if(!isupper(i) && !islower(i))
+ fprintf(stderr, "Neither\n");
+ }
+}
+
+
/* Checks to see if the argument is already in the list and adds */
/* it if necessary. Returns 1 if char added, 0 if already in list, */
/* -1 if list already up to maximum size: */
-int add_unicode(wchar_t uc)
+static int add_char(wchar_t uc)
{
int i = 0;
- while ((unicode_chars_used[i] != uc)
- && (unicode_chars_used[i] != '\0')
+ while ((char_list[i] != uc)
+ && (char_list[i] != '\0')
&& (i < MAX_UNICODES - 1)) //Because 1 need for null terminator
{
i++;
}
/* unicode already in list: */
- if (unicode_chars_used[i] == uc)
+ if (char_list[i] == uc)
{
DEBUGCODE{ fprintf(stderr,
"Unicode value: %d\tcharacter %lc already in list\n",
@@ -698,11 +735,11 @@
return 0;
}
- if (unicode_chars_used[i] == '\0')
+ if (char_list[i] == '\0')
{
DEBUGCODE{ fprintf(stderr, "Adding unicode value: %d\tcharacter %lc\n", uc, uc);}
- unicode_chars_used[i] = uc;
- unicode_chars_used[i + 1] = '\0';
+ char_list[i] = uc;
+ char_list[i + 1] = '\0';
return 1;
}
@@ -713,14 +750,15 @@
}
}
-/* For debugging purposes: */
-void print_keymap(void)
-{
- int i;
- for(i = 0; i < 256; i++)
- {
- fprintf(stderr, "i = %d\t(int)KEYMAP[i] = %d\tKEYMAP[i] = %lc\n",
- i, KEYMAP[i], KEYMAP[i]);
- }
+static void clear_keyboard( void ) {
+ int i,j;
+
+ ALPHABET_SIZE = 0;
+ for (i=0; i<256; i++) {
+ ALPHABET[i]=0;
+ for (j=0; j<10; j++)
+ FINGER[i][j]=0;
+ KEYMAP[i]=i;
+ }
}
Modified: tuxtype/trunk/tuxtype/audio.c
===================================================================
--- tuxtype/trunk/tuxtype/audio.c 2007-05-29 21:53:02 UTC (rev 184)
+++ tuxtype/trunk/tuxtype/audio.c 2007-06-07 18:54:49 UTC (rev 185)
@@ -18,40 +18,40 @@
#include "globals.h"
#include "funcs.h"
+/* NOTE these two don't really belong here - not used in this file */
+Mix_Chunk* sound[NUM_WAVES];
+Mix_Music* music;
-Mix_Chunk *sound[NUM_WAVES];
-Mix_Music *music;
+Mix_Music* defaultMusic = NULL; // holds music for audioMusicLoad/unload
-void playsound(Mix_Chunk *snd) {
+void PlaySound(Mix_Chunk* snd) {
if (!sys_sound) return;
Mix_PlayChannel(-1, snd, 0);
}
-Mix_Music *defaultMusic = NULL; // holds music for audioMusicLoad/unload
-
-/* audioMusicLoad attempts to load and play the music file
+/* MusicLoad attempts to load and play the music file
* Note: loops == -1 means forever
*/
-void audioMusicLoad( char *musicFilename, int loops ) {
+void MusicLoad(const char *musicFilename, int loops ) {
if (!sys_sound) return;
- audioMusicUnload(); // make sure defaultMusic is clear
+ MusicUnload(); // make sure defaultMusic is clear
defaultMusic = LoadMusic( musicFilename );
Mix_PlayMusic( defaultMusic, loops );
}
-/* audioMusicUnload attempts to unload any music data that was
+/* MusicUnload attempts to unload any music data that was
* loaded using the audioMusicLoad function
*/
-void audioMusicUnload( void ) {
+void MusicUnload( void ) {
if (!sys_sound) return;
if ( defaultMusic )
Mix_FreeMusic( defaultMusic );
- defaultMusic=NULL;
+ defaultMusic = NULL;
}
/* audioMusicPlay attempts to play the passed music data.
@@ -59,9 +59,10 @@
* it will be stopped and unloaded
* Note: loops == -1 means forever
*/
-void audioMusicPlay( Mix_Music *musicData, int loops ) {
- if (!sys_sound) return;
-
- audioMusicUnload();
- Mix_PlayMusic( musicData, loops );
+void MusicPlay(Mix_Music* musicData, int loops)
+{
+ if (!sys_sound) return;
+ /* Stop previous music before playing new one: */
+ MusicUnload();
+ Mix_PlayMusic(musicData, loops);
}
Modified: tuxtype/trunk/tuxtype/funcs.h
===================================================================
--- tuxtype/trunk/tuxtype/funcs.h 2007-05-29 21:53:02 UTC (rev 184)
+++ tuxtype/trunk/tuxtype/funcs.h 2007-06-07 18:54:49 UTC (rev 185)
@@ -16,95 +16,92 @@
* *
***************************************************************************/
+/* NOTE - there is no reason to declare functions using "extern", as all */
+/* non-local functions are visible throughout the program. */
-extern int max( int n1, int n2 );
+/* In alphabet.c */
+SDL_Surface* BlackOutline(const unsigned char *t, TTF_Font* font, const SDL_Color* c);
+SDL_Surface* BlackOutline_wchar(wchar_t t, TTF_Font* font, const SDL_Color* c);
+void ClearWordList(void);
+void FreeLetters(void);
+void GenerateWordList(const char* wordFn);
+wchar_t GetLetter(void);
+wchar_t* GetWord(void);
+SDL_Surface* GetWhiteGlyph(wchar_t t);
+SDL_Surface* GetRedGlyph(wchar_t t);
+int GetGlyphCoords(wchar_t t, int* x, int* y);
+void LoadKeyboard(void);
+int RenderLetters(const TTF_Font* letter_font);
+void UseAlphabet(void);
-extern void WaitFrame( void );
-extern void FreeGraphics( void );
-extern void InstructCascade( void );
-extern void InstructLaser( void );
-extern int PlayCascade( int level );
-extern int laser_game( int DIF_LEVEL );
-extern void AddRect(SDL_Rect * src, SDL_Rect * dst);
+/* In audio.c: */
+void PlaySound(Mix_Chunk* snd);
+void MusicLoad(const char* musicFilename, int repeatQty);
+void MusicUnload(void);
+void MusicPlay(Mix_Music* musicData, int repeatQty);
-/* in scripting.c */
-extern void testLesson( void );
-extern void projectInfo( void );
-extern void closeScript( void );
-extern int loadScript( const char *fn );
-/* in audio.c */
-extern void playsound( Mix_Chunk *snd );
-extern void audioMusicLoad( char *musicFilename, int repeatQty );
-extern void audioMusicUnload( void );
-extern void audioMusicPlay( Mix_Music *musicData, int repeatQty );
+/* In gettext.c: */
+unsigned char* gettext(const unsigned char* in);
+int Load_PO_File(const char* file);
-/* in theme.c */
-extern void chooseTheme(void);
-extern void setupTheme( char *dirname );
-/* in gettext.c */
-extern unsigned char *gettext( unsigned char *in );
-extern int load_trans(char* file);
+/* In laser.c: */
+int PlayLaserGame(int diff_level);
-/* in pause.c */
-extern int Pause( void );
-extern void pause_load_media( void );
-extern void pause_unload_media( void );
-extern int inRect( SDL_Rect r, int x, int y);
-/* in loaders.c */
-extern int CheckFile(const char *file);
-extern TTF_Font *LoadFont( char *fontfile, int fontsize );
-extern void LoadLang( void );
-extern Mix_Chunk *LoadSound( char *datafile );
-extern SDL_Surface *LoadImage( char *datafile, int mode );
-extern sprite *LoadSprite( char *name, int MODE );
-extern sprite *FlipSprite( sprite *in, int X, int Y );
-extern void FreeSprite( sprite *gfx );
-extern Mix_Music *LoadMusic( char *datafile );
-extern SDL_Surface *flip( SDL_Surface *in, int x, int y );
+/* In loaders.c: */
+int CheckFile(const char* file);
+sprite* FlipSprite(sprite* in, int X, int Y);
+void FreeSprite(sprite* gfx);
+TTF_Font* LoadFont(const char* fontfile, int fontsize);
+SDL_Surface* LoadImage(const char* datafile, int mode);
+void LoadLang(void);
+Mix_Music* LoadMusic(const char* datafile);
+Mix_Chunk* LoadSound(const char* datafile);
+sprite* LoadSprite(const char* name, int MODE);
-/* in setup.c */
-extern void GraphicsInit( Uint32 video_flags );
-extern void LibInit( Uint32 lib_flags );
-extern void LoadSettings( void );
-extern void SaveSettings( void );
+/* In pause.c: */
+int Pause(void);
+void PauseLoadMedia(void);
+void PauseUnloadMedia(void);
+int inRect(SDL_Rect r, int x, int y);
-extern void InitEngine( void ); /* NOT in setup.c */
-/* in alphabet.c */
-extern void LoadKeyboard( void );
-extern void set_letters( unsigned char *t );
-extern unsigned char get_letter( void );
-extern void custom_letter_setup( void );
-extern void show_letters( void );
-extern SDL_Surface* black_outline( unsigned char *t, TTF_Font* font, SDL_Color* c );
-extern SDL_Surface* black_outline_wchar(wchar_t t, TTF_Font* font, SDL_Color* c);
-extern SDL_Surface* GetWhiteGlyph(wchar_t t);
-extern SDL_Surface* GetRedGlyph(wchar_t t);
-extern int GetGlyphCoords(wchar_t t, int* x, int* y);
-extern int RenderLetters(TTF_Font* letter_font);
-extern void FreeLetters(void);
-/* WORD FUNCTIONS (also in alphabet.c) */
-extern void WORDS_init( void );
-extern void WORDS_use_alphabet( void );
-extern void WORDS_use( char *wordFn );
-extern wchar_t* WORDS_get(void);
+/* In playgame.c: */
+int PlayCascade(int level);
+void InitEngine(void);
+void TransWipe(SDL_Surface* newbkg, int type, int var1, int var2);
-/* in practice.c */
-extern int Practice( void );
-extern void print_phrase( char *pphrase, int wrap );
-/* in titlescreen.c */
-extern void TitleScreen( void );
-extern void switch_screen_mode( void );
-extern int Phrases(char *practice_phrase);
-extern int chooseWordlist( void );
+/* In practice.c: */
+int Practice( void );
+int Phrases(char* practice_phrase);
-/* In playgame.c: */
-extern int int_rand( int min, int max );
-extern void TransWipe(SDL_Surface * newbkg, int type, int var1, int var2);
+
+/* In scripting.c: */
+void TestLesson(void);
+void ProjectInfo(void);
+void InstructCascade(void);
+void InstructLaser(void);
+
+
+/* In setup.c: */
+void GraphicsInit(Uint32 video_flags);
+void LibInit(Uint32 lib_flags);
+void LoadSettings(void);
+void SaveSettings(void);
+
+
+/* In theme.c: */
+void ChooseTheme(void);
+void SetupTheme(const char *dirname);
+
+
+/* In titlescreen.c: */
+void SwitchScreenMode(void);
+void TitleScreen(void);
+
Modified: tuxtype/trunk/tuxtype/gettext.c
===================================================================
--- tuxtype/trunk/tuxtype/gettext.c 2007-05-29 21:53:02 UTC (rev 184)
+++ tuxtype/trunk/tuxtype/gettext.c 2007-06-07 18:54:49 UTC (rev 185)
@@ -23,7 +23,7 @@
* we don't expect too large of a list (famous last words!)
*/
-/* FIXME not sure if this file's code is UTF-8 compatible DSB */
+/* FIXME don't think this file's code is UTF-8/Unicode compatible DSB */
struct node {
unsigned char *in; // the english
@@ -35,6 +35,9 @@
item *HEAD=NULL;
+/* Local function prototypes: */
+void add_word(unsigned char* in, unsigned char* out);
+
/* --- add a word to the linked list --- */
void add_word(unsigned char *in, unsigned char *out) {
@@ -53,7 +56,7 @@
HEAD = cur;
}
-int load_trans(char *file) {
+int Load_PO_File(const char* file) {
/* this function will load the passed file (a .po file)
* if need be, it should erase any previously loaded
* translations.
@@ -159,7 +162,7 @@
return 0;
}
-unsigned char * gettext( unsigned char *in ) {
+unsigned char* gettext(const unsigned char* in ) {
/* this function will attempt to translate the string
* "in" to an "translation of in" if one exists.
* if it doesn't exist in the translation set, it
@@ -171,10 +174,12 @@
* we should move to a hash table.
*/
- item *cur=HEAD;
+ item* cur = HEAD;
if (useEnglish)
- return in;
+ // the cast is to keep the compiler from complaining
+ // about "discarded qualifiers"
+ return (unsigned char*)in;
while (cur != NULL)
if (strcmp(cur->in, in) == 0)
@@ -183,5 +188,5 @@
cur = cur->next;
/* if we didn't find anything return what we were asked */
- return in;
+ return (unsigned char*)in;
}
Modified: tuxtype/trunk/tuxtype/globals.h
===================================================================
--- tuxtype/trunk/tuxtype/globals.h 2007-05-29 21:53:02 UTC (rev 184)
+++ tuxtype/trunk/tuxtype/globals.h 2007-06-07 18:54:49 UTC (rev 185)
@@ -171,7 +171,6 @@
extern wchar_t KEYMAP[256];
extern unsigned char FINGER[256][10];
extern int ALPHABET_SIZE;
-extern wchar_t unicode_chars_used[MAX_UNICODES];
//global vars
extern int speed_up;
Modified: tuxtype/trunk/tuxtype/laser.c
===================================================================
--- tuxtype/trunk/tuxtype/laser.c 2007-05-29 21:53:02 UTC (rev 184)
+++ tuxtype/trunk/tuxtype/laser.c 2007-06-07 18:54:49 UTC (rev 185)
@@ -27,57 +27,8 @@
Mix_Music* musics[NUM_MUSICS];
SDL_Surface* bkgd;
-/* --- unload all media --- */
-void laser_unload_data(void) {
- int i;
- FreeLetters();
- for (i = 0; i < NUM_IMAGES; i++)
- SDL_FreeSurface(images[i]);
-
- if (sys_sound) {
- for (i = 0; i < NUM_SOUNDS; i++)
- Mix_FreeChunk(sounds[i]);
- for (i = 0; i < NUM_MUSICS; i++)
- Mix_FreeMusic(musics[i]);
- }
-
- FreeSprite(shield);
-
- pause_unload_media();
-
-
- TTF_CloseFont(font);
-}
-
-/* --- Load all media --- */
-void laser_load_data(void)
-{
- int i;
-
- /* Create the SDL_Surfaces for all of the characters */
- /* used in the word list: */
- font = LoadFont( ttf_font, 32);
- RenderLetters(font);
-
- /* Load images: */
- for (i = 0; i < NUM_IMAGES; i++)
- images[i] = LoadImage(image_filenames[i], IMG_ALPHA);
- shield = LoadSprite( "cities/shield", IMG_ALPHA );
-
- if (sys_sound) {
- for (i = 0; i < NUM_SOUNDS; i++)
- sounds[i] = LoadSound(sound_filenames[i]);
-
- for (i = 0; i < NUM_MUSICS; i++)
- musics[i] = LoadMusic(music_filenames[i]);
- }
-
- pause_load_media();
-}
-
-
#define FPS (1000 / 15) /* 15 fps max */
#define CITY_EXPL_START 3 * 5 /* Must be mult. of 5 (number of expl frames) */
#define COMET_EXPL_START 2 * 2 /* Must be mult. of 2 (number of expl frames) */
@@ -98,19 +49,20 @@
laser_type laser;
/* Local function prototypes: */
-
-void laser_reset_level(int DIF_LEVEL);
-void laser_add_comet(int DIF_LEVEL);
-void laser_draw_numbers(unsigned char * str, int x);
-void laser_draw_line(int x1, int y1, int x2, int y2, int r, int g, int b);
-void laser_putpixel(SDL_Surface * surface, int x, int y, Uint32 pixel);
+void laser_add_comet(int diff_level);
+void laser_add_score(int inc);
void laser_draw_console_image(int i);
void laser_draw_let(wchar_t c, int x, int y);
-void laser_add_score(int inc);
+void laser_draw_line(int x1, int y1, int x2, int y2, int r, int g, int b);
+void laser_draw_numbers(const unsigned char* str, int x);
+void laser_load_data(void);
+void laser_reset_level(int diff_level);
+void laser_putpixel(SDL_Surface* surface, int x, int y, Uint32 pixel);
+void laser_unload_data(void);
/* --- MAIN GAME FUNCTION!!! --- */
-int laser_game(int DIF_LEVEL)
+int PlayLaserGame(int diff_level)
{
int i, img, done, quit, frame, lowest, lowest_y,
tux_img, old_tux_img, tux_pressing, tux_anim, tux_anim_frame,
@@ -128,7 +80,7 @@
unsigned char str[64];
LOG( "starting Comet Zap game\n" );
- DOUT( DIF_LEVEL );
+ DOUT( diff_level );
SDL_ShowCursor(0);
laser_load_data();
@@ -184,7 +136,7 @@
/* Reset remaining stuff: */
bkgd = NULL;
- laser_reset_level(DIF_LEVEL);
+ laser_reset_level(diff_level);
/* --- MAIN GAME LOOP!!! --- */
@@ -197,8 +149,7 @@
tux_same_counter = 0;
ans_num = 0;
- /* Next line changed to get rid of int_rand() which didn't work on win32: */
- audioMusicPlay(musics[MUS_GAME + (rand() % NUM_MUSICS)], 0);
+ MusicPlay(musics[MUS_GAME + (rand() % NUM_MUSICS)], 0);
do {
@@ -219,7 +170,8 @@
} else if (event.type == SDL_KEYDOWN) {
key = event.key.keysym.sym;
-
+ if (key == SDLK_F10)
+ SwitchScreenMode();
if (key == SDLK_F11)
SDL_SaveBMP( screen, "laser.bmp");
@@ -314,7 +266,7 @@
laser.y2 = comets[lowest].y;
}
- playsound(sounds[SND_LASER]);
+ PlaySound(sounds[SND_LASER]);
/* 50% of the time.. */
@@ -331,13 +283,13 @@
/* Increment score: */
- laser_add_score( (DIF_LEVEL+1) * 5 * ((screen->h - comets[lowest].y)/20 ));
+ laser_add_score( (diff_level+1) * 5 * ((screen->h - comets[lowest].y)/20 ));
} else {
/* Didn't hit anything! */
- playsound(sounds[SND_BUZZ]);
+ PlaySound(sounds[SND_BUZZ]);
if (0 == (rand() % 2))
tux_img = IMG_TUX_DRAT;
@@ -363,7 +315,7 @@
tux_img = IMG_TUX_SIT;
if (level_start_wait == LEVEL_START_WAIT_START / 4)
- playsound(sounds[SND_ALARM]);
+ PlaySound(sounds[SND_ALARM]);
}
@@ -422,12 +374,12 @@
if (cities[comets[i].city].shields) {
cities[comets[i].city].shields = 0;
- playsound(sounds[SND_SHIELDSDOWN]);
- laser_add_score(-500 * (DIF_LEVEL+1));
+ PlaySound(sounds[SND_SHIELDSDOWN]);
+ laser_add_score(-500 * (diff_level+1));
} else {
cities[comets[i].city].expl = CITY_EXPL_START;
- playsound(sounds[SND_EXPLOSION]);
- laser_add_score(-1000 * (DIF_LEVEL+1));
+ PlaySound(sounds[SND_EXPLOSION]);
+ laser_add_score(-1000 * (diff_level+1));
}
tux_anim = IMG_TUX_FIST1;
@@ -464,7 +416,7 @@
if ((num_comets_alive < 2 || ((rand() % 4) == 0)) && distanceMoved > 40) {
distanceMoved = 0;
- laser_add_comet(DIF_LEVEL);
+ laser_add_comet(diff_level);
num_attackers--;
}
} else {
@@ -478,7 +430,7 @@
/* Go on to the next wave: */
wave++;
- laser_reset_level(DIF_LEVEL);
+ laser_reset_level(diff_level);
} else {
@@ -668,7 +620,7 @@
/* Keep playing music: */
if (sys_sound && !Mix_PlayingMusic())
- audioMusicPlay(musics[MUS_GAME + (rand() % NUM_MUSICS)], 0);
+ MusicPlay(musics[MUS_GAME + (rand() % NUM_MUSICS)], 0);
/* Pause (keep frame-rate event) */
@@ -694,9 +646,70 @@
}
+/*****************************************************/
+/* */
+/* Local ("private") functions: */
+/* */
+/*****************************************************/
+
+
+
+
+/* --- Load all media --- */
+void laser_load_data(void)
+{
+ int i;
+
+ /* Create the SDL_Surfaces for all of the characters */
+ /* used in the word list: */
+ font = LoadFont( ttf_font, 32);
+ RenderLetters(font);
+
+ /* Load images: */
+ for (i = 0; i < NUM_IMAGES; i++)
+ images[i] = LoadImage(image_filenames[i], IMG_ALPHA);
+ shield = LoadSprite( "cities/shield", IMG_ALPHA );
+
+ if (sys_sound) {
+ for (i = 0; i < NUM_SOUNDS; i++)
+ sounds[i] = LoadSound(sound_filenames[i]);
+
+ for (i = 0; i < NUM_MUSICS; i++)
+ musics[i] = LoadMusic(music_filenames[i]);
+ }
+
+ PauseLoadMedia();
+}
+
+
+/* --- unload all media --- */
+void laser_unload_data(void) {
+ int i;
+
+ FreeLetters();
+
+ for (i = 0; i < NUM_IMAGES; i++)
+ SDL_FreeSurface(images[i]);
+
+ if (sys_sound) {
+ for (i = 0; i < NUM_SOUNDS; i++)
+ Mix_FreeChunk(sounds[i]);
+ for (i = 0; i < NUM_MUSICS; i++)
+ Mix_FreeMusic(musics[i]);
+ }
+
+ FreeSprite(shield);
+
+ PauseUnloadMedia();
+
+
+ TTF_CloseFont(font);
+}
+
+
/* Reset stuff for the next level! */
-void laser_reset_level(int DIF_LEVEL)
+void laser_reset_level(int diff_level)
{
unsigned char fname[1024];
static int last_bkgd = -1;
@@ -711,7 +724,7 @@
LOG("Loading background in laser_reset_level()\n");
do {
- i = rand() % NUM_BKGDS; /* int_rand() didn't work correctly on win32 */
+ i = rand() % NUM_BKGDS;
DOUT(i);
}
while (i == last_bkgd);
@@ -745,12 +758,12 @@
/* Set number of attackers & speed for this wave: */
- switch (DIF_LEVEL) {
+ switch (diff_level) {
case 0 : speed = 1 + (wave/5); num_attackers=15; break;
case 1 : speed = 1 + (wave/4); num_attackers=15; break;
case 2 : speed = 1 + ((wave<<1)/3); num_attackers=(wave<<1); break;
case 3 : speed = 1 + wave; num_attackers=(wave<<1); break;
- default: LOG("DIF_LEVEL not recognized!\n");
+ default: LOG("diff_level not recognized!\n");
}
distanceMoved = 100; // so that we don't have to wait to start the level
@@ -760,12 +773,12 @@
/* Add an comet to the game (if there's room): */
-void laser_add_comet(int DIF_LEVEL) {
+void laser_add_comet(int diff_level) {
int target, location = 0;
static int last = -1;
int targeted[NUM_CITIES] = { 0 };
- int add = (rand() % (DIF_LEVEL + 2));
+ int add = (rand() % (diff_level + 2));
LOG ("Entering laser_add_comet()\n");
DEBUGCODE { fprintf(stderr, "Adding %d comets \n", add); }
@@ -800,7 +813,7 @@
comets[location].y = 0;
/* Pick a letter */
- comets[location].ch = get_letter();
+ comets[location].ch = GetLetter();
add--;
}
DEBUGCODE {if (location == MAX_COMETS)
@@ -810,7 +823,7 @@
else /* Odd number of cities (is this a hack that means we are using words?) */
{
LOG("NUM_CITIES is odd\n");
- wchar_t* word = WORDS_get();
+ wchar_t* word = GetWord();
int i=0;
DEBUGCODE {fprintf(stderr, "word is: %s\n", word);}
@@ -828,8 +841,8 @@
if (location < MAX_COMETS)
{
comets[location].alive = 1;
- comets[location].city = target+i;
- comets[location].x = cities[target+i].x;
+ comets[location].city = target + i;
+ comets[location].x = cities[target + i].x;
comets[location].y = 0;
comets[location].ch = word[i];
DEBUGCODE {fprintf(stderr, "Assigning letter to comet: %c\n", word[i]);}
@@ -844,18 +857,23 @@
void laser_draw_let(wchar_t c, int x, int y)
{
- SDL_Rect dst;
- dst.y = y - 10;
- dst.x = x - (GetWhiteGlyph(c)->w/2);
- /* Correct for varying height of glyphs: */
- GetGlyphCoords(c, &dst.x, &dst.y);
- SDL_BlitSurface(GetWhiteGlyph(c), NULL, screen, &dst);
+ int top_x, top_y;
+ SDL_Rect dst;
+ /* Start with coords for where we want glyph origin to go: */
+ top_x = x - (GetWhiteGlyph(c)->w/2);
+ top_y = y - 10;
+ /* Correct for varying height of glyphs: */
+ GetGlyphCoords(c, &top_x, &top_y);
+ /* Plug into the SDL_Rect and blit: */
+ dst.x = top_x;
+ dst.y = top_y;
+ SDL_BlitSurface(GetWhiteGlyph(c), NULL, screen, &dst);
}
/* Draw status numbers: */
-void laser_draw_numbers(unsigned char * str, int x)
+void laser_draw_numbers(const unsigned char* str, int x)
{
int i, cur_x, c;
SDL_Rect src, dest;
Modified: tuxtype/trunk/tuxtype/loaders.c
===================================================================
--- tuxtype/trunk/tuxtype/loaders.c 2007-05-29 21:53:02 UTC (rev 184)
+++ tuxtype/trunk/tuxtype/loaders.c 2007-06-07 18:54:49 UTC (rev 185)
@@ -20,6 +20,10 @@
#include "globals.h"
#include "funcs.h"
+/* Local function prototypes: */
+int max(int n1, int n2);
+SDL_Surface* flip(SDL_Surface *in, int x, int y);
+
/* Returns 1 if valid file, 2 if valid dir, 0 if neither: */
int CheckFile(const char* file)
{
@@ -55,7 +59,7 @@
return 0;
}
-void LoadLang( void )
+void LoadLang(void)
{
char fn[FNLEN];
@@ -81,14 +85,15 @@
fprintf(stderr, "Cannot support UTF-8, ASCII-only words will be used\n");
/* This function confusingly returns 0 if successful! */
- if (0 != load_trans( fn )) /* Meaning it failed! */
+ if (0 != Load_PO_File( fn )) /* Meaning it failed! */
{
/* failed to find a lang.po file, clear gettext & return */
return;
}
}
-int max( int n1, int n2 ) {
+int max(int n1, int n2)
+{
return (n1 > n2 ? n1 : n2);
}
@@ -102,7 +107,7 @@
note: you can have it flip both
**********************/
-SDL_Surface *flip( SDL_Surface *in, int x, int y ) {
+SDL_Surface* flip(SDL_Surface* in, int x, int y ) {
SDL_Surface *out, *tmp;
SDL_Rect from_rect, to_rect;
Uint32 flags;
@@ -191,7 +196,7 @@
return out;
}
-TTF_Font *LoadFont( char *fontfile, int fontsize ) {
+TTF_Font* LoadFont(const char* fontfile, int fontsize ) {
TTF_Font *loadedFont = NULL;
char fn[FNLEN];
int i;
@@ -235,7 +240,7 @@
/***********************
LoadImage : Load an image and set transparent if requested
************************/
-SDL_Surface *LoadImage( char *datafile, int mode )
+SDL_Surface* LoadImage(const char* datafile, int mode )
{
int i;
int oldDebug; //so we can turn off debug output for this func only
@@ -313,8 +318,8 @@
return (final_pic);
}
-sprite* FlipSprite( sprite *in, int X, int Y ) {
- sprite *out;
+sprite* FlipSprite(sprite* in, int X, int Y ) {
+ sprite* out;
out = malloc(sizeof(sprite));
if (in->default_img != NULL)
@@ -327,7 +332,7 @@
return out;
}
-sprite* LoadSprite( char* name, int MODE ) {
+sprite* LoadSprite(const char* name, int MODE ) {
sprite *new_sprite;
char fn[FNLEN];
int x;
@@ -356,7 +361,7 @@
return new_sprite;
}
-void FreeSprite( sprite *gfx ) {
+void FreeSprite(sprite *gfx ) {
int x;
for (x = 0; x < gfx->num_frames; x++)
SDL_FreeSurface( gfx->frame[x] );
@@ -367,9 +372,9 @@
/***************************
LoadSound : Load a sound/music patch from a file.
****************************/
-Mix_Chunk *LoadSound( char *datafile )
+Mix_Chunk* LoadSound(const char* datafile )
{
- Mix_Chunk *tempChunk=NULL;
+ Mix_Chunk* tempChunk=NULL;
char fn[FNLEN];
int i;
@@ -389,7 +394,7 @@
LoadMusic : Load
music from a datafile
*************************/
-Mix_Music *LoadMusic(char *datafile )
+Mix_Music* LoadMusic(const char* datafile )
{
char fn[FNLEN];
Mix_Music *tempMusic;
Modified: tuxtype/trunk/tuxtype/main.c
===================================================================
--- tuxtype/trunk/tuxtype/main.c 2007-05-29 21:53:02 UTC (rev 184)
+++ tuxtype/trunk/tuxtype/main.c 2007-06-07 18:54:49 UTC (rev 185)
@@ -49,7 +49,7 @@
srand(time(NULL));
// This sets realPath[] to the default theme file path:
- setupTheme(NULL);
+ SetupTheme(NULL);
LoadSettings();
DEBUGCODE { printf("Window setting from config file is: %s\n", localsettings.window );}
@@ -127,7 +127,7 @@
if ((strcmp(argv[i], "-t") == 0) |
(strcmp(argv[i], "--theme") == 0))
- setupTheme( argv[++i] );
+ SetupTheme( argv[++i] );
}
DEBUGCODE {
Modified: tuxtype/trunk/tuxtype/pause.c
===================================================================
--- tuxtype/trunk/tuxtype/pause.c 2007-05-29 21:53:02 UTC (rev 184)
+++ tuxtype/trunk/tuxtype/pause.c 2007-06-07 18:54:49 UTC (rev 185)
@@ -25,149 +25,12 @@
TTF_Font *f1, *f2;
extern settings localsettings;
-void pause_load_media(void) {
- if (sys_sound)
- pause_sfx = LoadSound( "tock.wav" );
+/* Local function prototypes: */
+void darkenscreen(void);
+void draw_vols(int sfx, int mus);
+void pause_draw_info(void);
- up = LoadImage("up.png", IMG_ALPHA);
- rectUp.w = up->w; rectUp.h = up->h;
- down = LoadImage("down.png", IMG_ALPHA);
- rectDown.w = down->w; rectDown.h = down->h;
-
- left = LoadImage("left.png", IMG_ALPHA);
- rectLeft.w = left->w; rectLeft.h = left->h;
-
- right = LoadImage("right.png", IMG_ALPHA);
- rectRight.w = right->w; rectRight.h = right->h;
-
- f1 = LoadFont( ttf_font, 24 );
- f2 = LoadFont( ttf_font, 36 );
-}
-
-void pause_unload_media(void) {
- if (sys_sound)
- Mix_FreeChunk(pause_sfx);
- SDL_FreeSurface(up);
- SDL_FreeSurface(down);
- SDL_FreeSurface(left);
- SDL_FreeSurface(right);
- TTF_CloseFont(f1);
- TTF_CloseFont(f2);
-}
-
-void pause_draw_info(void) {
- SDL_Rect s;
- SDL_Surface *t;
-
- rectLeft.y = rectRight.y = 200;
- rectDown.y = rectUp.y = 300;
-
- rectLeft.x = rectDown.x = 320 - (7*16) - rectLeft.w - 4;
- rectRight.x = rectUp.x = 320 + (7*16) + 4;
-
- if (sys_sound) {
-
- SDL_BlitSurface(left, NULL, screen, &rectLeft);
- SDL_BlitSurface(right, NULL, screen, &rectRight);
-
- SDL_BlitSurface(down, NULL, screen, &rectDown);
- SDL_BlitSurface(up, NULL, screen, &rectUp);
- }
-
- if (sys_sound) {
-
- t = black_outline(_("Sound Effects Volume"), f1, &white);
- s.y = 160;
- s.x = 320 - t->w/2;
- SDL_BlitSurface(t, NULL, screen, &s);
- SDL_FreeSurface(t);
-
- t = black_outline(_("Music Volume"), f1, &white);
- s.y = 260;
- s.x = 320 - t->w/2;
- SDL_BlitSurface(t, NULL, screen, &s);
- SDL_FreeSurface(t);
-
- } else {
-
- t = black_outline(_("Sound & Music Disabled"), f1, &white);
- s.y = 160;
- s.x = 320 - t->w/2;
- SDL_BlitSurface(t, NULL, screen, &s);
- SDL_FreeSurface(t);
- }
-
- t = black_outline(_("Paused!"), f2, &white);
- s.y = 60;
- s.x = 320 - t->w/2;
- SDL_BlitSurface(t, NULL, screen, &s);
- SDL_FreeSurface(t);
-
- t = black_outline(_("Press escape again to return to menu"), f1, &white);
- s.y = 400;
- s.x = 320 - t->w/2;
- SDL_BlitSurface(t, NULL, screen, &s);
- SDL_FreeSurface(t);
-
- t = black_outline(_("Press space bar to return to game"), f1, &white);
- s.y = 440;
- s.x = 320 - t->w/2;
- SDL_BlitSurface(t, NULL, screen, &s);
- SDL_FreeSurface(t);
-}
-
-void draw_vols(int sfx, int mus) {
- SDL_Rect s,m;
- int i;
-
- s.y = rectLeft.y;
- m.y = rectDown.y;
- m.w = s.w = 5;
- s.x = rectLeft.x + rectLeft.w + 5;
- m.x = rectDown.x + rectDown.w + 5;
- m.h = s.h = 40;
-
- for (i = 1; i<=32; i++){
- if (sfx >= i*4)
- SDL_FillRect(screen, &s, SDL_MapRGB(screen->format, 0, 0, 127+sfx));
- else
- SDL_FillRect(screen, &s, SDL_MapRGB(screen->format, 0, 0, 0));
-
- if (mus >= i*4)
- SDL_FillRect(screen, &m, SDL_MapRGB(screen->format, 0, 0, 127+mus));
- else
- SDL_FillRect(screen, &m, SDL_MapRGB(screen->format, 0, 0, 0));
-
- m.x = s.x += 7;
- }
-}
-
-/* ==== fillscreen ====
- * RESULT: it will darken the screen by a factor of 4
- * WARNING: only works on 16bit screens right now!
- */
-void darkenscreen( void ){
- Uint16 rm = screen->format->Rmask;
- Uint16 gm = screen->format->Gmask;
- Uint16 bm = screen->format->Bmask;
- Uint16 *p;
- int x, y;
-
- p = screen->pixels;
-
- for (y = 0; y<480; y++)
- for (x = 0; x<640; x++) {
- *p = (((*p&rm)>>2)&rm) | (((*p&gm)>>2)&gm) | (((*p&bm)>>2)&bm); p++;
- }
-}
-
-int inRect( SDL_Rect r, int x, int y) {
- if ((x < r.x) || (y < r.y) || (x > r.x + r.w) || (y > r.y + r.h))
- return 0;
- return 1;
-}
-
// QUESTION: For usability sake, should escape return to the game
// and the user have to choose to quit the game, or ???
/**********************
@@ -203,6 +66,7 @@
darkenscreen();
pause_draw_info();
+
if (sys_sound) {
draw_vols(sfx_volume, mus_volume);
}
@@ -335,3 +199,162 @@
return (quit);
}
+
+void PauseLoadMedia(void) {
+ if (sys_sound)
+ pause_sfx = LoadSound( "tock.wav" );
+
+ up = LoadImage("up.png", IMG_ALPHA);
+ rectUp.w = up->w; rectUp.h = up->h;
+
+ down = LoadImage("down.png", IMG_ALPHA);
+ rectDown.w = down->w; rectDown.h = down->h;
+
+ left = LoadImage("left.png", IMG_ALPHA);
+ rectLeft.w = left->w; rectLeft.h = left->h;
+
+ right = LoadImage("right.png", IMG_ALPHA);
+ rectRight.w = right->w; rectRight.h = right->h;
+
+ f1 = LoadFont( ttf_font, 24 );
+ f2 = LoadFont( ttf_font, 36 );
+}
+
+void PauseUnloadMedia(void) {
+ if (sys_sound)
+ Mix_FreeChunk(pause_sfx);
+ SDL_FreeSurface(up);
+ SDL_FreeSurface(down);
+ SDL_FreeSurface(left);
+ SDL_FreeSurface(right);
+ TTF_CloseFont(f1);
+ TTF_CloseFont(f2);
+}
+
+
+/* Slightly useful function but not sure this file is the right place for it. */
+int inRect(SDL_Rect r, int x, int y)
+{
+ if ((x < r.x) || (y < r.y) || (x > r.x + r.w) || (y > r.y + r.h))
+ return 0;
+ return 1;
+}
+
+
+/******************************************/
+/* */
+/* Local ("private") functions */
+/* */
+/******************************************/
+
+
+
+void pause_draw_info(void) {
+ SDL_Rect s;
+ SDL_Surface *t;
+
+ rectLeft.y = rectRight.y = 200;
+ rectDown.y = rectUp.y = 300;
+
+ rectLeft.x = rectDown.x = 320 - (7*16) - rectLeft.w - 4;
+ rectRight.x = rectUp.x = 320 + (7*16) + 4;
+
+ if (sys_sound) {
+
+ SDL_BlitSurface(left, NULL, screen, &rectLeft);
+ SDL_BlitSurface(right, NULL, screen, &rectRight);
+
+ SDL_BlitSurface(down, NULL, screen, &rectDown);
+ SDL_BlitSurface(up, NULL, screen, &rectUp);
+ }
+
+ if (sys_sound) {
+
+ t = BlackOutline(_("Sound Effects Volume"), f1, &white);
+ s.y = 160;
+ s.x = 320 - t->w/2;
+ SDL_BlitSurface(t, NULL, screen, &s);
+ SDL_FreeSurface(t);
+
+ t = BlackOutline(_("Music Volume"), f1, &white);
+ s.y = 260;
+ s.x = 320 - t->w/2;
+ SDL_BlitSurface(t, NULL, screen, &s);
+ SDL_FreeSurface(t);
+
+ } else {
+
+ t = BlackOutline(_("Sound & Music Disabled"), f1, &white);
+ s.y = 160;
+ s.x = 320 - t->w/2;
+ SDL_BlitSurface(t, NULL, screen, &s);
+ SDL_FreeSurface(t);
+ }
+
+ t = BlackOutline(_("Paused!"), f2, &white);
+ s.y = 60;
+ s.x = 320 - t->w/2;
+ SDL_BlitSurface(t, NULL, screen, &s);
+ SDL_FreeSurface(t);
+
+ t = BlackOutline(_("Press escape again to return to menu"), f1, &white);
+ s.y = 400;
+ s.x = 320 - t->w/2;
+ SDL_BlitSurface(t, NULL, screen, &s);
+ SDL_FreeSurface(t);
+
+ t = BlackOutline(_("Press space bar to return to game"), f1, &white);
+ s.y = 440;
+ s.x = 320 - t->w/2;
+ SDL_BlitSurface(t, NULL, screen, &s);
+ SDL_FreeSurface(t);
+}
+
+
+
+void draw_vols(int sfx, int mus) {
+ SDL_Rect s,m;
+ int i;
+
+ s.y = rectLeft.y;
+ m.y = rectDown.y;
+ m.w = s.w = 5;
+ s.x = rectLeft.x + rectLeft.w + 5;
+ m.x = rectDown.x + rectDown.w + 5;
+ m.h = s.h = 40;
+
+ for (i = 1; i<=32; i++){
+ if (sfx >= i*4)
+ SDL_FillRect(screen, &s, SDL_MapRGB(screen->format, 0, 0, 127+sfx));
+ else
+ SDL_FillRect(screen, &s, SDL_MapRGB(screen->format, 0, 0, 0));
+
+ if (mus >= i*4)
+ SDL_FillRect(screen, &m, SDL_MapRGB(screen->format, 0, 0, 127+mus));
+ else
+ SDL_FillRect(screen, &m, SDL_MapRGB(screen->format, 0, 0, 0));
+
+ m.x = s.x += 7;
+ }
+}
+
+/* ==== fillscreen ====
+ * RESULT: it will darken the screen by a factor of 4
+ * WARNING: only works on 16bit screens right now!
+ */
+void darkenscreen( void ){
+ Uint16 rm = screen->format->Rmask;
+ Uint16 gm = screen->format->Gmask;
+ Uint16 bm = screen->format->Bmask;
+ Uint16 *p;
+ int x, y;
+
+ p = screen->pixels;
+
+ for (y = 0; y<480; y++)
+ for (x = 0; x<640; x++) {
+ *p = (((*p&rm)>>2)&rm) | (((*p&gm)>>2)&gm) | (((*p&bm)>>2)&bm); p++;
+ }
+}
+
+
Modified: tuxtype/trunk/tuxtype/playgame.c
===================================================================
--- tuxtype/trunk/tuxtype/playgame.c 2007-05-29 21:53:02 UTC (rev 184)
+++ tuxtype/trunk/tuxtype/playgame.c 2007-06-07 18:54:49 UTC (rev 185)
@@ -56,24 +56,573 @@
+/* Local function prototypes: */
+static void AddRect(SDL_Rect * src, SDL_Rect * dst);
+static void AddSplat(int *splats, struct fishypoo *f, int *curlives, int *frame);
+static void CheckCollision(int fishies, int *fish_left, int frame );
+static void CheckFishies(int *fishies, int *splats);
+static int check_word(int f);
+static void display_msg(const unsigned char *msg, int x, int y);
+static void DrawBackground(void);
+static void draw_bar(int curlevel, int diflevel, int curlives,
+ int oldlives, int fish_left, int oldfish_left);
+static void DrawFish(int which);
+static void DrawNumbers(int num, int x, int y, int places);
+static void DrawObject(SDL_Surface* sprite, int x, int y);
+static void DrawSprite(sprite *gfx, int x, int y);
+static void EraseNumbers(int num, int x, int y, int places);
+static void EraseObject(SDL_Surface* sprite, int x, int y);
+static void EraseSprite(sprite *img, int x, int y);
+static float float_restrict(float a, float x, float b);
+static void FreeGame(void);
+static int int_restrict(int a, int x, int b);
+static void LoadFishies(void);
+static void LoadOthers(void);
+static void LoadTuxAnims(void);
+static void MoveFishies(int* fishies, int* splats, int* lifes, int* frame);
+static void MoveTux(int frame, int fishies);
+static void next_tux_frame(void);
+static void ResetObjects(void);
+static void SpawnFishies(int diflevel, int* fishies, int* frame);
+static void UpdateScreen(int* frame);
+static void UpdateTux(wchar_t letter_pressed, int fishies, int frame);
+static void WaitFrame(void);
-/* Local function prototypes: */
-void UpdateTux(wchar_t letter_pressed, int fishies, int frame);
+/************************************************************************/
+/* */
+/* "Public" functions (callable throughout program) */
+/* */
+/************************************************************************/
+/*************************************************************************
+* PlayCascade : This is the main Cascade game loop *
+*************************************************************************/
+int PlayCascade( int diflevel ) {
+ unsigned char filename[FNLEN];
+ int still_playing = 1;
+ int playing_level = 1;
+ int setup_new_level = 1;
+ int won_level = 0;
+ int quitting = 0;
+ int curlevel = 0;
+ int i;
+ int curlives;
+ int oldlives=0, oldfish_left=0;
+ int fish_left, fishies = 0, local_max_fishies=1;
+ int frame = 0;
+ int done_frames;
+ int splats = 0;
+ SDL_Event event;
+ SDL_Surface *temp_text[CONGRATS_FRAMES + OH_NO_FRAMES];
+ SDL_Rect text_rect;
+ int text_y_end;
+ int xamp, yamp, x_not, y_not;
+ int temp_text_frames;
+ int temp_text_count;
+ Uint16 key_unicode;
-/***************************************
- int_rand: returns an integer x
- such that - min <= x <= max
-***************************************/
-int int_rand(int min, int max) {
- int diff = max - min;
- return min + (rand() % diff); //NOTE I think this is what we want DSB
-// return min + (int) (((double)(max-min))*(float)rand()/(RAND_MAX+1.0)); // JA - FIX this doesn't return MAX
+ DEBUGCODE {
+ fprintf(stderr, "->PlayCascade: level=%i\n", diflevel );
+ }
+
+ SDL_WarpMouse(screen->w / 2, screen->h / 2);
+ SDL_ShowCursor(0);
+
+ SNOW_init();
+
+ LoadTuxAnims();
+ LoadFishies();
+ LoadOthers();
+ LOG( " before RenderLetters()\n" );
+ RenderLetters(font);
+ LOG( " after RenderLetters()\n" );
+
+ LOG( " starting game \n ");
+ while (still_playing) {
+
+ if (setup_new_level) {
+
+ switch (diflevel) {
+ case EASY:
+ fish_left = MAX_FISHIES_EASY;
+ if (o_lives > LIVES_INIT_EASY){
+ curlives = o_lives;
+ }else
+ curlives = LIVES_INIT_EASY;
+ break;
+ case MEDIUM:
+ fish_left = MAX_FISHIES_MEDIUM;
+ if (o_lives > LIVES_INIT_MEDIUM){
+ curlives = o_lives;
+ }else
+ curlives = LIVES_INIT_MEDIUM;
+ break;
+ case HARD:
+ fish_left = MAX_FISHIES_HARD;
+ if (o_lives > LIVES_INIT_HARD){
+ curlives = o_lives;
+ }else
+ curlives = LIVES_INIT_HARD;
+ break;
+ }
+
+ local_max_fishies = fish_left;
+
+ if (curlevel != 0) {
+ SDL_FreeSurface(background);
+ }
+
+ if (diflevel == INF_PRACT)
+ sprintf(filename, "pract.png");
+ else
+ sprintf(filename, "kcas%i_%i.jpg", diflevel+1, curlevel+1);
+
+ /* --- Special Hidden Code --- */
+
+ if (hidden && curlevel == 3)
+ sprintf(filename, "hidden.jpg");
+
+ DEBUGCODE {
+ fprintf(stderr, "->>Loading background: %s\n", filename);
+ }
+
+ background = LoadImage( filename, IMG_REGULAR );
+ SNOW_setBkg( background );
+
+ DrawBackground();
+
+ ResetObjects();
+
+ if (sys_sound) {
+ sprintf(filename, "kmus%i.wav", curlevel + 1);
+ MusicLoad( filename, -1 );
+ }
+
+ LOG( "->>PLAYING THE GAME\n" );
+
+ setup_new_level = 0;
+ }
+
+ /* --- Poll input queue, get keyboard info --- */
+
+ while (playing_level) {
+
+ oldlives = curlives;
+ oldfish_left = fish_left;
+
+ EraseSprite( tux_object.spr[tux_object.state][tux_object.facing], tux_object.x, tux_object.y );
+
+ /* --- Checking input --- */
+
+ while ( SDL_PollEvent( &event ) )
+ if ( event.type == SDL_QUIT ) {
+ exit(0);
+ } else if (event.type == SDL_KEYDOWN) {
+
+ if (event.key.keysym.sym == SDLK_F11)
+ SDL_SaveBMP( screen, "screenshot.bmp" );
+ if (event.key.keysym.sym == SDLK_F6){
+ o_lives=o_lives-10;
+ curlives=curlives-10;
+ }
+ if (event.key.keysym.sym == SDLK_F7) {
+ o_lives=o_lives+10;
+ curlives=curlives+10;
+ }
+ if (event.key.keysym.sym == SDLK_F10)
+ SwitchScreenMode();
+ if (event.key.keysym.sym == SDLK_F12)
+ SNOW_toggle();
+ if (event.key.keysym.sym == SDLK_ESCAPE) {
+
+ if (Pause() == 1) {
+ playing_level = 0;
+ still_playing = 0;
+ quitting = 1;
+ }
+ DrawBackground();
+ }
+
+// /* ASCII lowercase is 97-122, whereas uppercase is */
+// /* 65-90 - this if() converts lowercase to corresponding */
+// /* uppercase - not sure we always want this! */
+// if (((event.key.keysym.unicode & 0xff) >= 97) & ((event.key.keysym.unicode & 0xff) <= 122)){
+// UpdateTux(KEYMAP[(event.key.keysym.unicode & 0xff)-32], fishies, frame);
+// } else {
+// UpdateTux(KEYMAP[(event.key.keysym.unicode & 0xff)], fishies, frame);
+// }
+
+ key_unicode = event.key.keysym.unicode & 0xff;
+ /* For now, tuxtype is case-insensitive for input, */
+ /* with only uppercase for answers: */
+ DEBUGCODE
+ {
+ fprintf(stderr,
+ "\nkey_unicode = %d\twchar_t = %lc\tKEYMAP[key_unicode] = %c\n",
+ key_unicode, key_unicode, KEYMAP[key_unicode]);
+ }
+
+ if (key_unicode >= 97 && key_unicode <= 122)
+ key_unicode -= 32; //convert lowercase to uppercase
+ if (key_unicode >= 224 && key_unicode <= 255)
+ key_unicode -= 32; //same for non-US chars
+
+ LOG ("After checking for lower case:\n");
+ DEBUGCODE
+ {
+ fprintf(stderr,
+ "key_unicode = %d\twchar_t = %lc\tKEYMAP[key_unicode] = %c\n\n",
+ key_unicode, key_unicode, KEYMAP[key_unicode]);
+ }
+
+ /* Now update with case-folded value: */
+ UpdateTux(KEYMAP[key_unicode], fishies, frame);
+ }
+
+ /* --- fishy updates --- */
+
+ if ((frame % 10) == 0) next_frame( fishy );
+
+ if (fishies < local_max_fishies)
+ SpawnFishies( diflevel, &fishies, &frame );
+
+ MoveTux( frame, fishies );
+ CheckCollision(fishies, &fish_left, frame );
+ DrawSprite( tux_object.spr[tux_object.state][tux_object.facing], tux_object.x, tux_object.y );
+ MoveFishies(&fishies, &splats, &curlives, &frame);
+ CheckFishies(&fishies, &splats);
+ SNOW_update();
+
+ /* --- update top score/info bar --- */
+
+ if (diflevel != INF_PRACT) {
+ draw_bar(curlevel, diflevel, curlives, oldlives, fish_left, oldfish_left);
+
+ if (curlives <= 0) {
+ playing_level = 0;
+ still_playing = 0;
+ }
+ } else
+ fish_left = 1; // in practice there is always 1 fish left!
+
+ if (fish_left <= 0) {
+ won_level = 1;
+ playing_level = 0;
+ curlevel++;
+ setup_new_level = 1;
+ still_playing = 1;
+ }
+
+ if (!quitting) {
+ UpdateScreen(&frame);
+
+ if (speed_up == 0)
+ WaitFrame();
+ }
+ }
+
+ if (sys_sound)
+ Mix_FadeOutMusic(MUSIC_FADE_OUT_MS);
+
+ DrawBackground();
+
+ if (quitting == 0) {
+
+ if (won_level) {
+
+ won_level = 0;
+ if (curlevel < 4) {
+
+ LOG( "--->NEXT LEVEL!\n" );
+
+ done_frames = MAX_END_FRAMES_BETWEEN_LEVELS;
+ playing_level = 1;
+ xamp = 0;
+ yamp = 0;
+
+ } else {
+
+ LOG( "--->WINNER!\n" );
+
+ done_frames = MAX_END_FRAMES_WIN_GAME;
+ still_playing = 0;
+ xamp = WIN_GAME_XAMP;
+ yamp = WIN_GAME_YAMP;
+
+ if (sys_sound)
+ Mix_PlayChannel(WINFINAL_WAV, sound[WINFINAL_WAV], 0);
+ }
+
+ if (sys_sound)
+ Mix_PlayChannel(WIN_WAV, sound[WIN_WAV], 0);
+
+ for (i = 0; i < CONGRATS_FRAMES; i++)
+ temp_text[i] = congrats[i];
+
+ temp_text_frames = CONGRATS_FRAMES;
+ tux_object.state = TUX_WINNING;
+
+ } else {
+
+ LOG( "--->LOST :(\n" );
+
+ done_frames = MAX_END_FRAMES_GAMEOVER;
+ xamp = 0;
+ yamp = 0;
+
+ if (sys_sound)
+ Mix_PlayChannel(LOSE_WAV, sound[LOSE_WAV], 0);
+
+ for (i = 0; i < OH_NO_FRAMES; i++)
+ temp_text[i] = ohno[i];
+
+ temp_text_frames = OH_NO_FRAMES;
+ tux_object.state = TUX_YIPING;
+ }
+
+ /* --- draw the animation here --- */
+
+ temp_text_count = 0;
+ text_y_end = (screen->h / 2) - (temp_text[0]->h / 2);
+ text_rect.x = (screen->w / 2) - (temp_text[0]->w / 2);
+ text_rect.y = screen->h - temp_text[0]->h - 1;
+ x_not = text_rect.x;
+
+ LOG( "--->Starting Ending Animation\n" );
+
+ for ( i=0; i<= done_frames; i++ ) {
+ temp_text_count = (temp_text_count+1) % temp_text_frames;
+
+ text_rect.y -= END_FRAME_DY;
+ y_not = text_rect.y;
+
+ if (text_rect.y < text_y_end) {
+ y_not = text_y_end + yamp * sin(i / WIN_GAME_ANGLE_MULT);
+ text_rect.y = text_y_end;
+ text_rect.x = x_not + xamp * cos(i / WIN_GAME_ANGLE_MULT);
+ }
+
+ DrawSprite( tux_object.spr[tux_object.state][tux_object.facing], tux_object.x, tux_object.y );
+ DrawObject(temp_text[temp_text_count], text_rect.x, y_not);
+ DrawObject(level[diflevel], 1, 1);
+ draw_bar(curlevel - 1, diflevel, curlives, oldlives, fish_left, oldfish_left);
+
+ next_tux_frame();
+ SNOW_update();
+ UpdateScreen(&frame);
+
+ EraseSprite( tux_object.spr[tux_object.state][tux_object.facing], tux_object.x, tux_object.y );
+
+ EraseObject(temp_text[temp_text_count], text_rect.x, y_not);
+
+ if (speed_up == 0)
+ WaitFrame();
+ }
+ }
+ }
+
+ SNOW_on = 0;
+
+ LOG( "->Done with level... cleaning up\n" );
+
+ FreeGame();
+
+ LOG( "->PlayCascade: END\n" );
+
+ return 1;
}
-int check_word( int f ) {
+
+
+
+/***********************
+ InitEngine
+ ***********************/
+void InitEngine(void) {
+ int i;
+
+ /* --- Set up the update rectangle pointers --- */
+
+ for (i = 0; i < MAX_UPDATES; ++i) {
+ blits[i].srcrect = &srcupdate[i];
+ blits[i].dstrect = &dstupdate[i];
+ }
+}
+
+
+
+/*************************************************/
+/* TransWipe: Performs various wipes to new bkgs */
+/*************************************************/
+/*
+ * Given a wipe request type, and any variables
+ * that wipe requires, will perform a wipe from
+ * the current screen image to a new one.
+ */
+void TransWipe(SDL_Surface * newbkg, int type, int var1, int var2)
+{
+ int i, j, x1, x2, y1, y2;
+ int step1, step2, step3, step4;
+ int frame;
+ SDL_Rect src;
+ SDL_Rect dst;
+
+ LOG("->TransWipe(): START\n");
+
+ numupdates = 0;
+ frame = 0;
+
+ if(newbkg->w == screen->w && newbkg->h == screen->h) {
+ if( type == RANDOM_WIPE )
+ type = (RANDOM_WIPE* ((float) rand()) / (RAND_MAX+1.0));
+
+ switch( type ) {
+ case WIPE_BLINDS_VERT: {
+ LOG("--+ Doing 'WIPE_BLINDS_VERT'\n");
+ /* var1 is num of divisions
+ var2 is how many frames animation should take */
+ if( var1 < 1 ) var1 = 1;
+ if( var2 < 1 ) var2 = 1;
+ step1 = screen->w / var1;
+ step2 = step1 / var2;
+
+ for(i = 0; i <= var2; i++) {
+ for(j = 0; j <= var1; j++) {
+ x1 = step1 * (j - 0.5) - i * step2 + 1;
+ x2 = step1 * (j - 0.5) + i * step2 + 1;
+ src.x = x1;
+ src.y = 0;
+ src.w = step2;
+ src.h = screen->h;
+ dst.x = x2;
+ dst.y = 0;
+ dst.w = step2;
+ dst.h = screen->h;
+ SDL_BlitSurface(newbkg, &src, screen, &src);
+ SDL_BlitSurface(newbkg, &dst, screen, &dst);
+ AddRect(&src, &src);
+ AddRect(&dst, &dst);
+ }
+ UpdateScreen(&frame);
+ }
+
+ src.x = 0;
+ src.y = 0;
+ src.w = screen->w;
+ src.h = screen->h;
+ SDL_BlitSurface(newbkg, NULL, screen, &src);
+ SDL_Flip(screen);
+
+ break;
+ } case WIPE_BLINDS_HORIZ: {
+ LOG("--+ Doing 'WIPE_BLINDS_HORIZ'\n");
+ /* var1 is num of divisions
+ var2 is how many frames animation should take */
+ if( var1 < 1 ) var1 = 1;
+ if( var2 < 1 ) var2 = 1;
+ step1 = screen->h / var1;
+ step2 = step1 / var2;
+
+ for(i = 0; i <= var2; i++) {
+ for(j = 0; j <= var1; j++) {
+ y1 = step1 * (j - 0.5) - i * step2 + 1;
+ y2 = step1 * (j - 0.5) + i * step2 + 1;
+ src.x = 0;
+ src.y = y1;
+ src.w = screen->w;
+ src.h = step2;
+ dst.x = 0;
+ dst.y = y2;
+ dst.w = screen->w;
+ dst.h = step2;
+ SDL_BlitSurface(newbkg, &src, screen, &src);
+ SDL_BlitSurface(newbkg, &dst, screen, &dst);
+ AddRect(&src, &src);
+ AddRect(&dst, &dst);
+ }
+ UpdateScreen(&frame);
+ }
+
+ src.x = 0;
+ src.y = 0;
+ src.w = screen->w;
+ src.h = screen->h;
+ SDL_BlitSurface(newbkg, NULL, screen, &src);
+ SDL_Flip(screen);
+
+ break;
+ } case WIPE_BLINDS_BOX: {
+ LOG("--+ Doing 'WIPE_BLINDS_BOX'\n");
+ /* var1 is num of divisions
+ var2 is how many frames animation should take */
+ if( var1 < 1 ) var1 = 1;
+ if( var2 < 1 ) var2 = 1;
+ step1 = screen->w / var1;
+ step2 = step1 / var2;
+ step3 = screen->h / var1;
+ step4 = step1 / var2;
+
+ for(i = 0; i <= var2; i++) {
+ for(j = 0; j <= var1; j++) {
+ x1 = step1 * (j - 0.5) - i * step2 + 1;
+ x2 = step1 * (j - 0.5) + i * step2 + 1;
+ src.x = x1;
+ src.y = 0;
+ src.w = step2;
+ src.h = screen->h;
+ dst.x = x2;
+ dst.y = 0;
+ dst.w = step2;
+ dst.h = screen->h;
+ SDL_BlitSurface(newbkg, &src, screen, &src);
+ SDL_BlitSurface(newbkg, &dst, screen, &dst);
+ AddRect(&src, &src);
+ AddRect(&dst, &dst);
+ y1 = step3 * (j - 0.5) - i * step4 + 1;
+ y2 = step3 * (j - 0.5) + i * step4 + 1;
+ src.x = 0;
+ src.y = y1;
+ src.w = screen->w;
+ src.h = step4;
+ dst.x = 0;
+ dst.y = y2;
+ dst.w = screen->w;
+ dst.h = step4;
+ SDL_BlitSurface(newbkg, &src, screen, &src);
+ SDL_BlitSurface(newbkg, &dst, screen, &dst);
+ AddRect(&src, &src);
+ AddRect(&dst, &dst);
+ }
+ UpdateScreen(&frame);
+ }
+
+ src.x = 0;
+ src.y = 0;
+ src.w = screen->w;
+ src.h = screen->h;
+ SDL_BlitSurface(newbkg, NULL, screen, &src);
+ SDL_Flip(screen);
+
+ break;
+ } default:
+ break;
+ }
+ }
+}
+
+
+
+/************************************************************************/
+/* */
+/* "Private" functions (local to playgame.c) */
+/* */
+/************************************************************************/
+
+
+
+static int check_word( int f ) {
int i;
if (wcslen(fish_object[f].word) > tux_object.wordlen)
@@ -108,25 +657,12 @@
next_tick = this_tick + (1000 / FRAMES_PER_SEC);
}
-/***********************
- InitEngine
- ***********************/
-void InitEngine(void) {
- int i;
- /* --- Set up the update rectangle pointers --- */
-
- for (i = 0; i < MAX_UPDATES; ++i) {
- blits[i].srcrect = &srcupdate[i];
- blits[i].dstrect = &dstupdate[i];
- }
-}
-
/****************************************************
ResetObjects : Clear and reset all objects to dead
****************************************************/
-void ResetObjects( void ) {
+static void ResetObjects( void ) {
int i;
LOG( "RESETTING OBJECTS\n" );
@@ -150,7 +686,7 @@
LOG( "OBJECTS RESET\n" );
}
-void DrawSprite(sprite *gfx, int x, int y) {
+static void DrawSprite(sprite *gfx, int x, int y) {
if (!gfx) return;
struct blit *update;
@@ -171,7 +707,8 @@
DrawObject : Draw an object at the specified
location. No respect to clipping!
*************************/
-void DrawObject(SDL_Surface* sprite, int x, int y) {
+static void DrawObject(SDL_Surface* sprite, int x, int y)
+{
if (!sprite) return;
struct blit *update;
@@ -191,7 +728,7 @@
/************************
UpdateScreen : Update the screen and increment the frame num
***************************/
-void UpdateScreen(int *frame) {
+static void UpdateScreen(int *frame) {
int i;
/* -- First erase everything we need to -- */
@@ -216,7 +753,7 @@
*frame = *frame + 1;
}
-void EraseSprite(sprite *img, int x, int y) {
+static void EraseSprite(sprite *img, int x, int y) {
struct blit *update;
update = &blits[numupdates++];
@@ -243,7 +780,7 @@
/*************************
EraseObject : Erase an object from the screen
**************************/
-void EraseObject(SDL_Surface * sprite, int x, int y) {
+static void EraseObject(SDL_Surface * sprite, int x, int y) {
struct blit *update;
update = &blits[numupdates++];
@@ -272,7 +809,7 @@
but add a rect to be updated next
update
*******************************/
-void AddRect(SDL_Rect * src, SDL_Rect * dst) {
+static void AddRect(SDL_Rect * src, SDL_Rect * dst) {
/*borrowed from SL's alien (and modified)*/
struct blit *update;
@@ -292,7 +829,7 @@
/*********************
LoadOthers : Load all other graphics
**********************/
-void LoadOthers( void ) {
+static void LoadOthers( void ) {
int i;
unsigned char filename[FNLEN];
@@ -300,14 +837,14 @@
font = LoadFont( ttf_font, ttf_font_size );
- curlev = black_outline(_("Level"), font, &white);
- lives = black_outline(_("Lives"), font, &white);
- fish = black_outline(_("Fish"), font, &white);
+ curlev = BlackOutline(_("Level"), font, &white);
+ lives = BlackOutline(_("Lives"), font, &white);
+ fish = BlackOutline(_("Fish"), font, &white);
- level[0] = black_outline(_("Easy"), font, &white);
- level[1] = black_outline(_("Medium"), font, &white);
- level[2] = black_outline(_("Hard"), font, &white);
- level[3] = black_outline(_("Practice"), font, &white);
+ level[0] = BlackOutline(_("Easy"), font, &white);
+ level[1] = BlackOutline(_("Medium"), font, &white);
+ level[2] = BlackOutline(_("Hard"), font, &white);
+ level[3] = BlackOutline(_("Practice"), font, &white);
number_max_w = 0;
for (i = 0; i < NUM_NUMS; i++) {
@@ -318,11 +855,11 @@
}
for (i = 0; i < CONGRATS_FRAMES; i++) {
- congrats[i] = black_outline(_("Congratulations"), font, &white);
+ congrats[i] = BlackOutline(_("Congratulations"), font, &white);
}
for (i = 0; i < OH_NO_FRAMES; i++) {
- ohno[i] = black_outline(_("Oh No!"), font, &white);
+ ohno[i] = BlackOutline(_("Oh No!"), font, &white);
}
if (sys_sound) {
@@ -340,7 +877,7 @@
} else
LOG( "=NO SOUND FX LOADED (not selected)\n" );
- pause_load_media();
+ PauseLoadMedia();
LOG( "=Setting NULL fish & splat & word\n" );
@@ -358,17 +895,19 @@
LOG( "=LoadOthers() END\n" );
}
-void debugDISPLAY( unsigned char *msg, int x, int y ) {
- SDL_Surface *m;
- m = TTF_RenderUTF8_Shaded( font, msg, white, white );
+static void display_msg(const unsigned char *msg, int x, int y)
+{
+ SDL_Surface* m;
+ m = TTF_RenderUTF8_Shaded(font, msg, white, white);
EraseObject(m, x, y);
DrawObject(m, x, y);
+ SDL_FreeSurface(m);
}
/***************************
LoadFishies : Load the fish animations and graphics
*****************************/
-void LoadFishies( void ) {
+static void LoadFishies( void ) {
int i;
LOG( "=LoadFishies()\n" );
@@ -388,7 +927,7 @@
/******************************
LoadTuxAnims : Load the Tux graphics and animations
*******************************/
-void LoadTuxAnims( void ) {
+static void LoadTuxAnims( void ) {
int i;
int height = 0; //temp width/height varis to determine max's
@@ -408,9 +947,9 @@
/******************************
DrawNumbers : Draw numbers at
a certain x,y. See "usage"
-bellow
+below
*******************************/
-void DrawNumbers(int num, int x, int y, int places) {
+static void DrawNumbers(int num, int x, int y, int places) {
//usage:
// num = number to draw onscreen
// x, y = coords to place number (starting upper left)
@@ -446,7 +985,8 @@
EraseNumbers: Erase numbers
from the screen. See "usage"
*****************************/
-void EraseNumbers(int num, int x, int y, int places) {
+static void EraseNumbers(int num, int x, int y, int places)
+{
//usage:
// num = number to draw onscreen
// x, y = coords to place number (starting upper left)
@@ -481,7 +1021,7 @@
FreeGame : Free all
the game elements
***********************/
-void FreeGame( void ) {
+static void FreeGame( void ) {
int i;
FreeLetters();
@@ -526,7 +1066,7 @@
Mix_FreeChunk(sound[i]);
}
- pause_unload_media();
+ PauseUnloadMedia();
LOG( "FreeGame(): END\n" );
@@ -539,7 +1079,8 @@
loading new backgrounds,
or clearing game screen
****************************/
-void DrawBackground( void ) {
+static void DrawBackground(void)
+{
struct blit *update;
LOG( "-DrawBackground(): Updating entire background\n" );
@@ -561,7 +1102,7 @@
SpawnFishies: Spawn the fishes
in the key cascade game
*****************************/
-void SpawnFishies(int diflevel, int *fishies, int *frame ) {
+static void SpawnFishies(int diflevel, int *fishies, int *frame ) {
int i, spacing;
wchar_t* new_word;
@@ -583,7 +1124,7 @@
/* so we can't just use strlen() anymore - DSB.*/
LOG( "=>Spawning fishy\n" );
- new_word = WORDS_get();
+ new_word = GetWord();
/* If we get to here, it should be OK to actually spawn the fishy: */
fish_object[*fishies].word = new_word;
@@ -631,7 +1172,8 @@
CheckFishies : Check all the fishies and splats.
sort the splats and fishies
****************************/
-void CheckFishies(int *fishies, int *splats) {
+static void CheckFishies(int *fishies, int *splats)
+{
int forward, backward;
struct fishypoo fish_temp;
struct splatter splat_temp;
@@ -691,13 +1233,14 @@
}
// Restrict x to a value in the range from a ... b
-int int_restrict(int a, int x, int b) {
+static int int_restrict(int a, int x, int b) {
if (x < a) x = a;
if (x > b) x = b;
return x;
}
-float float_restrict(float a, float x, float b) {
+static float float_restrict(float a, float x, float b)
+{
if (x < a) x = a;
if (x > b) x = b;
return x;
@@ -706,7 +1249,7 @@
/***************************
AddSplat: A fish has died, add a splat where he used to be
****************************/
-void AddSplat(int *splats, struct fishypoo *f, int *curlives, int *frame) {
+static void AddSplat(int *splats, struct fishypoo *f, int *curlives, int *frame) {
int i;
for ( i = 0; i < f->len; i++ ) {
@@ -729,7 +1272,7 @@
-void DrawFish( int which )
+static void DrawFish( int which )
{
/* LOG ("Entering DrawFish()\n");*/
int j = 0;
@@ -817,7 +1360,7 @@
move the fishies according
to their settings
*****************************/
-void MoveFishies(int *fishies, int *splats, int *lifes, int *frame) {
+static void MoveFishies(int *fishies, int *splats, int *lifes, int *frame) {
int i, j;
// LOG("start MoveFishies\n");
@@ -899,7 +1442,7 @@
and Fishies. If collided,
perform appropriate action
***************************/
-void CheckCollision(int fishies, int *fish_left, int frame ) {
+static void CheckCollision(int fishies, int *fish_left, int frame ) {
int i, j;
// LOG( "start CheckCollision\n" );
@@ -938,7 +1481,7 @@
// LOG( "end CheckCollision\n" );
}
-void next_tux_frame(void) {
+static void next_tux_frame(void) {
if ( tux_object.state != TUX_GULPING ) {
next_frame(tux_object.spr[tux_object.state][tux_object.facing]);
@@ -952,7 +1495,7 @@
/***********************************
MoveTux : Update Tux's location & then blit him!
************************************/
-void MoveTux( int frame, int fishies ) {
+static void MoveTux( int frame, int fishies ) {
int i;
int which=-1, time_to_splat=0;
@@ -1020,7 +1563,7 @@
if ((frame % 8) == 0) next_tux_frame();
}
-void draw_bar(int curlevel, int diflevel, int curlives, int oldlives, int fish_left, int oldfish_left) {
+static void draw_bar(int curlevel, int diflevel, int curlives, int oldlives, int fish_left, int oldfish_left) {
/* --- draw difficulty --- */
DrawObject(level[diflevel], 1, 1);
@@ -1051,498 +1594,6 @@
-/*************************************************************************
-* PlayCascade : This is the main Cascade game loop *
-*************************************************************************/
-int PlayCascade( int diflevel ) {
- unsigned char filename[FNLEN];
- int still_playing = 1;
- int playing_level = 1;
- int setup_new_level = 1;
- int won_level = 0;
- int quitting = 0;
- int curlevel = 0;
- int i;
- int curlives;
- int oldlives=0, oldfish_left=0;
- int fish_left, fishies = 0, local_max_fishies=1;
- int frame = 0;
- int done_frames;
- int splats = 0;
- SDL_Event event;
- SDL_Surface *temp_text[CONGRATS_FRAMES + OH_NO_FRAMES];
- SDL_Rect text_rect;
- int text_y_end;
- int xamp, yamp, x_not, y_not;
- int temp_text_frames;
- int temp_text_count;
- Uint16 key_unicode;
- DEBUGCODE {
- fprintf(stderr, "->PlayCascade: level=%i\n", diflevel );
- }
- SDL_WarpMouse(screen->w / 2, screen->h / 2);
- SDL_ShowCursor(0);
- SNOW_init();
-
- LoadTuxAnims();
- LoadFishies();
- LoadOthers();
- LOG( " before RenderLetters()\n" );
- RenderLetters(font);
- LOG( " after RenderLetters()\n" );
-
- LOG( " starting game \n ");
- while (still_playing) {
-
- if (setup_new_level) {
-
- switch (diflevel) {
- case EASY:
- fish_left = MAX_FISHIES_EASY;
- if (o_lives > LIVES_INIT_EASY){
- curlives = o_lives;
- }else
- curlives = LIVES_INIT_EASY;
- break;
- case MEDIUM:
- fish_left = MAX_FISHIES_MEDIUM;
- if (o_lives > LIVES_INIT_MEDIUM){
- curlives = o_lives;
- }else
- curlives = LIVES_INIT_MEDIUM;
- break;
- case HARD:
- fish_left = MAX_FISHIES_HARD;
- if (o_lives > LIVES_INIT_HARD){
- curlives = o_lives;
- }else
- curlives = LIVES_INIT_HARD;
- break;
- }
-
- local_max_fishies = fish_left;
-
- if (curlevel != 0) {
- SDL_FreeSurface(background);
- }
-
- if (diflevel == INF_PRACT)
- sprintf(filename, "pract.png");
- else
- sprintf(filename, "kcas%i_%i.jpg", diflevel+1, curlevel+1);
-
- /* --- Special Hidden Code --- */
-
- if (hidden && curlevel == 3)
- sprintf(filename, "hidden.jpg");
-
- DEBUGCODE {
- fprintf(stderr, "->>Loading background: %s\n", filename);
- }
-
- background = LoadImage( filename, IMG_REGULAR );
- SNOW_setBkg( background );
-
- DrawBackground();
-
- ResetObjects();
-
- if (sys_sound) {
- sprintf(filename, "kmus%i.wav", curlevel + 1);
- audioMusicLoad( filename, -1 );
- }
-
- LOG( "->>PLAYING THE GAME\n" );
-
- setup_new_level = 0;
- }
-
- /* --- Poll input queue, get keyboard info --- */
-
- while (playing_level) {
-
- oldlives = curlives;
- oldfish_left = fish_left;
-
- EraseSprite( tux_object.spr[tux_object.state][tux_object.facing], tux_object.x, tux_object.y );
-
- /* --- Checking input --- */
-
- while ( SDL_PollEvent( &event ) )
- if ( event.type == SDL_QUIT ) {
- exit(0);
- } else if (event.type == SDL_KEYDOWN) {
-
- if (event.key.keysym.sym == SDLK_F11)
- SDL_SaveBMP( screen, "screenshot.bmp" );
- if (event.key.keysym.sym == SDLK_F6){
- o_lives=o_lives-10;
- curlives=curlives-10;
- }
- if (event.key.keysym.sym == SDLK_F7) {
- o_lives=o_lives+10;
- curlives=curlives+10;
- }
- if (event.key.keysym.sym == SDLK_F12)
- SNOW_toggle();
- if (event.key.keysym.sym == SDLK_ESCAPE) {
-
- if (Pause() == 1) {
- playing_level = 0;
- still_playing = 0;
- quitting = 1;
- }
- DrawBackground();
- }
-
-// /* ASCII lowercase is 97-122, whereas uppercase is */
-// /* 65-90 - this if() converts lowercase to corresponding */
-// /* uppercase - not sure we always want this! */
-// if (((event.key.keysym.unicode & 0xff) >= 97) & ((event.key.keysym.unicode & 0xff) <= 122)){
-// UpdateTux(KEYMAP[(event.key.keysym.unicode & 0xff)-32], fishies, frame);
-// } else {
-// UpdateTux(KEYMAP[(event.key.keysym.unicode & 0xff)], fishies, frame);
-// }
-
- key_unicode = event.key.keysym.unicode & 0xff;
- /* For now, tuxtype is case-insensitive for input, */
- /* with only uppercase for answers: */
- DEBUGCODE
- {
- fprintf(stderr,
- "\nkey_unicode = %d\twchar_t = %lc\tKEYMAP[key_unicode] = %c\n",
- key_unicode, key_unicode, KEYMAP[key_unicode]);
- }
-
- if (key_unicode >= 97 && key_unicode <= 122)
- key_unicode -= 32; //convert lowercase to uppercase
- if (key_unicode >= 224 && key_unicode <= 255)
- key_unicode -= 32; //same for non-US chars
-
- LOG ("After checking for lower case:\n");
- DEBUGCODE
- {
- fprintf(stderr,
- "key_unicode = %d\twchar_t = %lc\tKEYMAP[key_unicode] = %c\n\n",
- key_unicode, key_unicode, KEYMAP[key_unicode]);
- }
-
- /* Now update with case-folded value: */
- UpdateTux(KEYMAP[key_unicode], fishies, frame);
- }
-
- /* --- fishy updates --- */
-
- if ((frame % 10) == 0) next_frame( fishy );
-
- if (fishies < local_max_fishies)
- SpawnFishies( diflevel, &fishies, &frame );
-
- MoveTux( frame, fishies );
- CheckCollision(fishies, &fish_left, frame );
- DrawSprite( tux_object.spr[tux_object.state][tux_object.facing], tux_object.x, tux_object.y );
- MoveFishies(&fishies, &splats, &curlives, &frame);
- CheckFishies(&fishies, &splats);
- SNOW_update();
-
- /* --- update top score/info bar --- */
-
- if (diflevel != INF_PRACT) {
- draw_bar(curlevel, diflevel, curlives, oldlives, fish_left, oldfish_left);
-
- if (curlives <= 0) {
- playing_level = 0;
- still_playing = 0;
- }
- } else
- fish_left = 1; // in practice there is always 1 fish left!
-
- if (fish_left <= 0) {
- won_level = 1;
- playing_level = 0;
- curlevel++;
- setup_new_level = 1;
- still_playing = 1;
- }
-
- if (!quitting) {
- UpdateScreen(&frame);
-
- if (speed_up == 0)
- WaitFrame();
- }
- }
-
- if (sys_sound)
- Mix_FadeOutMusic(MUSIC_FADE_OUT_MS);
-
- DrawBackground();
-
- if (quitting == 0) {
-
- if (won_level) {
-
- won_level = 0;
- if (curlevel < 4) {
-
- LOG( "--->NEXT LEVEL!\n" );
-
- done_frames = MAX_END_FRAMES_BETWEEN_LEVELS;
- playing_level = 1;
- xamp = 0;
- yamp = 0;
-
- } else {
-
- LOG( "--->WINNER!\n" );
-
- done_frames = MAX_END_FRAMES_WIN_GAME;
- still_playing = 0;
- xamp = WIN_GAME_XAMP;
- yamp = WIN_GAME_YAMP;
-
- if (sys_sound)
- Mix_PlayChannel(WINFINAL_WAV, sound[WINFINAL_WAV], 0);
- }
-
- if (sys_sound)
- Mix_PlayChannel(WIN_WAV, sound[WIN_WAV], 0);
-
- for (i = 0; i < CONGRATS_FRAMES; i++)
- temp_text[i] = congrats[i];
-
- temp_text_frames = CONGRATS_FRAMES;
- tux_object.state = TUX_WINNING;
-
- } else {
-
- LOG( "--->LOST :(\n" );
-
- done_frames = MAX_END_FRAMES_GAMEOVER;
- xamp = 0;
- yamp = 0;
-
- if (sys_sound)
- Mix_PlayChannel(LOSE_WAV, sound[LOSE_WAV], 0);
-
- for (i = 0; i < OH_NO_FRAMES; i++)
- temp_text[i] = ohno[i];
-
- temp_text_frames = OH_NO_FRAMES;
- tux_object.state = TUX_YIPING;
- }
-
- /* --- draw the animation here --- */
-
- temp_text_count = 0;
- text_y_end = (screen->h / 2) - (temp_text[0]->h / 2);
- text_rect.x = (screen->w / 2) - (temp_text[0]->w / 2);
- text_rect.y = screen->h - temp_text[0]->h - 1;
- x_not = text_rect.x;
-
- LOG( "--->Starting Ending Animation\n" );
-
- for ( i=0; i<= done_frames; i++ ) {
- temp_text_count = (temp_text_count+1) % temp_text_frames;
-
- text_rect.y -= END_FRAME_DY;
- y_not = text_rect.y;
-
- if (text_rect.y < text_y_end) {
- y_not = text_y_end + yamp * sin(i / WIN_GAME_ANGLE_MULT);
- text_rect.y = text_y_end;
- text_rect.x = x_not + xamp * cos(i / WIN_GAME_ANGLE_MULT);
- }
-
- DrawSprite( tux_object.spr[tux_object.state][tux_object.facing], tux_object.x, tux_object.y );
- DrawObject(temp_text[temp_text_count], text_rect.x, y_not);
- DrawObject(level[diflevel], 1, 1);
- draw_bar(curlevel - 1, diflevel, curlives, oldlives, fish_left, oldfish_left);
-
- next_tux_frame();
- SNOW_update();
- UpdateScreen(&frame);
-
- EraseSprite( tux_object.spr[tux_object.state][tux_object.facing], tux_object.x, tux_object.y );
-
- EraseObject(temp_text[temp_text_count], text_rect.x, y_not);
-
- if (speed_up == 0)
- WaitFrame();
- }
- }
- }
-
- SNOW_on = 0;
-
- LOG( "->Done with level... cleaning up\n" );
-
- FreeGame();
-
- LOG( "->PlayCascade: END\n" );
-
- return 1;
-}
-
-/*************************************************/
-/* TransWipe: Performs various wipes to new bkgs */
-/*************************************************/
-/*
- * Given a wipe request type, and any variables
- * that wipe requires, will perform a wipe from
- * the current screen image to a new one.
- */
-void TransWipe(SDL_Surface * newbkg, int type, int var1, int var2)
-{
- int i, j, x1, x2, y1, y2;
- int step1, step2, step3, step4;
- int frame;
- SDL_Rect src;
- SDL_Rect dst;
-
- LOG("->TransWipe(): START\n");
-
- numupdates = 0;
- frame = 0;
-
- if(newbkg->w == screen->w && newbkg->h == screen->h) {
- if( type == RANDOM_WIPE )
- type = (RANDOM_WIPE* ((float) rand()) / (RAND_MAX+1.0));
-
- switch( type ) {
- case WIPE_BLINDS_VERT: {
- LOG("--+ Doing 'WIPE_BLINDS_VERT'\n");
- /* var1 is num of divisions
- var2 is how many frames animation should take */
- if( var1 < 1 ) var1 = 1;
- if( var2 < 1 ) var2 = 1;
- step1 = screen->w / var1;
- step2 = step1 / var2;
-
- for(i = 0; i <= var2; i++) {
- for(j = 0; j <= var1; j++) {
- x1 = step1 * (j - 0.5) - i * step2 + 1;
- x2 = step1 * (j - 0.5) + i * step2 + 1;
- src.x = x1;
- src.y = 0;
- src.w = step2;
- src.h = screen->h;
- dst.x = x2;
- dst.y = 0;
- dst.w = step2;
- dst.h = screen->h;
- SDL_BlitSurface(newbkg, &src, screen, &src);
- SDL_BlitSurface(newbkg, &dst, screen, &dst);
- AddRect(&src, &src);
- AddRect(&dst, &dst);
- }
- UpdateScreen(&frame);
- }
-
- src.x = 0;
- src.y = 0;
- src.w = screen->w;
- src.h = screen->h;
- SDL_BlitSurface(newbkg, NULL, screen, &src);
- SDL_Flip(screen);
-
- break;
- } case WIPE_BLINDS_HORIZ: {
- LOG("--+ Doing 'WIPE_BLINDS_HORIZ'\n");
- /* var1 is num of divisions
- var2 is how many frames animation should take */
- if( var1 < 1 ) var1 = 1;
- if( var2 < 1 ) var2 = 1;
- step1 = screen->h / var1;
- step2 = step1 / var2;
-
- for(i = 0; i <= var2; i++) {
- for(j = 0; j <= var1; j++) {
- y1 = step1 * (j - 0.5) - i * step2 + 1;
- y2 = step1 * (j - 0.5) + i * step2 + 1;
- src.x = 0;
- src.y = y1;
- src.w = screen->w;
- src.h = step2;
- dst.x = 0;
- dst.y = y2;
- dst.w = screen->w;
- dst.h = step2;
- SDL_BlitSurface(newbkg, &src, screen, &src);
- SDL_BlitSurface(newbkg, &dst, screen, &dst);
- AddRect(&src, &src);
- AddRect(&dst, &dst);
- }
- UpdateScreen(&frame);
- }
-
- src.x = 0;
- src.y = 0;
- src.w = screen->w;
- src.h = screen->h;
- SDL_BlitSurface(newbkg, NULL, screen, &src);
- SDL_Flip(screen);
-
- break;
- } case WIPE_BLINDS_BOX: {
- LOG("--+ Doing 'WIPE_BLINDS_BOX'\n");
- /* var1 is num of divisions
- var2 is how many frames animation should take */
- if( var1 < 1 ) var1 = 1;
- if( var2 < 1 ) var2 = 1;
- step1 = screen->w / var1;
- step2 = step1 / var2;
- step3 = screen->h / var1;
- step4 = step1 / var2;
-
- for(i = 0; i <= var2; i++) {
- for(j = 0; j <= var1; j++) {
- x1 = step1 * (j - 0.5) - i * step2 + 1;
- x2 = step1 * (j - 0.5) + i * step2 + 1;
- src.x = x1;
- src.y = 0;
- src.w = step2;
- src.h = screen->h;
- dst.x = x2;
- dst.y = 0;
- dst.w = step2;
- dst.h = screen->h;
- SDL_BlitSurface(newbkg, &src, screen, &src);
- SDL_BlitSurface(newbkg, &dst, screen, &dst);
- AddRect(&src, &src);
- AddRect(&dst, &dst);
- y1 = step3 * (j - 0.5) - i * step4 + 1;
- y2 = step3 * (j - 0.5) + i * step4 + 1;
- src.x = 0;
- src.y = y1;
- src.w = screen->w;
- src.h = step4;
- dst.x = 0;
- dst.y = y2;
- dst.w = screen->w;
- dst.h = step4;
- SDL_BlitSurface(newbkg, &src, screen, &src);
- SDL_BlitSurface(newbkg, &dst, screen, &dst);
- AddRect(&src, &src);
- AddRect(&dst, &dst);
- }
- UpdateScreen(&frame);
- }
-
- src.x = 0;
- src.y = 0;
- src.w = screen->w;
- src.h = screen->h;
- SDL_BlitSurface(newbkg, NULL, screen, &src);
- SDL_Flip(screen);
-
- break;
- } default:
- break;
- }
- }
-}
-
Modified: tuxtype/trunk/tuxtype/practice.c
===================================================================
--- tuxtype/trunk/tuxtype/practice.c 2007-05-29 21:53:02 UTC (rev 184)
+++ tuxtype/trunk/tuxtype/practice.c 2007-06-07 18:54:49 UTC (rev 185)
@@ -59,7 +59,7 @@
for (i=1; i<255; i++)
if (ALPHABET[i]) {
let[0]=i;
- letters[i] = black_outline(let, font, &white);
+ letters[i] = BlackOutline(let, font, &white);
}
LOG("DONE - Loading practice media\n");
@@ -315,7 +315,7 @@
c++;
} else {
if ( event.key.keysym.sym != SDLK_RSHIFT && event.key.keysym.sym != SDLK_LSHIFT )
- playsound( wrong );
+ PlaySound(wrong);
}
}
}
Modified: tuxtype/trunk/tuxtype/scripting.c
===================================================================
--- tuxtype/trunk/tuxtype/scripting.c 2007-05-29 21:53:02 UTC (rev 184)
+++ tuxtype/trunk/tuxtype/scripting.c 2007-06-07 18:54:49 UTC (rev 185)
@@ -18,7 +18,271 @@
#include "scripting.h"
-char *getQuote(const char *in) {
+/* Local function prototypes: */
+static void clear_items(itemType* i);
+static void clear_pages(pageType* p);
+static void close_script(void);
+static SDL_Color* get_color(const char* in);
+static int get_int(const char* in);
+static char* get_quote(const char* in);
+static char hex2int(char b, char s);
+static int load_script(const char* fn);
+static void run_script(void);
+
+/************************************************************************/
+/* */
+/* "Public" functions (callable throughout program) */
+/* */
+/************************************************************************/
+
+
+void InstructCascade(void)
+{
+ char fn[FNLEN];
+ sprintf( fn, "%s/scripts/cascade.xml", realPath[useEnglish] );
+ if (load_script( fn ) != 0) return; // bail if any errors occur
+ run_script();
+}
+
+
+void InstructLaser(void)
+{
+ char fn[FNLEN];
+ sprintf( fn, "%s/scripts/laser.xml", realPath[useEnglish] );
+ if (load_script( fn ) != 0) return; // bail if any errors occur
+ { int i; for (i=0; i<20; i++) {
+ run_script(); SDL_Delay(500); }}
+}
+
+
+void ProjectInfo(void)
+{
+ char fn[FNLEN];
+ sprintf( fn, "%s/scripts/projectInfo.xml", realPath[1]);
+ if (load_script( fn ) != 0) return; // bail if any errors occur
+ run_script();
+}
+
+
+void TestLesson( void ) {
+ SDL_Surface *left, *right, *pointer, *bkg;
+ SDL_Surface *filenames[200];
+
+ SDL_Rect spot, arrow_area;
+ SDL_Rect leftRect, rightRect;
+ SDL_Rect titleRects[8];
+
+ int stop = 0;
+ int loc = 0;
+ int old_loc = 1;
+ int i;
+ int c = 0;
+
+ char fn[FNLEN];
+ unsigned char wordlistFile[200][200];
+ unsigned char wordPath[FNLEN];
+
+ DIR *wordsDir;
+ struct dirent *wordsFile;
+// FILE *tempFile;
+
+ pointer = LoadImage( "right.png", IMG_ALPHA );
+ bkg = LoadImage( "main_bkg.png", IMG_REGULAR );
+
+ SDL_ShowCursor(0);
+
+ /* find the directory to load wordlists from */
+
+ for (i=useEnglish; i<2; i++) {
+ sprintf( wordPath, "%s/scripts", realPath[i] );
+ if (CheckFile(wordPath))
+ break;
+ }
+
+ if (i==2) {
+ fprintf(stderr, "ERROR: Unable to find wordlist directory\n");
+ exit(1);
+ }
+ spot.x=60;
+ spot.y=20;
+
+
+ /* create a list of all the .txt files */
+
+ wordsDir = opendir( wordPath );
+ font = LoadFont( ttf_font, 14 );
+ do {
+ wordsFile = readdir(wordsDir);
+ if (!wordsFile)
+ break;
+
+ /* must have at least .txt at the end */
+ if (strlen(wordsFile->d_name) < 5)
+ continue;
+
+ if (strcmp(&wordsFile->d_name[strlen(wordsFile->d_name)-4],".xml"))
+ continue;
+
+ sprintf( wordlistFile[c], "%s", wordsFile->d_name );
+
+ filenames[c] = TTF_RenderUTF8_Blended( font, wordsFile->d_name, white);
+ SDL_BlitSurface( filenames[c], NULL, screen, &spot );
+ SDL_FreeSurface(filenames[c]);
+ c++;
+ spot.y+=18;
+
+ /* load the name for the wordlist from the file ... (1st line) */
+/* tempFile = fopen( wordlistFile[lists], "r" );
+ if (tempFile==NULL) continue;
+ fscanf( tempFile, "%[^\n]\n", wordlistName[lists] );
+*/
+ /* check to see if it has a \r at the end of it (dos format!) */
+/* if (wordlistName[lists][ strlen(wordlistName[lists])-1 ] == '\r')
+ wordlistName[lists][ strlen(wordlistName[lists])-1 ] = '\0';
+ lists++;
+
+ fclose(tempFile);*/
+
+ } while (1);
+
+ TTF_CloseFont(font);
+ closedir( wordsDir );
+ SDL_Flip( screen );
+
+ left = LoadImage("left.png", IMG_ALPHA);
+ leftRect.w = left->w; leftRect.h = left->h;
+ leftRect.x = 320 - 80 - (leftRect.w/2); leftRect.y = 430;
+
+ right = LoadImage("right.png", IMG_ALPHA);
+ rightRect.w = right->w; rightRect.h = right->h;
+ rightRect.x = 320 + 80 - (rightRect.w/2); rightRect.y = 430;
+
+ /* set initial rect sizes */
+ titleRects[0].y = 30;
+ titleRects[0].w = titleRects[0].h = titleRects[0].x = 0;
+ for (i = 1; i<8; i++) {
+ titleRects[i].y = titleRects[i-1].y + 50;
+ titleRects[i].w = titleRects[i].h = titleRects[i].x = 0;
+ }
+ arrow_area.x = 0;
+ arrow_area.y = 0;
+ arrow_area.w = 59;
+ arrow_area.h = 479;
+
+ while (!stop) {
+ while (SDL_PollEvent(&event))
+ switch (event.type) {
+ case SDL_QUIT:
+ exit(0);
+ break;
+ case SDL_MOUSEMOTION:
+ for (i=0; (i<8) && (loc-(loc%8)+i<c); i++)
+ if (inRect( titleRects[i], event.motion.x, event.motion.y )) {
+ loc = loc-(loc%8)+i;
+ break;
+ }
+
+ break;
+ case SDL_MOUSEBUTTONDOWN:
+ if (inRect( leftRect, event.button.x, event.button.y ))
+ if (loc-(loc%8)-8 >= 0) {
+ loc=loc-(loc%8)-8;
+ break;
+ }
+ if (inRect( rightRect, event.button.x, event.button.y ))
+ if (loc-(loc%8)+8 < c) {
+ loc=loc-(loc%8)+8;
+ break;
+ }
+ for (i=0; (i<8) && (loc-(loc%8)+i<c); i++)
+ if (inRect(titleRects[i], event.button.x, event.button.y)) {
+ loc = loc-(loc%8)+i;
+ ClearWordList(); /* clear old selection */
+ if (loc==0)
+ UseAlphabet();
+ else
+ GenerateWordList(wordlistFile[loc]);
+
+ stop = 1;
+ break;
+ }
+ break;
+ case SDL_KEYDOWN:
+ if (event.key.keysym.sym == SDLK_ESCAPE) { stop = 2; break; }
+ if (event.key.keysym.sym == SDLK_RETURN) {
+ sprintf( fn, "%s/scripts/%s", realPath[1], wordlistFile[loc]);
+ stop = 1;
+ break;
+ }
+
+ if ((event.key.keysym.sym == SDLK_LEFT) || (event.key.keysym.sym == SDLK_PAGEUP)) {
+ if (loc-(loc%8)-8 >= 0)
+ loc=loc-(loc%8)-8;
+ SDL_ShowCursor(1);}
+
+ if ((event.key.keysym.sym == SDLK_RIGHT) || (event.key.keysym.sym == SDLK_PAGEDOWN)) {
+ if (loc-(loc%8)+8 < c)
+ loc=(loc-(loc%8)+8);
+ }
+
+ if (event.key.keysym.sym == SDLK_UP) {
+ if (loc > 0)
+ loc--;
+ }
+
+ if (event.key.keysym.sym == SDLK_DOWN) {
+ if (loc+1< c)
+ loc++;
+ }
+ }
+
+ if (stop == 2) {
+ SDL_FreeSurface(pointer);
+ SDL_FreeSurface(left);
+ SDL_FreeSurface(right);
+ SDL_FreeSurface(bkg);
+ return;
+ }
+ if (old_loc != loc) {
+ int start;
+
+ SDL_BlitSurface( bkg, &arrow_area, screen, NULL);
+
+ start = loc;
+ for (i = start; i < c; i++) {
+ spot.x = 5;
+ spot.y = (i*18)+10;
+ if (i == loc)
+ SDL_BlitSurface(pointer, NULL, screen, &spot);
+ }
+
+ SDL_Flip(screen);
+ }
+ SDL_Delay(40);
+ old_loc = loc;
+ }
+
+ SDL_FreeSurface(pointer);
+ SDL_FreeSurface(left);
+ SDL_FreeSurface(right);
+ SDL_FreeSurface(bkg);
+
+ if (load_script( fn ) != 0) return; // bail if any errors occur
+ run_script();
+ SDL_ShowCursor(1);
+}
+
+
+
+/************************************************************************/
+/* */
+/* "Private" functions (local to scripting.c) */
+/* */
+/************************************************************************/
+
+
+static char* get_quote(const char* in)
+{
int start, finish;
char *out;
@@ -40,8 +304,10 @@
return out;
}
-int getInt(const char *in) {
- char *t = getQuote(in);
+
+static int get_int(const char* in)
+{
+ char *t = get_quote(in);
int ans=-1;
if (t) {
ans = atoi(t);
@@ -50,7 +316,9 @@
return ans;
}
-char hex2int(char b, char s) {
+
+static char hex2int(char b, char s)
+{
char ans=0;
if ((b>='0') && (b<='9')) ans=16*(b-'0');
@@ -64,10 +332,12 @@
return ans;
}
-SDL_Color *getColor(const char *in) {
- char *col;
- SDL_Color *out=malloc(sizeof(SDL_Color));
- col = getQuote(in);
+
+static SDL_Color* get_color(const char* in)
+{
+ char* col;
+ SDL_Color* out=malloc(sizeof(SDL_Color));
+ col = get_quote(in);
if ((strlen(col)==7) && (col[0] == '#')) {
out->r = hex2int( col[1], col[2] );
@@ -84,7 +354,8 @@
pageType *curPage=NULL;
itemType *curItem=NULL;
-int loadScript( const char *fn ) {
+static int load_script(const char* fn)
+{
int i;
char str[FNLEN];
FILE *f;
@@ -93,7 +364,7 @@
if (curScript) {
LOG( "script already in memory, removing now!\n");
- closeScript();
+ close_script();
}
f = fopen( fn, "r" );
@@ -108,16 +379,16 @@
curScript = (scriptType *)calloc(1,sizeof(scriptType));
for (i=7; i<strlen(str) && str[i]!='>'; i++) {
if ((str[i]=='t') && strncmp("title", &str[i], 5)==0)
- curScript->title = getQuote(&str[i+5]);
+ curScript->title = get_quote(&str[i+5]);
if ((str[i]=='b') && strncmp("bgcolor", &str[i], 7)==0)
- curScript->bgcolor = getColor(&str[i+7]);
+ curScript->bgcolor = get_color(&str[i+7]);
if ((str[i]=='b') && strncmp("background", &str[i], 10)==0)
- curScript->background = getQuote(&str[i+10]);
+ curScript->background = get_quote(&str[i+10]);
if ((str[i]=='f') && strncmp("fgcolor", &str[i], 7)==0)
- curScript->fgcolor = getColor(&str[i+7]);
+ curScript->fgcolor = get_color(&str[i+7]);
}
} else if (strncmp("<page", str, 5)==0) {
if (curScript==NULL) { fprintf(stderr, "CRITICAL XML ERROR: <page> should be in a <script> in file %s line (todo)", fn); exit(1); }
@@ -134,16 +405,16 @@
for (i=5; i<strlen(str) && str[i]!='>'; i++) {
if ((str[i]=='b') && strncmp("background", &str[i], 10)==0)
- curPage->background = getQuote(&str[i+10]);
+ curPage->background = get_quote(&str[i+10]);
if ((str[i]=='t') && strncmp("title", &str[i], 5)==0)
- curPage->title = getQuote(&str[i+5]);
+ curPage->title = get_quote(&str[i+5]);
if ((str[i]=='b') && strncmp("bgcolor", &str[i], 7)==0)
- curPage->bgcolor = getColor(&str[i+7]);
+ curPage->bgcolor = get_color(&str[i+7]);
if ((str[i]=='f') && strncmp("fgcolor", &str[i], 7)==0)
- curPage->fgcolor = getColor(&str[i+7]);
+ curPage->fgcolor = get_color(&str[i+7]);
}
} else if (strncmp("<text", str, 5)==0) {
if (curPage==NULL) { fprintf(stderr, "CRITICAL XML ERROR: <text> should be in a <page> in file %s line (todo)", fn); exit(1); }
@@ -161,10 +432,10 @@
for (i=5; i<strlen(str) && str[i]!='>'; i++) {
if ((str[i]=='s') && strncmp("size", &str[i], 4)==0)
- curItem->size = (char)getInt( &str[i+4] );
+ curItem->size = (char)get_int( &str[i+4] );
if ((str[i]=='a') && strncmp("align", &str[i], 5)==0) {
- char *t = getQuote(&str[i+5]);
+ char *t = get_quote(&str[i+5]);
if (strlen(t)>=1) {
if ((t[0] == 'l') || (t[0]=='L')) curItem->align='l'; // left
@@ -177,13 +448,13 @@
}
if ((str[i]=='c') && strncmp("color", &str[i], 5)==0)
- curItem->color = getColor(&str[i+5]);
+ curItem->color = get_color(&str[i+5]);
if ((str[i]=='x') && strncmp(" x=", &str[i-1], 3)==0)
- curItem->x = getInt(&str[i+2]);
+ curItem->x = get_int(&str[i+2]);
if ((str[i]=='y') && strncmp(" y=", &str[i-1], 3)==0)
- curItem->y = getInt(&str[i+2]);
+ curItem->y = get_int(&str[i+2]);
}
@@ -225,20 +496,20 @@
for (i=5; i<strlen(str); i++) {
if ((str[i]=='o') && strncmp("onclickplay", &str[i], 11)==0) {
- curItem->onclick = getQuote(&str[i+3]);
+ curItem->onclick = get_quote(&str[i+3]);
}
if ((str[i]=='x') && strncmp(" x=", &str[i-1], 3)==0)
- curItem->x = getInt(&str[i+2]);
+ curItem->x = get_int(&str[i+2]);
if ((str[i]=='y') && strncmp(" y=", &str[i-1], 3)==0)
- curItem->y = getInt(&str[i+2]);
+ curItem->y = get_int(&str[i+2]);
if ((str[i]=='s') && strncmp("src", &str[i], 3)==0)
- curItem->data = getQuote(&str[i+3]);
+ curItem->data = get_quote(&str[i+3]);
if ((str[i]=='a') && strncmp("align", &str[i], 5)==0) {
- char *t = getQuote(&str[i+5]);
+ char *t = get_quote(&str[i+5]);
if (strlen(t)>=1) {
if ((t[0] == 'l') || (t[0]=='L')) curItem->align='l'; // left
@@ -266,10 +537,10 @@
for (i=5; i<strlen(str); i++) {
if ((str[i]=='s') && strncmp("src", &str[i], 3)==0)
- curItem->data = getQuote(&str[i+3]);
+ curItem->data = get_quote(&str[i+3]);
if ((str[i]=='l') && strncmp("loop", &str[i], 4)==0) {
- char *t = getQuote(&str[i+4]);
+ char *t = get_quote(&str[i+4]);
if (strlen(t)>=1)
if ((t[0] == 't') || (t[0]=='T')) curItem->loop=1;
@@ -291,13 +562,13 @@
for (i=5; i<strlen(str) && str[i]!='>'; i++) {
if ((str[i]=='s') && strncmp("size", &str[i], 4)==0)
- curItem->size = (char)getInt( &str[i+4] );
+ curItem->size = (char)get_int( &str[i+4] );
if ((str[i]=='g') && strncmp("goal", &str[i], 4)==0)
- curItem->goal = (char)getInt( &str[i+4] );
+ curItem->goal = (char)get_int( &str[i+4] );
if ((str[i]=='a') && strncmp("align", &str[i], 5)==0) {
- char *t = getQuote(&str[i+5]);
+ char *t = get_quote(&str[i+5]);
if (strlen(t)>=1) {
if ((t[0] == 'l') || (t[0]=='L')) curItem->align='l'; // left
@@ -309,7 +580,7 @@
}
if ((str[i]=='c') && strncmp("color", &str[i], 5)==0)
- curItem->color = getColor(&str[i+5]);
+ curItem->color = get_color(&str[i+5]);
}
{ /* --- grab the text between <prac> and </prac> --- */
@@ -363,7 +634,8 @@
return 0;
}
-void runScript( void ) {
+static void run_script(void)
+{
Mix_Chunk *sounds[FNLEN];
@@ -644,22 +916,10 @@
}
}
-void InstructCascade(void) {
- char fn[FNLEN];
- sprintf( fn, "%s/scripts/cascade.xml", realPath[useEnglish] );
- if (loadScript( fn ) != 0) return; // bail if any errors occur
- runScript();
-}
-void InstructLaser(void) {
- char fn[FNLEN];
- sprintf( fn, "%s/scripts/laser.xml", realPath[useEnglish] );
- if (loadScript( fn ) != 0) return; // bail if any errors occur
- { int i; for (i=0; i<20; i++) {
- runScript(); SDL_Delay(500); }}
-}
-void clearItems( itemType *i ) {
+static void clear_items(itemType* i)
+{
itemType *n;
while (i) {
n = i->next; // remember the next guy
@@ -677,13 +937,14 @@
}
}
-void clearPages( pageType *p ) {
+static void clear_pages(pageType* p)
+{
pageType *n;
while (p) {
n = p->next; // remember the next guy
/* -- remove all of our sub elements -- */
- clearItems(p->items);
+ clear_items(p->items);
/* -- free anything we are pointing to --- */
free(p->background);
@@ -699,11 +960,13 @@
}
}
-void closeScript( void ) {
+
+static void close_script(void)
+{
if (curScript) {
/* -- remove all the pages we have --*/
- clearPages(curScript->pages);
+ clear_pages(curScript->pages);
/* -- remove attributes we are pointing to -- */
free(curScript->title);
@@ -719,220 +982,6 @@
}
}
-void testLesson( void ) {
- SDL_Surface *left, *right, *pointer, *bkg;
- SDL_Surface *filenames[200];
-
- SDL_Rect spot, arrow_area;
- SDL_Rect leftRect, rightRect;
- SDL_Rect titleRects[8];
-
- int stop = 0;
- int loc = 0;
- int old_loc = 1;
- int i;
- int c = 0;
-
- char fn[FNLEN];
- unsigned char wordlistFile[200][200];
- unsigned char wordPath[FNLEN];
- DIR *wordsDir;
- struct dirent *wordsFile;
- struct stat fileStats;
-// FILE *tempFile;
- pointer = LoadImage( "right.png", IMG_ALPHA );
- bkg = LoadImage( "main_bkg.png", IMG_REGULAR );
- SDL_ShowCursor(0);
-
- /* find the directory to load wordlists from */
-
- for (i=useEnglish; i<2; i++) {
- fileStats.st_mode = 0; // clear last use!
- sprintf( wordPath, "%s/scripts", realPath[i] );
- stat( wordPath, &fileStats );
- if ( fileStats.st_mode & S_IFDIR )
- break;
- }
-
- if (i==2) {
- fprintf(stderr, "ERROR: Unable to find wordlist directory\n");
- exit(1);
- }
- spot.x=60;
- spot.y=20;
-
-
- /* create a list of all the .txt files */
-
- wordsDir = opendir( wordPath );
- font = LoadFont( ttf_font, 14 );
- do {
- wordsFile = readdir(wordsDir);
- if (!wordsFile)
- break;
-
- /* must have at least .txt at the end */
- if (strlen(wordsFile->d_name) < 5)
- continue;
-
- if (strcmp(&wordsFile->d_name[strlen(wordsFile->d_name)-4],".xml"))
- continue;
-
- sprintf( wordlistFile[c], "%s", wordsFile->d_name );
-
- filenames[c] = TTF_RenderUTF8_Blended( font, wordsFile->d_name, white);
- SDL_BlitSurface( filenames[c], NULL, screen, &spot );
- SDL_FreeSurface(filenames[c]);
- c++;
- spot.y+=18;
-
- /* load the name for the wordlist from the file ... (1st line) */
-/* tempFile = fopen( wordlistFile[lists], "r" );
- if (tempFile==NULL) continue;
- fscanf( tempFile, "%[^\n]\n", wordlistName[lists] );
-*/
- /* check to see if it has a \r at the end of it (dos format!) */
-/* if (wordlistName[lists][ strlen(wordlistName[lists])-1 ] == '\r')
- wordlistName[lists][ strlen(wordlistName[lists])-1 ] = '\0';
- lists++;
-
- fclose(tempFile);*/
-
- } while (1);
-
- TTF_CloseFont(font);
- closedir( wordsDir );
- SDL_Flip( screen );
-
- left = LoadImage("left.png", IMG_ALPHA);
- leftRect.w = left->w; leftRect.h = left->h;
- leftRect.x = 320 - 80 - (leftRect.w/2); leftRect.y = 430;
-
- right = LoadImage("right.png", IMG_ALPHA);
- rightRect.w = right->w; rightRect.h = right->h;
- rightRect.x = 320 + 80 - (rightRect.w/2); rightRect.y = 430;
-
- /* set initial rect sizes */
- titleRects[0].y = 30;
- titleRects[0].w = titleRects[0].h = titleRects[0].x = 0;
- for (i = 1; i<8; i++) {
- titleRects[i].y = titleRects[i-1].y + 50;
- titleRects[i].w = titleRects[i].h = titleRects[i].x = 0;
- }
- arrow_area.x = 0;
- arrow_area.y = 0;
- arrow_area.w = 59;
- arrow_area.h = 479;
-
- while (!stop) {
- while (SDL_PollEvent(&event))
- switch (event.type) {
- case SDL_QUIT:
- exit(0);
- break;
- case SDL_MOUSEMOTION:
- for (i=0; (i<8) && (loc-(loc%8)+i<c); i++)
- if (inRect( titleRects[i], event.motion.x, event.motion.y )) {
- loc = loc-(loc%8)+i;
- break;
- }
-
- break;
- case SDL_MOUSEBUTTONDOWN:
- if (inRect( leftRect, event.button.x, event.button.y ))
- if (loc-(loc%8)-8 >= 0) {
- loc=loc-(loc%8)-8;
- break;
- }
- if (inRect( rightRect, event.button.x, event.button.y ))
- if (loc-(loc%8)+8 < c) {
- loc=loc-(loc%8)+8;
- break;
- }
- for (i=0; (i<8) && (loc-(loc%8)+i<c); i++)
- if (inRect(titleRects[i], event.button.x, event.button.y)) {
- loc = loc-(loc%8)+i;
- WORDS_init(); /* clear old selection */
- if (loc==0)
- WORDS_use_alphabet();
- else
- WORDS_use( wordlistFile[loc] );
- stop = 1;
- break;
- }
- break;
- case SDL_KEYDOWN:
- if (event.key.keysym.sym == SDLK_ESCAPE) { stop = 2; break; }
- if (event.key.keysym.sym == SDLK_RETURN) {
- sprintf( fn, "%s/scripts/%s", realPath[1], wordlistFile[loc]);
- stop = 1;
- break;
- }
-
- if ((event.key.keysym.sym == SDLK_LEFT) || (event.key.keysym.sym == SDLK_PAGEUP)) {
- if (loc-(loc%8)-8 >= 0)
- loc=loc-(loc%8)-8;
- SDL_ShowCursor(1);}
-
- if ((event.key.keysym.sym == SDLK_RIGHT) || (event.key.keysym.sym == SDLK_PAGEDOWN)) {
- if (loc-(loc%8)+8 < c)
- loc=(loc-(loc%8)+8);
- }
-
- if (event.key.keysym.sym == SDLK_UP) {
- if (loc > 0)
- loc--;
- }
-
- if (event.key.keysym.sym == SDLK_DOWN) {
- if (loc+1< c)
- loc++;
- }
- }
-
- if (stop == 2) {
- SDL_FreeSurface(pointer);
- SDL_FreeSurface(left);
- SDL_FreeSurface(right);
- SDL_FreeSurface(bkg);
- return;
- }
- if (old_loc != loc) {
- int start;
-
- SDL_BlitSurface( bkg, &arrow_area, screen, NULL);
-
- start = loc;
- for (i = start; i < c; i++) {
- spot.x = 5;
- spot.y = (i*18)+10;
- if (i == loc)
- SDL_BlitSurface(pointer, NULL, screen, &spot);
- }
-
- SDL_Flip(screen);
- }
- SDL_Delay(40);
- old_loc = loc;
- }
-
- SDL_FreeSurface(pointer);
- SDL_FreeSurface(left);
- SDL_FreeSurface(right);
- SDL_FreeSurface(bkg);
-
- if (loadScript( fn ) != 0) return; // bail if any errors occur
- runScript();
- SDL_ShowCursor(1);
-}
-
-void projectInfo( void ) {
- char fn[FNLEN];
- sprintf( fn, "%s/scripts/projectInfo.xml", realPath[1]);
- if (loadScript( fn ) != 0) return; // bail if any errors occur
- runScript();
-}
-
Modified: tuxtype/trunk/tuxtype/setup.c
===================================================================
--- tuxtype/trunk/tuxtype/setup.c 2007-05-29 21:53:02 UTC (rev 184)
+++ tuxtype/trunk/tuxtype/setup.c 2007-06-07 18:54:49 UTC (rev 185)
@@ -172,7 +172,7 @@
DEBUGCODE { printf("LoadSettings: Setting language to %s", value); }
strncpy( localsettings.lang, value, FNLEN-1 );
localsettings.lang[FNLEN-1]=0;
- setupTheme( value );
+ SetupTheme(value);
}
if (strncmp( setting, "o_lives", FNLEN ) == 0 ) {
DEBUGCODE { printf("LoadSettings: Setting lives to %s", value); }
Modified: tuxtype/trunk/tuxtype/theme.c
===================================================================
--- tuxtype/trunk/tuxtype/theme.c 2007-05-29 21:53:02 UTC (rev 184)
+++ tuxtype/trunk/tuxtype/theme.c 2007-06-07 18:54:49 UTC (rev 185)
@@ -47,7 +47,8 @@
* Paths[]. It will always put the theme path first, then
* the default path
*/
-void setupTheme( char *dirName ) {
+void SetupTheme(const char *dirName)
+{
int i;
int found = 0;
useEnglish=1; // default is to use English if we cannot find theme
@@ -99,7 +100,8 @@
}
-void chooseTheme( void ) {
+void ChooseTheme(void)
+{
SDL_Surface *titles[MAX_LANGUAGES];
SDL_Surface *select[MAX_LANGUAGES];
SDL_Surface *left, *right;
@@ -165,11 +167,11 @@
// HACK: is font empty now???
font = LoadFont( ttf_font, ttf_font_size );
- titles[0] = black_outline( "English", font, &white );
- select[0] = black_outline( "English", font, &yellow);
+ titles[0] = BlackOutline( "English", font, &white );
+ select[0] = BlackOutline( "English", font, &yellow);
for (i = 1; i<themes; i++) {
- titles[i] = black_outline( themeNames[i], font, &white );
- select[i] = black_outline( themeNames[i], font, &yellow);
+ titles[i] = BlackOutline( themeNames[i], font, &white );
+ select[i] = BlackOutline( themeNames[i], font, &yellow);
}
world = LoadImage("world.png", IMG_ALPHA);
@@ -233,10 +235,10 @@
loc = loc-(loc%8)+i;
if (loc) {
/* --- set theme --- */
- setupTheme(themePaths[loc]);
+ SetupTheme(themePaths[loc]);
} else {
/* --- english --- */
- setupTheme(NULL);
+ SetupTheme(NULL);
}
stop = 1;
break;
@@ -252,10 +254,10 @@
if (event.key.keysym.sym == SDLK_RETURN) {
if (loc) {
/* --- set theme --- */
- setupTheme(themePaths[loc]);
+ SetupTheme(themePaths[loc]);
} else {
/* --- english --- */
- setupTheme(NULL);
+ SetupTheme(NULL);
}
stop = 1;
break;
@@ -290,7 +292,7 @@
SDL_BlitSurface( world, NULL, screen, &worldRect );
- if (loc) setupTheme(themePaths[loc]); else setupTheme(NULL);
+ if (loc) SetupTheme(themePaths[loc]); else SetupTheme(NULL);
map = LoadImage( "map.png", IMG_ALPHA|IMG_NOT_REQUIRED );
if (map) {
Modified: tuxtype/trunk/tuxtype/titlescreen.c
===================================================================
--- tuxtype/trunk/tuxtype/titlescreen.c 2007-05-29 21:53:02 UTC (rev 184)
+++ tuxtype/trunk/tuxtype/titlescreen.c 2007-06-07 18:54:49 UTC (rev 185)
@@ -53,242 +53,30 @@
/* These are the rectangular mouse event "buttons" for each menu item */
SDL_Rect menu_button[TITLE_MENU_ITEMS + 1]; // size of "button"
-int chooseWordlist( void );
-void draw_button( int id, sprite *s ) {
- SDL_Rect button;
+/* Local function prototypes: */
+static int chooseWordlist(void);
+static void draw_button(int id, sprite* s);
+static void not_implemented(void);
+static void load_media(void);
+static void load_menu(void);
+static void unload_media(void);
+static void unload_menu(void);
- button.x = menu_button[id].x;
- button.y = menu_button[id].y;
- button.w = s->frame[0]->w;
- button.h = s->frame[0]->h;
- SDL_BlitSurface(s->frame[0], NULL, screen, &button);
- button.w = s->frame[1]->w;
- for (button.x += s->frame[0]->w; button.x < (menu_button[id].x + menu_width[menu_depth]); button.x += s->frame[1]->w)
- SDL_BlitSurface(s->frame[1], NULL, screen, &button);
- button.w = s->frame[2]->w;
- SDL_BlitSurface(s->frame[2], NULL, screen, &button);
-}
+/************************************************************************/
+/* */
+/* "Public" functions (callable throughout program) */
+/* */
+/************************************************************************/
-void TitleScreen_load_menu( void ) {
- unsigned char fn[FNLEN];
- int max, i, j;
- SDL_ShowCursor(1);
- LOG("loading & parsing menu\n");
-
- for (j = 1; j <= TITLE_MENU_DEPTH; j++) /* Each 'depth' is a different menu */
- {
- max = 0;
- for (i = 1; i <= TITLE_MENU_ITEMS; i++)
- {
- DEBUGCODE
- {
- fprintf(stderr, "i = '%d'\tj = '%d'\ttext = '%s'\n",
- i, j, _((unsigned char*)menu_text[i][j]));
- }
- /* --- create text surfaces --- */
- reg_text[i][j] = black_outline( _((unsigned char*)menu_text[i][j]), font, &white);
- sel_text[i][j] = black_outline( _((unsigned char*)menu_text[i][j]), font, &yellow);
-
- if (sel_text[i][j]->w > max)
- max = sel_text[i][j]->w;
-
- /* --- load animated icon for menu item --- */
- sprintf(fn, "menu/%s", menu_icon[i][j]);
- menu_gfx[i][j] = LoadSprite(fn, IMG_ALPHA);
- }
- menu_width[j] = max + 20 + 40; // Not clear where '20' and '40' are coming from
- }
-
- LOG("done creating graphics, now setting positions\n");
-
-
- /* --- setup menu item destinations --- */
-
-
- menu_button[1].x = 240;
- menu_button[1].y = 100;
- menu_button[1].w = menu_width[1]; //calc from width of widest menu item
- menu_button[1].h = sel->frame[1]->h; //height of sprite image
-
- menu_gfxdest[1].x = menu_button[1].x + 6; // inset graphic by (6, 4) */
- menu_gfxdest[1].y = menu_button[1].y + 4;
- menu_gfxdest[1].w = 40;
- menu_gfxdest[1].h = 50;
-
- text_dst[1].y = menu_button[1].y+15;
-
- /* FIXME each menu item drawn hardcoded 60 pixels below last - */
- /* perhaps increment should be "menu_button[j-1].h + MENU_ITEM_GAP" */
- for (j=2; j<6; j++)
- {
- /* --- setup vertical location of button text --- */
- text_dst[j].y = text_dst[j-1].y + 60;
-
- /* --- setup location of button background --- */
- menu_button[j].x = menu_button[j-1].x;
- menu_button[j].y = menu_button[j-1].y + 60;
- menu_button[j].w = menu_button[j-1].w;
- menu_button[j].h = menu_button[j-1].h;
-
- /* --- setup location of animated icon --- */
- menu_gfxdest[j].x = menu_gfxdest[j-1].x;
- menu_gfxdest[j].y = menu_gfxdest[j-1].y + 60;
- menu_gfxdest[j].w = menu_gfxdest[j-1].w;
- menu_gfxdest[j].h = menu_gfxdest[j-1].h;
- }
-}
-
-void TitleScreen_unload_menu( void ) {
- int i,j;
-
- for (i = 1; i <= TITLE_MENU_ITEMS; i++)
- for (j = 1; j <= TITLE_MENU_DEPTH; j++) {
- SDL_FreeSurface(reg_text[i][j]);
- SDL_FreeSurface(sel_text[i][j]);
- FreeSprite(menu_gfx[i][j]);
- }
-}
-
-void TitleScreen_load_media( void ) {
-
- /* --- load sounds --- */
- DEBUGCODE
- {
- fprintf(stderr, "Entering TitleScreen_load_media():\n");
- fprintf(stderr, "realPath[0] = %s\n", realPath[0]);
- fprintf(stderr, "realPath[1] = %s\n", realPath[1]);
- }
-
- if (menu_sound){
- snd_move = LoadSound("tock.wav");
- snd_select = LoadSound("pop.wav");
- }
-
- /* --- load graphics --- */
-
- title = LoadImage( "title1.png", IMG_ALPHA );
- speaker = LoadImage( "sound.png", IMG_ALPHA );
- speakeroff = LoadImage( "nosound.png", IMG_ALPHA );
- bkg = LoadImage( "main_bkg.png", IMG_REGULAR );
-
- sel = LoadSprite("menu/sel", IMG_ALPHA);
- reg = LoadSprite("menu/reg", IMG_ALPHA);
-
- Tux = LoadSprite("tux", IMG_ALPHA);
-
- font = LoadFont( menu_font, menu_font_size );
- /* Should probably call this directly from TitleScreen() */
- TitleScreen_load_menu();
-}
-
-void TitleScreen_unload_media( void ) {
-
- /* --- unload sounds --- */
-
- if (menu_sound){
- Mix_FreeChunk(snd_move);
- Mix_FreeChunk(snd_select);
- }
-
- /* --- unload graphics --- */
-
- SDL_FreeSurface(title);
- SDL_FreeSurface(speaker);
- SDL_FreeSurface(speakeroff);
- SDL_FreeSurface(bkg);
-
- FreeSprite(sel);
- FreeSprite(reg);
-
- FreeSprite(Tux);
-
- TTF_CloseFont(font);
- TitleScreen_unload_menu();
-}
-
-void NotImplemented(void) {
- SDL_Surface *s1, *s2, *s3, *s4;
- sprite *tux;
- SDL_Rect loc;
- int finished=0,i;
-
- LOG( "NotImplemented() - creating text\n" );
-
- s1 = black_outline( _("Work In Progress!"), font, &white);
- s2 = black_outline( _("This feature is not ready yet"), font, &white);
- s3 = black_outline( _("Discuss the future of TuxTyping at"), font, &white);
-
- /* we always want the URL in english */
- if (!useEnglish) {
- TTF_Font *english_font;
- useEnglish = 1;
- english_font = LoadFont( menu_font, menu_font_size );
- s4 = black_outline( "http://tuxtype.sf.net/forums", english_font, &white);
- TTF_CloseFont(english_font);
- useEnglish = 0;
- } else
- s4 = black_outline( "http://tuxtype.sf.net/forums", font, &white);
-
- LOG( "NotImplemented() - drawing screen\n" );
-
- SDL_BlitSurface( bkg, NULL, screen, NULL );
- loc.x = 320-(s1->w/2); loc.y = 10;
- SDL_BlitSurface( s1, NULL, screen, &loc);
- loc.x = 320-(s2->w/2); loc.y = 60;
- SDL_BlitSurface( s2, NULL, screen, &loc);
- loc.x = 320-(s3->w/2); loc.y = 400;
- SDL_BlitSurface( s3, NULL, screen, &loc);
- loc.x = 320-(s4->w/2); loc.y = 440;
- SDL_BlitSurface( s4, NULL, screen, &loc);
-
- tux = LoadSprite("tux/tux-egypt", IMG_ALPHA);
-
- loc.x = 320-(tux->frame[0]->w/2);
- loc.y = 200;
- loc.w = tux->frame[0]->w;
- loc.h = tux->frame[0]->h;
- SDL_BlitSurface( tux->frame[tux->cur], NULL, screen, &loc);
-
- SDL_UpdateRect(screen, 0, 0, 0, 0);
-
- i=0;
- while (!finished) {
- while (SDL_PollEvent(&event))
- switch (event.type) {
- case SDL_QUIT:
- exit(0);
- case SDL_MOUSEBUTTONDOWN:
- case SDL_KEYDOWN:
- finished=1;
- }
- i++;
- if (i%5==0) {
- next_frame(tux);
- SDL_BlitSurface( bkg, &loc, screen, &loc);
- SDL_BlitSurface( tux->frame[tux->cur], NULL, screen, &loc);
- SDL_UpdateRect(screen, loc.x, loc.y, loc.w, loc.h);
- }
-
-
- SDL_Delay(40);
- }
-
- SDL_FreeSurface(s1);
- SDL_FreeSurface(s2);
- SDL_FreeSurface(s3);
- SDL_FreeSurface(s4);
- FreeSprite(tux);
-}
-
/****************************************
* TitleScreen: Display the title screen *
*****************************************
* display title screen, get input
*/
-void TitleScreen( void )
+void TitleScreen(void)
{
SDL_Rect dest,
@@ -346,7 +134,7 @@
/* Load media and menu data: */
- TitleScreen_load_media();
+ load_media();
SDL_WM_GrabInput(SDL_GRAB_ON); // User input goes to TuxType, not window manager
@@ -422,7 +210,7 @@
/* Start playing menu music if desired: */
if (menu_music)
- audioMusicLoad( "tuxi.ogg", -1 );
+ MusicLoad( "tuxi.ogg", -1 );
LOG( "Tux and Title are in place now\n" );
@@ -483,7 +271,7 @@
menu_opt = menu_item[j][menu_depth];
if (menu_sound)
{
- playsound(snd_select);
+ PlaySound(snd_select);
}
DEBUGCODE
{
@@ -499,13 +287,13 @@
{
if (menu_music)
{
- audioMusicUnload();
+ MusicUnload();
menu_music = 0;
}
else
{
menu_music = 1;
- audioMusicLoad("tuxi.ogg", -1);
+ MusicLoad("tuxi.ogg", -1);
}
redraw = 1;
}
@@ -535,7 +323,7 @@
menu_opt = QUIT_GAME;
if (menu_sound)
- playsound(snd_select);
+ PlaySound(snd_select);
break;
}
@@ -543,7 +331,7 @@
/* Toggle screen mode: */
case SDLK_F10:
{
- switch_screen_mode();
+ SwitchScreenMode();
redraw = 1;
break;
}
@@ -554,13 +342,13 @@
{
if (menu_music)
{
- audioMusicUnload( );
+ MusicUnload( );
menu_music=0;
}
else
{
menu_music=1;
- audioMusicLoad("tuxi.ogg", -1);
+ MusicLoad("tuxi.ogg", -1);
}
redraw = 1;
break;
@@ -570,9 +358,9 @@
/* --- reload translation/graphics/media: for themers/translaters --- */
case SDLK_F12:
{
- TitleScreen_unload_media();
+ unload_media();
LoadLang();
- TitleScreen_load_media();
+ load_media();
redraw = 1;
break;
}
@@ -581,7 +369,7 @@
case SDLK_UP:
{
if (menu_sound)
- playsound(snd_move);
+ PlaySound(snd_move);
key_menu--;
if (key_menu < 1)
key_menu = 5;
@@ -593,7 +381,7 @@
{
key_menu++;
if (menu_sound)
- playsound(snd_move);
+ PlaySound(snd_move);
if (key_menu > 5)
key_menu = 1;
break;
@@ -606,7 +394,7 @@
{
menu_opt = menu_item[key_menu][menu_depth];
if (menu_sound)
- playsound(snd_select);
+ PlaySound(snd_select);
}
break;
}
@@ -684,14 +472,14 @@
if (menu_opt == NOT_CODED)
{
- NotImplemented();
+ not_implemented();
redraw = 1;
}
if (menu_opt == PROJECT_INFO)
{
- projectInfo();
+ ProjectInfo();
redraw = 1;
}
@@ -700,32 +488,32 @@
{
SDL_BlitSurface(bkg, NULL, screen, NULL);
SDL_Flip( screen );
- TitleScreen_unload_media();
+ unload_media();
if (menu_music)
- audioMusicUnload( );
+ MusicUnload( );
- testLesson();
+ TestLesson();
- TitleScreen_load_media();
+ load_media();
redraw = 1;
if (menu_music)
- audioMusicLoad( "tuxi.ogg", -1 );
+ MusicLoad( "tuxi.ogg", -1 );
}
if (menu_opt == SET_LANGUAGE)
{
- TitleScreen_unload_media();
- chooseTheme();
+ unload_media();
+ ChooseTheme();
LoadLang();
LoadKeyboard();
- TitleScreen_load_media();
+ load_media();
redraw = 1;
if (menu_music)
- audioMusicLoad( "tuxi.ogg", -1 );
+ MusicLoad( "tuxi.ogg", -1 );
}
@@ -733,18 +521,18 @@
{
if (chooseWordlist())
{
- TitleScreen_unload_media();
+ unload_media();
switch (sub_menu)
{
case CASCADE: PlayCascade( EASY ); break;
- case LASER: laser_game( EASY ); break;
+ case LASER: PlayLaserGame( EASY ); break;
}
- TitleScreen_load_media();
+ load_media();
if (menu_music)
- audioMusicLoad( "tuxi.ogg", -1 );
+ MusicLoad( "tuxi.ogg", -1 );
}
redraw = 1;
@@ -755,18 +543,18 @@
{
if (chooseWordlist())
{
- TitleScreen_unload_media();
+ unload_media();
switch (sub_menu)
{
case CASCADE: PlayCascade( MEDIUM ); break;
- case LASER: laser_game( MEDIUM ); break;
+ case LASER: PlayLaserGame( MEDIUM ); break;
}
- TitleScreen_load_media();
+ load_media();
if (menu_music)
- audioMusicLoad( "tuxi.ogg", -1 );
+ MusicLoad( "tuxi.ogg", -1 );
}
redraw = 1;
@@ -778,18 +566,18 @@
{
if (chooseWordlist())
{
- TitleScreen_unload_media();
+ unload_media();
switch (sub_menu)
{
case CASCADE: PlayCascade( HARD ); break;
- case LASER: laser_game( HARD ); break;
+ case LASER: PlayLaserGame( HARD ); break;
}
- TitleScreen_load_media();
+ load_media();
if (menu_music)
- audioMusicLoad( "tuxi.ogg", -1 );
+ MusicLoad( "tuxi.ogg", -1 );
}
redraw = 1;
@@ -801,18 +589,18 @@
{
if (chooseWordlist())
{
- TitleScreen_unload_media();
+ unload_media();
switch (sub_menu)
{
case CASCADE: PlayCascade( INSANE ); break;
- case LASER: laser_game( INSANE ); break;
+ case LASER: PlayLaserGame( INSANE ); break;
}
- TitleScreen_load_media();
+ load_media();
if (menu_music)
- audioMusicLoad( "tuxi.ogg", -1 );
+ MusicLoad( "tuxi.ogg", -1 );
}
redraw = 1;
@@ -822,7 +610,7 @@
if (menu_opt == INSTRUCT)
{
- TitleScreen_unload_media();
+ unload_media();
switch (sub_menu)
{
@@ -830,10 +618,10 @@
case LASER: InstructLaser(); break;
}
- TitleScreen_load_media();
+ load_media();
if (menu_music)
- audioMusicLoad( "tuxi.ogg", -1 );
+ MusicLoad( "tuxi.ogg", -1 );
redraw = 1;
}
@@ -842,10 +630,10 @@
if (menu_opt == FREETYPE)
{
- TitleScreen_unload_media();
+ unload_media();
Phrases( phrase );
//Practice();
- TitleScreen_load_media();
+ load_media();
redraw = 1;
}
@@ -953,7 +741,7 @@
if (key_menu != old_key_menu)
{
rewind(menu_gfx[key_menu][menu_depth]);
- playsound(snd_move);
+ PlaySound(snd_move);
}
SDL_BlitSurface(bkg, &menu_button[key_menu], screen, &menu_button[key_menu]);
@@ -1001,19 +789,307 @@
LOG( "->>Freeing title screen images\n" );
localsettings.menu_music=menu_music;
- TitleScreen_unload_media();
+ unload_media();
LOG( "->TitleScreen():END \n" );
}
+void SwitchScreenMode(void)
+{
+ SDL_Surface *tmp;
+ SDL_Rect src, dst;
+ int window=0;
+ src.x = 0; src.y = 0;
+ src.w = RES_X; src.h = RES_Y;
+ dst.x = 0; dst.y = 0;
+
+ tmp = SDL_CreateRGBSurface(
+ SDL_SWSURFACE,
+ RES_X,
+ RES_Y,
+ BPP,
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ 0xff000000,
+ 0x00ff0000,
+ 0x0000ff00,
+ 0x000000ff
+#else
+ 0x000000ff,
+ 0x0000ff00,
+ 0x00ff0000,
+ 0xff000000
+#endif
+ );
+ if (screen->flags & SDL_FULLSCREEN)
+ window=1;
+ SDL_BlitSurface(screen,&src,tmp,&dst);
+ SDL_UpdateRect(tmp,0,0,RES_X,RES_Y);
+ SDL_FreeSurface(screen);
+ screen = NULL;
+
+ if ( window ){
+ screen = SDL_SetVideoMode(RES_X,RES_Y,BPP, SDL_SWSURFACE|SDL_HWPALETTE);
+ } else {
+ screen = SDL_SetVideoMode(RES_X,RES_Y,BPP, SDL_SWSURFACE|SDL_HWPALETTE|SDL_FULLSCREEN);
+ }
+ SDL_BlitSurface(tmp,&src,screen,&dst);
+ SDL_UpdateRect(tmp,0,0,RES_X,RES_Y);
+ SDL_FreeSurface(tmp);
+
+}
+
+
+/************************************************************************/
+/* */
+/* "Private" functions (local to titlescreen.c) */
+/* */
+/************************************************************************/
+
+
+static void draw_button(int id, sprite* s) {
+ SDL_Rect button;
+
+ button.x = menu_button[id].x;
+ button.y = menu_button[id].y;
+ button.w = s->frame[0]->w;
+ button.h = s->frame[0]->h;
+ SDL_BlitSurface(s->frame[0], NULL, screen, &button);
+ button.w = s->frame[1]->w;
+ for (button.x += s->frame[0]->w; button.x < (menu_button[id].x + menu_width[menu_depth]); button.x += s->frame[1]->w)
+ SDL_BlitSurface(s->frame[1], NULL, screen, &button);
+ button.w = s->frame[2]->w;
+ SDL_BlitSurface(s->frame[2], NULL, screen, &button);
+}
+
+static void load_menu(void)
+{
+ unsigned char fn[FNLEN];
+ int max, i, j;
+
+ SDL_ShowCursor(1);
+
+ LOG("loading & parsing menu\n");
+
+ for (j = 1; j <= TITLE_MENU_DEPTH; j++) /* Each 'depth' is a different menu */
+ {
+ max = 0;
+ for (i = 1; i <= TITLE_MENU_ITEMS; i++)
+ {
+ DEBUGCODE
+ {
+ fprintf(stderr, "i = '%d'\tj = '%d'\ttext = '%s'\n",
+ i, j, _((unsigned char*)menu_text[i][j]));
+ }
+ /* --- create text surfaces --- */
+ reg_text[i][j] = BlackOutline( _((unsigned char*)menu_text[i][j]), font, &white);
+ sel_text[i][j] = BlackOutline( _((unsigned char*)menu_text[i][j]), font, &yellow);
+
+ if (sel_text[i][j]->w > max)
+ max = sel_text[i][j]->w;
+
+ /* --- load animated icon for menu item --- */
+ sprintf(fn, "menu/%s", menu_icon[i][j]);
+ menu_gfx[i][j] = LoadSprite(fn, IMG_ALPHA);
+ }
+ menu_width[j] = max + 20 + 40; // Not clear where '20' and '40' are coming from
+ }
+
+ LOG("done creating graphics, now setting positions\n");
+
+
+ /* --- setup menu item destinations --- */
+
+
+ menu_button[1].x = 240;
+ menu_button[1].y = 100;
+ menu_button[1].w = menu_width[1]; //calc from width of widest menu item
+ menu_button[1].h = sel->frame[1]->h; //height of sprite image
+
+ menu_gfxdest[1].x = menu_button[1].x + 6; // inset graphic by (6, 4) */
+ menu_gfxdest[1].y = menu_button[1].y + 4;
+ menu_gfxdest[1].w = 40;
+ menu_gfxdest[1].h = 50;
+
+ text_dst[1].y = menu_button[1].y+15;
+
+ /* FIXME each menu item drawn hardcoded 60 pixels below last - */
+ /* perhaps increment should be "menu_button[j-1].h + MENU_ITEM_GAP" */
+ for (j=2; j<6; j++)
+ {
+ /* --- setup vertical location of button text --- */
+ text_dst[j].y = text_dst[j-1].y + 60;
+
+ /* --- setup location of button background --- */
+ menu_button[j].x = menu_button[j-1].x;
+ menu_button[j].y = menu_button[j-1].y + 60;
+ menu_button[j].w = menu_button[j-1].w;
+ menu_button[j].h = menu_button[j-1].h;
+
+ /* --- setup location of animated icon --- */
+ menu_gfxdest[j].x = menu_gfxdest[j-1].x;
+ menu_gfxdest[j].y = menu_gfxdest[j-1].y + 60;
+ menu_gfxdest[j].w = menu_gfxdest[j-1].w;
+ menu_gfxdest[j].h = menu_gfxdest[j-1].h;
+ }
+}
+
+static void unload_menu(void)
+{
+ int i,j;
+
+ for (i = 1; i <= TITLE_MENU_ITEMS; i++)
+ for (j = 1; j <= TITLE_MENU_DEPTH; j++) {
+ SDL_FreeSurface(reg_text[i][j]);
+ SDL_FreeSurface(sel_text[i][j]);
+ FreeSprite(menu_gfx[i][j]);
+ }
+}
+
+static void load_media(void)
+{
+
+ /* --- load sounds --- */
+ DEBUGCODE
+ {
+ fprintf(stderr, "Entering titlescreen_load_media():\n");
+ fprintf(stderr, "realPath[0] = %s\n", realPath[0]);
+ fprintf(stderr, "realPath[1] = %s\n", realPath[1]);
+ }
+
+ if (menu_sound){
+ snd_move = LoadSound("tock.wav");
+ snd_select = LoadSound("pop.wav");
+ }
+
+ /* --- load graphics --- */
+
+ title = LoadImage( "title1.png", IMG_ALPHA );
+ speaker = LoadImage( "sound.png", IMG_ALPHA );
+ speakeroff = LoadImage( "nosound.png", IMG_ALPHA );
+ bkg = LoadImage( "main_bkg.png", IMG_REGULAR );
+
+ sel = LoadSprite("menu/sel", IMG_ALPHA);
+ reg = LoadSprite("menu/reg", IMG_ALPHA);
+
+ Tux = LoadSprite("tux", IMG_ALPHA);
+
+ font = LoadFont( menu_font, menu_font_size );
+ /* Should probably call this directly from TitleScreen() */
+ load_menu();
+}
+
+static void unload_media(void)
+{
+
+ /* --- unload sounds --- */
+
+ if (menu_sound){
+ Mix_FreeChunk(snd_move);
+ Mix_FreeChunk(snd_select);
+ }
+
+ /* --- unload graphics --- */
+
+ SDL_FreeSurface(title);
+ SDL_FreeSurface(speaker);
+ SDL_FreeSurface(speakeroff);
+ SDL_FreeSurface(bkg);
+
+ FreeSprite(sel);
+ FreeSprite(reg);
+
+ FreeSprite(Tux);
+
+ TTF_CloseFont(font);
+ unload_menu();
+}
+
+static void not_implemented(void) {
+ SDL_Surface *s1, *s2, *s3, *s4;
+ sprite *tux;
+ SDL_Rect loc;
+ int finished=0,i;
+
+ LOG( "NotImplemented() - creating text\n" );
+
+ s1 = BlackOutline( _("Work In Progress!"), font, &white);
+ s2 = BlackOutline( _("This feature is not ready yet"), font, &white);
+ s3 = BlackOutline( _("Discuss the future of TuxTyping at"), font, &white);
+
+ /* we always want the URL in english */
+ if (!useEnglish) {
+ TTF_Font *english_font;
+ useEnglish = 1;
+ english_font = LoadFont( menu_font, menu_font_size );
+ s4 = BlackOutline( "http://tuxtype.sf.net/forums", english_font, &white);
+ TTF_CloseFont(english_font);
+ useEnglish = 0;
+ } else
+ s4 = BlackOutline( "http://tuxtype.sf.net/forums", font, &white);
+
+ LOG( "NotImplemented() - drawing screen\n" );
+
+ SDL_BlitSurface( bkg, NULL, screen, NULL );
+ loc.x = 320-(s1->w/2); loc.y = 10;
+ SDL_BlitSurface( s1, NULL, screen, &loc);
+ loc.x = 320-(s2->w/2); loc.y = 60;
+ SDL_BlitSurface( s2, NULL, screen, &loc);
+ loc.x = 320-(s3->w/2); loc.y = 400;
+ SDL_BlitSurface( s3, NULL, screen, &loc);
+ loc.x = 320-(s4->w/2); loc.y = 440;
+ SDL_BlitSurface( s4, NULL, screen, &loc);
+
+ tux = LoadSprite("tux/tux-egypt", IMG_ALPHA);
+
+ loc.x = 320-(tux->frame[0]->w/2);
+ loc.y = 200;
+ loc.w = tux->frame[0]->w;
+ loc.h = tux->frame[0]->h;
+ SDL_BlitSurface( tux->frame[tux->cur], NULL, screen, &loc);
+
+ SDL_UpdateRect(screen, 0, 0, 0, 0);
+
+ i=0;
+ while (!finished) {
+ while (SDL_PollEvent(&event))
+ switch (event.type) {
+ case SDL_QUIT:
+ exit(0);
+ case SDL_MOUSEBUTTONDOWN:
+ case SDL_KEYDOWN:
+ finished=1;
+ }
+ i++;
+ if (i%5==0) {
+ next_frame(tux);
+ SDL_BlitSurface( bkg, &loc, screen, &loc);
+ SDL_BlitSurface( tux->frame[tux->cur], NULL, screen, &loc);
+ SDL_UpdateRect(screen, loc.x, loc.y, loc.w, loc.h);
+ }
+
+
+ SDL_Delay(40);
+ }
+
+ SDL_FreeSurface(s1);
+ SDL_FreeSurface(s2);
+ SDL_FreeSurface(s3);
+ SDL_FreeSurface(s4);
+ FreeSprite(tux);
+}
+
+
+
+
#define MAX_WORD_LISTS 100
/* returns 0 if user pressed escape ...
* 1 if word list was set correctly
*/
-int chooseWordlist( void ) {
+static int chooseWordlist(void)
+{
SDL_Surface *titles[MAX_WORD_LISTS];
SDL_Surface *select[MAX_WORD_LISTS];
SDL_Surface *left, *right;
@@ -1087,11 +1163,11 @@
/* let the user pick the list */
- titles[0] = black_outline( _("Alphabet"), font, &white );
- select[0] = black_outline( _("Alphabet"), font, &yellow);
+ titles[0] = BlackOutline( _("Alphabet"), font, &white );
+ select[0] = BlackOutline( _("Alphabet"), font, &yellow);
for (i = 1; i<lists; i++) {
- titles[i] = black_outline( wordlistName[i], font, &white );
- select[i] = black_outline( wordlistName[i], font, &yellow);
+ titles[i] = BlackOutline( wordlistName[i], font, &white );
+ select[i] = BlackOutline( wordlistName[i], font, &yellow);
}
SDL_FreeSurface(bkg);
@@ -1141,11 +1217,11 @@
for (i=0; (i<8) && (loc-(loc%8)+i<lists); i++)
if (inRect(titleRects[i], event.button.x, event.button.y)) {
loc = loc-(loc%8)+i;
- WORDS_init(); /* clear old selection */
+ ClearWordList(); /* clear old selection */
if (loc==0)
- WORDS_use_alphabet();
+ UseAlphabet();
else
- WORDS_use( wordlistFile[loc] );
+ GenerateWordList(wordlistFile[loc]);
stop = 1;
break;
}
@@ -1153,11 +1229,11 @@
case SDL_KEYDOWN:
if (event.key.keysym.sym == SDLK_ESCAPE) { stop = 2; break; }
if (event.key.keysym.sym == SDLK_RETURN) {
- WORDS_init(); /* clear old selection */
+ ClearWordList(); /* clear old selection */
if (loc==0)
- WORDS_use_alphabet();
+ UseAlphabet();
else
- WORDS_use( wordlistFile[loc] );
+ GenerateWordList(wordlistFile[loc]);
stop = 1;
break;
}
@@ -1231,47 +1307,5 @@
-void switch_screen_mode(void)
-{
- SDL_Surface *tmp;
- SDL_Rect src, dst;
- int window=0;
- src.x = 0; src.y = 0;
- src.w = RES_X; src.h = RES_Y;
- dst.x = 0; dst.y = 0;
- tmp = SDL_CreateRGBSurface(
- SDL_SWSURFACE,
- RES_X,
- RES_Y,
- BPP,
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- 0xff000000,
- 0x00ff0000,
- 0x0000ff00,
- 0x000000ff
-#else
- 0x000000ff,
- 0x0000ff00,
- 0x00ff0000,
- 0xff000000
-#endif
- );
- if (screen->flags & SDL_FULLSCREEN)
- window=1;
- SDL_BlitSurface(screen,&src,tmp,&dst);
- SDL_UpdateRect(tmp,0,0,RES_X,RES_Y);
- SDL_FreeSurface(screen);
- screen = NULL;
- if ( window ){
- screen = SDL_SetVideoMode(RES_X,RES_Y,BPP, SDL_SWSURFACE|SDL_HWPALETTE);
- } else {
- screen = SDL_SetVideoMode(RES_X,RES_Y,BPP, SDL_SWSURFACE|SDL_HWPALETTE|SDL_FULLSCREEN);
- }
- SDL_BlitSurface(tmp,&src,screen,&dst);
- SDL_UpdateRect(tmp,0,0,RES_X,RES_Y);
- SDL_FreeSurface(tmp);
-
-}
-
More information about the Tux4kids-commits
mailing list