type
TGun =
class
private
FDC: HDC;
FGunPosition: TPoint;
FDegree: Cardinal;
FGunEndPoints: TPoint;
procedure GunEndPoints(Degree: Cardinal);
procedure DrawMuzzle(Degree: Cardinal);
public
constructor Create(
DC: HDC);
property DC: HDC
read FDC;
procedure DrawMount(pt: TPoint);
property Degree: Cardinal
read FDegree
write DrawMuzzle;
property GunEndPoint: TPoint
read FGunEndPoints;
end;
implementation
constructor TGun.Create(
DC: HDC);
begin
FDC :=
DC;
end;
procedure TGun.DrawMount(pt: TPoint);
var
Pen, PenOld: HPen;
GreyBrush, GreyBrushOld: HBrush;
begin
Pen := CreatePen(PS_SOLID, 1,
RGB(0, 0, 0));
PenOld := SelectObject(FDC, Pen);
GreyBrush := CreateSolidBrush(
RGB(240, 240, 240));
GreyBrushOld := SelectObject(FDC, GreyBrush);
Rectangle(FDC, FGunPosition.X, FGunPosition.Y, FGunPosition.X - 20,
FGunPosition.Y - 7);
Chord(FDC, FGunPosition.X - 1, FGunPosition.Y + 19, FGunPosition.X - 19,
FGunPosition.Y - 14,
FGunPosition.X - 4, FGunPosition.Y - 5, FGunPosition.X - 16, FGunPosition.Y
- 5);
SelectObject(FDC, GreyBrushOld);
DeleteObject(GreyBrush);
SelectObject(FDC, PenOld);
DeleteObject(Pen);
end;
procedure TGun.GunEndPoints(Degree: Cardinal);
begin
FGunEndPoints.X := Round(cos(Degree / 180 * Pi) * LENMUZZLE);
FGunEndPoints.Y := Round(sin(Degree / 180 * Pi) * LENMUZZLE);
end;
procedure TGun.DrawMuzzle(Degree: Cardinal);
begin
GunEndPoints(Degree);
MoveToEx(FDC, FGunPosition.X-10, FGunPosition.Y-12,
nil);
LineTo(FDC, FGunPosition.X-10+FGunEndPoints.X, FGunPosition.Y-FGunEndPoints.Y-12);
end;