unit main_;

interface

uses
  Windows, Messages, SysUtils, Controls, Forms, Classes, units, records,
  OpenGL, vfm, constants, variables, buildings, loading, creation,
  global, textures, meshes, saving, pathfinding, fullscreen,
  time, particles, respawns, heights_map, font, MPlayer,
  DXSounds, mini_map, gui, towers_params, flat_button, files_names,
  upgrades, upgrade_window;

type
  Tmain = class(TForm)
    music: TMediaPlayer;
    snd: TDXSound;
    snd_list: TDXWaveList;
    procedure FormResize(Sender: TObject);
    procedure FormMouseWheelDown(Sender: TObject; Shift: TShiftState;
      MousePos: TPoint; var Handled: Boolean);
    procedure FormMouseWheelUp(Sender: TObject; Shift: TShiftState;
      MousePos: TPoint; var Handled: Boolean);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormKeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    private
      DC: HDC;
      hrc: HGLRC;
    protected
      procedure WMPaint(var Msg: TWMPaint); message WM_PAINT;
  end;

var
  main: Tmain;

procedure StartNewGame(level : string);

implementation

uses highscores;

{$R *.DFM}

procedure ViewOrtho;
begin
glMatrixMode(GL_PROJECTION);
glPushMatrix;
glLoadIdentity;
glOrtho(0, screen.width , screen.height , 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix;
glLoadIdentity;
end;

procedure ViewPerspective;
begin
glMatrixMode(GL_PROJECTION);
glPopMatrix;
glMatrixMode(GL_MODELVIEW);
glPopMatrix;
end;

procedure DrawPanels;
var
x0, y0 : single;
begin
glColor4f(1, 0.5, 0.25, interface_opacity);
all_textures[texture_bricks_id].enable;
glBegin(GL_QUADS);

x0 := 42 * interface_scale_x;
y0 := 42 * interface_scale_y;

glTexCoord2f(0, 0);    glVertex2f(0,                 0);
glTexCoord2f(0, 0.5);  glVertex2f(0,                 y0);
glTexCoord2f(10, 0.5); glVertex2f(screen_width,      y0);
glTexCoord2f(10, 0);   glVertex2f(screen_width,      0);

glTexCoord2f(0, 0);    glVertex2f(0,                 y0);
glTexCoord2f(0.5, 0);  glVertex2f(x0,                y0);
glTexCoord2f(0.5, 7);  glVertex2f(x0,                screen_height - y0);
glTexCoord2f(0, 7);    glVertex2f(0,                 screen_height - y0);

glTexCoord2f(0, 0);    glVertex2f(0,                 screen_height);
glTexCoord2f(0, 0.5);  glVertex2f(0,                 screen_height - y0);
glTexCoord2f(10, 0.5); glVertex2f(screen_width,      screen_height - y0);
glTexCoord2f(10, 0);   glVertex2f(screen_width,      screen_height);

glTexCoord2f(0, 0);    glVertex2f(screen_width - x0, y0);
glTexCoord2f(0.5, 0);  glVertex2f(screen_width,      y0);
glTexCoord2f(0.5, 7);  glVertex2f(screen_width,      screen_height - y0);
glTexCoord2f(0, 7);    glVertex2f(screen_width - x0, screen_height - y0);
glEnd;
end;

procedure DrawInterface;
var
s : string;
i : integer;
begin
ViewOrtho;

glColor4f(0.5, 0.7, 1, 1);

buttons[2].hint := 'Малая башня [ ' + inttostr(prices[1].credits) + ' кр. '
                   + inttostr(prices[1].scores) + 'оч. ]';
buttons[3].hint := 'Каменная башня [ ' + inttostr(prices[2].credits) + ' кр. '
                   + inttostr(prices[2].scores) + 'оч. ]';
buttons[4].hint := 'Большая башня [ ' + inttostr(prices[3].credits) + ' кр. '
                   + inttostr(prices[3].scores) + 'оч. ]';

buttons[5].text := inttostr(hours)+' : '+inttostr(minutes);
buttons[6].text := inttostr(time_scale);
buttons[7].text := inttostr(next_wave_hour)+' : '+inttostr(next_wave_minute);

buttons[8].text := inttostr(credits);
buttons[9].text := inttostr(score);

buttons[10].text := inttostr(life_enemys);
buttons[11].text := inttostr(killed_enemys);
buttons[12].text := inttostr(missed_enemys);

buttons[13].texture := gui_cancel_id;
buttons[20].texture := gui_health_id;
buttons[20].text := 'Выберите башню';
buttons[21].text := '0';
buttons[22].text := '0';
buttons[23].text := '0';
buttons[24].text := '0';
buttons[25].text := '0';
buttons[27].text := inttostr(round(gBase.health)) + ' / ' + inttostr(round(gBase.default_health));

if selected_tower <> 0 then
  with gTurrels[selected_tower] do
    begin
      buttons[13].texture := mode + 1;
      case showed_weapon of
        1 : buttons[19].texture := gui_one_id;
        2 : buttons[19].texture := gui_two_id;
        3 : buttons[19].texture := gui_three_id;
      end;

      with params.weapons[showed_weapon] do
        begin
          with buttons[20] do
            case primary of
              0 : begin texture := gui_health_id;   text := 'По самым больным' end;
              1 : begin texture := gui_damage_id;   text := 'По самым сильным' end;
              2 : begin texture := gui_speed_id;    text := 'По самым быстрым' end;
            end;
          buttons[21].text := inttostr(radius);
          buttons[22].text := inttostr(round(speed * 10));
          buttons[23].text := inttostr(round(damage_h * 10));
          buttons[24].text := inttostr(round(damage_d * 10));
          buttons[25].text := inttostr(round(damage_s * 10));
        end;
    end;

buttons[15].visible := upgrades_showed or bonuses_showed;
buttons[16].visible := upgrades_showed or bonuses_showed;
buttons[17].visible := upgrades_showed or bonuses_showed;

//minimap.redraw;

RedrawInterface(1);
DrawPanels;
RedrawInterface(2);

glColor4f(1, 0.5, 0.25, 1);
WriteText(50, 60, fps_string);
WriteText(200, 60, 'Треугольников: ' + inttostr(triangles_rendered));

ViewPerspective;
end;

function DegToRad(Degrees: Extended): Extended;
begin
  Result := Degrees * (PI / 180);
end;

{=============================================}
{---------------- OPENGL PROCEDURES ----------------}
{=============================================}

{---------------- OPENGL INITIALIZATION ----------------}
procedure Initialize;
begin
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
end;

procedure SetDCPixelFormat;
var
  nPixelFormat: Integer;
  pfd: TPixelFormatDescriptor;
begin
FillChar(pfd, SizeOf(pfd), 0);
pfd.dwFlags := PFD_DRAW_TO_WINDOW or
               PFD_SUPPORT_OPENGL or
               PFD_DOUBLEBUFFER;
nPixelFormat := ChoosePixelFormat(main.dc, @pfd);
SetPixelFormat(main.dc, nPixelFormat, @pfd);      
end;

procedure CloseGame;
var
i : integer;
begin
glDeleteLists(text_start_list, text_count_glyphs);
wglMakeCurrent(0, 0);
wglDeleteContext(main.hrc);
ReleaseDC(main.handle, main.DC);
DeleteDC(main.DC);
end;

{---------------- DRAWING PROCEDURES ----------------}
procedure MoveCamera;
var
  hor_s, ver_s : single;
begin
glViewPort(scr_left, scr_top, screen.width-scr_right, screen.height-scr_bottom);
gluPerspective(scr_field_of_view, scr_aspect, scr_near, scr_far);

with world.camera do
 begin
    hor_s := 0; ver_s := 0;
    if dtForward in dest then ver_s := sens_ver;
    if dtBackward in dest then ver_s := -sens_ver;
    if dtLeft in dest then hor_s := -sens_hor;
    if dtRight in dest then hor_s := sens_hor;
    if mouse_x < 3 then hor_s := -sens_hor;
    if mouse_x > screen.width - 1 - 3 then hor_s := sens_hor;
    if mouse_y < 3 then ver_s := sens_ver;
    if mouse_y > screen.height - 1 - 3 then ver_s := -sens_ver;

    eye.x := eye.x + hor_s * count_time;
    eye.y := eye.y + ver_s * count_time;

    if eye.x < world.left_border then eye.x := world.left_border;
    if eye.x > world.right_border then eye.x := world.right_border;
    if eye.y < world.near_border then eye.y := world.near_border;
    if eye.y > world.far_border then eye.y := world.far_border;

    target.x := eye.x;
    target.y := eye.y + destination;

    map_x := round(eye.x / landscape.sx);
    map_y := round(eye.y / landscape.sy);

    if height < 70 then height := 70;
    if height > 500 then height := 500;

    if (selected_enemy <> 0) and iEnemys[selected_enemy] then
      with gEnemys[selected_enemy] do
        begin
          eye.x := body1.x;
          eye.y := body1.y - enemy_destination;
          tz := gEnemys[selected_enemy].body1.z + enemy_height;
        end
    else
      tz := landscape.map[map_x, map_y].z + height;
    eye.z := eye.z + (tz - eye.z) * (count_new - count_last) * 0.005;

    eye_pos_x := eye.x; eye_pos_y := eye.y; eye_pos_z := eye.z;
    eye_map_x := map_x; eye_map_y := map_y;

    rain.x := eye.x;
    rain.y := eye.y;

    up.x := eye.x;
    up.y := eye.y;
    up.z := 100000;

    gluLookAt(eye.x, eye.y, eye.z,
              target.x, target.y, target.z,
              up.x, up.y, up.z);
  end;
end;

procedure Render;
var
i, i1, i2 : integer;
ps : TPaintStruct;
const
position : Array [0..3] of GLFloat = (100, 100, 1000, 1);

begin
if not application_started then exit;
BeginPaint(main.handle, ps);
glClear (GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);

triangles_rendered := 0;
//glLightfv (GL_LIGHT0, GL_POSITION, @position);

if not select_objects then landscape.Redraw;

for i1 := (world.camera.map_x - visible_radius_x) to
          (world.camera.map_x + visible_radius_x) do
  for i2 := (world.camera.map_y - 1) to
            (world.camera.map_y + visible_radius_y) do
    if not((i1 < 2)or(i1 > pathmap.width-1) or
           (i2 < 2)or(i2 > pathmap.height-1)) then
      with pathmap.map[i1, i2] do
        begin
          glLineWidth(2);
          case child_type of
            1 : gBase.Redraw;
            2 : gTrees[child_id].Redraw;
            3 : gTurrels[child_id].Redraw;
            4 : if tower_creation_mode > 0 then
                  gBuildPlaces[child_id].Redraw;
          end;
          if iEnemys[child_enemy_id] then
            gEnemys[child_enemy_id].Redraw;

          with landscape.map[i1, i2] do
            if not landscape.schematic_colors then
              case hours of
                23, 0..5 : color := night_color;
                else color := day_color;
              end
            else
              begin
                if walk then color := color_walk;
                if not walk then color := color_not_walk;
                if build then color := color_build;
              end;
        end;

if select_objects then glLoadName(0);

DrawInterface;

if not select_objects then rain.Redraw;

SwapBuffers(main.DC);
EndPaint(main.handle, ps);
InvalidateRect(main.handle, nil, false);
end;

procedure PlayMusic;
begin
if not sound_music then exit;
main.music.play;
end;

procedure PlaySound;
begin
if not sound_effects then exit;

while play_enemy_kill > 0 do
  begin
    play_enemy_kill := play_enemy_kill - 1;
    main.snd_list.Items.Find('enemy_kill').play(false);
  end;

while play_enemy_miss > 0 do
  begin
    play_enemy_miss := play_enemy_miss - 1;
    main.snd_list.Items.Find('enemy_miss').play(false);
  end;

while play_interface_move > 0 do
  begin
    play_interface_move := play_interface_move - 1;
    main.snd_list.Items.Find('interface_move').play(false);
  end;

while play_interface_click > 0 do
  begin
    play_interface_click := play_interface_click - 1;
    main.snd_list.Items.Find('interface_click').play(false);
  end;

while play_error > 0 do
  begin
    play_error := play_error - 1;
    main.snd_list.Items.Find('error').play(false);
  end;

while play_new_wave > 0 do
  begin
    play_new_wave := play_new_wave - 1;
    main.snd_list.Items.Find('new_wave').play(false);
  end;

while play_shoot > 0 do
  begin
    play_shoot := play_shoot - 1;
    main.snd_list.Items.Find('shoot').play(false);
  end;

if rain.active and (not ambient_playing) then
  begin
    ambient_playing := true;
    main.snd_list.Items.Find('rain').play(false);
  end;
if (not rain.active) and ambient_playing then
  begin
    ambient_playing := false;
    main.snd_list.Items.Find('rain').stop;
  end;

if (hours = 6) and (minutes = 0) then
  main.snd_list.Items.Find('dawn').play(false);
if (hours = 23) and (minutes = 0) then
  main.snd_list.Items.Find('dusk').play(false);
end;

procedure RedrawScene;
var
i : integer;
begin
glMatrixMode(GL_PROJECTION);
glLoadIdentity;

MoveCamera;
select_objects := false;
Render;

glMatrixMode(GL_MODELVIEW);
glLoadIdentity;
InvalidateRect(main.handle, nil, false);
end;

procedure Tmain.WMPaint(var Msg: TWMPaint);
var
i : integer;
begin
if not application_started then exit;
count_new := GetTickCount;

fps := fps + 1;
if (count_new - count_sec) >= 1000 then
  begin
    count_sec := count_sec + 1000;
    fps_string := 'FPS: ' + inttostr(fps);

    if min_fps = 0 then min_fps := fps;
    if fps < min_fps then min_fps := fps;
    if fps > max_fps then max_fps := fps;
    fps := 0;
    CountTime;
    PlayMusic;
  end;

PlaySound;
count_time := (count_new - count_last) * time_scale;

life_enemys := 0;
for i := 1 to total_enemys do if iEnemys[i] then gEnemys[i].Move;
for i := 1 to total_turrels do gTurrels[i].Shoot;
rain.Move;

RedrawScene;

if gBase.health <= 0 then main.close;

count_last := count_new;
end;

{=============================================}
{---------------- GAME PROCEDURES ----------------}
{=============================================}

{=============================================}
{---------------- FORM PROCEDURES ----------------}
{=============================================}

procedure Tmain.FormResize(Sender: TObject);
begin
scr_aspect := screen.width / screen.height;
end;

procedure Tmain.FormMouseWheelDown(Sender: TObject; Shift: TShiftState;
  MousePos: TPoint; var Handled: Boolean);
begin
world.camera.height := world.camera.height + sens_zoom_height;
end;

procedure Tmain.FormMouseWheelUp(Sender: TObject; Shift: TShiftState;
  MousePos: TPoint; var Handled: Boolean);
begin
world.camera.height := world.camera.height - sens_zoom_height;
end;

procedure Tmain.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if key = vk_escape then main.close;

if (chr(ord(key)) = 'W') or (key = vk_up) then Dest := Dest + [dtForward];
if (chr(ord(key)) = 'S') or (key = vk_down) then Dest := Dest + [dtBackward];
if (chr(ord(key)) = 'A') or (key = vk_left) then Dest := Dest + [dtLeft];
if (chr(ord(key)) = 'D') or (key = vk_right) then Dest := Dest + [dtRight];

if chr(ord(key)) = 'E' then SetTimescale(time_scale + 1);
if chr(ord(key)) = 'Q' then SetTimescale(time_scale - 1);

if chr(ord(key)) = '1' then tower_creation_mode := 1;
if chr(ord(key)) = '2' then tower_creation_mode := 2;
if chr(ord(key)) = '3' then tower_creation_mode := 3;
if chr(ord(key)) = '4' then tower_creation_mode := 0;

if chr(ord(key)) = 'B' then
  begin
    tower_creation_mode := tower_creation_mode + 1;
    if tower_creation_mode > 3 then tower_creation_mode := 0;
  end;

if chr(ord(key)) = 'R' then time_scale := 5;

if chr(ord(key)) = 'V' then
  if polygon_mode < 3 then polygon_mode := polygon_mode + 1
  else polygon_mode := 1;
case polygon_mode of
  1 : glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
  2 : glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  3 : glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
end;

if chr(ord(key)) = 'F' then
  begin
    SetUpgradesForSelected;
    if selected_tower <> 0 then upgrades_showed := not upgrades_showed;
  end;
if chr(ord(key)) = 'G' then
  begin
    SetBonuses;
    bonuses_showed := not bonuses_showed;
  end;

if chr(ord(key)) = 'C' then
  landscape.schematic_colors := not landscape.schematic_colors;
end;

procedure Tmain.FormKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (chr(ord(key)) = 'W') or (key = vk_up) then Dest := Dest - [dtForward];
if (chr(ord(key)) = 'S') or (key = vk_down) then Dest := Dest - [dtBackward];
if (chr(ord(key)) = 'A') or (key = vk_left) then Dest := Dest - [dtLeft];
if (chr(ord(key)) = 'D') or (key = vk_right) then Dest := Dest - [dtRight];
end;

function DoSelect(x : GLint; y : GLint) : GLint;
var
  hits : GLint;
begin
glSelectBuffer(max_select, @selectBuf);
glRenderMode(GL_SELECT);
glInitNames;
glPushName(0);
glGetIntegerv(GL_VIEWPORT, @vp);
glMatrixMode(GL_PROJECTION);
glLoadIdentity;
gluPickMatrix(x, screen.height-y, 4, 4, @vp);
glViewPort(scr_left, scr_top, screen.width-scr_right, screen.height-scr_bottom);
gluPerspective(scr_field_of_view, scr_aspect, scr_near, scr_far);
 with world.camera do
    gluLookAt(eye.x, eye.y, eye.z,
              target.x, target.y, target.z,
              up.x, up.y, up.z);
glMatrixMode(GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT);
select_objects := true;
Render;
hits := glRenderMode(GL_RENDER);
result := -1;
result := selectbuf[max_select-1];
select_objects := false;
end;

procedure Tmain.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
if not application_started then exit;
if not CheckInterface(x, y, 1) then interface_selected := 0;
mouse_x := x; mouse_y := y;
end;

procedure StartNewGame(level : string);
var
i : integer;
begin
randomize;
decimalseparator := '.';

SetFullscreenMode(screen_width, screen_height, 32);
main.WindowState := wsMaximized;

main.DC := GetDC(main.handle);
SetDCPixelFormat;
main.hrc := wglCreateContext(main.DC);
wglMakeCurrent(main.DC, main.hrc);
Initialize;
InitializeFont(main.dc, font_name);

SetTowersParams;
SetTowersUpgrades;

World := TWorld.create;
LoadLevel(level);
main.music.filename := music_file_name;
main.music.open;

with world.camera do
  begin
    eye.x := gBase.base1.map_x * landscape.sx;
    eye.y := (gBase.base1.map_y - 6) * landscape.sy;
    eye.z := 900;
  end;

minimap := TMinimap.Create(pathmap, -20, -20, 2.5, 2.5, 2.5);
for i := 1 to total_respawns do gRespawns[i].RefindPath;

world.left_border := landscape.sx*2;
world.right_border := (landscape.width - 1) * landscape.sx;
world.near_border := landscape.sy*2;
world.far_border := (landscape.height - 1) * landscape.sy;

with landscape do 
  rain := TParticles.Create(width / 2 * sx, height / 2 * sy,
  1000, 0, 650, 5000);

CreateInterface;

days := 1;
hours := 7;
minutes := 0;
start_days := days;
start_hours := hours;
next_wave_day := days;
next_wave_hour := hours;
if next_wave_hour > 23 then next_wave_hour := next_wave_hour - 24;
next_wave_minute := minutes + random(60);
SetTimescale(5);
SetSkyColors;
CountTime;

MoveCamera;

fps := 0;
count_last := GetTickCount;
count_sec := count_last;

with color_walk do begin r := 0.1; g := 1; b := 0.1; a := 1; end;
with color_not_walk do begin r := 1; g := 0.1; b := 0.1; a := 1; end;
with color_build do begin r := 0.1; g := 0.1; b := 1; a := 1; end;

application_started := true;
end;

procedure Tmain.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
i, i1, i2, q : integer;

procedure CreateTower(mode : integer);
begin
with gBuildplaces[i - id_buildplaces] do
  begin i1 := obj.map_x; i2 := obj.map_y; end;
if (not pathmap.map[i1, i2].build) or
   (credits < prices[tower_creation_mode].credits) or
   (score < prices[tower_creation_mode].scores) then
   begin play_error := play_error + 1; exit; end;
credits := credits - prices[tower_creation_mode].credits;
score := score - prices[tower_creation_mode].scores;
total_turrels := total_turrels + 1;
if (q = 2) or (q = 3) then i1 := i1 - 1;
if (q = 4) or (q = 3) then i2 := i2 - 1;
gTurrels[total_turrels] := TTurrel.Create(i1, i2, tower_creation_mode);
gTurrels[total_turrels].base.id := total_turrels + id_turrels;
gTurrels[total_turrels].head.id := gTurrels[total_turrels].base.id;
pathmap.map[i1, i2].child_id := total_turrels;
if sound_effects then main.snd_list.Items.Find('build').play(false);
end;

function BigBuildPlace : boolean;
begin
with gBuildplaces[i - id_buildplaces] do
  begin i1 := obj.map_x; i2 := obj.map_y; end;
  
result := false;
if (pathmap.map[i1 - 1, i2].child_type = 4) and
   (pathmap.map[i1 - 1, i2 - 1].child_type = 4) and
   (pathmap.map[i1, i2 - 1].child_type = 4) then
     begin result := true; q := 3; exit; end;

if (pathmap.map[i1 + 1, i2].child_type = 4) and
   (pathmap.map[i1 + 1, i2 - 1].child_type = 4) and
   (pathmap.map[i1, i2 - 1].child_type = 4) then
     begin result := true; q := 4; exit; end;

if (pathmap.map[i1 - 1, i2].child_type = 4) and
   (pathmap.map[i1 - 1, i2 + 1].child_type = 4) and
   (pathmap.map[i1, i2 + 1].child_type = 4) then
     begin result := true; q := 2; exit; end;

if (pathmap.map[i1 + 1, i2].child_type = 4) and
   (pathmap.map[i1 + 1, i2 + 1].child_type = 4) and
   (pathmap.map[i1, i2 + 1].child_type = 4) then
     begin result := true; q := 1; exit; end;
end;

begin
if not application_started then exit;
selected_enemy := 0; 
if CheckInterface(x, y, 2) then exit;
if upgrades_showed or bonuses_showed then exit;

if not (ssLeft in shift) then tower_creation_mode := 0;
selected_tower := 0;
selected_enemy := 0;

i := doselect(x, y);
if i <= 0 then exit;

if (i > id_turrels) and (i <= id_enemys) then
  begin
    selected_tower := i - id_turrels;
    exit;
  end;

if tower_creation_mode <> 0 then
  if (i > id_buildplaces) and (i <= id_turrels) then
    if (tower_creation_mode <> 3) or BigBuildPlace then
      begin
        CreateTower(tower_creation_mode);
        exit;
      end;

if (i > id_enemys) and (ssRight in shift) then
  with gEnemys[i - id_enemys] do
    selected_enemy := i - id_enemys;
end;

procedure Tmain.FormCreate(Sender: TObject);
begin
hide;
end;

procedure Tmain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
music.Stop;
main.snd_list.Items.Find('rain').stop;
RestoreDefaultMode;
CloseGame;
highscores_.show;
end;

end.
