Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
6970 leency 1
/*
2
THE BUS
3
Copyright (C) 2008, 2012, 2017 Leency
4
Menu image from Freepik.com
5
D O N K E Y
6
Copyright (C) 2008 O.Bogomaz
7
*/
8
 
6984 leency 9
#ifndef AUTOBUILD
10
#include "lang.h--"
11
#endif
12
 
6970 leency 13
#define MEMSIZE 1024 * 60;
14
 
15
#include "..\lib\kolibri.h"
16
#include "..\lib\random.h"
17
 
7049 leency 18
#include "..\lib\obj\libio.h"
19
#include "..\lib\obj\libimg.h"
6970 leency 20
 
21
libimg_image menu;
22
libimg_image road;
6976 leency 23
libimg_image objects;
6970 leency 24
 
6995 leency 25
int frame_timeout = 1;
26
 
6997 leency 27
int lifes=0, level=0, score=0;
6984 leency 28
int don_x, don_y, don_h, don_w=68, don_type, don_image_y, don_step_y, don_step_y_default=3;
29
int don_h_mas[8] = { 36,72,36,74,24,64,48,74 };
30
int bus_x, bus_w=42, bus_y, bus_h=88, bus_y_default=290;
6970 leency 31
 
32
#define SCR_MENU_MAIN   1
33
#define SCR_GAME        2
34
#define SCR_PAUSE       3
35
 
6976 leency 36
#define RAND -1
6970 leency 37
 
6984 leency 38
#define WIN_X 516
39
#define WIN_Y 382
6970 leency 40
 
41
int screen_type=SCR_MENU_MAIN;
42
 
43
#define COLOR_ROAD 0x6D879B;
44
 
45
int active_menu_item=0;
46
 
6995 leency 47
#ifdef LANG_RUS
48
#define THE_BUS_TEXT "Маршрутка"
49
#define CONTROLS_TEXT "'Маршрутка
50
Управление:
51
Влево/Вправо или Пробел
52
Клавиша P ставит на паузу'tI"
53
#define ABOUT_TEXT "'Маршрутка
6996 leency 54
Версия v1.01
6995 leency 55
 
6997 leency 56
Сыграйте за дерзкого маршрутчика,
6995 leency 57
который несется домой после смены.
7578 leency 58
Он уже накатил рюмаху с мужиками
6995 leency 59
и теперь его ничто не остановит!
60
 
61
Автор Leency
62
Картинка в меню Freepik.com'tI"
63
#define PAUSE_TEXT "ПАУЗА"
64
#define GAME_OVER_TEXT "Игра окончена"
65
#define FINAL_SCORE_TEXT "Финальный счет"
6997 leency 66
#define LIFES_TEXT "Жизни"
6995 leency 67
#define LEVEL_TEXT "Уровень"
68
#define SCORE_TEXT "Счет"
6984 leency 69
char *MENU_LIST[]={
6995 leency 70
"Новая игра",
71
"Управление",
72
"Об игре",
73
"Выход",
74
0};
75
	#else
76
#define THE_BUS_TEXT "THE BUS"
77
#define CONTROLS_TEXT "'The Bus
78
Control keys:
79
Left, Right, Space
80
Press P key for pause'tI"
81
#define ABOUT_TEXT "'The Bus
6996 leency 82
Version v1.01
6995 leency 83
Author: Leency
84
Menu image from Freepik.com'tI"
85
#define PAUSE_TEXT "PAUSE"
86
#define GAME_OVER_TEXT "GAME OVER"
87
#define FINAL_SCORE_TEXT "Final Score"
6997 leency 88
#define LIFES_TEXT "Lifes"
6995 leency 89
#define LEVEL_TEXT "Level"
90
#define SCORE_TEXT "Score"
91
char *MENU_LIST[]={
6970 leency 92
"New game",
93
"Control keys",
94
"About",
95
"Exit",
96
0};
6995 leency 97
#endif
6970 leency 98
 
99
 
