Changeset 69 for trunk/UEngine.pas


Ignore:
Timestamp:
Jan 9, 2023, 1:05:50 AM (23 months ago)
Author:
chronos
Message:
  • Fixed: Show informations and instructions texts.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UEngine.pas

    r68 r69  
    44
    55uses
    6   Dialogs, Classes, SysUtils, Graphics, SpecializedMatrix, URegistry,
     6  Dialogs, Classes, SysUtils, Graphics, SpecializedMatrix, URegistry, UCommon,
    77  IntfGraphics, FPImage, LCLType, SpecializedBitmap, GraphType, Math, URectangle,
    88  Syncobjs, UThreading, Forms, DateUtils, UAudioSystem, Generics.Collections,
     
    232232    procedure DrawMap;
    233233    procedure SetState(AValue: TGameState);
     234    function TextOutWordWrap(Canvas: TCanvas; X, Y: Integer; Text: string; Width: Integer): Integer;
    234235  public
    235236    ThreadErrorMessage: string;
     
    281282  SStartGame = 'Start game';
    282283  SInstructions = 'Instructions';
     284  SInstructionsDetails = 'Tunneler is a two player game. The objective of the game is to be the first to win three rounds. ' +
     285    'A round continues until one tank blows up (from being shot or simply running out of energy).';
     286  SInstructionsDetails2 = 'The display: Each player has a view screen and an instrument panel with two meters. ' +
     287    'The view screen shows your surroundings from above (about 1% of the entire "worlds"). ' +
     288    'The two meters indicate the player''s energy and shield condition.';
     289  SInstructionsDetails3 = 'The Game: Players can move in one of 8 directions. ' +
     290    'Movement in tunnels is three times as fast as normal digging. ' +
     291    'Fast digging can be accomplished by firing the tank''s cannon while moving. ' +
     292    'Various actions use up different amounts of energy : moving costs some energy, digging costs more, and shotting costs the most. ' +
     293    'Shields are damaged when hit by the other player''s cannon. ' +
     294    'Players can refuel at either base but can repair their shields only at their own bases.';
     295  SInstructionsDetails4 = 'Controls: \n ' +
     296    'Blue: W - up, A - left, S - down, D - right, E - shoot \n ' +
     297    'Green: arrows key, CTRL - shoot';
    283298  SInformation = 'Information';
     299  SInformationDetails = 'Tunneler is written from scratch in Lazarus/FPC. ' +
     300    'It is designed to be as similar as the original MS-DOS game (https://tunneler.org/) but also with some modern extensions. ' +
     301    'The program uses standard canvas drawing with combination of low resolution fast pixel matrix. ' +
     302    'It supports High DPI scaling. It supports up to eight players.';
     303  SInformationDetails2 = 'This is a public domain open source program: feel free to copy it for friends and study the source code. \n ' +
     304    'Homepage: https://app.zdechov.net/Tunneler';
    284305  SWorldReady = 'World ready';
    285306  SExit = 'Exit';
     
    11861207  Text: string;
    11871208  X: Integer;
     1209  Y: Integer;
     1210const
     1211  LineHeight = 60;
    11881212begin
    11891213  with Bitmap.Canvas do begin
     
    11931217
    11941218    X := Bitmap.Width div 2;
     1219    Y := Bitmap.Height div 20;
    11951220
    11961221    Brush.Style := bsClear;
    11971222    Pen.Style := psSolid;
    11981223    Pen.Color := clWhite;
    1199     Font.Color := clTuna;
     1224    Font.Color := clGreen;
    12001225    Font.Size := 30;
    12011226    Text := SInformation;
    1202     TextOut(X - TextWidth(Text) div 2, Bitmap.Height div 10, Text);
     1227    TextOut(X - TextWidth(Text) div 2, Y, Text);
     1228    Inc(Y, 2 * LineHeight);
     1229
     1230    X := 30;
     1231
     1232    Font.Color := clYellow;
     1233    Font.Size := 20;
     1234    Text := SInformationDetails;
     1235    Inc(Y, LineHeight * TextOutWordWrap(Bitmap.Canvas, X, Y, Text,  Bitmap.Width - 60));
     1236    Inc(Y, LineHeight);
     1237
     1238    Text := SInformationDetails2;
     1239    Inc(Y, LineHeight * TextOutWordWrap(Bitmap.Canvas, X, Y, Text,  Bitmap.Width - 60));
     1240    Inc(Y, LineHeight);
     1241
     1242    X := Bitmap.Width div 2;
    12031243
    12041244    Font.Color := clGreen;
     
    12131253  Text: string;
    12141254  X: Integer;
     1255  Y: Integer;
     1256const
     1257  LineHeight = 60;
    12151258begin
    12161259  with Bitmap.Canvas do begin
     
    12201263
    12211264    X := Bitmap.Width div 2;
     1265    Y := Bitmap.Height div 20;
    12221266
    12231267    Brush.Style := bsClear;
     
    12271271    Font.Size := 30;
    12281272    Text := SInstructions;
    1229     TextOut(X - TextWidth(Text) div 2, Bitmap.Height div 10, Text);
    1230 
     1273    TextOut(X - TextWidth(Text) div 2, Y, Text);
     1274    Inc(Y, 2 * LineHeight);
     1275
     1276    X := 30;
     1277
     1278    Font.Color := clTeal;
     1279    Font.Size := 20;
     1280    Text := SInstructionsDetails;
     1281    Inc(Y, LineHeight * TextOutWordWrap(Bitmap.Canvas, X, Y, Text,  Bitmap.Width - 60));
     1282    Inc(Y, LineHeight);
     1283
     1284    Text := SInstructionsDetails2;
     1285    Inc(Y, LineHeight * TextOutWordWrap(Bitmap.Canvas, X, Y, Text,  Bitmap.Width - 60));
     1286    Inc(Y, LineHeight);
     1287
     1288    Text := SInstructionsDetails3;
     1289    Inc(Y, LineHeight * TextOutWordWrap(Bitmap.Canvas, X, Y, Text,  Bitmap.Width - 60));
     1290    Inc(Y, LineHeight);
     1291
     1292    Text := SInstructionsDetails4;
     1293    Inc(Y, LineHeight * TextOutWordWrap(Bitmap.Canvas, X, Y, Text,  Bitmap.Width - 60));
     1294    Inc(Y, LineHeight);
     1295
     1296    X := Bitmap.Width div 2;
    12311297    Font.Color := clGreen;
    12321298    Font.Size := 30;
     
    12951361  FRedrawPending := True;
    12961362  FStateTime := Now;
     1363end;
     1364
     1365function TEngine.TextOutWordWrap(Canvas: TCanvas; X, Y: Integer; Text: string; Width: Integer): Integer;
     1366var
     1367  Parts: TStringArray;
     1368  I: Integer;
     1369  XX: Integer;
     1370begin
     1371  Result := 1;
     1372  XX := 0;
     1373  Parts := Explode(' ', Text);
     1374  for I := 0 to Length(Parts) - 1 do begin
     1375    if (X + XX + Canvas.TextWidth(Parts[I]) > Width) or (Parts[I] = '\n') then begin
     1376      Y := Y + Canvas.TextHeight(Parts[I]);
     1377      XX := 0;
     1378      Inc(Result);
     1379    end;
     1380    if Parts[I] = '\n' then Continue;
     1381    Canvas.TextOut(X + XX, Y, Parts[I]);
     1382    XX := XX + Canvas.TextWidth(Parts[I]) + Canvas.TextWidth(' ');
     1383  end;
    12971384end;
    12981385
Note: See TracChangeset for help on using the changeset viewer.