author | ecalot
<ecalot> 2005-02-26 13:45:54 UTC |
committer | ecalot
<ecalot> 2005-02-26 13:45:54 UTC |
parent | e993b156fc094f37187ae6725cbb6b5ce25337eb |
FP/src/ker/object.c | +12 | -3 |
FP/src/ker/room.c | +10 | -10 |
FP/src/res/maps.c | +12 | -7 |
diff --git a/FP/src/ker/object.c b/FP/src/ker/object.c index b965f53..f80f21c 100644 --- a/FP/src/ker/object.c +++ b/FP/src/ker/object.c @@ -90,8 +90,8 @@ 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; - int x=object->location/TILE_W; - int y=object->floor; + int x; + int y; flags=stateUpdate(&key,object,room); @@ -106,11 +106,20 @@ int objectMove(tObject* object,tKey key,tRoom* room) { switch (object->type) { case oKid: + /* Move the kid */ refresh=kidMove(object,flags,room); + /* Calculate the new positions */ + x=object->location/TILE_W; + y=object->floor; + if (refresh) *room=mapGetRoom(room->level,room->id); + refresh=0; /* Check if the object must fall down */ if (flags&STATES_FLAG_P) { tTile tile=roomGetTile(room,x+1,y+1); - if (!isIn(tile,TILES_WALKABLE)) { + if (!isIn(tile,TILES_WALKABLE)) { /* INTERRUPTION */ +#ifdef OBJECT_DEBUG + printf("INTERRUPTION! (x,y)=(%d,%d) tile=(%d,%d)\n",x,y,tile.code,tile.back); +#endif objectInterrupt(object,STATE_MARKS_FALL); flags=stateUpdate(&key,object,room); /* move again the to the interrupted state */ } diff --git a/FP/src/ker/room.c b/FP/src/ker/room.c index 8b54aa1..e5c8028 100644 --- a/FP/src/ker/room.c +++ b/FP/src/ker/room.c @@ -93,33 +93,33 @@ tTile roomGetTile(tRoom* room,int x, int y) { /* TODO: use a tile group: special, with GATES, PRESSABLE, SPIKES, * CHOPPER. - * Code SPIKES and CHOPPER as memory structures */ + */ + roomId=room->id; + if ((!roomId)||(roomId>24)) { + fprintf(stderr,"Assert: invalid room read: %d\n",roomId); + exit(1); + } + if (isIn(result,TILES_GATES)) { - roomId=room->id; if (y==0) roomId=room->links[eUp]; if (x==0) roomId=room->links[eLeft]; if (y==4) roomId=room->links[eDown]; if (x==11)roomId=room->links[eRight]; - if (roomId<24) - result.moreInfo=room->level->screenGates[roomId-1][result.back]; + result.moreInfo=room->level->screenGates[roomId-1][result.back]; } else if (isIn(result,TILES_PRESSABLE)) { - roomId=room->id; if (y==0) roomId=room->links[eUp]; /*TODO: validate corners */ if (x==0) roomId=room->links[eLeft]; if (y==4) roomId=room->links[eDown]; if (x==11)roomId=room->links[eRight]; /* the case that a button is in tile 0 should never happen, but we'll care about it just in case */ - if (roomId<24) - result.moreInfo=room->level->screenPressables[roomId-1][result.back]; + result.moreInfo=room->level->screenPressables[roomId-1][result.back]; } else if (isIn(result,TILES_CHOPPER_SPIKE)) { - roomId=room->id; if (y==0) roomId=room->links[eUp]; /*TODO: validate corners */ if (x==0) roomId=room->links[eLeft]; if (y==4) roomId=room->links[eDown]; if (x==11)roomId=room->links[eRight]; - if (roomId<24) - result.moreInfo=room->level->screenDangers[roomId-1][result.back]; + result.moreInfo=room->level->screenDangers[roomId-1][result.back]; } return result; } diff --git a/FP/src/res/maps.c b/FP/src/res/maps.c index e9911ea..f74813e 100644 --- a/FP/src/res/maps.c +++ b/FP/src/res/maps.c @@ -333,7 +333,7 @@ void mapStart(tMap* map, tObject* kid, tRoomId *roomId, int level) { /* kid->x,y */ static char environments[]=MAP_ENVIRONMENTS; *roomId=slevel(start)[0]; -#if defined DEBUGMAPS || 1 +#if defined DEBUGMAPS printf("mapStart: binding kid to map in room %d using the %d environment\n",*roomId,environments[level]); #endif slevel(time)=0; @@ -473,15 +473,21 @@ int mapMove(tMap* map) { int x=loose->x/TILE_W; int y=loose->y/TILE_H; +#if defined DEBUGMAPS if (loose->screen) printf("Updating tile (x,y)=(%d,%d) s=%d\n",loose->x,loose->y,loose->screen); +#endif if (loose->speed<7) loose->speed++; if (loose->screen) room=mapGetRoom(map,loose->screen); /* calculate if there will be an impact */ if (loose->screen&&(y!=((loose->y+loose->speed*3)/TILE_H))) { /* tile changed floor and not in screen 0*/ - tTile tile=roomGetTile(&room,x,y); - printf("Tile changed floor\n"); + tTile tile=roomGetTile(&room,x+1,y+1); +#if defined DEBUGMAPS + printf("Tile changed floor tile=(%d,%d)\n",tile.code,tile.back); +#endif if (isIn(tile,TILES_WALKABLE)) { +#if defined DEBUGMAPS printf("IMPACT in s%d x%d y%d\n",loose->screen,x,y); +#endif map->fore[(loose->screen-1)*30+x+y*10]=TILE_DEBRIS; map->back[(loose->screen-1)*30+x+y*10]=0; refresh=1; @@ -492,11 +498,10 @@ int mapMove(tMap* map) { /* if not keep falling */ loose->y+=loose->speed*3; if (loose->y>3*TILE_H) { /* go the the screen bellow */ - loose->screen=*(slevel(links)+((loose->screen-1)*4)+eDown); + if (loose->screen) loose->screen=*(slevel(links)+((loose->screen-1)*4)+eDown); loose->y=0; /* TODO: if the screen is 0 destroy loose tiles from the falling list */ } - loose->screen=loose->screen; loose=loose->next; } } @@ -513,11 +518,11 @@ void mapFreeLevel(tMap* map) { for (i=0;i<24;i++) { free(map->screenGates[i]); free(map->screenPressables[i]); - /*free(map->screenDangers[i]);*/ + free(map->screenDangers[i]); } free(map->gates); free(map->pressables); - /*free(map->dangers);*/ + free(map->dangers); free(map); }