sokoban.h 2.0 KB

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