hedgewars/uGears.pas
changeset 16 b6f4b413dd41
parent 15 6200cca92480
child 17 a6bed8d31444
equal deleted inserted replaced
15:6200cca92480 16:b6f4b413dd41
   195                 Result.Elasticity:= 0.55;
   195                 Result.Elasticity:= 0.55;
   196                 Result.Friction:= 0.995;
   196                 Result.Friction:= 0.995;
   197                 Result.Timer:= 3000;
   197                 Result.Timer:= 3000;
   198                 end;
   198                 end;
   199         gtCase: begin
   199         gtCase: begin
   200                 Result.HalfWidth:= 10;
   200                 Result.HalfWidth:= 14;
   201                 Result.HalfHeight:= 10;
   201                 Result.HalfHeight:= 14;
   202                 Result.Elasticity:= 0.6
   202                 Result.Elasticity:= 0.6
   203                 end;
   203                 end;
   204      end;
   204      end;
   205 if GearsList = nil then GearsList:= Result
   205 if GearsList = nil then GearsList:= Result
   206                    else begin
   206                    else begin
   461                     end;
   461                     end;
   462        gtExplosion: DrawSprite(sprExplosion50, Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface);
   462        gtExplosion: DrawSprite(sprExplosion50, Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface);
   463             gtMine: if ((Gear.State and gstAttacking) = 0)or((Gear.Timer and $3FF) < 420)
   463             gtMine: if ((Gear.State and gstAttacking) = 0)or((Gear.Timer and $3FF) < 420)
   464                        then DrawSprite(sprMineOff , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface)
   464                        then DrawSprite(sprMineOff , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface)
   465                        else DrawSprite(sprMineOn  , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface);
   465                        else DrawSprite(sprMineOn  , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface);
   466             gtCase: DrawSprite(sprCase, Round(Gear.X) - 12 + WorldDx, Round(Gear.Y) - 12 + WorldDy, 0, Surface);
   466             gtCase: DrawSprite(sprCase, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, 0, Surface);
   467               end;
   467               end;
   468       Gear:= Gear.NextGear
   468       Gear:= Gear.NextGear
   469       end;
   469       end;
   470 end;
   470 end;
   471 
   471 
   487 procedure AddMiscGears;
   487 procedure AddMiscGears;
   488 var i, x, y: integer;
   488 var i, x, y: integer;
   489 begin
   489 begin
   490 for i:= 0 to cCloudsNumber do AddGear( - cScreenWidth + i * ((cScreenWidth * 2 + 2304) div cCloudsNumber), -128, gtCloud, random(4), (0.5-random)*0.01);
   490 for i:= 0 to cCloudsNumber do AddGear( - cScreenWidth + i * ((cScreenWidth * 2 + 2304) div cCloudsNumber), -128, gtCloud, random(4), (0.5-random)*0.01);
   491 AddGear(0, 0, gtActionTimer, gtsStartGame, 0, 0, 2000).Health:= 3;
   491 AddGear(0, 0, gtActionTimer, gtsStartGame, 0, 0, 2000).Health:= 3;
   492 for i:= 0 to 2 do
   492 for i:= 0 to 3 do
   493     begin
   493     begin
   494     GetHHPoint(x, y);
   494     GetHHPoint(x, y);
   495     AddGear(X, Y + 9, gtMine, 0);
   495     AddGear(X, Y + 9, gtMine, 0);
   496     end;
       
   497 
       
   498 for i:= 0 to 0 do
       
   499     begin
       
   500     GetHHPoint(x, y);
       
   501     AddGear(X, Y, gtCase, 0)
       
   502     end;
   496     end;
   503 end;
   497 end;
   504 
   498 
   505 procedure doMakeExplosion(X, Y, Radius: integer; Mask: LongWord);
   499 procedure doMakeExplosion(X, Y, Radius: integer; Mask: LongWord);
   506 var Gear: PGear;
   500 var Gear: PGear;
   570       t:= t.NextGear
   564       t:= t.NextGear
   571       end;
   565       end;
   572 Result:= nil
   566 Result:= nil
   573 end;
   567 end;
   574 
   568 
       
   569 function CheckGearsNear(mX, mY: integer; Kind: TGearsType; rX, rY: integer): PGear;
       
   570 var t: PGear;
       
   571 begin
       
   572 t:= GearsList;
       
   573 rX:= sqr(rX);
       
   574 rY:= sqr(rY);
       
   575 while t <> nil do
       
   576       begin
       
   577       if t.Kind in Kind then
       
   578          if sqr(mX - t.X) / rX + sqr(mY - t.Y) / rY <= 1 then
       
   579             begin
       
   580             Result:= t;
       
   581             exit
       
   582             end;
       
   583       t:= t.NextGear
       
   584       end;
       
   585 Result:= nil
       
   586 end;
       
   587 
       
   588 function CountGears(Kind: TGearType): Longword;
       
   589 var t: PGear;
       
   590 begin
       
   591 Result:= 0;
       
   592 t:= GearsList;
       
   593 while t <> nil do
       
   594       begin
       
   595       if t.Kind = Kind then inc(Result);
       
   596       t:= t.NextGear
       
   597       end;
       
   598 end;
       
   599 
   575 procedure SpawnBoxOfSmth;
   600 procedure SpawnBoxOfSmth;
   576 begin
   601 var i, x, y, k: integer;
       
   602     b: boolean;
       
   603 begin
       
   604 if CountGears(gtCase) > 4 then exit;
       
   605 k:= 7;
       
   606 repeat
       
   607   x:= getrandom(2000) + 24;
       
   608   b:= false;
       
   609   y:= -1;
       
   610   while (y < 1024) and not b do
       
   611         begin
       
   612         inc(y);
       
   613         i:= x - 14;
       
   614         while (i <= x + 14) and not b do // 14 is gtCase HalfWidth
       
   615               begin
       
   616               if Land[y, i] <> 0 then b:= true;
       
   617               inc(i)
       
   618               end;
       
   619         end;
       
   620   if b then
       
   621      b:= CheckGearsNear(x, y, [gtMine, gtHedgehog, gtCase], 70, 70) = nil;
       
   622   dec(k)
       
   623 until (k = 0) or b;
       
   624 if b then FollowGear:= AddGear(x, -30, gtCase, 0)
   577 end;
   625 end;
   578 
   626 
   579 initialization
   627 initialization
   580 
   628 
   581 finalization
   629 finalization