git » fp-git.git » commit 510de2a

Added floor falling and screen moving. Fixed prototypes.

author ecalot
2004-08-24 03:54:21 UTC
committer ecalot
2004-08-24 03:54:21 UTC
parent e6df04fb186b59fdc9ecdd66165a37c03fe5e5f8

Added floor falling and screen moving. Fixed prototypes.

FP/src/include/kid.h +4 -11
FP/src/include/maps.h +6 -17
FP/src/include/object.h +4 -11
FP/src/include/room.h +1 -39
FP/src/ker/kernel.c +9 -7
FP/src/ker/kid.c +25 -25
FP/src/ker/object.c +25 -25
FP/src/res/maps.c +5 -6

diff --git a/FP/src/include/kid.h b/FP/src/include/kid.h
index 0bd9458..7462f34 100644
--- a/FP/src/include/kid.h
+++ b/FP/src/include/kid.h
@@ -35,23 +35,16 @@ kid.h: Free Prince : Kid object
 
 #include "resources.h"
 #include "input.h"
-
-typedef struct {
-	int location;
-	int floor;
-	int direction;
-	int frame;
-	int velocity;
-	enum {stay,run}nextAction;
-	tData* action;
-} tKid;
+#include "room.h"
 
 #define DIR_LEFT  1
 #define DIR_RIGHT 0
 
+#include "types.h"
+
 tKid kidCreate();
 void kidDraw(tKid kid);
-int  kidMove(tKid* kid,tKey key/*,tRoom room*/);
+int  kidMove(tKid* kid,tKey key,tRoom* room);
 void kidFree();
 
 #endif
diff --git a/FP/src/include/maps.h b/FP/src/include/maps.h
index 3e429d4..6948a1e 100644
--- a/FP/src/include/maps.h
+++ b/FP/src/include/maps.h
@@ -40,30 +40,19 @@ maps.c: Freeprince : Map handling library
 
 #define MAP_ENVIRONMENTS {0,0,0,0,1,1,1,0,0,0,1,1,0,0,1,0}
 
-typedef struct {
-	tRoomId        links[4*24];
-	unsigned char  fore [24*30];
-	unsigned char  back [24*30];
-	/*
-	 * Active door handling here
-	 * */
-	int time;
-	unsigned char start[3];
-} tMap;
-
-typedef enum {eLeft=0,eRight=1,eUp=2,eDown=3}tDirection;
+#include "types.h"
 
 /* called from reources */
 void* mapLoadLevel(tMemory level);
-void  mapDestroy(tData* map);
+void  mapDestroy(tMap* map);
 
 /* called from the kernel */
-tRoom mapGetRoom(tData* map, tRoomId roomId);
-void  mapStart(tData* map, tKid* kid, tRoomId* roomId, int level);
+tRoom mapGetRoom(tMap* map, tRoomId roomId);
+void  mapStart(tMap* map, tKid* kid, tRoomId* roomId, int level);
 
 /* events */
-void  mapPressedTile(tData* map, tTile tile);
-void  mapMove(tData* map);
+void  mapPressedTile(tMap* map, tTile tile);
+void  mapMove(tMap* map);
 
 #endif
 
diff --git a/FP/src/include/object.h b/FP/src/include/object.h
index 0bd9458..7462f34 100644
--- a/FP/src/include/object.h
+++ b/FP/src/include/object.h
@@ -35,23 +35,16 @@ kid.h: Free Prince : Kid object
 
 #include "resources.h"
 #include "input.h"
-
-typedef struct {
-	int location;
-	int floor;
-	int direction;
-	int frame;
-	int velocity;
-	enum {stay,run}nextAction;
-	tData* action;
-} tKid;
+#include "room.h"
 
 #define DIR_LEFT  1
 #define DIR_RIGHT 0
 
+#include "types.h"
+
 tKid kidCreate();
 void kidDraw(tKid kid);
-int  kidMove(tKid* kid,tKey key/*,tRoom room*/);
+int  kidMove(tKid* kid,tKey key,tRoom* room);
 void kidFree();
 
 #endif
