unit Baseclass;

interface

uses
  Windows, SysUtils, classes, Graphics, trigu,enemyheap,bass;

const mine_count = 7;

type
  TBase = class
     XPos, YPos: integer;
     Angle: Integer;
     _rot:boolean;
     _velos:real;
  end;

  TSoundBlock = class
  private
   procedure _Sound(s:string; Handle:HWND; vol:DWORD);
   function Get_playing(i:integer):boolean;
  public
  _on:boolean;
  _loop:boolean;
  _fast_stop:boolean;
  _playing:boolean;
  Channel:DWORD;
  _direc:string;
  _Handle:HWND;
  function getpos:integer;
  procedure play(i:integer);
  procedure Stop;
  end;

  TRPoint = record
  	X, Y: integer;
  end;


  TBaseHouse = class(TBase)
    x,y:integer;
    _visible:boolean;
    shield,helth:integer;
    angle:integer;
    _energy:boolean;
    _energy_level:integer;
    _radar:boolean;
    _active:boolean;
    procedure Init;
    procedure Draw(canvas:Tcanvas);
    procedure Energy(_b:boolean);
  end;

  TWEAP = (twsnipergun,twgun,twliser,twdgun,twdliser,twbazooka,twsun);

  TWeapon = class(TBase)
     Ammo: integer;
     Speed: integer;
     _speed_rot:integer;
     _Type:TWEAP;
     _visible:boolean;
     ColDelta: Integer;
     _radius:integer;
     _sector:integer;

     _target:integer;

     _reload:integer;
     _refire:integer;

     _wait:boolean;
     _OnTarget:boolean;
     SB:TsoundBlock;
     _level:real;
     _killed:integer;

     procedure Rotate(Degrees: integer);
     function Fire(x,y:integer; canvas,b_canvas:Tcanvas):integer; //бабах

  end;

  TMine = record
   use:boolean;
   activated:boolean;
   enabled:boolean;
   Coo:TRPoint;
   _light:byte;
   _timer:integer;
   _timer_enabled:boolean;
  end;

  TBaseCenter = class(TBase)
    _x,_y:integer;
    _reload:integer;
    _refire:integer;
    _radius:integer;
    _sector:integer;
    Ammo: integer;
    _visible:boolean;
    _level:real;
    _killed:integer;
    _active:boolean;
    _wait:boolean;
    _bax:boolean;
    _Weapon1:TBase;
    _Weapon2:TBase;
    _Weapon3:TBase;
    _Weapon4:TBase;
    SB:TsoundBlock;
    SB_mine:TsoundBlock;
    _mine: array[0..7] of TMine;
    procedure Draw(canvas,canvas_b:Tcanvas);
    procedure Init;
    procedure CurRotate(x,y:integer);
    procedure Fire(var _mm:TContenerEnemy; x,y:integer; Canvas,b_canvas:Tcanvas);
    procedure CoordBax(var _mm:TContenerEnemy; x,y:integer);
    procedure _Rotate(Degrees: Integer; var TB:Tbase);
    procedure Draw_mine(canvas,canvas_b:Tcanvas);
    procedure Add_mine(x,y:integer);
    procedure AI;
    procedure Mine_AI(var CE:TContenerEnemy);
  end;
  function GetAngle(x1,y1,x2,y2:integer):integer;

implementation

uses gi;

function InRect(x,y,left,top,right,down:integer):boolean;
begin
if (x>left)and(x<right)and(y>top)and(y<down) then InRect:=true else InRect:=false;
end;

function GetTrace(x1,y1,x2,y2:integer):integer;
var ix,iy:integer;
begin
//  ix:=x1-x2; iy:=y1-y2;

  result:=trunc(sqrt(sqr(x1-x2)+sqr(y1-y2)));
end;

procedure Draw_Ba_Bax(canvas:TCanvas; x,y:integer);
var ix,iy,iix,iiy,i,ii:integer;
begin
for ii:=0 to 2 do
 for i:=0 to 10 do begin
   randomize;
   ix:=x+random(7)-3;
   iy:=y+random(7)-3;
   iix:=ix+random(7)-3;
   iiy:=iy+random(7)-3;
   canvas.MoveTo(ix,iy); canvas.LineTo(iix,iiy);
  end;
end;

function GetAngle(x1,y1,x2,y2:integer):integer;
begin
result:=0;
if (x1>x2)and(y1>y2) then begin
     result := (-1)*Round(ArcTan((y1-Y2)/(X2-x1))*180/pi);
     end else
       if (x1<x2)and(y1>y2) then begin
       result :=180+(-1)*Round(ArcTan((y1-Y2)/(X2-x1))*180/pi);
       end else
         if (x1>x2)and(y1<y2) then begin
         result :=360+(-1)*Round(ArcTan((y1-Y2)/(X2-x1))*180/pi);
         end else
           if (x1<x2)and(y1<y2) then begin
           result :=180+(-1)*Round(ArcTan((y1-Y2)/(X2-x1))*180/pi);
           end else begin
             if (x1=x2)and(y1<y2) then result :=270;
             if (x1=x2)and(y1>y2) then result :=90;
             if (x1>x2)and(y1=y2) then result :=0;
             if (x1<x2)and(y1=y2) then result :=180;
           end;
//PS не надо смеяться
end;



procedure TBaseCenter.Draw(canvas,canvas_b:Tcanvas);
var x,y,iiz1,iiz2,angl:integer;
begin
try
 Canvas.Brush.Style:=bsClear;
 Canvas.Pen.Color:=$6A6A00;
 Canvas.Ellipse(xpos-_radius,ypos-_radius,xpos+_radius,ypos+_radius);
 Canvas.Brush.Style:=bsSolid;
 Canvas.Brush.Color:=clblack;

 Draw_mine(canvas,canvas_b);

if _level>1 then begin
 with _weapon1 do begin
 Canvas.Brush.Color:=$664534;
 Canvas.Font.Color:=clred;
 Canvas.Ellipse(xpos-5,ypos-5,xpos+6,ypos+6);
 Canvas.Brush.Color:=clblack;
 angl:=angle;
 x:=xpos;
 y:=ypos;
 canvas.Pen.Style:=psSolid;
 canvas.Pen.Color:=clblack;
 canvas.Polygon([
 point(Round(((-6)*CosineArray^[Angl]-(6)*SineArray^[Angl])+x),Round(((-6)*SineArray^[Angl]+(6)*CosineArray^[Angl])+y)),
 point(Round(((-5)*CosineArray^[Angl]-(5)*SineArray^[Angl])+x),Round(((-5)*SineArray^[Angl]+(5)*CosineArray^[Angl])+y)),
 point(Round(((-1)*CosineArray^[Angl]-(5)*SineArray^[Angl])+x),Round(((-1)*SineArray^[Angl]+(5)*CosineArray^[Angl])+y)),
 point(Round(((-2)*CosineArray^[Angl]-(2)*SineArray^[Angl])+x),Round(((-2)*SineArray^[Angl]+(2)*CosineArray^[Angl])+y)),
 point(Round(((-2)*CosineArray^[Angl]-(-3)*SineArray^[Angl])+x),Round(((-2)*SineArray^[Angl]+(-3)*CosineArray^[Angl])+y)),
 point(Round(((2)*CosineArray^[Angl]-(-3)*SineArray^[Angl])+x),Round(((2)*SineArray^[Angl]+(-3)*CosineArray^[Angl])+y)),
 point(Round(((2)*CosineArray^[Angl]-(2)*SineArray^[Angl])+x),Round(((2)*SineArray^[Angl]+(2)*CosineArray^[Angl])+y)),
 point(Round(((1)*CosineArray^[Angl]-(5)*SineArray^[Angl])+x),Round(((1)*SineArray^[Angl]+(5)*CosineArray^[Angl])+y)),
 point(Round(((4)*CosineArray^[Angl]-(5)*SineArray^[Angl])+x),Round(((4)*SineArray^[Angl]+(5)*CosineArray^[Angl])+y)),
 point(Round(((5)*CosineArray^[Angl]-(3)*SineArray^[Angl])+x),Round(((5)*SineArray^[Angl]+(3)*CosineArray^[Angl])+y)),
 point(Round(((7)*CosineArray^[Angl]-(3)*SineArray^[Angl])+x),Round(((7)*SineArray^[Angl]+(3)*CosineArray^[Angl])+y)),
 point(Round(((7)*CosineArray^[Angl]-(11)*SineArray^[Angl])+x),Round(((7)*SineArray^[Angl]+(11)*CosineArray^[Angl])+y)),
 point(Round(((5)*CosineArray^[Angl]-(11)*SineArray^[Angl])+x),Round(((5)*SineArray^[Angl]+(11)*CosineArray^[Angl])+y)),
 point(Round(((4)*CosineArray^[Angl]-(9)*SineArray^[Angl])+x),Round(((4)*SineArray^[Angl]+(9)*CosineArray^[Angl])+y)),
 point(Round(((-5)*CosineArray^[Angl]-(9)*SineArray^[Angl])+x),Round(((-5)*SineArray^[Angl]+(9)*CosineArray^[Angl])+y)),
 point(Round(((-6)*CosineArray^[Angl]-(8)*SineArray^[Angl])+x),Round(((-6)*SineArray^[Angl]+(8)*CosineArray^[Angl])+y))
]);
 

