unit Tennis;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TField =
class(TForm)
Decke: TShape;
shLinks: TShape;
ShSchlaeger: TShape;
shRechts: TShape;
Ball: TShape;
Timer1: TTimer;
procedure FormKeyDown(Sender: TObject;
var Key: Word; Shift: TShiftState);
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Field: TField;
x, y : Integer;
Lives : Byte;
oben, rechts, links, unten : Integer;
implementation
{$R *.dfm}
procedure TField.FormCreate(Sender: TObject);
begin
Field.DoubleBuffered := True;
x := 3;
y := -4;
Lives := 3;
oben := Decke.Top + Decke.Height;
links := shLinks.Left + ShLinks.Height;
rechts := shRechts.Left;
unten := shSchlaeger.Top;
end;
procedure TField.FormKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
begin
case Key
of
VK_Left:
Begin
if ShSchlaeger.Left >= 30
then
ShSchlaeger.Left := ShSchlaeger.Left - 10;
End;
VK_Right:
Begin
if (ShSchlaeger.Left + ShSchlaeger.Width) <= 660
then
ShSchlaeger.Left := ShSchlaeger.Left + 10;
End;
end;
end;
function BallOben : Boolean;
Begin
Result := Field.Ball.Top <= oben;
End;
function BallUnten : Boolean;
Begin
Result := Field.Ball.Top + Field.Ball.Height >= unten;
End;
function BallLinks : Boolean;
Begin
Result := Field.Ball.Left <= Links;
End;
function BallRechts : Boolean;
Begin
Result := Field.Ball.Left + Field.Ball.Width >= Rechts;
End;
procedure TField.Timer1Timer(Sender: TObject);
begin
Ball.Left := Ball.Left + x;
Ball.Top := Ball.Top + y;
if BallOben
then
y := -y;
if BallLinks
then
x := -x;
if BallRechts
then
x := -x;
if BallUnten
AND (Ball.Left >= shSchlaeger.Left)
AND (Ball.Left <= (shSchlaeger.Left + shSchlaeger.Width))
then
y:= -y;
end;
end.