1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105:
| unit uball1;
interface
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls;
type TSpielfeld = class(TForm) Bild: TImage; Timer1: TTimer; procedure FormCreate(Sender: TObject); procedure Timer1Timer(Sender: TObject); private public end;
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;
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; x:= 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 Spielfeld.doublebuffered:= true; 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. |