(20111219) 01:00

This commit is contained in:
2011-12-19 01:00:00 +01:00
parent 0f403b8234
commit 49ce46f808
97 changed files with 1280 additions and 159 deletions

1
Draw.c
View File

@@ -480,6 +480,7 @@ DrawFnt Draw_LoadFont(char *fichero,int min,int max){
SDL_UnlockSurface(font->surf);
return((DrawFnt)font);*/
return(NULL);
}
/////////////////////////////

View File

@@ -13,27 +13,42 @@
// Entity_New
//
//
Entity *_free_entity=NULL;
Entity *Entity_New(){
Entity *e;
e=malloc(sizeof(Entity));
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=1.0f;
e->fric_static=0.5f;
e->fric_dynamic=0.0f;
//e->img=NULL;
AnimPlay_SetImg(&e->anim,NULL);
e->oncopy=NULL;
e->proc=NULL;
e->postproc=NULL;
e->collision=NULL;
e->overlap=NULL;
e->A=0;
e->child=NULL;
e->next=NULL;
return(e);
}
@@ -44,7 +59,8 @@ Entity *Entity_New(){
//
//
void Entity_Destroy(Entity *e){
free(e);
e->next=_free_entity;
_free_entity=e;
}
@@ -59,6 +75,8 @@ Entity *Entity_Copy(Entity *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;
@@ -70,9 +88,19 @@ Entity *Entity_Copy(Entity *e){
//n->img=e->img;
AnimPlay_Copy(&n->anim,&e->anim);
n->oncopy=e->oncopy;
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);
}
@@ -82,10 +110,8 @@ Entity *Entity_Copy(Entity *e){
// Entity_Draw
//
//
void Entity_Draw(Entity *e){
//if(e->img)
// Draw_DrawImg(e->img,e->pos[0],e->pos[1]);
AnimPlay_Draw(&e->anim,e->pos[0],e->pos[1]);
void Entity_Draw(Entity *e,int x,int y){
AnimPlay_Draw(&e->anim,e->pos[0]+x,e->pos[1]+y);
}
@@ -197,6 +223,9 @@ int Entity_Collide(Entity *b1,Entity *b2){
vec2 cir1[2];
Entity *b_aux;
if(!(b1->flags&EntityFlag_Collision) || !(b2->flags&EntityFlag_Collision))
return(0);
// FIX: Swap colision order based on moving object
if(vec2_dot(b1->vel,b1->vel)<vec2_dot(b2->vel,b2->vel)){
b_aux=b1;
@@ -238,6 +267,29 @@ int Entity_Collide(Entity *b1,Entity *b2){
}
/////////////////////////////
// Entity_Overlaps
//
//
void Entity_Overlaps(Entity *b1,Entity *b2){
vec2 len;
float dist;
if(!(b1->flags&EntityFlag_Overlap) || !(b2->flags&EntityFlag_Overlap))
return;
vec2_minus(len,b1->pos,b2->pos);
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);
}
}
/////////////////////////////
// Entity_AddVelLimit
//

View File

@@ -5,15 +5,20 @@
#include "Draw.h"
#include "Anim.h"
#define EntityFlag_Collision 1
#define EntityFlag_Overlap 2
////////////////////////////////////////////////
// Entity //
////////////
//
typedef struct Tag_Entity{
typedef struct Tag_Entity {
int type;
vec2 pos;
int flags;
int zorder;
vec2 vel;
vec2 bod_offset;
@@ -23,15 +28,23 @@ typedef struct Tag_Entity{
float fric_static;
float fric_dynamic;
//DrawImg img;
AnimPlay anim;
void (*oncopy)(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);
int A;
struct Tag_Entity *child;
void *next;
} Entity;
@@ -60,7 +73,7 @@ Entity *Entity_Copy(Entity *e);
// Entity_Draw
//
//
void Entity_Draw(Entity *e);
void Entity_Draw(Entity *e,int x,int y);
/////////////////////////////
@@ -83,6 +96,13 @@ void Entity_PostProcess(Entity *e,int ft);
int Entity_Collide(Entity *b1,Entity *b2);
/////////////////////////////
// Entity_Overlaps
//
//
void Entity_Overlaps(Entity *b1,Entity *b2);
/////////////////////////////
// Entity_AddVelLimit
//

520
GameEnts.c Normal file
View File

@@ -0,0 +1,520 @@
#include <stdlib.h>
#include <math.h>
#include "GameLib.h"
#include "GameEnts.h"
DrawImg img_barrel;
DrawImg img_barrel2;
DrawImg img_column;
DrawImg img_column_faded;
DrawImg img_floor;
DrawImg img_floor_left;
DrawImg img_floor_right;
DrawImg img_floor_center;
DrawImg img_hole_spiked;
Anim anim_hole_lava;
DrawImg img_player_down;
DrawImg img_player_up;
DrawImg img_player_left;
DrawImg img_player_right;
DrawImg img_savepoint;
DrawImg img_endpoint;
Anim anim_exitpoint;
DrawImg img_arrowshooter_up;
DrawImg img_arrowshooter_down;
DrawImg img_arrowshooter_left;
DrawImg img_arrowshooter_right;
DrawImg img_arrow_up;
DrawImg img_arrow_down;
DrawImg img_arrow_left;
DrawImg img_arrow_right;
Anim anim_fire;
DrawImg img_player_broken;
AudioSnd snd_arrowhit;
AudioSnd snd_savepoint;
AudioSnd snd_exitpoint;
AudioSnd snd_shootarrow;
AudioSnd snd_burn;
AudioSnd snd_fillhole;
AudioSnd snd_drag;
Entity *ent_player;
Entity *ent_barrel;
Entity *ent_column;
Entity *ent_column_faded;
Entity *ent_floor;
Entity *ent_floor_right;
Entity *ent_floor_left;
Entity *ent_floor_center;
Entity *ent_hole_spiked;
Entity *ent_hole_filled;
Entity *ent_hole_lava;
Entity *ent_arrowshooter_up;
Entity *ent_arrowshooter_down;
Entity *ent_arrowshooter_left;
Entity *ent_arrowshooter_right;
Entity *ent_arrow_up;
Entity *ent_arrow_down;
Entity *ent_arrow_left;
Entity *ent_arrow_right;
Entity *ent_exitpoint;
Entity *ent_endpoint;
Entity *ent_savepoint_1;
Entity *ent_savepoint_2;
Entity *ent_savepoint_3;
Entity *ent_savepoint_4;
Entity *ent_fire;
Entity *ent_player_broken;
extern int game_level;
extern int game_level_point;
extern int game_level_reset;
void player_proc(Entity *e,int ft){
vec2 vel;
int pos[2],size[2],delta[2];
if(Input_GetDir(vel)){
vec2 up,right;
float updown,leftright;
vec2_set(up,0,-1);
vec2_set(right,1,0);
updown=vec2_dot(up,vel);
leftright=vec2_dot(right,vel);
if(fabs(updown)>=fabs(leftright)){
if(updown>0.0f){
AnimPlay_SetImg(&e->anim,img_player_up);
}else{
AnimPlay_SetImg(&e->anim,img_player_down);
}
}else{
if(leftright>0.0f){
AnimPlay_SetImg(&e->anim,img_player_right);
}else{
AnimPlay_SetImg(&e->anim,img_player_left);
}
}
vec2_scale(vel,vel,1.0f);
Entity_AddVelLimit(e,vel,3.0f);
}
GameLib_GetPos(pos);
GameLib_GetSize(size);
size[0]/=2;
size[1]/=2;
pos[0]+=size[0];
pos[1]+=size[1];
delta[0]=e->pos[0]-pos[0];
delta[1]=e->pos[1]-pos[1];
pos[0]-=size[0];
pos[1]-=size[1];
pos[0]=pos[0]+delta[0]/10;
pos[1]=pos[1]+delta[1]/10;
GameLib_SetPos(pos);
}
void barrel_proc(Entity *e,int ft){
float qvel;
int tnow;
qvel=vec2_dot(e->vel,e->vel);
if(qvel>0.0f){
tnow=Time_GetTime()/1000;
if(tnow-250>e->A){
GameLib_PlaySound(snd_drag,(int)e->pos[0],(int)e->pos[1]);
e->A=tnow;
}
}
}
void destroy_postproc(Entity *e,int ft){
GameLib_DelEntity(e);
}
void hole_spiked_overlap(Entity *e1,Entity *e2){
Entity *e;
if(e1->postproc)
return;
if(e2->type==Ent_Barrel){
Entity *e;
e1->postproc=destroy_postproc;
e2->postproc=destroy_postproc;
GameLib_PlaySound(snd_fillhole,(int)e2->pos[0],(int)e2->pos[1]);
e=Entity_Copy(ent_hole_filled);
vec2_copy(e->pos,e1->pos);
GameLib_AddEntity(e);
}
if(e2->type==Ent_Player){
// KILL the player
e=Entity_Copy(ent_player_broken);
vec2_copy(e->pos,e2->pos);
GameLib_AddEntity(e);
GameLib_PlaySound(snd_burn,(int)e2->pos[0],(int)e2->pos[1]);
e2->postproc=destroy_postproc;
game_level_reset=1;
}
}
void hole_lava_overlap(Entity *e1,Entity *e2){
Entity *e;
if(e2->type==Ent_Barrel && e1->postproc==NULL){
e2->postproc=destroy_postproc;
// Burning effect
e=Entity_Copy(ent_fire);
vec2_copy(e->pos,e2->pos);
GameLib_AddEntity(e);
GameLib_PlaySound(snd_burn,(int)e2->pos[0],(int)e2->pos[1]);
}
if(e2->type==Ent_Player && e1->postproc==NULL){
// KILL the player (burned)
e2->postproc=destroy_postproc;
game_level_reset=1;
// Burning effect
e=Entity_Copy(ent_fire);
vec2_copy(e->pos,e2->pos);
GameLib_AddEntity(e);
GameLib_PlaySound(snd_burn,(int)e2->pos[0],(int)e2->pos[1]);
}
}
int arrow_collision(Entity *e1,Entity *e2,float t,vec2 n){
Entity *e;
if(e1->postproc)
return(0);
if(e2->type==Ent_ArrowShooter)
return(0);
if(e2->type==Ent_Arrow)
return(0);
if(e2->type==Ent_Player){
// KILL the player
e=Entity_Copy(ent_player_broken);
vec2_copy(e->pos,e2->pos);
GameLib_AddEntity(e);
e2->postproc=destroy_postproc;
GameLib_PlaySound(snd_burn,(int)e2->pos[0],(int)e2->pos[1]);
game_level_reset=1;
}
e1->postproc=destroy_postproc;
GameLib_PlaySound(snd_arrowhit,(int)e1->pos[0],(int)e1->pos[1]);
return(0);
}
void arrowshooter_oncopy(Entity *e){
e->A=rand()%30;
}
void arrowshooter_proc(Entity *e,int ft){
if(e->A==0){
Entity *e2;
e2=Entity_Copy(e->child);
vec2_copy(e2->pos,e->pos);
GameLib_AddEntity(e2);
GameLib_PlaySound(snd_shootarrow,(int)e->pos[0],(int)e->pos[1]);
e->A=60;
}else{
e->A--;
}
}
void savepoint_overlap(Entity *e1,Entity *e2){
if(e2->type==Ent_Player){
// Save the point
if(game_level_point!=e1->A){
game_level_point=e1->A;
GameLib_PlaySound(snd_savepoint,(int)e1->pos[0],(int)e1->pos[1]);
}
}
}
void exitpoint_overlap(Entity *e1,Entity *e2){
if(e2->type==Ent_Player){
// Exit the level
game_level++;
game_level_point=1;
game_level_reset=2;
// HACK: Delete the player
e2->postproc=destroy_postproc;
GameLib_PlaySound(snd_exitpoint,(int)e1->pos[0],(int)e1->pos[1]);
}
}
void endpoint_overlap(Entity *e1,Entity *e2){
if(e2->type==Ent_Player){
// Go to end
game_level_reset=3;
// HACK: Delete the player
e2->postproc=destroy_postproc;
GameLib_PlaySound(snd_exitpoint,(int)e1->pos[0],(int)e1->pos[1]);
}
}
void fire_proc(Entity *e,int ft){
if(e->A==0){
e->postproc=destroy_postproc;
}else{
e->A--;
}
}
void GameEnts_Init(){
// Load Graphics
img_barrel=Draw_LoadImage("data/barrel.bmp");
Draw_SetOffset(img_barrel,-16,-32);
img_barrel2=Draw_LoadImage("data/barrel2.bmp");
Draw_SetOffset(img_barrel2,-16,-16);
img_floor=Draw_LoadImage("data/floor.bmp");
Draw_SetOffset(img_floor,-16,-16);
img_floor_left=Draw_LoadImage("data/floor_left.bmp");
Draw_SetOffset(img_floor_left,-16,-16);
img_floor_right=Draw_LoadImage("data/floor_right.bmp");
Draw_SetOffset(img_floor_right,-16,-16);
img_floor_center=Draw_LoadImage("data/floor_center.bmp");
Draw_SetOffset(img_floor_center,-16,-16);
img_column=Draw_LoadImage("data/column.bmp");
Draw_SetOffset(img_column,-16,-80);
img_column_faded=Draw_LoadImage("data/column_faded.bmp");
Draw_SetOffset(img_column_faded,-16,-80);
img_hole_spiked=Draw_LoadImage("data/hole_spiked.bmp");
Draw_SetOffset(img_hole_spiked,-16,-16);
anim_hole_lava=Anim_LoadAnim("data/hole_lava.bmp",2,3);
Anim_SetOffset(anim_hole_lava,-16,-16);
img_player_up=Draw_LoadImage("data/player_up.bmp");
Draw_SetOffset(img_player_up,-16,-48);
img_player_down=Draw_LoadImage("data/player_down.bmp");
Draw_SetOffset(img_player_down,-16,-48);
img_player_left=Draw_LoadImage("data/player_left.bmp");
Draw_SetOffset(img_player_left,-16,-48);
img_player_right=Draw_LoadImage("data/player_right.bmp");
Draw_SetOffset(img_player_right,-16,-48);
img_savepoint=Draw_LoadImage("data/save_point.bmp");
Draw_SetOffset(img_savepoint,-16,-16);
anim_exitpoint=Anim_LoadAnim("data/exit_point.bmp",2,10);
Anim_SetOffset(anim_exitpoint,-16,-48);
img_endpoint=Draw_LoadImage("data/end_point.bmp");
Draw_SetOffset(img_endpoint,-16,-32);
img_arrowshooter_up=Draw_LoadImage("data/arrowshooter_up.bmp");
Draw_SetOffset(img_arrowshooter_up,-16,-16);
img_arrowshooter_down=Draw_LoadImage("data/arrowshooter_down.bmp");
Draw_SetOffset(img_arrowshooter_down,-16,-16);
img_arrowshooter_left=Draw_LoadImage("data/arrowshooter_left.bmp");
Draw_SetOffset(img_arrowshooter_left,-16,-16);
img_arrowshooter_right=Draw_LoadImage("data/arrowshooter_right.bmp");
Draw_SetOffset(img_arrowshooter_right,-16,-16);
img_arrow_up=Draw_LoadImage("data/arrow_up.bmp");
Draw_SetOffset(img_arrow_up,-16,-16);
img_arrow_down=Draw_LoadImage("data/arrow_down.bmp");
Draw_SetOffset(img_arrow_down,-16,-16);
img_arrow_left=Draw_LoadImage("data/arrow_left.bmp");
Draw_SetOffset(img_arrow_left,-16,-16);
img_arrow_right=Draw_LoadImage("data/arrow_right.bmp");
Draw_SetOffset(img_arrow_right,-16,-16);
anim_fire=Anim_LoadAnim("data/fire.bmp",3,5);
Anim_SetOffset(anim_fire,-16,-48);
img_player_broken=Draw_LoadImage("data/player_broken.bmp");
Draw_SetOffset(img_player_broken,-16,-48);
snd_arrowhit=Audio_LoadSound("data/Hit_Hurt10.wav");
snd_exitpoint=Audio_LoadSound("data/Powerup10.wav");
snd_savepoint=Audio_LoadSound("data/Powerup30.wav");
snd_shootarrow=Audio_LoadSound("data/Laser_Shoot2.wav");
snd_burn=Audio_LoadSound("data/Explosion2.wav");
snd_fillhole=Audio_LoadSound("data/Hit_Hurt16.wav");
snd_drag=Audio_LoadSound("data/Explosion16.wav");
// Create the entity templates
ent_player=Entity_New();
ent_player->type=Ent_Player;
ent_player->radius=16.0f;
ent_player->mass=70.0f;
AnimPlay_SetImg(&ent_player->anim,img_player_down);
//AnimPlay_SetAnim(&ent_player->anim,anim_fire);
ent_player->proc=player_proc;
ent_barrel=Entity_New();
ent_barrel->type=Ent_Barrel;
ent_barrel->radius=16.0f;
ent_barrel->mass=100.0f;
ent_barrel->proc=barrel_proc;
AnimPlay_SetImg(&ent_barrel->anim,img_barrel);
ent_column=Entity_New();
ent_column->type=Ent_Column;
ent_column->flags=EntityFlag_Collision;
ent_column->radius=12;
ent_column->mass=-1.0f;
AnimPlay_SetImg(&ent_column->anim,img_column);
ent_column_faded=Entity_Copy(ent_column);
AnimPlay_SetImg(&ent_column_faded->anim,img_column_faded);
ent_floor=Entity_New();
ent_floor->type=Ent_Floor;
ent_floor->zorder=-1;
ent_floor->flags=0;
AnimPlay_SetImg(&ent_floor->anim,img_floor);
ent_floor_left=Entity_Copy(ent_floor);
AnimPlay_SetImg(&ent_floor_left->anim,img_floor_left);
ent_floor_right=Entity_Copy(ent_floor);
AnimPlay_SetImg(&ent_floor_right->anim,img_floor_right);
ent_floor_center=Entity_Copy(ent_floor);
AnimPlay_SetImg(&ent_floor_center->anim,img_floor_center);
ent_hole_spiked=Entity_New();
ent_hole_spiked->type=Ent_Hole_Spiked;
ent_hole_spiked->zorder=-1;
ent_hole_spiked->flags=EntityFlag_Overlap;
ent_hole_spiked->radius=18;
AnimPlay_SetImg(&ent_hole_spiked->anim,img_hole_spiked);
ent_hole_spiked->overlap=hole_spiked_overlap;
ent_hole_filled=Entity_New();
ent_hole_filled->type=Ent_Hole_Filled;
ent_hole_filled->zorder=-1;
ent_hole_filled->flags=0;
AnimPlay_SetImg(&ent_hole_filled->anim,img_barrel2);
ent_hole_lava=Entity_New();
ent_hole_lava->type=Ent_Hole_Lava;
ent_hole_lava->zorder=-1;
ent_hole_lava->flags=EntityFlag_Overlap;
ent_hole_lava->radius=18;
AnimPlay_SetAnim(&ent_hole_lava->anim,anim_hole_lava);
ent_hole_lava->overlap=hole_lava_overlap;
ent_arrow_up=Entity_New();
ent_arrow_up->type=Ent_Arrow;
ent_arrow_up->flags=EntityFlag_Collision;
ent_arrow_up->radius=10;
ent_arrow_up->fric_static=0;
ent_arrow_up->collision=arrow_collision;
AnimPlay_SetImg(&ent_arrow_up->anim,img_arrow_up);
vec2_set(ent_arrow_up->vel,0,-4);
ent_arrow_down=Entity_Copy(ent_arrow_up);
AnimPlay_SetImg(&ent_arrow_down->anim,img_arrow_down);
vec2_set(ent_arrow_down->vel,0,4);
ent_arrow_left=Entity_Copy(ent_arrow_up);
AnimPlay_SetImg(&ent_arrow_left->anim,img_arrow_left);
vec2_set(ent_arrow_left->vel,-4,0);
ent_arrow_right=Entity_Copy(ent_arrow_up);
AnimPlay_SetImg(&ent_arrow_right->anim,img_arrow_right);
vec2_set(ent_arrow_right->vel,4,0);
ent_arrowshooter_up=Entity_New();
ent_arrowshooter_up->type=Ent_ArrowShooter;
ent_arrowshooter_up->flags=EntityFlag_Collision;
ent_arrowshooter_up->radius=15;
ent_arrowshooter_up->mass=-1.0f;
ent_arrowshooter_up->oncopy=arrowshooter_oncopy;
ent_arrowshooter_up->proc=arrowshooter_proc;
AnimPlay_SetImg(&ent_arrowshooter_up->anim,img_arrowshooter_up);
ent_arrowshooter_up->child=ent_arrow_up;
ent_arrowshooter_down=Entity_Copy(ent_arrowshooter_up);
AnimPlay_SetImg(&ent_arrowshooter_down->anim,img_arrowshooter_down);
ent_arrowshooter_down->child=ent_arrow_down;
ent_arrowshooter_left=Entity_Copy(ent_arrowshooter_up);
AnimPlay_SetImg(&ent_arrowshooter_left->anim,img_arrowshooter_left);
ent_arrowshooter_left->child=ent_arrow_left;
ent_arrowshooter_right=Entity_Copy(ent_arrowshooter_up);
AnimPlay_SetImg(&ent_arrowshooter_right->anim,img_arrowshooter_right);
ent_arrowshooter_right->child=ent_arrow_right;
ent_savepoint_1=Entity_New();
ent_savepoint_1->type=Ent_SavePoint;
ent_savepoint_1->zorder=0;
ent_savepoint_1->flags=EntityFlag_Overlap;
ent_savepoint_1->radius=16;
AnimPlay_SetImg(&ent_savepoint_1->anim,img_savepoint);
ent_savepoint_1->overlap=savepoint_overlap;
ent_savepoint_1->A=1;
ent_savepoint_2=Entity_Copy(ent_savepoint_1);
ent_savepoint_2->A=2;
ent_savepoint_3=Entity_Copy(ent_savepoint_1);
ent_savepoint_3->A=3;
ent_savepoint_4=Entity_Copy(ent_savepoint_1);
ent_savepoint_4->A=4;
ent_exitpoint=Entity_New();
ent_exitpoint->type=Ent_ExitPoint;
ent_exitpoint->flags=EntityFlag_Overlap;
ent_exitpoint->radius=16;
AnimPlay_SetAnim(&ent_exitpoint->anim,anim_exitpoint);
ent_exitpoint->overlap=exitpoint_overlap;
ent_endpoint=Entity_Copy(ent_exitpoint);
AnimPlay_SetImg(&ent_endpoint->anim,img_endpoint);
ent_endpoint->overlap=endpoint_overlap;
ent_fire=Entity_New();
ent_fire->type=Ent_Effect;
ent_fire->flags=0;
AnimPlay_SetAnim(&ent_fire->anim,anim_fire);
ent_fire->proc=fire_proc;
ent_fire->A=30;
ent_player_broken=Entity_New();
ent_player_broken->type=Ent_Effect;
ent_player_broken->flags=0;
AnimPlay_SetImg(&ent_player_broken->anim,img_player_broken);
}

46
GameEnts.h Normal file
View File

@@ -0,0 +1,46 @@
#ifndef _GAMEENTS_H_
#define _GAMEENTS_H_
void GameEnts_Init();
enum {
Ent_Player,
Ent_Barrel,
Ent_Column,
Ent_Floor,
Ent_Hole_Spiked,
Ent_Hole_Filled,
Ent_Hole_Lava,
Ent_ArrowShooter,
Ent_Arrow,
Ent_SavePoint,
Ent_ExitPoint,
Ent_Effect
} EntityType;
extern Entity *ent_player;
extern Entity *ent_barrel;
extern Entity *ent_column;
extern Entity *ent_column_faded;
extern Entity *ent_floor;
extern Entity *ent_floor_right;
extern Entity *ent_floor_left;
extern Entity *ent_floor_center;
extern Entity *ent_hole_spiked;
extern Entity *ent_hole_filled;
extern Entity *ent_hole_lava;
extern Entity *ent_arrowshooter_up;
extern Entity *ent_arrowshooter_down;
extern Entity *ent_arrowshooter_left;
extern Entity *ent_arrowshooter_right;
extern Entity *ent_arrow_up;
extern Entity *ent_arrow_down;
extern Entity *ent_arrow_left;
extern Entity *ent_arrow_right;
extern Entity *ent_exitpoint;
extern Entity *ent_endpoint;
extern Entity *ent_savepoint_1;
extern Entity *ent_savepoint_2;
extern Entity *ent_savepoint_3;
extern Entity *ent_savepoint_4;
#endif

168
GameLib.c
View File

@@ -18,6 +18,9 @@ int _n_entities_res=0;
void (*_gameproc)()=NULL;
void (*_gamepostproc)()=NULL;
int _ft;
int _game_size[2];
int _game_pos[2];
/////////////////////////////
// GameLib_Init
@@ -32,6 +35,11 @@ int GameLib_Init(int w,int h,char *title,int fps){
}
Audio_Init();
_game_size[0]=w;
_game_size[1]=h;
_game_pos[0]=0;
_game_pos[1]=0;
_ft=1000/fps;
return(1);
@@ -109,8 +117,8 @@ int GameLib_ProcLoop(){
}
// Process entities
vec2 grav;
vec2_set(grav,0,1);
// vec2 grav;
// vec2_set(grav,0,1);
for(i=0;i<_n_entities;i++){
if(!_entity[i])
continue;
@@ -127,8 +135,12 @@ int GameLib_ProcLoop(){
do{
repeat=0;
for(i=0;i<_n_entities-1;i++){
if(!_entity[i])
continue;
if(!(_entity[i]->flags&EntityFlag_Collision))
continue;
for(j=i+1;j<_n_entities;j++){
if(!_entity[i] || !_entity[j])
if(!_entity[j])
continue;
if(Entity_Collide(_entity[i],_entity[j])){
repeat=1;
@@ -140,8 +152,12 @@ int GameLib_ProcLoop(){
// Stop remaining collisions
for(i=0;i<_n_entities-1;i++){
if(!_entity[i])
continue;
if(!(_entity[i]->flags&EntityFlag_Collision))
continue;
for(j=i+1;j<_n_entities;j++){
if(!_entity[i] || !_entity[j])
if(!_entity[j])
continue;
if(Entity_Collide(_entity[i],_entity[j])){
vec2_set(_entity[i]->vel,0,0);
@@ -150,12 +166,17 @@ int GameLib_ProcLoop(){
}
}
// PostProcess and draw entities
for(i=0;i<_n_entities;i++){
// Process Overlaps
for(i=0;i<_n_entities-1;i++){
if(!_entity[i])
continue;
Entity_PostProcess(_entity[i],_ft);
Entity_Draw(_entity[i]);
if(!(_entity[i]->flags&EntityFlag_Overlap))
continue;
for(j=i+1;j<_n_entities;j++){
if(!_entity[j])
continue;
Entity_Overlaps(_entity[i],_entity[j]);
}
}
// Compactate
@@ -169,6 +190,56 @@ int GameLib_ProcLoop(){
}
_n_entities=j;
// Sort
int n,n2,swap;
n=_n_entities;
do{
n2=0;
for(i=1;i<n;i++){
swap=0;
if(_entity[i-1]->zorder > _entity[i]->zorder){
// Lower level
swap=1;
}else
if(_entity[i-1]->zorder < _entity[i]->zorder){
// Upper level
}else{
// Same level
if(_entity[i-1]->pos[1] > _entity[i]->pos[1]){
swap=1;
}
}
if(swap){
Entity *ent;
ent=_entity[i];
_entity[i]=_entity[i-1];
_entity[i-1]=ent;
n2=i;
}
}
n=n2;
}while(n>0);
// PostProcess and draw entities
for(i=0;i<_n_entities;i++){
Entity *e;
Entity_PostProcess(_entity[i],_ft);
if(!_entity[i])
continue;
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))
continue;
Entity_Draw(e,-_game_pos[0],-_game_pos[1]);
}
// Launch the method
if(_gamepostproc){
_gamepostproc();
@@ -201,3 +272,84 @@ void GameLib_Loop(
void GameLib_BreakLoop(){
_running=0;
}
void GameLib_GetPos(int pos[2]){
pos[0]=_game_pos[0];
pos[1]=_game_pos[1];
}
void GameLib_SetPos(int pos[2]){
_game_pos[0]=pos[0];
_game_pos[1]=pos[1];
}
void GameLib_GetSize(int size[2]){
size[0]=_game_size[0];
size[1]=_game_size[1];
}
void GameLib_DelEnts(){
int i;
for(i=0;i<_n_entities;i++){
if(!_entity[i])
continue;
Entity_Destroy(_entity[i]);
}
_n_entities=0;
}
void GameLib_ForEachEnt(int (*func)(Entity *ent)){
int i;
for(i=0;i<_n_entities;i++){
if(!_entity[i])
continue;
if(!func(_entity[i])){
break;
}
}
}
void GameLib_PlaySound(AudioSnd snd,int x,int y){
float vleft,vright,vcen;
int r,cx,cy,off;
cx=_game_pos[0]+_game_size[0]/2;
cy=_game_pos[1]+_game_size[1]/2;
if(_game_size[0]>_game_size[1]){
r=_game_size[0]/2;
}else{
r=_game_size[1]/2;
}
r=r*1.2f;
off=r/10.0f;
vleft=vright=1.0f;
vcen=1.0f-(abs(y-cy)/(float)r);
vright=1.0f-(abs(x-(cx+off))/(float)r);
vleft=1.0f-(abs(x-(cx-off))/(float)r);
vright*=vcen;
vleft*=vcen;
if(vleft<0.0f)
vleft=0.0f;
if(vright<0.0f)
vright=0.0f;
if(vleft<=0.0f && vright<=0.0f){
return;
}
Audio_PlaySound(snd,vleft,vright);
}

View File

@@ -56,4 +56,16 @@ void GameLib_BreakLoop();
void GameLib_GetPos(int pos[2]);
void GameLib_SetPos(int pos[2]);
void GameLib_GetSize(int size[2]);
void GameLib_DelEnts();
void GameLib_ForEachEnt(int (*func)(Entity *ent));
void GameLib_PlaySound(AudioSnd snd,int x,int y);
#endif

200
GameMap.c Normal file
View File

@@ -0,0 +1,200 @@
#include <stdio.h>
#include <string.h>
#include "GameLib.h"
#include "GameEnts.h"
#include "GameMap.h"
void GameMapAux_CreateEnt(Entity *ent,int i,int j){
Entity *e;
e=Entity_Copy(ent);
vec2_set(e->pos,16+i*32,16+j*32);
GameLib_AddEntity(e);
}
void Aux_Linea(FILE *f,char *line){
int c;
int i=0;
memset(line,0,1024);
while(i<1024){
c=fgetc(f);
if(c==EOF){
line[i]=0;
break;
}
if(c=='\r'){
continue;
}
if(c=='\n'){
line[i]=0;
break;
}
line[i]=c;
i++;
}
}
int _startpoint;
int GameMapAux_CreatePlayer(Entity *ent){
if(ent->type==Ent_SavePoint){
if(ent->A==_startpoint){
Entity *e;
e=Entity_Copy(ent_player);
vec2_copy(e->pos,ent->pos);
GameLib_AddEntity(e);
return(0);
}
}
return(1);
}
int GameMapAux_IsFloor(char c){
if( c=='.' ||
c=='#' ||
c=='m' ||
c=='B' ||
c=='1' ||
c=='2' ||
c=='3' ||
c=='4' ||
c=='E' ||
c=='F' ||
c=='A' ||
c=='V' ||
c=='<' ||
c=='>' )
{
return(1);
}
return(0);
}
int GameMap_CreateLevel(int level,int point){
char filename[128];
FILE *file;
char line[1024];
int w,h;
int i,j;
int floor;
sprintf(filename,"data/level_%02d.txt",level);
file=fopen(filename,"r");
if(!file){
return(0);
}
GameLib_DelEnts();
Aux_Linea(file,line);
sscanf(line,"%d %d",&w,&h);
for(j=0;j<h;j++){
Aux_Linea(file,line);
for(i=0;i<w;i++){
// Prepare the floor
floor=0;
if(i>0){
if(GameMapAux_IsFloor(line[i-1])){
floor|=4;
}
}
if(i<(w-1)){
if(GameMapAux_IsFloor(line[i+1])){
floor|=1;
}
}
if(GameMapAux_IsFloor(line[i])){
floor|=2;
}
if(floor==7){
GameMapAux_CreateEnt(ent_floor,i,j);
}
if(floor==6){
GameMapAux_CreateEnt(ent_floor_right,i,j);
}
if(floor==3){
GameMapAux_CreateEnt(ent_floor_left,i,j);
}
if(floor==2){
GameMapAux_CreateEnt(ent_floor_center,i,j);
}
// Put the rest of the entities
if(line[i]=='.'){
// Floor
}else
if(line[i]=='#'){
// Column
GameMapAux_CreateEnt(ent_column,i,j);
}else
if(line[i]=='m'){
// Column faded
GameMapAux_CreateEnt(ent_column_faded,i,j);
}else
if(line[i]=='B'){
// Barrel
GameMapAux_CreateEnt(ent_barrel,i,j);
}else
if(line[i]=='S'){
// Spiked hole
GameMapAux_CreateEnt(ent_hole_spiked,i,j);
}else
if(line[i]=='L'){
// Lava hole
GameMapAux_CreateEnt(ent_hole_lava,i,j);
}else
if(line[i]=='1'){
// Save point 1
GameMapAux_CreateEnt(ent_savepoint_1,i,j);
}else
if(line[i]=='2'){
// Save point 2
GameMapAux_CreateEnt(ent_savepoint_2,i,j);
}else
if(line[i]=='3'){
// Save point 3
GameMapAux_CreateEnt(ent_savepoint_3,i,j);
}else
if(line[i]=='4'){
// Save point 4
GameMapAux_CreateEnt(ent_savepoint_4,i,j);
}else
if(line[i]=='E'){
// Exit point
GameMapAux_CreateEnt(ent_exitpoint,i,j);
}else
if(line[i]=='F'){
// End point
GameMapAux_CreateEnt(ent_endpoint,i,j);
}else
if(line[i]=='>'){
// ArrowShooter right
GameMapAux_CreateEnt(ent_arrowshooter_right,i,j);
}else
if(line[i]=='<'){
// ArrowShooter left
GameMapAux_CreateEnt(ent_arrowshooter_left,i,j);
}else
if(line[i]=='V'){
// ArrowShooter down
GameMapAux_CreateEnt(ent_arrowshooter_down,i,j);
}else
if(line[i]=='A'){
// ArrowShooter up
GameMapAux_CreateEnt(ent_arrowshooter_up,i,j);
}else
{}
}
}
fclose(file);
// Find the player start position
_startpoint=point;
GameLib_ForEachEnt(GameMapAux_CreatePlayer);
return(1);
}

8
GameMap.h Normal file
View File

@@ -0,0 +1,8 @@
#ifndef _GAMEMAP_H_
#define _GAMEMAP_H_
int GameMap_CreateLevel(int level,int point);
#endif

17
Input.c
View File

@@ -41,6 +41,8 @@ void Input_Frame(){
Input_SetKey(InputKey_Left,keys[SDLK_LEFT]);
Input_SetKey(InputKey_Right,keys[SDLK_RIGHT]);
Input_SetKey(InputKey_Jump,keys[SDLK_SPACE]);
Input_SetKey(InputKey_Continue,keys[SDLK_RETURN]|keys[SDLK_KP_ENTER]);
}
@@ -70,6 +72,21 @@ InputKeyStatus Input_GetKey(InputKey key){
}
/////////////////////////////
// Input_AnyKey
//
//
int Input_AnyKey(){
int i;
for(i=0;i<InputKey_Max;i++){
if(_keys[i]==InputKey_Pressed){
return(1);
}
}
return(0);
}
/////////////////////////////
// Input_GetDir
//

View File

@@ -30,6 +30,7 @@ typedef enum {
InputKey_Left,
InputKey_Right,
InputKey_Jump,
InputKey_Continue,
InputKey_Max
} InputKey;
@@ -59,6 +60,13 @@ typedef enum {
InputKeyStatus Input_GetKey(InputKey key);
/////////////////////////////
// Input_AnyKey
//
//
int Input_AnyKey();
/////////////////////////////
// Input_GetDir
//

View File

@@ -6,7 +6,9 @@ HEADS= \
Audio.h \
Anim.h \
Entity.h \
GameLib.h
GameLib.h \
GameEnts.h \
GameMap.h
OBJS= \
$(BUILDDIR)/Time.o \
@@ -17,6 +19,8 @@ OBJS= \
$(BUILDDIR)/Anim.o \
$(BUILDDIR)/Entity.o \
$(BUILDDIR)/GameLib.o \
$(BUILDDIR)/GameEnts.o \
$(BUILDDIR)/GameMap.o \
$(BUILDDIR)/main.o
@@ -51,6 +55,12 @@ $(BUILDDIR)/Anim.o: Anim.c $(HEADS)
$(BUILDDIR)/GameLib.o: GameLib.c $(HEADS)
$(CC) -c GameLib.c -o $(BUILDDIR)/GameLib.o $(CFLAGS)
$(BUILDDIR)/GameEnts.o: GameEnts.c $(HEADS)
$(CC) -c GameEnts.c -o $(BUILDDIR)/GameEnts.o $(CFLAGS)
$(BUILDDIR)/GameMap.o: GameMap.c $(HEADS)
$(CC) -c GameMap.c -o $(BUILDDIR)/GameMap.o $(CFLAGS)
$(BUILDDIR)/main.o: main.c $(HEADS)
$(CC) -c main.c -o $(BUILDDIR)/main.o $(CFLAGS)

View File

@@ -0,0 +1 @@
3,0.5,0.32,0.31,,0.285,,1,,-1,-1,,,0.14,,,-1,,-1,,,,,-1,-1,1,1,,,-1,,-1,masterVolume

BIN
data/Explosion16.wav Normal file

Binary file not shown.

View File

@@ -0,0 +1 @@
3,0.5,,0.2901,0.4276,0.4858,0.3,0.0327,,0.0396,,,,,,,,,,,,,0.4513,0.4207,-0.2057,1,,,,,,,masterVolume

BIN
data/Explosion2.wav Normal file

Binary file not shown.

View File

@@ -0,0 +1 @@
3,0.5,,0.0824,,0.1102,0.3,0.2174,,-0.551,,,,,,,,,,,,,,,,1,,,,,,,masterVolume

BIN
data/Hit_Hurt10.wav Normal file

Binary file not shown.

View File

@@ -0,0 +1 @@
3,0.5,,0.0316,,0.2791,0.3,0.2286,,-0.5036,,,,,,,,,,,,,,,,1,,,0.0144,,,,masterVolume

BIN
data/Hit_Hurt16.wav Normal file

Binary file not shown.

View File

@@ -0,0 +1 @@
8,0.5,,0.1744,0.1511,0.1706,0.3,0.6762,0.2,-0.2748,,,,,,,,,,,0.5075,-0.0829,,0.395,-0.3199,0.625,,,,,,,masterVolume

BIN
data/Laser_Shoot2.wav Normal file

Binary file not shown.

1
data/Powerup10.bfxrsound Normal file
View File

@@ -0,0 +1 @@
2,0.5,,0.3096,,0.4346,0.3,0.2865,,0.1628,,0.5293,0.426,,,,,,,,0.3934,,,,,1,,,,,,,masterVolume

BIN
data/Powerup10.wav Normal file

Binary file not shown.

1
data/Powerup30.bfxrsound Normal file
View File

@@ -0,0 +1 @@
2,0.5,,0.1458,,0.3359,0.3,0.2684,,0.2068,,,,,,,,,,,0.5759,,0.4191,,,1,,,,,,,masterVolume

BIN
data/Powerup30.wav Normal file

Binary file not shown.

BIN
data/arrow_down.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

BIN
data/arrow_down.xcf Normal file

Binary file not shown.

BIN
data/arrow_left.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

BIN
data/arrow_left.xcf Normal file

Binary file not shown.

BIN
data/arrow_right.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

BIN
data/arrow_right.xcf Normal file

Binary file not shown.

BIN
data/arrow_up.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

BIN
data/arrow_up.xcf Normal file

Binary file not shown.

BIN
data/arrowshooter_down.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

BIN
data/arrowshooter_down.xcf Normal file

Binary file not shown.

BIN
data/arrowshooter_left.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

BIN
data/arrowshooter_left.xcf Normal file

Binary file not shown.

BIN
data/arrowshooter_right.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

BIN
data/arrowshooter_right.xcf Normal file

Binary file not shown.

BIN
data/arrowshooter_up.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

BIN
data/arrowshooter_up.xcf Normal file

Binary file not shown.

BIN
data/barrel.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

BIN
data/barrel.xcf Normal file

Binary file not shown.

BIN
data/barrel2.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

BIN
data/barrel2.xcf Normal file

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

BIN
data/column.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
data/column.xcf Normal file

Binary file not shown.

BIN
data/column_faded.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
data/end.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 234 KiB

BIN
data/end.xcf Normal file

Binary file not shown.

BIN
data/end_point.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

BIN
data/end_point.xcf Normal file

Binary file not shown.

BIN
data/exit_point.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
data/exit_point.xcf Normal file

Binary file not shown.

BIN
data/fire.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

BIN
data/fire.xcf Normal file

Binary file not shown.

BIN
data/floor.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

BIN
data/floor.xcf Normal file

Binary file not shown.

BIN
data/floor_center.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

BIN
data/floor_center.xcf Normal file

Binary file not shown.

BIN
data/floor_left.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

BIN
data/floor_left.xcf Normal file

Binary file not shown.

BIN
data/floor_right.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

BIN
data/floor_right.xcf Normal file

Binary file not shown.

BIN
data/hole_lava.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
data/hole_lava.xcf Normal file

Binary file not shown.

BIN
data/hole_spiked.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

BIN
data/hole_spiked.xcf Normal file

Binary file not shown.

23
data/level_00.txt Normal file
View File

@@ -0,0 +1,23 @@
33 23
############### #############
#.............# #...........#
#.........S...#####..SSSSSSS..#
#.1.......S........2.S........#
#.........S...mmmmm..S..SSSSSS#
#.............m m..S........#
#mmmmmmmmmmmmmm mmmmmmm.mmmm#
m.m
m.m
m.m
m.m
######.#####
#.....3....#
#..........#
#..........#
#..BBB.BBB.#
#SSSSSSSSSS#
#..........#
#..........#
#.....E....#
#mmmmmmmmmm#

23
data/level_01.txt Normal file
View File

@@ -0,0 +1,23 @@
33 23
############### #############
#.............# #...........#
#.........L...#####..LLLLLLL..#
#.1.......L........2.L........#
#.........L...mmmmm..L..LLLLLL#
#.............m m..L........#
#mmmmmmmmmmmmmm mmmmmmm.mmmm#
m.m
m.m
m.m
m.m
######.#####
#.....3....#
#..........#
#..........#
#..BBB.BBB.#
#LLLLLSSSSS#
#..........#
#..........#
#.....E....#
#mmmmmmmmmm#

24
data/level_02.txt Normal file
View File

@@ -0,0 +1,24 @@
33 24
############### #############
#.............# #........V..#
#.............#####...........#
#.1................2..........#
#.............mmmmm>..........#
#.........A...m m....A......#
#mmmmmmmmmmmmmm mmmmmmm.mmmm#
m.m
m.m
m.m
m.m
######.#####
#.....3....#
#.BB....BB.#
#.........<#
#>.........#
#.BB....BB.#
#.........<#
#>.........#
#..........#
#.....E....#
#mmmmmmmmmm#

50
data/level_03.txt Normal file
View File

@@ -0,0 +1,50 @@
100 100
#########
#...1...#
#.......#
#.......#
#.SSSSSS#
#.......#
#SSSSSS.#
#.......#
#.B.LLLL#
#SSSmmmm#
#.......# ############
#mmm.mmm# #....L.....#
m.m #..S.L.S..<#
m.m #..S.L.S...#
m.#######..S.L.S..<#
m........2.S.L.S...#
mmmmmmmmmSSS.L.S...#
m.>..L.S...#
m....L.S.B.########
m.>....S.B........#
mmmmmmmmmmmmmmmmm.#
m.#
m.#
m.#
m.#
######.######
#.....3.....#
#.B.B...B.B.#
#...........#
#LLLSSSSSLLL#
#...A...A...#
#...........#
#...........#
#mmmmm.mmmmm#
m.m
m.m
m.m
m.m
m.m
######.######
#.....4.....#
#.B.B...B.B.#
#...........#
#LLLLLSLLLLL#
#...A...A...#
#...........#
#.....F.....#
#mmmmmmmmmmm#

BIN
data/logo.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 234 KiB

BIN
data/logo.xcf Normal file

Binary file not shown.

BIN
data/player.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

BIN
data/player.xcf Normal file

Binary file not shown.

BIN
data/player_broken.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

BIN
data/player_broken.xcf Normal file

Binary file not shown.

BIN
data/player_down.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

BIN
data/player_down.xcf Normal file

Binary file not shown.

BIN
data/player_left.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

BIN
data/player_right.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

BIN
data/player_right.xcf Normal file

Binary file not shown.

BIN
data/player_up.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

BIN
data/player_up.xcf Normal file

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

BIN
data/save_point.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

BIN
data/save_point.xcf Normal file

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

228
main.c
View File

@@ -5,177 +5,125 @@
#include "GameLib.h"
#include "GameEnts.h"
#include "GameMap.h"
int play;
int game_level=0;
int game_level_point=1;
int game_level_reset=0;
DrawImg img_logo;
DrawImg img_end;
DrawFnt font;
DrawFnt font_shad;
DrawImg img_yball;
DrawImg img_rball;
DrawImg img_block;
DrawImg img_block2;
int ProcTitle(){
Draw_Clean(0,0,0);
Anim anim_whitey;
Draw_DrawImg(img_logo,170,100);
AudioSnd coin;
Draw_DrawText(font ,"Press [Space] to Start.",300,300);
enum {
Ent_Player,
Ent_Ball,
Ent_Block,
Ent_Block2
} EntityType;
Entity *ent_player;
Entity *ent_ball;
Entity *ent_block;
Entity *ent_block2;
Draw_DrawText(font ,"By Kableado (VAR)",200,440);
if(Input_AnyKey()){
play=1;
return(0);
}
return(1);
}
int ProcEnd(){
Draw_Clean(0,0,0);
Draw_DrawImg(img_end,170,100);
Draw_DrawText(font ,"Congratulations you saved the kittie!",300,320);
Draw_DrawText(font ,"Thanks for playing!",100,440);
if(Input_AnyKey()){
return(0);
}
return(1);
}
void ProcGame(){
Draw_Clean(0,0,0);
}
void PostProcGame(){
if(Input_GetKey(InputKey_Action1)==InputKey_Pressed){
Audio_PlaySound(coin,1,1);
char string[1024];
sprintf(string, "Level: %d.%d",game_level+1,game_level_point);
Draw_DrawText(font_shad,string,17,17);
Draw_DrawText(font ,string,16,16);
if(game_level_reset==2){
Draw_DrawText(font_shad,"Level Complete",301,301);
Draw_DrawText(font ,"Level Complete.",300,300);
}else
if(game_level_reset==1){
Draw_DrawText(font_shad,"You are dead.",301,301);
Draw_DrawText(font ,"You are dead.",300,300);
}else
if(game_level_reset==3){
play=2;
GameLib_BreakLoop();
}
Draw_DrawText(font_shad,"Buncy Buncy!",41,41);
Draw_DrawText(font ,"Buncy Buncy!",40,40);
}
void player_proc(Entity *e,int ft){
vec2 vel;
if(Input_GetDir(vel)){
vec2_scale(vel,vel,2.0f);
Entity_AddVelLimit(e,vel,10.0f);
if(game_level_reset){
if( Input_AnyKey()){
if(GameMap_CreateLevel(game_level,game_level_point)){
if(game_level_reset==2){
int pos[2]={0,0};
GameLib_SetPos(pos);
}
game_level_reset=0;
}else{
play=2;
GameLib_BreakLoop();
}
}
}
}
int block2_collision(Entity *e,Entity *e2,float t,vec2 n){
if(e2->type==Ent_Ball){
return(0);
}else{
return(1);
}
}
int main(int argc,char *argv[]){
int i;
Entity *e;
srand(time(NULL));
GameLib_Init(640,480,"Game",60);
img_logo=Draw_LoadImage("data/logo.bmp");
img_end=Draw_LoadImage("data/end.bmp");
font=Draw_DefaultFont(255,255,255,255);
font_shad=Draw_DefaultFont(0,0,0,127);
img_yball=Draw_LoadImage("data/yball.bmp");
Draw_SetOffset(img_yball,-16,-16);
GameEnts_Init();
do{
play=0;
Draw_Loop(ProcTitle);
if(play==1){
int pos[2]={0,0};
GameLib_SetPos(pos);
img_rball=Draw_LoadImage("data/rball.bmp");
Draw_SetOffset(img_rball,-16,-16);
img_block=Draw_LoadImage("data/block.bmp");
Draw_SetOffset(img_block,-16,-16);
img_block2=Draw_LoadImage("data/block2.bmp");
Draw_SetOffset(img_block2,-16,-16);
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;
//AnimPlay_SetImg(&ent_player->anim,img_whitey);
AnimPlay_SetAnim(&ent_player->anim,anim_whitey);
ent_player->proc=player_proc;
ent_ball=Entity_New();
ent_ball->type=Ent_Ball;
ent_ball->radius=16.0f;
ent_ball->fric_static=0.1f;
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;
ent_block->radius=15.5f;
AnimPlay_SetImg(&ent_block->anim,img_block);
ent_block2=Entity_New();
ent_block2->type=Ent_Block2;
ent_block2->mass=-1.0f;
ent_block2->radius=15.5f;
AnimPlay_SetImg(&ent_block2->anim,img_block2);
ent_block2->collision=block2_collision;
for(i=0;i<20;i++){
e=Entity_Copy(ent_block);
vec2_set(e->pos,16+i*32,16);
GameLib_AddEntity(e);
}
for(i=0;i<20;i++){
e=Entity_Copy(ent_block);
vec2_set(e->pos,16+i*32,464);
GameLib_AddEntity(e);
}
for(i=1;i<14;i++){
e=Entity_Copy(ent_block);
vec2_set(e->pos,16,16+i*32);
GameLib_AddEntity(e);
}
for(i=1;i<14;i++){
e=Entity_Copy(ent_block);
vec2_set(e->pos,624,16+i*32);
GameLib_AddEntity(e);
}
for(i=0;i<4;i++){
e=Entity_Copy(ent_block);
vec2_set(e->pos,100,100+i*32);
GameLib_AddEntity(e);
}
for(i=0;i<4;i++){
e=Entity_Copy(ent_block);
vec2_set(e->pos,164,100+i*32);
GameLib_AddEntity(e);
}
e=Entity_Copy(ent_block2);
vec2_set(e->pos,132,100+3*32);
GameLib_AddEntity(e);
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);
GameLib_Loop(ProcGame,PostProcGame);
game_level=0;
game_level_point=1;
game_level_reset=0;
GameMap_CreateLevel(game_level,game_level_point);
GameLib_Loop(ProcGame,PostProcGame);
}
if(play==2){
Draw_Loop(ProcEnd);
}
}while(play);
return(0);
}

BIN
shot.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 900 KiB

BIN
shot_20111217-1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

BIN
shot_20111218-1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB