Subversion Repositories Kolibri OS

Rev

Rev 7493 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7493 Rev 7494
Line 1... Line 1...
1
/* Rocket Forces
1
/* Rocket Forces
2
 * Filename: rforces.cpp
2
 * Filename: rforces.cpp
3
 * Version 0.1.1
3
 * Version 0.1
4
 * Copyright (c) Serial 2007
4
 * Copyright (c) Serial 2007
5
 */
5
 */
Line -... Line 6...
-
 
6
 
-
 
7
/* Version 0.2
-
 
8
 * Copyright (c) Leency 2018
-
 
9
 */
Line 6... Line 10...
6
 
10
 
Line 7... Line 11...
7
 
11
 
8
#include 
12
#include 
Line 24... Line 28...
24
cExplode **explodes = new cExplode*[R_COUNT + B_COUNT]; 
28
cExplode **explodes = new cExplode*[R_COUNT + B_COUNT]; 
25
cBuilding *house = new cBuilding();
29
cBuilding *house = new cBuilding();
26
Dword *cur_handle;
30
Dword *cur_handle;
27
int score, health;
31
int score, health;
Line -... Line 32...
-
 
32
 
-
 
33
bool game_over;
28
 
34
 
29
struct MouseState
35
struct MouseState
30
{
36
{
31
	int x, y, lbclick;	
37
	int x, y, lbclick;	
32
	Dword buttons;
38
	Dword buttons;
Line 33... Line 39...
33
} ms;
39
} ms;
34
 
40
 
35
 
-
 
36
void kos_Main()
41
 
