Subversion Repositories Kolibri OS

Rev

Rev 1810 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
950 leency 1
 
2
 
1810 Albom 3
#include "system/string.h"
4
5
#include "system/gblib.h"
6
 
7
#include "az3.h"
8
 
950 leency 9
10
//=====================================
11
 
12
#define scrw (8*32)
13
 
14
15
//=====================================
16
 
17
typedef struct
18
 
19
char x;
20
char y;
21
} p_point;
22
23
//=====================================
24
 
25
char STR_TITLE[] = {"Piton 0.3.1"};
26
 
1810 Albom 27
int mode;
950 leency 28
 
29
30
char scr[scrw*scrh*3];
31
 
32
33
char M[32][32];
34
 
35
p_point v;
36
p_point r;
37
int len;
38
39
unsigned color[] = {0xcccccc, 0xaa2222, 0x44bb, 0x7788aa};
40
 
41
42
 
43
 
44
void az_putc(unsigned char c, int x, int y)
45
 
46
if (c > 191)
47
	gb_image_set_t(&screen, x, y, &azr, (c-192)*8, 1, 8, 14, 0);
48
else
49
	gb_image_set_t(&screen, x, y, &az, (c-' ')*8, 1, 8, 14, 0);
50
}
51
52
//=====================================
53
 
54
void az_puts(unsigned char *s, int x, int y)
55
 
56
unsigned i;
57
i = 0;
58
while (*(s+i))
59
	{
60
	az_putc(*(s+i), x+i*9, y);
61
	i++;
62
	}
63
64
}
65
 
66
//=====================================
67
 
68
az_puti(int n, int x, int y)
69
 
70
char c;
71
int i = 0;
72
do
73
	{
74
	c = n % 10 + '0';
75
	az_putc(c, x-9*i, y);
76
	i++;
77
	}
78
	while ((n /= 10) > 0);
79
}
80
81
//=====================================
82
 
83
void clear()
84
 
85
86
int x, y;
87
 
88
for (y = 0; y < 32; y++)
89
 
90
		M[x][y] = 0;
91
92
for (y = 0; y < 32; y++)
93
 
94
	M[0][y] = 1;
95
	M[31][y] = 1;
96
	M[y][0] = 1;
97
	M[y][31] = 1;
98
	}
99
}
100
101
//=====================================
102
 
103
void put_z()
104
 
105
int i;
106
107
for (i = 0; i < len; i++)
108
 
109
110
}
111
 
112
//=====================================
113
 
114
void put_r()
115
 
116
M[r.x][r.y] = 3;
117
}
118
119
//=====================================
120
 
121
void rabbit_new()
122
 
123
124
for (;;)
125
 
126
	r.x = rand()%29+1;
127
	r.y = rand()%29+1;
128
129
	if (0 == M[r.x][r.y])
130
 
131
	}
132
}
133
//=====================================
134
135
void game_start()
136
 
137
138
clear();
139
 
140
v.x = 1;
141
 
142
143
len = 2;
144
 
145
z[0].x = 16;
146
 
147
148
z[1].x = 15;
149
 
150
151
rabbit_new();
152
 
153
put_z();
154
155
kol_sleep(30);
156
 
157
158
//=====================================
159
 
160
void press_space()
161
 
162
az_puts("нажмите Пробел", 10, 180);
163
az_puts("чтобы продолжить", 10, 195);
164
}
165
166
//=====================================
167
 
168
void screen_draw()
169
 
170
171
int x, y;
172
 
173
switch ( mode)
174
 
175
	case 0:
176
		gb_bar(&screen, 0, 0, scrw, scrh, 0xbb);
177
		az_puts("П И Т О Н   0.3.1", 10, 60);
178
		az_puts("ремейк для ОС Колибри", 10, 120);
1810 Albom 179
		az_puts("автор: А. Богомаз", 10, 135);
950 leency 180
		press_space();
181
		break;
182
183
184
 
185
 
186
		az_puts("ОЧКИ:", 10, 0);
