diff --git a/Anim.c b/Anim.c index bcd5ca1..370e566 100644 --- a/Anim.c +++ b/Anim.c @@ -4,16 +4,26 @@ #include "Draw.h" #include "Anim.h" + +//////////////////////////////////////////////// +// Animation // +/////////////// +// typedef struct { DrawImg img; int w; - int fps; + float fps; int frames; int ftime; int time; } Animation; -Anim Anim_LoadAnim(char *fichero,int frames,int fps){ + +///////////////////////////// +// Anim_LoadAnim +// +// +Anim Anim_LoadAnim(char *fichero,int frames,float fps){ DrawImg img; Animation *anim; int w,h; @@ -37,12 +47,22 @@ Anim Anim_LoadAnim(char *fichero,int frames,int fps){ } +///////////////////////////// +// Anim_GetTime +// +// int Anim_GetTime(Anim a){ Animation *anim=a; return(anim->time); } + +///////////////////////////// +// Anim_SetOffset +// Anim_GetOffset +// +// void Anim_SetOffset(Anim a,int x,int y){ Animation *anim=a; @@ -54,6 +74,11 @@ void Anim_GetOffset(Anim a,int *x,int *y){ Draw_GetOffset(anim->img,x,y); } + +///////////////////////////// +// Anim_Draw +// +// void Anim_Draw(Anim a,int time_ms,int x,int y){ Animation *anim=a; int frame; @@ -63,14 +88,10 @@ void Anim_Draw(Anim a,int time_ms,int x,int y){ } - - - - - - - - +///////////////////////////// +// AnimPlay_Copy +// +// void AnimPlay_Copy(AnimPlay *ad,AnimPlay *ao){ ad->img=ao->img; ad->anim=ao->anim; @@ -78,6 +99,11 @@ void AnimPlay_Copy(AnimPlay *ad,AnimPlay *ao){ } +///////////////////////////// +// AnimPlay_SetImg +// AnimPlay_SetAnim +// +// void AnimPlay_SetImg(AnimPlay *ap,DrawImg img){ ap->anim=NULL; ap->img=img; @@ -90,6 +116,10 @@ void AnimPlay_SetAnim(AnimPlay *ap,Anim ani){ } +///////////////////////////// +// AnimPlay_Draw +// +// void AnimPlay_Draw(AnimPlay *ani,int x,int y){ if(ani->anim){ Anim_Draw(ani->anim,ani->time_ms,x,y); @@ -99,6 +129,11 @@ void AnimPlay_Draw(AnimPlay *ani,int x,int y){ } } + +///////////////////////////// +// AnimPlay_IncTime +// +// void AnimPlay_IncTime(AnimPlay *ani,int t){ if(ani->anim){ ani->time_ms+=t; diff --git a/Anim.h b/Anim.h index dbf1f5f..23f2f7c 100644 --- a/Anim.h +++ b/Anim.h @@ -3,31 +3,83 @@ #include "Draw.h" + +//////////////////////////////////////////////// +// Anim // +////////// +// typedef void *Anim; -Anim Anim_LoadAnim(char *fichero,int frames,int fps); +///////////////////////////// +// Anim_LoadAnim +// +// +Anim Anim_LoadAnim(char *fichero,int frames,float fps); + +///////////////////////////// +// Anim_GetTime +// +// int Anim_GetTime(Anim anim); + +///////////////////////////// +// Anim_SetOffset +// Anim_GetOffset +// +// void Anim_SetOffset(Anim anim,int x,int y); void Anim_GetOffset(Anim anim,int *x,int *y); + +///////////////////////////// +// Anim_Draw +// +// void Anim_Draw(Anim anim,int time_ms,int x,int y); + +//////////////////////////////////////////////// +// AnimPlay // +////////////// +// typedef struct { Anim anim; DrawImg img; int time_ms; } AnimPlay; + +///////////////////////////// +// AnimPlay_Copy +// +// void AnimPlay_Copy(AnimPlay *ad,AnimPlay *ao); + +///////////////////////////// +// AnimPlay_SetImg +// AnimPlay_SetAnim +// +// void AnimPlay_SetImg(AnimPlay *ap,DrawImg img); void AnimPlay_SetAnim(AnimPlay *ap,Anim ani); + +///////////////////////////// +// AnimPlay_Draw +// +// void AnimPlay_Draw(AnimPlay *ani,int x,int y); + +///////////////////////////// +// AnimPlay_IncTime +// +// void AnimPlay_IncTime(AnimPlay *ani,int t); + #endif diff --git a/Draw.c b/Draw.c index 5a3d13b..caca10f 100644 --- a/Draw.c +++ b/Draw.c @@ -3,6 +3,7 @@ #include #endif #include +#include #include "Time.h" #include "Util.h" @@ -161,11 +162,10 @@ typedef struct Tag_DrawImage { ///////////////////////////// -// Draw_LoadImage +// Draw_LoadSurface // -// Loads a image, giving a reference. -DrawImg Draw_LoadImage(char *filename){ - DrawImage *image; +// Loads a surface. +SDL_Surface *Draw_LoadSurface(char *filename){ SDL_Surface *surf; // Load the BMP as a surface @@ -199,6 +199,24 @@ DrawImg Draw_LoadImage(char *filename){ } } + return(surf); +} + + +///////////////////////////// +// Draw_LoadImage +// +// Loads a image, giving a reference. +DrawImg Draw_LoadImage(char *filename){ + DrawImage *image; + SDL_Surface *surf; + + // Loads the surface + surf=Draw_LoadSurface(filename); + if(surf == NULL){ + return(NULL); + } + // Create the image container image=malloc(sizeof(DrawImage)); image->surf=surf; @@ -316,6 +334,28 @@ void Draw_DrawImgPart(DrawImg img,int x,int y,int w,int i){ } +///////////////////////////// +// Draw_DrawImgTrans +// +// Draws an image transformed. +void Draw_DrawImgTrans(DrawImg img,int x,int y,float angle){ + DrawImage *image=img; + SDL_Rect orig; + SDL_Rect dest; + + // Prepare the rects + orig.x=0; + orig.y=0; + dest.x=x+image->x; + dest.y=y+image->y; + orig.w=dest.w=image->surf->w; + orig.h=dest.h=image->surf->h; + + // Blit the surface on the screen + SDL_BlitSurface(image->surf,&orig,_screen,&dest); +} + + //////////////////////////////////////////////// // DrawFnt // ///////////// @@ -323,14 +363,59 @@ void Draw_DrawImgPart(DrawImg img,int x,int y,int w,int i){ typedef struct { SDL_Surface *surf; int w,h; + int min,max; } DrawFont; ///////////////////////////// // Draw_DefaultFont // -// Creates a image with the default font. +// Creates a surface with the default font. #include "FontData.h" +SDL_Surface *Draw_DefaultFontSurface( + unsigned char r, + unsigned char g, + unsigned char b, + unsigned char a) +{ + SDL_Surface *surf; + int x,y,c; + Uint32 color,color2; + + // Create the surface + surf = SDL_CreateRGBSurface(SDL_SWSURFACE, + 8*256, 8, 32,0,0,0,0); + surf->format->Amask=0xFF000000; + surf->format->Ashift=24; + + // Draw the font + SDL_LockSurface(surf); + color =SDL_MapRGBA(surf->format,r,g,b,a); + color2=SDL_MapRGBA(surf->format,r,g,b,0); + for(c=0;c<256;c++){ + for(y=0;y<8;y++){ + for(x=0;x<8;x++){ + if(((fontdata_8x8[c*8+y]>>(7-x)) & 0x01)==1){ + //Imagen_PutPixel(dest,c*8+x,y,color); + ((Uint32 *)surf->pixels)[(c*8+x)+(8*256*y)]= + color; + }else{ + //Imagen_PutPixel(dest,c*8+x,y,color2); + ((Uint32 *)surf->pixels)[(c*8+x)+(8*256*y)]= + color2; + } + } + } + } + SDL_UnlockSurface(surf); + + return(surf); +} + +///////////////////////////// +// Draw_DefaultFont +// +// Creates the default font. DrawFnt Draw_DefaultFont( unsigned char r, unsigned char g, @@ -338,6 +423,28 @@ DrawFnt Draw_DefaultFont( unsigned char a) { DrawFont *font; + + // Create the default font + font=malloc(sizeof(DrawFont)); + font->surf = Draw_DefaultFontSurface(r,g,b,a); + font->w=8; + font->h=8; + + font->surf->format->Amask=0xFF000000; + font->surf->format->Ashift=24; + SDL_SetAlpha(font->surf, SDL_SRCALPHA, 255); + + + + return((DrawFnt)font); +} + +///////////////////////////// +// Draw_LoadFont +// +// Load a font from a file. +DrawFnt Draw_LoadFont(char *fichero,int min,int max){ + /*DrawFont *font; int x,y,c; Uint32 color,color2; @@ -372,10 +479,9 @@ DrawFnt Draw_DefaultFont( } SDL_UnlockSurface(font->surf); - return((DrawFnt)font); + return((DrawFnt)font);*/ } - ///////////////////////////// // Draw_DrawText // diff --git a/Draw.h b/Draw.h index cdf42d9..c082b62 100644 --- a/Draw.h +++ b/Draw.h @@ -87,6 +87,13 @@ void Draw_DrawImg(DrawImg img,int x,int y); void Draw_DrawImgPart(DrawImg img,int x,int y,int w,int i); +///////////////////////////// +// Draw_DrawImgTrans +// +// Draws an image transformed. +void Draw_DrawImgTrans(DrawImg img,int x,int y,float angle); + + //////////////////////////////////////////////// // DrawFnt // ///////////// @@ -97,7 +104,7 @@ typedef void *DrawFnt; ///////////////////////////// // Draw_DefaultFont // -// Loads a image, giving a reference. +// Creates the default font. DrawFnt Draw_DefaultFont( unsigned char r, unsigned char g, @@ -105,6 +112,13 @@ DrawFnt Draw_DefaultFont( unsigned char a); +///////////////////////////// +// Draw_LoadFont +// +// Load a font from a file. +DrawFnt Draw_LoadFont(char *fichero,int min,int max); + + ///////////////////////////// // Draw_DrawText // diff --git a/Entity.c b/Entity.c index 2eed55c..dbb8c90 100644 --- a/Entity.c +++ b/Entity.c @@ -131,6 +131,7 @@ void Entity_PostProcess(Entity *e,int ft){ vec2_scale(e->vel,e->vel, 1.0f-(e->fric_dynamic+(e->fric_static/len))); } + } // Animate @@ -146,7 +147,7 @@ void Entity_CollisionResponse( Entity *b1,Entity *b2,float t,vec2 n) { float moment; - vec2 temp,temp2; + vec2 temp; float elast; if(b1->mass>0.0f && b2->mass>0.0f){ @@ -194,7 +195,6 @@ int Entity_Collide(Entity *b1,Entity *b2){ float t; vec2 n; vec2 cir1[2]; - vec2 cir1i,cir2i; Entity *b_aux; // FIX: Swap colision order based on moving object diff --git a/GameLib.c b/GameLib.c index 64ef8d3..a7ebcdd 100644 --- a/GameLib.c +++ b/GameLib.c @@ -119,7 +119,7 @@ int GameLib_ProcLoop(){ if(_entity[i]->mass>0.0f){ vec2_plus(_entity[i]->vel,_entity[i]->vel,grav); } - */ +*/ } // Process colisions between entities @@ -136,7 +136,7 @@ int GameLib_ProcLoop(){ } } count++; - }while(repeat && count<10); + }while(repeat && count<20); // Stop remaining collisions for(i=0;i<_n_entities-1;i++){ diff --git a/Makefile.common b/Makefile.common old mode 100644 new mode 100755 diff --git a/Makefile.mingw b/Makefile.mingw index 88ece6e..16786c4 100644 --- a/Makefile.mingw +++ b/Makefile.mingw @@ -1,6 +1,6 @@ -LIBS=-I/mingw/include/SDL -D_GNU_SOURCE=1 -Dmain=SDL_main -CFLAGS= -L/mingw/lib -lmingw32 -lSDLmain -lSDL -mwindows -CC=gcc +LIBS= -L/usr/i486-mingw/lib -D_GNU_SOURCE=1 -Dmain=SDL_main +CFLAGS= -I/usr/i486-mingw/include -lmingw32 -lSDLmain -lSDL -mwindows +CC= i486-mingw32-gcc RM=rm -rf RESULT=game.exe diff --git a/SDL.dll b/SDL.dll new file mode 100644 index 0000000..a5da7bb Binary files /dev/null and b/SDL.dll differ diff --git a/Util.c b/Util.c index 1c423d9..194a263 100644 --- a/Util.c +++ b/Util.c @@ -40,7 +40,7 @@ int Intersec_RayUnitCircle(vec2 orig,vec2 vel,vec2 center,float *t){ // Solve as a unit circle a=vec2_dot(vel,vel); - if(fabs(a)<0.0f){ + if(fabs(a)<=0.0f){ return(0); } vec2_minus(temp,orig,center); diff --git a/macosx/SDL_dev.zip b/macosx/SDL_dev.zip new file mode 100644 index 0000000..e860dfb Binary files /dev/null and b/macosx/SDL_dev.zip differ diff --git a/main.c b/main.c index 403d02f..46c6c22 100644 --- a/main.c +++ b/main.c @@ -1,6 +1,8 @@ #include #include #include +#include + #include "GameLib.h" @@ -37,8 +39,8 @@ void PostProcGame(){ Audio_PlaySound(coin,1,1); } - Draw_DrawText(font_shad,"Hola Mundo!",11,11); - Draw_DrawText(font ,"Hola Mundo!",10,10); + Draw_DrawText(font_shad,"Buncy Buncy!",41,41); + Draw_DrawText(font ,"Buncy Buncy!",40,40); } void player_proc(Entity *e,int ft){ @@ -81,14 +83,14 @@ int main(int argc,char *argv[]){ img_block2=Draw_LoadImage("data/block2.bmp"); Draw_SetOffset(img_block2,-16,-16); -// img_whitey=Draw_LoadImage("data/whitey.bmp"); -// Draw_SetOffset(img_whitey,-16,-16); - anim_whitey=Anim_LoadAnim("data/whitey.bmp",4,5); + anim_whitey=Anim_LoadAnim("data/whitey.bmp",4,2.5); Anim_SetOffset(anim_whitey,-16,-16); coin=Audio_LoadSound("data/coin.wav"); + + ent_player=Entity_New(); ent_player->type=Ent_Player; ent_player->radius=16.0f; @@ -100,9 +102,10 @@ int main(int argc,char *argv[]){ ent_ball->type=Ent_Ball; ent_ball->radius=16.0f; ent_ball->fric_static=0.1f; - ent_ball->elast=1.0f; + ent_ball->elast=0.5f; AnimPlay_SetImg(&ent_ball->anim,img_rball); + ent_block=Entity_New(); ent_block->type=Ent_Block; ent_block->mass=-1.0f; @@ -152,10 +155,20 @@ int main(int argc,char *argv[]){ vec2_set(e->pos,132,100+3*32); GameLib_AddEntity(e); - e=Entity_Copy(ent_ball); + for(i=0;i<3;i++){ + e=Entity_Copy(ent_ball); + vec2_set(e->pos,200+i*33,100); + GameLib_AddEntity(e); + } + for(i=0;i<3;i++){ + e=Entity_Copy(ent_ball); + vec2_set(e->pos,200+i*33,133); + GameLib_AddEntity(e); + } + /*e=Entity_Copy(ent_ball); vec2_set(e->pos,132,100); GameLib_AddEntity(e); - +*/ e=Entity_Copy(ent_player); vec2_set(e->pos,132,50); GameLib_AddEntity(e);