+7(960) 250-82-68 spam@mirossa.ru


  MCU         C           1С         PHP       JAVA      разное 


Статьи
 
 

2D игра Бластероиды. Allegro 5.0

printScreenGame

Настройка CMAKE
The option `SHARED` controls whether libraries are built as shared libraries
or static libraries. Shared libraries are built by default.

CMD
/build> make.exe
/build> make.exe install


silver_font.tga

blasteroids.exe

файл blasteroids.c

//компиляция:
//cd "C:\Program Files (x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin"
// console + window
//i686-w64-mingw32-gcc-8.1.0.exe blasteroids.c -L"C:\allegro_5_0_11_Sborka\build\lib" -lallegro.dll 
   //-lallegro_primitives.dll -lallegro_font.dll -lallegro_image.dll -o blasteroids.exe

// window
//i686-w64-mingw32-gcc-8.1.0.exe blasteroids.c -L"C:\allegro_5_0_11_Sborka\build\lib" -lallegro.dll 
   //-lallegro_primitives.dll -lallegro_font.dll -lallegro_image.dll -o blasteroidsW.exe -mwindows

// console + window
//err    //i686-w64-mingw32-gcc-8.1.0.exe blasteroids.c -L"C:\allegro_5_0_11_Sborka\build2\lib" 
//-lallegro-static -lallegro_primitives-static -lallegro_font-static -lallegro_image-static -o blasteroids.exe
			

// http://masandilov.ru/snippets/directx9_allegro      как использовать winMain()
// https://wiki.allegro.cc/index.php?title=Tilemap_Example
// https://wiki.allegro.cc/index.php?title=Basic_Keyboard_Example


////////////////////////////////////////////////////////////////////////////////////
// https://www.allegro.cc/forums/thread/617174 :

// // Here is the full list of static libraries to link to when on Windows :

// // -static -ljpeg -ldumb -lFLAC -lfreetype -lvorbisfile -lvorbis -logg -lphysfs -lpng16 -lzlibstatic -ldsound 
// //   -lgdiplus -luuid -lkernel32 -lwinmm -lpsapi -lopengl32 -lglu32 -luser32 -lcomdlg32 -lgdi32 -lshell32 
// //   -lole32 -ladvapi32 -lws2_32 -lshlwapi -static-libstdc++ -static-libgcc

// // This tells the linker to static link all of the following libraries :

// // -static

// // These are the optional dependencies you compiled support for when building allegro (omit any you didn't build support for) :

// // -ljpeg
// // -ldumb
// // -lFLAC
// // -lfreetype
// // -lvorbisfile
// // -lvorbis
// // -logg
// // -lphysfs
// // -lpng16
// // -lzlibstatic

// // These are the Windows libraries. You must link all of these.

// // -ldsound
// // -lgdiplus
// // -luuid
// // -lkernel32
// // -lwinmm
// // -lpsapi
// // -lopengl32
// // -lglu32
// // -luser32
// // -lcomdlg32
// // -lgdi32
// // -lshell32
// // -lole32
// // -ladvapi32
// // -lws2_32
// // -lshlwapi

// // And last but not least, the C Run Time libraries :

// // -static-libstdc++
// // -static-libgcc
////////////////////////////////////////////////////////////////////////////////////



// Install Allegro 5.2.4.1 on Win10
// https://www.allegro.cc/forums/thread/617338

#include <allegro5/allegro.h>
#include <allegro5/allegro_primitives.h>
#include <allegro5\allegro_image.h>
#include <allegro5/allegro_font.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h> 

typedef struct {
		float sx;
		float sy;
		float ungle;
		float speed;
		float scale;
		int gone;
		ALLEGRO_COLOR color;
	} Blast;
	
	
	float s = 0.0f; //
	
// астероид
typedef struct Asteroid {
	float sx;
	float sy;
	float ungle;
	float speed;
	float scale;
	int gone;
	int split;
	ALLEGRO_COLOR color;
	struct Asteroid * next;
} Asteroid;

// звездолет
typedef struct LEXX {
	float sx;
	float sy;
	float ungle;
	float scale;
	int gone;
	ALLEGRO_COLOR color;
} LEXX;

	float w, h;
	
	LEXX Lexx;
	LEXX * Lexx1 = &Lexx;
