Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
7332 leency 1
/*	------- KOSILKA FOR KOLIBI -------
2
Written in C++ (MS Visual C++ 6.0+).
3
Version 1.16.
968 leency 4
 
5
					 Andrey Mihaylovich aka Dron2004
3132 leency 6
*/
968 leency 7
 
8
 
9
#include "kosSyst.h"
10
#include "kosFile.h"
3132 leency 11
#include "images.cpp"
968 leency 12
 
13
 
7332 leency 14
//External levels
968 leency 15
bool external_levels_available=false;
16
bool external_levels = false;
17
int level_read_result;
18
Byte * externallevels;
19
Byte external_levels_count[1] = {0};
20
/////////////////
21
 
22
int lastkosilkadirection=1;
7332 leency 23
int laststep=0; //Last step. 0-does not exists, 1-bottom, 2-up, 3-left, 4-right
968 leency 24
 
25
 
26
Byte skindata[13824];
27
int read_result=0;
28
bool skin_available=false;
29
bool w_redraw=true;
30
 
7332 leency 31
#if LANG == RUS
32
	const char windowTitle[] = "Косилка для Колибри";
33
	const char version[]     = "Версия 1.16";
34
	const char win[]         = "Вы выиграли!";
35
	const char press_q[]     = "<нажмите  для возврата в меню>";
36
	const char fail[]        = "Игра окончена...";
37
	const char press_r[]     = "<нажмите  для того, чтобы сыграть ещё раз>";
38
	const char k_o_s_i_l_k[] = "К   О   С   И   Л   К   А";
39
	const char for_kolibri[] = "для Колибри ОС";
40
	const char press_enter[] = "<для начала игры нажмите ENTER>";
41
	const char press_g[]     = "<нажмите  для переключения режима графики>";
42
	const char press_a[]     = "<нажмите  для включения/выключения анимации>";
43
	const char press_h[]     = "<нажмите  для просмотра сведений о программе>";
44
	const char press_s[]     = "<нажмите  чтобы выключить/включить скин>";
7333 leency 45
	const char level_label[] = "Уровень:";
7332 leency 46
	const char attempts_left[] = "Осталось попыток:";
47
	const char grass_left[]  = "Осталось травы:";
48
#else
49
	const char windowTitle[] = "Kosilka for Kolibri";
50
	const char version[]     = "  Ver. 1.16";
51
	const char win[]         = "  You won!  ";
52
	const char press_q[]     = " to return to the menu>";
53
	const char fail[]        = "   Game over.   ";
54
	const char press_r[]     = "";
55
	const char k_o_s_i_l_k[] = "K   O   S   I   L   K   A";
56
	const char for_kolibri[] = "for Kolibri OS";
57
	const char press_enter[] = "press ENTER to start the game";
58
	const char press_g[]     = " to switch graphics mode>";
59
	const char press_a[]     = " to turn on/off animation>";
60
	const char press_h[]     = " to view information about the program>";
61
	const char press_s[]     = " to turn on/off external skin>";
7333 leency 62
	const char level_label[] = "Level:";
7332 leency 63
	const char attempts_left[] = "Attempts left:";
64
	const char grass_left[]  = "Grass left:";
65
#endif
968 leency 66
 
7332 leency 67
int levelcount=7;
968 leency 68
 
7332 leency 69
char gamearea[20][20]; //The map
968 leency 70
 
7332 leency 71
 
72
short int kosilkax; // Kosilka position
968 leency 73
short int kosilkay;
7332 leency 74
short int kosilkadirection=1; //Last step direction. 1-bottom, 2-up, 3-left, 4-right
75
short int lives=2;
76
short int level=1;
77
short int status=0; //Where 0 - welcome screen
78
					// 1 - the game
79
					// 2 - win
80
					// 3 - fail
81
					// 4 - select the level (internal or external)
82
					// -1 - about
83
bool gamestarted=false; //Key locker. If "false" then not possible to play
968 leency 84
 
7332 leency 85
bool drawgraphics=true; //Draw detailed graphics or just colored rectangles
86
bool drawanimation=true;
87
int grassLeft();  //Notify about "Grass Left" function
968 leency 88
 
89
RGB kosilka_d[576];
90
RGB kosilka_l[576];
91
RGB kosilka_r[576];
92
RGB kosilka_u[576];
93
RGB grass[576];
94
RGB stone[576];
95
RGB tree[576];
96
RGB skos[576];
97
 
7332 leency 98
//Palette. Decoding to 0xRRGGBB
968 leency 99
char * apppath;
100
char * levpath;
101
 
102
 
103
char * getLevelsPathName(){
104
 
105
	int lastslashindex=0;
106
	static char levfilename[]="koslevel.pak";
107
	int tempslfnd=0;
108
 
109
	for (tempslfnd=0; tempslfnd < strlen(kosExePath); tempslfnd++){
110
			if (kosExePath[tempslfnd]=='/'){lastslashindex=tempslfnd;}
111
	}
112
 
113
	levpath = new char[lastslashindex+strlen(levfilename)+1];
114
 
115
	for (tempslfnd=0; tempslfnd <= lastslashindex; tempslfnd++){
116
		levpath[tempslfnd]=kosExePath[tempslfnd];
117
	}
118
	for (tempslfnd=0; tempslfnd < strlen(levfilename); tempslfnd++){
119
		levpath[tempslfnd+lastslashindex+1]=levfilename[tempslfnd];
120
	}
121
 
122
	return levpath;
123
}
124
 
125
 
7332 leency 126
void interlevelpause(){ //The pause between levels
968 leency 127
	Byte tempCode;
128
	RGB tmprgb;
129
	int tmpa=0;
130
	laststep=0;
131
	static int yellow_pal[] = {0xA8A93D,0xBEBF4C,0xD6D856,0xDFE15A,0xECEE5B,
132
						    0xECEE5B,0xDFE15A,0xD6D856,0xBEBF4C,0xA8A93D};
133
		for (int iic=0;iic<240;iic++){
3137 leency 134
			kos_WaitForEvent(1); //Pause()?
968 leency 135
			kos_GetKey(tempCode);
136
 
137
			kos_DrawBar(iic*2,0,2,480,yellow_pal[tmpa]);
138
 
139
			tmpa++;
3132 leency 140
			if (tmpa>9) tmpa=0;
968 leency 141
		}
142
}
143
 
7332 leency 144
void draw_element(int elx, int ely){ //Draw map element
968 leency 145
switch (gamearea[elx][ely]){
146
			case 'g':
147
				if (drawgraphics==true){
148
					kos_PutImage((RGB*)grass,24,24,elx*24,ely*24);
149
				}
150
				else
151
				{
152
					kos_DrawBar(elx*24,ely*24,24,24,0xAAAA00);
153
				}
154
 
155
				break;
156
			case 'k':
157
				if (drawgraphics==true){
158
					switch(kosilkadirection){
159
					case 1:
160
						kos_PutImage((RGB*)kosilka_d,24,24,elx*24,ely*24);
161
						break;
162
					case 2:
163
						kos_PutImage((RGB*)kosilka_u,24,24,elx*24,ely*24);
164
						break;
165
					case 3:
166
						kos_PutImage((RGB*)kosilka_l,24,24,elx*24,ely*24);
167
						break;
168
					case 4:
169
						kos_PutImage((RGB*)kosilka_r,24,24,elx*24,ely*24);
170
						break;
171
					}
172
				}
173
				else
174
				{
175
					kos_DrawBar(elx*24,ely*24,24,24,0x00AAAA);
176
				}
177
 
178
 
179
				break;
180
			case 'n':
181
				if (drawgraphics==true){
182
					kos_PutImage((RGB*)skos,24,24,elx*24,ely*24);
183
				}
184
				else
185
				{
186
					kos_DrawBar(elx*24,ely*24,24,24,0xAAAAAA);
187
				}
188
 
189
 
190
				break;
191
			case 's':
192
				if (drawgraphics==true){
193
					kos_PutImage((RGB*)stone,24,24,elx*24,ely*24);
194
				}
195
				else
196
				{
197
					kos_DrawBar(elx*24,ely*24,24,24,0x555555);
198
				}
199
 
200
 
201
				break;
202
 
203
			case 't':
204
				if (drawgraphics==true){
205
					kos_PutImage((RGB*)tree,24,24,elx*24,ely*24);
206
				}
207
				else
208
				{
209
					kos_DrawBar(elx*24,ely*24,24,24,0x005500);
210
				}
211
 
212
 
213
				break;
214
			}
215
 
216
}
217
 
218
 
7332 leency 219
void display_grass_left(){
968 leency 220
	kos_DrawBar(605,120,20,10,0xEEEEEE);
221
	kos_DisplayNumberToWindow(grassLeft(),3,605,120,0x0000FF,nbDecimal,false);
222
}
223
 
224
 
7332 leency 225
void animate(int initcellx, int initcelly, int direction){ //kosilka movement animation
968 leency 226
	int tmpp=0;
227
 
3132 leency 228
	switch (direction){
968 leency 229
		case 1:
230
			for (tmpp=0; tmpp<23;tmpp++){
231
				if (drawgraphics==true){
232
					kos_PutImage((RGB*)skos,24,24,initcellx*24,initcelly*24);
233
					kos_PutImage((RGB*)kosilka_d,24,24,initcellx*24,initcelly*24+tmpp);
234
				} else {
235
					kos_DrawBar(initcellx*24,initcelly*24,24,24,0xAAAAAA);
236
					kos_DrawBar(initcellx*24,initcelly*24+tmpp,24,24,0x00AAAA);
237