00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
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 {
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
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);
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