Changeset 23 for trunk/UCore.pas
- Timestamp:
- Sep 28, 2011, 8:34:06 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UCore.pas
r22 r23 8 8 Dialogs, Classes, SysUtils, Contnrs, Graphics, SpecializedMatrix, SpecializedList, 9 9 IntfGraphics, FPImage, LCLType, SpecializedBitmap, GraphType, Math, URectangle, 10 Syncobjs, UThreading ;10 Syncobjs, UThreading, Forms; 11 11 12 12 const … … 173 173 IntfImage: TLazIntfImage; 174 174 ClearBackground: Boolean; 175 function GetPlayerCount: Integer;176 175 procedure SetActive(const AValue: Boolean); 177 176 procedure SetBitmap(const AValue: TBitmap); 178 procedure SetPlayerCount(const AValue: Integer);179 177 procedure Redraw; 180 178 function IsInsideHouses(Pos: TPoint): Boolean; 181 179 procedure DoDrawToBitmap; 180 procedure InitPlayerPool; 182 181 public 183 182 Keyboard: TKeyboard; 184 183 World: TWorld; 184 PlayerPool: TListObject; // TListObject<TPlayer> 185 185 Players: TListObject; // TListObject<TPlayer> 186 186 Lock: TCriticalSection; … … 189 189 procedure ResizePlayerFrames; 190 190 procedure Tick; 191 procedure Draw ;191 procedure Draw(Thread: TVirtualThread); 192 192 procedure NewGame; 193 property PlayerCount: Integer read GetPlayerCount write SetPlayerCount;194 193 property Bitmap: TBitmap read FBitmap write SetBitmap; 195 194 property Active: Boolean read FActive write SetActive; … … 213 212 implementation 214 213 214 resourcestring 215 SPlayer = 'Player'; 216 217 215 218 function SwapBRComponent(Value: Integer): Integer; 216 219 begin … … 236 239 begin 237 240 repeat 238 Engine.Draw ;241 Engine.Draw(Self); 239 242 Sleep(50); 240 243 until Terminated; … … 589 592 var 590 593 I: Integer; 594 P: Integer; 591 595 Pos: TPoint; 592 596 D: Real; … … 660 664 end; 661 665 end else begin 662 if (ItemsXY[Pos.X, Pos.Y] = Byte(miPlayer1TankBody)) or 663 (ItemsXY[Pos.X, Pos.Y] = Byte(miPlayer1TankBody2)) then 664 with TPlayer(Engine.Players[0]) do begin 665 Shield := Shield - 1 / ShieldSteps; 666 end; 667 if (ItemsXY[Pos.X, Pos.Y] = Byte(miPlayer2Tankbody)) or 668 (ItemsXY[Pos.X, Pos.Y] = Byte(miPlayer2TankBody2)) then 669 with TPlayer(Engine.Players[1]) do begin 670 Shield := Shield - 1 / ShieldSteps; 671 end; 672 if (ItemsXY[Pos.X, Pos.Y] = Byte(miPlayer3TankBody)) or 673 (ItemsXY[Pos.X, Pos.Y] = Byte(miPlayer3TankBody2)) then 674 with TPlayer(Engine.Players[2]) do begin 675 Shield := Shield - 1 / ShieldSteps; 676 end; 677 if (ItemsXY[Pos.X, Pos.Y] = Byte(miPlayer4TankBody)) or 678 (ItemsXY[Pos.X, Pos.Y] = Byte(miPlayer4TankBody2)) then 679 with TPlayer(Engine.Players[3]) do begin 680 Shield := Shield - 1 / ShieldSteps; 681 end; 666 for P := 0 to Engine.Players.Count - 1 do 667 with TPlayer(Engine.Players[P]) do 668 if Enabled and (TMatter(Engine.World.Matter[ItemsXY[Pos.X, Pos.Y]]).Kind = mkTankBody) then 669 Shield := Shield - 1 / ShieldSteps; 682 670 if StopByDirt then Explosion(LastPos, BulletExplosionRange); 683 671 Bullets.Delete(I); … … 753 741 not (((Y = 0) or (Y = (HouseSize - 1))) and (X > ((HouseSize - DoorSize) div 2)) and 754 742 (X < ((HouseSize - 1 + DoorSize) div 2))) 755 then Matter := Byte(miPlayer1 Cannon) + Id * 4743 then Matter := Byte(miPlayer1Home) + Id * 4 756 744 else Matter := Byte(miSpace); 757 745 Engine.World.Surface.ItemsXY[House.Left + X, … … 965 953 { TEngine } 966 954 967 function TEngine.GetPlayerCount: Integer;968 begin969 Result := Players.Count;970 end;971 972 955 procedure TEngine.SetActive(const AValue: Boolean); 973 956 begin … … 986 969 FSystemThread.Start; 987 970 end else begin 971 FDrawThread.Terminate; 972 Application.ProcessMessages; 988 973 FreeAndNil(FDrawThread); 989 974 FreeAndNil(FSystemThread); … … 994 979 begin 995 980 FBitmap := AValue; 996 ResizePlayerFrames;997 end;998 999 procedure TEngine.SetPlayerCount(const AValue: Integer);1000 var1001 NewPlayer: TPlayer;1002 I: Integer;1003 begin1004 if Players.Count < AValue then begin1005 for I := Players.Count to AValue - 1 do begin1006 NewPlayer := TPlayer.Create;1007 NewPlayer.Engine := Self;1008 NewPlayer.Id := I;1009 NewPlayer.Name := 'Player ' + IntToStr(I);1010 NewPlayer.InitTanks;1011 Players.Add(NewPlayer);1012 end;1013 end else1014 if Players.Count > AValue then begin1015 for I := Players.Count - 1 downto AValue do1016 Players.Delete(I);1017 end;1018 981 ResizePlayerFrames; 1019 982 end; … … 1125 1088 end; 1126 1089 1090 procedure TEngine.InitPlayerPool; 1091 var 1092 I: Integer; 1093 begin 1094 PlayerPool.Clear; 1095 with TPlayer(PlayerPool.AddNew(TPlayer.Create)) do begin 1096 Keys.Left := 65; 1097 Keys.Down := 83; 1098 Keys.Right := 68; 1099 Keys.Up := 87; 1100 Keys.Shoot := 69; 1101 Enabled := True; 1102 end; 1103 with TPlayer(PlayerPool.AddNew(TPlayer.Create)) do begin 1104 Keys.Left := 37; 1105 Keys.Down := 40; 1106 Keys.Right := 39; 1107 Keys.Up := 38; 1108 Keys.Shoot := 17; 1109 Enabled := True; 1110 end; 1111 with TPlayer(PlayerPool.AddNew(TPlayer.Create)) do begin 1112 Keys.Left := 76; 1113 Keys.Down := 186; 1114 Keys.Right := 222; 1115 Keys.Up := 80; 1116 Keys.Shoot := 191; 1117 end; 1118 with TPlayer(PlayerPool.AddNew(TPlayer.Create)) do begin 1119 Keys.Left := 100; 1120 Keys.Down := 98; 1121 Keys.Right := 102; 1122 Keys.Up := 104; 1123 Keys.Shoot := 105; 1124 end; 1125 for I := 0 to PlayerPool.Count - 1 do 1126 with TPlayer(PlayerPool[I]) do begin 1127 Engine := Self; 1128 Id := I; 1129 InitTanks; 1130 Name := SPlayer + ' ' + IntToStr(I + 1); 1131 end; 1132 end; 1133 1127 1134 procedure TEngine.ResizePlayerFrames; 1128 1135 var … … 1159 1166 FBitmapLock := TCriticalSection.Create; 1160 1167 IntfImage := TLazIntfImage.Create(1, 1); 1168 PlayerPool := TListObject.Create; 1161 1169 Players := TListObject.Create; 1170 Players.OwnsObjects := False; 1162 1171 Keyboard := TKeyboard.Create; 1163 1172 World := TWorld.Create; 1164 1173 World.Engine := Self; 1174 InitPlayerPool; 1165 1175 Redraw; 1166 1176 end; … … 1172 1182 FBitmapLock.Free; 1173 1183 IntfImage.Free; 1184 PlayerPool.Free; 1174 1185 Players.Free; 1175 1186 Keyboard.Free; … … 1194 1205 end; 1195 1206 1196 procedure TEngine.Draw ;1207 procedure TEngine.Draw(Thread: TVirtualThread); 1197 1208 var 1198 1209 I: Integer; … … 1210 1221 Lock.Release; 1211 1222 end; 1212 Synchronize(DoDrawToBitmap);1223 if not Thread.Terminated then Thread.Synchronize(DoDrawToBitmap); 1213 1224 end; 1214 1225 end; … … 1219 1230 I2: Integer; 1220 1231 begin 1232 Players.Clear; 1233 for I := 0 to PlayerPool.Count - 1 do 1234 with TPlayer(PlayerPool[I]) do 1235 if Enabled then 1236 Players.Add(PlayerPool[I]); 1237 ResizePlayerFrames; 1238 1221 1239 World.Generate; 1222 1240 … … 1227 1245 end; 1228 1246 1229 initialization1230 1231 Engine := TEngine.Create;1232 1233 finalization1234 1235 Engine.Free;1236 1237 1247 end. 1238 1248
Note:
See TracChangeset
for help on using the changeset viewer.