git » fp-git.git » commit b8861f4

finished spikes and chopper behavior. Room changing bugfix.

author ecalot
2005-01-16 00:20:47 UTC
committer ecalot
2005-01-16 00:20:47 UTC
parent 611e3d2528e0694fd0dfbd4f0699773d09bba8ab

finished spikes and chopper behavior. Room changing bugfix.

FP/src/include/room.h +1 -1
FP/src/include/types.h +1 -1
FP/src/ker/kid.c +21 -25
FP/src/ker/object.c +1 -1
FP/src/ker/room.c +46 -23
FP/src/res/maps.c +25 -8

diff --git a/FP/src/include/room.h b/FP/src/include/room.h
index fcf7361..8c17e32 100644
--- a/FP/src/include/room.h
+++ b/FP/src/include/room.h
@@ -44,6 +44,6 @@ void roomDrawBackground(tRoom* room);
 void roomDrawForeground(tRoom* room);
 void roomLoadGfx(long environment); /* Only to initialize environment by mapStart */
 int roomPress(tRoom* room, tObject* obj);
-
+void roomKidChangedFloor(tRoom* room, tObject* kid);
 #endif
 
diff --git a/FP/src/include/types.h b/FP/src/include/types.h
index 5b52dbf..b8f8ebd 100644
--- a/FP/src/include/types.h
+++ b/FP/src/include/types.h
@@ -76,7 +76,7 @@ typedef struct {
 
 typedef struct {
 	int frame;
-	enum {eChoMoving,eChoWaiting,eChoClosed,eSpiUp,eSpiWaitUp,eSpiDown,eSpiStuck} action;
+	enum {eChoActive,eChoInactive,eSpiUp,eSpiWaitUp,eSpiDown,eSpiStuck} action;
 	int time;
 } tDanger;
 
diff --git a/FP/src/ker/kid.c b/FP/src/ker/kid.c
index afd0b08..198502a 100644
--- a/FP/src/ker/kid.c
+++ b/FP/src/ker/kid.c
@@ -34,44 +34,43 @@ kid.c: Free Prince : Kid object
 #include "room.h"
 #include <stdio.h> /* DEBUG printf */
 #include "states.h"
-/* #include "maps.h" * mapPressedTile */
+#include "maps.h" /* mapGetRoom */
 
 
-int kidVerifyRoom(tObject *kid,tRoom *room) {
+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
 	 * PRE: tObject *kid is a kid
 	 */
 	
-	int refresh=0;
-	
 	/* The kid is down */
-	if (kid->floor==4) {
+	if (kid->floor==3) {
 		kid->floor=0;
-		room->id=room->links[eDown];
-		refresh=1;
+		*room=mapGetRoom(room->level,room->links[eDown]);
+		refresh=0;
 	}
 	
 	/* The kid is up */
 	if (kid->floor==-1) {
-		printf("pas\xf3: kf=0 ahora es 3, cambio el id del room y refresco\n");
 		kid->floor=2;
-		room->id=room->links[eUp];
-		refresh=1;
+		*room=mapGetRoom(room->level,room->links[eUp]);
+		refresh=0;
 	}
 
 	/* The kid is left */
 	if (kid->location<0) {
 		kid->location+=TILE_W*10;
-		room->id=room->links[eLeft];
-		refresh=1;
+		refresh=0;
+		*room=mapGetRoom(room->level,room->links[eLeft]);
+		roomKidChangedFloor(room,kid);
 	}
 
 	/* The kid is right */
 	if (kid->location>TILE_W*10) {
 		kid->location-=TILE_W*10;
-		room->id=room->links[eRight];
-		refresh=1;
+		refresh=0;
+		*room=mapGetRoom(room->level,room->links[eRight]);
+		roomKidChangedFloor(room,kid);
 	}
 
 	return refresh;
@@ -83,20 +82,17 @@ int kidMove(tObject* kid,short flags,tRoom* room) {
 /*	x=object_getLocation(*kid,kid->gfxCache[kid->direction]->pFrames[stateGetImage(*kid)-1])/TILE_W;*/
 	
 	if (flags&STATES_FLAG_P)
-/*		refresh=mapPressedTile(
-			room->level,
-			roomGetTile(room,x+1,kid->floor+1),
-			room->id,
-			x+1,
-			kid->floor+1
-		);*/
 		refresh=roomPress(room,kid);
 printf("f era %d. ",kid->floor);
-	if (flags&STATES_FLAG_F)
+	if (flags&STATES_FLAG_F) {
 		kid->floor++;
-	if (flags&STATES_FLAG_U)
+		roomKidChangedFloor(room,kid);
+	}
+	if (flags&STATES_FLAG_U) {
 		kid->floor--;
+		roomKidChangedFloor(room,kid);
+	}
 printf("f pasa a ser %d\n",kid->floor);
-	return kidVerifyRoom(kid,room)||refresh;
+	return kidVerifyRoom(kid,room,refresh);
 }
-	
+
diff --git a/FP/src/ker/object.c b/FP/src/ker/object.c
index 00313cb..02c36c5 100644
--- a/FP/src/ker/object.c
+++ b/FP/src/ker/object.c
@@ -85,7 +85,7 @@ int objectMove(tObject* object,tKey key,tRoom* 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 */	
+ * call a function that performs all the actions knowing the room, the object and the flags. Returns refresh. */	
 	switch (object->type) {
 		case oKid:
 			refresh=kidMove(object,flags,room);
diff --git a/FP/src/ker/room.c b/FP/src/ker/room.c
index c316dc5..3b66da3 100644
--- a/FP/src/ker/room.c
+++ b/FP/src/ker/room.c
@@ -150,20 +150,23 @@ void drawExit(int x, int y, int frame) {
 	e(2,x,y);
 }
 
-typedef enum {layBack=113,layRight=108,layFore=102}tSpikeLayer;
+typedef enum {layFore=113,layRight=108,layBack=102}tSpikeLayer;
 void drawSpike(int x, int y, int frame, tSpikeLayer layer) {
-	/* Frame defined from 0 (none) to 5 (near none). 3 is out normal. */
-	switch (layer) { /* TODO: use relative offsets in resources */
-		case layRight:
-			x+=32;
-			y-=7;
-			break;				
-		case layFore:
-		case layBack:
-			y-=2;
-			break;
+	if (frame) {
+		frame--;
+		/* Frame defined from 0 (none) to 5 (near none). 3 is out normal. */
+		switch (layer) { /* TODO: use relative offsets in resources */
+			case layRight:
+				x+=32;
+				y-=7;
+				break;				
+			case layFore:
+			case layBack:
+				y-=2;
+				break;
+		}
+		e((int)layer+((frame>4)?(6-frame):frame),x,y);
 	}
-	e((int)layer+((frame>4)?(6-frame):frame),x,y);
 }	
 
 typedef enum {layCBack=1,layCFore=2}tChopperLayer;
@@ -238,7 +241,7 @@ void drawBackPanel(tRoom* room,int x, int y) {
 	}
 	/* chopper/this */
 	if (isIn(tile,TILE_CHOPPER)) 
-		drawChopper((x-1)*TILE_W+0,y*TILE_H,room->level->time%8,layCBack);
+		drawChopper((x-1)*TILE_W+0,y*TILE_H,chopperGetFrame(tile),layCBack);
 	/* empty_bricks/this */
 	if (isIn(tile,TILES_BRICKE1)) 
 		e(51,x*TILE_W+0,y*TILE_H-18);
@@ -292,7 +295,7 @@ void drawBackPanel(tRoom* room,int x, int y) {
 	/* spikes/this */
 	if (isIn(tile,TILES_SPIKES)) {
 		e(101,(x-1)*TILE_W+0,y*TILE_H+0);
-		drawSpike((x-1)*TILE_W+0,y*TILE_H,spikeGetFrame(tile),layFore);
+		drawSpike((x-1)*TILE_W+0,y*TILE_H,spikeGetFrame(tile),layBack);
 	}
 	/* skeleton/this */
 	if (isIn(tile,TILES_SKELETON)) 
@@ -354,7 +357,7 @@ void drawBackBottomTile(tRoom* room,int x, int y) {
 			/* pillar/left */
 			if (isIn(dleft,TILES_PILLAR)) 
 				e(45,(x-1)*TILE_W+0,y*TILE_H+3);
-			/* pillar/left */
+			/* wall/left */
 			if (isIn(dleft,TILES_WALL)) 
 				e(64,(x-1)*TILE_W+0,y*TILE_H+3);
 		}
@@ -434,6 +437,9 @@ void drawForePanel(tRoom* room,int x, int y) {
 	/* debris/this foreground layer */
 	if (isIn(tile,TILES_BROKENTILE)) 
 		e(51,(x-1)*TILE_W+0,y*TILE_H+0);
+	/* spikes/this foreground layer */
+	if (isIn(tile,TILES_SPIKES)) 
+		drawSpike((x-1)*TILE_W+0,y*TILE_H+0,spikeGetFrame(tile),layFore);
 }	
 
 /*
@@ -502,8 +508,8 @@ int roomPress(tRoom* room, tObject* obj) {
 
 	/* spikes */
 	/* there are 7 possibilities to be */
-#define WHERE_NEAR 3
-#define WHERE_IN 1
+#define WHERE_NEAR 6
+#define WHERE_IN 3
 	where=border;i=1;
 	if (((obj->location%TILE_W)<(TILE_W-WHERE_IN))&&obj->direction==DIR_LEFT){
 		where=nearborder;i=1;}
@@ -520,23 +526,40 @@ int roomPress(tRoom* room, tObject* obj) {
 
 	if (where!=middle) { /* TODO: the first case is different.
 	                      * try to make it as similar as possible */
-		if (isIn(aux=roomGetTile(room,x+i,y),TILES_CHOPPER_SPIKE)) {
+		if (isIn(aux=roomGetTile(room,x+i,y),TILES_SPIKES)) {
 			/* spikes left in this floor */
 			tDanger* danger=aux.moreInfo;
-			/*danger->action=eSpiUp;*/
-		} else if ((y<3)&&isIn(roomGetTile(room,x+i,y),TILE_EMPTY)&&isIn(aux=roomGetTile(room,x+i,y+1),TILES_CHOPPER_SPIKE)) {
+			danger->action=eSpiUp;
+		} else if ((y<3)&&isIn(roomGetTile(room,x+i,y),TILE_EMPTY)&&isIn(aux=roomGetTile(room,x+i,y+1),TILES_SPIKES)) {
 			/* spikes left in the lower floor, there is
 			 * a space so you can fall down */
 			tDanger* danger=aux.moreInfo;
-			/*danger->action=eSpiUp;*/
-		} else if ((y<2)&&isIn(roomGetTile(room,x+i,y),TILE_EMPTY)&&isIn(roomGetTile(room,x+i,y+1),TILE_EMPTY)&&isIn(aux=roomGetTile(room,x+i,y+2),TILES_CHOPPER_SPIKE)) {
+			danger->action=eSpiUp;
+		} else if ((y<2)&&isIn(roomGetTile(room,x+i,y),TILE_EMPTY)&&isIn(roomGetTile(room,x+i,y+1),TILE_EMPTY)&&isIn(aux=roomGetTile(room,x+i,y+2),TILES_SPIKES)) {
 			/* spikes left in the 2 level lower floor, there are
 			 * spaces so you can fall down */
 			tDanger* danger=aux.moreInfo;
-			/*danger->action=eSpiUp;*/
+			danger->action=eSpiUp;
 		}
 	}	
+
 	return refresh;
 
 }
 
+void roomKidChangedFloor(tRoom* room, tObject* kid) {
+	/* Choppers */
+	tTile aux;
+	int i,j;
+
+	printf("kid had changed the floor. Guards and choppers may be allerted.\n");
+	for (j=1;j<4;j++) {
+		for (i=1;i<10;i++) {
+			if (isIn((aux=roomGetTile(room,i,j)),TILE_CHOPPER)) {
+				tDanger* chopper=aux.moreInfo;
+				chopper->action=((j-1)==kid->floor)?eChoActive:eChoInactive;
+			}
+		}
+	}
+}
+
diff --git a/FP/src/res/maps.c b/FP/src/res/maps.c
index 1704c0d..23d79e0 100644
--- a/FP/src/res/maps.c
+++ b/FP/src/res/maps.c
@@ -131,7 +131,8 @@ void* mapLoadLevel(tMemory level) {
 				tDanger newDanger;
 				/* initialize the tDanger object*/
 	 			newDanger.frame=0;
-				newDanger.action=((map->fore[i*30+j]&0x1f)==TILE_CHOPPER)?eChoWaiting:eSpiDown;
+	 			newDanger.time=1;
+				newDanger.action=((map->fore[i*30+j]&0x1f)==TILE_CHOPPER)?eChoInactive:eSpiDown;
 				map->back[i*30+j]=dangerInRoom;
 				map->screenDangers[i][dangerInRoom]=map->dangers+dangers;
 				fprintf(stderr,"mapLoadLevel: Creating danger tile: indexed=%d,%d btn pointer=%p\n",i,dangerInRoom,(void*)(map->dangers+dangers));
@@ -380,15 +381,14 @@ void  mapMove(tMap* map) {
 		}
 	}
 
-	/* check out and update all the spikes and choppers *
-	printf("updating\n");
-	for (i=0;i<slevel(totalDangers);i++) {
-		printf("updating Spikes: action: %d frame=%d time=%d\n",map->dangers[i].action,map->dangers[i].frame,map->dangers[i].time);
+	/* check out and update all the spikes and choppers */
+	printf("chopper act=%d tim=%d fra=%d\n",map->dangers[i].time,map->dangers[i].action,map->dangers[i].frame);
+	for (i=0;i<slevel(totalDangers);i++) { 
 		switch (map->dangers[i].action) {
 		case eSpiUp:
 			map->dangers[i].frame++;
-			if (map->dangers[i].frame>3) {
-				map->dangers[i].frame=3;
+			if (map->dangers[i].frame>4) {
+				map->dangers[i].frame=4;
 				map->dangers[i].action=eSpiWaitUp;
 				map->dangers[i].time=30;
 			}
@@ -400,13 +400,30 @@ void  mapMove(tMap* map) {
 			}
 			break;
 		case eSpiDown:
+			if (map->dangers[i].frame) map->dangers[i].frame++;
+			if (map->dangers[i].frame==7) map->dangers[i].frame=0;
+			break;
+		case eChoInactive:
 			if (map->dangers[i].frame) map->dangers[i].frame++;
 			if (map->dangers[i].frame==6) map->dangers[i].frame=0;
+			map->dangers[i].time=1;
+			break;
+		case eChoActive:
+			if (map->dangers[i].frame) {
+				map->dangers[i].frame++;
+			} else {
+				map->dangers[i].time--;
+			}
+			if (map->dangers[i].frame==6) {
+				map->dangers[i].frame=0;
+				map->dangers[i].time=10;
+			}
+			if (!map->dangers[i].time) map->dangers[i].frame++;
 			break;
 		default:
 			break;
 		}
-	}*/
+	}
 }
 
 void  mapFreeLevel(tMap* map) {