Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1805 yogev_ezra 1
/* Rocket Forces
2
 * Filename: objects.h
3
 * Version 0.1
4
 * Copyright (c) Serial 2007
5
 */
6
 
7
 
8
void ppx(int x, int y, int color);
9
void pline(int x1, int y1, int x2, int y2, int color);
10
void draw4(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, int color);
11
 
12
 
13
class cBuilding
14
{
15
public:
16
	void Draw(int x, int y, int color)
17
	{
18
		draw4(x, y, x+10, y-5, x+20, y, x, y, color);
19
		draw4(x, y, x+20, y, x+20, y+11, x, y+11, color);
20
		draw4(x+3, y+3, x+8, y+3, x+8, y+8, x+3, y+8, color);
21
		draw4(x+15, y+3, x+20, y+3, x+20, y+11, x+15, y+11, color);
22
	}
23
};
24
 
25
class cCursor
26
{
27
public:
28
	cCursor()
29
	{
30
		cx = -1;
31
		cy = -1;
32
	}
33
	void Delete(int color)
34
	{
35
		ppx(cx, cy, color);
36
 
37
		ppx(cx-3, cy, color);
38
		ppx(cx-4, cy, color);
39
		ppx(cx-5, cy, color);
40
		ppx(cx, cy-3, color);
41
		ppx(cx, cy-4, color);
42
		ppx(cx, cy-5, color);
43
		ppx(cx-1, cy-3, color);
44
		ppx(cx-2, cy-3, color);
45
		ppx(cx-3, cy-3, color);
46
		ppx(cx-3, cy-2, color);
47
		ppx(cx-3, cy-1, color);
48
		ppx(cx+1, cy-3, color);
49
 
50
		ppx(cx+3, cy, color);
51
		ppx(cx+4, cy, color);
52
		ppx(cx+5, cy, color);
53
		ppx(cx, cy+3, color);
54
		ppx(cx, cy+4, color);
55
		ppx(cx, cy+5, color);
56
		ppx(cx+1, cy+3, color);
57
		ppx(cx+2, cy+3, color);
58
		ppx(cx+3, cy+3, color);
59
		ppx(cx+3, cy+2, color);
60
		ppx(cx+3, cy+1, color);
61
		ppx(cx+1, cy-3, color);
62
		ppx(cx-1, cy+3, color);
63
	}
64
	void Draw(int x, int y, int color)
65
	{
66
		if (cx!=x || cy!=y)
67
		{
68
			Delete(BG_COLOR);
69
			cx = x;
70
			cy = y;
71
			ppx(cx, cy, color);
72
 
73
			ppx(cx-3, cy, color);
74
			ppx(cx-4, cy, color);
75
			ppx(cx-5, cy, color);
76
			ppx(cx, cy-3, color);
77
			ppx(cx, cy-4, color);
78
			ppx(cx, cy-5, color);
79
			ppx(cx-1, cy-3, color);
80
			ppx(cx-2, cy-3, color);
81
			//ppx(cx-3, cy-3, color);
82
			ppx(cx-3, cy-2, color);
83
			ppx(cx-3, cy-1, color);
84
			ppx(cx+1, cy-3, color);
85
 
86
			ppx(cx+3, cy, color);
87
			ppx(cx+4, cy, color);
88
			ppx(cx+5, cy, color);
89
			ppx(cx, cy+3, color);
90
			ppx(cx, cy+4, color);
91
			ppx(cx, cy+5, color);
92
			ppx(cx+1, cy+3, color);
93
			ppx(cx+2, cy+3, color);
94
			//ppx(cx+3, cy+3, color);
95
			ppx(cx+3, cy+2, color);
96
			ppx(cx+3, cy+1, color);
97
			ppx(cx+1, cy-3, color);
98
			ppx(cx-1, cy+3, color);
99
		}
100
	}
101
private:
102
	int cx, cy;
103
};
104
 
