(20130126)

This commit is contained in:
2013-01-26 00:00:00 +01:00
parent 23c81ceb32
commit e283956e98
77 changed files with 1489 additions and 603 deletions

449
Entity.c
View File

@@ -1,449 +0,0 @@
// Copyright (C) 2011 Valeriano Alfonso Rodriguez (Kableado)
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "Util.h"
#include "Draw.h"
#include "Anim.h"
#include "Entity.h"
/////////////////////////////
// Entity_New
//
//
Entity *_free_entity=NULL;
Entity *Entity_New(){
Entity *e;
if(!_free_entity){
e=malloc(sizeof(Entity));
}else{
e=_free_entity;
_free_entity=e->next;
}
e->type=0;
vec2_set(e->pos,0.0f,0.0f);
e->flags=EntityFlag_Collision|EntityFlag_Overlap;
e->zorder=1;
vec2_set(e->vel,0.0f,0.0f);
e->radius=1.0f;
e->mass=1.0f;
e->elast=0.0f;
e->fric_static=0.0f;
e->fric_dynamic=0.0f;
AnimPlay_SetImg(&e->anim,NULL);
e->color[0]=e->color[1]=e->color[2]=e->color[3]=1.0f;
e->light[0]=e->light[1]=e->light[2]=e->light[3]=1.0f;
e->oncopy=NULL;
e->ondelete=NULL;
e->proc=NULL;
e->postproc=NULL;
e->collision=NULL;
e->overlap=NULL;
e->A=0;
e->child=NULL;
e->next=NULL;
return(e);
}
/////////////////////////////
// Entity_Destroy
//
//
void Entity_Destroy(Entity *e){
if(e->ondelete){
e->ondelete(e);
}
e->next=_free_entity;
_free_entity=e;
}
/////////////////////////////
// Entity_Copy
//
//
Entity *Entity_Copy(Entity *e){
Entity *n;
n=Entity_New();
n->type=e->type;
vec2_set(n->pos,e->pos[0],e->pos[1]);
n->flags=e->flags;
n->zorder=e->zorder;
vec2_set(n->vel,e->vel[0],e->vel[1]);
n->radius=e->radius;
n->mass=e->mass;
n->elast=e->elast;
n->fric_static=e->fric_static;
n->fric_dynamic=e->fric_dynamic;
AnimPlay_Copy(&n->anim,&e->anim);
n->color[0]=e->color[0];
n->color[1]=e->color[1];
n->color[2]=e->color[2];
n->color[3]=e->color[3];
n->light[0]=e->light[0];
n->light[1]=e->light[1];
n->light[2]=e->light[2];
n->light[3]=e->light[3];
n->oncopy=e->oncopy;
n->ondelete=e->ondelete;
n->proc=e->proc;
n->postproc=e->postproc;
n->collision=e->collision;
n->overlap=e->overlap;
n->A=e->A;
n->child=e->child;
// Call the copy event
if(n->oncopy){
n->oncopy(n);
}
return(n);
}
/////////////////////////////
// Entity_Draw
//
//
void Entity_Draw(Entity *e,int x,int y){
Draw_SetColor(e->color[0],e->color[1],e->color[2],e->color[3]);
AnimPlay_Draw(&e->anim,e->pos[0]+x,e->pos[1]+y);
}
/////////////////////////////
// Entity_Process
//
//
void Entity_Process(Entity *b,int ft){
b->flags&=~EntityFlag_UpdatedPos;
// Launch method
if(b->proc){
b->proc(b,ft);
}
}
/////////////////////////////
// Entity_PostProcess
//
//
void Entity_PostProcess(Entity *e,int ft){
float qlen,len;
// Launch method
if(e->postproc){
e->postproc(e,ft);
}
// Determine if there is movement
qlen=vec2_dot(e->vel,e->vel);
if(qlen>0.0f){
// Update position
vec2_plus(e->pos,e->pos,e->vel);
// Aply friction
len=sqrtf(qlen);
if(len<e->fric_static){
// Stopped by static friction
vec2_set(e->vel,0,0);
}else{
// Aply dynamic friction
vec2_scale(e->vel,e->vel,
1.0f-(e->fric_dynamic+(e->fric_static/len)));
}
e->flags|=EntityFlag_UpdatedPos;
}
// Animate
AnimPlay_IncTime(&e->anim,ft);
}
/////////////////////////////
// Entity_CollisionResponse
//
// Normal response to a collision.
void Entity_CollisionResponse(
Entity *b1,Entity *b2,float t,vec2 n)
{
float moment;
vec2 temp;
float elast;
if(b1->mass>0.0f && b2->mass>0.0f){
// Calculate elasticity
elast=(b1->mass*b1->elast+b2->mass*b2->elast)/
(b1->mass+b2->mass);
// Collision between two massed balls
moment=((1.0f+elast)*b1->mass*b2->mass*
(vec2_dot(b1->vel,n)+vec2_dot(b2->vel,n)))
/(b1->mass+b2->mass);
vec2_scale(temp,n,moment/b1->mass);
vec2_minus(b1->vel,b1->vel,temp);
vec2_scale(temp,n,moment/b2->mass);
vec2_plus(b2->vel,b2->vel,temp);
}else
if(b1->mass>0.0f && b2->mass<=0.0f){
// Collision between a massed ball and a fixed ball
moment=(1.0f+b1->elast)*
(vec2_dot(b1->vel,n));
vec2_scale(temp,n,moment);
vec2_minus(b1->vel,b1->vel,temp);
}else
if(b1->mass<=0.0f && b2->mass>0.0f){
// Collision between a massed ball and a fixed ball
// (imposible, but better safe)
moment=(1.0f+b2->elast)*
(vec2_dot(b2->vel,n));
vec2_scale(temp,n,moment);
vec2_plus(b2->vel,b2->vel,temp);
}else{
// Collision between 2 fixed balls
// (imposible, but better safe)
vec2_set(b1->vel,0,0);
vec2_set(b2->vel,0,0);
}
}
/////////////////////////////
// Entity_Collide
//
//
int Entity_Collide(Entity *b1,Entity *b2){
float t;
vec2 n;
vec2 vel;
//if(!(b1->flags&EntityFlag_Collision) || !(b2->flags&EntityFlag_Collision))
// return(0);
// Test relative to b1
vec2_minus(vel,b1->vel,b2->vel);
if(vec2_dot(vel,vel)<=0.0f)
return(0);
if(Colision_CircleCircle(b1->pos,b1->radius,vel,b2->pos,b2->radius,&t,n)){
int response=1;
int rc;
// Check the collision methods
if(b1->collision){
rc=b1->collision(b1,b2,t,n);
if (rc==0)
response=0;
if (rc>1)
response=2;
}
if(b2->collision){
vec2 n2;
vec2_scale(n2,n,-1.0f);
rc=b2->collision(b2,b1,t,n2);
if (rc==0)
response=0;
if (rc>1)
response=2;
}
// Collision response
if(response==1){
if(vec2_dot(b1->vel,b1->vel)>vec2_dot(b2->vel,b2->vel)){
Entity_CollisionResponse(b1,b2,t,n);
}else{
Entity_CollisionResponse(b2,b1,t,n);
}
return(1);
}
if (response==2) {
return(1);
}
return(0);
}
return(0);
}
/////////////////////////////
// Entity_Overlaps
//
//
void Entity_Overlaps(Entity *b1,Entity *b2){
vec2 len;
// if(!(b1->flags&EntityFlag_Overlap) || !(b2->flags&EntityFlag_Overlap))
// return;
vec2_minus(len,b1->pos,b2->pos);
#if 0
if(fabs(len[0])>b1->radius)
return;
if(fabs(len[1])>b1->radius)
return;
if(fabs(len[0])>b2->radius)
return;
if(fabs(len[1])>b2->radius)
return;
dist=sqrtf(vec2_dot(len,len));
if(b1->radius>dist && b1->overlap){
b1->overlap(b1,b2);
}
if(b2->radius>dist && b2->overlap){
b2->overlap(b2,b1);
}
#else
vec2_set(len,fabs(b1->pos[0]-b2->pos[0]),fabs(b1->pos[1]-b2->pos[1]));
if(b1->overlap){
if( len[0]<=b1->radius &&
len[1]<=b1->radius)
{
b1->overlap(b1,b2);
}
}
if(b2->overlap){
if( len[0]<=b2->radius &&
len[1]<=b2->radius)
{
b2->overlap(b2,b1);
}
}
#endif
}
/////////////////////////////
// Entity_AddVelLimit
//
//
void Entity_AddVelLimit(Entity *e,vec2 vel,float limit){
float vlen_orig,vlen;
vec2 dir,vel_temp;
// Normalize vel getting vel
vlen_orig=sqrtf(vec2_dot(vel,vel));
vec2_scale(dir,vel,1.0f/vlen_orig);
// Limit velocity
vlen=vec2_dot(e->vel,dir);
if(vlen<limit){
vlen=limit-vlen;
if(vlen>vlen_orig){
vlen=vlen_orig;
}
vec2_scale(vel_temp,dir,vlen);
vec2_plus(e->vel,e->vel,vel_temp);
}
}
/////////////////////////////
// Entity_SetColor
//
//
void Entity_SetColor(Entity *e,float r,float g,float b,float a){
e->color[0]=r;
e->color[1]=g;
e->color[2]=b;
e->color[3]=a;
}
/////////////////////////////
// Entity_AddColor
//
//
void Entity_AddColor(Entity *e,float r,float g,float b,float a){
e->color[0]+=r;
if(e->color[0]>1.0f)
e->color[0]=1.0f;
e->color[1]+=g;
if(e->color[1]>1.0f)
e->color[1]=1.0f;
e->color[2]+=b;
if(e->color[2]>1.0f)
e->color[2]=1.0f;
e->color[3]+=a;
if(e->color[3]>1.0f)
e->color[3]=1.0f;
}
/////////////////////////////
// Entity_AddColor
//
//
void Entity_SetLight(Entity *e,float r,float g,float b,float rad){
e->light[0]=r;
e->light[1]=g;
e->light[2]=b;
e->light[3]=rad;
}
/////////////////////////////
// Entity_AddColor
//
//
void Entity_Iluminate(Entity *e,Entity **elist,int n){
int i;
vec2 vdist;
float qdist,f;
float qrad;
if(!(e->flags&EntityFlag_Light)){
Entity_SetColor(e,
e->light[0],
e->light[1],
e->light[2],
1.0f);
}else{
Entity_SetColor(e,1.0f,1.0f,1.0f,1.0f);
return;
}
for(i=0;i<n;i++){
if(e==elist[i] || !(elist[i]->flags&EntityFlag_Light))
continue;
vec2_minus(vdist,e->pos,elist[i]->pos);
qdist=vec2_dot(vdist,vdist);
qrad=elist[i]->light[3]*elist[i]->light[3];
if(qdist<qrad){
//dist=sqrtf(qdist);
//f=1.0f-dist/elist[i]->light[3];
f=1.0f-qdist/qrad;
Entity_AddColor(e,
f*elist[i]->light[0],
f*elist[i]->light[1],
f*elist[i]->light[2],
1.0f);
}
}
}

