635 |
635 |
636 //////////////////////////////////////////////////////////////////////////////// |
636 //////////////////////////////////////////////////////////////////////////////// |
637 |
637 |
638 procedure doStepRopeWork(Gear: PGear); |
638 procedure doStepRopeWork(Gear: PGear); |
639 var HHGear: PGear; |
639 var HHGear: PGear; |
640 len, cs, cc, tx, ty, nx, ny, ropeDx, ropeDy: hwFloat; |
640 len, cs, cc, tx, ty, nx, ny, ropeDx, ropeDy, mdX, mdY: hwFloat; |
641 lx, ly: LongInt; |
641 lx, ly: LongInt; |
642 haveCollision, |
642 haveCollision, |
643 haveDivided: boolean; |
643 haveDivided: boolean; |
644 |
644 |
645 procedure DeleteMe; |
645 procedure DeleteMe; |
660 begin |
660 begin |
661 DeleteMe; |
661 DeleteMe; |
662 exit |
662 exit |
663 end; |
663 end; |
664 |
664 |
|
665 if (Gear^.Message and gm_Left <> 0) then HHGear^.dX:= HHGear^.dX - _0_0002 else |
|
666 if (Gear^.Message and gm_Right <> 0) then HHGear^.dX:= HHGear^.dX + _0_0002; |
|
667 |
|
668 if not TestCollisionYwithGear(HHGear, 1) then HHGear^.dY:= HHGear^.dY + cGravity; |
|
669 |
665 ropeDx:= HHGear^.X - Gear^.X; // vector between hedgehog and rope attaching point |
670 ropeDx:= HHGear^.X - Gear^.X; // vector between hedgehog and rope attaching point |
666 ropeDy:= HHGear^.Y - Gear^.Y; |
671 ropeDy:= HHGear^.Y - Gear^.Y; |
667 |
672 |
668 if (Gear^.Message and gm_Left <> 0) then HHGear^.dX:= HHGear^.dX - _0_0002 else |
673 mdX:= ropeDx + HHGear^.dX; |
669 if (Gear^.Message and gm_Right <> 0) then HHGear^.dX:= HHGear^.dX + _0_0002; |
674 mdY:= ropeDy + HHGear^.dY; |
670 |
675 len:= _1 / Distance(mdX, mdY); |
671 if not TestCollisionYwithGear(HHGear, 1) then HHGear^.dY:= HHGear^.dY + cGravity; |
676 mdX:= mdX * len; // rope vector plus hedgehog direction vector normalized |
672 |
677 mdY:= mdY * len; |
673 tx:= ropeDx + HHGear^.dX; |
678 |
674 ty:= ropeDy + HHGear^.dY; |
679 Gear^.dX:= mdX; // for visual purposes only |
675 len:= _1 / Distance(tx, ty); |
680 Gear^.dY:= mdY; |
676 tx:= tx * len; // rope vector plus hedgehog direction vector normalized |
681 |
677 ty:= ty * len; |
682 ///// |
678 |
683 tx:= HHGear^.X; |
679 Gear^.dX:= tx; // for visual purposes only |
684 ty:= HHGear^.Y; |
680 Gear^.dY:= ty; |
685 |
|
686 if ((Gear^.Message and gm_Down) <> 0) and (Gear^.Elasticity < Gear^.Friction) then |
|
687 if not (TestCollisionXwithGear(HHGear, hwSign(ropeDx)) |
|
688 or TestCollisionYwithGear(HHGear, hwSign(ropeDy))) then |
|
689 Gear^.Elasticity:= Gear^.Elasticity + _0_3; |
|
690 |
|
691 if ((Gear^.Message and gm_Up) <> 0) and (Gear^.Elasticity > _30) then |
|
692 if not (TestCollisionXwithGear(HHGear, -hwSign(ropeDx)) |
|
693 or TestCollisionYwithGear(HHGear, -hwSign(ropeDy))) then |
|
694 Gear^.Elasticity:= Gear^.Elasticity - _0_3; |
|
695 |
|
696 HHGear^.X:= Gear^.X + mdX * Gear^.Elasticity; |
|
697 HHGear^.Y:= Gear^.Y + mdY * Gear^.Elasticity; |
|
698 |
|
699 HHGear^.dX:= HHGear^.X - tx; |
|
700 HHGear^.dY:= HHGear^.Y - ty; |
|
701 //// |
|
702 |
681 |
703 |
682 haveDivided:= false; |
704 haveDivided:= false; |
683 // check whether rope needs dividing |
705 // check whether rope needs dividing |
684 len:= _1 / Distance(ropeDx, ropeDy); // old rope pos |
706 len:= _1 / Distance(ropeDx, ropeDy); // old rope pos |
685 nx:= ropeDx * len; |
707 nx:= ropeDx * len; |
686 ny:= ropeDy * len; |
708 ny:= ropeDy * len; |
687 |
709 |
688 len:= Gear^.Elasticity - _20; |
710 len:= Gear^.Elasticity - _0_3x70; |
689 while len > _5 do |
711 while len > _0_3 do |
690 begin |
712 begin |
691 lx:= hwRound(Gear^.X + tx * len); |
713 lx:= hwRound(Gear^.X + mdX * len); |
692 ly:= hwRound(Gear^.Y + ty * len); |
714 ly:= hwRound(Gear^.Y + mdY * len); |
693 if ((ly and $FFFFFC00) = 0) and ((lx and $FFFFF800) = 0) and (Land[ly, lx] <> 0) then |
715 if ((ly and $FFFFFC00) = 0) and ((lx and $FFFFF800) = 0) and (Land[ly, lx] <> 0) then |
694 begin |
716 begin |
695 with RopePoints.ar[RopePoints.Count] do |
717 with RopePoints.ar[RopePoints.Count] do |
696 begin |
718 begin |
697 X:= Gear^.X; |
719 X:= Gear^.X; |
698 Y:= Gear^.Y; |
720 Y:= Gear^.Y; |
699 if RopePoints.Count = 0 then RopePoints.HookAngle:= DxDy2Angle(Gear^.dY, Gear^.dX); |
721 if RopePoints.Count = 0 then RopePoints.HookAngle:= DxDy2Angle(Gear^.dY, Gear^.dX); |
700 b:= (tx * HHGear^.dY) > (ty * HHGear^.dX); |
722 b:= (nx * HHGear^.dY) > (ny * HHGear^.dX); |
701 dLen:= len |
723 dLen:= len |
702 end; |
724 end; |
703 Gear^.X:= Gear^.X + nx * len; |
725 Gear^.X:= Gear^.X + nx * len; |
704 Gear^.Y:= Gear^.Y + ny * len; |
726 Gear^.Y:= Gear^.Y + ny * len; |
705 inc(RopePoints.Count); |
727 inc(RopePoints.Count); |
718 tx:= RopePoints.ar[Pred(RopePoints.Count)].X; |
740 tx:= RopePoints.ar[Pred(RopePoints.Count)].X; |
719 ty:= RopePoints.ar[Pred(RopePoints.Count)].Y; |
741 ty:= RopePoints.ar[Pred(RopePoints.Count)].Y; |
720 if RopePoints.ar[Pred(RopePoints.Count)].b xor ((tx - Gear^.X) * (ty - HHGear^.Y) > (tx - HHGear^.X) * (ty - Gear^.Y)) then |
742 if RopePoints.ar[Pred(RopePoints.Count)].b xor ((tx - Gear^.X) * (ty - HHGear^.Y) > (tx - HHGear^.X) * (ty - Gear^.Y)) then |
721 begin |
743 begin |
722 dec(RopePoints.Count); |
744 dec(RopePoints.Count); |
723 Gear^.X:=RopePoints.ar[RopePoints.Count].X; |
745 Gear^.X:= RopePoints.ar[RopePoints.Count].X; |
724 Gear^.Y:=RopePoints.ar[RopePoints.Count].Y; |
746 Gear^.Y:= RopePoints.ar[RopePoints.Count].Y; |
725 Gear^.Elasticity:= Gear^.Elasticity + RopePoints.ar[RopePoints.Count].dLen; |
747 Gear^.Elasticity:= Gear^.Elasticity + RopePoints.ar[RopePoints.Count].dLen; |
726 Gear^.Friction:= Gear^.Friction + RopePoints.ar[RopePoints.Count].dLen |
748 Gear^.Friction:= Gear^.Friction + RopePoints.ar[RopePoints.Count].dLen |
727 end |
749 end |
728 end; |
750 end; |
729 |
|
730 ropeDx:= HHGear^.X - Gear^.X; |
|
731 ropeDy:= HHGear^.Y - Gear^.Y; |
|
732 |
|
733 cs:= ropeDy + HHGear^.dY; |
|
734 cc:= ropeDx + HHGear^.dX; |
|
735 len:= _1 / Distance(cc, cs); |
|
736 cc:= cc * len; |
|
737 cs:= cs * len; |
|
738 |
|
739 tx:= HHGear^.X; |
|
740 ty:= HHGear^.Y; |
|
741 |
|
742 if ((Gear^.Message and gm_Down) <> 0) and (Gear^.Elasticity < Gear^.Friction) then |
|
743 if not (TestCollisionXwithGear(HHGear, hwSign(ropeDx)) |
|
744 or TestCollisionYwithGear(HHGear, hwSign(ropeDy))) then Gear^.Elasticity:= Gear^.Elasticity + _0_3; |
|
745 |
|
746 if ((Gear^.Message and gm_Up) <> 0) and (Gear^.Elasticity > _30) then |
|
747 if not (TestCollisionXwithGear(HHGear, -hwSign(ropeDx)) |
|
748 or TestCollisionYwithGear(HHGear, -hwSign(ropeDy))) then Gear^.Elasticity:= Gear^.Elasticity - _0_3; |
|
749 |
|
750 HHGear^.X:= Gear^.X + cc*Gear^.Elasticity; |
|
751 HHGear^.Y:= Gear^.Y + cs*Gear^.Elasticity; |
|
752 |
|
753 HHGear^.dX:= HHGear^.X - tx; |
|
754 HHGear^.dY:= HHGear^.Y - ty; |
|
755 |
751 |
756 haveCollision:= false; |
752 haveCollision:= false; |
757 if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then |
753 if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then |
758 begin |
754 begin |
759 HHGear^.dX:= -_0_6 * HHGear^.dX; |
755 HHGear^.dX:= -_0_6 * HHGear^.dX; |