37
{
42
void kos_Main()
38
	Dword btn_id;
43
{
39
	Dword frame_start, frame_end;
44
	Dword frame_start, frame_end;
40
	OnStart();
45
	OnStart();
41
	Menu();
46
	Menu();
42
	kos_SetMaskForEvents(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
47
	kos_SetMaskForEvents(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
43
	for (;;)
48
	for (;;)
44
	{
49
	{
45
		frame_start = kos_GetTime();
-
 
46
		switch (kos_CheckForEvent())
-
 
47
		{
-
 
48
		case EM_WINDOW_REDRAW:
50
		frame_start = kos_GetTime();
49
			DrawWindow();
51
		switch (kos_CheckForEvent())
50
			break;
52
		{
51
		case EM_KEY_PRESS:
53
		case EM_KEY_PRESS:
52
			Byte keyCode;
54
			Byte keyCode;
53
			kos_GetKey(keyCode);
55
			kos_GetKey(keyCode);
54
			if (keyCode == 27)
56
			if (keyCode == 27)
55
			{
57
			{
56
				OnExit();
58
				kos_ExitApp();
57
			}
59
			}
58
			if (keyCode == 51)
60
			if (keyCode == 51)
59
			{
61
			{
60
				OnStart();
62
				OnStart();
-
 
63
			}
61
			}
64
			break;
62
			break;
65
		case EM_BUTTON_CLICK:
63
		case EM_BUTTON_CLICK: // button pressed; we have only one button, close
66
			Dword btn_id;
64
			if (kos_GetButtonID(btn_id)) {
67
			if (kos_GetButtonID(btn_id)) {
65
				if (btn_id == 1) OnExit();
68
				if (btn_id == 1) kos_ExitApp();
66
			}
69
			}
67
			break;
70
			break;
68
		case EM_MOUSE_EVENT: // ñîáûòèå îò ìûøè (íàæàòèå íà êíîïêó ìûøè èëè ïåðåìåùåíèå; ñáðàñûâàåòñÿ ïðè ïðî÷òåíèè) 
71
		case EM_MOUSE_EVENT:
69
			OnMouseMove();
72
			OnMouseMove();
70
			if (ms.lbclick == 1)
73
			if (ms.lbclick == 1)
71
			{
74
			{
-
 
75
				OnLMBClick();
-
 
76
			}
-
 
77
			break;
72
				OnLMBClick();
78
		case EM_WINDOW_REDRAW:
-
 
79
			DrawWindow();
73
			}
80
			break;
74
			break;
81
		default:
75
		default:
82
			if (game_over) break;
-
 
83
			DrawBombs();
76
			DrawBombs();
84
			DrawRocketsAndCrosses();
77
			DrawRocketsAndCrosses();
85
			DrawExplodes();
78
			DrawExplodes();
-
 
79
			frame_end = kos_GetTime();
86
			DrawStats();
80
			if (frame_end - frame_start < FRAME_TIME)
87
			frame_end = kos_GetTime();
81
			{
88
			if (frame_end - frame_start < FRAME_TIME) {
82
				kos_Pause(FRAME_TIME - (frame_end - frame_start));
-
 
83
			}
-
 
84
			if (health <= 0)
-
 
85
			{
89
				kos_Pause(FRAME_TIME - (frame_end - frame_start));
86
				OnExit();
90
			}
87
			}
91
			if (health <= 0) GameOver();
Line 88... Line 92...
88
		}
92
		}
89
	}
93
	}
90
}
94
}
91
 
95
 
-
 
96
void DrawWindow()
-
 
97
{
92
void DrawWindow()
98
	kos_WindowRedrawStatus(1);
Line 93... Line 99...
93
{
99
	kos_DefineAndDrawWindow(10, 40, WINDOW_WIDTH + 12, 
-
 
100
		WINDOW_HEIGHT + kos_GetSkinHeight() + 12, 0x34, 
Line 94... Line 101...
94
	kos_WindowRedrawStatus(1);
101
		BG_COLOR, 0, 0, (Dword)header);
95
	kos_DefineAndDrawWindow(10, 40, WINDOW_WIDTH + 8, WINDOW_HEIGHT + kos_GetSkinHeight() + 12, 0x34, BG_COLOR, 0, 0, (Dword)header);
102
	kos_WindowRedrawStatus(2);
96
	kos_WindowRedrawStatus(2);
103
 
97
 
104
	DrawStats();
Line 211... Line 218...
211
void OnMouseMove()
218
void OnMouseMove()
212
{
219
{
213
	Dword old_buttons = ms.buttons;
220
	Dword old_buttons = ms.buttons;
214
	kos_GetMouseWindowXY(ms.x, ms.y);
221
	kos_GetMouseWindowXY(ms.x, ms.y);
215
	kos_GetMouseButtonsState(ms.buttons);
222
	kos_GetMouseButtonsState(ms.buttons);
-
 
223
 
-
 
224
	if (health <= 0) return;
-
 
225
 
-
 
226
	//restore mouse cursor when it over Window Header
-
 
227
	if (ms.y > 5000) RestoreSystemCursor(); else SetGameCursor();
-
 
228
 
216
	if ((old_buttons & 0x00000001) == 0 && (ms.buttons & 0x00000001) == 1)
229
	if ((old_buttons & 0x00000001) == 0 && (ms.buttons & 0x00000001) == 1)
217
	{
230
	{
218
		ms.lbclick = 1;
231
		ms.lbclick = 1;
219
	}
232
	}
220
	else
233
	else
221
	{
234
	{
222
		ms.lbclick = 0;
235
		ms.lbclick = 0;
223
	}
236
	}
Line 224... Line -...
224
 
-
 
225
	kos_DrawBar(8, 10, 6*11, 22, 0);
-
 
226
	kos_WriteTextToWindow(8, 10, 0, TEXT_COLOR, "Population:    %", 16);
-
 
227
	kos_WriteTextToWindow(8, 22, 0, TEXT_COLOR, "Score:", 6);
-
 
228
 
-
 
229
	kos_DisplayNumberToWindowBg(health, 3, 79, 10, TEXT_COLOR, BG_COLOR, nbDecimal, false);
-
 
230
	kos_DisplayNumberToWindowBg(score, 4, 49, 22, TEXT_COLOR, BG_COLOR, nbDecimal, false);
-
 
231
 
237
 
232
	if (ms.x >= 0 && ms.x < WINDOW_WIDTH &&  ms.y >= 0 && ms.y < WINDOW_HEIGHT)
238
	if (ms.x >= 0 && ms.x < WINDOW_WIDTH &&  ms.y >= 0 && ms.y < WINDOW_HEIGHT)
233
	{
239
	{
234
		gun->DrawAngle(ms.x, ms.y, G_COLOR);
240
		gun->DrawAngle(ms.x, ms.y, G_COLOR);
Line 243... Line 249...
243
	{
249
	{
244
		kos_DisplayNumberToWindowBg(ms.x, 3, WINDOW_WIDTH - 30, 10, TEXT_COLOR, BG_COLOR, nbDecimal, false);
250
		kos_DisplayNumberToWindowBg(ms.x, 3, WINDOW_WIDTH - 30, 10, TEXT_COLOR, BG_COLOR, nbDecimal, false);
245
		kos_DisplayNumberToWindowBg(ms.y, 3, WINDOW_WIDTH - 30, 22, TEXT_COLOR, BG_COLOR, nbDecimal, false);
251
		kos_DisplayNumberToWindowBg(ms.y, 3, WINDOW_WIDTH - 30, 22, TEXT_COLOR, BG_COLOR, nbDecimal, false);
246
		kos_DisplayNumberToWindowBg(ms.buttons, 1, WINDOW_WIDTH - 30, 34, TEXT_COLOR, BG_COLOR, nbDecimal, false);
252
		kos_DisplayNumberToWindowBg(ms.buttons, 1, WINDOW_WIDTH - 30, 34, TEXT_COLOR, BG_COLOR, nbDecimal, false);
247
	}*/
253
	}*/
-
 
254
}
Line -... Line 255...
-
 
255
 
-
 
256
void DrawStats()
-
 
257
{
-
 
258
	kos_WriteTextWithBg(8, 10, 0xC0, TEXT_COLOR, 0, "Population:", 11);
-
 
259
	kos_WriteTextWithBg(8+15*6, 9, 0xC0, TEXT_COLOR, 0, "%", 1);
-
 
260
	kos_WriteTextWithBg(8, 22, 0xC0, TEXT_COLOR, 0, "Score:", 6);
-
 
261
	kos_DisplayNumberToWindowBg(health, 3, 79, 10, TEXT_COLOR, BG_COLOR, nbDecimal, false);
248
 
262
	kos_DisplayNumberToWindowBg(score, 4, 49, 22, TEXT_COLOR, BG_COLOR, nbDecimal, false);
Line 249... Line 263...
249
}
263
}
250
 
264
 
251
void OnLMBClick()
265
void OnLMBClick()
Line 282... Line 296...
282
			rockets[j]->Enable(round_int(gun->cx - 15 * cos(a)) - 2, round_int(gun->cy - 15 * sin(a)) - 5, 3, 6, round_int(gun->cx - 15 * cos(a)), round_int(gun->cy - 15 * sin(a)));
296
			rockets[j]->Enable(round_int(gun->cx - 15 * cos(a)) - 2, round_int(gun->cy - 15 * sin(a)) - 5, 3, 6, round_int(gun->cx - 15 * cos(a)), round_int(gun->cy - 15 * sin(a)));
283
		}
297
		}
284
	}
298
	}
285
}
299
}
Line 286... Line -...
286
 
