ohmu
·
2026-09-07
1enum {
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
18enum {
19 /* glenda faces the horizontal direction she's moving in */
20 GLeft = 0,
21 GRight = 1,
22};
23
24enum {
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
35typedef struct Step {
36 uint dir; /* direction */
37 uint count; /* number of single-step moves */
38} Step;
39
40typedef struct Route {
41 uint nstep; /* number of valid Step */
42 Step *step;
43 Point dest; /* result of step */
44} Route;
45
46typedef struct Walk {
47 uint nroute; /* number of valid Route* */
48 Route **route;
49 uint beyond; /* number of allocated Route* */
50} Walk;
51
52typedef struct Visited {
53 uint board[MazeX][MazeY];
54} Visited;
55
56typedef struct Animation {
57 Route* route;
58 Step *step;
59 int count;
60} Animation;
61
62typedef 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
70extern Level level; /* the current level */
71extern Level levels[Maxlevels]; /* all levels from this file */
72extern int numlevels; /* how many levels do we have */
73
74extern Image *img; /* buffer */
75extern Image *text; /* for text messages */
76extern Image *win;
77
78extern Image *goal;
79extern Image *cargo;
80extern Image *goalcargo;
81extern Image *wall;
82extern Image *empty;
83extern Image *gleft;
84extern Image *gright;
85extern Image *glenda;
86extern Image *bg;
87
88/* graphics.c */
89void drawscreen(void);
90void drawlevel(void);
91void drawwin(void);
92void drawglenda(void);
93void drawboard(Point);
94void resize(Point);
95Point boardsize(Point);
96
97/* level.c */
98int loadlevels(char *);
99
100/* move.c */
101void move(int);
102
103/* route.c */
104int validpush(Point, Step*, Point*);
105int isvalid(Point, Route*, int (*)(Point, Step*, Point*));
106void freeroute(Route*);
107Route* extend(Route*, int, int, Point);
108Route* findroute(Point, Point);
109
110/* animation.c */
111void initanimation(Animation*);
112void setupanimation(Animation*, Route*);
113int onestep(Animation*);
114void stopanimation(Animation*);
115
116
117/* sokoban.c */
118char *genlevels(int);
119Image *eallocimage(Rectangle, int, uint);
120