void initLexx(LEXX * lxx){
	
	lxx->sx = w * 0.5;
	lxx->sy = h * 0.8;
	lxx->ungle = 0.0;
	lxx->scale = 2;
	lxx->gone = 0;
}
	
	float Xa;
	long int ttime;
	
void initBlast(Blast * bl, LEXX * Lxx){
	
	bl->sx = Lxx->sx; // w * 0.5;
	bl->sy = Lxx->sy; // h * 0.8;
	bl->gone = 0;
	bl->ungle = Lxx->ungle;
	bl->scale = 2;
}

	Asteroid * StartAsteroid = NULL;
	Asteroid * NextAsteroid = NULL;
	Asteroid * PrevAsteroid = NULL;
	Asteroid * EndAsteroid = NULL;
	Asteroid * i;
	
void delAllAsteroids(){
	
	i = StartAsteroid;
		for(; i != NULL; ){
			NextAsteroid = i->next;
			free(i);
			i = NextAsteroid;
		}
	StartAsteroid = NULL;	
}
	
Blast * blX;

const float FPS = 60;

   
int main(int argc, char *argv[])
{
	
	ALLEGRO_DISPLAY *display = NULL;
	ALLEGRO_EVENT_QUEUE *event_queue = NULL;
	ALLEGRO_TIMER *timer = NULL;

	bool running = true;
	bool redraw = true;
	
	int cc;
	long int Total = 0;
	char TotalT[11];
	
	// Initialize allegro
	if (!al_init()) {
		fprintf(stderr, "Failed to initialize allegro.\n");
		return 1;
	}

	if(!al_install_keyboard()) {
      fprintf(stderr, "failed to initialize the keyboard!\n");
      return 1;
   }
   
	// Initialize the timer
	timer = al_create_timer(1.0 / FPS);
	if (!timer) {
		fprintf(stderr, "Failed to create timer.\n");
		return 1;
	}

	float imTimerAsteroid; //счетчик для задержки создания астероидов
	int TimerContinue = 0; //обход imTimerAsteroid
	
	if(!al_init_primitives_addon()){                                //дл¤ корректной работы al_draw_line()
        fprintf(stderr, "Failed to init primitives_addon.\n");
		return 1;
    }
	
	/// Set up a fullscreen display using the desktop width and height 
	int nva = al_get_num_video_adapters(); 
	if (nva < 1) {
		fprintf(stderr, "Failed of get num video adapters.\n");
		return 1; 
	}
	
	ALLEGRO_MONITOR_INFO aminfo; 
	al_get_monitor_info(0 , &aminfo);
	int desktop_width = aminfo.x2 - aminfo.x1 + 1; 
	int desktop_height = aminfo.y2 - aminfo.y1 + 1;
	
	//временно
	// desktop_width = 640; 
	// desktop_height = 480;
	
	
	// Create the display
	//display = al_create_display(640, 480);
	display = al_create_display(desktop_width, desktop_height);
	if (!display) {
		fprintf(stderr, "Failed to create display.\n");
		return 1;
	}

	// Create the event queue
	event_queue = al_create_event_queue();
	if (!event_queue) {
		fprintf(stderr, "Failed to create event queue.");
		return 1;
	}

	// Register event sources, будем получать события следующих типов
	 al_register_event_source(event_queue, al_get_display_event_source(display));
	 al_register_event_source(event_queue, al_get_timer_event_source(timer));
	 al_register_event_source(event_queue, al_get_keyboard_event_source());   //добавляем события клавиатуры

	// Display a black screen
	al_clear_to_color(al_map_rgb(0, 140, 0)); //зелЄный экран
	
	w = al_get_display_width(display);
    h = al_get_display_height(display);
	
	if(!al_init_image_addon()){                           // BMP, PCX, TGA; для PNG нужно что-то ещ�'
		fprintf(stderr, "Failed of init_image_addon.\n");
		return 1; 
	}
	
    // al_init_acodec_addon();
	
	al_init_font_addon();
	
	//al_init_ttf_addon();   //тут проблема , нет lib
	ALLEGRO_BITMAP * bmp;
	ALLEGRO_PATH *path;
	path = al_get_standard_path(ALLEGRO_EXENAME_PATH);
    //al_append_path_component(path, "resources");
    al_set_path_filename(path, "silver_font.tga");
//printf("\n%s\n", al_path_cstr(path, '\\'));	

    //в этом файле глифы - белые на прозрачном фоне(в Paint не видно, в браузере видно) http://wiki.mrhide.fr/doku.php?id=allegro:addon_fonts
	bmp = al_load_bitmap(al_path_cstr(path, '\\')); 
	if (bmp == NULL)
			printf("Error bmp");
	ALLEGRO_FONT * font1;
	ALLEGRO_FONT * font2;
	
	//int ranges[] = {32, 126};
	int ranges[] = {' ', '~'};
	font1 = al_grab_font_from_bitmap(bmp, 1, ranges); //   https://www.allegro.cc/manual/5/al_grab_font_from_bitmap
	
	//font1 = al_load_font("times.ttf", 48, 0);
	font2 = al_create_builtin_font();
	if(font1 == NULL)
		printf("Error of get font");
	
	ALLEGRO_TRANSFORM transform;
	
	initLexx(Lexx1);
	
	// al_identity_transform(&transform);
	// al_translate_transform(&transform, w * 0.5, h * 0.8);
	// al_use_transform(&transform);

	// al_draw_line(-8, 9, 0, -11, al_map_rgb(0, 0, 0), 3.0f); // лини¤
	// al_draw_line(0, -11, 8, 9, al_map_rgb(0, 0, 0), 3.0f); 
	// al_draw_line(-6, 4, -1, 4, al_map_rgb(0, 0, 0), 3.0f);
	// al_draw_line(6, 4, 1, 4, al_map_rgb(0, 0, 0), 3.0f);
	
	// al_draw_line(12, 29, 20, 9, al_map_rgb(0, 0, 0), 3.0f); // лини¤
	// al_draw_line(20, 9, 28, 29, al_map_rgb(0, 0, 0), 3.0f); 
	// al_draw_line(14, 24, 19, 24, al_map_rgb(0, 0, 0), 3.0f);
	// al_draw_line(26, 24, 21, 24, al_map_rgb(0, 0, 0), 3.0f);
	
	al_flip_display();

	// Start the timer
	al_start_timer(timer);

		
	//выстрелы. 15 статических
	
	int maxBlast = 14;
	
	Blast blast0, blast1, blast2, blast3, blast4, blast5, blast6, blast7, blast8, blast9, blast10, blast11, blast12, blast13, blast14;
	Blast * arrBlast[maxBlast + 1];
	arrBlast[0] = &blast0;
	arrBlast[1] = &blast1;
	arrBlast[2] = &blast2;
	arrBlast[3] = &blast3;
	arrBlast[4] = &blast4;
	arrBlast[5] = &blast5;
	arrBlast[6] = &blast6;
	arrBlast[7] = &blast7;
	arrBlast[8] = &blast8;
	arrBlast[9] = &blast9;
	arrBlast[10] = &blast10;
	arrBlast[11] = &blast11;
	arrBlast[12] = &blast12;
	arrBlast[13] = &blast13;
	arrBlast[14] = &blast14;
	
	blast0.gone = 1; blast1.gone = 1; blast2.gone = 1; blast3.gone = 1; blast4.gone = 1; blast5.gone = 1; blast6.gone = 1;
	blast7.gone = 1; blast8.gone = 1; blast9.gone = 1;
	blast10.gone = 1; blast11.gone = 1; blast12.gone = 1; blast13.gone = 1; blast14.gone = 1;
	
	int indexBlast = maxBlast;
	
	// blast1.sx = 0.0;
	// blast1.sy = 0.0;
	// blast1.gone = 1;
	
	int currscale;
	
	int PAUSE = 1;
	int gameOver = 0;
	
	srand(time(NULL));
	Xa = rand();
	
	// Game loop
	while (running) {
		ALLEGRO_EVENT event;
		// ALLEGRO_TIMEOUT timeout;

		// // Initialize timeout
		// al_init_timeout(&timeout, 0.06);

		// // Fetch the event (if one exists)
		// bool get_event = al_wait_for_event_until(event_queue, &event, &timeout);
		
		al_wait_for_event(event_queue, &event);

		// Handle the event
		//if (get_event) {
			switch (event.type) {
				case ALLEGRO_EVENT_TIMER:     // https://wiki.allegro.cc/index.php?title=Basic_Keyboard_Example
					if(PAUSE == 0)
						redraw = true;
					//printf("timer");
					break;
				case ALLEGRO_EVENT_DISPLAY_CLOSE:
					running = false;
					break;
				case ALLEGRO_EVENT_KEY_CHAR:    //ALLEGRO_EVENT_KEY_DOWN:
						//printf("down");
							switch(event.keyboard.keycode){
								
								case ALLEGRO_KEY_LEFT:
									//printf("left");
									if(PAUSE == 0)
										Lexx1->ungle -= 0.1;
									break;
								case ALLEGRO_KEY_RIGHT:
									//printf("right");
									if(PAUSE == 0)
										Lexx1->ungle += 0.1;
									break;
								case ALLEGRO_KEY_UP:   //движение звездол�'та с учетом угла
									//printf("\nALLEGRO_KEY_UP\n");
									//Lexx1->sy -= 4.0;
									if(PAUSE == 0){
										Lexx1->sy -= 5.0 * sinf(Lexx1->ungle + 1.5708); // a = c * sin(A)
										Lexx1->sx -= 5.0 * cosf(Lexx1->ungle + 1.5708);
									}
									break;
									// https://liballeg.org/a5docs/trunk/keyboard.html#key-codes
								case ALLEGRO_KEY_PAUSE: 
									//printf("\nALLEGRO_KEY_PAUSE\n");
									
									if(PAUSE == 0)
										PAUSE = 1;
									// else
										// if(!gameOver)
											// PAUSE = 0;
									
									break;
								case ALLEGRO_KEY_ESCAPE:
									
									running = false;
								
									break;
								case ALLEGRO_KEY_ENTER:
									
									if(gameOver){
										initLexx(Lexx1);
										PAUSE = 0;
										gameOver = 0;
										delAllAsteroids();
										Total = 0;
									}else 
										if(PAUSE)
											PAUSE = 0;
									
									break;
								// case ALLEGRO_KEY_SPACE: //выстрелы
									// //printf("space");
									// // blast1.gone = 0;
									// if(PAUSE == 0){
										// if(indexBlast == maxBlast)
											// indexBlast = 0;
										// else
											// indexBlast += 1;
										
										// initBlast(arrBlast[indexBlast], Lexx1);
									// }
									// break;
							}	
						
					break;
				case ALLEGRO_EVENT_KEY_DOWN:
							switch(event.keyboard.keycode){
								case ALLEGRO_KEY_SPACE: //выстрелы
									//printf("space");
									// blast1.gone = 0;
									if(PAUSE == 0){
										if(indexBlast == maxBlast)
											indexBlast = 0;
										else
											indexBlast += 1;
										
										initBlast(arrBlast[indexBlast], Lexx1);
									}
									break;
							}
							
					break;
				default:   //остальные события
					// if(PAUSE == 0)
						// fprintf(stderr, "Unsupported event received: %d\n", event.type);
					break;
			}
		//}

		// Check if we need to redraw
		if (redraw && al_is_event_queue_empty(event_queue)) {
			// Redraw
			al_clear_to_color(al_map_rgb(0, 140, 0)); //зелЄный экран
			
			//отображаем космический корабль
			
			al_identity_transform(&transform);
			al_rotate_transform(&transform, Lexx1->ungle);
			al_scale_transform(&transform, Lexx1->scale, Lexx1->scale);   //масштаб (в большую и меньшую сторону) по оси X и Y отдельно.
			al_translate_transform(&transform, Lexx1->sx, Lexx1->sy);
			al_use_transform(&transform);

			al_draw_line(-8, 9, 0, -11, al_map_rgb(0, 0, 0), 3.0f); // лини¤
			al_draw_line(0, -11, 8, 9, al_map_rgb(0, 0, 0), 3.0f); 
			al_draw_line(-6, 4, -1, 4, al_map_rgb(0, 0, 0), 3.0f);
			al_draw_line(6, 4, 1, 4, al_map_rgb(0, 0, 0), 3.0f);
			// al_draw_line(12, 29, 20, 9, al_map_rgb(0, 0, 0), 3.0f); // лини¤
			// al_draw_line(20, 9, 28, 29, al_map_rgb(0, 0, 0), 3.0f); 
			// al_draw_line(14, 24, 19, 24, al_map_rgb(0, 0, 0), 3.0f);
			// al_draw_line(26, 24, 21, 24, al_map_rgb(0, 0, 0), 3.0f);
			
			
			//обработка попадания "пули" в астероид
			
			for(cc = 0; cc < maxBlast + 1; cc += 1){
				
				blX = arrBlast[cc];
				if( blX->gone == 0 ){
					
					
					i = StartAsteroid;
					//PrevAsteroid = NULL;
					
					for(; i != NULL; ){
						
						//fprintf(stdout, "%f - %f - %f - %f\n", blX->sx + w * 0.5, i->sx, blX->sy + h * 0.8, i->sy);
						s = sqrtf( powf(blX->sx - i->sx, 2) + powf(blX->sy + - i->sy, 2));
						//fprintf(stdout, "s = %f\n", s);
						
						if(i->scale == 2)
							currscale = 2;
						else
							currscale = 1;
						
						if( currscale == 1 && s < 20){
								//fprintf(stdout, "you hit the asteroid\n");
								blX->gone = 1;
								i->gone = 1;
								Total += 100;
								
								i = i->next;
								
						}else if ( currscale == 2 && s < 40){
								//fprintf(stdout, "you hit the asteroid\n");
								blX->gone = 1;

					//в секции создания астероидов будет i->gone = 1, в секции удаления астероидов - free(i)
								i-> split = 1;
								TimerContinue = 1;

								Total += 100;
								
								i = i->next;
						}else
							
							i = i->next;
						
					}
				}
					
			}
			
			
			
			//двигаем "пули"
			for(cc = 0; cc < maxBlast + 1; cc += 1){
				
				blX = arrBlast[cc];
				if( blX->gone == 0 ){
					
					al_identity_transform(&transform);
					al_rotate_transform(&transform, blX->ungle);
					//масштаб (в большую и меньшую сторону) по оси X и Y отдельно.
					al_scale_transform(&transform, blX->scale, blX->scale); 
					al_translate_transform(&transform, blX->sx, blX->sy);
					al_use_transform(&transform);
//fprintf(stdout, "Create Blast ");			
					al_draw_line(0, 10, 0, 0, al_map_rgb(0, 0, 0), 3.0f);
					
					blX->sy -= 6.0 * sinf(blX->ungle + 1.5708); // a = c * sin(A)
					blX->sx -= 6.0 * cosf(blX->ungle + 1.5708);
					
					if (blX->sy < 10 / blX->scale){
						blX->gone = 1;
					}
					
				}	
			}
			
			
			//созда�'м астероиды после попадания в астероид
			if(TimerContinue == 1){

				TimerContinue = 0;
				
					i = StartAsteroid;
					PrevAsteroid = NULL; // начало цепочки астероидов, созданных при делении астероидов при попадании
					EndAsteroid = NULL;
					NextAsteroid = NULL;
						
						for(; ; ){
							
							if(i->split == 1){

								i->gone = 1; //чтобы удалить его в секции удаления астероидов
									
									if (PrevAsteroid == NULL){
										PrevAsteroid = malloc(sizeof(Asteroid));
										PrevAsteroid-> gone = 0;
										PrevAsteroid-> split = 0;
										PrevAsteroid-> scale = 1;
										PrevAsteroid-> ungle = 0.0;
										PrevAsteroid-> sx = i->sx + 60.0;
										PrevAsteroid-> sy = i->sy + 40.0;
										PrevAsteroid-> next = NULL;
										
										NextAsteroid = malloc(sizeof(Asteroid));
										NextAsteroid-> gone = 0;
										NextAsteroid-> split = 0;
										NextAsteroid-> scale = 1;
										NextAsteroid-> ungle = 0.0;
										NextAsteroid-> sx = i->sx - 60.0;
										NextAsteroid-> sy = i->sy + 40.0;
										NextAsteroid-> next = NULL;
										
										PrevAsteroid-> next = NextAsteroid;
										EndAsteroid = NextAsteroid;
									}else{
										NextAsteroid = malloc(sizeof(Asteroid));
										NextAsteroid-> gone = 0;
										NextAsteroid-> split = 0;
										NextAsteroid-> scale = 1;
										NextAsteroid-> ungle = 0.0;
										NextAsteroid-> sx = i->sx + 60.0;
										NextAsteroid-> sy = i->sy + 40.0;
										NextAsteroid-> next = NULL;
										
										EndAsteroid->next = NextAsteroid;
										EndAsteroid = NextAsteroid;
										
										NextAsteroid = malloc(sizeof(Asteroid));
										NextAsteroid-> gone = 0;
										NextAsteroid-> split = 0;
										NextAsteroid-> scale = 1;
										NextAsteroid-> ungle = 0.0;
										NextAsteroid-> sx = i->sx - 60.0;
										NextAsteroid-> sy = i->sy + 40.0;
										NextAsteroid-> next = NULL;
										
										EndAsteroid->next = NextAsteroid;
										EndAsteroid = NextAsteroid;
									}	
								
							}							
							if(i->next == NULL)
								break;
							else
								i = i->next;							
						}
					//соединение цепочек астероидов
					if (PrevAsteroid != NULL && EndAsteroid != NULL){
						i->next = PrevAsteroid;
						i = EndAsteroid;
						//imTimerAsteroid = 7.0;
					}
					
			}
			
			
			//созда�'м новые астероиды автогенерацией
			imTimerAsteroid += 0.015;
		if(imTimerAsteroid > 6.0 ){              //|| TimerContinue == 1){
//fprintf(stdout, "Create Ast  %f\n", imTimerAsteroid);

				imTimerAsteroid = 0.0;
				
				//вычисление начальных координат
				Xa = rand() % (desktop_width-79) + 40;
//fprintf(stdout, "random = %f   ", Xa);				
				
				
				if(StartAsteroid == NULL){
				
					StartAsteroid = malloc(sizeof(Asteroid));
					StartAsteroid-> gone = 0;
					StartAsteroid-> split = 0;
					StartAsteroid-> scale = 2;
					StartAsteroid-> ungle = 0.0;
					StartAsteroid-> sx = Xa;
					StartAsteroid-> sy = -40.0;
					StartAsteroid-> next = NULL;
				}
				else{
					i = StartAsteroid;
					PrevAsteroid = NULL; // начало цепочки астероидов, созданных при делении астероидов при попадании
					EndAsteroid = NULL;
					NextAsteroid = NULL;
					
						 for(; i->next != NULL; )
							i = i->next;
						
					// автогенерация
					NextAsteroid = malloc(sizeof(Asteroid));
					NextAsteroid-> gone = 0;
					NextAsteroid-> split = 0;
					NextAsteroid-> scale = 2;
					NextAsteroid-> ungle = 0.0;
					

						NextAsteroid-> sx = Xa;

					NextAsteroid-> sy = -40.0;
					NextAsteroid-> next = NULL;
//fprintf(stdout, "Create. X = %f\n", NextAsteroid->sx);					
					i->next = NextAsteroid; 
					
				}

			}
			
			// удаляем астероиды
			
			i = StartAsteroid;
			PrevAsteroid = NULL;
			
			for(; i != NULL; ){

				if(i->gone == 1){
//fprintf(stdout, "Free Ast\n ");
						NextAsteroid = i->next;
						free(i);
						i = NextAsteroid;
						if(PrevAsteroid == NULL)
							StartAsteroid = NextAsteroid;
						else
							PrevAsteroid->next = NextAsteroid;
						//continue;
				}else 
					if (i->sy > desktop_height)
						i->sy = -40.0;
				else{
					PrevAsteroid = i;
					i = i->next;
					
				}
			} 
			
			// двигаем Астероиды
//ttime = time (NULL);
//printf ("==================Time: %s\n",ctime (&ttime) );
			i = StartAsteroid;
			for(; i != NULL; i = i->next){
				
				if(i-> gone == 0){
					al_identity_transform(&transform);
					al_rotate_transform(&transform, i->ungle);
					al_scale_transform(&transform, i->scale, i->scale);
					al_translate_transform(&transform, i->sx, i->sy);
					al_use_transform(&transform);
					
					al_draw_line(-20, 20, -25, 5, al_map_rgb(0, 0, 0), 2.0f); 
					al_draw_line(-25, 5, -25, -10, al_map_rgb(0, 0, 0), 2.0f);
					al_draw_line(-25, -10, -5, -10, al_map_rgb(0, 0, 0), 2.0f);
					al_draw_line(-5, -10, -10, -20, al_map_rgb(0, 0, 0), 2.0f);
					al_draw_line(-10, -20, 5, -20, al_map_rgb(0, 0, 0), 2.0f);
					al_draw_line(5, -20, 20, -10, al_map_rgb(0, 0, 0), 2.0f); 
					al_draw_line(20, -10, 20, -5, al_map_rgb(0, 0, 0), 2.0f);
					al_draw_line(20, -5, 0, 0, al_map_rgb(0, 0, 0), 2.0f);
					al_draw_line(0, 0, 20, 10, al_map_rgb(0, 0, 0), 2.0f);
					al_draw_line(20, 10, 10, 20, al_map_rgb(0, 0, 0), 2.0f);
					al_draw_line(10, 20, 0, 15, al_map_rgb(0, 0, 0), 2.0f);
					al_draw_line(0, 15, -20, 20, al_map_rgb(0, 0, 0), 2.0f);
					
					i->ungle += 0.02;
					i->sy += 0.5;
				

					// обработка столкновения с астероидом
					s = sqrtf( powf(Lexx1->sx - i->sx, 2) + powf(Lexx1->sy + - i->sy, 2));
					if( s < 20){
						gameOver = 1;
						PAUSE = 1;
					}
				}
			}
			
			
			
			
			//обновляем счет
			sprintf(TotalT, "%i", Total);
			al_identity_transform(&transform);
			al_rotate_transform(&transform, 0.0);
			al_scale_transform(&transform, 1, 1);
			al_translate_transform(&transform, 0.0, 0.0);
			al_use_transform(&transform);

			al_draw_text(font1, al_map_rgb(255, 255, 0), 30 , 30, ALLEGRO_ALIGN_LEFT, TotalT);
			
			//////////////////////////
			
			al_flip_display();
			redraw = false;
		}
		
		if (PAUSE){
			al_identity_transform(&transform);
			al_rotate_transform(&transform, 0.0);
			al_scale_transform(&transform, 1, 1);
			al_translate_transform(&transform, 0.0, 0.0);
			al_use_transform(&transform);
			
			al_draw_text(font1, al_map_rgb(255, 255, 0), w * 0.1 , 30, ALLEGRO_ALIGN_LEFT, "Control keys:");
			al_draw_text(font1, al_map_rgb(255, 255, 0), w * 0.2 , 60, ALLEGRO_ALIGN_LEFT, "ENTER - start/continue game");
			al_draw_text(font1, al_map_rgb(255, 255, 0), w * 0.2 , 90, ALLEGRO_ALIGN_LEFT, "PAUSE");
			al_draw_text(font1, al_map_rgb(255, 255, 0), w * 0.2 , 120, ALLEGRO_ALIGN_LEFT, "LEFT, RIGHT, UP - spaceship behavior");
			al_draw_text(font1, al_map_rgb(255, 255, 0), w * 0.2 , 150, ALLEGRO_ALIGN_LEFT, "SPACE - fire!");
			al_draw_text(font1, al_map_rgb(255, 255, 0), w * 0.2 , 180, ALLEGRO_ALIGN_LEFT, "ESCAPE - exit");
			
			
			if(!gameOver){
				al_draw_text(font1, al_map_rgb(128, 0, 0), w * 0.5 , h*0.5, ALLEGRO_ALIGN_CENTRE, "PAUSE");
				al_draw_text(font2, al_map_rgb(255, 255, 255), w * 0.5 , h*0.6, ALLEGRO_ALIGN_CENTRE, "PAUSE");
			}else{
				al_draw_text(font1, al_map_rgb(128, 0, 0), w * 0.5 , h*0.5, ALLEGRO_ALIGN_CENTRE, "GAME OVER");
				al_draw_text(font2, al_map_rgb(255, 255, 255), w * 0.5 , h*0.6, ALLEGRO_ALIGN_CENTRE, "GAME OVER");
			}
			
			al_draw_text(font1, al_map_rgb(255, 255, 255), w * 0.5 , h*0.7, ALLEGRO_ALIGN_CENTRE, "Play - Press <Enter>");
			
			al_flip_display();
		}
			
	} 

	//удаляем все астероиды
	delAllAsteroids();
						
			
	// Clean up
	al_destroy_display(display);
	al_destroy_event_queue(event_queue);

	
	return 0;
}

17.02.2019
to be continued...