-
 
287
void OnRMBClick()
-
 
288
{
-
 
289
}
-
 
290
 
300
 
291
void ChangeCursor()
301
void SetGameCursor()
292
{
302
{
293
	Dword *cur = new Dword[1024];
303
	Dword *cur = new Dword[1024];
294
	for (int i = 0; i < 1024; i++)
304
	for (int i = 0; i < 1024; i++)
295
	{
305
	{
Line 327... Line 337...
327
	cur_handle = kos_LoadMouseCursor(cur, 0x05050002);
337
	cur_handle = kos_LoadMouseCursor(cur, 0x05050002);
328
	delete[] cur;
338
	delete[] cur;
329
	kos_SetMouseCursor(cur_handle);
339
	kos_SetMouseCursor(cur_handle);
330
}
340
}
Line -... Line 341...
-
 
341
 
-
 
342
void RestoreSystemCursor()
-
 
343
{
-
 
344
	if (cur_handle) kos_SetMouseCursor(0); 
-
 
345
	cur_handle=0;
-
 
346
}
331
 
347
 
332
void Menu()
348
void Menu()
333
{
349
{
334
	NewGame();
350
	NewGame();
Line 343... Line 359...
343
{
359
{
344
	if (HARDWARE_CURSOR == 0)
360
	if (HARDWARE_CURSOR == 0)
345
	{
361
	{
346
		cursor = new cCursor();
362
		cursor = new cCursor();
347
	}
363
	}
348
	ChangeCursor();
364
	SetGameCursor();
Line 349... Line 365...
349
 
365
 
Line 350... Line 366...
350
	gun->Enable((WINDOW_WIDTH / 2) - 10, WINDOW_HEIGHT - 30, 10, 20, (WINDOW_WIDTH / 2) - 5, WINDOW_HEIGHT - 20); 
366
	gun->Enable((WINDOW_WIDTH / 2) - 10, WINDOW_HEIGHT - 30, 10, 20, (WINDOW_WIDTH / 2) - 5, WINDOW_HEIGHT - 20); 
351
 
367
 
Line 364... Line 380...
364
	}
380
	}
Line 365... Line 381...
365
 
381
 
366
	health = 100;
382
	health = 100;
Line -... Line 383...
-
 
383
	score = 0;
-
 
384
 
367
	score = 0;
385
	game_over = false;
Line 368... Line 386...
368
 
386
 
369
	rtlSrand(kos_GetTime());
387
	rtlSrand(kos_GetTime());
Line 370... Line 388...
370
 
388
 
371
	DrawWindow();
389
	DrawWindow();
-
 
390
}
-
 
391
 
372
}
392
void GameOver()
-
 
393
{
-
 
394
	int xcenter = WINDOW_WIDTH / 2;
373
 
395
	int y = WINDOW_HEIGHT/ 2 - 40;
374
void OnExit()
396
	kos_WriteTextToWindow(xcenter-50, y, 0x81, TEXT_COLOR, "Game Over", 9);
375
{
-
 
376
	kos_WriteTextToWindow(WINDOW_WIDTH / 2 - 35, WINDOW_HEIGHT / 2 - 10, 0, TEXT_COLOR, "Game Over", 9);
397
	kos_WriteTextToWindow(xcenter-43, y+36, 0x80, TEXT_COLOR, "[F2] - New game", 0);
377
 
398
	kos_WriteTextToWindow(xcenter-43, y+53, 0x80, TEXT_COLOR, "[Ecs] - Exit", 0);