if (_active)and not(_wait) then begin
 Canvas.Pen.Color:=$E1F7E;
 canvas.MoveTo(Round((-8)*CosineArray^[Angle]-(7)*SineArray^[Angle])+x,
 Round((-8)*SineArray^[Angle]+(7)*CosineArray^[Angle])+y);
 canvas.LineTo(_x,_y);  end;
 end; end;

with _weapon2 do begin
 Canvas.Pen.Color:=$664534;
 Canvas.Brush.Color:=$664534;
 Canvas.Font.Color:=clred;
 Canvas.Ellipse(xpos-8,ypos-8,xpos+9,ypos+9);
 Canvas.Brush.Color:=clblack;
 angl:=angle;
 x:=xpos;
 y:=ypos;
 canvas.Pen.Color:=clblack;
 canvas.Polygon([
 point(Round(((-17)*CosineArray^[Angl]-(-1)*SineArray^[Angl])+x),Round(((-17)*SineArray^[Angl]+(-1)*CosineArray^[Angl])+y) ),
 point(Round(((-3)*CosineArray^[Angl]-(-1)*SineArray^[Angl])+x),Round(((-3)*SineArray^[Angl]+(-1)*CosineArray^[Angl])+y)),
 point(Round(((-3)*CosineArray^[Angl]-(-3)*SineArray^[Angl])+x),Round(((-3)*SineArray^[Angl]+(-3)*CosineArray^[Angl])+y)),
 point(Round(((-8)*CosineArray^[Angl]-(-3)*SineArray^[Angl])+x),Round(((-8)*SineArray^[Angl]+(-3)*CosineArray^[Angl])+y)),
 point(Round(((-6)*CosineArray^[Angl]-(-6)*SineArray^[Angl])+x),Round(((-6)*SineArray^[Angl]+(-6)*CosineArray^[Angl])+y) ),
 point(Round(((4)*CosineArray^[Angl]-(-6)*SineArray^[Angl])+x),Round(((4)*SineArray^[Angl]+(-6)*CosineArray^[Angl])+y)),
 point(Round(((5)*CosineArray^[Angl]-(-3)*SineArray^[Angl])+x),Round(((5)*SineArray^[Angl]+(-3)*CosineArray^[Angl])+y)),
 point(Round(((3)*CosineArray^[Angl]-(-3)*SineArray^[Angl])+x),Round(((3)*SineArray^[Angl]+(-3)*CosineArray^[Angl])+y)),
 point(Round(((3)*CosineArray^[Angl]-(-1)*SineArray^[Angl])+x),Round(((3)*SineArray^[Angl]+(-1)*CosineArray^[Angl])+y)),
 point(Round(((6)*CosineArray^[Angl]-(-1)*SineArray^[Angl])+x),Round(((6)*SineArray^[Angl]+(-1)*CosineArray^[Angl])+y)),
 point(Round(((6)*CosineArray^[Angl]-(1)*SineArray^[Angl])+x),Round(((6)*SineArray^[Angl]+(1)*CosineArray^[Angl])+y)),
 point(Round(((3)*CosineArray^[Angl]-(1)*SineArray^[Angl])+x),Round(((3)*SineArray^[Angl]+(1)*CosineArray^[Angl])+y)),
 point(Round(((3)*CosineArray^[Angl]-(3)*SineArray^[Angl])+x),Round(((3)*SineArray^[Angl]+(3)*CosineArray^[Angl])+y)),
 point(Round(((5)*CosineArray^[Angl]-(3)*SineArray^[Angl])+x),Round(((5)*SineArray^[Angl]+(3)*CosineArray^[Angl])+y)),
 point(Round(((4)*CosineArray^[Angl]-(6)*SineArray^[Angl])+x),Round(((4)*SineArray^[Angl]+(6)*CosineArray^[Angl])+y)),
 point(Round(((-6)*CosineArray^[Angl]-(6)*SineArray^[Angl])+x),Round(((-6)*SineArray^[Angl]+(6)*CosineArray^[Angl])+y) ),
 point(Round(((-8)*CosineArray^[Angl]-(3)*SineArray^[Angl])+x),Round(((-8)*SineArray^[Angl]+(3)*CosineArray^[Angl])+y)),
 point(Round(((-3)*CosineArray^[Angl]-(3)*SineArray^[Angl])+x),Round(((-3)*SineArray^[Angl]+(3)*CosineArray^[Angl])+y)),
 point(Round(((-3)*CosineArray^[Angl]-(1)*SineArray^[Angl])+x),Round(((-3)*SineArray^[Angl]+(1)*CosineArray^[Angl])+y)),
 point(Round(((-17)*CosineArray^[Angl]-(1)*SineArray^[Angl])+x),Round(((-17)*SineArray^[Angl]+(1)*CosineArray^[Angl])+y) )
 ]);
if _bax then begin
 Canvas.brush.Color:=clyellow;
 Canvas.brush.Style:=bsSolid;
 Canvas.Pen.Color:=$7D5744;

 iiz1:=Round((-19)*CosineArray^[Angle]-(0)*SineArray^[Angle])+XPos;
 iiz2:=Round((-19)*SineArray^[Angle]+(0)*CosineArray^[Angle])+YPos;
 
 Canvas.Ellipse(iiz1-3,iiz2-3,iiz1+4,iiz2+4);

 iiz1:=Round((-23)*CosineArray^[Angle]-(0)*SineArray^[Angle])+XPos;
 iiz2:=Round((-23)*SineArray^[Angle]+(0)*CosineArray^[Angle])+YPos;
 Canvas.Ellipse(iiz1-2,iiz2-2,iiz1+3,iiz2+3);

 GI._Shadow_II.Draw_shadow(canvas,canvas, Round((-23)*CosineArray^[Angle])+XPos-20,Round((-23)*SineArray^[Angle])+YPos-20);

 end;
 end;