6976 leency 100
void DrawObstacle(signed int x, y) {
6970 leency 101
	int don_offset_y;
102
	int image_h;
103
 
6976 leency 104
	if (y >= 0) {
105
		image_h = don_h;
106
		don_offset_y = don_image_y;
6970 leency 107
	}
108
	else {
6976 leency 109
		image_h = don_h + y;
110
		don_offset_y = don_image_y - y;
6970 leency 111
		y = 0;
112
	}
6995 leency 113
	DrawBar(x, y-don_step_y, don_w, don_step_y, COLOR_ROAD);
114
	if (y>0) && (y
6984 leency 115
	if (image_h>0) DrawLibImage(objects.image, x, y, don_w, image_h, 0, don_offset_y);
6970 leency 116
}
6984 leency 117
void DrawBus(dword x, y) { DrawLibImage(objects.image, x, y, bus_w, bus_h, 0, 444); }
118
void DrawBoom(dword x, y) { DrawLibImage(objects.image, x, y, 78, 66, 0, 536); }
119
void DrawHighway() { DrawLibImage(road.image, 0,0, WIN_X, WIN_Y, 0, 0); }
120
void DrawMenuBackground() { DrawLibImage(menu.image, 0, 0, WIN_X, WIN_Y, 0, 0); }
6970 leency 121
 
122
void main()
123
{
124
	randomize();
6984 leency 125
	StartNewGame();
6970 leency 126
 
127
	load_dll(libio,  #libio_init,1);
128
	load_dll(libimg, #libimg_init,1);
6995 leency 129
	Libimg_LoadImage(#menu, abspath("menu.png"));
130
	Libimg_LoadImage(#road, abspath("road.png"));
131
	Libimg_LoadImage(#objects, abspath("objects.png"));
6970 leency 132
 
133
	loop()
134
	{
6995 leency 135
		WaitEventTimeout(frame_timeout);
6970 leency 136
 
137
		switch(EAX & 0xFF)
138
		{
139
			case evKey:
140
				GetKeys();
141
				if (key_scancode == SCAN_CODE_ESC)
142
				{
143
					if (screen_type==SCR_GAME) SetScreen(SCR_MENU_MAIN);
144
					else if (screen_type==SCR_MENU_MAIN) ExitProcess();
145
				}
146
				if (key_scancode == SCAN_CODE_DOWN) && (screen_type==SCR_MENU_MAIN)
147
				{
148
					if (active_menu_item<>3) active_menu_item++; ELSE active_menu_item=0;
149
					DrawMenuList();
150
				}
151
				if (key_scancode == SCAN_CODE_UP) && (screen_type==SCR_MENU_MAIN)
152
				{
153
					if (active_menu_item<>0) active_menu_item--; ELSE active_menu_item=3;
154
					DrawMenuList();
155
				}
156
				if (key_scancode == SCAN_CODE_ENTER) && (screen_type==SCR_MENU_MAIN)
157
				{
158
					if (active_menu_item==0)
159
					{
6984 leency 160
						StartNewGame();
6970 leency 161
						SetScreen(SCR_GAME);
162
					}
6995 leency 163
					if (active_menu_item==1) notify(CONTROLS_TEXT);
164
					if (active_menu_item==2) notify(ABOUT_TEXT);
6970 leency 165
					if (active_menu_item==3) ExitProcess();
166
				}
167
				if (key_scancode == SCAN_CODE_SPACE) && (screen_type==SCR_GAME)
168
				{
6984 leency 169
					DrawBar(bus_x*80+200, bus_y, bus_w, bus_h+1, COLOR_ROAD);
6970 leency 170
					if (bus_x==1) bus_x=0; else bus_x=1;
171
				}
172
				if (key_scancode == SCAN_CODE_LEFT) && (screen_type==SCR_GAME)
173
				{
174
					if (bus_x==0) break;
6984 leency 175
					DrawBar(bus_x*80+200, bus_y, bus_w, bus_h+1, COLOR_ROAD);
6970 leency 176
					bus_x=0;
177
				}
178
				if (key_scancode == SCAN_CODE_RIGHT) && (screen_type==SCR_GAME)
179
				{
180
					if (bus_x==1) break;
6984 leency 181
					DrawBar(bus_x*80+200, bus_y, bus_w, bus_h+1, COLOR_ROAD);
6970 leency 182
					bus_x=1;
183
				}
184
				if (key_scancode == SCAN_CODE_KEY_P)
185
				{
186
					if (screen_type==SCR_MENU_MAIN) break;
187
					else if (screen_type==SCR_GAME) SetScreen(SCR_PAUSE);
188
					else if (screen_type==SCR_PAUSE) SetScreen(SCR_GAME);
189
				}
190
				break;
191
 
192
			case evReDraw:
6995 leency 193
				DefineAndDrawWindow(250,150,WIN_X-1,WIN_Y-1,0x01,0,THE_BUS_TEXT,0); //0x74 is also possible if you fix bottom border
6970 leency 194
				DrawScreen();
195
				break;
196
 
197
			case evButton:
198
				ExitProcess();
199
				break;
200
 
201
			default:
6984 leency 202
				if (screen_type==SCR_GAME)
203
				{
6996 leency 204
					if ((don_x == bus_x)&&(don_y + don_h > bus_y )&&(don_y < bus_y + don_h )) {
6997 leency 205
						lifes--;
6984 leency 206
						DrawBus(bus_x*80+200,bus_y);
6996 leency 207
						DrawBoom(bus_x*80+180,bus_y+10);
6984 leency 208
						pause(150);
209
						GetNewObstacle(RAND);
210
						DrawScreen();
211
					}
212
 
6997 leency 213
					if (lifes==0) {
6984 leency 214
						DrawGameOverMessage();
215
						break;
216
					}
217
 
218
					don_y += don_step_y;
219
 
220
					if (don_y - don_step_y >= WIN_Y)
221
					{
222
						GetNewObstacle(RAND);
223
						score++;
224
						bus_y -= don_step_y+1;
6995 leency 225
						DrawBar(bus_x*80+200, bus_y+bus_h, bus_w, don_step_y+1, COLOR_ROAD);
6984 leency 226
						WriteScore();
227
					}
228
 
229
					if (score) && (score % 15 == 0)
230
					{
231
						score++;
232
						NewLevel();
233
						DrawScreen();
234
						don_step_y++;
235
					}
236
 
237
					DrawRoad();
238
				}
6970 leency 239
		}
240
	}
241
}
242
 
6984 leency 243
void NewLevel()
244
{
245
	level++;
246
	bus_y = bus_y_default;
247
}
248
 
249
void StartNewGame()
250
{
6997 leency 251
	lifes=3;
6984 leency 252
	level=0;
253
	score=0;
254
	bus_y = bus_y_default;
255
	don_step_y = don_step_y_default;
256
	GetNewObstacle(RAND);
257
}
258
 
6970 leency 259
void WriteScore() {
6984 leency 260
	DrawLibImage(road.image, 20, 166, 120, 24, 20, 164);
6995 leency 261
	WriteText(20, 140, 0x81, 0xFFFFFF, SCORE_TEXT);
6984 leency 262
	WriteText(20, 166, 0x81, 0xFFFFFF, itoa(score));
6970 leency 263
}
264
 
265
void SetScreen(dword _screen_type) {
266
	screen_type = _screen_type;
267
	DrawScreen();
268
}
269
 
270
void DrawScreen()
271
{
6976 leency 272
	int i;
6970 leency 273
	if (screen_type==SCR_MENU_MAIN)
274
	{
275
		DrawMenuBackground();
6995 leency 276
		WriteTextB(20, 20, 0x83, 0xE8783F, THE_BUS_TEXT);
6970 leency 277
		DrawMenuList();
278
	}
279
	if (screen_type==SCR_GAME) || (screen_type==SCR_PAUSE)
280
	{
281
		DrawHighway();
6997 leency 282
		WriteText(20, 20,  0x81, 0xFFFFFF, LIFES_TEXT);
283
		WriteText(20, 46,  0x81, 0xFFFFFF, itoa(lifes));
6995 leency 284
		WriteText(20, 80,  0x81, 0xFFFFFF, LEVEL_TEXT);
6984 leency 285
		WriteText(20, 106, 0x81, 0xFFFFFF, itoa(level));
6970 leency 286
		WriteScore();
287
		DrawRoad();
288
		if (screen_type==SCR_PAUSE) {
6984 leency 289
			DrawBar(0,0,140,60,0xFF0000);
6995 leency 290
			WriteText(10,14,0x83,0xFFFfff,PAUSE_TEXT);
6976 leency 291
		}
6970 leency 292
	}
293
}
294
 
295
 
296
void DrawMenuList()
297
{
298
	int j;
299
	for (j=0; j<4; j++) DrawMenuItem(j, j);
300
}
301
 
302
void DrawMenuItem(int item_n, text_n)
303
{
304
	dword color;
305
	if (active_menu_item==item_n) color = 0xFF0000; else color = 0xFFffff;
6984 leency 306
	WriteText(20+2, item_n*56+116+2, 0x81, 0xAAAaaa, MENU_LIST[text_n]);
307
	WriteText(20, item_n*56+116, 0x81, color, MENU_LIST[text_n]);
6970 leency 308
}
309
 
310
void DrawGameOverMessage()
311
{
6984 leency 312
	DrawBar(0, 0, WIN_X, WIN_Y, 0xF3E1BD);
6995 leency 313
	WriteText(40, 40, 0x81, 0xA48C74, GAME_OVER_TEXT);
314
	WriteText(40, 75, 0x81, 0xA48C74, FINAL_SCORE_TEXT);
6984 leency 315
	WriteTextB(40, 140, 0x85, 0xA48C74, itoa(score));
6970 leency 316
	pause(350);
317
	active_menu_item=0;
6976 leency 318
	SetScreen(SCR_MENU_MAIN);
6970 leency 319
}
320
 
6976 leency 321
void GetNewObstacle(int N)
322
{
323
	int i;
324
	don_x = random(2);
6984 leency 325
	if (N==RAND) don_type = random(7); else don_type = N;
6976 leency 326
	don_h = don_h_mas[don_type];
6984 leency 327
	don_y = -don_h;
6976 leency 328
	don_image_y = 0;
6984 leency 329
	for (i = 0; i < don_type; i++) don_image_y += don_h_mas[i]+2; //calculate image y offset for current obstacle
6976 leency 330
}
331
 
6970 leency 332
#define LINE_LENGTH 10
6984 leency 333
int line_y=0;
334
void DrawLineSeparator()
6970 leency 335
{
6984 leency 336
	int y;
337
	if (screen_type == SCR_GAME) line_y += don_step_y;
6970 leency 338
	//the beginning of the white dashed line between two roadways
339
	if (line_y>=20) {
340
		line_y=0;
341
	}
342
	else
343
	{
6984 leency 344
		DrawBar(258, 0, 2, line_y, COLOR_ROAD);
345
		DrawBar(258, 0, 2, line_y-LINE_LENGTH, 0xDDE9F2);
6970 leency 346
	}
6976 leency 347
	for (y=0; y
6970 leency 348
	{
6984 leency 349
		DrawBar(258, line_y+y, 2, LINE_LENGTH, 0xDDE9F2);
350
		DrawBar(258, line_y+y+LINE_LENGTH, 2, LINE_LENGTH, COLOR_ROAD);
6970 leency 351
	}
352
}
353
 
6984 leency 354
void DrawRoad()
355
{
356
	DrawLineSeparator();
357
	DrawObstacle(don_w+10*don_x+186,don_y);
358
	DrawBus(bus_x*80+200,bus_y);
359
}
6970 leency 360
 
361
 
362
 
363
 
6984 leency 364
 
6970 leency 365
stop: