3566 else if Gear^.Timer < 6000 then |
3566 else if Gear^.Timer < 6000 then |
3567 Gear^.RenderTimer:= true; |
3567 Gear^.RenderTimer:= true; |
3568 |
3568 |
3569 if not cakeStep(Gear) then Gear^.doStep:= @doStepCakeFall; |
3569 if not cakeStep(Gear) then Gear^.doStep:= @doStepCakeFall; |
3570 |
3570 |
|
3571 // Cake passed world edge. |
3571 if (Gear^.Karma = 1) then |
3572 if (Gear^.Karma = 1) then |
3572 begin |
3573 (* This code is not ideal, but at least not horribly broken. |
3573 // Cake hit bouncy edge, turn around |
3574 The cake tries to reach the other side and continue to walk, |
|
3575 but there are some exceptions. |
|
3576 This code is called *after* the X coordinate have been wrapped. |
|
3577 Depending on terrain on the other side, the cake does this: |
|
3578 * Cake collides horizontally (even by 1 pixel): Turn around |
|
3579 * Cake does not see walkable ground above or below: Fall |
|
3580 * Otherwise: Walk normally |
|
3581 *) |
|
3582 begin |
|
3583 // Update coordinates |
|
3584 tdx:=Gear^.X; |
|
3585 if (hwRound(Gear^.X) < LongInt(leftX)) then |
|
3586 Gear^.X:= Gear^.X + int2hwfloat(rightX - leftX) |
|
3587 else Gear^.X:= Gear^.X - int2hwfloat(rightX - leftX); |
|
3588 |
|
3589 Gear^.Tag:= 0; |
|
3590 if ((TestCollisionXwithGear(Gear, 1) <> 0) or (TestCollisionXwithGear(Gear, -1) <> 0)) then |
|
3591 // Cake collided horizontally, turn around. Prevents cake from being stuck in infinite loop. |
|
3592 // This can also happen if the terrain is just a slight slope. :-( |
|
3593 begin |
|
3594 Gear^.X := tdx; |
|
3595 Gear^.Karma := 3; |
|
3596 end |
|
3597 else |
|
3598 begin |
|
3599 // Check if cake has something to walk on the other side. If not, make it drop. |
|
3600 // There is nothing for the cake to stand on. |
|
3601 if (TestCollisionYwithGear(Gear, 1) = 0) and (TestCollisionYwithGear(Gear, -1) = 0) then |
|
3602 Gear^.doStep:= @doStepCakeFall; |
|
3603 Gear^.Karma := 4; |
|
3604 end; |
|
3605 end; |
|
3606 // Cake bounced! |
|
3607 if (Gear^.Karma = 2) or (Gear^.Karma = 3) then |
|
3608 begin |
|
3609 // Turn cake around |
3574 Gear^.dX.isNegative := (not Gear^.dX.isNegative); |
3610 Gear^.dX.isNegative := (not Gear^.dX.isNegative); |
3575 Gear^.WDTimer := 0; |
3611 Gear^.WDTimer := 0; |
3576 Gear^.Angle := (LongInt(Gear^.Angle) + 2) and 3; |
3612 Gear^.Angle := (LongInt(Gear^.Angle) + 2) and 3; |
3577 Gear^.Karma := 0; |
|
3578 |
3613 |
3579 // Bounce effect |
3614 // Bounce effect |
3580 if (Gear^.Radius > 2) then |
3615 if (Gear^.Karma = 2) and (Gear^.Radius > 2) then |
3581 AddBounceEffectForGear(Gear, 0.55); |
3616 AddBounceEffectForGear(Gear, 0.55); |
3582 |
3617 |
|
3618 Gear^.Tag:= 0; |
|
3619 Gear^.Karma := 4; |
|
3620 end; |
|
3621 if (Gear^.Karma = 4) then |
|
3622 begin |
3583 // Reset CakePoints to fix cake angle |
3623 // Reset CakePoints to fix cake angle |
3584 cakeData:= PCakeData(Gear^.Data); |
3624 cakeData:= PCakeData(Gear^.Data); |
3585 with cakeData^ do |
3625 with cakeData^ do |
3586 begin |
3626 begin |
3587 for i:= 0 to Pred(cakeh) do |
3627 for i:= 0 to Pred(cakeh) do |