author | ecalot
<ecalot> 2005-02-19 02:15:15 UTC |
committer | ecalot
<ecalot> 2005-02-19 02:15:15 UTC |
parent | 06f2b9fe75ddcdf1ef365d61ac0ac0a7f3ccdffa |
FP/src/conf/awk/states_conf_static.awk | +16 | -8 |
FP/src/conf/states/main.conf | +3 | -1 |
FP/src/include/input.h | +1 | -0 |
FP/src/include/kid.h | +4 | -0 |
FP/src/include/types.h | +3 | -1 |
FP/src/ker/kernel.c | +9 | -4 |
FP/src/ker/kid.c | +33 | -0 |
FP/src/ker/object.c | +10 | -0 |
FP/src/out/input.c | +5 | -0 |
diff --git a/FP/src/conf/awk/states_conf_static.awk b/FP/src/conf/awk/states_conf_static.awk index 5ebf949..27ae6fa 100644 --- a/FP/src/conf/awk/states_conf_static.awk +++ b/FP/src/conf/awk/states_conf_static.awk @@ -31,6 +31,7 @@ BEGIN { currentCondition=-1 currentAction=-1 + exitNextState=-1 printf("#define STATES_MOVETYPES_ABSOLUTEONSTART 0\n") printf("#define STATES_MOVETYPES_ABSOLUTEONSTOP 1\n") printf("#define STATES_MOVETYPES_RELATIVETURN 2\n") @@ -54,6 +55,20 @@ BEGIN { first=0 } +function addExit (name) { + if (exitArray[name]) { + nextStateId=exitArray[name] + } else { + nextStateId=exitNextState + exitArray[name]=exitNextState + exitNextState-- + } +} + +/^create exit [^ ]+$/ { + addExit(toupper($3)) +} + #3 tabs (options values) /^\t\t\t[^\t# ].*$/ { # next option @@ -204,18 +219,11 @@ END { actionArray[currentAction,"lastComma"]="" printf("\t{esLast,0} /* the end */\\\n}\n\n#define STATES_ACTIONS {\\\n") - exitNextState=-1 for (i=0;i<=currentAction;i++) { nextState=actionArray[i,"nextState"] if (nextState ~ /^exit /) { #if the next state is exit+something, something will be remembered split(nextState,a," ") - if (exitArray[a[2]]) { - nextStateId=exitArray[a[2]] - } else { - nextStateId=exitNextState - exitArray[a[2]]=exitNextState - exitNextState-- - } + addExit(a[2]) } else { nextStateId=stateList[nextState] } diff --git a/FP/src/conf/states/main.conf b/FP/src/conf/states/main.conf index 354a00e..a55187c 100644 --- a/FP/src/conf/states/main.conf +++ b/FP/src/conf/states/main.conf @@ -29,6 +29,8 @@ # DO NOT remove this copyright notice # +create exit splash + normal: # action Jump and crash # conditions @@ -192,7 +194,7 @@ normal: steps relative 0 animation - 15 f $2 + 15 fh $2 action If there aren't more actions then the normal state is kept conditions diff --git a/FP/src/include/input.h b/FP/src/include/input.h index e4e68ac..fcb11d6 100644 --- a/FP/src/include/input.h +++ b/FP/src/include/input.h @@ -80,5 +80,6 @@ int inputGetEvent(tKey* key); int inputDelay(tKey* key,int ticks); void inputStopTimer(); void inputInitTimer(); +void inputPause(); #endif diff --git a/FP/src/include/kid.h b/FP/src/include/kid.h index f653b72..fc18de8 100644 --- a/FP/src/include/kid.h +++ b/FP/src/include/kid.h @@ -38,6 +38,10 @@ kid.h: Free Prince : Kid object #include "types.h" +void kidDrawLives(tObject *kid); +void kidGetLive(tObject *kid); +void kidGetHitPoint(tObject *kid); +int kidTakeHitPoint(tObject *kid); int kidMove(tObject* kid,short flags,tRoom* room); #endif diff --git a/FP/src/include/types.h b/FP/src/include/types.h index e133dcf..df0bfde 100644 --- a/FP/src/include/types.h +++ b/FP/src/include/types.h @@ -51,7 +51,7 @@ typedef struct { /* The state object: only struct that is not static to the stat short* flags; /* actions to be performed by each frame (make sound, press floor, etc) */ short* steps; /* the number of steps each frame has to move */ short* offsx; /* the height the images has to be raised */ - short currentState; /* the Id of the state the kid is */ + short currentState; /* the Id of the state the object is */ short imgoffx; /* the height the current image has to be raised */ short image; /* the next image to be shown */ float step; /* the number of pixels a frame has to move */ @@ -136,6 +136,8 @@ typedef struct { tData* gfxCache[2]; tState action; tObjectType type; + int hitPoints; + int lives; } tObject; typedef enum {eLeft=0,eRight=1,eUp=2,eDown=3}tDirection; diff --git a/FP/src/ker/kernel.c b/FP/src/ker/kernel.c index 49bda01..2ebdd65 100644 --- a/FP/src/ker/kernel.c +++ b/FP/src/ker/kernel.c @@ -56,6 +56,7 @@ int playgame(int optionflag,int level) { tMap* map=(tMap*)resMap->pFrames; tRoom room; tRoomId roomId; + int death=0; /*TODO: use a map.c function that reads this information and creates the kid*/ kid=objectCreate(30,1,DIR_RIGHT,stateKidInLevel(level),RES_IMG_ALL_KID,1,oKid); @@ -68,7 +69,7 @@ int playgame(int optionflag,int level) { room=mapGetRoom(map,roomId); /* Level loop here */ - while (1) { + while (death>=0) { if (inputGetEvent(&key)) { /* Time event */ @@ -77,11 +78,12 @@ int playgame(int optionflag,int level) { * TODO: send to the real place where * the key is interpreted in kid object */ - objectMove(&kid,key,&room); + death=objectMove(&kid,key,&room); mapMove(map); /* Drawing functions */ outputClearScreen(); /* TODO: send to drawBackground() */ roomDrawBackground(&room); + kidDrawLives(&kid); objectDraw(kid); roomDrawForeground(&room); outputUpdateScreen(); @@ -148,8 +150,11 @@ int playgame(int optionflag,int level) { } } } - - return 0; + outputDrawMessage(1,"You are dead! Press a key\n"); + outputUpdateScreen(); + inputPause(); + return playgame(optionflag,level); /* TODO: fix this recursivity */ +/* return 0;*/ } /* diff --git a/FP/src/ker/kid.c b/FP/src/ker/kid.c index 50b981a..d4f9e4b 100644 --- a/FP/src/ker/kid.c +++ b/FP/src/ker/kid.c @@ -34,9 +34,42 @@ kid.c: Free Prince : Kid object #include "room.h" #include <stdio.h> /* DEBUG printf */ #include "states.h" +#include "output.h" /* outputDrawBitmap */ #include "maps.h" /* mapGetRoom */ +/* Live stuff */ +#define KID_LIVE_FILL 216 +#define KID_LIVE_EMPTY 217 +void kidDrawLives(tObject *kid) { + int i; + static int blink=0; + blink=!blink; + for (i=0;i<kid->lives;i++){ + register int res=((i<kid->hitPoints)&&!((kid->hitPoints==1)&&(blink)))? + KID_LIVE_FILL:KID_LIVE_EMPTY; + + outputDrawBitmap(kid->gfxCache[1]->pFrames[res],2+8*i,11+3*TILE_H); + + } +} + +void kidGetLive(tObject *kid) { + kid->lives++; +} + +void kidGetHitPoint(tObject *kid) { + if (kid->hitPoints<kid->lives) + kid->hitPoints++; +} + +int kidTakeHitPoint(tObject *kid) { + /* Returns 0 if death or the number of remaining hit points if not */ + return --kid->hitPoints; +} + +/* Room stuff */ + int kidVerifyRoom(tObject *kid,tRoom *room,int refresh) { /* if the kid is out of the screen we need to change the screen and put * the kid back again on it diff --git a/FP/src/ker/object.c b/FP/src/ker/object.c index 5d5e989..7f48f2d 100644 --- a/FP/src/ker/object.c +++ b/FP/src/ker/object.c @@ -62,6 +62,10 @@ tObject objectCreate(int location, int floor, int direction, int stateId, unsign object.type=type; object.direction=direction; object.action=createState(stateId); + + /* Default lives */ + object.lives=3; + object.hitPoints=3; return object; } @@ -89,6 +93,12 @@ int objectMove(tObject* object,tKey key,tRoom* room) { switch (object->type) { case oKid: refresh=kidMove(object,flags,room); + if (flags&STATES_FLAG_H) { + if (!kidTakeHitPoint(object)) { /* take a hit point */ + /* the kid has died! */ + flags=STATE_EXIT_CODE_SPLASH; + } + } break; case oGeneric: default: diff --git a/FP/src/out/input.c b/FP/src/out/input.c index bc10f8c..48253e3 100644 --- a/FP/src/out/input.c +++ b/FP/src/out/input.c @@ -263,4 +263,9 @@ int inputDelay(tKey* key,int ticks) { return ticks; } +void inputPause() { + tKey key=inputCreateKey(); + while (1) + if (!inputGetEvent(&key)) return; +}