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

📄 ucut.pas

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

unit uCut;

interface

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

type

  TCut = class
  private
    //    FSpeed: Integer;  //速度  单位:像素

    FDelay, FDelayCount: Integer;

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

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

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

    FBits, FInvBitmap: TBitmap;

    Numbers: Integer; //每张角色图片包含几张小图在里面
    CurrentNo: Integer; //当前显示的小图片编号

    //取得角色尺寸
    function GetObjectRect: TRect;
    //取得角色的宽和高
    function GetObjectWidth: Integer;
    function GetObjectHeight: Integer;

  protected

  public

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

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

    property HurtPoint: integer read FHurtPoint write FHurtPoint;

    //    property Speed:integer read FSpeed write FSpeed;

    property Active: Boolean read FActive write FActive;
    property Visible: Boolean read FVisible write FVisible;
    property Rect: TRect read FRect;

    property ObjectRect: TRect read GetObjectRect;
    property ObjectWidth: Integer read GetObjectWidth;
    property ObjectHeight: Integer read GetObjectHeight;

  end;

implementation

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

  FActive := False;
  FVisible := true;

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

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

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

  FInvBitmap.Width := ini.ReadInteger(iniSection, 'Width', FInvBitmap.Width);
  FInvBitmap.Height := ini.ReadInteger(iniSection, 'Height', FInvBitmap.Height);

  FInvBitmap.Transparent := True;
  FInvBitmap.TransparentColor := TRANSPARENT_COLOR;

  Numbers := ini.ReadInteger(iniSection, 'Numbers', 1);
  CurrentNo := 0;

  //  FSpeed:=ini.ReadInteger(iniSection,'Speed',1);

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

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

  FX := 0;

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

  FYMin := FY;
  FYMax := FY + FInvBitmap.Height;

  FRect := classes.Rect(FX, FY, FInvBitmap.Width, FInvBitmap.Height);

  ini.Destroy;
end;

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

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

function TCut.GetObjectWidth: Integer;
begin
  with GetObjectRect do
    Result := Right - Left;
end;

function TCut.GetObjectHeight: Integer;
begin
  with GetObjectRect do
    Result := Bottom - Top;
end;

procedure TCut.Draw(Canvas: TCanvas);
begin
  if not FVisible then
    Exit;

  FInvBitmap.Canvas.CopyRect(ObjectRect, FBits.Canvas,
    Classes.Rect(CurrentNo * ObjectWidth, 0,
    (CurrentNo + 1) * ObjectWidth, ObjectHeight));
  Canvas.Draw(FX, fy, FInvBitmap);
end;

procedure TCut.Cut;
begin
  if not FActive then
    Exit;

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

  CurrentNo := (CurrentNo + 1) mod Numbers;

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

end.

⌨️ 快捷键说明

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