-
Notifications
You must be signed in to change notification settings - Fork 1
/
L_FUNCS.C
416 lines (388 loc) · 11.6 KB
/
L_FUNCS.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
/* l_funcs.c */
#define BG_COLOR 0
#define MOUSE_COLOR 60
#define TEXT_COLOR 56
#define MSG_COLOR 60
#define SCREEN_X 77
#define SCREEN_Y 43
#define CTRL_MSG "NO ACTIONS LEFT FOR TODAY!"
#define MED_MSG "OSAMA NEEDS DRUGS..."
#define FOOD_MSG "OSAMA IS HUNGRY..."
#define STATUS_FILE "laden\\laden.box"
#define SMALL_FONT "laden\\Fonts\\EnSmall.mft"
#define NUM_FONT "laden\\Fonts\\Digits.mft"
#define TABLE "laden\\Images\\table.img"
#define IN_1 "laden\\Images\\in_1.img"
#define IN_2 "laden\\Images\\in_2.img"
#define IN_3 "laden\\Images\\in_3.img"
#define CREDITS "laden\\Images\\credits.img"
#define DEATH "laden\\Images\\death.img"
#define ANI_COOL1 "laden\\Ani\\cool1.anm"
#define ANI_COOL2 "laden\\Ani\\cool2.anm"
#define ANI_COOL3 "laden\\Ani\\cool3.anm"
#define ANI_COOL4 "laden\\Ani\\cool4.anm"
#define ANI_EYE1 "laden\\Ani\\eye1.anm"
#define ANI_EYE2 "laden\\Ani\\eye2.anm"
#define ANI_MOUTH1 "laden\\Ani\\mouth1.anm"
#define ANI_MOUTH2 "laden\\Ani\\mouth2.anm"
#define ANI_BALLS1 "laden\\Ani\\balls1.anm"
#define ANI_BALLS2 "laden\\Ani\\balls2.anm"
#define ANI_BOOM1 "laden\\Ani\\boom1.anm"
#define ANI_BOOM2 "laden\\Ani\\boom2.anm"
#define ANI_DRUGS1 "laden\\Ani\\drugs1.anm"
#define ANI_DRUGS2 "laden\\Ani\\drugs2.anm"
struct pos {
x, y;
};
struct BmpRec table, img;
unsigned char *vpage = NULL;
unsigned long text_timer=0, delay_timer;
int status[5]={100, 100, 40, 0, 0}, text_status=0, mouseOn=1, eye_status=-2;
void init(void);
void update_status(void);
void save_status(void);
/* main bars functions */
int run_bar(int in_num, struct pos *mnow, struct pos *mlast, unsigned char *page);
void inside_screen(int in_num, unsigned char *page);
int inside_bars(int in_num, struct pos mouse, unsigned char *page);
int check_button(int button_num, struct pos mouse);
void draw_mouse(struct pos now, struct pos *last, int ext, unsigned char *page);
void ReLoad(unsigned char *page);
void draw_num(int num, int x, int y, unsigned char *page);
int dec_food(unsigned char *page);
void Ani_laden(int ani_num, unsigned char *page);
int check_death(struct pos *mnow, struct pos *mlast, unsigned char *page);
void activate_bmp(struct BmpRec img, char *file, unsigned char *page);
void total_delay(int delay);
void init(void)
{
update_status();
LoadFont(SMALL_FONT, EnSmall, 276);
LoadFont(NUM_FONT, Digits, 70);
vpage = (unsigned char *) calloc(64000, 1);
ReadBMP(&table, TABLE, 1);
RetPal(BmpPall);
ReLoad(vpage);
}
void update_status(void)
{
FILE *fp;
struct DateRec log, today;
if ((fp = fopen(STATUS_FILE, "r"))!=NULL)
{
fseek(fp, 15L, 0);
fscanf(fp, "%d", &status[0]);
fseek(fp, 6L, 1);
fscanf(fp, "%d", &status[1]);
fseek(fp, 7L, 1);
fscanf(fp, "%d%c%d%c%d", &log.D, &log.Y, &log.M, &log.Y, &log.Y);
status[3] = log.D;
GetDate(&today);
fseek(fp, 7L, 1);
fscanf(fp, "%d", &status[2]);
if ((today.D!=log.D)||(today.M!=log.M)||(today.Y!=log.Y))
status[2] = 40;
fseek(fp, 7L, 1);
fscanf(fp, "%d", &status[4]);
fclose(fp);
}
}
void save_status(void)
{
FILE *fp;
struct DateRec today;
GetDate(&today);
fp = fopen(STATUS_FILE, "w");
fprintf(fp, "[BL BOX]\nfood=%d\nmed=%d\n", status[0], status[1]);
fprintf(fp, "date=%d/%d/%d\nctrl=%d\ntime=%d", today.D, today.M, today.Y, status[2], status[4]);
fclose(fp);
}
/* main bars functions */
int run_bar(int in_num, struct pos *mnow, struct pos *mlast, unsigned char *page)
{
int button=-1;
ReLoad(vpage);
inside_screen(in_num, page);
for (;;)
{
draw_mouse((struct pos)*mnow, mlast, button, page);
if ((button = MouseStatus(&(mnow->x), &(mnow->y), 1))==1)
if (inside_bars(in_num, (struct pos)*mnow, page)) {
status[2]--;
break;
}
else if (check_button(5, (struct pos)*mnow)) break;
}
ReLoad(page);
return(-1);
}
void inside_screen(int in_num, unsigned char *page)
{
switch (in_num)
{
case 0: ReadBMP(&img, DEATH, 0); break;
case 1: ReadBMP(&img, IN_1, 0); break;
case 2: ReadBMP(&img, IN_2, 0); break;
case 3: ReadBMP(&img, IN_3, 0); break;
case 4: ReadBMP(&img, CREDITS, 0);
}
DrawBMP(&img, SCREEN_X, SCREEN_Y, 0, 1, page);
CloseBMP(img);
}
int inside_bars(int in_num, struct pos mouse, unsigned char *page)
{
int in_ani_status;
switch (in_num)
{
case 1: /* feed him acts */
if (check_button(6, mouse))
{
status[0] += 10;
return(1);
}
else if (check_button(7, mouse))
{
status[0] += 20;
return(1);
}
else if (check_button(8, mouse))
{
status[0] += 25;
return(1);
}
else if (check_button(9, mouse))
{
status[0] += 15;
return(1);
}
break; /* end of feed him acts */
case 2: /* hit him acts */
if (check_button(6, mouse))
{
Ani_laden(eye_status, page);
for (in_ani_status=5; in_ani_status<8; in_ani_status++)
{
LoadPage(VGA, page);
total_delay(15);
if (in_ani_status!=7)
Ani_laden(in_ani_status, page);
}
status[1] -= 20;
return(1);
}
else if (check_button(7, mouse))
{
Ani_laden(eye_status, page);
for (in_ani_status=9; in_ani_status<12; in_ani_status++)
{
LoadPage(VGA, page);
total_delay(15);
if (in_ani_status!=11)
Ani_laden(in_ani_status, page);
}
status[1] = 0;
return(1);
}
else if (check_button(8, mouse))
{
Ani_laden(eye_status, page);
for (in_ani_status=3; in_ani_status<6; in_ani_status++)
{
LoadPage(VGA, page);
total_delay(15);
if (in_ani_status!=5)
Ani_laden(in_ani_status, page);
}
status[1] -= 20;
return(1);
}
else if (check_button(9, mouse))
{
Ani_laden(eye_status, page);
for (in_ani_status=7; in_ani_status<10; in_ani_status++)
{
LoadPage(VGA, page);
total_delay(15);
if (in_ani_status!=9)
Ani_laden(in_ani_status, page);
}
status[1] -= 60;
return(1);
}
break; /* end of hit him acts */
case 3: /* drug him acts */
if (check_button(7, mouse))
{
Ani_laden(eye_status, page);
for (in_ani_status=11; in_ani_status<14; in_ani_status++)
{
LoadPage(VGA, page);
total_delay(15);
if (in_ani_status!=13)
Ani_laden(in_ani_status, page);
}
status[1] += 20;
return(1);
}
else if (check_button(9, mouse))
{
Ani_laden(eye_status, page);
for (in_ani_status=11; in_ani_status<14; in_ani_status++)
{
LoadPage(VGA, page);
total_delay(15);
if (in_ani_status!=13)
Ani_laden(in_ani_status, page);
}
status[1] = 0;
return(1);
}
break; /* end of drug him acts */
}
return(0);
}
int check_button(int button_num, struct pos mouse)
{
int yes=0;
switch (button_num)
{
/* main buttons */
case 0: /* exit */
if ((mouse.x>266)&&(mouse.y>162)&&(mouse.x<279)&&(mouse.y<177)) yes=1; break;
case 1: /* feed him */
if ((mouse.x>76)&&(mouse.y>153)&&(mouse.x<128)&&(mouse.y<177)) yes=1; break;
case 2: /* bit him */
if ((mouse.x>130)&&(mouse.y>153)&&(mouse.x<182)&&(mouse.y<177)) yes=1; break;
case 3: /* drug him */
if ((mouse.x>184)&&(mouse.y>153)&&(mouse.x<236)&&(mouse.y<177)) yes=1; break;
case 4: /* credits */
if ((mouse.x>37)&&(mouse.y>162)&&(mouse.x<50)&&(mouse.y<175)) yes=1; break;
/* inside buttons */
case 5: /* cancel */
if ((mouse.x>194)&&(mouse.y>114)&&(mouse.x<232)&&(mouse.y<132)) yes=1; break;
case 6: /* water / mouth*/
if ((mouse.x>109)&&(mouse.y>62)&&(mouse.x<153)&&(mouse.y<80)) yes=1; break;
case 7: /* hotdog / boom / legal_drug*/
if ((mouse.x>109)&&(mouse.y>81)&&(mouse.x<153)&&(mouse.y<99)) yes=1; break;
case 8: /* pizza / eye */
if ((mouse.x>154)&&(mouse.y>62)&&(mouse.x<198)&&(mouse.y<80)) yes=1; break;
case 9: /* beer / balls / illegal drug*/
if ((mouse.x>154)&&(mouse.y>81)&&(mouse.x<198)&&(mouse.y<99)) yes=1; break;
}
return(yes);
}
void draw_mouse(struct pos now, struct pos *last, int ext, unsigned char *page)
{
if ((now.x!=last->x)||(now.y!=last->y)||(ext==-1))
{
LoadPage(VGA, page);
if (mouseOn)
MouseImg(0, now.x, now.y, MOUSE_COLOR, VGA);
} last->x = now.x; last->y = now.y;
}
void ReLoad(unsigned char *page)
{
int i;
RePaint(0, 0, SX_MAX, SY_MAX, BG_COLOR, page);
DrawBMP(&table, 38, 20, 0, 1, page);
/* updating all the info */
for (i=0; i<2; ++i)
if (status[i]>100)
status[i] = 100;
else if (status[i]<0)
status[i] = 0;
if (status[2]<0) status[2] = 0;
else if ((!status[4])&&(!status[2]))
status[2] = 40;
draw_num(status[0], 43, 70, page);
draw_num(status[1], 43, 135, page);
draw_num(status[2], 247, 80, page);
if ((text_status)&&(*Clock18>text_timer))
{
RePaint(77, 139, 235, 144, BG_COLOR, page);
text_status = 0;
}
else if ((!text_status)&&((status[0]<15)||(status[1]<40)||(status[2]==0)))
{
text_timer = *Clock18+50;
text_status = 1;
if (status[0]<15) EnSmallStr(FOOD_MSG, 78, 140, MSG_COLOR, page, 0);
else if (status[1]<40) EnSmallStr(MED_MSG, 78, 140, MSG_COLOR, page, 0);
else if (status[2]==0) EnSmallStr(CTRL_MSG, 78, 140, MSG_COLOR, page, 0);
}
}
void draw_num(int num, int x, int y, unsigned char *page)
{
do
{
Digit(num%10+'0', x+10, y, TEXT_COLOR, page, 0);
num /= 10;
x -= 6;
} while (num);
}
int dec_food(unsigned char *page)
{
struct TimeRec nowT;
struct DateRec nowD;
GetTime(&nowT);
GetDate(&nowD);
if (status[4]!=nowT.H){
if (nowD.D==status[3])
{
status[0] -= 3*(nowT.H-status[4]);
status[4] = nowT.H;
ReLoad(page);
return(-1);
}
else
{
if (((nowD.D-status[3])==1)||((nowD.D==1)&&((status[3]==30)||(status[3]==31))))
status[0] -= 3*((24-status[4])+nowT.H);
else status[0] = 0;
status[4] = nowT.H;
ReLoad(page);
return(-1);
}
}
return(0);
}
void Ani_laden(int ani_num, unsigned char *page)
{
ReLoad(page);
switch (ani_num)
{
case -1: ReadBMP(&img, ANI_COOL1, 0); break;
case 0: ReadBMP(&img, ANI_COOL2, 0); break;
case 1: ReadBMP(&img, ANI_COOL3, 0); break;
case 2: ReadBMP(&img, ANI_COOL4, 0); break;
case 3: ReadBMP(&img, ANI_EYE1, 0); break;
case 4: ReadBMP(&img, ANI_EYE2, 0); break;
case 5: ReadBMP(&img, ANI_MOUTH1, 0); break;
case 6: ReadBMP(&img, ANI_MOUTH2, 0); break;
case 7: ReadBMP(&img, ANI_BALLS1, 0); break;
case 8: ReadBMP(&img, ANI_BALLS2, 0); break;
case 9: ReadBMP(&img, ANI_BOOM1, 0); break;
case 10: ReadBMP(&img, ANI_BOOM2, 0); break;
case 11: ReadBMP(&img, ANI_DRUGS1, 0); break;
case 12: ReadBMP(&img, ANI_DRUGS2, 0); break;
}
DrawBMP(&img, SCREEN_X, SCREEN_Y, 0, 1, page);
CloseBMP(img);
}
int check_death(struct pos *mnow, struct pos *mlast, unsigned char *page)
{
if ((!status[0])||(!status[1])) {
run_bar(0, mnow, mlast, page);
status[0] = 100; status[1] = 100; status[2] = 40;
eye_status = -2;
ReLoad(page);
return(1);
}
return(0);
}
void total_delay(int delay)
{
delay_timer = *Clock18+delay;
while (*Clock18<delay_timer);
}