if _level>4 then begin
with _weapon3 do begin
 Canvas.Pen.Color:=$664534;
 Canvas.Brush.Color:=$664534;
 Canvas.Font.Color:=clred;
 Canvas.Ellipse(xpos-8,ypos-8,xpos+9,ypos+9);
 Canvas.Brush.Color:=clblack;
 Canvas.Brush.Style:=bsSolid;
 angl:=angle;
 x:=xpos;
 y:=ypos;
 canvas.Pen.Color:=clblack;
 canvas.Polygon([
 point(Round(((-17)*CosineArray^[Angl]-(-1)*SineArray^[Angl])+x),Round(((-17)*SineArray^[Angl]+(-1)*CosineArray^[Angl])+y) ),
 point(Round(((-3)*CosineArray^[Angl]-(-1)*SineArray^[Angl])+x),Round(((-3)*SineArray^[Angl]+(-1)*CosineArray^[Angl])+y)),
 point(Round(((-3)*CosineArray^[Angl]-(-3)*SineArray^[Angl])+x),Round(((-3)*SineArray^[Angl]+(-3)*CosineArray^[Angl])+y)),
 point(Round(((-8)*CosineArray^[Angl]-(-3)*SineArray^[Angl])+x),Round(((-8)*SineArray^[Angl]+(-3)*CosineArray^[Angl])+y)),
 point(Round(((-6)*CosineArray^[Angl]-(-6)*SineArray^[Angl])+x),Round(((-6)*SineArray^[Angl]+(-6)*CosineArray^[Angl])+y) ),
 point(Round(((4)*CosineArray^[Angl]-(-6)*SineArray^[Angl])+x),Round(((4)*SineArray^[Angl]+(-6)*CosineArray^[Angl])+y)),
 point(Round(((5)*CosineArray^[Angl]-(-3)*SineArray^[Angl])+x),Round(((5)*SineArray^[Angl]+(-3)*CosineArray^[Angl])+y)),
 point(Round(((3)*CosineArray^[Angl]-(-3)*SineArray^[Angl])+x),Round(((3)*SineArray^[Angl]+(-3)*CosineArray^[Angl])+y)),
 point(Round(((3)*CosineArray^[Angl]-(-1)*SineArray^[Angl])+x),Round(((3)*SineArray^[Angl]+(-1)*CosineArray^[Angl])+y)),
 point(Round(((6)*CosineArray^[Angl]-(-1)*SineArray^[Angl])+x),Round(((6)*SineArray^[Angl]+(-1)*CosineArray^[Angl])+y)),
 point(Round(((6)*CosineArray^[Angl]-(1)*SineArray^[Angl])+x),Round(((6)*SineArray^[Angl]+(1)*CosineArray^[Angl])+y)),
 point(Round(((3)*CosineArray^[Angl]-(1)*SineArray^[Angl])+x),Round(((3)*SineArray^[Angl]+(1)*CosineArray^[Angl])+y)),
 point(Round(((3)*CosineArray^[Angl]-(3)*SineArray^[Angl])+x),Round(((3)*SineArray^[Angl]+(3)*CosineArray^[Angl])+y)),
 point(Round(((5)*CosineArray^[Angl]-(3)*SineArray^[Angl])+x),Round(((5)*SineArray^[Angl]+(3)*CosineArray^[Angl])+y)),
 point(Round(((4)*CosineArray^[Angl]-(6)*SineArray^[Angl])+x),Round(((4)*SineArray^[Angl]+(6)*CosineArray^[Angl])+y)),
 point(Round(((-6)*CosineArray^[Angl]-(6)*SineArray^[Angl])+x),Round(((-6)*SineArray^[Angl]+(6)*CosineArray^[Angl])+y) ),
 point(Round(((-8)*CosineArray^[Angl]-(3)*SineArray^[Angl])+x),Round(((-8)*SineArray^[Angl]+(3)*CosineArray^[Angl])+y)),
 point(Round(((-3)*CosineArray^[Angl]-(3)*SineArray^[Angl])+x),Round(((-3)*SineArray^[Angl]+(3)*CosineArray^[Angl])+y)),
 point(Round(((-3)*CosineArray^[Angl]-(1)*SineArray^[Angl])+x),Round(((-3)*SineArray^[Angl]+(1)*CosineArray^[Angl])+y)),
 point(Round(((-17)*CosineArray^[Angl]-(1)*SineArray^[Angl])+x),Round(((-17)*SineArray^[Angl]+(1)*CosineArray^[Angl])+y) )
 ]);
if _bax then begin
 Canvas.brush.Color:=clyellow;
 Canvas.brush.Style:=bsSolid;
 Canvas.Pen.Color:=$7D5744;

 iiz1:=Round((-19)*CosineArray^[Angle]-(0)*SineArray^[Angle])+XPos;
 iiz2:=Round((-19)*SineArray^[Angle]+(0)*CosineArray^[Angle])+YPos;
 
 Canvas.Ellipse(iiz1-3,iiz2-3,iiz1+4,iiz2+4);

 iiz1:=Round((-23)*CosineArray^[Angle]-(0)*SineArray^[Angle])+XPos;
 iiz2:=Round((-23)*SineArray^[Angle]+(0)*CosineArray^[Angle])+YPos;
 Canvas.Ellipse(iiz1-2,iiz2-2,iiz1+3,iiz2+3);

 GI._Shadow_II.Draw_shadow(canvas,canvas, Round((-23)*CosineArray^[Angle])+XPos-20,Round((-23)*SineArray^[Angle])+YPos-20);

 end;
 end; end;

