Changeset 26 for trunk/UCore.pas
- Timestamp:
- Sep 29, 2011, 8:54:28 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UCore.pas
r25 r26 13 13 MaxBulletCount = 10; 14 14 EnergySteps = 4000; 15 EnergyDecreaseDig = 0.001; 15 16 ShieldSteps = 40; 16 17 ExplosionBulletCount = 100; … … 20 21 BulletExplosionRange = 3; 21 22 ShootDelay = 0.2; // seconds 23 DigDelay = 0.2; // seconds 24 ShootDigDelay = 0.005; // seconds 22 25 ShootEnergyDecrease = 0.01; 26 PlayerFrameWidth = 80; 27 PlayerFrameHeight = 80; 28 PlayerHouseSize = 30; 29 PlayerHouseDoorSize = 8; 23 30 24 31 type … … 59 66 end; 60 67 61 TMatterIndex = (miSpace, miDirt1, miDirt2, miRock, miBullet1, miBullet2, 68 TMatterIndex = (miSpace, miDirt1, miDirt2, miRock, miBullet1, miBullet2, miBorder, 62 69 miPlayer1Cannon, miPlayer1Home, miPlayer1TankBody, miPlayer1TankBody2, 63 70 miPlayer2Cannon, miPlayer2Home, miPlayer2TankBody, miPlayer2TankBody2, … … 70 77 71 78 TMatterKind = (mkSpace, mkDirt, mkRock, mkBullet, mkTankBody, 72 mkHome );79 mkHome, mkBorder); 73 80 74 81 { TPlayer } … … 84 91 function ShowTankProc(Item1, Item2: Byte): Byte; 85 92 function HideTankProc(Item1, Item2: Byte): Byte; 93 function DigProc(Item1, Item2: Byte): Byte; 86 94 public 87 95 Id: Integer; … … 96 104 Bullets: TListObject; // TListObject<TBullet> 97 105 LastShootTime: TDateTime; 106 LastDigTime: TDateTime; 98 107 Energy: Real; 99 108 LastEnergy: Real; … … 176 185 IntfImage: TLazIntfImage; 177 186 ClearBackground: Boolean; 187 procedure InitDigMasks; 178 188 procedure SetActive(const AValue: Boolean); 179 189 procedure SetBitmap(const AValue: TBitmap); … … 187 197 PlayerPool: TListObject; // TListObject<TPlayer> 188 198 Players: TListObject; // TListObject<TPlayer> 199 DigMasks: TListObject; // TListObject<TMatrixByte> 189 200 Lock: TCriticalSection; 190 201 constructor Create; … … 207 218 (X: 0; Y: 1), (X: -1; Y: 1), (X: -1; Y: 0), (X: -1; Y: -1)); 208 219 209 function SwapBRComponent(Value: Integer): Integer; inline;220 function SwapBRComponent(Value: Cardinal): Cardinal; inline; 210 221 211 222 … … 216 227 217 228 218 function SwapBRComponent(Value: Integer): Integer;229 function SwapBRComponent(Value: Cardinal): Cardinal; inline; 219 230 begin 220 231 // Result := (Value and $00ff00) or ((Value shr 16) and $ff) or ((Value and $ff) shl 16); … … 326 337 Kind := mkBullet; 327 338 Color := clRed; 339 Player := -1; 340 end; 341 // Border 342 with TMatter(Matter.AddNew(TMatter.Create)) do begin 343 Kind := mkBorder; 344 Color := clNavy; 328 345 Player := -1; 329 346 end; … … 667 684 HideTank; 668 685 Matter := CheckColision; 669 if (Matter = miDirt1) then Dig := not Dig; 670 if (Matter = miSpace) or ((Matter = miDirt1) and (not Dig)) then begin 686 if (Matter = miDirt1) and ( 687 (Engine.KeyBoard.KeyState[Ord(Keys.Shoot)] and 688 ((Now - LastDigTime) > ShootDigDelay * OneSecond)) or 689 (not Engine.KeyBoard.KeyState[Ord(Keys.Shoot)] and 690 ((Now - LastDigTime) > DigDelay * OneSecond))) then begin 691 Dig := not Dig; 692 with Engine, World do 693 Surface.Merge(Surface.CreateIndex( 694 Position.X - TMatrixByte(DigMasks[Direction]).Count.X div 2, 695 Position.Y - TMatrixByte(DigMasks[Direction]).Count.Y div 2), 696 TMatrixByte(DigMasks[Direction]), DigProc); 697 Energy := Energy - EnergyDecreaseDig; 698 if Energy < 0 then Energy := 0; 699 Engine.Redraw; 700 LastDigTime := Now; 701 Direction := NewDirection; 702 end; 703 if (Matter = miSpace) then begin 671 704 Position := NewPosition; 672 705 Direction := NewDirection; … … 681 714 NewBullet := TBullet.Create; 682 715 NewBullet.Player := Self; 683 NewBullet.Position.X := Position.X + DirectionToDelta[Direction].X * 4;684 NewBullet.Position.Y := Position.Y + DirectionToDelta[Direction].Y * 4;716 NewBullet.Position.X := Position.X + DirectionToDelta[Direction].X * 3; 717 NewBullet.Position.Y := Position.Y + DirectionToDelta[Direction].Y * 3; 685 718 NewBullet.Direction.X := DirectionToDelta[Direction].X; 686 719 NewBullet.Direction.Y := DirectionToDelta[Direction].Y; … … 807 840 // FillRect(ScreenFrame); 808 841 Fill(CreateIndex(ScreenFrame.Left, ScreenFrame.Top), 809 CreateIndex(ScreenFrame.Right - 1, ScreenFrame.Bottom - 1),842 CreateIndex(ScreenFrame.Right, ScreenFrame.Bottom), 810 843 TMatter(Engine.World.Matter[Integer(miRock)]).Color); 811 844 … … 834 867 835 868 procedure TPlayer.PlaceHouse; 836 const837 HouseSize = 30;838 DoorSize = 8;839 869 var 840 870 X, Y: Integer; 841 871 Matter: Byte; 842 872 begin 843 House.AsTRect := Rect(Position.X - HouseSize div 2, Position.Y -HouseSize div 2,844 Position.X + HouseSize div 2, Position.Y +HouseSize div 2);845 for Y := 0 to HouseSize - 1 do846 for X := 0 to HouseSize - 1 do begin847 if ((Y = 0) or (Y = ( HouseSize - 1)) or (X = 0) or (X = (HouseSize - 1))) and848 not (((Y = 0) or (Y = ( HouseSize - 1))) and (X > ((HouseSize -DoorSize) div 2)) and849 (X < (( HouseSize - 1 +DoorSize) div 2)))873 House.AsTRect := Rect(Position.X - PlayerHouseSize div 2, Position.Y - PlayerHouseSize div 2, 874 Position.X + PlayerHouseSize div 2, Position.Y + PlayerHouseSize div 2); 875 for Y := 0 to PlayerHouseSize - 1 do 876 for X := 0 to PlayerHouseSize - 1 do begin 877 if ((Y = 0) or (Y = (PlayerHouseSize - 1)) or (X = 0) or (X = (PlayerHouseSize - 1))) and 878 not (((Y = 0) or (Y = (PlayerHouseSize - 1))) and (X > ((PlayerHouseSize - PlayerHouseDoorSize) div 2)) and 879 (X < ((PlayerHouseSize - 1 + PlayerHouseDoorSize) div 2))) 850 880 then Matter := Byte(miPlayer1Home) + Id * 4 851 881 else Matter := Byte(miSpace); … … 907 937 begin 908 938 if Item2 > 0 then Result := 0 else Result := Item1; 939 end; 940 941 function TPlayer.DigProc(Item1, Item2: Byte): Byte; 942 begin 943 if ((Item1 = Integer(miDirt1)) or (Item1 = Integer(miDirt2))) and (Item2 = 1) then 944 Result := Integer(miSpace) else Result := Item1; 909 945 end; 910 946 … … 1126 1162 TargetHeight: Integer; 1127 1163 TargetWidth: Integer; 1164 BgColor: Cardinal; 1128 1165 begin 1129 1166 if Assigned(FBitmap) then … … 1134 1171 BytePerRow := RawImage.Description.BytesPerLine; 1135 1172 if ClearBackground then begin 1136 FillChar(RawImage.Data^, Bitmap.Height * BytePerRow, 0); 1173 BgColor := TMatter(World.Matter[Integer(miBorder)]).Color; 1174 BgColor := SwapBRComponent(BgColor); 1175 FillDWord(RawImage.Data^, Bitmap.Height * BytePerRow div 4, BgColor); 1137 1176 ClearBackground := False; 1138 1177 end; … … 1195 1234 end; 1196 1235 1236 procedure TEngine.InitDigMasks; 1237 var 1238 NewMask: TMatrixByte; 1239 I: Integer; 1240 X, Y: Integer; 1241 begin 1242 DigMasks.Clear; 1243 1244 // 001111100 1245 // 0111A1110 1246 // 00z1A1z00 1247 // 00zxAxz00 1248 // 00zxAxz00 1249 // 00zxxxz00 1250 // 00z000z00 1251 // 000000000 1252 // 000000000 1253 1254 NewMask := TMatrixByte.Create; 1255 with NewMask do begin 1256 Count := CreateIndex(9, 9); 1257 for I := 0 to 4 do ItemsXY[2 + I, 0] := 1; 1258 for I := 0 to 2 do begin 1259 ItemsXY[1 + I, 1] := 1; 1260 ItemsXY[5 + I, 1] := 1; 1261 end; 1262 ItemsXY[3, 2] := 1; 1263 ItemsXY[5, 2] := 1; 1264 end; 1265 DigMasks.Add(NewMask); 1266 1267 // 000011110 1268 // 0000z1111 1269 // 000zx1A11 1270 // 00zxxA111 1271 // 0zxxAxxz1 1272 // 000xxxz00 1273 // 0000xz000 1274 // 0000z0000 1275 // 000000000 1276 1277 NewMask := TMatrixByte.Create; 1278 with NewMask do begin 1279 Count := CreateIndex(9, 9); 1280 for I := 0 to 3 do begin 1281 ItemsXY[4 + I, 0] := 1; 1282 ItemsXY[5 + I, 1] := 1; 1283 end; 1284 ItemsXY[5, 2] := 1; 1285 ItemsXY[7, 2] := 1; 1286 ItemsXY[8, 2] := 1; 1287 for I := 0 to 2 do 1288 ItemsXY[6 + I, 3] := 1; 1289 ItemsXY[8, 4] := 1; 1290 end; 1291 DigMasks.Add(NewMask); 1292 1293 NewMask := TMatrixByte.Create; 1294 NewMask.Assign(TMatrixByte(DigMasks[0])); 1295 NewMask.Reverse; 1296 NewMask.ReverseHorizontal; 1297 DigMasks.Add(NewMask); 1298 1299 NewMask := TMatrixByte.Create; 1300 NewMask.Assign(TMatrixByte(DigMasks[1])); 1301 NewMask.ReverseVertical; 1302 DigMasks.Add(NewMask); 1303 1304 NewMask := TMatrixByte.Create; 1305 NewMask.Assign(TMatrixByte(DigMasks[0])); 1306 NewMask.ReverseVertical; 1307 DigMasks.Add(NewMask); 1308 1309 NewMask := TMatrixByte.Create; 1310 NewMask.Assign(TMatrixByte(DigMasks[1])); 1311 NewMask.ReverseVertical; 1312 NewMask.ReverseHorizontal; 1313 DigMasks.Add(NewMask); 1314 1315 NewMask := TMatrixByte.Create; 1316 NewMask.Assign(TMatrixByte(DigMasks[0])); 1317 NewMask.Reverse; 1318 DigMasks.Add(NewMask); 1319 1320 NewMask := TMatrixByte.Create; 1321 NewMask.Assign(TMatrixByte(DigMasks[1])); 1322 NewMask.ReverseHorizontal; 1323 DigMasks.Add(NewMask); 1324 end; 1325 1197 1326 procedure TEngine.InitPlayerPool; 1198 1327 var … … 1283 1412 HorizFrameCount := 1; 1284 1413 end; 1285 FBitmapLower.Count := FBitmapLower.CreateIndex(80 * HorizFrameCount, 60 * VertFrameCount); 1414 FBitmapLower.Count := FBitmapLower.CreateIndex(PlayerFrameWidth * HorizFrameCount, 1415 PlayerFrameHeight * VertFrameCount); 1286 1416 for I := 0 to Players.Count - 1 do begin 1287 1417 TPlayer(Players[I]).ScreenFrame.AsTRect := Rect( 1288 (I mod HorizFrameCount) * (FBitmapLower.Count.X div HorizFrameCount) ,1289 (I div HorizFrameCount) * (FBitmapLower.Count.Y div VertFrameCount) ,1418 (I mod HorizFrameCount) * (FBitmapLower.Count.X div HorizFrameCount) + 1, 1419 (I div HorizFrameCount) * (FBitmapLower.Count.Y div VertFrameCount) + 1, 1290 1420 ((I mod HorizFrameCount) + 1) * (FBitmapLower.Width div HorizFrameCount), 1291 1421 ((I div HorizFrameCount) + 1) * (FBitmapLower.Height div VertFrameCount)); … … 1309 1439 World.Engine := Self; 1310 1440 InitPlayerPool; 1441 DigMasks := TListObject.Create; 1442 InitDigMasks; 1311 1443 Redraw; 1312 1444 end; … … 1315 1447 begin 1316 1448 Active := False; 1449 DigMasks.Free; 1317 1450 FBitmapLower.Free; 1318 1451 FBitmapLock.Free; … … 1350 1483 try 1351 1484 Lock.Acquire; 1352 //FBitmapLower.FillAll(0);1485 if ClearBackground then FBitmapLower.FillAll(clNavy); 1353 1486 for I := 0 to Players.Count - 1 do begin 1354 1487 TPlayer(Players[I]).Paint;
Note:
See TracChangeset
for help on using the changeset viewer.