unit Explotion;

interface

Uses
 Windows;
Type


 TPixel=class
 private
    FAlpha: Extended;
    FStartSpeed: Extended;
    FXpixel: Integer;
    FYPixel: Integer;
    FTime: Extended;
    FGravity: Extended;
    FiSpr: Integer;
    FTimeLife: Integer;
    procedure SetStartSpeed(const Value: Extended);
    procedure ReMath;
    procedure SetTime(const Value: Extended);
    procedure SetGravity(const Value: Extended);
    procedure SetAlpha(const Value: Extended);
    procedure SetiSpr(const Value: Integer);
    procedure SetTimeLife(const Value: Integer);

 public
    constructor Create;
    property Time:Extended read FTime write SetTime;
    property Alpha:Extended read FAlpha write SetAlpha;
    property StartSpeed:Extended read FStartSpeed write SetStartSpeed;
    property Gravity:Extended read FGravity write SetGravity;
    property Xpixel:Integer read FXpixel;
    property YPixel:Integer read FYPixel;
    property iSpr:Integer read FiSpr write SetiSpr;
    property TimeLife:Integer read FTimeLife write SetTimeLife;
 end;

 TPixels = array [0..32200] of TPixel;

 TFlash = Class
 private
    FPixels:TPixels;
    FPixelsCount:Integer;
    FTimer:Extended;
    FTimerCount: Extended;
    FMaxTime: Extended;
    FLifeOff: Boolean;

    function GetPixels(index: Integer): TPixel;
    procedure SetTimerCount(const Value: Extended);
    procedure SetMaxTime(const Value: Extended);
    procedure SetPixelsCount(const Value: Integer);
    procedure SetLifeOff(const Value: Boolean);
 public
    constructor Create;
    property Pixels[index:Integer]:TPixel read GetPixels;
    property TimerCount:Extended read FTimerCount write SetTimerCount;
    property MaxTime:Extended read FMaxTime write SetMaxTime;
    property PixelsCount:Integer read FPixelsCount write SetPixelsCount;
    property LifeOff:Boolean read FLifeOff write SetLifeOff;
    procedure Add(StartSpeed,Alpha:Extended);
    procedure Math;

 end;

implementation


{ TMapthPixel }

constructor TPixel.Create;
begin
  FGravity:=0.98;
  FXPixel:=0;
  FYPixel:=0;
  FTimeLife:=100;
end;

procedure TPixel.ReMath;
begin
  FXpixel:=Round(FStartSpeed*Cos(FAlpha)*FTime);
  FYpixel:=Round(FStartSpeed*Sin(FAlpha)*FTime-(FGravity*FTime*FTime)/2);
 { If Sqrt(FXpixel*FXpixel+FYpixel*FYpixel)>3400 Then
   FTime:=0;}
end;


procedure TPixel.SetAlpha(const Value: Extended);
begin
  FAlpha := Value;
  ReMath;
end;

procedure TPixel.SetGravity(const Value: Extended);
begin
  FGravity := Value;
  ReMath;
end;

procedure TPixel.SetiSpr(const Value: Integer);
begin
  FiSpr := Value;
end;

procedure TPixel.SetStartSpeed(const Value: Extended);
begin
  FStartSpeed := Value;
  ReMath;
end;

procedure TPixel.SetTime(const Value: Extended);
begin
  FTime := Value;
  ReMath;
end;

{ TFlash }

procedure TFlash.Add(StartSpeed, Alpha: Extended);
begin
  FPixels[FPixelsCount]:=TPixel.Create;
  FPixels[FPixelsCount].FAlpha:=Alpha;
  FPixels[FPixelsCount].FStartSpeed:=StartSpeed;
  Inc(FPixelsCount);
end;

constructor TFlash.Create;
begin
  FPixelsCount:=0;
  FTimer:=0;
  FTimerCount:=0.1;
  FMaxTime:=-1;
end;

function TFlash.GetPixels(index: Integer): TPixel;
begin
  result := FPixels[index];
end;

procedure TFlash.Math;
Var
  i:Integer;
begin
  FTimer:=FTimer+FTimerCount;
  If FMaxTime<>-1 Then
    If FTimer>FMaxTime Then
      begin
     {   For i:=0 to FPixelsCount-1 do
          begin
            FPixels[i].FAlpha:=Random(300)+Random(100);
            FPixels[i].FGravity:=Random(4)+3;
            FPixels[i].FStartSpeed:=Random(25)+Random(16);
            //FPixels[i].ReMath;
          end;}
        FTimer:=0;
      end;

  For i:=0 to FPixelsCount-1 do
   begin
//     FPixels[i].FTime:=FTimer;
     FPixels[i].FTime:=FPixels[i].FTime+FTimerCount;
     If FPixels[i].FTime>FPixels[i].FTimeLife Then FPixels[i].FTime:=0;
     FPixels[i].ReMath;
   end;
end;

procedure TFlash.SetLifeOff(const Value: Boolean);
begin
  FLifeOff := Value;
end;

procedure TFlash.SetMaxTime(const Value: Extended);
begin
  FMaxTime := Value;
end;

procedure TFlash.SetPixelsCount(const Value: Integer);
begin
  FPixelsCount := Value;
end;

procedure TFlash.SetTimerCount(const Value: Extended);
begin
  FTimerCount := Value;
end;

procedure TPixel.SetTimeLife(const Value: Integer);
begin
  FTimeLife := Value;
end;

end.