if _level>8 then begin
with _weapon4 do begin
 Canvas.Pen.Color:=$664534;
 Canvas.Brush.Color:=$664534;
 Canvas.Font.Color:=clred;
 Canvas.Ellipse(xpos-8,ypos-8,xpos+9,ypos+9);
 Canvas.Brush.Color:=clblack;
 Canvas.Brush.Style:=bsSolid;
 angl:=angle;
 x:=xpos;
 y:=ypos;
 canvas.Pen.Color:=clblack;
 canvas.Polygon([
 point(Round(((-17)*CosineArray^[Angl]-(-1)*SineArray^[Angl])+x),Round(((-17)*SineArray^[Angl]+(-1)*CosineArray^[Angl])+y) ),
 point(Round(((-3)*CosineArray^[Angl]-(-1)*SineArray^[Angl])+x),Round(((-3)*SineArray^[Angl]+(-1)*CosineArray^[Angl])+y)),
 point(Round(((-3)*CosineArray^[Angl]-(-3)*SineArray^[Angl])+x),Round(((-3)*SineArray^[Angl]+(-3)*CosineArray^[Angl])+y)),
 point(Round(((-8)*CosineArray^[Angl]-(-3)*SineArray^[Angl])+x),Round(((-8)*SineArray^[Angl]+(-3)*CosineArray^[Angl])+y)),
 point(Round(((-6)*CosineArray^[Angl]-(-6)*SineArray^[Angl])+x),Round(((-6)*SineArray^[Angl]+(-6)*CosineArray^[Angl])+y) ),
 point(Round(((4)*CosineArray^[Angl]-(-6)*SineArray^[Angl])+x),Round(((4)*SineArray^[Angl]+(-6)*CosineArray^[Angl])+y)),
 point(Round(((5)*CosineArray^[Angl]-(-3)*SineArray^[Angl])+x),Round(((5)*SineArray^[Angl]+(-3)*CosineArray^[Angl])+y)),
 point(Round(((3)*CosineArray^[Angl]-(-3)*SineArray^[Angl])+x),Round(((3)*SineArray^[Angl]+(-3)*CosineArray^[Angl])+y)),
 point(Round(((3)*CosineArray^[Angl]-(-1)*SineArray^[Angl])+x),Round(((3)*SineArray^[Angl]+(-1)*CosineArray^[Angl])+y)),
 point(Round(((6)*CosineArray^[Angl]-(-1)*SineArray^[Angl])+x),Round(((6)*SineArray^[Angl]+(-1)*CosineArray^[Angl])+y)),
 point(Round(((6)*CosineArray^[Angl]-(1)*SineArray^[Angl])+x),Round(((6)*SineArray^[Angl]+(1)*CosineArray^[Angl])+y)),
 point(Round(((3)*CosineArray^[Angl]-(1)*SineArray^[Angl])+x),Round(((3)*SineArray^[Angl]+(1)*CosineArray^[Angl])+y)),
 point(Round(((3)*CosineArray^[Angl]-(3)*SineArray^[Angl])+x),Round(((3)*SineArray^[Angl]+(3)*CosineArray^[Angl])+y)),
 point(Round(((5)*CosineArray^[Angl]-(3)*SineArray^[Angl])+x),Round(((5)*SineArray^[Angl]+(3)*CosineArray^[Angl])+y)),
 point(Round(((4)*CosineArray^[Angl]-(6)*SineArray^[Angl])+x),Round(((4)*SineArray^[Angl]+(6)*CosineArray^[Angl])+y)),
 point(Round(((-6)*CosineArray^[Angl]-(6)*SineArray^[Angl])+x),Round(((-6)*SineArray^[Angl]+(6)*CosineArray^[Angl])+y) ),
 point(Round(((-8)*CosineArray^[Angl]-(3)*SineArray^[Angl])+x),Round(((-8)*SineArray^[Angl]+(3)*CosineArray^[Angl])+y)),
 point(Round(((-3)*CosineArray^[Angl]-(3)*SineArray^[Angl])+x),Round(((-3)*SineArray^[Angl]+(3)*CosineArray^[Angl])+y)),
 point(Round(((-3)*CosineArray^[Angl]-(1)*SineArray^[Angl])+x),Round(((-3)*SineArray^[Angl]+(1)*CosineArray^[Angl])+y)),
 point(Round(((-17)*CosineArray^[Angl]-(1)*SineArray^[Angl])+x),Round(((-17)*SineArray^[Angl]+(1)*CosineArray^[Angl])+y) )
 ]);
if _bax then begin
 Canvas.brush.Color:=clyellow;
 Canvas.brush.Style:=bsSolid;
 Canvas.Pen.Color:=$7D5744;
 randomize;

 iiz1:=Round((-19)*CosineArray^[Angle]-(0)*SineArray^[Angle])+XPos;
 iiz2:=Round((-19)*SineArray^[Angle]+(0)*CosineArray^[Angle])+YPos;
 
 Canvas.Ellipse(iiz1-3,iiz2-3,iiz1+4,iiz2+4);

 iiz1:=Round((-23)*CosineArray^[Angle]-(0)*SineArray^[Angle])+XPos;
 iiz2:=Round((-23)*SineArray^[Angle]+(0)*CosineArray^[Angle])+YPos;
 Canvas.Ellipse(iiz1-2,iiz2-2,iiz1+3,iiz2+3);

 GI._Shadow_II.Draw_shadow(canvas,canvas, Round((-23)*CosineArray^[Angle])+XPos-20,Round((-23)*SineArray^[Angle])+YPos-20);

 end;
 end; end;

 _bax:=false;

 Canvas.TextOut(xpos,ypos+5,inttostr(trunc(_level)));
 Canvas.TextOut(xpos,ypos+16,inttostr(_killed));
 except
 end;
end;

procedure TBaseCenter.Draw_mine(canvas,canvas_b:Tcanvas);
var i:integer;
begin
for i:=0 to mine_count-1 do
if (_mine[i].use) then begin
  canvas.Brush.Style:=bsSolid;
  canvas.Brush.Color:=clblack;
  canvas.pen.Color:=clblack;
 if _mine[i].activated then begin //мож бахнем?
    _mine[i].use:=false;
    _mine[i].enabled:=false;
  GI._Shadow_Ext.Draw_shadow_Dark(canvas_b,canvas_b,_mine[i].Coo.X-15,_mine[i].Coo.Y-15);
  SB_mine.Stop;
  SB_mine._playing:=true;
  SB_mine.play(12);
  GI._Shadow_Mine.Draw_shadow_EXT(canvas,canvas,_mine[i].Coo.X-30,_mine[i].Coo.Y-30);
  // обязательно бахнем
  _xz:=5+random(2);  _yz:=5+random(2);
 end;
  canvas.MoveTo(_mine[i].Coo.X-5,_mine[i].Coo.Y-5);  canvas.LineTo(_mine[i].Coo.X+6,_mine[i].Coo.Y+6);
  canvas.MoveTo(_mine[i].Coo.X-5,_mine[i].Coo.Y+6);  canvas.LineTo(_mine[i].Coo.X+6,_mine[i].Coo.Y-5);
  canvas.Ellipse(_mine[i].Coo.X-3,_mine[i].Coo.Y-3,_mine[i].Coo.X+4,_mine[i].Coo.Y+4);
 if not(_mine[i]._timer_enabled) then begin
  _mine[i]._light:=_mine[i]._light+1;
  if _mine[i]._light<50 then canvas.Brush.Color:=clgreen else begin canvas.Brush.Color:=cllime;
  _mine[i]._light:=0;  end; 
  end else canvas.Brush.Color:=clred;

  canvas.Ellipse(_mine[i].Coo.X-1,_mine[i].Coo.Y-1,_mine[i].Coo.X+3,_mine[i].Coo.Y+3);
end;
end;

procedure TBaseCenter.Mine_AI(var CE:TContenerEnemy);
var i,ii:integer; TE:TEnemy;
begin
 if CE.List.Size<>0 then
 for i:=0 to (CE.List.Size div sizeof(TEnemy))-1 do begin
  CE.List.Position:=sizeof(TEnemy)*i;
  CE.List.ReadBuffer(te,sizeof(TEnemy));

 if te._use then
  for ii:=0 to mine_count-1 do
   if (_mine[ii].use)and(_mine[ii].enabled) then  begin

    if GetTrace(_mine[ii].Coo.X,_mine[ii].Coo.Y,trunc(te.XPos),trunc(te.YPos))<25
      then  _mine[ii]._timer_enabled:=true;

     

    if (_mine[ii]._timer<=0)and(GetTrace(_mine[ii].Coo.X,_mine[ii].Coo.Y,trunc(te.XPos),trunc(te.YPos))<30)
      then begin

  // _mine[ii].use:=false;

   _killed:=_killed+1;
  // _mine[ii]._timer:=50;
   
   te._use:=false;
   CE._more:=CE._more+1;

   CE.List.Position:=sizeof(TEnemy)*i;
   CE.List.WriteBuffer(te,sizeof(TEnemy));
   end;

   end;
 end;
                            
 for ii:=0 to mine_count-1 do
   if (_mine[ii].use)and(_mine[ii].enabled) then  begin

   if _mine[ii]._timer_enabled then _mine[ii]._timer:=_mine[ii]._timer-1;

   if (_mine[ii]._timer<0) then begin
     //_mine[ii].use:=false;
    // _mine[ii].enabled:=false;
     _mine[ii].activated:=true;
   end; end;
end;

procedure TBaseCenter.Add_mine(x,y:integer);
var i:integer;
begin
for i:=0 to mine_count-1 do
if not(_mine[i].use) then begin
  _mine[i].use:=true;
  _mine[i].activated:=false;
  _mine[i].enabled:=true;
  _mine[i].Coo.X:=x;
  _mine[i].Coo.Y:=y;
  _mine[i]._timer:=20;
  _mine[i]._timer_enabled:=false;
  SB_mine.Stop;
  SB_mine._playing:=true;
  SB_mine.play(11);
  exit;