187
		az_puti(len-2, 120, 0);
188
		for (y = 0; y < 32; y++)
189
			for (x = 0; x < 32; x++)
190
				gb_bar(&screen, x*8, y*8+16, 8, 8, color[ M[x][y] ]);
191
192
		break;
193
 
194
	case 2:
195
 
196
		az_puts("П А У З А", 10, 60);
197
		press_space();
198
		break;
199
200
	case 3:
201
 
202
		az_puts("К О Н Е Ц    И Г Р Ы", 10, 60);
203
		kol_screen_wait_rr();
204
		kol_paint_image(0, 0, scrw, scrh, screen.bmp);
205
		kol_sleep(170);
206
		mode = 0;
1810 Albom 207
		return;
950 leency 208
	};
209
210
kol_screen_wait_rr();
211
 
212
213
}
214
 
215
//=====================================
216
 
217
void wnd_draw()
218
 
219
kol_paint_start();
220
kol_wnd_define(280, 30, scrw+8, scrh+kol_skin_height()+4, 0x34888888, 0x34888888, STR_TITLE);
221
screen_draw();
2829 Albom 222
kol_paint_end();
950 leency 223
}
224
225
//=====================================
226
 
227
int piton_move()
228
 
229
int i;
230
231
for (i = len-1; i > 0; i--)
232
 
233
	z[i].x = z[i-1].x;
234
	z[i].y = z[i-1].y;
235
	}
236
237
z[0].x += v.x;
238
 
239
240
if ((1 == M[z[0].x][z[0].y])||(2 == M[z[0].x][z[0].y]))
241
 
242
243
if (3 == M[z[0].x][z[0].y])
244
 
245
	rabbit_new();
246
	return 1;
247
	}
248
249
250
 
251
 
252
put_z();
253
254
return 0;
255
 
256
257
//=====================================
258
 
259
void kol_main()
260
 
261
262
unsigned event, key;
263
 
264
265
srand(kol_system_time_get()<<8);
266
 
267
screen.bmp = scr;
268
 
269
screen.h = scrh;
270
271
az.bmp = AZ3;
272
 
273
az.h = 15;
274
275
azr.bmp = AZ4;
276
 
277
azr.h = 15;
278
279
mode = 0;
280
 
281
for (;;)
282
 
283
	kol_sleep(7);
284
1810 Albom 285
	if ( 1 == mode)
950 leency 286
 
287
		res = piton_move();
288
289
		if (1 == res)
290
 
291
292
		if (-1 == res)
293
 
294
295
		}
296
 
297
	screen_draw();
298
 
299
300
	switch (event)
301
 
302
		case 1:
303
			wnd_draw();
304
			break;
305
306
		case 2:
307
 
308
309
			switch (mode)
310
 
311
312
				case 0:
313
 
314
						{
315
						mode = 1;
316
						game_start();
317
						}
318
					break;
319
320
				case 1:
321
 
322
						{
323
						case 27:
324
							mode = 0;
325
							break;
326
						case 32:
327
							mode = 2;
328
							break;
329
						case 178:
330
							if (0 == v.y)
331
								{
332
								v.x = 0;
333
								v.y = -1;
334
								}
335
							break;
336
						case 177:
337
							if (0 == v.y)
338
								{
339
								v.x = 0;
340
								v.y = 1;
341
								}
342
							break;
343
						case 176:
344
							if (0 == v.x)
345
								{
346
								v.x = -1;
347
								v.y = 0;
348
								}
349
							break;
350
						case 179:
351
							if (0 == v.x)
352
								{
353
								v.x = 1;
354
								v.y = 0;
355
								}
356
							break;
357
						};
358
					break;
359
360
				case 2:
361
 
362
						mode = 1;
363
					break;
364
365
				};
366
 
367
			break;
368
 
369
		case 3:
370
 
371
				kol_exit();
372
			break;
373
374
		};
375
 
376
377
}
378
 
379
//=====================================
380
 
381
screen.bmp>