Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

spritelibtest.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           spritelibtest.cpp  -  description
00003                              -------------------
00004     begin                : Sun Jun 8 2003
00005     copyright            : (C) 2003 by Tyler Montbriand
00006     email                : tsm@accesscomm.ca
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 #include <stdio.h>
00018 #include <stdlib.h>
00019 #include <spritelib.h>
00020 #include "screen.h"
00021 #include "bouncy.h"
00022 
00023 
00024 #ifdef _WIN32_WCE
00025 #  define VFLAGS (SDL_ANYFORMAT|SDL_FULLSCREEN)
00026 #  define SPRITE_FILE_DIR "\\"
00027 /* Yeah, Windows CE framerates suck.  But at least it's not my fault. */
00028 #  define FPS 20
00029 #else
00030 #  define VFLAGS (SDL_ANYFORMAT)
00031 #  define SPRITE_FILE_DIR "/usr/share/spritelib/"
00032 #  define FPS 100
00033 #endif
00034 #define NUM_FACES       5
00035 
00038 
00045 void TestFxp();
00046 
00048 int main(int argc, char *argv[])
00049 {
00050   int n=-1;  
00052   SpriteManager sm(SCREEN_W,SCREEN_H,SCREEN_BPP,VFLAGS);
00054   SpriteLoader  bg("background.spr",SPRITE_FILE_DIR);
00056   SpriteLoader  faces("faces.spr",SPRITE_FILE_DIR);
00057   
00058   if(bg.Good())
00059   { /*  Blit background image onto SM's internal background */
00060     sm.DrawOnBG(bg.GetSurface(),NULL,NULL);
00061   }
00062   else
00063   {
00064     fprintf(stderr,"Couldn't load %sbackground.spr\n",SPRITE_FILE_DIR);
00065     return(1);
00066   }
00067 
00068   TestFxp();
00069 
00070   if(faces.Good())
00071   {
00072     /* Add bouncy sprites to to the game  */  
00073     for(n=0; n<NUM_FACES; n++)
00074     {
00075       Sprite *spr=faces.GetSprite(new Bouncy());            
00076       sm.AddSprite(spr);
00077     }
00078   }
00079   else
00080   {
00081     fprintf(stderr,"Couldn't load %sfaces.spr\n",SPRITE_FILE_DIR);
00082     return(1);
00083   }
00084   
00085   sm.Run(1000/FPS); /* Run event loop until SDL_QUIT  */
00086   
00087   return(0);
00088 }
00089 
00090 void TestFxp()
00091 {
00092   int n;
00093 
00094   Sfxp a=TO_SFXP(2);
00095   Sfxp b=TO_SFXP(3);
00096 
00097   printf("Testing some basic math, in fixed point:\n");
00098 
00099   printf("%d + %d = %d\n",FROM_SFXP(a),FROM_SFXP(b),FROM_SFXP(a+b));
00100   printf("%d - %d = %d\n",FROM_SFXP(a),FROM_SFXP(b),FROM_SFXP(a-b));
00101   printf("%d * %d = %d\n",FROM_SFXP(a),FROM_SFXP(b),FROM_SFXP(MUL_SFXP(a,b)));
00102   printf("%d / %d = %f\n",FROM_SFXP(a),FROM_SFXP(b),SFXP_TO_F(DIV_SFXP(a,b)));
00103 
00104   printf("%.3f ~=%d\n",1.499,FROM_SFXP(F_TO_SFXP(1.499)));
00105   printf("%.3f ~=%d\n",1.500,FROM_SFXP(F_TO_SFXP(1.500)));
00106 
00107   printf("\nTesting trig:\n");
00108   for(n=0; n<360; n+=45)
00109   {
00110     printf("Cos(%3d deg.) = %f\n",n%360,SFXP_TO_F(FXP_Cos(DEG_TO_AFXP(n))));
00111     printf("Sin(%3d deg.) = %f\n",n%360,SFXP_TO_F(FXP_Sin(DEG_TO_AFXP(n))));
00112     printf("Tan(%3d deg.) = %f\n",n%360,SFXP_TO_F(FXP_Tan(DEG_TO_AFXP(n))));
00113   }
00114 
00115   printf("\nTesting trajectory angle:\n");
00116   for(n=0; n<360; n+=(360/12))
00117   {
00118     Afxp a=DEG_TO_AFXP(n);
00119     Afxp na=FXP_Traj(FXP_Sin(a),FXP_Cos(a));
00120 
00121     printf("%3d degrees -> %3d degrees\n",n%360,(int)AFXP_TO_DEG(na));
00122   }
00123 }
00124 

Generated on Sat Oct 11 13:19:25 2003 for Spritelib by doxygen 1.3.4