author | ecalot
<ecalot> 2005-02-20 09:11:05 UTC |
committer | ecalot
<ecalot> 2005-02-20 09:11:05 UTC |
parent | 64166fd99e97c3c919fa7937a2b811d76b28af68 |
FP/src/include/types.h | +10 | -0 |
FP/src/ker/room.c | +28 | -0 |
FP/src/res/maps.c | +50 | -1 |
diff --git a/FP/src/include/types.h b/FP/src/include/types.h index df0bfde..c96b28e 100644 --- a/FP/src/include/types.h +++ b/FP/src/include/types.h @@ -84,8 +84,16 @@ typedef struct { int time; unsigned char back; } more; + short pos; } tDanger; +typedef struct node { + int screen; + int x,y; + int speed; + struct node* next; +}tFlying; + typedef struct { tRoomId links[ 4*24]; unsigned char fore [24*30]; @@ -107,6 +115,8 @@ typedef struct { int time; unsigned char start[3]; unsigned char levelNumber; + + tFlying* flyingObjects; } tMap; typedef struct { diff --git a/FP/src/ker/room.c b/FP/src/ker/room.c index 39fc6ef..e0d3a86 100644 --- a/FP/src/ker/room.c +++ b/FP/src/ker/room.c @@ -169,6 +169,28 @@ void drawLoose(int x, int y, int frame,tLooseLayer layer) { } } +void drawUnlinkedLoose(int x, int y/*, int frame,tLooseLayer layer*/) { + register int base,tritop,tribot; + base=44; + tritop=42; + tribot=40; +/* switch(layer) { + case layTritop: + e(tritop-3,x,y); + break; + case layTribot: + e(tribot-3,x,y); + break; + case layBase: + e(base-3,x,y); + break; + }*/ + e(tritop-3,x+TILE_W,y+2); + e(tribot-3,x,y); + e(base-3,x,y+3); +} + + void drawGate(int x, int y, int frame) { /* frames are from 0 to 46, 0 is open; 46 is closed */ register int i; @@ -498,6 +520,7 @@ void drawForePanel(tRoom* room,int x, int y) { void roomDrawBackground(tRoom* room) { int x,y; + tFlying* loose=room->level->flyingObjects; for (x=1;x<11;x++) { drawBackBottomTile(room,x,0); @@ -506,6 +529,11 @@ void roomDrawBackground(tRoom* room) { drawBackBottomTile(room,x,y); } } + while (loose) { /* for each flying object check if it is in this room */ + if (loose->screen==room->id) /* if it is draw it */ + drawUnlinkedLoose(loose->x,loose->y); + loose=loose->next; + } } void roomDrawForeground(tRoom* room) { diff --git a/FP/src/res/maps.c b/FP/src/res/maps.c index 18e2574..68e7074 100644 --- a/FP/src/res/maps.c +++ b/FP/src/res/maps.c @@ -52,6 +52,7 @@ void* mapLoadLevel(tMemory level) { int dangers=0; int dangerInRoom=0; tGate** auxGates=malloc(sizeof(tGate*)*24*30); + map->flyingObjects=NULL; /* copy maps, links and start position */ memcpy(map->fore,level.array+MAPS_BLOCK_OFFSET_WALL,30*24); @@ -147,6 +148,7 @@ void* mapLoadLevel(tMemory level) { break; case TILE_LOOSE: newDanger.action=eLosNormal; + newDanger.pos=i*30+j; break; } map->back[i*30+j]=dangerInRoom; @@ -443,12 +445,59 @@ void mapMove(tMap* map) { break; case eLosMoving: map->dangers[i].frame++; - if (map->dangers[i].frame==11) map->dangers[i].action=eLosDown; + if (map->dangers[i].frame==11) { + /* Unlink the tile from the map and add it as a falling object */ + tFlying* loose=(tFlying*)malloc(sizeof(tFlying)); + + map->dangers[i].action=eLosDown; /* Mark it as down in the map */ + loose->next=map->flyingObjects; /* Link the tile to the flying objects list */ + map->flyingObjects=loose; + + loose->x=(map->dangers[i].pos%10)*TILE_W; + loose->y=((map->dangers[i].pos%30)/10+1)*TILE_H; + loose->speed=0; + loose->screen=map->dangers[i].pos/30+1; + } break; default: break; } } + + /* Now it's time to move the flying objects */ + { + tFlying* loose=map->flyingObjects; + while (loose) { + tRoom room; + int x=loose->x/TILE_W; + int y=loose->y/TILE_H; + + if (loose->screen) printf("Updating tile (x,y)=(%d,%d) s=%d\n",loose->x,loose->y,loose->screen); + 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"); + if (isIn(tile,TILES_WALKABLE)) { + printf("IMPACT in s%d x%d y%d\n",loose->screen,x,y); + map->fore[(loose->screen-1)*30+x+y*10]=TILE_DEBRIS; + map->back[(loose->screen-1)*30+x+y*10]=0; + loose->screen=0; + } + } + + /* 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); + loose->y=0; + /* TODO: if the screen is 0 destroy loose tiles from the falling list */ + } + loose->screen=loose->screen; + loose=loose->next; + } + } } void mapFreeLevel(tMap* map) {