程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> Delphi與DirectX之DelphiX(1):安裝測試(2)

Delphi與DirectX之DelphiX(1):安裝測試(2)

編輯:Delphi

代碼文件:

unit Unit1;
interface
uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, DXDraws, StdCtrls, DXClass;
type
 TForm1 = class(TDXForm)
  DXDraw1: TDXDraw;
  DXTimer1: TDXTimer;
  DXImageList1: TDXImageList;
  procedure FormCreate(Sender: TObject);
  procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  procedure DXDraw1Initialize(Sender: TObject);
  procedure DXDraw1Finalize(Sender: TObject);
  procedure DXTimer1Timer(Sender: TObject; LagCount: Integer);
 private
  procedure CalculateTables;
  procedure PlotPoint(XCenter, YCenter, Radius, Angle: Word);
 end;
var
 Form1: TForm1;
implementation
{$R *.dfm}
var
 SineMove: array[0..255] of integer;
 CosineMove: array[0..255] of integer;
 SineTable: array[0..449] of integer;
 CenterX, CenterY: Integer;
 x: Word = 0;
 y: Word = 0;
procedure TForm1.CalculateTables;
var
 wCount: Word;
begin
 for wCount := 0 to 255 do
 begin
  SineMove[wCount] := round( sin( pi*wCount/128 ) * 45 );
  CosineMove[wCount] := round( cos( pi*wCount/128 ) * 60 );
 end;
 for wCount := 0 to 449 do
 begin
  SineTable[wCount] := round( sin( pi*wCount/180 ) * 128);
 end;
end;
procedure TForm1.PlotPoint(XCenter, YCenter, Radius, Angle: Word);
var
 a, b : Word;
begin
 a := ( Radius * SineTable[90 + Angle]);
 asm
  sar a,7
 end;
 a := CenterX + XCenter + a;
 b := ( Radius * SineTable[Angle] );
 asm
  sar b,7
 end;
 b := CenterY + YCenter + b;
 if (a < Width ) and ( b < Height ) then
 begin
  DXImageList1.Items[0].Draw(DXDraw1.Surface, a, b, 0 );
 end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
 DXDraw1.Align := alClIEnt;
 CenterX := Width div 2;
 CenterY := Height div 2;
 CalculateTables;
end;
procedure TForm1.DXDraw1Finalize(Sender: TObject);
begin
 DXTimer1.Enabled := False;
end;
procedure TForm1.DXDraw1Initialize(Sender: TObject);
begin
 DXTimer1.Enabled := True;
end;
procedure TForm1.DXTimer1Timer(Sender: TObject; LagCount: Integer);
const
 IncAngle = 12;
 XMove = 7;
 YMove = 8;
var
 CountAngle : Word;
 CountLong : Word;
 IncLong :Word;
begin
 if not DXDraw1.CanDraw then exit;
 IncLong := 2;
 CountLong := 20;
 DXDraw1.Surface.Fill(0);
 repeat
  CountAngle := 0;
  repeat
   PlotPoint(CosineMove[(x + (200 - CountLong)) mod 255],
        SineMove[(y + (200 - CountLong)) mod 255], CountLong, CountAngle);
   Inc(CountAngle, IncAngle);
  until CountAngle >= 360;
  inc(CountLong, IncLong);
  if (CountLong mod 3) = 0 then
  begin
   inc(IncLong);
  end;
 until CountLong >= 270;
 x := XMove + x mod 255;
 y := YMove + y mod 255;
 with DXDraw1.Surface.Canvas do
 begin
  Brush.Style := bsClear;
  Font.Color := clWhite;
  Font.Size := 12;
  Textout(0, 0, 'FPS: '+inttostr( DXTimer1.FrameRate)); { 錄制動畫是丟了這句 }
  Release;
 end;
 DXDraw1.Flip;
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
 Shift: TShiftState);
begin
 if Key = VK_ESCAPE then Close;
end;
end.

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved