Subversion Repositories Kolibri OS

Rev

Rev 950 | 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);
221
kol_wnd_caption(STR_TITLE);
222
screen_draw();
223
kol_paint_end();
224
}
225
226
//=====================================
227
 
228
int piton_move()
229
 
230
int i;
231
232
for (i = len-1; i > 0; i--)
233
 
234
	z[i].x = z[i-1].x;
235
	z[i].y = z[i-1].y;
236
	}
237
238
z[0].x += v.x;
239
 
240
241
if ((1 == M[z[0].x][z[0].y])||(2 == M[z[0].x][z[0].y]))
242
 
243
244
if (3 == M[z[0].x][z[0].y])
245
 
246
	rabbit_new();
247
	return 1;
248
	}
249
250
251
 
252
 
253
put_z();
254
255
return 0;
256
 
257
258
//=====================================
259
 
260
void kol_main()
261
 
262
263
unsigned event, key;
264
 
265
266
srand(kol_system_time_get()<<8);
267
 
268
screen.bmp = scr;
269
 
270
screen.h = scrh;
271
272
az.bmp = AZ3;
273
 
274
az.h = 15;
275
276
azr.bmp = AZ4;
277
 
278
azr.h = 15;
279
280
mode = 0;
281
 
282
for (;;)
283
 
284
	kol_sleep(7);
285
1810 Albom 286
	if ( 1 == mode)
950 leency 287
 
288
		res = piton_move();
289
290
		if (1 == res)
291
 
292
293
		if (-1 == res)
294
 
295
296
		}
297
 
298
	screen_draw();
299
 
300
301
	switch (event)
302
 
303
		case 1:
304
			wnd_draw();
305
			break;
306
307
		case 2:
308
 
309
310
			switch (mode)
311
 
312
313
				case 0:
314
 
315
						{
316
						mode = 1;
317
						game_start();
318
						}
319
					break;
320
321
				case 1:
322
 
323
						{
324
						case 27:
325
							mode = 0;
326
							break;
327
						case 32:
328
							mode = 2;
329
							break;
330
						case 178:
331
							if (0 == v.y)
332
								{
333
								v.x = 0;
334
								v.y = -1;
335
								}
336
							break;
337
						case 177:
338
							if (0 == v.y)
339
								{
340
								v.x = 0;
341
								v.y = 1;
342
								}
343
							break;
344
						case 176:
345
							if (0 == v.x)
346
								{
347
								v.x = -1;
348
								v.y = 0;
349
								}
350
							break;
351
						case 179:
352
							if (0 == v.x)
353
								{
354
								v.x = 1;
355
								v.y = 0;
356
								}
357
							break;
358
						};
359
					break;
360
361
				case 2:
362
 
363
						mode = 1;
364
					break;
365
366
				};
367
 
368
			break;
369
 
370
		case 3:
371
 
372
				kol_exit();
373
			break;
374
375
		};
376
 
377
378
}
379
 
380
//=====================================
381
 
382
screen.bmp>