1 | /* |
---|
2 | * Abuse - dark 2D side-scrolling platform game |
---|
3 | * Copyright (c) 1995 Crack dot Com |
---|
4 | * |
---|
5 | * This software was released into the Public Domain. As with most public |
---|
6 | * domain software, no warranty is made or implied by Crack dot Com or |
---|
7 | * Jonathan Clark. |
---|
8 | */ |
---|
9 | |
---|
10 | #include "config.h" |
---|
11 | |
---|
12 | #include "help.hpp" |
---|
13 | #include "game.hpp" |
---|
14 | |
---|
15 | int help_page=0; |
---|
16 | |
---|
17 | |
---|
18 | #define HELP_PAGES 3 |
---|
19 | |
---|
20 | char *get_page(int x) |
---|
21 | { |
---|
22 | char tmp[800],line[120]; |
---|
23 | FILE *fp=fopen("help.txt","r"); |
---|
24 | if (!fp) |
---|
25 | return strcpy((char *)malloc(40),"help.txt missing"); |
---|
26 | else |
---|
27 | { |
---|
28 | tmp[0]=0; |
---|
29 | while (x) |
---|
30 | { |
---|
31 | fgets(line,120,fp); |
---|
32 | if (line[0]=='.' && line[1]=='n') |
---|
33 | x--; |
---|
34 | if (line[0]=='.' && line[1]=='e') |
---|
35 | { |
---|
36 | fclose(fp); |
---|
37 | return strcpy((char *)malloc(30),"missing page"); |
---|
38 | } |
---|
39 | |
---|
40 | } |
---|
41 | do |
---|
42 | { |
---|
43 | fgets(line,120,fp); |
---|
44 | if (line[0]=='.') |
---|
45 | { |
---|
46 | fclose(fp); |
---|
47 | return strcpy((char *)malloc(strlen(tmp)+1),tmp); |
---|
48 | } |
---|
49 | else strcat(tmp,line); |
---|
50 | } while (1); |
---|
51 | } |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | void make_help_page(int page, image *s) |
---|
56 | { |
---|
57 | int x=0,y=0,fw=wm->font()->width(),fh=wm->font()->height(),ya; |
---|
58 | char *h,*ho,imname[30],*inp; |
---|
59 | h=ho=get_page(page); |
---|
60 | |
---|
61 | s->clear(28); // light gray |
---|
62 | |
---|
63 | bFILE *fp=open_file("art/joy.spe","rb"); |
---|
64 | if (fp->open_failure()) |
---|
65 | { |
---|
66 | wm->font()->put_string(s,10,10,"Help file missing!"); |
---|
67 | return ; |
---|
68 | |
---|
69 | } |
---|
70 | spec_directory sd(fp); |
---|
71 | image *im; |
---|
72 | |
---|
73 | |
---|
74 | while (*h) |
---|
75 | { |
---|
76 | ya=fh; |
---|
77 | while (*h && *h!='\n') |
---|
78 | { |
---|
79 | if (*h=='@') |
---|
80 | { |
---|
81 | h++; |
---|
82 | if (*h=='@') |
---|
83 | { |
---|
84 | wm->font()->put_char(s,x,y,*h); |
---|
85 | x+=fw; |
---|
86 | h++; |
---|
87 | } |
---|
88 | else |
---|
89 | { |
---|
90 | inp=imname; |
---|
91 | int center=0; |
---|
92 | if (*h=='#') |
---|
93 | { |
---|
94 | center=1; |
---|
95 | h++; |
---|
96 | } |
---|
97 | if (*h=='+') |
---|
98 | { |
---|
99 | h++; |
---|
100 | while (*h!='+') |
---|
101 | { |
---|
102 | *inp=*h; |
---|
103 | h++; |
---|
104 | inp++; |
---|
105 | } |
---|
106 | h++; |
---|
107 | *inp=0; |
---|
108 | x=atoi(imname); |
---|
109 | inp=imname; |
---|
110 | } |
---|
111 | |
---|
112 | |
---|
113 | while (*h!='@') |
---|
114 | { |
---|
115 | *inp=*h; |
---|
116 | h++; |
---|
117 | inp++; |
---|
118 | } |
---|
119 | *inp=0; |
---|
120 | h++; |
---|
121 | |
---|
122 | if (!sd.find(imname)) |
---|
123 | { |
---|
124 | wm->font()->put_string(s,0,yres-10,"Missing image!"); |
---|
125 | delete fp; |
---|
126 | free(ho); |
---|
127 | return ; |
---|
128 | } |
---|
129 | im=new image(sd.find(imname),fp); |
---|
130 | |
---|
131 | if (center) |
---|
132 | { |
---|
133 | im->put_image(s,x,y-im->height()/2,1); |
---|
134 | if (im->height()/2>=ya) |
---|
135 | ya=im->height()/2+1; |
---|
136 | } |
---|
137 | else |
---|
138 | { |
---|
139 | im->put_image(s,x,y,1); |
---|
140 | if (im->height()>=ya) |
---|
141 | ya=im->height()+1; |
---|
142 | } |
---|
143 | x+=im->width()+1; |
---|
144 | delete im; |
---|
145 | } |
---|
146 | } else if (*h=='`') |
---|
147 | { |
---|
148 | inp=imname; |
---|
149 | h+=2; |
---|
150 | while (*h!='`') |
---|
151 | { |
---|
152 | *inp=*h; |
---|
153 | h++; |
---|
154 | inp++; |
---|
155 | } |
---|
156 | h++; |
---|
157 | *inp=0; |
---|
158 | x=atoi(imname); |
---|
159 | } |
---|
160 | else |
---|
161 | { |
---|
162 | wm->font()->put_char(s,x,y,*h); |
---|
163 | x+=fw; |
---|
164 | h++; |
---|
165 | } |
---|
166 | } |
---|
167 | y+=ya; |
---|
168 | x=0; |
---|
169 | if (*h) h++; |
---|
170 | } |
---|
171 | free(ho); |
---|
172 | delete fp; |
---|
173 | } |
---|
174 | |
---|
175 | |
---|
176 | void show_help(int direction) |
---|
177 | { |
---|
178 | int i; |
---|
179 | image *h=new image(screen->width(),screen->height(),NULL,2),*old_screen; |
---|
180 | |
---|
181 | if (direction>0) |
---|
182 | make_help_page(help_page,h); |
---|
183 | else |
---|
184 | { |
---|
185 | old_screen=screen; |
---|
186 | screen=h; |
---|
187 | the_game->draw(); |
---|
188 | screen=old_screen; |
---|
189 | } |
---|
190 | |
---|
191 | |
---|
192 | int steps=8; |
---|
193 | int scroll_step=screen->height()/steps; |
---|
194 | int helpy=-screen->height()+scroll_step; |
---|
195 | |
---|
196 | for (i=0;i<steps;i++,helpy+=scroll_step) |
---|
197 | { |
---|
198 | screen->scroll(0,0,xres,yres,0,scroll_step); |
---|
199 | h->put_part(screen,0,helpy,0,0,xres,-helpy+scroll_step); |
---|
200 | wm->flush_screen(); |
---|
201 | } |
---|
202 | delete h; |
---|
203 | } |
---|
204 | |
---|
205 | |
---|
206 | |
---|
207 | |
---|
208 | |
---|
209 | |
---|
210 | void help_handle_event(event &ev) |
---|
211 | { |
---|
212 | if (ev.window!=NULL) return ; |
---|
213 | |
---|
214 | if (the_game->state!=HELP_STATE) |
---|
215 | { |
---|
216 | if (ev.type==EV_KEY && (ev.key=='h' || ev.key=='?')) |
---|
217 | { |
---|
218 | the_game->state=HELP_STATE; |
---|
219 | help_page=0; |
---|
220 | show_help(1); |
---|
221 | } |
---|
222 | } else if (ev.type==EV_KEY) |
---|
223 | { |
---|
224 | if (ev.key==JK_ESC || help_page==HELP_PAGES-1) |
---|
225 | { |
---|
226 | show_help(-1); |
---|
227 | the_game->state=RUN_STATE; |
---|
228 | } |
---|
229 | else |
---|
230 | { |
---|
231 | help_page++; |
---|
232 | show_help(1); |
---|
233 | } |
---|
234 | } |
---|
235 | } |
---|