📄 ufire.pas
字号:
//极限1000米
//Author: CrazyWill
//Email: CrazyWill@163.com
unit uFire;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ImgList, ExtCtrls, StdCtrls, MMSystem,
IniFiles, uInclude;
type
TFire = class
private
FSpeed: Integer; //速度 单位:像素
FDelay, FDelayCount: Integer;
FX, FY: Integer; //坐标
FYMin, FYMax: Integer;
FActive: Boolean; //是否进行动作
FVisible: Boolean; //是否可见
FRect: TRect; //占用矩形区域
FHurtPoint: integer; //伤害点数
FHurtDelay: integer;
FProbability: double; //出现机率
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 Drop;
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 Active: Boolean read FActive write FActive;
property Visible: Boolean read FVisible write FVisible;
property Rect: TRect read FRect;
property Width: integer read GetObjectWidth;
property Height: integer read GetObjectHeight;
property ObjectRect: TRect read GetObjectRect;
property ObjectWidth: Integer read GetObjectWidth;
property ObjectHeight: Integer read GetObjectHeight;
end;
implementation
constructor TFire.Create;
var
ini: TIniFile;
sTemp: string;
iniSection: string;
begin
inherited Create;
// 初始化
iniSection := 'Fire';
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);
FProbability := ini.ReadFloat(iniSection, 'Probability', 0.1);
FX := WORLD_WIDTH;
FY := 0;
FYMin := 0;
FYMax := ini.ReadInteger('Map', 'Height', 0)
- ini.ReadInteger('Map', 'GroundHeight', 0) - FInvBitmap.Height;
FRect := classes.Rect(FX, FY, FInvBitmap.Width, FInvBitmap.Height);
ini.Destroy;
end;
destructor TFire.Destroy;
begin
FInvBitmap.Free;
FBits.Free;
inherited Destroy;
end;
function TFire.GetObjectRect: TRect;
begin
Result := FInvBitmap.Canvas.ClipRect;
end;
function TFire.GetObjectWidth: Integer;
begin
with GetObjectRect do
Result := Right - Left;
end;
function TFire.GetObjectHeight: Integer;
begin
with GetObjectRect do
Result := Bottom - Top;
end;
procedure TFire.Draw(Canvas: TCanvas);
begin
if not FVisible then
Exit;
if (FY > FYMax) then
exit;
FInvBitmap.Canvas.CopyRect(
ObjectRect,
FBits.Canvas,
Classes.Rect(CurrentNo * ObjectWidth, 0, (CurrentNo + 1) * ObjectWidth,
ObjectHeight));
Canvas.Draw(FX, FY, FInvBitmap);
end;
procedure TFire.Drop;
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;
CurrentNo := (CurrentNo + 1) mod Numbers;
Inc(FY, FSpeed);
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);
if (FY > FYMax) then // 如果火球已经隐藏不见
FRect := classes.Rect(WORLD_WIDTH, WORLD_HEIGHT, 0, 0);
end;
procedure TFire.ReSet;
begin
if Random(Dynameter) * FProbability > 1 then
begin
FY := 0;
CurrentNo := 0;
FDelayCount := 0;
FX := Random(WORLD_WIDTH) + 50;
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 + -