/
ingame.h
436 lines (282 loc) · 5.92 KB
/
ingame.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
#include <SDL/SDL.h>
#include <SDL/SDL_ttf.h>
#include <SDL/SDL_mixer.h>
#include <stdlib.h>
#include <math.h>
int GAME=1;
//FPS LIMIT
#define FPS_LIMIT 75
Uint32 then, now, frames;
int fps;
//END
/// STANDART VAR ////
float x;
float y;
float x2;
float y2;
#define velocity 3.5
float vel;
float vel2;
float vel3;
float vel4;
// ---- GAME KEYS -----//
int LEFT;
int RIGHT;
int UP;
int DOWN;
int FIRE;
int F;
int W;
//-----------------------------------------------//
typedef struct WiHi
{
SDL_Surface *tmp;
}
WH;
WH pic[1900];
// õðàíåíèå äàííûõ â ïåðåìåííûõ
typedef struct SiHi
{
Mix_Chunk *tmp;
}
SH;
SH sn[500];
// Õðàíåíèå ìóçûêè â ïåðåìåííûõ
typedef struct MiHi
{
Mix_Music *tmp;
}
MH;
MH mn[100];
SDL_Surface *display;
SDL_Event event;
Uint8* keys;
TTF_Font *fnt;
//-------------
typedef struct stars
{
float x;
float y;
float speed;
}
stars;
#define MAX_SPEED 6
#define MAX_STAR 30
//------
int box( int num, float x1, float y1, int num2, float x2, float y2)
{
int ycol=0;
int xcol=0;
if
((y1+pic[num].tmp->h>y2) && (y1<y2+pic[num2].tmp->h))
{
ycol=0;
}
else
{
ycol=1;
}
if
((x1+pic[num].tmp->w>x2) && (x1<x2+pic[num2].tmp->w))
{
xcol=0;
}
else
{
xcol=1;
}
if
(xcol || ycol)
return 0;
else
return 1;
}
void clear()
{
SDL_FillRect(display, NULL, SDL_MapRGB(display->format, 0, 0, 0));
}
void fx()
{
while (SDL_PollEvent(&event))
{
if (event.type==SDL_QUIT)
{
GAME=0;
SDL_Quit();
}
if (event.type==SDL_KEYDOWN)
{
if(event.key.keysym.sym==SDLK_ESCAPE)
{
GAME=0;
SDL_Quit();
}
}
}
keys=SDL_GetKeyState(NULL);
if(keys[SDLK_LEFT])
{
LEFT=1; vel=velocity;
}
else
LEFT=0;
if(keys[SDLK_RIGHT])
{
RIGHT=1;vel2=velocity;
}
else
RIGHT=0;
if(keys[SDLK_UP])
{
UP=1;vel3=velocity;
}
else
UP=0;
if(keys[SDLK_DOWN])
{
DOWN=1;vel4=velocity;
}
else
DOWN=0;
if(keys[SDLK_SPACE])
{
FIRE=1;
}
else
FIRE=0;
if(keys[SDLK_f])
{
F=1;
}
else
F=0;
if(keys[SDLK_w])
{
W=1;
}
else
W=0;
///VELOCITY
if (vel>0){vel=(float)(vel-0.1);}
if (vel<=0){vel=0;}
x=x-vel;
if (vel2>0){vel2=(float)(vel2-0.1);}
if (vel2<=0){vel2=0;}
x=x+vel2;
/////////////////
///VELOCITY2
if (vel3>0){vel3=(float)(vel3-0.1);}
if (vel3<=0){vel3=0;}
y=y-vel3;
if (vel4>0){vel4=(float)(vel4-0.1);}
if (vel4<=0){vel4=0;}
y=y+vel4;
//FPS LIMIT
++frames;
now = SDL_GetTicks();
if ( now > then ) {
fps= (int)((double)frames*1000)/(now-then);
}
if ( fps > FPS_LIMIT ) {SDL_Delay(1000/FPS_LIMIT);}
//mouse();
SDL_Flip(display);
clear();
}
void colorfon(int r,int g, int b) //0-255
{
SDL_FillRect(display, NULL, SDL_MapRGB(display->format,r , g, b));
}
void screen(int w, int h)
{
SDL_Init (SDL_INIT_VIDEO|SDL_INIT_TIMER| SDL_INIT_AUDIO);
/*#ifdef __linux__
putenv("SDL_VIDEODRIVER=dga");
#endif*/
// display = SDL_SetVideoMode (w, h, 0, SDL_SWSURFACE | SDL_DOUBLEBUF| SDL_ANYFORMAT);
display = SDL_SetVideoMode (w, h, 0, SDL_SWSURFACE | SDL_ANYFORMAT);
SDL_WM_SetCaption ("Linux GAMES", NULL);
TTF_Init();
fnt = TTF_OpenFont("font.ttf", 20);
//SOUND
Mix_OpenAudio (44100, MIX_DEFAULT_FORMAT, 2, 2024);
//for FPS limit
frames = 0;
then = SDL_GetTicks();
}
void screen(int w, int h, int full)
{
SDL_Init (SDL_INIT_VIDEO|SDL_INIT_TIMER| SDL_INIT_AUDIO);
// display = SDL_SetVideoMode (w, h, 0, SDL_HWSURFACE | SDL_DOUBLEBUF| SDL_ANYFORMAT|SDL_FULLSCREEN);
display = SDL_SetVideoMode (w, h, 0, SDL_SWSURFACE | SDL_ANYFORMAT|SDL_FULLSCREEN);
TTF_Init();
fnt = TTF_OpenFont("font.ttf", 20);
//SOUND
Mix_OpenAudio (44100, MIX_DEFAULT_FORMAT, 2, 2024);
//for FPS limit
frames = 0;
then = SDL_GetTicks();
}
void loadsprite(int num, char * name)
{
// pic[num].tmp=SDL_LoadBMP(name);
pic[num].tmp=SDL_DisplayFormat(SDL_LoadBMP(name));
}
void sprite(int num, float x, float y)
{
SDL_Rect shadow;
shadow.x=(Sint16)x;
shadow.y=(Sint16)y;
SDL_SetColorKey(pic[num].tmp,SDL_SRCCOLORKEY|SDL_RLEACCEL,SDL_MapRGB(pic[num].tmp->format,255,0,255));
SDL_BlitSurface(pic[num].tmp,0,display,&shadow);
}
void sprite(int num, float x, float y, unsigned int a)
{
SDL_Rect shadow;
shadow.x=(Sint16)x;
shadow.y=(Sint16)y;
SDL_SetColorKey(pic[num].tmp,SDL_SRCCOLORKEY|SDL_RLEACCEL,SDL_MapRGB(pic[num].tmp->format,255,0,255));
SDL_SetAlpha(pic[num].tmp, SDL_SRCALPHA|SDL_RLEACCEL,a);
SDL_BlitSurface(pic[num].tmp,0,display,&shadow);
}
void print (char * txt, float x, float y)
{
SDL_Color color = {255,255,255,0};
SDL_Rect dest= {(Sint16)x, (Sint16)y,0,0};
pic[1000].tmp = TTF_RenderText_Blended( fnt, txt, color);
SDL_BlitSurface( pic[1000].tmp,NULL, display,&dest );
SDL_FreeSurface( pic[1000].tmp );
}
void print (int txt, float x, float y)
{
SDL_Color color = {255,255,255,0};
SDL_Rect dest= {(Sint16)x, (Sint16)y,0,0};
char tmp[25];
sprintf(tmp,"%i",txt);
pic[1001].tmp = TTF_RenderText_Blended(fnt, tmp, color);
SDL_BlitSurface( pic[1001].tmp,NULL, display,&dest );
SDL_FreeSurface( pic[1001].tmp );
}
void mouseview(int i)
{
SDL_ShowCursor(i);
}
void loadsound(char * name, int num)
{
sn[num].tmp = Mix_LoadWAV (name);
}
void sound (int num)
{
Mix_PlayChannel (-1, sn[num].tmp, 0);
}
void loadmusic(char * name, int num)
{
mn[num].tmp = Mix_LoadMUS (name);
}
void music(int num)
{
Mix_PlayMusic (mn[num].tmp, -1);
}
void stopmusic()
{
Mix_FadeOutMusic(1000);
}