unit Kreise;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
tBall =
class
x,y,vx,vy,r:Single;
farbe :tcolor;
procedure Init(fNeu: tcolor; xNeu,yNeu,vxNeu,vyNeu,rNeu: Single);
procedure ZeigeDich;
procedure BewegeDich;
end;
TSpielfeld =
class(TForm)
Bild: TImage;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Spielfeld: TSpielfeld;
ball : tBall;
implementation
{$R *.dfm}
procedure tBall.Init(fNeu: tcolor; xNeu,yNeu,vxNeu,vyNeu,rNeu: Single);
begin
farbe := fNeu;
r := rNeu;
x := xNeu;
y := yNeu;
vx := vxNeu;
vy := vyNeu;
end;
procedure tBall.ZeigeDich;
begin
with Spielfeld.Bild.Canvas
do
begin
brush.color := Farbe;
ellipse(Round(x-r),Round(y-r),Round(x+r),Round(y+r))
end;
end;
procedure tBall.BewegeDich;
begin
x := x + vx;
y := y + vy;
with Spielfeld.Bild
do
begin
if (x >width-r-1)
then
begin
x := width-r-1;
vx := -vx
end;
if x < r + 1
then
begin
x := r + 1;
vx := -vx
end;
if (y >height-r - 1)
then
begin
y := height-r-1;
vy := -vy
end;
if y < r + 1
then
begin
y := r + 1;
vy := -vy
end
end
end;
procedure TSpielfeld.FormCreate(Sender: TObject);
begin
with Bild.Canvas
do
begin
pen.Width := 5;
brush.Color := clwhite;
rectangle(0,0,Bild.Width,Bild.Height);
pen.width := 2;
brush.style := bsSolid;
pen.mode := pmNOTXOR;
end;
Ball.init(clRed,random(Bild.width-50)+25,random(Bild.height-50)+25,random(9)-4,
random(9)-4,20);
Ball.ZeigeDich;
end;
procedure TSpielfeld.Timer1Timer(Sender: TObject);
begin
Ball.ZeigeDich;
Bild.Canvas.Pixels[Round(Ball.x),Round(Ball.y)] := clBlack;
Ball.BewegeDich;
Ball.ZeigeDich;
end;
Initialization
Randomize;
Ball := tBall.Create;
Finalization
Ball.Destroy
end.