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: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208:
| unit Pong;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls;
type TForm1 = class(TForm) Panel1: TPanel; Image1: TImage; Label1: TLabel; Timer: TTimer; procedure FormCreate(Sender: TObject);
procedure FormPaint(Sender: TObject); procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure TimerTimer(Sender: TObject);
private ball_bmp : TBitmap; schlaeger1_bmp : TBitmap; schlaeger2_bmp : TBitmap; buffer : TBitmap; sx1,sx2,sy1,sy2,bx,by,richtung : integer ; procedure schlaeger1(xpos,ypos : integer); procedure schlaeger2(xpos,ypos : integer); procedure ball(xpos,ypos : integer) ; procedure anzeige ;
public end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.schlaeger1(xpos,ypos : integer); begin Buffer.Canvas.Draw(xpos,ypos,schlaeger1_bmp); end;
procedure TForm1.schlaeger2(xpos,ypos : integer); begin Buffer.Canvas.Draw(xpos,ypos,schlaeger2_bmp); end;
procedure TForm1.ball(xpos,ypos : integer); begin Buffer.Canvas.Draw(xpos,ypos,ball_bmp); end;
procedure TForm1.anzeige; var i : integer; begin i := 4; while i > 0 do begin Label1.Caption := IntToStr(i-1); if i = 1 then Label1.Caption := 'Los'; i := i - 1; application.ProcessMessages; sleep(800); end;
if i = 0 then Label1.Caption := '';
end;
procedure TForm1.FormCreate(Sender: TObject); begin
Form1.KeyPreview := true; Form1.DoubleBuffered := true;
timer.Enabled := false; Label1.Caption := 'Zum Starten Leertaste drücken';
Buffer := TBitmap.Create; Buffer.Height := Image1.Height; Buffer.Width := Image1.Width ; Buffer.Canvas.Brush.Color := clBlack; Buffer.Canvas.Rectangle(0,0,Image1.Width,Image1.Height);
schlaeger1_bmp := TBitmap.Create; with schlaeger1_bmp do begin Height := 80; Width := 10; Canvas.Brush.Color := clWhite; Canvas.Rectangle(0,0,10,100); end;
schlaeger2_bmp := TBitmap.Create; with schlaeger2_bmp do begin Height := 80; Width := 10; Canvas.Brush.Color := clWhite; Canvas.Rectangle(0,0,10,100); end;
ball_bmp := TBitmap.Create; ball_bmp.Transparent := true; ball_bmp.TransparentColor := clWhite; with ball_bmp do begin Height := 15; Width := 15; Canvas.Brush.Color := clGray; Canvas.Ellipse(0,0,15,15);
sx1 := 100 ; sx2 := Image1.Width-100 ; sy1 := (Image1.Height div 2)-50; sy2 := (Image1.Height div 2)-50; bx := Image1.Width div 2 ; by := Image1.Height div 2 ; end;
richtung := Random(1); if richtung = 0 then richtung := -1 ; if richtung = 1 then richtung := 1 ;
end;
procedure TForm1.FormPaint(Sender: TObject); begin Buffer.Canvas.Brush.Color := clBlack ; Buffer.Canvas.Rectangle(0,0,Image1.Width,Image1.Height);
schlaeger1(sx1,sy1) ; schlaeger2(sx2,sy2) ; ball(bx,by) ; Image1.Canvas.Draw(0,0,Buffer); end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin Case key of
VK_UP : begin if sy1 >= 25 then sy1 := sy1 - 20; end; VK_DOWN : begin if sy1 <= Image1.Height - 90 then sy1 := sy1 + 20; end; ord('A') : begin if sy2 >= 25 then sy2 := sy2 - 20; end; ord('S') : begin if sy2 <= Image1.Height - 90 then sy2 := sy2 + 20; end; VK_SPACE : begin anzeige ; timer.Enabled := true ; end;
end;
Form1.Invalidate;
end;
procedure TForm1.TimerTimer(Sender: TObject); begin bx := bx + 15; Form1.Invalidate ; end;
end. |