diff --git a/FP/src/include/room.h b/FP/src/include/room.h
index 84f35f0..34c5efa 100644
--- a/FP/src/include/room.h
+++ b/FP/src/include/room.h
@@ -37,45 +37,7 @@ room.h: FreePrince : Draw Screen
 #define TILE_W 32
 #define TILE_H 63
 
-typedef char tRoomId;
-typedef unsigned char tTileId;
-typedef unsigned char tModId;
-
-typedef struct {
-	/*tMap*/ void*          level;
-	tRoomId        id;
-	tRoomId        links[4];
-	tRoomId        corners[4];
-	unsigned char  fore [60];	
-	unsigned char  back [60];
-	/* TODO: add guards */
-} tRoom;
-
-typedef struct {
-	/* Physical attributes */
-	int walkable;
-	int block;
-	
-	/* Graphical arributes */
-	int hasTorch;
-	int hasGateFrame;
-	int hasSkeleton;
-	int hasChopper;
-	int hasBigPillar;
-	int isExit;
-	int isGate;
-	int gateStatus;
-	int bricks;
-	int isPressable;
-	int hasSpikes;
-	int hasPillar;
-	int hasFloor;
-	int hasBrokenTile;
-	int isWall;
-	int hasSword;
-
-	char code;
-} tTile;
+#include "types.h"
 
 tTile roomGetTile(tRoom* room,int x, int y);
 void roomDrawBackground(tRoom* room);
diff --git a/FP/src/ker/kernel.c b/FP/src/ker/kernel.c
index 4565af1..7f4d62c 100644
--- a/FP/src/ker/kernel.c
+++ b/FP/src/ker/kernel.c
@@ -50,7 +50,8 @@ int playgame(int optionflag,int level) {
 	/* Create objects */
 	tKey    key=inputCreateKey();
 	tKid    kid=kidCreate();
-	tData*  map=resLoad(RES_MAP|level);
+	tData*  resMap=resLoad(RES_MAP|level);
+	tMap*   map=(tMap*)resMap->pFrames;
 	tRoom   room;
 	tRoomId roomId;
 	
@@ -70,8 +71,8 @@ int playgame(int optionflag,int level) {
 			 * TODO: send to the real place where
 			 * the key is interpreted in kid object
 			 */
-			kidMove(&kid,key);
-			mapMove(map);	
+			kidMove(&kid,key,&room);
+			mapMove(map);
 			/* Drawing functions */
 			outputClearScreen(); /* TODO: send to drawBackground() */
 			roomDrawBackground(&room);
@@ -82,10 +83,10 @@ int playgame(int optionflag,int level) {
 			/* Action event */
 			switch (key.actionPerformed) {
 			case quit:
-				resFree(map);
+				resFree(resMap);
 				return 1;
 			case gotoTitles:
-				resFree(map);
+				resFree(resMap);
 				return 0;
 			case showUp:
 				if ((roomId=room.links[eUp])) {
@@ -106,10 +107,11 @@ int playgame(int optionflag,int level) {
 					room=mapGetRoom(map,roomId);
 				break;
 			case passLevel:
-				resFree(map);
+				resFree(resMap);
 				level++;
 				level%=16;
-				map=resLoad(RES_MAP|level);
+				resMap=resLoad(RES_MAP|level);
+				map=(tMap*)resMap->pFrames;
 				mapStart(map,&kid,&roomId,level);
 				room=mapGetRoom(map,roomId);
 				printf("Kernel/playgame: cheat: Pass to level %d\n",level);
diff --git a/FP/src/ker/kid.c b/FP/src/ker/kid.c
index 41ee724..b4b8cbf 100644
--- a/FP/src/ker/kid.c
+++ b/FP/src/ker/kid.c
@@ -33,7 +33,8 @@ kid.h: Free Prince : Kid object
 #include "kid.h"
 #include "output.h"
 #include "resources.h" /* resLoad/resFree */
-#include "room.h" /* TILE_H */
+#include "room.h"
+#include "maps.h" /* getTile */
 #include <stdio.h> /* NULL */
 
 static struct {
@@ -115,7 +116,9 @@ void kidDraw(tKid kid) {
 	outputDrawBitmap(kid.action->pFrames[kid.frame],kid.location,58+kid.floor*TILE_H); /* TODO: use TILE_H */
 }
 
-int kidMove(tKid* kid,tKey key/*,tRoom room*/) {
+int kidMove(tKid* kid,tKey key,tRoom* room) {
+	int result;
+	tTile tile;
 	/* Returns 1 if the action is done
 	 * returns 0 if the action needs more time */
 
@@ -126,23 +129,6 @@ int kidMove(tKid* kid,tKey key/*,tRoom room*/) {
 		kid->frame=0;
 		/* keylogIntercept(&key) --> here is the right place */
 		/* Switch the right action knowing the actual status and set the velocity and action */
-		/* stay context (walk,stay,stand,jump,turn)
-		 * stay --> stay
-		 * stay --> turn 
-		 * stay --> run
-		 * stay --> walk
-		 * stay --> couch
-		 * stay --> jump
-		 * run context 
-		 * run --> turnrun
-		 * run --> run
-		 * run --> jumprun
-		 * run --> couchrun
-		 *
-		 * Note: falling and climbing context are ignored
-		 */
-		/*printf("next action=%d direction=%d keystatus=%x ",kid->nextAction,kid->direction,key.status);*/
-
 		/* STAY events
 		 */
 		
@@ -251,14 +237,28 @@ int kidMove(tKid* kid,tKey key/*,tRoom room*/) {
 				kid->velocity=kid->velocity/2; /* 50% slower */
 			}
 		}
-		return 1;
+		result=1;
 	} else {
-		/* TODO: tile traspassing and validations here
-		 * use roomStep(tRoom room,x,y) roomTouch(tRoom room,x,y) to activate tile events
-		 * use int roomKidValid(tRoom room,tKid kid) to validate kid position
-		 */
 		kid->location+=kid->velocity;
-		return 0;
+		result=0;
+	}
+
+	/* TODO: tile traspassing and validations here
+	 * use roomStep(tRoom room,x,y) roomTouch(tRoom room,x,y) to activate tile events
+	 * use int roomKidValid(tRoom room,tKid kid) to validate kid position
+	 */
+	if (kid->location<0) {
+		kid->location=10*TILE_W;
+		*room=mapGetRoom((void*)(room->level),room->links[eLeft]);
+	} else if (kid->location>10*TILE_W) {
+		*room=mapGetRoom((void*)(room->level),room->links[eRight]);
+		kid->location=0;
+	}
+	tile=roomGetTile(room,(kid->location/TILE_W)+1,kid->floor+1);
+	if (!tile.walkable) {
+			fprintf(stderr,"kidMove: Tile not walkable, falling\n");
+			kid->floor++;
 	}
+	return result;
 }
 
diff --git a/FP/src/ker/object.c b/FP/src/ker/object.c
index 41ee724..b4b8cbf 100644
--- a/FP/src/ker/object.c
+++ b/FP/src/ker/object.c
@@ -33,7 +33,8 @@ kid.h: Free Prince : Kid object
 #include "kid.h"
 #include "output.h"
 #include "resources.h" /* resLoad/resFree */
-#include "room.h" /* TILE_H */
+#include "room.h"
+#include "maps.h" /* getTile */
 #include <stdio.h> /* NULL */
 
 static struct {
@@ -115,7 +116,9 @@ void kidDraw(tKid kid) {
 	outputDrawBitmap(kid.action->pFrames[kid.frame],kid.location,58+kid.floor*TILE_H); /* TODO: use TILE_H */
 }
 
-int kidMove(tKid* kid,tKey key/*,tRoom room*/) {
+int kidMove(tKid* kid,tKey key,tRoom* room) {
+	int result;
+	tTile tile;
 	/* Returns 1 if the action is done
 	 * returns 0 if the action needs more time */
 
@@ -126,23 +129,6 @@ int kidMove(tKid* kid,tKey key/*,tRoom room*/) {
 		kid->frame=0;
 		/* keylogIntercept(&key) --> here is the right place */
 		/* Switch the right action knowing the actual status and set the velocity and action */
-		/* stay context (walk,stay,stand,jump,turn)
-		 * stay --> stay
-		 * stay --> turn 
-		 * stay --> run
-		 * stay --> walk
-		 * stay --> couch
-		 * stay --> jump
-		 * run context 
-		 * run --> turnrun
-		 * run --> run
-		 * run --> jumprun
-		 * run --> couchrun
-		 *
-		 * Note: falling and climbing context are ignored
-		 */
-		/*printf("next action=%d direction=%d keystatus=%x ",kid->nextAction,kid->direction,key.status);*/
-
 		/* STAY events
 		 */
 		
@@ -251,14 +237,28 @@ int kidMove(tKid* kid,tKey key/*,tRoom room*/) {
 				kid->velocity=kid->velocity/2; /* 50% slower */
 			}
 		}
-		return 1;
+		result=1;
 	} else {
-		/* TODO: tile traspassing and validations here
-		 * use roomStep(tRoom room,x,y) roomTouch(tRoom room,x,y) to activate tile events
-		 * use int roomKidValid(tRoom room,tKid kid) to validate kid position
-		 */
 		kid->location+=kid->velocity;
-		return 0;
+		result=0;
+	}
+
+	/* TODO: tile traspassing and validations here
+	 * use roomStep(tRoom room,x,y) roomTouch(tRoom room,x,y) to activate tile events
+	 * use int roomKidValid(tRoom room,tKid kid) to validate kid position
+	 */
+	if (kid->location<0) {
+		kid->location=10*TILE_W;
+		*room=mapGetRoom((void*)(room->level),room->links[eLeft]);
+	} else if (kid->location>10*TILE_W) {
+		*room=mapGetRoom((void*)(room->level),room->links[eRight]);
+		kid->location=0;
+	}
+	tile=roomGetTile(room,(kid->location/TILE_W)+1,kid->floor+1);
+	if (!tile.walkable) {
+			fprintf(stderr,"kidMove: Tile not walkable, falling\n");
+			kid->floor++;
 	}
+	return result;
 }
 
diff --git a/FP/src/res/maps.c b/FP/src/res/maps.c
index 57d0b7d..b9f0008 100644
--- a/FP/src/res/maps.c
+++ b/FP/src/res/maps.c
@@ -35,9 +35,8 @@ maps.c: Freeprince : Map handling library
 #include "maps.h"
 #include "room.h"
 #include "kid.h"
-#include "resources.h"
 
-#define slevel(field) (((tMap*)(((tData*)map)->pFrames))->field)
+#define slevel(field) (map->field)
 
 /* Privates 
 
@@ -76,12 +75,12 @@ void* mapLoadLevel(tMemory level) {
 	return (void*)map;
 }
 
-tRoom mapGetRoom(tData* map, tRoomId roomAux) {
+tRoom mapGetRoom(tMap* map, tRoomId roomAux) {
 	tRoom result;
 
 	/* SET room id*/
 	result.id=roomAux;
-	result.level=map->pFrames;
+	result.level=map;
 	
 	/* SET room links */
 	memcpy(result.links,slevel(links)+((roomAux-1)*4),4);
@@ -220,7 +219,7 @@ tRoom mapGetRoom(tData* map, tRoomId roomAux) {
 	return result;
 }
 
-void  mapStart(tData* map, tKid* kid, tRoomId *roomId, int level) {
+void  mapStart(tMap* map, tKid* kid, tRoomId *roomId, int level) {
 	/* kid->x,y */
 	static char environments[]=MAP_ENVIRONMENTS;
 	*roomId=slevel(start)[0];
@@ -228,7 +227,7 @@ void  mapStart(tData* map, tKid* kid, tRoomId *roomId, int level) {
 	roomLoadGfx(/*environments[level]?RES_IMG_ENV_PALACE:*/RES_IMG_ENV_DUNGEON);
 }
 
-void  mapMove(tData* map) {
+void  mapMove(tMap* map) {
 	slevel(time)++;
 	if (slevel(time)==1000) slevel(time)=0;
 }