View File

@@ -72,6 +72,9 @@ Entity *ent_arrow_right;
Entity *ent_exitpoint;
Entity *ent_endpoint;
Entity *ent_savepoint;
Entity *ent_teleporter;
Entity *ent_teleporter_dest;
Entity *ent_fire;
Entity *ent_player_broken;
@@ -149,7 +152,7 @@ int player_collision(Entity *e1,Entity *e2,float t,vec2 n){
if(vlen>0.0f){
vec2_scale(vdir,e1->vel,1.0f/vlen);
if(vec2_dot(vdir,n)>0.9){
Entity_CollisionResponse(e1,e2,t,vdir);
Entity_CollisionResponseCircle(e1,e2,t,vdir);
return(2);
}else{
return(1);
@@ -336,6 +339,29 @@ void timeoutent_proc(Entity *e,int ft){
}
}
int teleporter_searchdest(Entity *ent,void *d){
int a=*(int*)d;
if(ent->type!=Ent_Teleporter_Dest){
return 0;
}
if(ent->A==a){
return 1;
}
return 0;
}
void teleporter_overlap(Entity *e1,Entity *e2){
Entity *dest=NULL;
// Search the destination
dest=GameLib_SearchEnt(teleporter_searchdest,&e1->A);
if(dest){
vec2_copy(e2->pos,dest->pos);
}
}
void GameEnts_Init(){
Entity *ent;
@@ -447,7 +473,7 @@ void GameEnts_Init(){
ent_player->type=Ent_Player;
ent_player->radius=16.0f;
ent_player->mass=70.0f;
ent_player->fric_static=0.5f;
ent_player->backFric_static=0.5f;
ent_player->flags=
EntityFlag_Collision|EntityFlag_Overlap|EntityFlag_Light;
Entity_SetLight(ent_player,0.4f,0.4f,0.4f,3*32.0f);
@@ -462,7 +488,7 @@ void GameEnts_Init(){
EntityFlag_Collision|EntityFlag_Overlap;
ent_barrel->radius=16.0f;
ent_barrel->mass=100.0f;
ent_barrel->fric_static=0.5f;
ent_barrel->backFric_static=0.5f;
ent_barrel->proc=barrel_proc;
AnimPlay_SetImg(&ent_barrel->anim,img_barrel);
@@ -585,6 +611,25 @@ void GameEnts_Init(){
AnimPlay_SetImg(&ent_endpoint->anim,img_endpoint);
ent_endpoint->overlap=endpoint_overlap;
ent_teleporter=Entity_Copy(ent);
ent_teleporter->zorder=0;
ent_teleporter->type=Ent_Teleporter;
ent_teleporter->flags=EntityFlag_Overlap|EntityFlag_Light;
Entity_SetLight(ent_teleporter,0.5f,0.5f,0.5f,5*32.0f);
ent_teleporter->radius=20;
AnimPlay_SetImg(&ent_teleporter->anim,img_savepoint);
ent_teleporter->overlap=teleporter_overlap;
ent_teleporter_dest=Entity_Copy(ent);
ent_teleporter_dest->zorder=0;
ent_teleporter_dest->type=Ent_Teleporter_Dest;
ent_teleporter_dest->flags=0;
AnimPlay_SetImg(&ent_teleporter_dest->anim,img_savepoint);
ent_fire=Entity_Copy(ent);
ent_fire->type=Ent_Effect;
ent_fire->flags=EntityFlag_Light;

View File

@@ -17,6 +17,8 @@ enum {
Ent_Arrow,
Ent_SavePoint,
Ent_ExitPoint,
Ent_Teleporter,
Ent_Teleporter_Dest,
Ent_Effect
} EntityType;
extern Entity *ent_player;
@@ -43,5 +45,7 @@ extern Entity *ent_arrow_right;
extern Entity *ent_exitpoint;
extern Entity *ent_endpoint;
extern Entity *ent_savepoint;
extern Entity *ent_teleporter;
extern Entity *ent_teleporter_dest;
#endif

View File

@@ -125,6 +125,10 @@ void AnimPlay_SetImg(AnimPlay *ap,DrawImg img){
ap->time_ms=0;
}
void AnimPlay_SetAnim(AnimPlay *ap,Anim ani){
ap->pause=0;
if(ap->anim==ani){
return;
}
ap->anim=ani;
ap->img=NULL;
ap->time_ms=0;
@@ -168,13 +172,25 @@ void AnimPlay_GetSize(AnimPlay *ani,int *w,int *h){
}
/////////////////////////////
// AnimPlay_SetPause
//
//
void AnimPlay_SetPause(AnimPlay *ani,int p){
ani->pause=p;
}
/////////////////////////////
// AnimPlay_IncTime
//
//
void AnimPlay_IncTime(AnimPlay *ani,int t){
if(ani->anim){
ani->time_ms+=t;
if(!ani->pause){
ani->time_ms+=t;
}
}
}

View File

@@ -57,6 +57,7 @@ void Anim_Draw(Anim anim,int time_ms,int x,int y);
typedef struct {
Anim anim;
DrawImg img;
int pause;
int time_ms;
} AnimPlay;
@@ -93,6 +94,12 @@ void AnimPlay_GetOffset(AnimPlay *ani,int *x,int *y);
void AnimPlay_GetSize(AnimPlay *ani,int *w,int *h);
/////////////////////////////
// AnimPlay_SetPause
//
//
void AnimPlay_SetPause(AnimPlay *ani,int p);
/////////////////////////////
// AnimPlay_IncTime
//

View File

@@ -33,14 +33,14 @@
SDL_Surface *_screen=NULL;
int _width;
int _height;
long long _t_frame=17000;
long long min_t_frame=16000;
long long proc_t_frame=33333;
long long draw_t_frame=16667;
/////////////////////////////
// Draw_Init
//
// Initializes the game window.
int Draw_Init(int width,int height,char *title,int fps){
int Draw_Init(int width,int height,char *title,int pfps,int fps){
#ifdef WIN32
// Stdout on the parent console
AttachConsole(ATTACH_PARENT_PROCESS);
@@ -81,7 +81,8 @@ int Draw_Init(int width,int height,char *title,int fps){
return(0);
}
SDL_WM_SetCaption(title, NULL);
_t_frame=1000000/fps;
proc_t_frame=1000000/pfps;
draw_t_frame=1000000/fps;
_width=width;
_height=height;
@@ -137,17 +138,16 @@ void Draw_Loop(int (*proc)(),void (*draw)()){
int done=0;
SDL_Event event;
Uint8* keys;
long long time,time2;
long long time,time2,timed;
long long t_frame=0;
t_frame=0;
t_frame=proc_t_frame;
time=Time_GetTime();
while(!done){
// Update screen
time=Time_GetTime();
SDL_GL_SwapBuffers();
// Process Events
while(SDL_PollEvent(&event) ){
if(event.type == SDL_QUIT ){
@@ -170,40 +170,38 @@ void Draw_Loop(int (*proc)(),void (*draw)()){
// Sound Frame
Audio_Frame();
// Measure time
time2=Time_GetTime();
t_frame+=time2-time;
time=time2;
// FIX: Limit
if(t_frame>50000){
t_frame=50000;
}
// Process
// Process and draw
if(proc){
while(t_frame>_t_frame && !done){
//while(t_frame>0 && !done){
while(t_frame>=proc_t_frame && !done){
Input_Frame();
if(!proc()){
done=1;
}
t_frame-=_t_frame;
t_frame-=proc_t_frame;
}
}
// Draw
time2=Time_GetTime();
draw();
time2=Time_GetTime()-time2;
if(time2<min_t_frame){
Time_Pause(min_t_frame-time2);
if(draw){
draw();
}
// Measure time
time2=Time_GetTime();
timed=time2-time;
if(timed<draw_t_frame){
Time_Pause(draw_t_frame-timed);
time2=Time_GetTime();
t_frame+=time2-time;
}else{
t_frame+=timed;
}
time=time2;
//Time_Pause(0);
t_frame+=Time_GetTime()-time;
// FIX: Limit process frame rate
if(t_frame>50000){
t_frame=50000;
}
}
}
@@ -327,8 +325,10 @@ DrawImg Draw_LoadImage(char *filename){
image=malloc(sizeof(DrawImage));
image->surf=surf;
image->tex=Draw_UploadGLTexture(surf);
image->x=0;
image->y=0;
//image->x=0;
//image->y=0;
image->x=-(surf->w/2);
image->y=-(surf->h/2);
return((DrawImg)image);
@@ -401,6 +401,39 @@ void Draw_DrawImg(DrawImg img,int x,int y){
}
/////////////////////////////
// Draw_DrawImgResized
//
// Draws an image, resizing.
void Draw_DrawImgResized(DrawImg img,int x,int y,float w,float h){
DrawImage *image=img;
int x1,x2,y1,y2;
// Prepare
x1=x+image->x;
y1=_height-(y+image->y);
x2=(x+image->x)+w;
y2=_height-((y+image->y)+h);
// Draw a quad
glBindTexture(GL_TEXTURE_2D, image->tex);
glBegin (GL_QUADS);
glTexCoord2f (1, 0);
glVertex2i (x2, y1);
glTexCoord2f (0, 0);
glVertex2i (x1, y1);
glTexCoord2f (0, 1);
glVertex2i (x1, y2);
glTexCoord2f (1, 1);
glVertex2i (x2, y2);
glEnd ();
}
/////////////////////////////
// Draw_DrawImgPart
//

View File

@@ -8,7 +8,7 @@
// Draw_Init
//
// Initializes the game window.
int Draw_Init(int width,int height,char *title,int fps);
int Draw_Init(int width,int height,char *title,int pfps,int fps);
/////////////////////////////
@@ -65,6 +65,13 @@ void Draw_GetOffset(DrawImg img,int *x,int *y);
void Draw_DrawImg(DrawImg img,int x,int y);
/////////////////////////////
// Draw_DrawImgResized
//
// Draws an image, resizing.
void Draw_DrawImgResized(DrawImg img,int x,int y,float w,float h);
/////////////////////////////
// Draw_DrawImgPart
//

761
GameLib/Entity.c Normal file
View File

@@ -0,0 +1,761 @@
// Copyright (C) 2011 Valeriano Alfonso Rodriguez (Kableado)
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "Util.h"
#include "Draw.h"
#include "Anim.h"
#include "Entity.h"
/////////////////////////////
// Entity_New
//
//
Entity *_free_entity=NULL;
Entity *Entity_New(){
Entity *e;
if(!_free_entity){
e=malloc(sizeof(Entity));
}else{
e=_free_entity;
_free_entity=e->next;
}
e->base=NULL;
e->type=0;
vec2_set(e->pos,0.0f,0.0f);
e->flags=EntityFlag_Collision|EntityFlag_Overlap;
e->zorder=1;
vec2_set(e->dir,0.0f,0.0f);
vec2_set(e->vel,0.0f,0.0f);
e->radius=1.0f;
e->width=1.0f;
e->height=1.0f;
e->mass=1.0f;
e->elast=0.0f;
e->backFric_static=0.0f;
e->backFric_dynamic=0.0f;
e->fric_static=0.0f;
e->fric_dynamic=0.0f;
AnimPlay_SetImg(&e->anim,NULL);
e->color[0]=e->color[1]=e->color[2]=e->color[3]=1.0f;
e->light[0]=e->light[1]=e->light[2]=e->light[3]=1.0f;
e->oncopy=NULL;
e->ondelete=NULL;
e->proc=NULL;
e->postproc=NULL;
e->collision=NULL;
e->overlap=NULL;
e->A=0;
e->B=0;
e->C=0;
e->D=0;
e->child=NULL;
e->next=NULL;
return(e);
}
/////////////////////////////
// Entity_Destroy
//
//
void Entity_Destroy(Entity *e){
if(e->ondelete){
e->ondelete(e);
}
e->next=_free_entity;
_free_entity=e;
}
/////////////////////////////
// Entity_Copy
//
//
Entity *Entity_Copy(Entity *e){
Entity *n;
n=Entity_New();
n->base=e;
n->type=e->type;
vec2_set(n->pos,e->pos[0],e->pos[1]);
n->flags=e->flags;
n->zorder=e->zorder;
vec2_set(n->vel,e->vel[0],e->vel[1]);
n->radius=e->radius;
n->width=e->width;
n->height=e->height;
n->mass=e->mass;
n->elast=e->elast;
n->backFric_static=e->backFric_static;
n->backFric_dynamic=e->backFric_dynamic;
n->fric_static=e->fric_static;
n->fric_dynamic=e->fric_dynamic;
AnimPlay_Copy(&n->anim,&e->anim);
n->color[0]=e->color[0];
n->color[1]=e->color[1];
n->color[2]=e->color[2];
n->color[3]=e->color[3];
n->light[0]=e->light[0];
n->light[1]=e->light[1];
n->light[2]=e->light[2];
n->light[3]=e->light[3];
n->oncopy=e->oncopy;
n->ondelete=e->ondelete;
n->proc=e->proc;
n->postproc=e->postproc;
n->collision=e->collision;
n->overlap=e->overlap;
n->A=e->A;
n->B=e->B;
n->C=e->C;
n->D=e->D;
n->child=e->child;
// Call the copy event
if(n->oncopy){
n->oncopy(n);
}
return(n);
}
/////////////////////////////
// Entity_Draw
//
//
void Entity_Draw(Entity *e,int x,int y){
Draw_SetColor(e->color[0],e->color[1],e->color[2],e->color[3]);
AnimPlay_Draw(&e->anim,e->pos[0]+x,e->pos[1]+y);
}
/////////////////////////////
// Entity_IsVisible
//
//
int Entity_IsVisible(Entity *e,int x,int y,int w,int h){
int xmax,xmin;
int ymax,ymin;
int ih,iw;
AnimPlay_GetSize(&e->anim,&iw,&ih);
xmin=x-iw;
xmax=x+w+iw;
ymin=y-ih;
ymax=y+h+ih;
if(e->pos[0]<xmin ||
e->pos[0]>xmax ||
e->pos[1]<ymin ||
e->pos[1]>ymax)
{
return(0);
}
return(1);
}
/////////////////////////////
// Entity_Process
//
//
void Entity_Process(Entity *b,int ft){
b->flags&=~EntityFlag_UpdatedPos;
// Launch method
if(b->proc){
b->proc(b,ft);
}
}
/////////////////////////////
// Entity_PostProcess
//
//
void Entity_PostProcess(Entity *e,int ft){
float qlen,len;
// Determine if there is movement
qlen=vec2_dot(e->vel,e->vel);
if(qlen>0.0f){
// Update position
vec2_plus(e->pos,e->pos,e->vel);
// Apply friction
len=sqrtf(qlen);
if(len<e->backFric_static){
// Stopped by static friction
vec2_set(e->vel,0,0);
}else{
// Apply dynamic friction
vec2_scale(e->vel,e->vel,
1.0f-(e->backFric_dynamic+(e->backFric_static/len)));
}
// Mark the update of the position.
vec2_copy(e->oldpos,e->pos);
e->flags|=EntityFlag_UpdatedPos;
}
// Launch method
if(e->postproc){
e->postproc(e,ft);
}
// Animate
AnimPlay_IncTime(&e->anim,ft);
}
/////////////////////////////
// Entity_CollisionResponseClircle
//
// Normal response to a collision between circles.
void Entity_CollisionResponseCircle(
Entity *b1,Entity *b2,float t,vec2 n)
{
float moment;
vec2 temp;
float elast;
if(b1->mass>0.0f && b2->mass>0.0f){
// Calculate elasticity
elast=(b1->mass*b1->elast+b2->mass*b2->elast)/
(b1->mass+b2->mass);
// Collision between two massed balls
moment=((1.0f+elast)*b1->mass*b2->mass*
(fabs(vec2_dot(b1->vel,n))+fabs(vec2_dot(b2->vel,n))))
/(b1->mass+b2->mass);
vec2_scale(temp,n,moment/b1->mass);
vec2_minus(b1->vel,b1->vel,temp);
vec2_scale(temp,n,moment/b2->mass);
vec2_plus(b2->vel,b2->vel,temp);
}else
if(b1->mass>0.0f && b2->mass<=0.0f){
// Collision between a massed ball and a fixed ball
moment=(1.0f+b1->elast)*
(vec2_dot(b1->vel,n));
vec2_scale(temp,n,moment);
vec2_minus(b1->vel,b1->vel,temp);
}else
if(b1->mass<=0.0f && b2->mass>0.0f){
// Collision between a massed ball and a fixed ball
// (imposible, but better safe)
moment=(1.0f+b2->elast)*
(vec2_dot(b2->vel,n));
vec2_scale(temp,n,moment);
vec2_plus(b2->vel,b2->vel,temp);
}else{
// Collision between 2 fixed balls
// (imposible, but better safe)
vec2_set(b1->vel,0,0);
vec2_set(b2->vel,0,0);
}
}
/////////////////////////////
// Entity_CollisionResponseLine
//
// Normal response to a collision with a line.
void Entity_CollisionResponseLine(
Entity *ent,Entity *ent2,float t,vec2 norm,int applyFriction)
{
vec2 pos2,vel2,velFric,intersection;
float dist,fric_static,fric_dynamic,fricLen;
// Calculate friction
fric_static=(ent->fric_static+ent2->fric_static)/2;
fric_dynamic=(ent->fric_dynamic+ent2->fric_dynamic)/2;
// Calculate end position
vec2_scale(vel2,ent->vel,1.0f-t);
dist=-vec2_dot(norm,vel2);
vec2_plus(pos2,ent->pos,ent->vel);
vec2_scaleadd(pos2,pos2,norm,dist);
// Calculate intersection
vec2_scaleadd(intersection,ent->pos,ent->vel,t);
if(applyFriction){
// Apply friction
vec2_minus(velFric,pos2,intersection);
fricLen=sqrtf(vec2_dot(velFric,velFric));
if(fricLen<fric_static){
// Apply static friction
vec2_copy(pos2,intersection);
}else{
// Apply dynamic friction
if(fricLen>0.0f){
vec2_scaleadd(pos2,intersection,velFric,
1.0f-(fric_dynamic+(fric_static/fricLen)));
}else{
vec2_scaleadd(pos2,intersection,velFric,
1.0f-fric_dynamic);
}
}
}
// Apply to velocity
vec2_scaleadd(pos2,pos2,norm,0.1f);
vec2_minus(ent->vel,pos2,ent->pos);
}
/////////////////////////////
// Entity_Collide
//
//
int Entity_Collide(Entity *b1,Entity *b2){
float t;
vec2 n,p;
vec2 vel;
int flags=b1->flags|b2->flags;
if(flags&EntityFlag_Platform && !(flags&EntityFlag_Block)){
// One of the entities is a platform and none is a block
Entity *ent,*ent_plat;
float plat_width;
vec2 p;
// Decide who is the platform and who is the ent
if(b1->mass<=0.0f && b2->mass>0.0f){
ent=b2;
ent_plat=b1;
}else
if(b2->mass<=0.0f && b1->mass>0.0f){
ent=b1;
ent_plat=b2;
}else{
// Two static or two dinamic entities?!?
return(0);
}
// Check Top
vec2_set(n,0,-1);
vec2_scaleadd(p,ent_plat->pos,n,(ent->height+ent_plat->height)/2);
plat_width=ent_plat->width+ent->width;
if(Intersect_RayEdge(ent->pos,ent->vel,
n,p,plat_width,&t))
{
int response=1;
int rc;
// Check the collision methods
if(ent->collision){
rc=ent->collision(ent,ent_plat,t,n);
if (rc==0)
response=0;
if (rc>1)
response=2;
}
if(ent_plat->collision){
vec2 n2;
vec2_scale(n2,n,-1.0f);
rc=ent_plat->collision(ent_plat,ent,t,n2);
if (rc==0)
response=0;
if (rc>1)
response=2;
}
// Collision response
if(response==1){
Entity_CollisionResponseLine(ent,ent_plat,t,n,1);
return(1);
}
if (response==2) {
return(1);
}
return(0);
}
return(0);
}
if(flags&EntityFlag_Block && !(flags&EntityFlag_Platform)){
// One of the entities is a block and none is a platform
Entity *ent,*ent_block;
float auxT,block_len;
vec2 auxN,p;
int applyFriction;
// Decide who is the block and who is the ent
if(b1->mass<=0.0f && b2->mass>0.0f){
ent=b2;
ent_block=b1;
}else
if(b2->mass<=0.0f && b1->mass>0.0f){
ent=b1;
ent_block=b2;
}else{
// Two static or two dinamic entities?!?
return(0);
}
// Prepare some variables
t=1.0f;
applyFriction=1;
// Check Top
vec2_set(auxN,0,-1);
vec2_scaleadd(p,ent_block->pos,auxN,(ent->height+ent_block->height)/2);
block_len=ent_block->width+ent->width;
if(Intersect_RayEdge(ent->pos,ent->vel,
auxN,p,block_len,&auxT))
{
if(auxT<t){
vec2_copy(n,auxN);
t=auxT;
applyFriction=1;
}
}
// Check Bottom
vec2_set(auxN,0,1);
vec2_scaleadd(p,ent_block->pos,auxN,(ent->height+ent_block->height)/2);
block_len=ent_block->width+ent->width;
if(Intersect_RayEdge(ent->pos,ent->vel,
auxN,p,block_len,&auxT))
{
if(auxT<t){
vec2_copy(n,auxN);
t=auxT;
applyFriction=1;
}
}
// Check Left
vec2_set(auxN,1,0);
vec2_scaleadd(p,ent_block->pos,auxN,(ent->width+ent_block->width)/2);
block_len=ent_block->height+ent->height;
if(Intersect_RayEdge(ent->pos,ent->vel,
auxN,p,block_len,&auxT))
{
if(auxT<t){
vec2_copy(n,auxN);
t=auxT;
applyFriction=0;
}
}
// Check Right
vec2_set(auxN,-1,0);
vec2_scaleadd(p,ent_block->pos,auxN,(ent->width+ent_block->width)/2);
block_len=ent_block->height+ent->height;
if(Intersect_RayEdge(ent->pos,ent->vel,
auxN,p,block_len,&auxT))
{
if(auxT<t){
vec2_copy(n,auxN);
t=auxT;
applyFriction=0;
}
}
if(t<1.0f){
// Handle colision
int response=1;
int rc;
// Check the collision methods
if(ent->collision){
rc=ent->collision(ent,ent_block,t,n);
if (rc==0)
response=0;
if (rc>1)
response=2;
}
if(ent_block->collision){
vec2 n2;
vec2_scale(n2,n,-1.0f);
rc=ent_block->collision(ent_block,ent,t,n2);
if (rc==0)
response=0;
if (rc>1)
response=2;
}
// Collision response
if(response==1){
Entity_CollisionResponseLine(ent,ent_block,t,n,applyFriction);
return(1);
}
if (response==2) {
return(1);
}
return(0);
}
return(0);
}
// Test relative to b1
vec2_minus(vel,b1->vel,b2->vel);
if(Colision_CircleCircle(b1->pos,b1->radius,vel,b2->pos,b2->radius,&t,n)){
int response=1;
int rc;
vec2 n2;
vec2_scale(n2,n,-1.0f);
// Check the collision methods
if(b1->collision){
rc=b1->collision(b1,b2,t,n2);
if (rc==0)
response=0;
if (rc>1)
response=2;
}
if(b2->collision){
rc=b2->collision(b2,b1,t,n);
if (rc==0)
response=0;
if (rc>1)
response=2;
}
// Collision response
if(response==1){
if(vec2_dot(b1->vel,b1->vel)>vec2_dot(b2->vel,b2->vel)){
Entity_CollisionResponseCircle(b1,b2,t,n);
}else{
Entity_CollisionResponseCircle(b2,b1,t,n);
}
return(1);
}
if (response==2) {
return(1);
}
return(0);
}
return(0);
}
/////////////////////////////
// Entity_Overlaps
//
//
void Entity_Overlaps(Entity *b1,Entity *b2){
vec2 len;
vec2_minus(len,b1->pos,b2->pos);
vec2_set(len,fabs(b1->pos[0]-b2->pos[0]),fabs(b1->pos[1]-b2->pos[1]));
if(b1->overlap){
if( len[0]<=b1->radius &&
len[1]<=b1->radius)
{
b1->overlap(b1,b2);
}
}
if(b2->overlap){
if( len[0]<=b2->radius &&
len[1]<=b2->radius)
{
b2->overlap(b2,b1);
}
}
}
/////////////////////////////
// Entity_GetPos
//
//
void Entity_GetPos(Entity *e,vec2 pos){
vec2_copy(pos,e->pos);
}
/////////////////////////////
// Entity_UpdatePos
//
//
void Entity_UpdatePos(Entity *e,vec2 pos){
// Mark the update of the position.
vec2_copy(e->oldpos,e->pos);
e->flags|=EntityFlag_UpdatedPos;
vec2_copy(e->pos,pos);
}
/////////////////////////////
// Entity_AddVelLimit
//
//
void Entity_AddVelLimit(Entity *e,vec2 vel,float limit){
float vlen_orig,vlen;
vec2 dir,vel_temp;
// Normalize vel getting vel
vlen_orig=sqrtf(vec2_dot(vel,vel));
vec2_scale(dir,vel,1.0f/vlen_orig);
// Limit velocity
vlen=vec2_dot(e->vel,dir);
if(vlen<limit){
vlen=limit-vlen;
if(vlen>vlen_orig){
vlen=vlen_orig;
}
vec2_scale(vel_temp,dir,vlen);
vec2_plus(e->vel,e->vel,vel_temp);
}
}
/////////////////////////////
// Entity_SetColor
//
//
void Entity_SetColor(Entity *e,float r,float g,float b,float a){
e->color[0]=r;
e->color[1]=g;
e->color[2]=b;
e->color[3]=a;
}
/////////////////////////////
// Entity_AddColor
//
//
void Entity_AddColor(Entity *e,float r,float g,float b,float a){
e->color[0]+=r;
if(e->color[0]>1.0f)
e->color[0]=1.0f;
e->color[1]+=g;
if(e->color[1]>1.0f)
e->color[1]=1.0f;
e->color[2]+=b;
if(e->color[2]>1.0f)
e->color[2]=1.0f;
e->color[3]+=a;
if(e->color[3]>1.0f)
e->color[3]=1.0f;
}
/////////////////////////////
// Entity_SetLight
//
//
void Entity_SetLight(Entity *e,float r,float g,float b,float rad){
e->light[0]=r;
e->light[1]=g;
e->light[2]=b;
e->light[3]=rad;
}
/////////////////////////////
// Entity_Iluminate
//
//
void Entity_Iluminate(Entity *e,Entity **elist,int n){
int i;
vec2 vdist;
float qdist,f;
float qrad;
if(!(e->flags&EntityFlag_Light)){
Entity_SetColor(e,
e->light[0],
e->light[1],
e->light[2],
1.0f);
}else{
Entity_SetColor(e,1.0f,1.0f,1.0f,1.0f);
return;
}
for(i=0;i<n;i++){
if(e==elist[i] || !(elist[i]->flags&EntityFlag_Light))
continue;
vec2_minus(vdist,e->pos,elist[i]->pos);
qdist=vec2_dot(vdist,vdist);
qrad=elist[i]->light[3]*elist[i]->light[3];
if(qdist<qrad){
f=1.0f-qdist/qrad;
Entity_AddColor(e,
f*elist[i]->light[0],
f*elist[i]->light[1],
f*elist[i]->light[2],
1.0f);
}
}
}
/////////////////////////////
// Entity_MarkUpdateLight
//
//
void Entity_MarkUpdateLight(Entity *e,Entity **elist,int n){
if(e->flags&EntityFlag_Light){
int i;
vec2 max,min;
if(e->pos[0]<e->oldpos[0]){
min[0]=e->pos[0]-e->light[3];
max[0]=e->oldpos[0]+e->light[3];
}else{
min[0]=e->oldpos[0]-e->light[3];
max[0]=e->pos[0]+e->light[3];
}
if(e->pos[1]<e->oldpos[1]){
min[1]=e->pos[1]-e->light[3];
max[1]=e->oldpos[1]+e->light[3];
}else{
min[1]=e->oldpos[1]-e->light[3];
max[1]=e->pos[1]+e->light[3];
}
for(i=0;i<n;i++){
if( min[0]<=elist[i]->pos[0] &&
max[0]>=elist[i]->pos[0] &&
min[1]<=elist[i]->pos[1] &&
max[1]>=elist[i]->pos[1])
{
elist[i]->flags|=EntityFlag_UpdateLight;
}
}
}else{
e->flags|=EntityFlag_UpdateLight;
}
}

View File

@@ -7,29 +7,40 @@
#include "Draw.h"
#include "Anim.h"
#define EntityFlag_Collision 1
#define EntityFlag_Overlap 2
#define EntityFlag_Light 4
#define EntityFlag_UpdateLight 8
#define EntityFlag_UpdatedPos 16
////////////////////////////////////////////////
// Entity //
////////////
//
#define EntityFlag_Collision 1
#define EntityFlag_Platform 2
#define EntityFlag_Block 4
#define EntityFlag_PlatformCollision 3
#define EntityFlag_BlockCollision 5
#define EntityFlag_Overlap 8
#define EntityFlag_Light 16
#define EntityFlag_UpdateLight 32
#define EntityFlag_UpdatedPos 64
typedef struct Tag_Entity {
struct Tag_Entity *base;
int type;
vec2 oldpos;
vec2 pos;
int flags;
int zorder;
vec2 dir;
vec2 vel;
vec2 bod_offset;
float radius;
float width;
float height;
float mass;
float elast;
float backFric_static;
float backFric_dynamic;
float fric_static;
float fric_dynamic;
@@ -51,6 +62,9 @@ typedef struct Tag_Entity {
struct Tag_Entity *ent2);
int A;
int B;
int C;
int D;
struct Tag_Entity *child;
void *next;
@@ -84,6 +98,11 @@ Entity *Entity_Copy(Entity *e);
//
void Entity_Draw(Entity *e,int x,int y);
/////////////////////////////
// Entity_IsVisible
//
//
int Entity_IsVisible(Entity *e,int x,int y,int w,int h);
/////////////////////////////
// Entity_Process
@@ -99,13 +118,21 @@ void Entity_PostProcess(Entity *e,int ft);
/////////////////////////////
// Entity_CollisionResponse
// Entity_CollisionResponseClircle
//
// Normal response to a collision.
void Entity_CollisionResponse(
// Normal response to a collision of spheres.
void Entity_CollisionResponseCircle(
Entity *b1,Entity *b2,float t,vec2 n);
/////////////////////////////
// Entity_CollisionResponseLine
//
// Normal response to a collision with a line.
void Entity_CollisionResponseLine(
Entity *ent,Entity *ent2,float t,vec2 n,int applyFriction);
/////////////////////////////
// Entity_Collide
//
@@ -120,6 +147,20 @@ int Entity_Collide(Entity *b1,Entity *b2);
void Entity_Overlaps(Entity *b1,Entity *b2);
/////////////////////////////
// Entity_GetPos
//
//
void Entity_GetPos(Entity *e,vec2 pos);
/////////////////////////////
// Entity_UpdatePos
//
//
void Entity_UpdatePos(Entity *e,vec2 pos);
/////////////////////////////
// Entity_AddVelLimit
//
@@ -153,6 +194,11 @@ void Entity_SetLight(Entity *e,float r,float g,float b,float rad);
//
void Entity_Iluminate(Entity *e,Entity **elist,int n);
/////////////////////////////
// Entity_MarkUpdateLight
//
//
void Entity_MarkUpdateLight(Entity *e,Entity **elist,int n);
#endif

View File

@@ -23,6 +23,7 @@ int _entities_lock=0;
int _entities_compactate=0;
void (*_gameproc)()=NULL;
void (*_gamepostproc)()=NULL;
void (*_gamepredraw)()=NULL;
void (*_gamedraw)()=NULL;
int _ft;
int _game_size[2];
@@ -43,8 +44,8 @@ int gamelib_debug=0;
// GameLib_Init
//
// Initializes the game.
int GameLib_Init(int w,int h,char *title,int fps){
if(!Draw_Init(w,h,title,fps)){
int GameLib_Init(int w,int h,char *title,int pfps,int fps){
if(!Draw_Init(w,h,title,pfps,fps)){
return(0);
}
if(!Input_Init()){
@@ -98,7 +99,7 @@ void GameLib_AddEntity(Entity *e){
_n_entities++;
// Mark for light update
GameLib_EntityUpdateLight(e);
Entity_MarkUpdateLight(e,_entity,_n_entities);
}
@@ -120,7 +121,7 @@ int GameLib_UnrefEntity(Entity *e){
_entities_compactate=1;
// Mark for light update
GameLib_EntityUpdateLight(e);
Entity_MarkUpdateLight(e,_entity,_n_entities);
return(i);
}
}
@@ -290,7 +291,7 @@ int GameLib_ProcLoop(){
for(i=0;i<_n_entities;i++){
Entity_PostProcess(_entity[i],_ft);
if(_entity[i]->flags&EntityFlag_UpdatedPos){
GameLib_EntityUpdateLight(_entity[i]);
Entity_MarkUpdateLight(_entity[i],_entity,_n_entities);
}
}
if(_gamepostproc){
@@ -318,24 +319,28 @@ void GameLib_DrawLoop(){
// Update Lights
//GameLib_UpdateIlumination();
// Limpiar pantalla
Draw_Clean(0,0,0);
// Predibujado
if(_gamepredraw){
_gamepredraw();
}else{
// Limpiar pantalla
Draw_Clean(0,0,0);
}
// Draw entities
GameLib_Compactate();_entities_lock=1;
for(i=0;i<_n_entities;i++){
Entity *e;
Entity *e=_entity[i];
// FIXME: This is a hack
e=_entity[i];
if(e->pos[0]<(_game_pos[0]-128))
continue;
if(e->pos[0]>(_game_pos[0]+_game_size[0]+128))
continue;
if(e->pos[1]<(_game_pos[1]-128))
continue;
if(e->pos[1]>(_game_pos[1]+_game_size[1]+128))
// Check visivility
if(!Entity_IsVisible(e,
_game_pos[0],_game_pos[1],
_game_size[0],_game_size[1]))
{
continue;
}
// Update ilumination of this entity
if(e->flags&EntityFlag_UpdateLight){
@@ -345,6 +350,7 @@ void GameLib_DrawLoop(){
Entity_Draw(e,-_game_pos[0],-_game_pos[1]);
}
Draw_SetColor(1,1,1,1);
if(_gamedraw){
_gamedraw();
}
@@ -364,12 +370,14 @@ void GameLib_DrawLoop(){
void GameLib_Loop(
void (*gameproc)(),
void (*gamepostproc)(),
void (*gamepredraw)(),
void (*gamedraw)())
{
_running=1;
_gameproc=gameproc;
_gamepostproc=gamepostproc;
_gamepredraw=gamepredraw;
_gamedraw=gamedraw;
t_proc=0;
t_col=0;
@@ -420,6 +428,28 @@ void GameLib_GetSize(int size[2]){
}
/////////////////////////////
// GameLib_MoveToPos
// GameLib_MoveToPosH
// GameLib_MoveToPosV
//
//
void GameLib_MoveToPos(vec2 pos,float f){
GameLib_MoveToPosH(pos,f);
GameLib_MoveToPosV(pos,f);
}
void GameLib_MoveToPosH(vec2 pos,float f){
_game_pos[0]=_game_pos[0]+(pos[0]-(_game_pos[0]+(_game_size[0]/2.0f)))*f;
}
void GameLib_MoveToPosV(vec2 pos,float f){
_game_pos[1]=_game_pos[1]+(pos[1]-(_game_pos[1]+(_game_size[1]/2.0f)))*f;
}
/////////////////////////////
// GameLib_ForEachEn
//
@@ -452,6 +482,24 @@ void GameLib_ForEachEnt(int (*func)(Entity *ent)){
}
/////////////////////////////
// GameLib_SearchEnt
//
// Searches throught the entities.
Entity *GameLib_SearchEnt(int (*func)(Entity *ent,void *d),void *d){
int i;
Entity *ent=NULL;
for(i=0;i<_n_entities;i++){
if(!_entity[i])
continue;
if(func(_entity[i],d)){
ent=_entity[i];
break;
}
}
return ent;
}
/////////////////////////////
// GameLib_PlaySound
//
@@ -512,9 +560,9 @@ void GameLib_Iluminate(){
//
void GameLib_EntitySetLight(Entity *e,float r,float g,float b,float rad){
if(e->flags&EntityFlag_Light){
GameLib_EntityUpdateLight(e);
Entity_MarkUpdateLight(e,_entity,_n_entities);
Entity_SetLight(e,r,g,b,rad);
GameLib_EntityUpdateLight(e);
Entity_MarkUpdateLight(e,_entity,_n_entities);
}else{
Entity_SetLight(e,r,g,b,rad);
e->flags|=EntityFlag_UpdateLight;
@@ -522,32 +570,6 @@ void GameLib_EntitySetLight(Entity *e,float r,float g,float b,float rad){
}
/////////////////////////////
// GameLib_EntityUpdateLight
//
//
void GameLib_EntityUpdateLight(Entity *e){
if(e->flags&EntityFlag_Light){
int i;
vec2 max,min;
vec2_set(max,e->pos[0]+e->light[3],e->pos[1]+e->light[3]);
vec2_set(min,e->pos[0]-e->light[3],e->pos[1]-e->light[3]);
for(i=0;i<_n_entities;i++){
if( min[0]<=_entity[i]->pos[0] &&
max[0]>=_entity[i]->pos[0] &&
min[1]<=_entity[i]->pos[1] &&
max[1]>=_entity[i]->pos[1])
{
_entity[i]->flags|=EntityFlag_UpdateLight;
}
}
}else{
e->flags|=EntityFlag_UpdateLight;
}
}
/////////////////////////////
// GameLib_UpdateIlumination
//

View File

@@ -16,7 +16,7 @@
// GameLib_Init
//
// Initializes the game.
int GameLib_Init(int w,int h,char *title,int fps);
int GameLib_Init(int w,int h,char *title,int pfps,int fps);
/////////////////////////////
@@ -47,6 +47,7 @@ int GameLib_DelEntity(Entity *e);
void GameLib_Loop(
void (*gameproc)(),
void (*gamepostproc)(),
void (*gamepredraw)(),
void (*gamedraw)());
@@ -68,6 +69,17 @@ void GameLib_SetPos(int pos[2]);
void GameLib_GetSize(int size[2]);
/////////////////////////////
// GameLib_MoveToPos
// GameLib_MoveToPosH
// GameLib_MoveToPosV
//
//
void GameLib_MoveToPos(vec2 pos,float f);
void GameLib_MoveToPosH(vec2 pos,float f);
void GameLib_MoveToPosV(vec2 pos,float f);
/////////////////////////////
// GameLib_ForEachEn
//
@@ -76,12 +88,19 @@ void GameLib_DelEnts();
/////////////////////////////
// GameLib_ForEachEn
// GameLib_ForEachEnt
//
// Iterates every entity.
void GameLib_ForEachEnt(int (*func)(Entity *ent));
/////////////////////////////
// GameLib_SearchEnt
//
// Searches throught the entities.
Entity *GameLib_SearchEnt(int (*func)(Entity *ent,void *d),void *d);
/////////////////////////////
// GameLib_PlaySound
//
@@ -103,13 +122,6 @@ void GameLib_Iluminate();
void GameLib_EntitySetLight(Entity *e,float r,float g,float b,float rad);
/////////////////////////////
// GameLib_EntityUpdateLight
//
//
void GameLib_EntityUpdateLight(Entity *e);
/////////////////////////////
// GameLib_UpdateIlumination
//

View File

@@ -5,7 +5,6 @@
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
#include <SDL/SDL.h>
#include "Time.h"
@@ -38,7 +37,7 @@ void Time_Pause(int pausa){
do{
diff=tend-t;
if(diff>1000){
SDL_Delay(diff/1000);
Sleep(diff/1000);
}else{
Sleep(0);
}

View File

@@ -4,6 +4,17 @@
#include "Util.h"
////////////////////////////////////////////////
// vec2 //
//////////
// A 2D vector.
float vec2_norm(vec2 v){
float len;
len=vec2_len(v);
vec2_scale(v,v,1.0f/len);
return(len);
}
/////////////////////////////
// SolveQuadratic
@@ -30,6 +41,7 @@ int SolveQuadratic(float a,float b,float c,float *Rmin,float *Rmax){
return(1);
}
/////////////////////////////
// Intersec_RayUnitCircle
//
@@ -57,7 +69,7 @@ int Intersec_RayUnitCircle(vec2 orig,vec2 vel,vec2 center,float *t){
*t=Rmin;
return(1);
}
if(Rmax>=-1.0f && Rmin>Rmax && Rmax<=1.0f){
if(Rmax>=-0.0f && Rmin>Rmax && Rmax<=1.0f){
*t=Rmax;
return(1);
}
@@ -102,7 +114,6 @@ int Colision_CircleCircle(
return(0);
// Convert to a unit circle vs ray
rads=rad1+rad2;
invrads=1.0f/rads;
vec2_scale(vel_a,vel,invrads);
vec2_scale(orig_a,cir1,invrads);
@@ -118,3 +129,75 @@ int Colision_CircleCircle(
return(0);
}
/////////////////////////////
// Intersect_RayEdge
//
// Intersection between a ray and a edge.
int Intersect_RayEdge(
vec2 pos,vec2 vel,
vec2 norm,vec2 edgePos,float len,
float *t)
{
vec2 pos2,intersection,perp,edgePos2;
float delta,d1,d2,hLen;
vec2_plus(pos2,pos,vel);
hLen=len/2;
// Check intersection against the line
delta=vec2_dot(norm,edgePos);
d1=vec2_dot(pos ,norm)-delta;
d2=vec2_dot(pos2,norm)-delta;
if(d1>=-0.0001f && d2<=0.0001f){
// Intersection with line, Calculate intersection point
*t=d1/(d1-d2);
vec2_scaleadd(intersection,pos,vel,*t);
// Perpendicular
vec2_perp(perp,norm);
// Check sides
vec2_scaleadd(edgePos2,edgePos,perp,-hLen);
delta=-vec2_dot(perp,edgePos2);
d1=(-vec2_dot(perp,intersection))-delta;
vec2_scaleadd(edgePos2,edgePos,perp,hLen);
delta=vec2_dot(perp,edgePos2);
d2=vec2_dot(perp,intersection)-delta;
if(d1<=0.0f && d2<=0.0f){
// Intersection inside Edge.
return(1);
}
}
return(0);
}
/////////////////////////////
// absmod
//
int absmod(int v,int d){
if(v<0){
v+=d*(((v/d)*(-1))+1);
return(v);
}else{
return(v%d);
}
}
float fabsmod(float v,int d){
if(v<0){
v+=d*((((int)(v/d))*(-1))+1);
return(v);
}else{
v-=d*(((int)(v/d))+1);
return(v);
}
}

View File

@@ -22,6 +22,10 @@ typedef float vec2[2];
#define vec2_minus(v,v1,v2) (v)[0]=(v1)[0]-(v2)[0];(v)[1]=(v1)[1]-(v2)[1];
#define vec2_scale(v,v1,s) (v)[0]=(v1)[0]*(s);(v)[1]=(v1)[1]*(s);
#define vec2_dot(v1,v2) ((v1)[0]*(v2)[0]+(v1)[1]*(v2)[1])
#define vec2_len(v) sqrtf((v)[0]*(v)[0]+(v)[1]*(v)[1])
#define vec2_perp(v,n) (v)[0]=-(n)[1];(v)[1]=(n)[0];
#define vec2_scaleadd(v,v1,v2,s) (v)[0]=(v2)[0]*(s)+(v1)[0];(v)[1]=(v2)[1]*(s)+(v1)[1];
float vec2_norm(vec2 v);
/////////////////////////////
@@ -30,7 +34,6 @@ typedef float vec2[2];
// Intersection between a ray and a Unit Circle.
int Intersec_RayUnitCircle(vec2 orig,vec2 vel,vec2 center,float *t);
/////////////////////////////
// Intersect_CircleCircle
//
@@ -40,5 +43,22 @@ int Colision_CircleCircle(
vec2 cb,float rb,
float *t,vec2 n);
/////////////////////////////
// Intersect_RayEdge
//
// Intersection between a ray and a edge.
int Intersect_RayEdge(
vec2 pos,vec2 vel,
vec2 norm,vec2 edgePos,float len,
float *t);
/////////////////////////////
// absmod
//
int absmod(int v,int d);
float fabsmod(float v,int d);
#endif

View File

@@ -65,6 +65,8 @@ int GameMapAux_IsFloor(char c){
c=='<' ||
c=='>' ||
c=='r' ||
c=='T' ||
c=='D' ||
c=='l' )
{
return(1);
@@ -185,6 +187,16 @@ int GameMap_CreateLevel(int level,int point){
// ArrowShooter up
GameMapAux_CreateEnt(ent_arrowshooter_up,i,j);
}else
if(line[i2]=='T'){
// Teleporter
Entity *ent=GameMapAux_CreateEnt(ent_teleporter,i,j);
ent->A=line[i2+1]-'0';
}else
if(line[i2]=='D'){
// Teleporter Destination
Entity *ent=GameMapAux_CreateEnt(ent_teleporter_dest,i,j);
ent->A=line[i2+1]-'0';
}else
{}
}

View File

@@ -1,59 +1,90 @@
HEADS= \
Time.h \
Util.h \
Draw.h \
Input.h \
Audio.h \
Anim.h \
Entity.h \
GameLib.h \
GameEnts.h \
GameMap.h
########################
# GameLib Declarations #
########################
CFLAGS += -IGameLib
HEADS= \
GameLib/Time.h \
GameLib/Util.h \
GameLib/Draw.h \
GameLib/Input.h \
GameLib/Audio.h \
GameLib/Anim.h \
GameLib/Entity.h \
GameLib/GameLib.h
OBJS= \
$(BUILDDIR)/Time.o \
$(BUILDDIR)/Util.o \
$(BUILDDIR)/Draw.o \
$(BUILDDIR)/Input.o \
$(BUILDDIR)/Audio.o \
$(BUILDDIR)/Anim.o \
$(BUILDDIR)/Entity.o \
$(BUILDDIR)/GameLib.o \
$(BUILDDIR)/GameLib/Time.o \
$(BUILDDIR)/GameLib/Util.o \
$(BUILDDIR)/GameLib/Draw.o \
$(BUILDDIR)/GameLib/Input.o \
$(BUILDDIR)/GameLib/Audio.o \
$(BUILDDIR)/GameLib/Anim.o \
$(BUILDDIR)/GameLib/Entity.o \
$(BUILDDIR)/GameLib/GameLib.o \
#####################
# Game Declarations #
#####################
HEADS+= GameEnts.h GameMap.h
OBJS+= \
$(BUILDDIR)/GameEnts.o \
$(BUILDDIR)/GameMap.o \
$(BUILDDIR)/main.o
#################
# General Rules #
#################
all: $(BUILDDIR) $(BUILDDIR)/$(RESULT)
$(BUILDDIR):
mkdir $(BUILDDIR)
mkdir $(BUILDDIR)/GameLib
clean:
rm -f $(OBJS) $(BUILDDIR)/$(RESULT)
run: $(BUILDDIR)/$(RESULT)
./$(BUILDDIR)/$(RESULT) debug
$(BUILDDIR)/Time.o: Time.c $(HEADS)
$(CC) -c Time.c -o $(BUILDDIR)/Time.o $(CFLAGS)
$(BUILDDIR)/Util.o: Util.c $(HEADS)
$(CC) -c Util.c -o $(BUILDDIR)/Util.o $(CFLAGS)
$(BUILDDIR)/Draw.o: Draw.c $(HEADS)
$(CC) -c Draw.c -o $(BUILDDIR)/Draw.o $(CFLAGS)
#################
# GameLib Rules #
#################
$(BUILDDIR)/GameLib/Time.o: GameLib/Time.c $(HEADS)
$(CC) -c GameLib/Time.c -o $(BUILDDIR)/GameLib/Time.o $(CFLAGS)
$(BUILDDIR)/GameLib/Util.o: GameLib/Util.c $(HEADS)
$(CC) -c GameLib/Util.c -o $(BUILDDIR)/GameLib/Util.o $(CFLAGS)
$(BUILDDIR)/GameLib/Draw.o: GameLib/Draw.c $(HEADS)
$(CC) -c GameLib/Draw.c -o $(BUILDDIR)/GameLib/Draw.o $(CFLAGS)
$(BUILDDIR)/GameLib/Input.o: GameLib/Input.c $(HEADS)
$(CC) -c GameLib/Input.c -o $(BUILDDIR)/GameLib/Input.o $(CFLAGS)
$(BUILDDIR)/GameLib/Audio.o: GameLib/Audio.c $(HEADS)
$(CC) -c GameLib/Audio.c -o $(BUILDDIR)/GameLib/Audio.o $(CFLAGS)
$(BUILDDIR)/GameLib/Entity.o: GameLib/Entity.c $(HEADS)
$(CC) -c GameLib/Entity.c -o $(BUILDDIR)/GameLib/Entity.o $(CFLAGS)
$(BUILDDIR)/GameLib/Anim.o: GameLib/Anim.c $(HEADS)
$(CC) -c GameLib/Anim.c -o $(BUILDDIR)/GameLib/Anim.o $(CFLAGS)
$(BUILDDIR)/GameLib/GameLib.o: GameLib/GameLib.c $(HEADS)
$(CC) -c GameLib/GameLib.c -o $(BUILDDIR)/GameLib/GameLib.o $(CFLAGS)
$(BUILDDIR)/Input.o: Input.c $(HEADS)
$(CC) -c Input.c -o $(BUILDDIR)/Input.o $(CFLAGS)
$(BUILDDIR)/Audio.o: Audio.c $(HEADS)
$(CC) -c Audio.c -o $(BUILDDIR)/Audio.o $(CFLAGS)
$(BUILDDIR)/Entity.o: Entity.c $(HEADS)
$(CC) -c Entity.c -o $(BUILDDIR)/Entity.o $(CFLAGS)
$(BUILDDIR)/Anim.o: Anim.c $(HEADS)
$(CC) -c Anim.c -o $(BUILDDIR)/Anim.o $(CFLAGS)
$(BUILDDIR)/GameLib.o: GameLib.c $(HEADS)
$(CC) -c GameLib.c -o $(BUILDDIR)/GameLib.o $(CFLAGS)
##############
# Game Rules #
##############
$(BUILDDIR)/GameEnts.o: GameEnts.c $(HEADS)
$(CC) -c GameEnts.c -o $(BUILDDIR)/GameEnts.o $(CFLAGS)
@@ -68,10 +99,5 @@ $(BUILDDIR)/$(RESULT): $(OBJS)
$(CC) -o $(BUILDDIR)/$(RESULT) $(OBJS) $(LIBS) $(CFLAGS)
clean:
rm -f $(OBJS) $(BUILDDIR)/$(RESULT)
run: $(BUILDDIR)/$(RESULT)
./$(BUILDDIR)/$(RESULT) debug

View File

@@ -2,7 +2,7 @@ TODO
----
- Entities:
- Teleporters
- Doors
- Doors and Buttons
- Buttons
- Music
- Non-SFXR sounds

BIN
a.out

Binary file not shown.

BIN
data/._level_03.txt Normal file

Binary file not shown.

BIN
data/arrow_down.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 790 B

BIN
data/arrow_left.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 864 B

BIN
data/arrow_right.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 881 B

BIN
data/arrow_up.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 800 B

BIN
data/arrowshooter_down.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

BIN
data/arrowshooter_left.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

BIN
data/arrowshooter_right.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

BIN
data/arrowshooter_up.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 8.1 KiB

BIN
data/barrel.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 8.1 KiB

BIN
data/barrel2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 16 KiB

BIN
data/column.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 16 KiB

BIN
data/column_faded.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

BIN
data/end.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 8.1 KiB

BIN
data/end_point.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

BIN
data/exit_point.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

BIN
data/fire.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

BIN
data/floor.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

BIN
data/floor_center.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

BIN
data/floor_left.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

BIN
data/floor_right.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 16 KiB

BIN
data/hole_lava.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 8.1 KiB

BIN
data/hole_spiked.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

BIN
data/lamp.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@@ -1,11 +1,11 @@
33 23
############ll################ ######ll############ll####
##..........................## ##......................##
##....T0................D1..## ##......................##
##..................||......ll########....||||||||||||||....##
##..S1..............||..............S2....||................##
##..................||......llmmmmmmmm....||....||||||||||||##
##..........................mm mm....||................##
##....T1................D0..mm mm....||................##
##mmmmmmmmmmllmmmmmmmmmmmmmmmm mmmmmmmmmmmmll..llmmmmmm##
mm..mm
mm..mm

BIN
data/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

View File

@@ -0,0 +1,23 @@
33 23
############ll################ ######ll############ll####
##..........................## ##......................##
##..................||......ll########....||||||||||||||....##
##..S1..............||..............S2....||................##
##..................||......llmmmmmmmm....||....||||||||||||##
##..........................mm mm....||................##
##mmmmmmmmmmllmmmmmmmmmmmmmmmm mmmmmmmmmmmmll..llmmmmmm##
mm..mm
mm..mm
mm..mm
mm..mm
##########S3##########
##..................##
##..................##
ll..................ll
mm..BBBBBB..BBBBBB..mm
mm||||||||ll||||||||mm
mm..................mm
mm..................mm
mm........EE........mm
mmmmmmmmmmmmmmmmmmmmmm

View File

@@ -0,0 +1,51 @@
100 100
##################
##......S1......##
##..............##
##..............##
##..............##
##mmmmll..llmmmm##
mm..mm
mm..mm
mm..mm
mm..mm
mm..mm
mm..mm
############S2##############
##||||||||........||||||||##
##||||||||..BBll..||||||||##
ll||....||||BB....||||||||ll
mm||..||||||||||||||||||||mm
mm||..||||||||||||||||||||mm
mm||..||||||||||||||||||||mm
mm||..........BB||||BB..||mm
mm||||||||||..||||||||||||mm
mmmmmmmmmmll..llmmmmmmmmmmmm
mm..mm
mm..mm
mm..mm
mm..mm
mm..mm
############S3############
##......||......||......##
##......||..BB..||......##
ll......||||||||||..BB..ll
mm||||||rrrrllrrrr||||||mm
mm......................mm
mm||||||....BB....||||||mm
mm......rr||||||rr......mm
mm......||rrrrrr||......mm
mm....BB||......||......mm
mmmmmmmmmmll..llmmmmmmmmmm
mm..mm
mm..mm
mm..mm
mm..mm
mm..mm
########..########
##..............##
##..............##
##..............##
##......EE......##
##mmmmmmmmmmmmmm##

View File

@@ -0,0 +1,23 @@
33 23
############ll################ ##########################
##..........................## ##......................##
##..................LL......ll########....LLLLLLLLLLLLLL....##
##..S1..............LL..............S2....LL................##
##..................LL......llmmmmmmmm....LL....LLLLLLLLLLLL##
##..........................mm mm....LL................##
##mmmmmmmmmmllmmmmmmmmmmmmmmmm mmmmmmmmmmmmll..llmmmmmm##
mm..mm
mm..mm
mm..mm
mm..mm
##########S3##########
##..................##
##..................##
ll..................ll
##..BBBBBB..BBBBBB..##
##LLLLLLLLrr||||||||##
##..................##
##..................##
##........EE........##
##mmmmmmmmmmmmmmmmmm##

View File

@@ -0,0 +1,29 @@
100 100
##################
##......S1......##
##..............##
##..............##
##..............##
##mmmmll..llmmmm##
mm..mm
mm..mm
mm..mm
mm..mm
##############S2##############
##||||||||||||..||||||||||||##
##||........||..||........||## ################
##||..LLLLBB||..||..LLLL..||## ##............##
##||............||........||## ##............##
##||||||||..||||||||||||||||ll########............##
##||||||||||||||||............................EE..##
##||||||||..||||||||||||||||llmmmmmmmm............##
##||....BB....||..........||mm mm............##
##||..LLLL..||||||BBLLLL..||mm mm............##
##||........||||||........||mm mmmmmmmmmmmmmm##
##||||||||||||||||||||||||||mm
mmmmmmmmmmmmmmmmmmmmmmmmmmmmmm

View File

@@ -0,0 +1,26 @@
33 26
############ll################ ######ll##########ll######
##..........................## ##................VV....##
##..........................ll########......................##
##..S1..............................S2......................##
##..........................llmmmmmmmm>>....................##
##..................AA......mm mm........AA............##
##mmmmmmmmmmllmmmmmmmmmmmmmmmm mmmmmmmmmmmmll..llmmmmmm##
mm..mm
mm..mm
mm..mm
mm..mm
##########S3##########
##..................##
##............BBBB..##
##................<<##
ll..BBBB............ll
##>>................##
##............BBBB..##
##................<<##
ll..BBBB............ll
##>>................##
##..................##
##........EE........##
##mmmmmmmmmmmmmmmmmm##

View File

@@ -0,0 +1,69 @@
100 100
##################
##......S1......##
##..............##
##..............##
##..............##
##mmmmll..llmmmm##
mm..mm
mm..mm
mm..mm
mm..mm
mm..mm
mm..mm
####ll######S2######ll####
##......................##
##..BB..BB......BB..BB..##
##......................##
##LLLLLLLLrr||rrLLLLLLLL##
##......AA......AA......##
##mmmmmmmmll..llmmmmmmmm##
mm..mm
mm..mm
mm..mm
mm..mm
############S3############
##....VV..VV..........LL##
##LLLLLLLLLLLLLLLLLL..LL##
##LL..................LL##
##LL..LLLLLLLLLLLLLLLLLL##
##LL..................LL##
##LLLLLLLLLLLLLLLLLL..LL##
##LL..................LL##
##LL..LLLLLLLLLLLLLLLLLL##
##LL..........AA..AA....##
##mmmmmmmmll..llmmmmmmmm##
mm..mm
mm..mm
mm..mm
mm..mm
mm..mm
######VV##VVS4############
##LLLLLLLLLL..LLLLLLLLLL##
##LLLLLLLLLL..........LL##
>>LLLLLLLLLLLLLLLLLL..LL##
mmLL..................LL##
mmLL..LLLLLLLLLLLLLLLLLL<<
mmLL..................LLmm
>>LLLLLLLLLLLLLLLLLL..LLmm
mmLL..................LLmm
mmLL..LLLLLLLLLLLLLLLLLL<<
mmLL..........LLLLLLLLLLmm
mmLLLLLLLLLL..LLLLLLLLLLmm
mmmmmmmmmmmm..AAmmAAmmmmmm
ll..ll
mm..mm
mm..mm
mm..mm
mm..mm
########..########
##..............##
##..............##
##..............##
##......EE......##
##mmmmmmmmmmmmmm##

View File

@@ -0,0 +1,21 @@
100 100
##################
##......S1......##
##..............##
##..............##
##..............##
##mmmmll..llmmmm##
mm..mm
mm..mm
mm..mm
mm..mm
########..########
##..............##
##..............##
##..............##
##......FF......##
##mmmmmmmmmmmmmm##

BIN
data/player_broken.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

BIN
data/player_down.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

BIN
data/player_left.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

BIN
data/player_right.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

BIN
data/player_up.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 8.1 KiB

BIN
data/rock.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

BIN
data/save_point.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

BIN
data/save_point_active.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

BIN
game.exe Normal file

Binary file not shown.

BIN
game.save

Binary file not shown.

8
main.c
View File

@@ -46,7 +46,7 @@ void DrawTitle(){
Draw_Clean(0,0,0);
Draw_SetColor(1.0f,1.0f,1.0f,1.0f);
Draw_DrawImg(img_logo,170,100);
Draw_DrawImg(img_logo,320,150);
if(!game_started){
Draw_DrawText(font,"Press [Space] to Start.",300,300);
}else{
@@ -73,7 +73,7 @@ void DrawEnd(){
Draw_Clean(0,0,0);
Draw_SetColor(1.0f,1.0f,1.0f,1.0f);
Draw_DrawImg(img_end,170,100);
Draw_DrawImg(img_end,320,150);
Draw_DrawText(font,"Congratulations you saved the kittie!",250,320);
Draw_DrawText(font,"Thanks for playing!",250,350);
@@ -174,7 +174,7 @@ int main(int argc,char *argv[]){
}
}
GameLib_Init(640,480,"Game",60);
GameLib_Init(640,480,"Game",60,60);
img_logo=Draw_LoadImage("data/logo.bmp");
img_end=Draw_LoadImage("data/end.bmp");
@@ -199,7 +199,7 @@ int main(int argc,char *argv[]){
GameMap_CreateLevel(game_level,game_level_point);
game_started=1;
}
GameLib_Loop(ProcGame,PostProcGame,DrawGame);
GameLib_Loop(ProcGame,PostProcGame,NULL,DrawGame);
}
if(play==2){
Draw_Loop(ProcEnd,DrawEnd);