1 enum { 2 /* levels */ 3 Empty = 0, 4 Background, 5 Wall, 6 Cargo, 7 Goal, 8 GoalCargo, 9 Glenda, 10 11 /* movements */ 12 Up, 13 Down, 14 Left, 15 Right, 16 }; 17 18 enum { 19 /* glenda faces the horizontal direction she's moving in */ 20 GLeft = 0, 21 GRight = 1, 22 }; 23 24 enum { 25 MazeX = 20, 26 MazeY = 18, 27 BoardX = 49, 28 BoardY = 49, 29 SizeX = MazeX*BoardX+10, 30 SizeY = MazeY*BoardY+10, 31 32 Maxlevels = 200, 33 }; 34 35 typedef struct Step { 36 uint dir; /* direction */ 37 uint count; /* number of single-step moves */ 38 } Step; 39 40 typedef struct Route { 41 uint nstep; /* number of valid Step */ 42 Step *step; 43 Point dest; /* result of step */ 44 } Route; 45 46 typedef struct Walk { 47 uint nroute; /* number of valid Route* */ 48 Route **route; 49 uint beyond; /* number of allocated Route* */ 50 } Walk; 51 52 typedef struct Visited { 53 uint board[MazeX][MazeY]; 54 } Visited; 55 56 typedef struct Animation { 57 Route* route; 58 Step *step; 59 int count; 60 } Animation; 61 62 typedef struct { 63 Point glenda; 64 Point max; /* that's how much the board spans */ 65 uint index; 66 uint done; 67 uint board[MazeX][MazeY]; 68 } Level; 69 70 Level level; /* the current level */ 71 Level levels[Maxlevels]; /* all levels from this file */ 72 int numlevels; /* how many levels do we have */ 73 74 Image *img; /* buffer */ 75 Image *text; /* for text messages */ 76 Image *win; 77 78 Image *goal; 79 Image *cargo; 80 Image *goalcargo; 81 Image *wall; 82 Image *empty; 83 Image *gleft; 84 Image *gright; 85 Image *glenda; 86 Image *bg; 87 88 /* graphics.c */ 89 void drawscreen(void); 90 void drawlevel(void); 91 void drawwin(void); 92 void drawglenda(void); 93 void drawboard(Point); 94 void resize(Point); 95 Point boardsize(Point); 96 97 /* level.c */ 98 int loadlevels(char *); 99 100 /* move.c */ 101 void move(int); 102 103 /* route.c */ 104 int validpush(Point, Step*, Point*); 105 int isvalid(Point, Route*, int (*)(Point, Step*, Point*)); 106 void freeroute(Route*); 107 Route* extend(Route*, int, int, Point); 108 Route* findroute(Point, Point); 109 110 /* animation.c */ 111 void initanimation(Animation*); 112 void setupanimation(Animation*, Route*); 113 int onestep(Animation*); 114 void stopanimation(Animation*); 115 116 117 /* sokoban.c */ 118 char *genlevels(int); 119 Image *eallocimage(Rectangle, int, uint); 120