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

📄 unit1.pas

📁 一个很有意思的用delphi编写的游戏软件
💻 PAS
字号:
//Delphi code from tutorial three of 'Ye Olde Delphi Game Developer'
//Written by Ben Watt for www.delphigamedev.com
unit Unit1;

interface

uses
  Classes,
  {$IFDEF WIn32}
   Windows, Messages, Graphics, Controls, Forms, Dialogs,
   StdCtrls, ExtCtrls, ComCtrls, Buttons, ExtDlgs,
  {$ENDIF}

  {$IFDEF Linux}
    QGraphics, QControls, QForms, QDialogs, QStdCtrls,
    QExtCtrls, QComCtrls, QButtons, Types, QTypes, Variants,
  {$ENDIF}

  SysUtils, DXInput, DXClass;

type
  TForm1 = class(TForm)
    ImgCharacter: TImage;
    DXTimer1: TDXTimer;
    DXInput1: TDXInput;
    Label1: TLabel;
    procedure DXTimer1Activate(Sender: TObject);
    procedure DXTimer1Timer(Sender: TObject; LagCount: Integer);

  private
    { Private declarations }
    procedure Left;
procedure Right;
procedure Up;
procedure Down;

  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Left;
begin
  if ImgCharacter.Left > 0 then
    ImgCharacter.Left := ImgCharacter.Left - 10;
end;

procedure TForm1.Up;
begin
  if ImgCharacter.Top > 0 then
    ImgCharacter.Top := ImgCharacter.Top - 10;
end;

procedure TForm1.Right;
begin
  if ImgCharacter.Left < (Form1.ClientWidth - ImgCharacter.Width - 4) then
    ImgCharacter.Left := ImgCharacter.Left + 10;
end;

procedure TForm1.Down;
begin
  if ImgCharacter.Top < (Form1.ClientHeight - ImgCharacter.Height - 1) then
    ImgCharacter.Top := ImgCharacter.Top + 10;
end;



procedure TForm1.DXTimer1Activate(Sender: TObject);
begin
    DXInput1.Update;
if isLeft in DXInput1.States then Left;
if isRight in DXInput1.States then Right;
if isUp in DXInput1.States then Up;
if isDown in DXInput1.States then Down;


Label1.Caption := IntToStr(StrToInt(Label1.Caption )+1);

end;

procedure TForm1.DXTimer1Timer(Sender: TObject; LagCount: Integer);
begin
    DXInput1.Update;
if isLeft in DXInput1.States then Left;
if isRight in DXInput1.States then Right;
if isUp in DXInput1.States then Up;
if isDown in DXInput1.States then Down;


Label1.Caption := IntToStr(StrToInt(Label1.Caption )+1);

end;

end.

⌨️ 快捷键说明

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