end;
end;

procedure TBaseCenter._Rotate(Degrees: Integer; var TB:Tbase);
var iangle:integer; _b:boolean;
begin
with TB do begin
 if Angle<180 then begin
  iangle:=Angle+180;
  if (Degrees>=Angle)and(Degrees<iangle) then _b:=true else _b:=false;
 end else begin
  iangle:=Angle-180;
  if (Degrees<Angle)and(Degrees>=iangle) then _b:=false else _b:=true;
 end;
 if _b then begin  //против часовой
    if (Angle+_velos>=360) then begin
    Angle:=round(Angle+_velos-360);
  end else
    Angle:=round(Angle+_velos);
 end else begin            //по часовой

    if (Angle-_velos<0) then begin
      if Angle-Degrees<_velos then Angle:=Angle-(Angle-Degrees)+360 else
    Angle:=round(Angle-_velos+360)
  end else begin
      if Angle-Degrees<_velos then Angle:=Angle-(Angle-Degrees) else
    Angle:=round(Angle-_velos);
  end;

 end;  end;
end;

procedure TBaseCenter.CurRotate(x,y:integer);
var iii:integer;
begin
iii:=GetTrace(XPos,YPos,x,y);
if (iii<iii+1)and(iii<=_radius)and(iii+1>0) then begin
  _active:=true;
  _x:=x;
  _y:=y;
  end else _active:=false;
end;              //angle:=GetAngle(xpos,ypos,x,y);_Rotate(angle);

function getplace(angle,a2:integer):boolean;
var iangle:integer;
begin
 iangle:=Angle-a2;
 result:=false;
 if ((iangle>2)and(iangle>0))or((iangle<-2)and(iangle<0)) then result:=true;
end;

procedure TBaseCenter.AI;
var ii:integer;
begin
 _wait:=false;
if _level>1 then begin
 ii:=GetAngle(_weapon1.XPos,_weapon1.YPos,_x,_y);
 if (ii<>_weapon1.angle) then begin
 _Rotate(ii, _weapon1);
 if getplace(_weapon1.angle,ii) then
 _wait:=true;_weapon1._rot:=true;
 end else _weapon1._rot:=false; end;

 ii:=GetAngle(_weapon2.XPos,_weapon2.YPos,_x,_y);
 if (ii<>_weapon2.angle) then begin
 _Rotate(ii, _weapon2);
 if getplace(_weapon2.angle,ii) then
 _wait:=true; _weapon2._rot:=true;
 end else _weapon2._rot:=false;

if _level>4 then begin
 ii:=GetAngle(_weapon3.XPos,_weapon3.YPos,_x,_y);
 if (ii<>_weapon3.angle) then begin
 _Rotate(ii, _weapon3);
 if getplace(_weapon3.angle,ii) then
 _wait:=true; _weapon3._rot:=true;
 end else _weapon3._rot:=false; end;

if _level>8 then begin
 ii:=GetAngle(_weapon4.XPos,_weapon4.YPos,_x,_y);
 if (ii<>_weapon4.angle) then begin
 _Rotate(ii, _weapon4);
 if getplace(_weapon4.angle,ii) then
 _wait:=true; _weapon4._rot:=true;
 end else _weapon4._rot:=false; end;

 _refire:=_refire+1;
 if ammo<=0 then begin
  if _reload>0 then _reload:=_reload-1 else  begin
    _reload:=35;
    ammo:=1+(trunc(_level) div 2);
  end;
  _wait:=true;
 end;
end;

procedure TBaseCenter.CoordBax(var _mm:TContenerEnemy; x,y:integer);
var i:integer; TE:TEnemy;
begin
if _mm.List.Size<>0 then
 for i:=0 to (_mm.List.Size div sizeof(TEnemy))-1 do begin
  _mm.List.Position:=sizeof(TEnemy)*i;
  _mm.List.ReadBuffer(te,sizeof(TEnemy));
 if te._use then
 if inrect(trunc(te.XPos),trunc(te.yPos),x-5,y-5,x+5,y+5) then begin
  te.helth:=te.helth-20-random(20);
  if _level>4 then
  te.helth:=te.helth-10-random(20);
  if _level>8 then
  te.helth:=te.helth-10-random(20);
  if te.helth<0 then begin
   _level:=_level+0.15;
   _killed:=_killed+1;
   te._use:=false;
   _mm._more:=_mm._more+1;
  end;
  _mm.List.Position:=sizeof(TEnemy)*i;
  _mm.List.WriteBuffer(te,sizeof(TEnemy));
 end;
 end;
end;

procedure Bux(TB:TBase; x,y:integer; b_canvas:Tcanvas);
var iiz1,iiz2,iix,iiy:integer;
begin
randomize;
   b_canvas.Pen.Color:=$4A8788+random(120);
   iix:=Round((-2)*CosineArray^[TB.Angle]-(-10-random(13)-random(5))*SineArray^[TB.Angle])+TB.XPos;
   iiy:=Round((-2)*SineArray^[TB.Angle]+(-10-random(13)-random(5))*CosineArray^[TB.Angle])+TB.YPos;
   iiz1:=random(9)-4;
   iiz2:=random(9)-4;
   b_canvas.MoveTo(iix+iiz1,iiy+iiz2);
   b_canvas.lineTo(iix,iiy);
   b_canvas.Pen.Color:=$A0E18;
   b_canvas.brush.Color:=$A0E18;

//Draw_Ba_Bax(b_canvas,x+random(13)-6,y+random(13)-6);
end;

procedure TBaseCenter.Fire(var _mm:TContenerEnemy; x,y:integer; Canvas,b_canvas:Tcanvas);
var iii,iiz1,iiz2,iix,iiy:integer;
begin
if _refire<0 then exit;
_refire:=-25;
iii:=GetTrace(XPos,YPos,x,y);
if ((iii<iii+1)and(iii<=_radius)and(iii+1>0))and(not(_wait))and(_active) then begin
 CoordBax(_mm,x,y);
 if _level>10 then _level:=10;
  if ammo>0 then begin
    _bax:=true;
    ammo:=ammo-1;
    Bux(_weapon2, x,y,b_canvas);
 if _level>4 then begin
    Bux(_weapon3, x,y,b_canvas);
  end;
 if _level>8 then begin
    Bux(_weapon4, x,y,b_canvas);
  end;
    Draw_Ba_Bax(b_canvas,x+random(9)-4,y+random(9)-4);


    sb._playing:=true;
    SB.play(10);
  end;
end;
end;

