Subversion Repositories Kolibri OS

Rev

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