105
class cExplode
106
{
107
public:
108
	cExplode()
109
	{
110
		cx = -1;
111
		cy = -1;
112
	}
113
	void Enable(int cx, int cy)
114
	{
115
		step = 1;
116
		cExplode::cx = cx;
117
		cExplode::cy = cy;
118
	}
119
	int IsEnabled(void)
120
	{
121
		if (cx==-1 && cy==-1)
122
		{
123
			return 0;
124
		}
125
		else
126
		{
127
			return 1;
128
		}
129
	}
130
	void Draw(int r, int color)
131
	{
132
		int d=3-2*r, x=-1, y=r;
133
		while (x++
134
		{
135
			ppx(cx+x, cy+y, color);
136
			ppx(cx+x, cy-y, color);
137
			ppx(cx-x, cy+y, color);
138
			ppx(cx-x, cy-y, color);
139
			ppx(cx+y, cy+x, color);
140
			ppx(cx+y, cy-x, color);
141
			ppx(cx-y, cy+x, color);
142
			ppx(cx-y, cy-x, color);
143
			if (d<0)
144
			{
145
				d += 4*x+6;
146
			}
147
			else
148
			{
149
				d += 4*(x-y)+10;
150
				y--;
151
			}
152
		}
153
	}
154
	void DrawNext(int color)
155
	{
156
		if (step>=EXP_RAD)
157
		{
158
			Disable(BG_COLOR);
159
		}
160
		else
161
		{
162
			Draw(step, BG_COLOR);
163
			Draw(++step, color);
164
		}
165
	}
166
	void Disable(int color)
167
	{
168
		Draw(step, color);
169
		cx = -1;
170
		cy = -1;
171
	}
172
	int cx, cy;
173
	int step;
174
};
175
 
176
class cRocket
177
{
178
public:
179
	cRocket()
180
	{
181
		cx = -1;
182
		cy = -1;
183
	}
184
	void Enable(int x, int y, int width, int height, int cx, int cy)
185
	{
186
		coord[0][0] = x;
187
		coord[0][1] = y;
188
		coord[1][0] = x+width;
189
		coord[1][1] = y;
190
		coord[2][0] = x+width;
191
		coord[2][1] = y+height;
192
		coord[3][0] = x;
193
		coord[3][1] = y+height;
194
		cRocket::cx = cx;
195
		cRocket::cy = cy;
196
		for (int j=0; j<4; j++)
197
		{
198
			dist[j] = sqrt((double)((coord[j][0]-cx)*(coord[j][0]-cx)+(coord[j][1]-cy)*(coord[j][1]-cy)));
199
			fi[j] = acos((coord[j][0]-cx)/dist[j]);
200
			if (coord[j][1]
201
			fire[j][0] = -1;
202
			fire[j][1] = -1;
203
		}
204
	}
205
	int IsEnabled(void)
206
	{
207
		if (cx==-1 && cy==-1)
208
		{
209
			return 0;
210
		}
211
		else
212
		{
213
			return 1;
214
		}
215
	}
216
	void Draw(int color)
217
	{
218
		draw4(coord[0][0], coord[0][1], coord[1][0], coord[1][1], coord[2][0], coord[2][1], coord[3][0], coord[3][1], color);
219
		if (fire[3][0]!=-1 || fire[3][1]!=-1)
220
		{
221
			ppx(fire[3][0], fire[3][1], BG_COLOR);
222
		}
223
	}
224
	void DrawAngle(int mx, int my, int color)
225
	{
226
		// Delete old rectangle
227
		Draw(BG_COLOR);
228
 
229
		// Draw new rectangle
230
		double a;
231
		long int dx = (long int) (cx-mx)*(cx-mx);
232
		long int dy = (long int) (cy-my)*(cy-my);
233
		if (cx!=mx || cy!=my)
234
		{
235
			a = -M_PI/2+acos((cx-mx)/sqrt((double)(dx+dy)));
236
			for (int j=0; j<4; j++)
237
			{
238
				coord[j][0] = round_int((double)(cx+dist[j]*cos(a+fi[j])));
239
				coord[j][1] = round_int((double)(cy+dist[j]*sin(a+fi[j])));
240
			}
241
		}
242
		draw4(coord[0][0], coord[0][1], coord[1][0], coord[1][1], coord[2][0], coord[2][1], coord[3][0], coord[3][1], color);
243
		for (int i=3; i>0; i--)
244
		{
245
			fire[i][0] = fire[i-1][0];
246
			fire[i][1] = fire[i-1][1];
247
		}
248
		fire[0][0] = cx;
249
		fire[0][1] = cy;
250
		for (int i=1; i<4; i++)
251
		{
252
			if (fire[i][0]!=-1 || fire[i][1]!=-1) ppx(fire[i][0], fire[i][1], SMOKE_COLOR);
253
		}
254
	}
255
	void Disable(int color)
256
	{
257
		for (int i=0; i<4; i++)
258
		{
259
			ppx(fire[i][0], fire[i][1], color);
260
			fire[i][0] = 0;
261
			fire[i][1] = 0;
262
		}
263
		Draw(color);
264
		cx = -1;
265
		cy = -1;
266
	}
267
	int cx, cy;
268
	protected:
269
	int coord[4][2];
270
	double dist[4];
271
	double fi[4];
272
	int fire[4][2];
273
};
274
 
275
class cBomb: public cRocket
276
{
277
public:
278
	void Draw(int color)
279
	{
280
		draw4(coord[0][0], coord[0][1], coord[1][0], coord[1][1], coord[2][0], coord[2][1], coord[3][0], coord[3][1], color);
281
		ppx(cx-1, coord[2][1]+1, color);
282
		ppx(cx, coord[2][1]+1, color);
283
		ppx(cx+1, coord[2][1]+1, color);
284
		for (int i=1; i<4; i++)
285
		{
286
			if (fire[i][0]!=-1 || fire[i][1]!=-1)
287
			{
288
				if (i==1)
289
				{
290
					ppx(fire[i][0]-1, fire[i][1], BG_COLOR);
291
					ppx(fire[i][0]+1, fire[i][1], BG_COLOR);
292
				}
293
				else
294
				{
295
					ppx(fire[i][0], fire[i][1], BG_COLOR);
296
				}
297
			}
298
		}
299
	}
300
	void DrawAngle(int mx, int my, int color)
301
	{
302
		// Delete old rectangle
303
		Draw(BG_COLOR);
304
 
305
		// Draw new rectangle
306
		for (int j=0; j<4; j++)
307
		{
308
			coord[j][1] += B_SPEED;
309
		}
310
		draw4(coord[0][0], coord[0][1], coord[1][0], coord[1][1], coord[2][0], coord[2][1], coord[3][0], coord[3][1], color);
311
		ppx(cx-1, coord[2][1]+1, color);
312
		ppx(cx, coord[2][1]+1, color);
313
		ppx(cx+1, coord[2][1]+1, color);
314
		for (int i=3; i>0; i--)
315
		{
316
			fire[i][0] = fire[i-1][0];
317
			fire[i][1] = fire[i-1][1];
318
		}
319
		fire[0][0] = cx;
320
		fire[0][1] = cy;
321
		for (int i=1; i<4; i++)
322
		{
323
			if (fire[i][0]!=-1 || fire[i][1]!=-1)
324
			{
325
				if (i==1)
326
				{
327
					ppx(fire[i][0]-1, fire[i][1], SMOKE_COLOR);
328
					ppx(fire[i][0]+1, fire[i][1], SMOKE_COLOR);
329
				}
330
				else
331
				{
332
					ppx(fire[i][0], fire[i][1], SMOKE_COLOR);
333
				}
334
			}
335
		}
336
	}
337
	void Disable(int color)
338
	{
339
		for (int i=0; i<4; i++)
340
		{
341
			ppx(fire[i][0], fire[i][1], color);
342
			fire[i][0] = 0;
343
			fire[i][1] = 0;
344
		}
345
		Draw(color);
346
		cx = -1;
347
		cy = -1;
348
	}
349
};
350
 
351
class cGun: public cRocket
352
{
353
public:
354
	void Enable(int x, int y, int width, int height, int cx, int cy)
355
	{
356
		old_mx = -1;
357
		old_my = -1;
358
		coord[0][0] = x;
359
		coord[0][1] = y;
360
		coord[1][0] = x+width;
361
		coord[1][1] = y;
362
		coord[2][0] = x+width;
363
		coord[2][1] = y+height;
364
		coord[3][0] = x;
365
		coord[3][1] = y+height;
366
		cRocket::cx = cx;
367
		cRocket::cy = cy;
368
		for (int j=0; j<4; j++)
369
		{
370
			dist[j] = sqrt((double)((coord[j][0]-cx)*(coord[j][0]-cx)+(coord[j][1]-cy)*(coord[j][1]-cy)));
371
			fi[j] = acos((coord[j][0]-cx)/dist[j]);
372
			if (coord[j][1]
373
		}
374
	}
375
	void DrawAngle(int mx, int my, int color)
376
	{
377
		if (old_mx!=mx || old_my!=my)
378
		{
379
			// Delete old rectangle
380
			old_mx = mx;
381
			old_my = my;
382
			Draw(BG_COLOR);
383
 
384
			// Draw new rectangle
385
			double a;
386
			long int dx = (long int)(cx-mx)*(cx-mx);
387
			long int dy = (long int)(cy-my)*(cy-my);
388
			if (my<=cy && (cx!=mx || cy!=my))
389
			{
390
				a = -M_PI/2+acos((cx-mx)/sqrt((double)(dx+dy)));
391
				for (int j=0; j<4; j++)
392
				{
393
					coord[j][0] = round_int((double)(cx+dist[j]*cos(a+fi[j])));
394
					coord[j][1] = round_int((double)(cy+dist[j]*sin(a+fi[j])));
395
				}
396
			}
397
			draw4(coord[0][0], coord[0][1], coord[1][0], coord[1][1], coord[2][0], coord[2][1], coord[3][0], coord[3][1], color);
398
			draw4(cx-14, cy+2, cx+14, cy+2, cx+14, cy+18, cx-14, cy+18, color);
399
		}
400
	}
401
protected:
402
	int old_mx, old_my;
403
};
404
 
405
class cCross
406
{
407
public:
408
	cCross()
409
	{
410
		x = -1;
411
		y = -1;
412
	}
413
	void Enable(int x, int y)
414
	{
415
		cCross::x = x;
416
		cCross::y = y;
417
		size = 2;
418
	}
419
	int IsEnabled(void)
420
	{
421
		if (x == -1 && y == -1)
422
		{
423
			return 0;
424
		}
425
		else
426
		{
427
			return 1;
428
		}
429
	}
430
	void Draw(int color)
431
	{
432
		pline(x-size, y, x+size, y, color);
433
		pline(x, y-size, x, y+size, color);
434
		ppx(x, y, BG_COLOR);
435
	}
436
	void Disable(int color)
437
	{
438
		pline(x-size, y, x+size, y, color);
439
		pline(x, y-size, x, y+size, color);
440
		x = -1;
441
		y = -1;
442
	}
443
	int x, y;
444
protected:
445
	int size;
446
};
447
 
448
 
449
void ppx(int x, int y, int color)
450
{
451
	if (x >= 0 && x < WINDOW_WIDTH &&  y >= 0 && y < WINDOW_HEIGHT) kos_PutPixel(x, y, color);
452
}
453
 
454
void pline(int x1, int y1, int x2, int y2, int color)
455
{
456
	kos_DrawLine(x1, y1, x2, y2, color);
457
}
458
 
459
 
460
void draw4(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, int color)
461
{
462
	pline(x1, y1, x2, y2, color);
463
	pline(x2, y2, x3, y3, color);
464
	pline(x3, y3, x4, y4, color);
465
	pline(x4, y4, x1, y1, color);
466
}