unit DX4;
// Olley geht in die Tiefe
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, DXClass, DXDraws, DXInput, DXSprite, Wave, DXSounds;
type
TFigur =
class (TImageSprite)
private
Nr, xDiff, yDiff: Integer;
procedure ResizeImage (Faktor: Single; Grenze: Integer);
public
constructor Create (AParent: TSprite);
override;
procedure DoDraw;
override;
procedure DoMove (MoveCount: Integer);
override;
end;
TForm1 =
class(TDXForm)
DXDraw1: TDXDraw;
DXImageList1: TDXImageList;
DXTimer1: TDXTimer;
DXSpriteEngine1: TDXSpriteEngine;
DXInput1: TDXInput;
DXWaveList1: TDXWaveList;
DXSound1: TDXSound;
procedure FormCreate(Sender: TObject);
procedure DXTimer1Timer(Sender: TObject; LagCount: Integer);
private
{ Private-Deklarationen }
Figur1: TFigur;
public
{ Public-Deklarationen }
end;
const ZFaktor = 1.1;
var
Form1: TForm1;
bagopen : boolean;
implementation
uses Unit2;
{$R *.DFM}
constructor TFigur.Create (AParent: TSprite);
begin
inherited Create (AParent);
Image := Form1.DXImageList1.Items[0];
Width := Image.Width;
Height := Image.Height;
AnimStart := 0;
AnimCount := 0;
AnimLooped := true;
AnimSpeed := 1/20;
Nr := 0; xDiff := 20; yDiff := 10;
end;
procedure TFigur.ResizeImage (Faktor: Single; Grenze: Integer);
begin
if Faktor < 0
then exit;
// Verkleinern
if Faktor < 1
then
begin
if Width > Image.Width
div Grenze
then
Width := Round(Width * Faktor);
if Height > Image.Height
div Grenze
then
Height := Round(Height * Faktor);
end
// Vergrößern
else if Faktor > 1
then
begin
if Width < Image.Width * Grenze
then
Width := Round(Width * Faktor);
if Height < Image.Height * Grenze
then
Height := Round(Height * Faktor);
end;
end;
procedure TFigur.DoDraw;
var
Nr: Integer; Bereich: TRect;
begin
Nr := AnimStart + Trunc(AnimPos);
Bereich := BoundsRect;
OffsetRect (Bereich,
(Image.Width-Width)
div 2, (Image.Height-Height)
div 2);
Image.StretchDraw (Engine.Surface, Bereich, Nr);
(*OffsetRect (Bereich,
(Width-Image.Width) div 2, (Height-Image.Height) div 2);
Image.Draw (Engine.Surface, Bereich.Left, Bereich.Top, Nr);*)
end;
procedure TFigur.DoMove (MoveCount: Integer);
var fMoved: Boolean;
begin
inherited DoMove(MoveCount);
// Mit Esc beenden
if isButton3
in Form1.DXInput1.States
then Form1.Close;
// Abfrage der Pfeiltasten
fMoved := false;
if isLeft
in Form1.DXInput1.States
then
begin X := X - xDiff; Nr := 3; fMoved := true;
end;
if isRight
in Form1.DXInput1.States
then
begin X := X + xDiff; Nr := 2; fMoved := true;
end;
if isUp
in Form1.DXInput1.States
then
begin
Y := Y - yDiff; ResizeImage (1/ZFaktor, 3);
Nr := 1; fMoved := true;
end;
if isDown
in Form1.DXInput1.States
then
begin
Y := Y + yDiff; ResizeImage (ZFaktor, 2);
Nr := 0; fMoved := true;
end;
Image := Form1.DXImageList1.Items[Nr];
// Stehen oder Bewegen?
if fMoved
then
AnimCount := Image.PatternCount
else
begin AnimCount := 0; Nr := Nr;
end;
// Spielfeld ggf. scrollen
// Engine.X := -X + (Engine.Width - Width) div 2;
// Engine.Y := -Y + (Engine.Height - Height) div 2;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
if isButton4
in Form1.DXInput1.States
then
begin
Form2.show;
bagopen := true
end ;
DxWaveList1.Items.Find('
output.wav').Play(True);
randomize;
// Hintergrund einsetzen
with TBackgroundSprite.Create (DXSpriteEngine1.Engine)
do
begin
Tile := true;
SetMapSize (1, 1);
Image := DXImageList1.Items[4];
Z := -1;
end;
// Figur erzeugen und positionieren
Figur1 := TFigur.Create (DXSpriteEngine1.Engine);
with Figur1
do
begin
Nr := 1;
X := (ClientWidth - 100)
div 2;
Y := (ClientHeight - (-300))
div 3;
Z := 1;
end;
end;
procedure TForm1.DXTimer1Timer(Sender: TObject; LagCount: Integer);
begin
DXInput1.Update;
DXDraw1.Surface.Fill(clBlack);
DXSpriteEngine1.Draw;
DXSpriteEngine1.Move(20);
DXDraw1.Flip;
end;
end.