procedure TBaseCenter.Init;
var i:integer;
begin
 _reload:=0;
 _refire:=0;
 _radius:=350;
 _sector:=2;
 Ammo:=0;
 angle:=0;
 _visible:=false;
 _level:=0;
 _killed:=0;
 _active:=false;
 _x:=0;
 _y:=0;
 _wait:=false;
 _bax:=false;
 xpos:=640;
 ypos:=512;
 for i:=0 to 7 do begin
  _mine[i].use:=false;
  _mine[i]._light:=0;
  _mine[i].enabled:=false;
  _mine[i]._timer:=50;
  _mine[i]._timer_enabled:=false;
  end;
 _Weapon1:=Tbase.Create;
 _Weapon1.XPos:=xpos+30;
 _Weapon1.YPos:=ypos+30;
 _Weapon1.Angle:=0;
 _Weapon1._velos:=5.8;
 _Weapon2:=Tbase.Create;
 _Weapon2.XPos:=xpos-30;
 _Weapon2.YPos:=ypos-30;
 _Weapon2.Angle:=0;
 _Weapon2._velos:=4.1;
 _Weapon3:=Tbase.Create;
 _Weapon3.XPos:=xpos-30;
 _Weapon3.YPos:=ypos+30;
 _Weapon3.Angle:=0;
 _Weapon3._velos:=3.9;
 _Weapon4:=Tbase.Create;
 _Weapon4.XPos:=xpos+30;
 _Weapon4.YPos:=ypos-30;
 _Weapon4.Angle:=0;
 _Weapon4._velos:=3.8;
 SB:=TsoundBlock.Create;
 SB._on:=true;
 SB._loop:=false;
 SB._playing:=false;
 SB.Channel:=0;

 SB_mine:=TsoundBlock.Create;
 SB_mine._on:=true;
 SB_mine._fast_stop:=false;
 SB_mine._loop:=false;
 SB_mine._playing:=false;
end;

procedure TBaseHouse.Init;
begin
 x:=640;
 y:=512;
 shield:=200;
 helth:=100;
 angle:=0;
 _energy:=true;
 _energy_level:=0;
 _radar:=False;
 _visible:=false;
 _active:=false;
end;

procedure TBaseHouse.Energy(_b:boolean);
var i:integer;
begin
 if _energy then
 if _b then begin    //shield,helth
 shield:=shield+2;
 helth:=helth+1;
 end;//  else _energy_level:=_energy_level-17;
 if _energy_level<256 then begin
 if _energy_level<0 then _energy_level:=0;
 _radar:=false;

 end;

 if shield>1024 then shield:=1024;
 if helth>1024 then helth:=1024;
 if shield<0 then shield:=0;
end;


procedure TBaseHouse.Draw(canvas:Tcanvas);
begin
 try
  canvas.pen.Color:=clred;
  canvas.Ellipse(x-5,y-5,x+5,y+5);



  except
 end;
end;




function TWeapon.Fire(x,y:integer; canvas,b_canvas:Tcanvas):integer;
var ix,iy,iix,iiy,iiz1,iiz2:integer;
begin
result:=0;
case _type of

 twdgun: begin

   if _level>8 then _level:=8;
  if _reload>0 then begin
    ammo:=ammo-1;
    if _refire>0 then _refire:=_refire-1 else begin

    Canvas.Pen.Color:=clyellow;
    Canvas.brush.Color:=clyellow;

    sb._playing:=true;
    iiz1:=Round((-18)*CosineArray^[Angle]-(-8)*SineArray^[Angle])+XPos;
    iiz2:=Round((-18)*SineArray^[Angle]+(-8)*CosineArray^[Angle])+YPos;
  Canvas.Ellipse(iiz1-2,iiz2-2,iiz1+3,iiz2+3);

    iiz1:=Round((-13)*CosineArray^[Angle]-(-10)*SineArray^[Angle])+XPos;
    iiz2:=Round((-13)*SineArray^[Angle]+(-10)*CosineArray^[Angle])+YPos;
  Canvas.Ellipse(iiz1-2,iiz2-2,iiz1+3,iiz2+3);

  iiz1:=Round((-18)*CosineArray^[Angle]-(8)*SineArray^[Angle])+XPos;
    iiz2:=Round((-18)*SineArray^[Angle]+(8)*CosineArray^[Angle])+YPos;
  Canvas.Ellipse(iiz1-2,iiz2-2,iiz1+3,iiz2+3);

    iiz1:=Round((-13)*CosineArray^[Angle]-(10)*SineArray^[Angle])+XPos;
    iiz2:=Round((-13)*SineArray^[Angle]+(10)*CosineArray^[Angle])+YPos;
  Canvas.Ellipse(iiz1-2,iiz2-2,iiz1+3,iiz2+3);

   GI._Shadow_II.Draw_shadow(canvas,canvas,Round((-15)*CosineArray^[Angle]-(-9)*SineArray^[Angle])-20+XPos,Round((-15)*SineArray^[Angle]+(-9)*CosineArray^[Angle])+YPos-20);
   GI._Shadow_II.Draw_shadow(canvas,canvas,Round((-15)*CosineArray^[Angle]-(9)*SineArray^[Angle])-20+XPos,Round((-15)*SineArray^[Angle]+(9)*CosineArray^[Angle])+YPos-20);

     Canvas.Pen.Color:=$185E74;
 if random(5)=4 then begin
  Canvas.Pen.Color:=$3F8383;
   Canvas.MoveTo(
   Round(XPos+(1*CosineArray^[Angle]-(-10)*SineArray^[Angle])),
   Round(YPos-(1*SineArray^[Angle]-(-10)*CosineArray^[Angle])));
   randomize;
   ix:=x+random(4)-2;iy:=y+random(4)-2;
   Canvas.lineTo(ix,iy);
  end;

  case random(2) of
   0: b_canvas.Pen.Color:=$0;
   1: b_canvas.Pen.Color:=$A0E18;
  end;

 for iiz1:=0 to 3 do begin
   ix:=x+random(7)-3;iy:=y+random(7)-3;
   b_canvas.Ellipse(ix-1,iy-1,ix+1,iy+1);
 end;

  if random(3)=2 then begin
   Canvas.MoveTo(
   Round(XPos+(1*CosineArray^[Angle]-(-8)*SineArray^[Angle])),
   Round(YPos-(1*SineArray^[Angle]-(-8)*CosineArray^[Angle])));
   ix:=x+random(8)-4;iy:=y+random(8)-4;
   Canvas.lineTo(ix,iy); end;

   b_canvas.Pen.Color:=$A0E18;
   b_canvas.Ellipse(ix-1,iy-1,ix+1,iy+1);


  if random(3)=2 then begin
   Canvas.MoveTo(
   Round(XPos+(1*CosineArray^[Angle]-(8)*SineArray^[Angle])),
   Round(YPos-(1*SineArray^[Angle]-(8)*CosineArray^[Angle])));
   ix:=x+random(8)-4;iy:=y+random(8)-4;
   Canvas.lineTo(ix,iy);
   b_canvas.Ellipse(ix-1,iy-1,ix+1,iy+1); end;
  if random(5)=4 then begin
   Canvas.MoveTo(
   Round(XPos+(1*CosineArray^[Angle]-(10)*SineArray^[Angle])),
   Round(YPos-(1*SineArray^[Angle]-(10)*CosineArray^[Angle])));
   ix:=x+random(8)-4;iy:=y+random(8)-4;
   Canvas.lineTo(ix,iy);
   b_canvas.Ellipse(ix-1,iy-1,ix+1,iy+1);   end;

   b_canvas.Pixels[
   Round(XPos+(1*CosineArray^[Angle]-(-18+random(10)-random(12))*SineArray^[Angle])),
   Round(YPos-(1*SineArray^[Angle]-(-18+random(10)-random(12))*CosineArray^[Angle]))]:=$4A8788+random(120);
   b_canvas.Pixels[
   Round(XPos+(1*CosineArray^[Angle]-(15+random(10)-random(12))*SineArray^[Angle])),
   Round(YPos-(1*SineArray^[Angle]-(15+random(10)-random(12))*CosineArray^[Angle]))]:=$4A8788+random(120);


   result:=random(7)+1+trunc(_level)*1;
    _refire:=1;
   end;
   if ammo<=0 then begin
  _reload:=-45;
  ammo:=200+trunc(_level)*12;
  end;
  end else _reload:=_reload+1;
 end;

 twgun: begin
 
 if _level>2 then begin
  Canvas.Pen.Color:=$E1F7E;
  Canvas.MoveTo(
  Round(XPos+(1*CosineArray^[Angle]-(4)*SineArray^[Angle])),
  Round(YPos-(1*SineArray^[Angle]-(4)*CosineArray^[Angle])));
  Canvas.lineTo(x,y);
 end;
  if _level>4 then _level:=4;
  if _reload>0 then begin
    ammo:=ammo-1;
    if _refire>0 then _refire:=_refire-1 else begin
    sb._playing:=true;
    Canvas.Pen.Color:=$3F8383;
    Canvas.brush.Color:=clyellow;
    randomize;

    iiz1:=Round((-17)*CosineArray^[Angle])+XPos;
    iiz2:=Round((-17)*SineArray^[Angle])+YPos;
  Canvas.Ellipse(iiz1-2,iiz2-2,iiz1+3,iiz2+3);
    GI._Shadow_II.Draw_shadow(canvas,canvas,Round((-17)*CosineArray^[Angle]-20+XPos),Round((-17)*SineArray^[Angle])+YPos-20);


     if random(6)=5 then begin
    Canvas.MoveTo(xPos,yPos);
    ix:=x+random(4)-2;iy:=y+random(2)-2;
   Canvas.lineTo(ix,iy); end;

   b_canvas.Pixels[
   Round(XPos+(1*CosineArray^[Angle]-(-15+random(10)-random(12))*SineArray^[Angle])),
   Round(YPos-(1*SineArray^[Angle]-(-15+random(10)-random(12))*CosineArray^[Angle]))]:=$4A8788+random(120);
  case random(2) of
   0: b_canvas.Pen.Color:=$0;
   1: b_canvas.Pen.Color:=$A0E18;
  end;
   b_canvas.Ellipse(x-1,y-1,x+1,y+1);
    result:=random(4)+trunc(_level);
    _refire:=1;
   end;
   if ammo<=0 then begin
  _reload:=-25;
  ammo:=85+trunc(_level)*10;
  end;
  end else _reload:=_reload+1;
 end;
   twsnipergun: begin
   if _level>5 then _level:=5;
    Canvas.Pen.Color:=$E1F7E;
    Canvas.MoveTo(
    Round(XPos+(1*CosineArray^[Angle]-(4)*SineArray^[Angle])),
    Round(YPos-(1*SineArray^[Angle]-(4)*CosineArray^[Angle])));
    Canvas.lineTo(x,y);
  if _reload>0 then begin
    ammo:=ammo-1;
    if _refire>0 then _refire:=_refire-1 else begin
    Canvas.Pen.Color:=$3F8383;
    Canvas.brush.Color:=clyellow;
    sb._playing:=true;
    randomize;
    Canvas.MoveTo(
    Round(XPos+(1*CosineArray^[Angle]-(-3)*SineArray^[Angle])),
    Round(YPos-(1*SineArray^[Angle]-(-3)*CosineArray^[Angle])));
    ix:=x+random(4)-2;iy:=y+random(2)-2;
   Canvas.lineTo(ix,iy);

   iiz1:=Round((-19)*CosineArray^[Angle]-(-4)*SineArray^[Angle])+XPos;
   iiz2:=Round((-19)*SineArray^[Angle]+(-4)*CosineArray^[Angle])+YPos;
   Canvas.Ellipse(iiz1-2,iiz2-2,iiz1+3,iiz2+3);
    GI._Shadow_I.Draw_shadow(canvas,canvas,Round((-19)*CosineArray^[Angle]-(-4)*SineArray^[Angle])-15+XPos,Round((-19)*SineArray^[Angle]+(-4)*CosineArray^[Angle])+YPos-15);


   b_canvas.Pixels[
   Round(XPos+(1*CosineArray^[Angle]-(-19+random(10)-random(12))*SineArray^[Angle])),
   Round(YPos-(1*SineArray^[Angle]-(-19+random(10)-random(12))*CosineArray^[Angle]))]:=$4A8788+random(120);
 //  Paint_dead_small(x,y,0,b_canvas);
  case random(2) of
   0: begin b_canvas.Pen.Color:=$0; b_canvas.brush.Color:=$0; end;
   1: begin b_canvas.Pen.Color:=$A0E18; b_canvas.brush.Color:=$A0E18; end;
  end;
    b_canvas.Ellipse(ix-1,iy-1,ix+2,iy+2);
    result:=random(8)+22+trunc(_level)*2;
    _refire:=5;
    sb._playing:=true;
   end;
   if ammo<=0 then begin
  _reload:=-45;
   sb._playing:=true;
  ammo:=7+trunc(_level);
  end;
  end else _reload:=_reload+1;
 end;
 twbazooka: begin
  if _level>8 then _level:=8;

  if _reload>0 then begin
    ammo:=ammo-1;                //9671424
    if _refire>0 then _refire:=_refire-1 else begin
    sb._playing:=true;
    Canvas.Pen.Color:=$7D5744;
    Canvas.brush.Color:=clyellow;
    randomize;
    Canvas.MoveTo(xPos,yPos);
    ix:=x+random(4)-2;iy:=y+random(2)-2;
   Canvas.lineTo(ix,iy);
    GI._Shadow_Ext.Draw_shadow_EXT(canvas,canvas,ix-15,iy-15);


   iiz1:=Round((-22)*CosineArray^[Angle])+XPos;
   iiz2:=Round((-22)*SineArray^[Angle])+YPos;
   Canvas.Ellipse(iiz1-3,iiz2-3,iiz1+4,iiz2+4);
   Canvas.Pen.Color:=clyellow;
   iiz1:=Round((-25)*CosineArray^[Angle])+XPos;
   iiz2:=Round((-25)*SineArray^[Angle])+YPos;
   Canvas.Ellipse(iiz1-1,iiz2-1,iiz1+2,iiz2+2);
   GI._Shadow_II.Draw_shadow(canvas,canvas,Round((-23)*CosineArray^[Angle])-20+XPos,Round((-23)*SineArray^[Angle])+YPos-20);

    b_canvas.Pen.Color:=$4A8788+random(120);
  randomize;
   iix:=Round(XPos+(1*CosineArray^[Angle]-(-15+random(10)-random(12))*SineArray^[Angle]));
   iiy:=Round(YPos-(1*SineArray^[Angle]-(-15+random(10)-random(12))*CosineArray^[Angle]));
   iiz1:=random(9)-4;
   iiz2:=random(9)-4;
   
   b_canvas.MoveTo(iix+iiz1,iiy+iiz2);
   b_canvas.lineTo(iix,iiy);
 {  mainForm.BT_back.Canvas.Pixels[
   ,
   ]:=$4A8788+random(120);}

  b_canvas.Pen.Color:=$A0E18;
  b_canvas.brush.Color:=$A0E18;
  Draw_Ba_Bax(b_canvas,x,y);
 // mainForm.BT_back.Canvas.Ellipse(x-2,y-2,x+3,y+3);

  // mainForm.BT_back.Canvas.Ellipse(ix-1,iy-1,ix+1,iy+1);
    result:=random(48)+15+trunc(_level)*3;
    _refire:=1;
   end;
   if ammo<=0 then begin
  if _level>3 then _reload:=-18 else _reload:=-28;
  ammo:=1;
  end;
  end else _reload:=_reload+1;
 end;

 twdliser: begin
  if _level>8 then _level:=8;
  if _refire>0 then _refire:=_refire-1 else begin

   Canvas.Pen.Color:=$4040FF;
   Canvas.brush.Color:=$8484FF;
   randomize;
   sb._playing:=true;
   iiz1:=Round((-17)*CosineArray^[Angle]-(-5)*SineArray^[Angle])+XPos;
   iiz2:=Round((-17)*SineArray^[Angle]+(-5)*CosineArray^[Angle])+YPos;
   Canvas.Ellipse(iiz1-2,iiz2-2,iiz1+3,iiz2+3);
   iiz1:=Round((-17)*CosineArray^[Angle]-(5)*SineArray^[Angle])+XPos;
   iiz2:=Round((-17)*SineArray^[Angle]+(5)*CosineArray^[Angle])+YPos;
   Canvas.Ellipse(iiz1-2,iiz2-2,iiz1+3,iiz2+3);

   GI._Shadow_I.Draw_shadow(canvas,canvas,Round((-17)*CosineArray^[Angle]-(-5)*SineArray^[Angle])-15+XPos,Round((-17)*SineArray^[Angle]+(-5)*CosineArray^[Angle])+YPos-15);
   GI._Shadow_I.Draw_shadow(canvas,canvas,Round((-17)*CosineArray^[Angle]-(5)*SineArray^[Angle])-15+XPos,Round((-17)*SineArray^[Angle]+(5)*CosineArray^[Angle])+YPos-15);


   Canvas.MoveTo(
   Round(XPos+((-17)*CosineArray^[Angle]-(-5)*SineArray^[Angle])),
   Round(YPos+((-17)*SineArray^[Angle]+(-5)*CosineArray^[Angle])));
   ix:=x+random(4)-2;iy:=y+random(2)-2;
   Canvas.lineTo(ix,iy);
  case random(2) of
   0: b_canvas.Pen.Color:=$0;
   1: b_canvas.Pen.Color:=$A0E18;
  end;
   b_canvas.Ellipse(ix-1,iy-1,ix+1,iy+1);
   Canvas.MoveTo(
   Round(XPos+((-17)*CosineArray^[Angle]-(5)*SineArray^[Angle])),
   Round(YPos+((-17)*SineArray^[Angle]+(5)*CosineArray^[Angle])));
   ix:=x+random(4)-2;iy:=y+random(2)-2;
   Canvas.lineTo(ix,iy);
  case random(2) of
   0: b_canvas.Pen.Color:=$0;
   1: b_canvas.Pen.Color:=$A0E18;
  end;
   b_canvas.Ellipse(ix-1,iy-1,ix+1,iy+1);

   _refire:=3;
   result:=random(5)+2+trunc(_level)*2;
  end;
 end;
 twliser: begin
  if _level>4 then _level:=4;
  if _refire>0 then _refire:=_refire-1 else begin
  // mainForm.FOffscreenBuffer.Canvas.Pen.Color:=$4B27B8;

   

   Canvas.Pen.Color:=$4040FF;
   Canvas.brush.Color:=$8484FF;
   sb._playing:=true;
   iiz1:=Round((-16)*CosineArray^[Angle])+XPos;
   iiz2:=Round((-16)*SineArray^[Angle])+YPos;
   Canvas.Ellipse(iiz1-2,iiz2-2,iiz1+3,iiz2+3);
   GI._Shadow_I.Draw_shadow(canvas,canvas,Round((-16)*CosineArray^[Angle])-15+XPos,Round((-16)*SineArray^[Angle])+YPos-15);

   Canvas.MoveTo(XPos,YPos);
   randomize;
   ix:=x+random(4)-2;iy:=y+random(4)-2;
  // mainForm.FOffscreenBuffer.canvas.pen.Style:=psDash;
   Canvas.lineTo(ix,iy);
  // mainForm.FOffscreenBuffer.canvas.pen.Style:=psSolid;
  case random(2) of
   0: b_canvas.Pen.Color:=$0;
   1: b_canvas.Pen.Color:=$A0E18;
  end;
   b_canvas.Ellipse(ix-1,iy-1,ix+1,iy+1);

   result:=random(2)+1+trunc(_level)*2;
   _refire:=3;
  end;
 end;
