author | ecalot
<ecalot> 2004-08-25 00:42:12 UTC |
committer | ecalot
<ecalot> 2004-08-25 00:42:12 UTC |
parent | 8072cc84bd16e84e837b82d1fa427dca0300ad83 |
FP/src/include/types.h | +12 | -0 |
FP/src/ker/kid.c | +9 | -0 |
FP/src/ker/object.c | +9 | -0 |
FP/src/res/maps.c | +46 | -0 |
diff --git a/FP/src/include/types.h b/FP/src/include/types.h index ce042e5..00b877e 100644 --- a/FP/src/include/types.h +++ b/FP/src/include/types.h @@ -39,10 +39,22 @@ typedef char tRoomId; typedef unsigned char tTileId; typedef unsigned char tModId; +typedef struct { + int status; + int action; +} tGate; + +typedef struct { + tGate* gate; + int triggerNext; +} tEvent; + typedef struct { tRoomId links[4*24]; unsigned char fore [24*30]; unsigned char back [24*30]; + tGate** screenGates[24]; + tGate* gates; /* * Active door handling here * */ diff --git a/FP/src/ker/kid.c b/FP/src/ker/kid.c index b4b8cbf..dc1bd6a 100644 --- a/FP/src/ker/kid.c +++ b/FP/src/ker/kid.c @@ -162,6 +162,7 @@ int kidMove(tKid* kid,tKey key,tRoom* room) { } else if (key.status&K_Up) { /* jump */ kid->action=kidGfx.jumping[kid->direction]; + kid->floor--; kid->velocity=0; } else if (key.status&K_Left) { if (kid->direction==DIR_LEFT) { @@ -259,6 +260,14 @@ int kidMove(tKid* kid,tKey key,tRoom* room) { fprintf(stderr,"kidMove: Tile not walkable, falling\n"); kid->floor++; } + if (kid->floor<0) { + kid->floor=2; + *room=mapGetRoom((void*)(room->level),room->links[eUp]); + } else if (kid->floor>2) { + *room=mapGetRoom((void*)(room->level),room->links[eDown]); + kid->floor=0; + } + return result; } diff --git a/FP/src/ker/object.c b/FP/src/ker/object.c index b4b8cbf..dc1bd6a 100644 --- a/FP/src/ker/object.c +++ b/FP/src/ker/object.c @@ -162,6 +162,7 @@ int kidMove(tKid* kid,tKey key,tRoom* room) { } else if (key.status&K_Up) { /* jump */ kid->action=kidGfx.jumping[kid->direction]; + kid->floor--; kid->velocity=0; } else if (key.status&K_Left) { if (kid->direction==DIR_LEFT) { @@ -259,6 +260,14 @@ int kidMove(tKid* kid,tKey key,tRoom* room) { fprintf(stderr,"kidMove: Tile not walkable, falling\n"); kid->floor++; } + if (kid->floor<0) { + kid->floor=2; + *room=mapGetRoom((void*)(room->level),room->links[eUp]); + } else if (kid->floor>2) { + *room=mapGetRoom((void*)(room->level),room->links[eDown]); + kid->floor=0; + } + return result; } diff --git a/FP/src/res/maps.c b/FP/src/res/maps.c index b9f0008..8548247 100644 --- a/FP/src/res/maps.c +++ b/FP/src/res/maps.c @@ -35,6 +35,7 @@ maps.c: Freeprince : Map handling library #include "maps.h" #include "room.h" #include "kid.h" +#include "types.h" #define slevel(field) (map->field) @@ -68,10 +69,55 @@ void maps_getGuard(int pantalla,int *p,int *b,int *skill,int *color,tDirection * /* Publics */ void* mapLoadLevel(tMemory level) { tMap* map=(tMap*)malloc(sizeof(tMap)); + int i; + int gates=0; + int gateInRoom=0; + int change=-1; + /* copy maps, links and start position */ memcpy(map->fore,level.array+MAPS_BLOCK_OFFSET_WALL,30*24); memcpy(map->back,level.array+MAPS_BLOCK_OFFSET_BACK,30*24); memcpy(map->start,level.array+MAPS_BLOCK_OFFSET_START_POSITION,3); memcpy(map->links,level.array+MAPS_BLOCK_OFFSET_LINK,4*24); + + /* generate and load gate structures */ + for (i=0;i<30*24;i++) { /* count gates and create gate tree middle nodes */ + if ((map->fore[i]==T_GATE)||(map->fore[i]==T_EXIT_LEFT)) { + if (i/30!=change) { + printf("Screen %d has %d gates.",change,gateInRoom); + map->screenGates[change]=malloc(gateInRoom*sizeof(tGate*)); + gateInRoom=0; + } else { + gateInRoom++; + } + gates++; + } + } + if (gateInRoom) { + printf("Screen %d has %d gates.",change,gateInRoom); + map->screenGates[change]=malloc(gateInRoom*sizeof(tGate*)); + gateInRoom=0; + } + change=-1; + /* create gates sctucture */ + map->gates=malloc(gates*sizeof(tGate)); + gates=0; + for (i=0;i<30*24;i++) { + if ((map->fore[i]==T_GATE)||(map->fore[i]==T_EXIT_LEFT)) { + tGate newGate; + if (i/30!=change) { + gateInRoom=0; + } else { + gateInRoom++; + } + newGate.status=map->back[i]; + newGate.action=map->back[i]; + map->back[i]=gateInRoom; + map->screenGates[i/30][gateInRoom]=map->gates+gates; + map->gates[gates++]=newGate; + } + } + + return (void*)map; }