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

📄 unit1.pas

📁 Directx游戏制作开发包DGCBETA6
💻 PAS
字号:
{The Delphi Games Creator Demo Program
 -------------------------------------
 This demo shows how to use images from the Image Library component.
 The TDGCImageLib component is assigned at design time by setting
 the TDGCScreen property ImageLibrary.
}
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  DGC, DGCILib, StdCtrls;

type
  TForm1 = class(TForm)
    DGCScreen1: TDGCScreen;
    DGCImageLib1: TDGCImageLib;
    Label1: TLabel;
    Label2: TLabel;
    procedure DGCScreen1Initialize(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure DGCScreen1Flip(Sender: TObject);
    procedure DGCScreen1Paint(Sender: TObject);
  private
    { Private declarations }
    x, y, xvel, yvel: Integer;
    procedure DrawFrame;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.DGCScreen1Initialize(Sender: TObject);
begin
     //Draw stuff on the hidden surface
     DrawFrame;

     //Quickly fade palette to black
     DGCScreen1.FadePaletteOut(1);

     //Flip the hidden surface with the visible one so you can
     //see it on the screen - but you can't see it yet cause the
     //palette is still black???
     DGCScreen1.Flip;

     //Finally Smoothly fade the palette in
     DGCScreen1.FadePaletteIn(100);

     //Copy the Front surface to the back buffer so
     //both surfaces contain the same info
     DGCScreen1.Back.BltFast(0, 0, DGCScreen1.Front, DGCScreen1.Front.ClientRect, False);

     //Initialise the image attributes (for my crude bounce code)
     x := 150;
     y := 200;
     yvel := 1;
     xvel := 2;

     //Now Start the page flipping
     DGCScreen1.FlippingEnabled := True;
end;

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
     //If the escape key is pressed fade the palette out and
     //Close the demo
     if Key = #27 then
     begin
          //DGCScreen1.FadePaletteOut(100);
          Close;
     end;
end;

procedure TForm1.DrawFrame;
begin
     with DGCScreen1.Back.Canvas do
     begin
          Brush.Style := bsClear;
          Font.Size := 24;
          Font.Color := clBlue;
          TextOut(110, 60, 'The Delphi Games Creator');
          Font.Color := clTeal;
          TextOut(108, 58, 'The Delphi Games Creator');
          Font.Size := 12;
          Font.Color := clYellow;
          TextOut(45, 150, 'This demos shows how to use images from the Image Library Component.');
          TextOut(205, 170, 'Press Escape to Quit');
          Font.Color := clWhite;
          Font.Size := 8;
          TextOut(0, 467, 'Sprites by Ari Feldman');
          Release; //This must be called to release the device context.
     end;
end;

procedure TForm1.DGCScreen1Flip(Sender: TObject);
begin
     //Erase the area theat the sprite will bounce in
     DGCScreen1.Back.EraseRect(Rect(0, 200, 640, 468), 0);

     //Now Draw the Sprite
     DGCScreen1.Back.Draw(x, y, DGCScreen1.Images[0], False);

     //Update the Images X position
     Inc(x, xvel);
     if (x < 0) or (x > 500) then
        xvel := -xvel;

     //Update the y position using yvel
     Inc(y, yvel);

     //Uncrease the Velocity and make sure it is in a range
     Inc(yvel);
     if yvel > 18 then yvel := 18;
     if yvel < -18 then yvel := -18;

     //If the image has reached the bottom then reverse direction
     if y > 380 then
     begin
          y := 380;
          yvel := -yvel;
     end;
end;

procedure TForm1.DGCScreen1Paint(Sender: TObject);
begin
     //The paint event should only be called when surfaces are lost. This
     //can be caused when application switching with ALT+TAB.
     DrawFrame;
     DGCScreen1.Flip;
     DrawFrame;
end;

end.

⌨️ 快捷键说明

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