Changeset 69 for trunk/UEngine.pas
- Timestamp:
- Jan 9, 2023, 1:05:50 AM (23 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UEngine.pas
r68 r69 4 4 5 5 uses 6 Dialogs, Classes, SysUtils, Graphics, SpecializedMatrix, URegistry, 6 Dialogs, Classes, SysUtils, Graphics, SpecializedMatrix, URegistry, UCommon, 7 7 IntfGraphics, FPImage, LCLType, SpecializedBitmap, GraphType, Math, URectangle, 8 8 Syncobjs, UThreading, Forms, DateUtils, UAudioSystem, Generics.Collections, … … 232 232 procedure DrawMap; 233 233 procedure SetState(AValue: TGameState); 234 function TextOutWordWrap(Canvas: TCanvas; X, Y: Integer; Text: string; Width: Integer): Integer; 234 235 public 235 236 ThreadErrorMessage: string; … … 281 282 SStartGame = 'Start game'; 282 283 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'; 283 298 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'; 284 305 SWorldReady = 'World ready'; 285 306 SExit = 'Exit'; … … 1186 1207 Text: string; 1187 1208 X: Integer; 1209 Y: Integer; 1210 const 1211 LineHeight = 60; 1188 1212 begin 1189 1213 with Bitmap.Canvas do begin … … 1193 1217 1194 1218 X := Bitmap.Width div 2; 1219 Y := Bitmap.Height div 20; 1195 1220 1196 1221 Brush.Style := bsClear; 1197 1222 Pen.Style := psSolid; 1198 1223 Pen.Color := clWhite; 1199 Font.Color := cl Tuna;1224 Font.Color := clGreen; 1200 1225 Font.Size := 30; 1201 1226 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; 1203 1243 1204 1244 Font.Color := clGreen; … … 1213 1253 Text: string; 1214 1254 X: Integer; 1255 Y: Integer; 1256 const 1257 LineHeight = 60; 1215 1258 begin 1216 1259 with Bitmap.Canvas do begin … … 1220 1263 1221 1264 X := Bitmap.Width div 2; 1265 Y := Bitmap.Height div 20; 1222 1266 1223 1267 Brush.Style := bsClear; … … 1227 1271 Font.Size := 30; 1228 1272 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; 1231 1297 Font.Color := clGreen; 1232 1298 Font.Size := 30; … … 1295 1361 FRedrawPending := True; 1296 1362 FStateTime := Now; 1363 end; 1364 1365 function TEngine.TextOutWordWrap(Canvas: TCanvas; X, Y: Integer; Text: string; Width: Integer): Integer; 1366 var 1367 Parts: TStringArray; 1368 I: Integer; 1369 XX: Integer; 1370 begin 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; 1297 1384 end; 1298 1385
Note:
See TracChangeset
for help on using the changeset viewer.