end;
end;

procedure TWeapon.Rotate(Degrees: Integer);
var iangle:integer; _b:boolean;
begin
//извращаемси :)
 if Angle<180 then begin
  iangle:=Angle+180;
  if (Degrees>=Angle)and(Degrees<iangle) then _b:=true else _b:=false;
 end else begin
  iangle:=Angle-180;
  if (Degrees<Angle)and(Degrees>=iangle) then _b:=false else _b:=true;
 end;
 if _b then begin  //против часовой
    if (Angle+_speed_rot>=359) then begin
    Angle:=Angle+_speed_rot-360;
  end else
    Angle:=Angle+_speed_rot;
 end else begin            //по часовой
    if (Angle-_speed_rot<0) then begin
      if Angle-Degrees<_speed_rot then Angle:=Angle-(Angle-Degrees)+360 else
    Angle:=Angle-_speed_rot+360
  end else begin
      if Angle-Degrees<_speed_rot then Angle:=Angle-(Angle-Degrees) else
    Angle:=Angle-_speed_rot;
  end;
 end;
end;

procedure TSoundBlock._Sound(s:string; Handle:HWND; vol:DWORD);
var ii,iii,iiii,iv:DWORD;
Begin
  BASS_Init(1, 22050, 0, Handle, nil);
 // BASS_Stop;  //фигня какая-то, останавливает весь БАСС а мне надо только канал
 // Bass_Start;
  BASS_StreamFree(Channel);
  BASS_SetConfig( BASS_CONFIG_GVOL_STREAM,vol);
  Channel := BASS_StreamCreateFile(FALSE, Pchar(s), 0, 0,BASS_MUSIC_RAMP );
  BASS_ChannelPlay(Channel,true);

end;

function TSoundBlock.Get_playing(i:integer):boolean;
var ii,i_delay:int64;
begin
if _fast_stop then begin //тиа прерывание звука другим. не пашет вроде
  result:=false;
  _fast_stop:=false;
  BASS_ChannelStop(Channel);
  exit;
end;
ii:=BASS_StreamGetLength(Channel); //+(ii*0.1)
if ii>0 then begin
i_delay:=0;
case i of
1: i_delay:=0;
3: i_delay:=0;
end;

if ii>BASS_ChannelGetPosition(Channel)+i_delay then
result:=true else begin
 result:=false;
 BASS_ChannelStop(Channel);
 end;

end else result:=false;
end;

function TSoundBlock.getpos:integer;
begin
result:=trunc(BASS_ChannelGetPosition(Channel)/1000);
end;

procedure TSoundBlock.Stop;
var i:integer;
begin
//i:=BASS_StreamGetLength(Channel);
//BASS_ChannelSetPosition(Channel,i);
//BASS_ChannelStop(Channel);
_fast_stop:=true;

end;

procedure TSoundBlock.play(i:Integer);
begin
 if not(_loop)and not(_playing) then exit;
 if (_playing) then
 if not(Get_playing(i)) then begin
   case i of
     1:_Sound(_direc+'sound\act_weap.wav',_Handle,5);
     2:_Sound(_direc+'sound\twbazooka.wav',_Handle,15);
     3:_Sound(_direc+'sound\twgun.wav',_Handle,9);
     4:_Sound(_direc+'sound\twdliser.wav',_Handle,9);
     5:_Sound(_direc+'sound\twliser.wav',_Handle,9);
     6:_Sound(_direc+'sound\twsniper.wav',_Handle,25);
     7:_Sound(_direc+'sound\twdgun.wav',_Handle,15);
     10:_Sound(_direc+'sound\twbase.wav',_Handle,15);
     11:_Sound(_direc+'sound\mine_install.wav',_Handle,15);
     12:_Sound(_direc+'sound\mine_expl.wav',_Handle,15);  //конкретный бабах
   end;
  end;
 _playing:=false;
end;


end.

