author | ecalot
<ecalot> 2005-01-14 19:53:42 UTC |
committer | ecalot
<ecalot> 2005-01-14 19:53:42 UTC |
parent | f52c2829e066e416cd9817263dda641ea980b424 |
FP/src/include/kid.h | +1 | -1 |
FP/src/include/object.h | +1 | -1 |
FP/src/include/types.h | +4 | -0 |
FP/src/ker/kernel.c | +1 | -1 |
FP/src/ker/kid.c | +33 | -16 |
FP/src/ker/object.c | +33 | -16 |
FP/src/ker/titles.c | +1 | -1 |
FP/src/res/maps.c | +5 | -5 |
diff --git a/FP/src/include/kid.h b/FP/src/include/kid.h index 4a38625..da03042 100644 --- a/FP/src/include/kid.h +++ b/FP/src/include/kid.h @@ -42,7 +42,7 @@ kid.h: Free Prince : Kid and other object #include "types.h" -tObject objectCreate(int location, int floor, int direction, int stateId, unsigned long resId,int cacheMirror); +tObject objectCreate(int location, int floor, int direction, int stateId, unsigned long resId, int cacheMirror, tObjectType type); void objectDraw(tObject obj); int objectMove(tObject* obj,tKey key,tRoom* room); void objectFree(tObject obj); diff --git a/FP/src/include/object.h b/FP/src/include/object.h index 4a38625..da03042 100644 --- a/FP/src/include/object.h +++ b/FP/src/include/object.h @@ -42,7 +42,7 @@ kid.h: Free Prince : Kid and other object #include "types.h" -tObject objectCreate(int location, int floor, int direction, int stateId, unsigned long resId,int cacheMirror); +tObject objectCreate(int location, int floor, int direction, int stateId, unsigned long resId, int cacheMirror, tObjectType type); void objectDraw(tObject obj); int objectMove(tObject* obj,tKey key,tRoom* room); void objectFree(tObject obj); diff --git a/FP/src/include/types.h b/FP/src/include/types.h index efb1a2b..f4771d9 100644 --- a/FP/src/include/types.h +++ b/FP/src/include/types.h @@ -76,6 +76,7 @@ typedef struct { typedef struct { int frame; + enum {eChoMoving,eChoWaiting,eChoClosed,eSpiDown,eSpiStuck} action; } tDanger; typedef struct { @@ -119,12 +120,15 @@ typedef struct { unsigned char code; } tTile; +typedef enum {oGeneric,oKid,oGuard,oTorch,oFallingTile} tObjectType; + typedef struct { int location; int floor; int direction; tData* gfxCache[2]; tState action; + tObjectType type; } 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 ff3d7be..c8e5adc 100644 --- a/FP/src/ker/kernel.c +++ b/FP/src/ker/kernel.c @@ -58,7 +58,7 @@ int playgame(int optionflag,int level) { tRoomId roomId; /*TODO: use a map.c function that reads this information and creates the kid*/ - kid=objectCreate(30,1,DIR_RIGHT,stateKidInLevel(/*level*/1),RES_IMG_ALL_KID,1); + kid=objectCreate(30,1,DIR_RIGHT,stateKidInLevel(/*level*/1),RES_IMG_ALL_KID,1,oKid); /* Game loop here */ diff --git a/FP/src/ker/kid.c b/FP/src/ker/kid.c index 073833f..2013eb7 100644 --- a/FP/src/ker/kid.c +++ b/FP/src/ker/kid.c @@ -54,19 +54,20 @@ void objectFree(tObject obj) { } /* TODO: make a function in maps.c that calls this one for the kid */ -tObject objectCreate(int location, int floor, int direction, int stateId, unsigned long resId,int cacheMirror) { +tObject objectCreate(int location, int floor, int direction, int stateId, unsigned long resId, int cacheMirror, tObjectType type) { tObject object; loadGfx(cacheMirror,object.gfxCache,resId); object.location=location; object.floor=floor; + object.type=type; object.direction=direction; object.action=createState(stateId); return object; } -int objectVerifyRoom(tObject *kid,tRoom *room) { +int kidVerifyRoom(tObject *kid,tRoom *room) { /* if the kid is out of the screen we need to change the screen and put * the kid back again on it * PRE: tObject *kid is a kid @@ -106,29 +107,23 @@ int objectVerifyRoom(tObject *kid,tRoom *room) { return refresh; } -#define kid_getLocation(kid,image) ((kid).location-(outputGetWidth(image)>>1)) +#define object_getLocation(object,image) ((object).location/*-(outputGetWidth(image)>>1)*/) -void objectDraw(tObject kid) { - void* image=kid.gfxCache[kid.direction]->pFrames[stateGetImage(kid)-1]; +void objectDraw(tObject object) { + void* image=object.gfxCache[object.direction]->pFrames[stateGetImage(object)-1]; /* TODO: move this -1 to each script frame */ outputDrawBitmap( image, - kid_getLocation(kid,image), - 58+kid.floor*TILE_H + object_getLocation(object,image), + 58+object.floor*TILE_H ); } -int objectMove(tObject* kid,tKey key,tRoom* room) { - /* advance state and get the flag, then interpret the flag and do the events */ - short flags; +int kidMove(tObject* kid,short flags,tRoom* room) { int refresh=0; int x; - flags=stateUpdate(&key,kid,room); - - if (room==NULL) return flags; /* exits if it is not associated to a room */ - - x=kid_getLocation(*kid,kid->gfxCache[kid->direction]->pFrames[stateGetImage(*kid)-1])/TILE_W; + x=object_getLocation(*kid,kid->gfxCache[kid->direction]->pFrames[stateGetImage(*kid)-1])/TILE_W; if (flags&STATES_FLAG_P) refresh=mapPressedTile( @@ -144,7 +139,29 @@ printf("f era %d. ",kid->floor); if (flags&STATES_FLAG_U) kid->floor--; printf("f pasa a ser %d\n",kid->floor); - refresh=objectVerifyRoom(kid,room)||refresh; + return kidVerifyRoom(kid,room)||refresh; +} + +int objectMove(tObject* object,tKey key,tRoom* room) { + /* advance state and get the flag, then interpret the flag and do the events */ + short flags; + int refresh; + + flags=stateUpdate(&key,object,room); + + if (room==NULL) return flags; /* exits if it is not associated to a room */ + +/* a static variable type in the tObject determinates what objet is it about. This is to simulate polymorphism. + * call a function that performs all the actions knowing the room, the object and the flags. Returns refresh. After that, kid.c can be renamed to object.c */ + switch (object->type) { + case oKid: + refresh=kidMove(object,flags,room); + break; + case oGeneric: + default: + refresh=0; + break; + } if (refresh) { /* room map was changed and needs to be refreshed */ *room=mapGetRoom(room->level,room->id); diff --git a/FP/src/ker/object.c b/FP/src/ker/object.c index 073833f..2013eb7 100644 --- a/FP/src/ker/object.c +++ b/FP/src/ker/object.c @@ -54,19 +54,20 @@ void objectFree(tObject obj) { } /* TODO: make a function in maps.c that calls this one for the kid */ -tObject objectCreate(int location, int floor, int direction, int stateId, unsigned long resId,int cacheMirror) { +tObject objectCreate(int location, int floor, int direction, int stateId, unsigned long resId, int cacheMirror, tObjectType type) { tObject object; loadGfx(cacheMirror,object.gfxCache,resId); object.location=location; object.floor=floor; + object.type=type; object.direction=direction; object.action=createState(stateId); return object; } -int objectVerifyRoom(tObject *kid,tRoom *room) { +int kidVerifyRoom(tObject *kid,tRoom *room) { /* if the kid is out of the screen we need to change the screen and put * the kid back again on it * PRE: tObject *kid is a kid @@ -106,29 +107,23 @@ int objectVerifyRoom(tObject *kid,tRoom *room) { return refresh; } -#define kid_getLocation(kid,image) ((kid).location-(outputGetWidth(image)>>1)) +#define object_getLocation(object,image) ((object).location/*-(outputGetWidth(image)>>1)*/) -void objectDraw(tObject kid) { - void* image=kid.gfxCache[kid.direction]->pFrames[stateGetImage(kid)-1]; +void objectDraw(tObject object) { + void* image=object.gfxCache[object.direction]->pFrames[stateGetImage(object)-1]; /* TODO: move this -1 to each script frame */ outputDrawBitmap( image, - kid_getLocation(kid,image), - 58+kid.floor*TILE_H + object_getLocation(object,image), + 58+object.floor*TILE_H ); } -int objectMove(tObject* kid,tKey key,tRoom* room) { - /* advance state and get the flag, then interpret the flag and do the events */ - short flags; +int kidMove(tObject* kid,short flags,tRoom* room) { int refresh=0; int x; - flags=stateUpdate(&key,kid,room); - - if (room==NULL) return flags; /* exits if it is not associated to a room */ - - x=kid_getLocation(*kid,kid->gfxCache[kid->direction]->pFrames[stateGetImage(*kid)-1])/TILE_W; + x=object_getLocation(*kid,kid->gfxCache[kid->direction]->pFrames[stateGetImage(*kid)-1])/TILE_W; if (flags&STATES_FLAG_P) refresh=mapPressedTile( @@ -144,7 +139,29 @@ printf("f era %d. ",kid->floor); if (flags&STATES_FLAG_U) kid->floor--; printf("f pasa a ser %d\n",kid->floor); - refresh=objectVerifyRoom(kid,room)||refresh; + return kidVerifyRoom(kid,room)||refresh; +} + +int objectMove(tObject* object,tKey key,tRoom* room) { + /* advance state and get the flag, then interpret the flag and do the events */ + short flags; + int refresh; + + flags=stateUpdate(&key,object,room); + + if (room==NULL) return flags; /* exits if it is not associated to a room */ + +/* a static variable type in the tObject determinates what objet is it about. This is to simulate polymorphism. + * call a function that performs all the actions knowing the room, the object and the flags. Returns refresh. After that, kid.c can be renamed to object.c */ + switch (object->type) { + case oKid: + refresh=kidMove(object,flags,room); + break; + case oGeneric: + default: + refresh=0; + break; + } if (refresh) { /* room map was changed and needs to be refreshed */ *room=mapGetRoom(room->level,room->id); diff --git a/FP/src/ker/titles.c b/FP/src/ker/titles.c index ceb4d9a..e8b3596 100644 --- a/FP/src/ker/titles.c +++ b/FP/src/ker/titles.c @@ -110,7 +110,7 @@ tMenuOption playAnimation(int id) { imgsActive++; } for (i=0;i<objCount;i++) { /*objects*/ - objArray[objsActive].obj=objectCreate(obj[i].location,obj[i].floor,DIR_LEFT,obj[i].state,obj[i].res,obj[i].cacheMirror); + objArray[objsActive].obj=objectCreate(obj[i].location,obj[i].floor,DIR_LEFT,obj[i].state,obj[i].res,obj[i].cacheMirror,oGeneric); objArray[objsActive].active=1; objArray[objsActive].duration=obj[i].duration; objsActive++; diff --git a/FP/src/res/maps.c b/FP/src/res/maps.c index 9e6f3b3..a7fa499 100644 --- a/FP/src/res/maps.c +++ b/FP/src/res/maps.c @@ -129,13 +129,12 @@ void* mapLoadLevel(tMemory level) { pressableInRoom++; } else if (isInGroup(map->fore[i*30+j],0,TILES_CHOPPER_SPIKE)) { tDanger newDanger; -/* TODO: initialize the tDanger object - * newDanger.frame=; - newDanger.action=eNormal; - newDanger.type=((map->fore[i*30+j]&0x1f)==TILE_CHOPPER)?eChopper:eSpikes;*/ + /* initialize the tDanger object*/ + newDanger.frame=0; + newDanger.action=((map->fore[i*30+j]&0x1f)==TILE_CHOPPER)?eChoWaiting:eSpiDown; map->back[i*30+j]=dangerInRoom; map->screenDangers[i][dangerInRoom]=map->dangers+dangers; - fprintf(stderr,"mapLoadLevel: Creating button: indexed=%d,%d btn pointer=%p\n",i,dangerInRoom,(void*)(map->dangers+dangers)); + fprintf(stderr,"mapLoadLevel: Creating danger tile: indexed=%d,%d btn pointer=%p\n",i,dangerInRoom,(void*)(map->dangers+dangers)); map->dangers[dangers++]=newDanger; dangerInRoom++; } @@ -316,6 +315,7 @@ void mapStart(tMap* map, tObject* kid, tRoomId *roomId, int level) { roomLoadGfx(/*environments[level]?RES_IMG_ENV_PALACE:*/RES_IMG_ENV_DUNGEON); } +/* TODO: This is part of the kernel, it needs to be moved */ void mapMove(tMap* map) { int i; slevel(time)++;