44 TGearArray = record |
44 TGearArray = record |
45 ar: array[0..cMaxGearArrayInd] of PGear; |
45 ar: array[0..cMaxGearArrayInd] of PGear; |
46 Count: Longword |
46 Count: Longword |
47 end; |
47 end; |
48 |
48 |
49 procedure FillRoundInLand(X, Y, Radius: integer; Value: Longword); |
|
50 procedure AddGearCI(Gear: PGear); |
49 procedure AddGearCI(Gear: PGear); |
51 procedure DeleteCI(Gear: PGear); |
50 procedure DeleteCI(Gear: PGear); |
52 function CheckGearsCollision(Gear: PGear): PGearArray; |
51 function CheckGearsCollision(Gear: PGear): PGearArray; |
53 function HHTestCollisionYwithGear(Gear: PGear; Dir: integer): boolean; |
52 function HHTestCollisionYwithGear(Gear: PGear; Dir: integer): boolean; |
54 function TestCollisionXwithGear(Gear: PGear; Dir: integer): boolean; |
53 function TestCollisionXwithGear(Gear: PGear; Dir: integer): boolean; |
55 function TestCollisionYwithGear(Gear: PGear; Dir: integer): boolean; |
54 function TestCollisionYwithGear(Gear: PGear; Dir: integer): boolean; |
56 function TestCollisionXwithXYShift(Gear: PGear; ShiftX, ShiftY: integer; Dir: integer): boolean; |
55 function TestCollisionXwithXYShift(Gear: PGear; ShiftX, ShiftY: integer; Dir: integer): boolean; |
57 function TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: integer; Dir: integer): boolean; |
56 function TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: integer; Dir: integer): boolean; |
58 |
57 |
59 implementation |
58 implementation |
60 uses uMisc, uConsts, uLand; |
59 uses uMisc, uConsts, uLand, uGraphics; |
61 |
60 |
62 type TCollisionEntry = record |
61 type TCollisionEntry = record |
63 X, Y, Radius: integer; |
62 X, Y, Radius: integer; |
64 cGear: PGear; |
63 cGear: PGear; |
65 end; |
64 end; |
67 const MAXRECTSINDEX = 255; |
66 const MAXRECTSINDEX = 255; |
68 var Count: Longword = 0; |
67 var Count: Longword = 0; |
69 cinfos: array[0..MAXRECTSINDEX] of TCollisionEntry; |
68 cinfos: array[0..MAXRECTSINDEX] of TCollisionEntry; |
70 ga: TGearArray; |
69 ga: TGearArray; |
71 |
70 |
72 procedure FillRoundInLand(X, Y, Radius: integer; Value: Longword); |
|
73 var ty, tx: integer; |
|
74 begin |
|
75 for ty:= max(-Radius, -y) to min(radius, 1023 - y) do |
|
76 for tx:= max(0, round(x-radius*sqrt(1-sqr(ty/radius)))) to min(2047,round(x+radius*sqrt(1-sqr(ty/radius)))) do |
|
77 Land[ty + y, tx]:= Value; |
|
78 end; |
|
79 |
|
80 procedure AddGearCI(Gear: PGear); |
71 procedure AddGearCI(Gear: PGear); |
81 begin |
72 begin |
82 if Gear.CollIndex < High(Longword) then exit; |
73 if Gear.CollIndex < High(Longword) then exit; |
83 TryDo(Count <= MAXRECTSINDEX, 'Collision rects array overflow', true); |
74 TryDo(Count <= MAXRECTSINDEX, 'Collision rects array overflow', true); |
84 with cinfos[Count] do |
75 with cinfos[Count] do |
85 begin |
76 begin |
86 X:= round(Gear.X); |
77 X:= round(Gear.X); |
87 Y:= round(Gear.Y); |
78 Y:= round(Gear.Y); |