Simplify data structures usage
This commit is contained in:
88
GameEnts.c
88
GameEnts.c
@@ -13,9 +13,9 @@ DrawImg img_player;
|
||||
DrawImg img_platform;
|
||||
DrawImg img_block;
|
||||
|
||||
Entity *ent_Player;
|
||||
Entity *ent_Platform;
|
||||
Entity *ent_Block;
|
||||
Entity ent_Player;
|
||||
Entity ent_Platform;
|
||||
Entity ent_Block;
|
||||
|
||||
|
||||
DrawImg img_wizard[2];
|
||||
@@ -42,31 +42,31 @@ DrawImg img_axe[2];
|
||||
DrawImg img_goatMan[2];
|
||||
DrawImg img_Princess[2];
|
||||
|
||||
Entity *ent_Wizard;
|
||||
Entity *ent_MagikBall;
|
||||
Entity *ent_Earth;
|
||||
Entity *ent_EarthBack;
|
||||
Entity *ent_StoneBrick;
|
||||
Entity *ent_StoneBrickBack;
|
||||
Entity *ent_SpikedBush;
|
||||
Entity *ent_Fireball;
|
||||
Entity *ent_LavaPit;
|
||||
Entity *ent_Spike[2];
|
||||
Entity *ent_Flower[2];
|
||||
Entity *ent_CarnivorePlant[2];
|
||||
Entity *ent_Bunny;
|
||||
Entity *ent_Spider;
|
||||
Entity *ent_Axe;
|
||||
Entity *ent_Guard;
|
||||
Entity *ent_EliteGuard;
|
||||
Entity *ent_GoatMan;
|
||||
Entity *ent_Princess;
|
||||
|
||||
|
||||
|
||||
int EntityApplyGravity(Entity *e){
|
||||
float grav=0.5f;
|
||||
float vTerminal=10.0f;
|
||||
Entity ent_Wizard;
|
||||
Entity ent_MagikBall;
|
||||
Entity ent_Earth;
|
||||
Entity ent_EarthBack;
|
||||
Entity ent_StoneBrick;
|
||||
Entity ent_StoneBrickBack;
|
||||
Entity ent_SpikedBush;
|
||||
Entity ent_Fireball;
|
||||
Entity ent_LavaPit;
|
||||
Entity ent_Spike[2];
|
||||
Entity ent_Flower[2];
|
||||
Entity ent_CarnivorePlant[2];
|
||||
Entity ent_Bunny;
|
||||
Entity ent_Spider;
|
||||
Entity ent_Axe;
|
||||
Entity ent_Guard;
|
||||
Entity ent_EliteGuard;
|
||||
Entity ent_GoatMan;
|
||||
Entity ent_Princess;
|
||||
|
||||
|
||||
|
||||
int EntityApplyGravity(Entity e){
|
||||
vec2 vGrav;
|
||||
|
||||
// Only apply gravity to some entity types
|
||||
@@ -97,7 +97,7 @@ int EntityApplyGravity(Entity *e){
|
||||
|
||||
|
||||
|
||||
void EntEarth_Init(Entity *ent,int up,int down,int left,int right){
|
||||
void EntEarth_Init(Entity ent,int up,int down,int left,int right){
|
||||
int val=up*8+right*4+down*2+left;
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ void EntEarth_Init(Entity *ent,int up,int down,int left,int right){
|
||||
AnimPlay_SetImg(&ent->anim,img_earth[val]);
|
||||
}
|
||||
|
||||
void EntStoneBrick_Init(Entity *ent,int up,int down,int left,int right){
|
||||
void EntStoneBrick_Init(Entity ent,int up,int down,int left,int right){
|
||||
if(!up && !down && !left && !right){
|
||||
ent->flags=0;
|
||||
}else
|
||||
@@ -129,7 +129,7 @@ void EntStoneBrick_Init(Entity *ent,int up,int down,int left,int right){
|
||||
|
||||
|
||||
|
||||
void player_proc(Entity *e,int ft){
|
||||
void player_proc(Entity e,int ft){
|
||||
float acel=1.0f;
|
||||
float maxVel=4.0f;
|
||||
float jumpVel=12.0f;
|
||||
@@ -170,11 +170,11 @@ void player_proc(Entity *e,int ft){
|
||||
|
||||
|
||||
|
||||
void wizard_proc(Entity *e,int ft){
|
||||
float acel=1.0f;
|
||||
float maxVel=6.0f;
|
||||
float jumpVel=8.0f;
|
||||
float shootVel=10.0f;
|
||||
void wizard_proc(Entity e,int ft){
|
||||
|
||||
if(Input_GetKey(InputKey_Jump)==InputKey_Pressed ||
|
||||
Input_GetKey(InputKey_Up)==InputKey_Pressed)
|
||||
@@ -212,7 +212,7 @@ void wizard_proc(Entity *e,int ft){
|
||||
if(Input_GetKey(InputKey_Action1)==InputKey_Pressed ||
|
||||
Input_GetKey(InputKey_Action2)==InputKey_Pressed)
|
||||
{
|
||||
Entity *e2;
|
||||
Entity e2;
|
||||
|
||||
// Create child entity
|
||||
e2=Entity_Copy(e->child);
|
||||
@@ -236,12 +236,12 @@ void wizard_proc(Entity *e,int ft){
|
||||
|
||||
|
||||
|
||||
int magikball_collision(Entity *ent,Entity *ent2,float t,vec2 n){
|
||||
int magikball_collision(Entity ent,Entity ent2,float t,vec2 n){
|
||||
if(ent->A==1)
|
||||
return(0);
|
||||
|
||||
if(ent2->type==Ent_Flower){
|
||||
Entity *e2;
|
||||
Entity e2;
|
||||
// Convert a flower
|
||||
|
||||
// Create replacemente entity
|
||||
@@ -253,7 +253,7 @@ int magikball_collision(Entity *ent,Entity *ent2,float t,vec2 n){
|
||||
GameLib_DelEntity(ent2);
|
||||
}
|
||||
if(ent2->type==Ent_Bunny){
|
||||
Entity *e2;
|
||||
Entity e2;
|
||||
// Convert a bunny
|
||||
printf("Bunny\n");
|
||||
|
||||
@@ -279,13 +279,13 @@ int magikball_collision(Entity *ent,Entity *ent2,float t,vec2 n){
|
||||
}
|
||||
|
||||
|
||||
void spikedentity_overlap(Entity *e,Entity *e2){
|
||||
void spikedentity_overlap(Entity e,Entity e2){
|
||||
// FIXME: damage player
|
||||
printf("FIXME: damage player\n");
|
||||
}
|
||||
|
||||
|
||||
int spike_collision(Entity *ent,Entity *ent2,float t,vec2 n){
|
||||
int spike_collision(Entity ent,Entity ent2,float t,vec2 n){
|
||||
if(ent->A==1)
|
||||
return(0);
|
||||
|
||||
@@ -305,13 +305,13 @@ int spike_collision(Entity *ent,Entity *ent2,float t,vec2 n){
|
||||
return(0);
|
||||
}
|
||||
|
||||
void flower_oncopy(Entity *ent){
|
||||
void flower_oncopy(Entity ent){
|
||||
ent->A=rand()%ent->C;
|
||||
}
|
||||
|
||||
void flower_proc(Entity *ent,int ft){
|
||||
void flower_proc(Entity ent,int ft){
|
||||
if(ent->A==0){
|
||||
Entity *e2;
|
||||
Entity e2;
|
||||
|
||||
// Create child entity
|
||||
e2=Entity_Copy(ent->child);
|
||||
@@ -332,7 +332,7 @@ void flower_proc(Entity *ent,int ft){
|
||||
|
||||
|
||||
|
||||
void bunny_proc(Entity *e,int ft){
|
||||
void bunny_proc(Entity e,int ft){
|
||||
float acel=1.0f;
|
||||
float maxVel=4.0f;
|
||||
float jumpVel=5.0f;
|
||||
@@ -370,7 +370,7 @@ void bunny_proc(Entity *e,int ft){
|
||||
AnimPlay_SetImg(&e->anim,img_bunny[1]);
|
||||
}
|
||||
}
|
||||
int bunny_collision(Entity *ent,Entity *ent2,float t,vec2 n){
|
||||
int bunny_collision(Entity ent,Entity ent2,float t,vec2 n){
|
||||
if(n[0]>0.5f){
|
||||
ent->A=1;
|
||||
}else
|
||||
@@ -391,7 +391,7 @@ int bunny_collision(Entity *ent,Entity *ent2,float t,vec2 n){
|
||||
|
||||
|
||||
|
||||
void spider_proc(Entity *e,int ft){
|
||||
void spider_proc(Entity e,int ft){
|
||||
float acel=1.0f;
|
||||
float maxVel=4.0f;
|
||||
float jumpVel=5.0f;
|
||||
@@ -429,7 +429,7 @@ void spider_proc(Entity *e,int ft){
|
||||
AnimPlay_SetImg(&e->anim,img_spider[1]);
|
||||
}
|
||||
}
|
||||
int spider_collision(Entity *ent,Entity *ent2,float t,vec2 n){
|
||||
int spider_collision(Entity ent,Entity ent2,float t,vec2 n){
|
||||
if(n[0]>0.5f){
|
||||
ent->A=1;
|
||||
}else
|
||||
@@ -613,7 +613,7 @@ void GameEnts_Init(){
|
||||
ent_Earth->width=32;
|
||||
ent_Earth->height=32;
|
||||
ent_Earth->fric_static=0.0f;
|
||||
ent_Earth->fric_dynamic=0.2f;
|
||||
ent_Earth->fric_dynamic=0.6f;
|
||||
|
||||
|
||||
// FIXME: Earth back
|
||||
|
||||
50
GameEnts.h
50
GameEnts.h
@@ -31,36 +31,36 @@ enum {
|
||||
Ent_Princess
|
||||
} EntityType;
|
||||
|
||||
extern Entity *ent_Player;
|
||||
extern Entity *ent_Platform;
|
||||
extern Entity *ent_Block;
|
||||
extern Entity ent_Player;
|
||||
extern Entity ent_Platform;
|
||||
extern Entity ent_Block;
|
||||
|
||||
extern Entity *ent_Wizard;
|
||||
extern Entity *ent_MagikBall;
|
||||
extern Entity *ent_Earth;
|
||||
extern Entity *ent_EarthBack;
|
||||
extern Entity *ent_StoneBrick;
|
||||
extern Entity *ent_StoneBrickBack;
|
||||
extern Entity *ent_SpikedBush;
|
||||
extern Entity *ent_LavaPit;
|
||||
extern Entity *ent_Fireball;
|
||||
extern Entity *ent_Spike[2];
|
||||
extern Entity *ent_Flower[2];
|
||||
extern Entity *ent_CarnivorePlant[2];
|
||||
extern Entity *ent_Bunny;
|
||||
extern Entity *ent_Spider;
|
||||
extern Entity *ent_Axe;
|
||||
extern Entity *ent_Guard;
|
||||
extern Entity *ent_EliteGuard;
|
||||
extern Entity *ent_GoatMan;
|
||||
extern Entity *ent_Princess;
|
||||
extern Entity ent_Wizard;
|
||||
extern Entity ent_MagikBall;
|
||||
extern Entity ent_Earth;
|
||||
extern Entity ent_EarthBack;
|
||||
extern Entity ent_StoneBrick;
|
||||
extern Entity ent_StoneBrickBack;
|
||||
extern Entity ent_SpikedBush;
|
||||
extern Entity ent_LavaPit;
|
||||
extern Entity ent_Fireball;
|
||||
extern Entity ent_Spike[2];
|
||||
extern Entity ent_Flower[2];
|
||||
extern Entity ent_CarnivorePlant[2];
|
||||
extern Entity ent_Bunny;
|
||||
extern Entity ent_Spider;
|
||||
extern Entity ent_Axe;
|
||||
extern Entity ent_Guard;
|
||||
extern Entity ent_EliteGuard;
|
||||
extern Entity ent_GoatMan;
|
||||
extern Entity ent_Princess;
|
||||
|
||||
|
||||
int EntityApplyGravity(Entity *e);
|
||||
int EntityApplyGravity(Entity e);
|
||||
|
||||
void EntEarth_Init(Entity *ent,int up,int down,int left,int right);
|
||||
void EntEarth_Init(Entity ent,int up,int down,int left,int right);
|
||||
|
||||
void EntStoneBrick_Init(Entity *ent,int up,int down,int left,int right);
|
||||
void EntStoneBrick_Init(Entity ent,int up,int down,int left,int right);
|
||||
|
||||
|
||||
void GameEnts_Init();
|
||||
|
||||
@@ -34,7 +34,7 @@ int _width;
|
||||
int _height;
|
||||
long long proc_t_frame=33333;
|
||||
long long draw_t_frame=16667;
|
||||
QuadArray2D *_quadArray=NULL;
|
||||
QuadArray2D _quadArray=NULL;
|
||||
GLuint _tex=-1;
|
||||
float _color[4];
|
||||
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
// Entity_New
|
||||
//
|
||||
//
|
||||
Entity *_free_entity=NULL;
|
||||
Entity *Entity_New(){
|
||||
Entity *e;
|
||||
Entity _free_entity=NULL;
|
||||
Entity Entity_New(){
|
||||
Entity e;
|
||||
|
||||
if(!_free_entity){
|
||||
e=malloc(sizeof(Entity));
|
||||
e=malloc(sizeof(TEntity));
|
||||
}else{
|
||||
e=_free_entity;
|
||||
_free_entity=e->next;
|
||||
@@ -76,7 +76,7 @@ Entity *Entity_New(){
|
||||
// Entity_Destroy
|
||||
//
|
||||
//
|
||||
void Entity_Destroy(Entity *e){
|
||||
void Entity_Destroy(Entity e){
|
||||
if(e->ondelete){
|
||||
e->ondelete(e);
|
||||
}
|
||||
@@ -89,8 +89,8 @@ void Entity_Destroy(Entity *e){
|
||||
// Entity_Copy
|
||||
//
|
||||
//
|
||||
Entity *Entity_Copy(Entity *e){
|
||||
Entity *n;
|
||||
Entity Entity_Copy(Entity e){
|
||||
Entity n;
|
||||
|
||||
n=Entity_New();
|
||||
|
||||
@@ -147,7 +147,7 @@ Entity *Entity_Copy(Entity *e){
|
||||
// Entity_Draw
|
||||
//
|
||||
//
|
||||
void Entity_Draw(Entity *e,int x,int y,float f){
|
||||
void Entity_Draw(Entity e,int x,int y,float f){
|
||||
vec2 fPos;
|
||||
Draw_SetColor(e->color[0],e->color[1],e->color[2],e->color[3]);
|
||||
if(e->flags&EntityFlag_UpdatedPos){
|
||||
@@ -164,7 +164,7 @@ void Entity_Draw(Entity *e,int x,int y,float f){
|
||||
// Entity_IsVisible
|
||||
//
|
||||
//
|
||||
int Entity_IsVisible(Entity *e,int x,int y,int w,int h){
|
||||
int Entity_IsVisible(Entity e,int x,int y,int w,int h){
|
||||
int xmax,xmin;
|
||||
int ymax,ymin;
|
||||
int ih,iw;
|
||||
@@ -192,7 +192,7 @@ int Entity_IsVisible(Entity *e,int x,int y,int w,int h){
|
||||
// Entity_Process
|
||||
//
|
||||
//
|
||||
void Entity_Process(Entity *b,int ft){
|
||||
void Entity_Process(Entity b,int ft){
|
||||
b->flags&=~EntityFlag_UpdatedPos;
|
||||
|
||||
// Launch method
|
||||
@@ -206,7 +206,7 @@ void Entity_Process(Entity *b,int ft){
|
||||
// Entity_PostProcess
|
||||
//
|
||||
//
|
||||
void Entity_PostProcess(Entity *e,int ft){
|
||||
void Entity_PostProcess(Entity e,int ft){
|
||||
float qlen,len;
|
||||
|
||||
vec2_copy(e->pos0,e->pos);
|
||||
@@ -249,7 +249,7 @@ void Entity_PostProcess(Entity *e,int ft){
|
||||
//
|
||||
// Normal response to a collision between circles.
|
||||
void Entity_CollisionResponseCircle(
|
||||
Entity *b1,Entity *b2,float t,vec2 n)
|
||||
Entity b1,Entity b2,float t,vec2 n)
|
||||
{
|
||||
float moment;
|
||||
vec2 temp;
|
||||
@@ -297,7 +297,7 @@ void Entity_CollisionResponseCircle(
|
||||
//
|
||||
// Normal response to a collision with a line.
|
||||
void Entity_CollisionResponseLine(
|
||||
Entity *ent,Entity *ent2,float t,vec2 norm,int applyFriction)
|
||||
Entity ent,Entity ent2,float t,vec2 norm,int applyFriction)
|
||||
{
|
||||
vec2 pos2,vel2,velFric,intersection;
|
||||
float dist,fric_static,fric_dynamic,fricLen;
|
||||
@@ -344,7 +344,7 @@ void Entity_CollisionResponseLine(
|
||||
// Entity_Collide
|
||||
//
|
||||
//
|
||||
int Entity_Collide(Entity *b1,Entity *b2){
|
||||
int Entity_Collide(Entity b1,Entity b2){
|
||||
float t;
|
||||
vec2 n,p;
|
||||
vec2 vel;
|
||||
@@ -352,7 +352,7 @@ int Entity_Collide(Entity *b1,Entity *b2){
|
||||
|
||||
if(flags&EntityFlag_Platform && !(flags&EntityFlag_Block)){
|
||||
// One of the entities is a platform and none is a block
|
||||
Entity *ent,*ent_plat;
|
||||
Entity ent,ent_plat;
|
||||
float plat_width;
|
||||
vec2 p;
|
||||
|
||||
@@ -414,7 +414,7 @@ int Entity_Collide(Entity *b1,Entity *b2){
|
||||
|
||||
if(flags&EntityFlag_Block && !(flags&EntityFlag_Platform)){
|
||||
// One of the entities is a block and none is a platform
|
||||
Entity *ent,*ent_block;
|
||||
Entity ent,ent_block;
|
||||
float auxT,block_len;
|
||||
vec2 auxN,p;
|
||||
int applyFriction;
|
||||
@@ -576,7 +576,7 @@ int Entity_Collide(Entity *b1,Entity *b2){
|
||||
// Entity_Overlaps
|
||||
//
|
||||
//
|
||||
void Entity_Overlaps(Entity *b1,Entity *b2){
|
||||
void Entity_Overlaps(Entity b1,Entity b2){
|
||||
vec2 len;
|
||||
|
||||
vec2_minus(len,b1->pos,b2->pos);
|
||||
@@ -603,7 +603,7 @@ void Entity_Overlaps(Entity *b1,Entity *b2){
|
||||
// Entity_GetPos
|
||||
//
|
||||
//
|
||||
void Entity_GetPos(Entity *e,vec2 pos){
|
||||
void Entity_GetPos(Entity e,vec2 pos){
|
||||
vec2_copy(pos,e->pos);
|
||||
}
|
||||
|
||||
@@ -611,7 +611,7 @@ void Entity_GetPos(Entity *e,vec2 pos){
|
||||
// Entity_UpdatePos
|
||||
//
|
||||
//
|
||||
void Entity_UpdatePos(Entity *e,vec2 pos){
|
||||
void Entity_UpdatePos(Entity e,vec2 pos){
|
||||
|
||||
// Mark the update of the position.
|
||||
vec2_copy(e->oldpos,e->pos);
|
||||
@@ -624,7 +624,7 @@ void Entity_UpdatePos(Entity *e,vec2 pos){
|
||||
// Entity_AddVelLimit
|
||||
//
|
||||
//
|
||||
void Entity_AddVelLimit(Entity *e,vec2 vel,float limit){
|
||||
void Entity_AddVelLimit(Entity e,vec2 vel,float limit){
|
||||
float vlen_orig,vlen;
|
||||
vec2 dir,vel_temp;
|
||||
|
||||
@@ -649,7 +649,7 @@ void Entity_AddVelLimit(Entity *e,vec2 vel,float limit){
|
||||
// Entity_SetColor
|
||||
//
|
||||
//
|
||||
void Entity_SetColor(Entity *e,float r,float g,float b,float a){
|
||||
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;
|
||||
@@ -661,7 +661,7 @@ void Entity_SetColor(Entity *e,float r,float g,float b,float a){
|
||||
// Entity_AddColor
|
||||
//
|
||||
//
|
||||
void Entity_AddColor(Entity *e,float r,float g,float b,float a){
|
||||
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;
|
||||
@@ -681,7 +681,7 @@ void Entity_AddColor(Entity *e,float r,float g,float b,float a){
|
||||
// Entity_SetLight
|
||||
//
|
||||
//
|
||||
void Entity_SetLight(Entity *e,float r,float g,float b,float rad){
|
||||
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;
|
||||
@@ -694,7 +694,7 @@ void Entity_SetLight(Entity *e,float r,float g,float b,float rad){
|
||||
// Entity_Iluminate
|
||||
//
|
||||
//
|
||||
void Entity_Iluminate(Entity *e,Entity **elist,int n){
|
||||
void Entity_Iluminate(Entity e,Entity *elist,int n){
|
||||
int i;
|
||||
vec2 vdist;
|
||||
float qdist,f;
|
||||
@@ -734,7 +734,7 @@ void Entity_Iluminate(Entity *e,Entity **elist,int n){
|
||||
// Entity_MarkUpdateLight
|
||||
//
|
||||
//
|
||||
void Entity_MarkUpdateLight(Entity *e,Entity **elist,int n){
|
||||
void Entity_MarkUpdateLight(Entity e,Entity *elist,int n){
|
||||
if(e->flags&EntityFlag_Light){
|
||||
int i;
|
||||
vec2 max,min;
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Entity //
|
||||
////////////
|
||||
// Entity
|
||||
//
|
||||
#define EntityFlag_Collision 1
|
||||
#define EntityFlag_Platform 2
|
||||
@@ -21,8 +20,9 @@
|
||||
#define EntityFlag_Light 16
|
||||
#define EntityFlag_UpdateLight 32
|
||||
#define EntityFlag_UpdatedPos 64
|
||||
typedef struct Tag_Entity {
|
||||
struct Tag_Entity *base;
|
||||
typedef struct TEntity TEntity, *Entity;
|
||||
struct TEntity {
|
||||
Entity base;
|
||||
|
||||
int type;
|
||||
vec2 oldpos;
|
||||
@@ -50,72 +50,60 @@ typedef struct Tag_Entity {
|
||||
float color[4];
|
||||
float light[4];
|
||||
|
||||
void (*oncopy)(struct Tag_Entity *ent);
|
||||
void (*ondelete)(struct Tag_Entity *ent);
|
||||
void (*proc)(struct Tag_Entity *ent,int ft);
|
||||
void (*postproc)(struct Tag_Entity *ent,int ft);
|
||||
int (*collision)(
|
||||
struct Tag_Entity *ent,
|
||||
struct Tag_Entity *ent2,
|
||||
float t,vec2 n);
|
||||
void (*overlap)(
|
||||
struct Tag_Entity *ent,
|
||||
struct Tag_Entity *ent2);
|
||||
void (*oncopy)(Entity ent);
|
||||
void (*ondelete)(Entity ent);
|
||||
void (*proc)(Entity ent,int ft);
|
||||
void (*postproc)(Entity ent,int ft);
|
||||
int (*collision)(Entity ent, Entity ent2, float t,vec2 n);
|
||||
void (*overlap)(Entity ent, Entity ent2);
|
||||
|
||||
int A;
|
||||
int B;
|
||||
int C;
|
||||
int D;
|
||||
struct Tag_Entity *child;
|
||||
Entity child;
|
||||
|
||||
void *next;
|
||||
} Entity;
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Entity_New
|
||||
//
|
||||
//
|
||||
Entity *Entity_New();
|
||||
Entity Entity_New();
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Entity_Destroy
|
||||
//
|
||||
//
|
||||
void Entity_Destroy(Entity *e);
|
||||
void Entity_Destroy(Entity e);
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Entity_Copy
|
||||
//
|
||||
//
|
||||
Entity *Entity_Copy(Entity *e);
|
||||
Entity Entity_Copy(Entity e);
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Entity_Draw
|
||||
//
|
||||
//
|
||||
void Entity_Draw(Entity *e,int x,int y,float f);
|
||||
void Entity_Draw(Entity e,int x,int y,float f);
|
||||
|
||||
/////////////////////////////
|
||||
// Entity_IsVisible
|
||||
//
|
||||
//
|
||||
int Entity_IsVisible(Entity *e,int x,int y,int w,int h);
|
||||
int Entity_IsVisible(Entity e,int x,int y,int w,int h);
|
||||
|
||||
/////////////////////////////
|
||||
// Entity_Process
|
||||
//
|
||||
//
|
||||
void Entity_Process(Entity *e,int ft);
|
||||
void Entity_Process(Entity e,int ft);
|
||||
|
||||
/////////////////////////////
|
||||
// Entity_PostProcess
|
||||
//
|
||||
//
|
||||
void Entity_PostProcess(Entity *e,int ft);
|
||||
void Entity_PostProcess(Entity e,int ft);
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
@@ -123,7 +111,7 @@ void Entity_PostProcess(Entity *e,int ft);
|
||||
//
|
||||
// Normal response to a collision of spheres.
|
||||
void Entity_CollisionResponseCircle(
|
||||
Entity *b1,Entity *b2,float t,vec2 n);
|
||||
Entity b1,Entity b2,float t,vec2 n);
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
@@ -131,75 +119,65 @@ void Entity_CollisionResponseCircle(
|
||||
//
|
||||
// Normal response to a collision with a line.
|
||||
void Entity_CollisionResponseLine(
|
||||
Entity *ent,Entity *ent2,float t,vec2 n,int applyFriction);
|
||||
Entity ent,Entity ent2,float t,vec2 n,int applyFriction);
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Entity_Collide
|
||||
//
|
||||
//
|
||||
int Entity_Collide(Entity *b1,Entity *b2);
|
||||
int Entity_Collide(Entity b1,Entity b2);
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Entity_Overlaps
|
||||
//
|
||||
//
|
||||
void Entity_Overlaps(Entity *b1,Entity *b2);
|
||||
void Entity_Overlaps(Entity b1,Entity b2);
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Entity_GetPos
|
||||
//
|
||||
//
|
||||
void Entity_GetPos(Entity *e,vec2 pos);
|
||||
void Entity_GetPos(Entity e,vec2 pos);
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Entity_UpdatePos
|
||||
//
|
||||
//
|
||||
void Entity_UpdatePos(Entity *e,vec2 pos);
|
||||
void Entity_UpdatePos(Entity e,vec2 pos);
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Entity_AddVelLimit
|
||||
//
|
||||
//
|
||||
void Entity_AddVelLimit(Entity *e,vec2 vel,float limit);
|
||||
void Entity_AddVelLimit(Entity e,vec2 vel,float limit);
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Entity_SetColor
|
||||
//
|
||||
//
|
||||
void Entity_SetColor(Entity *e,float r,float g,float b,float a);
|
||||
void Entity_SetColor(Entity e,float r,float g,float b,float a);
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Entity_AddColor
|
||||
//
|
||||
//
|
||||
void Entity_AddColor(Entity *e,float r,float g,float b,float a);
|
||||
void Entity_AddColor(Entity e,float r,float g,float b,float a);
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Entity_AddColor
|
||||
//
|
||||
//
|
||||
void Entity_SetLight(Entity *e,float r,float g,float b,float rad);
|
||||
void Entity_SetLight(Entity e,float r,float g,float b,float rad);
|
||||
|
||||
/////////////////////////////
|
||||
// Entity_AddColor
|
||||
//
|
||||
//
|
||||
void Entity_Iluminate(Entity *e,Entity **elist,int n);
|
||||
void Entity_Iluminate(Entity e,Entity *elist,int n);
|
||||
|
||||
/////////////////////////////
|
||||
// Entity_MarkUpdateLight
|
||||
//
|
||||
//
|
||||
void Entity_MarkUpdateLight(Entity *e,Entity **elist,int n);
|
||||
void Entity_MarkUpdateLight(Entity e,Entity *elist,int n);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
// Globals
|
||||
int _running;
|
||||
Entity **_entity=NULL;
|
||||
Entity *_entity=NULL;
|
||||
int *_entity_flag=NULL;
|
||||
int _n_entities=0;
|
||||
int _n_entities_res=0;
|
||||
@@ -71,9 +71,9 @@ int GameLib_Init(int w,int h,char *title,int pfps,int fps){
|
||||
// GameLib_AddEntity
|
||||
//
|
||||
// Adds an entity to the game.
|
||||
void GameLib_AddEntity(Entity *e){
|
||||
void GameLib_AddEntity(Entity e){
|
||||
if(_n_entities>=_n_entities_res){
|
||||
Entity **entity_aux;
|
||||
Entity *entity_aux;
|
||||
int *entity_flag_aux;
|
||||
int i;
|
||||
|
||||
@@ -82,7 +82,7 @@ void GameLib_AddEntity(Entity *e){
|
||||
_n_entities_res=32;
|
||||
else
|
||||
_n_entities_res*=2;
|
||||
entity_aux=malloc(sizeof(Entity *)*_n_entities_res);
|
||||
entity_aux=malloc(sizeof(Entity)*_n_entities_res);
|
||||
entity_flag_aux=malloc(sizeof(int)*_n_entities_res);
|
||||
for(i=0;i<_n_entities;i++){
|
||||
entity_aux[i]=_entity[i];
|
||||
@@ -110,7 +110,7 @@ void GameLib_AddEntity(Entity *e){
|
||||
// GameLib_UnrefEntity
|
||||
//
|
||||
// removes the reference to the entity.
|
||||
int GameLib_UnrefEntity(Entity *e){
|
||||
int GameLib_UnrefEntity(Entity e){
|
||||
int i;
|
||||
for(i=0;i<_n_entities;i++){
|
||||
if(e==_entity[i]){
|
||||
@@ -136,7 +136,7 @@ int GameLib_UnrefEntity(Entity *e){
|
||||
// GameLib_DelEntity
|
||||
//
|
||||
// Adds an entity to the game.
|
||||
int GameLib_DelEntity(Entity *e){
|
||||
int GameLib_DelEntity(Entity e){
|
||||
int i;
|
||||
if((i=GameLib_UnrefEntity(e))==-1){
|
||||
return(0);
|
||||
@@ -281,7 +281,7 @@ int GameLib_ProcLoop(){
|
||||
}
|
||||
}
|
||||
if(swap){
|
||||
Entity *ent;
|
||||
Entity ent;
|
||||
ent=_entity[i];
|
||||
_entity[i]=_entity[i-1];
|
||||
_entity[i-1]=ent;
|
||||
@@ -337,7 +337,7 @@ void GameLib_DrawLoop(float f){
|
||||
// Draw entities
|
||||
GameLib_Compactate();_entities_lock=1;
|
||||
for(i=0;i<_n_entities;i++){
|
||||
Entity *e=_entity[i];
|
||||
Entity e=_entity[i];
|
||||
|
||||
// Check visivility
|
||||
if(!Entity_IsVisible(e,
|
||||
@@ -481,7 +481,7 @@ void GameLib_DelEnts(){
|
||||
// GameLib_ForEachEn
|
||||
//
|
||||
// Iterates every entity.
|
||||
void GameLib_ForEachEnt(int (*func)(Entity *ent)){
|
||||
void GameLib_ForEachEnt(int (*func)(Entity ent)){
|
||||
int i;
|
||||
for(i=0;i<_n_entities;i++){
|
||||
if(!_entity[i])
|
||||
@@ -551,7 +551,7 @@ void GameLib_Iluminate(){
|
||||
// GameLib_EntitySetLight
|
||||
//
|
||||
//
|
||||
void GameLib_EntitySetLight(Entity *e,float r,float g,float b,float rad){
|
||||
void GameLib_EntitySetLight(Entity e,float r,float g,float b,float rad){
|
||||
if(e->flags&EntityFlag_Light){
|
||||
Entity_MarkUpdateLight(e,_entity,_n_entities);
|
||||
Entity_SetLight(e,r,g,b,rad);
|
||||
|
||||
@@ -23,21 +23,21 @@ int GameLib_Init(int w,int h,char *title,int pfps,int fps);
|
||||
// GameLib_AddEntity
|
||||
//
|
||||
// Adds an entity to the game.
|
||||
void GameLib_AddEntity(Entity *e);
|
||||
void GameLib_AddEntity(Entity e);
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// GameLib_UnrefEntity
|
||||
//
|
||||
// removes the reference to the entity.
|
||||
int GameLib_UnrefEntity(Entity *e);
|
||||
int GameLib_UnrefEntity(Entity e);
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// GameLib_DelEntity
|
||||
//
|
||||
// Adds an entity to the game.
|
||||
int GameLib_DelEntity(Entity *e);
|
||||
int GameLib_DelEntity(Entity e);
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
@@ -91,7 +91,7 @@ void GameLib_DelEnts();
|
||||
// GameLib_ForEachEn
|
||||
//
|
||||
// Iterates every entity.
|
||||
void GameLib_ForEachEnt(int (*func)(Entity *ent));
|
||||
void GameLib_ForEachEnt(int (*func)(Entity ent));
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
@@ -112,7 +112,7 @@ void GameLib_Iluminate();
|
||||
// GameLib_EntitySetLight
|
||||
//
|
||||
//
|
||||
void GameLib_EntitySetLight(Entity *e,float r,float g,float b,float rad);
|
||||
void GameLib_EntitySetLight(Entity e,float r,float g,float b,float rad);
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
#include "QuadArray2D.h"
|
||||
|
||||
|
||||
QuadArray2D *QuadArray2D_Create(int resVertex){
|
||||
QuadArray2D *quadArray=NULL;
|
||||
QuadArray2D QuadArray2D_Create(int resVertex){
|
||||
QuadArray2D quadArray=NULL;
|
||||
|
||||
quadArray=malloc(sizeof(QuadArray2D));
|
||||
quadArray=malloc(sizeof(TQuadArray2D));
|
||||
|
||||
quadArray->vertexData=malloc(sizeof(float)*Vertex2D_Length*resVertex);
|
||||
quadArray->nVertex=0;
|
||||
@@ -19,7 +19,7 @@ QuadArray2D *QuadArray2D_Create(int resVertex){
|
||||
return quadArray;
|
||||
}
|
||||
|
||||
void QuadArray2D_Destroy(QuadArray2D **quadArray){
|
||||
void QuadArray2D_Destroy(QuadArray2D *quadArray){
|
||||
if(!quadArray) return;
|
||||
if(!quadArray[0]) return;
|
||||
|
||||
@@ -28,11 +28,11 @@ void QuadArray2D_Destroy(QuadArray2D **quadArray){
|
||||
quadArray[0]=NULL;
|
||||
}
|
||||
|
||||
void QuadArray2D_Clean(QuadArray2D *quadArray){
|
||||
void QuadArray2D_Clean(QuadArray2D quadArray){
|
||||
quadArray->nVertex=0;
|
||||
}
|
||||
|
||||
void QuadArray2D_AddVertex(QuadArray2D *quadArray,float v[]){
|
||||
void QuadArray2D_AddVertex(QuadArray2D quadArray,float v[]){
|
||||
if(quadArray->resVertex<=quadArray->nVertex){
|
||||
// Grow vertexData
|
||||
quadArray->resVertex*=2;
|
||||
@@ -52,7 +52,7 @@ void QuadArray2D_AddVertex(QuadArray2D *quadArray,float v[]){
|
||||
quadArray->nVertex++;
|
||||
}
|
||||
|
||||
void QuadArray2D_AddQuad(QuadArray2D *quadArray,
|
||||
void QuadArray2D_AddQuad(QuadArray2D quadArray,
|
||||
float x0, float y0,float u0, float v0,
|
||||
float x1, float y1,float u1, float v1,
|
||||
float color[])
|
||||
|
||||
@@ -7,22 +7,26 @@
|
||||
#define Vertex2D_Length 8
|
||||
|
||||
|
||||
typedef struct Tag_QuadArray2D {
|
||||
////////////////////////////////////////////////
|
||||
// QuadArray2D
|
||||
//
|
||||
typedef struct TQuadArray2D TQuadArray2D, *QuadArray2D;
|
||||
struct TQuadArray2D {
|
||||
float *vertexData;
|
||||
int nVertex;
|
||||
int resVertex;
|
||||
} QuadArray2D;
|
||||
};
|
||||
|
||||
|
||||
QuadArray2D *QuadArray2D_Create(int resVertex);
|
||||
QuadArray2D QuadArray2D_Create(int resVertex);
|
||||
|
||||
void QuadArray2D_Destroy(QuadArray2D **quadArray);
|
||||
void QuadArray2D_Destroy(QuadArray2D *quadArray);
|
||||
|
||||
void QuadArray2D_Clean(QuadArray2D *quadArray);
|
||||
void QuadArray2D_Clean(QuadArray2D quadArray);
|
||||
|
||||
void QuadArray2D_AddVertex(QuadArray2D *quadArray,float v[]);
|
||||
void QuadArray2D_AddVertex(QuadArray2D quadArray,float v[]);
|
||||
|
||||
void QuadArray2D_AddQuad(QuadArray2D *quadArray,
|
||||
void QuadArray2D_AddQuad(QuadArray2D quadArray,
|
||||
float x0, float y0,float u0, float v0,
|
||||
float x1, float y1,float u1, float v1,
|
||||
float color[]);
|
||||
|
||||
@@ -35,8 +35,8 @@ int ReadLine(FILE *f,char *line,int max){
|
||||
}
|
||||
|
||||
|
||||
Entity *GameMapAux_CreateEnt(Entity *ent,int i,int j,int res){
|
||||
Entity *e;
|
||||
Entity GameMapAux_CreateEnt(Entity ent,int i,int j,int res){
|
||||
Entity e;
|
||||
vec2 pos;
|
||||
e=Entity_Copy(ent);
|
||||
vec2_set(pos,(res/2)+i*res,(res/2)+j*res);
|
||||
@@ -98,7 +98,7 @@ int GameMap_LoadLevel(char *filename,int res){
|
||||
// Parse the map
|
||||
for(j=0;j<height;j++){
|
||||
for(i=0;i<width;i++){
|
||||
Entity *ent;
|
||||
Entity ent;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ OBJS= \
|
||||
$(BUILDDIR)/GameLib/GameLib.o \
|
||||
|
||||
|
||||
|
||||
#####################
|
||||
# Game Declarations #
|
||||
#####################
|
||||
@@ -38,11 +37,6 @@ OBJS+= \
|
||||
$(BUILDDIR)/main.o
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#################
|
||||
# General Rules #
|
||||
#################
|
||||
@@ -59,9 +53,6 @@ run: $(BUILDDIR)/$(RESULT)
|
||||
./$(BUILDDIR)/$(RESULT) debug
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#################
|
||||
# GameLib Rules #
|
||||
#################
|
||||
@@ -85,7 +76,6 @@ $(BUILDDIR)/GameLib/GameLib.o: GameLib/GameLib.c $(HEADS)
|
||||
$(CC) -c GameLib/GameLib.c -o $(BUILDDIR)/GameLib/GameLib.o $(CFLAGS)
|
||||
|
||||
|
||||
|
||||
##############
|
||||
# Game Rules #
|
||||
##############
|
||||
@@ -99,6 +89,11 @@ $(BUILDDIR)/GameMap.o: GameMap.c $(HEADS)
|
||||
$(BUILDDIR)/main.o: main.c $(HEADS)
|
||||
$(CC) -c main.c -o $(BUILDDIR)/main.o $(CFLAGS)
|
||||
|
||||
|
||||
################
|
||||
# Result Rules #
|
||||
################
|
||||
|
||||
$(BUILDDIR)/$(RESULT): $(OBJS)
|
||||
$(CC) -o $(BUILDDIR)/$(RESULT) $(OBJS) $(LIBS) $(CFLAGS)
|
||||
|
||||
|
||||
4
main.c
4
main.c
@@ -26,13 +26,13 @@ void PostProcGame(){
|
||||
GameLib_ForEachEnt(EntityApplyGravity);
|
||||
}
|
||||
|
||||
void PreDrawGame(){
|
||||
void PreDrawGame(float f){
|
||||
//Draw_Clean(128,128,128);
|
||||
Draw_SetColor(1.0f,1.0f,1.0f,1.0f);
|
||||
Draw_DrawImgResized(img_background,0,0,640,480);
|
||||
}
|
||||
|
||||
void DrawGame(){
|
||||
void DrawGame(float f){
|
||||
char cadena[128];
|
||||
|
||||
// Watermark
|
||||
|
||||
Reference in New Issue
Block a user