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
|
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls;
type
TForm1 = class(TForm)
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormPaint(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
type
TCanvasHelper = class helper for TCanvas
procedure Wall(x, y, w, h, delta: Integer);
procedure Ground(x, y, w, h: Integer);
end;
procedure TCanvasHelper.Wall(x: Integer; y: Integer; w: Integer; h: Integer; delta: Integer);
var
p: array[0..3] of TPoint;
begin
p[0].X := x;
p[0].Y := y - h;
p[1].X := x + w;
p[1].Y := y - h + delta * w div 2;
p[2].X := x + w;
p[2].Y := y + delta * w div 2;
p[3].X := x;
p[3].Y := y;
Polygon(p);
end;
procedure TCanvasHelper.Ground(x: Integer; y: Integer; w: Integer; h: Integer);
var
p: array[0..3] of TPoint;
begin
p[0].X := x;
p[0].Y := y;
p[1].X := x + w;
p[1].Y := y - w div 2;
p[2].X := x + w + h;
p[2].Y := y + (h - w) div 2;
p[3].X := x + h;
p[3].Y := y + h div 2;
Polygon(p);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
DoubleBuffered := True;
Timer1.Interval := 40;
end;
procedure TForm1.FormPaint(Sender: TObject);
var
t: Int64;
w: Integer;
begin
with Canvas do
begin
// Fond d'écran
Brush.Color := clSkyBlue;
FillRect(ClientRect);
// Sol
Brush.Color := clMoneyGreen;
Ground(200, 400, 320, 200);
// Murs du fond
Brush.Color := clMaroon;
Wall(200, 400, 320, 100, -1);
Wall(200 + 320, 400 - 160, 200, 100, +1);
// Porte
Brush.Color := clSkyBlue;
Wall(200 + 320 + 50, 400 - 160 + 25, 50, 80, +1);
Brush.Color := clSilver;
t := GetTickCount;
w := Round(25 * Abs(Sin(t * PI/1800)));
Wall(200 + 320 + 50, 400 - 160 + 25, w, 80, +1);
Wall(200 + 320 + 50 + 50 - w, 400 - 160 + 25 + ( 50 - w ) div 2, w, 80, +1);
// Murs devant
Brush.Style := bsClear;
Wall(200 + 200, 400 + 100, 320, 100, -1);
Wall(200, 400, 200, 100, +1);
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Invalidate;
end;
end. |
Partager