(20111228) 01:00
This commit is contained in:
95
main.c
95
main.c
@@ -6,6 +6,7 @@
|
||||
#include <time.h>
|
||||
|
||||
#include "GameLib.h"
|
||||
extern int gamelib_debug;
|
||||
|
||||
#include "GameEnts.h"
|
||||
#include "GameMap.h"
|
||||
@@ -21,7 +22,6 @@ DrawImg img_logo;
|
||||
DrawImg img_end;
|
||||
|
||||
DrawFnt font;
|
||||
DrawFnt font_shad;
|
||||
|
||||
int ProcTitle(){
|
||||
if( Input_GetKey(InputKey_Jump)==InputKey_Pressed||
|
||||
@@ -30,20 +30,30 @@ int ProcTitle(){
|
||||
play=1;
|
||||
return(0);
|
||||
}
|
||||
if( (Input_GetKey(InputKey_Action1)==InputKey_Pressed||
|
||||
Input_GetKey(InputKey_Action2)==InputKey_Pressed) &&
|
||||
game_started)
|
||||
{
|
||||
play=1;
|
||||
game_started=0;
|
||||
return(0);
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
|
||||
void DrawTitle(){
|
||||
Draw_Clean(0,0,0);
|
||||
Draw_SetColor(1.0f,1.0f,1.0f,1.0f);
|
||||
|
||||
Draw_DrawImg(img_logo,170,100);
|
||||
if(!game_started){
|
||||
Draw_DrawText(font ,"Press [Space] to Start.",300,300);
|
||||
Draw_DrawText(font,"Press [Space] to Start.",300,300);
|
||||
}else{
|
||||
Draw_DrawText(font ,"Press [Space] to Continue.",300,300);
|
||||
Draw_DrawText(font,"Press [Space] to Continue.",300,300);
|
||||
Draw_DrawText(font,"Press [X] to Start.",300,316);
|
||||
}
|
||||
|
||||
Draw_DrawText(font ,"By Kableado (VAR)",200,440);
|
||||
Draw_DrawText(font,"By Kableado (VAR)",200,440);
|
||||
|
||||
}
|
||||
|
||||
@@ -60,13 +70,13 @@ int ProcEnd(){
|
||||
|
||||
void DrawEnd(){
|
||||
Draw_Clean(0,0,0);
|
||||
Draw_SetColor(1.0f,1.0f,1.0f,1.0f);
|
||||
|
||||
Draw_DrawImg(img_end,170,100);
|
||||
|
||||
Draw_DrawText(font ,"Congratulations you saved the kittie!",250,320);
|
||||
Draw_DrawText(font ,"Thanks for playing!",250,350);
|
||||
|
||||
Draw_DrawText(font ,"Press [Space] to Title.",300,400);
|
||||
Draw_DrawText(font,"Congratulations you saved the kittie!",250,320);
|
||||
Draw_DrawText(font,"Thanks for playing!",250,350);
|
||||
Draw_DrawText(font,"Press [Space] to Title.",300,400);
|
||||
}
|
||||
|
||||
|
||||
@@ -94,23 +104,61 @@ void PostProcGame(){
|
||||
void DrawGame(){
|
||||
char string[1024];
|
||||
|
||||
Draw_SetColor(1.0f,1.0f,1.0f,1.0f);
|
||||
|
||||
sprintf(string, "Level: %d.%d",game_level+1,game_level_point);
|
||||
Draw_DrawText(font_shad,string,17,17);
|
||||
Draw_DrawText(font ,string,16,16);
|
||||
Draw_SetColor(0,0,0,0.5f);
|
||||
Draw_DrawText(font,string,17,17);
|
||||
Draw_SetColor(1,1,1,1);
|
||||
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);
|
||||
Draw_SetColor(0,0,0,0.5f);
|
||||
Draw_DrawText(font,"Level Complete",301,301);
|
||||
Draw_SetColor(1,1,0,1);
|
||||
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);
|
||||
Draw_SetColor(0,0,0,0.5f);
|
||||
Draw_DrawText(font,"You are dead.",301,301);
|
||||
Draw_SetColor(1,0,0,1);
|
||||
Draw_DrawText(font,"You are dead.",300,300);
|
||||
}else
|
||||
if(game_level_reset==3){
|
||||
play=2;
|
||||
GameLib_BreakLoop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void LoadGame(char *fname){
|
||||
FILE *f;
|
||||
|
||||
f=fopen(fname,"rb");
|
||||
if(!f)
|
||||
return;
|
||||
|
||||
fread(&game_level,1,sizeof(int),f);
|
||||
fread(&game_level_point,1,sizeof(int),f);
|
||||
|
||||
GameMap_CreateLevel(game_level,game_level_point);
|
||||
game_started=1;
|
||||
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
void SaveGame(char *fname){
|
||||
FILE *f;
|
||||
|
||||
f=fopen(fname,"wb");
|
||||
if(!f)
|
||||
return;
|
||||
|
||||
fwrite(&game_level,1,sizeof(int),f);
|
||||
fwrite(&game_level_point,1,sizeof(int),f);
|
||||
|
||||
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
|
||||
@@ -118,16 +166,23 @@ int main(int argc,char *argv[]){
|
||||
|
||||
srand(time(NULL));
|
||||
|
||||
if (argc>1) {
|
||||
if (!strcmp(argv[1],"debug")) {
|
||||
gamelib_debug=1;
|
||||
}
|
||||
}
|
||||
|
||||
GameLib_Init(640,480,"Game",60);
|
||||
|
||||
img_logo=Draw_LoadImage("data/logo.bmp");
|
||||
img_end=Draw_LoadImage("data/end.bmp");
|
||||
|
||||
font=Draw_DefaultFont(255,0,0,255);
|
||||
font_shad=Draw_DefaultFont(0,0,0,127);
|
||||
|
||||
font=Draw_DefaultFont(255,255,255,255);
|
||||
|
||||
GameEnts_Init();
|
||||
|
||||
LoadGame("game.save");
|
||||
|
||||
do{
|
||||
play=0;
|
||||
Draw_Loop(ProcTitle,DrawTitle);
|
||||
@@ -138,9 +193,10 @@ int main(int argc,char *argv[]){
|
||||
game_level=0;
|
||||
game_level_point=1;
|
||||
game_level_reset=0;
|
||||
|
||||
GameMap_CreateLevel(game_level,game_level_point);
|
||||
game_started=1;
|
||||
}
|
||||
game_started=1;
|
||||
GameLib_Loop(ProcGame,PostProcGame,DrawGame);
|
||||
}
|
||||
if(play==2){
|
||||
@@ -148,5 +204,8 @@ int main(int argc,char *argv[]){
|
||||
}
|
||||
}while(play);
|
||||
|
||||
|
||||
SaveGame("game.save");
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user