⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uarrow.pas

📁 一个dos游戏的源代码
💻 PAS
字号:
//极限1000米
//Author: CrazyWill
//Email: CrazyWill@163.com

unit uArrow;

interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ImgList, ExtCtrls, StdCtrls, MMSystem,
  IniFiles, uInclude;

type

  TArrow = class
  private
    FDirection: TDirection;

    FSpeed: Integer; //速度  单位:像素

    FDelay, FDelayCount: Integer;

    FX, FY: Integer; //坐标
    FYMin, FYMax: Integer;

    FWidth: Integer;
    FHeight: Integer;

    FActive: Boolean; //是否进行动作
    FVisible: Boolean; //是否可见
    FRect: TRect; //占用矩形区域

    FHurtPoint: integer; //伤害点数
    FHurtDelay: integer;

    FProbability: double; //出现机率

    FBits, FInvBitmap: TBitmap;

    //取得角色尺寸
    function GetObjectRect: TRect;

  protected

  public

    constructor Create; virtual;
    destructor Destroy; override;
    procedure Draw(Canvas: TCanvas);
    procedure Roll;
    procedure ReSet;

    property X: Integer read FX write FX;
    property Y: Integer read FY write FY;

    property HurtPoint: integer read FHurtPoint write FHurtPoint;
    property Probability: Double read FProbability;

    property Speed: integer read FSpeed write FSpeed;
    property Width: integer read FWidth;
    property Height: integer read FHeight;
    property Active: Boolean read FActive write FActive;

    property Rect: TRect read FRect;
    property ObjectRect: TRect read GetObjectRect;
  end;

implementation

constructor TArrow.Create;
var
  ini: TIniFile;
  sTemp: string;
  iniSection: string;
begin
  inherited Create;
  // 初始化
  iniSection := 'Arrow';

  FActive := False;
  FDirection := drUp;

  FBits := TBitmap.Create;
  FInvBitmap := TBitmap.Create;

  ini := TIniFile.Create(IniDirectory + IniFilename);

  sTemp := ini.ReadString(iniSection, 'Filename', sTemp);
  FBits.LoadFromFile(IniDirectory + sTemp);

  FInvBitmap.Width := FBits.Width;
  FInvBitmap.Height := FBits.Height;

  FInvBitmap.Transparent := True;
  FInvBitmap.TransparentColor := TRANSPARENT_COLOR;
  FInvBitmap.Canvas.Brush.Color := TRANSPARENT_COLOR;

  FSpeed := ini.ReadInteger(iniSection, 'Speed', 1);
  FWidth := ini.ReadInteger(iniSection, 'Width', FWidth);
  FHeight := ini.ReadInteger(iniSection, 'Height', FHeight);

  FDelay := ini.ReadInteger(iniSection, 'Delay', 0);

  FProbability := ini.ReadFloat(iniSection, 'Probability', 0.1);

  FHurtPoint := ini.ReadInteger(iniSection, 'HurtPoint', 0);
  FHurtDelay := ini.ReadInteger(iniSection, 'HurtDelay', 0);

  FX := WORLD_WIDTH;

  FY := ini.ReadInteger('Map', 'Height', 0) - ini.ReadInteger('Map',
    'GroundHeight', 0);

  FYMin := FY - Height;
  FYMax := FY;

  ini.Destroy;
end;

destructor TArrow.Destroy;
begin
  FInvBitmap.Free;
  FBits.Free;
  inherited Destroy;
end;

procedure TArrow.Draw(Canvas: TCanvas);
begin
  FInvBitmap.canvas.FillRect(FInvBitmap.Canvas.ClipRect);

  FInvBitmap.Canvas.CopyRect(
    Classes.Rect(0, 0, Width, FYMax - FY),
    FBits.Canvas,
    Classes.Rect(0, 0, Width, FYMax - FY));

  Canvas.Draw(FX, FY, FInvBitmap);
end;

function TArrow.GetObjectRect: TRect;
begin
  Result := FInvBitmap.Canvas.ClipRect;
end;

procedure TArrow.Roll;
begin
  if not FActive then
    Exit;
  if FSpeed = 0 then
    Exit;

  if (FDelay <> 0) then
  begin
    Inc(FDelayCount);
    if FDelayCount <> FDelay then
      Exit;
    FDelayCount := 0;
  end;

  case FDirection of
    drUp:
      begin
        if (FY - FSpeed) < FYMin then
          FDirection := drDown
        else
          dec(FY, FSpeed);
      end;
    drDown:
      begin
        if FY > FYMax + 12 then
          FDirection := DrUp
        else
          Inc(FY, FSpeed);
      end;
  end;

  if FX < (-Width) then
    ReSet;

  FRect := ObjectRect;
  FRect := classes.Rect(FRect.Left + 5, FRect.Top + 5, FRect.Right - 5,
    FRect.Bottom - 5);
  OffsetRect(FRect, FX, FY);

end;

procedure TArrow.ReSet;
begin
  if Random(Dynameter) * FProbability > 1 then
  begin
    FY := FYMax;
    FDelayCount := 0;
    FX := WORLD_WIDTH;

    FRect := ObjectRect;
    FRect := classes.Rect(FRect.Left + 5, FRect.Top + 5, FRect.Right - 5,
      FRect.Bottom - 5);
    OffsetRect(FRect, FX, Fy);

  end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -