(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

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);
}