Changeset 8 for trunk


Ignore:
Timestamp:
Mar 26, 2015, 5:40:03 PM (10 years ago)
Author:
chronos
Message:
  • Added: Show clock in top right corner.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UEngine.pas

    r7 r8  
    134134    procedure ComputeShapeDistanceStation(Station: TMetroStation;
    135135      UpdatedShape: TStationShape; Distance: Integer);
     136    function GetTime: TDateTime;
     137    procedure DrawClock(Canvas: TCanvas);
    136138  public
    137139    Passengers: TMetroPassengers;
     
    146148    ServedPassengerCount: Integer;
    147149    State: TGameState;
    148     Time: TDateTime;
     150    StartTime: TDateTime;
    149151    procedure Tick;
    150152    procedure MouseMove(Position: TPoint);
     
    155157    destructor Destroy; override;
    156158    procedure Paint(Canvas: TCanvas);
     159    property Time: TDateTime read GetTime;
    157160  end;
    158161
     
    569572end;
    570573
     574function TEngine.GetTime: TDateTime;
     575begin
     576  Result := (Now - StartTime) / OneSecond * (60 * OneMinute);
     577end;
     578
     579procedure TEngine.DrawClock(Canvas: TCanvas);
     580var
     581  ClockCenter: TPoint;
     582  Angle: Double;
     583  Text: string;
     584  I: Integer;
     585const
     586  ClockSize = 20;
     587begin
     588  Canvas.Pen.Style := psSolid;
     589  Canvas.Pen.Color := clBlack;
     590  Canvas.Pen.Width := 2;
     591  ClockCenter := Point(Canvas.Width - 30, 40);
     592  Angle := Time / (12 * OneHour) * 2 * Pi - Pi / 2;
     593  Canvas.EllipseC(ClockCenter.X, ClockCenter.Y, ClockSize, ClockSize);
     594  Canvas.Line(ClockCenter, Point(ClockCenter.X + Round(Cos(Angle) * ClockSize * 0.8),
     595    ClockCenter.Y + Round(Sin(Angle) * ClockSize * 0.8)));
     596  Text := FormatDateTime('ddd', Time);
     597  Canvas.TextOut(ClockCenter.X - ClockSize - Canvas.TextWidth(Text) - 5, ClockCenter.Y -
     598    Canvas.TextWidth(Text) div 2, Text);
     599  for I := 0 to 12 do begin
     600    Angle := I / 12 * 2 * Pi;
     601    Canvas.Line(ClockCenter.X + Round(Cos(Angle) * ClockSize * 0.8),
     602      ClockCenter.Y + Round(Sin(Angle) * ClockSize * 0.8),
     603      ClockCenter.X + Round(Cos(Angle) * ClockSize * 0.9),
     604      ClockCenter.Y + Round(Sin(Angle) * ClockSize * 0.9));
     605  end;
     606end;
     607
    571608procedure TEngine.Tick;
    572609const
     
    584621begin
    585622  if State = gsRunning then begin
    586     Time := Time + OneMinute;
    587623
    588624  // Add new stations
     
    754790    if Assigned(Station) then begin
    755791      SelectedStation := Station;
     792      if not Assigned(SelectedLine) then
    756793      for I := 0 to Lines.Count - 1 do
    757794      if TMetroLine(Lines[I]).Stations.Count = 0 then begin
     
    801838  LastNewPassengerTime := Now;
    802839  State := gsRunning;
    803   Time := 0;
     840  StartTime := Now;
    804841end;
    805842
     
    928965    Canvas.Pen.Color := clBlack;
    929966    DrawShape(Canvas, Position, Shape, StationSize);
    930     Text := '';
    931     for P := 0 to 2 do
    932       Text := Text + IntToStr(ShapeDistance[TStationShape(P)]) + ',';
    933     Canvas.TextOut(Position.X + 20, Position.Y + 20, Text);
    934967
    935968    // Draw passengers
     
    965998  // Interface
    966999  Text := IntToStr(ServedPassengerCount);
    967   Canvas.Draw(Canvas.Width - 100, 20, ImagePassenger.Picture.Bitmap);
     1000  Canvas.Draw(Canvas.Width - 140, 20, ImagePassenger.Picture.Bitmap);
    9681001  Canvas.Brush.Style := bsClear;
    969   Canvas.TextOut(Canvas.Width - 106 - Canvas.TextWidth(Text), 25, Text);
     1002  Canvas.TextOut(Canvas.Width - 146 - Canvas.TextWidth(Text), 25, Text);
    9701003
    9711004  Text := IntToStr(Trains.GetUnusedCount);
    972   Canvas.Draw(Canvas.Width - 180, 20, ImageLocomotive.Picture.Bitmap);
     1005  Canvas.Draw(Canvas.Width - 240, 20, ImageLocomotive.Picture.Bitmap);
    9731006  Canvas.Brush.Style := bsClear;
    974   Canvas.TextOut(Canvas.Width - 186 - Canvas.TextWidth(Text), 25, Text);
     1007  Canvas.TextOut(Canvas.Width - 246 - Canvas.TextWidth(Text), 25, Text);
     1008
     1009  DrawClock(Canvas);
    9751010
    9761011  // Game over
Note: See TracChangeset for help on using the changeset viewer.