(version 2)
(include "sci.sh")
(use "Main")
(use "Cycle")
(script 57)



(class JumpX of Motion
    (properties
        client 0
        caller 0
        x 0
        y 0
        dx 0
        dy 0
        {b-moveCnt} 0
        {b-i1} 0
        {b-i2} 0
        {b-di} 0
        {b-xAxis} 0
        {b-incr} 0
        completed 0
        xLast 0
        yLast 0
        desX 0
        desY 0
        xInc 0
        yInc 0
        zStep 0
        level 0
        velocity 0
        gravity 10
        height 0
        peak 0
    )

    (method (init theClient param2 theCaller theCaller_2 theCaller_3 param6)
        (var temp0, temp1, temp2, temp3)
        = client theClient
        = temp0 0
        = temp1 0
        = temp2 0
        (switch (paramTotal)
            (case 2
                (self:height(param2))
            )
            (case 3
                (self:height(param2))
                = caller theCaller
            )
            (case 4
                (self:desX(param2))
                (self:height(theCaller))
                = temp0 Abs((- param2 (send client:x)))
                = caller theCaller_2
            )
            (case 5
                (self:desX(param2))
                (self:desY(theCaller))
                = temp0 Abs((- param2 (send client:x)))
                = temp1 Abs((- theCaller (send client:y)))
                (self:height(theCaller_2))
                = caller theCaller_3
            )
            (default 
                = caller theCaller_3
                (self:height(theCaller_2))
            )
        )
        (if (== paramTotal 7)
            (self:level(param6))
        )(else
            (self:level((send client:z)))
        )
        = temp3 (/ gravity 2)
        = temp2 (- (self:height) (send client:z))
        (if (> temp2 0)
            (self:velocity((+ Sqrt((* (* 2 temp2) temp3)) 1)))
            (self:zStep((- 0 temp3)))
        )(else
            (self:peak(1))
            (self:zStep(temp3))
            (self:level(height))
        )
        (if (< (self:xInc((/ temp0 (* (+ (/ velocity temp3) 1) 2)))) 0)
            (self:xInc(1))
        )
        (if (< (self:yInc((/ temp1 (* (+ (/ velocity temp3) 1) 2)))) 0)
            (self:yInc(1))
        )
        = {b-moveCnt} gLastTicks
    )


    (method (doit)
        (if (>= Abs((- gLastTicks {b-moveCnt})) (send client:moveSpeed))
            = {b-moveCnt} gLastTicks
            (if (((send client:cycler) and (send ((send client:cycler)):isKindOf(JumpCycler))) and not (send ((send client:cycler)):clear))
                return 
            )
            (if ((self:peak))
                (if (< (- (send client:z) velocity) level)
                    (send client:z(level))
                )(else
                    (send client:z((- (send client:z) velocity)))
                )
            )(else
                (send client:z((+ (send client:z) velocity)))
            )
            (if (<> xInc 0)
                (self:moveXPlane())
            )
            (if (<> yInc 0)
                (self:moveYPlane())
            )
            = velocity (+ velocity zStep)
            (if ((<= velocity 0) or (<= (send client:z) level))
                (if ((self:peak))
                    (self:moveDone())
                )(else
                    (self:peak(1))
                    (self:zStep((- 0 zStep)))
                    (self:chkTarget())
                )
                return 
            )
        )
    )


    (method (moveDone)
        (if (caller)
            = completed 1
        )
        (if ((send client:cycler))
            (if ((send ((send client:cycler)):isKindOf(JumpCycler)))
                (if ((send ((send client:cycler)):clear))
                    return 
                )
            )(else
                = global37 1
            )
        )(else
            = global37 1
        )
    )


    (method (motionCue)
        (send client:mover(0))
        (if (completed and IsObject(caller))
            (send caller:cue())
        )
        (self:dispose())
    )


    (method (moveXPlane)
        (if (< xInc 0)
            (if (< (+ (send client:x) xInc) desX)
                (send client:x(desX))
                = xInc 0
            )(else
                (send client:x((+ (send client:x) xInc)))
            )
        )(else
            (if (> (+ (send client:x) xInc) desX)
                (send client:x(desX))
                = xInc 0
            )(else
                (send client:x((+ (send client:x) xInc)))
            )
        )
    )


    (method (moveYPlane)
        (if (< yInc 0)
            (if (< (+ (send client:y) yInc) desY)
                (send client:y(desY))
                = yInc 0
            )(else
                (send client:y((+ (send client:y) yInc)))
            )
        )(else
            (if (> (+ (send client:y) yInc) desY)
                (send client:y(desY))
                = yInc 0
            )(else
                (send client:y((+ (send client:y) yInc)))
            )
        )
    )


    (method (chkTarget)
    )

)
(class JumpCycler of Cycle
    (properties
        client 0
        caller 0
        cycleDir 1
        cycleCnt 0
        completed 0
        clear 0
        start 0
        mid 0
        changed 1
    )

    (method (init param1 theStart theMid)
        = start theStart
        = mid theMid
        (super:init(param1))
        (send client:cel(0))
    )


    (method (doit)
        (var jumpCyclerNextCel)
        (if (not (self:clear))
            = jumpCyclerNextCel (self:nextCel())
            (send client:cel(jumpCyclerNextCel))
            (if (<> jumpCyclerNextCel (send client:lastCel()))
                (if ((== jumpCyclerNextCel (self:start())) or (== jumpCyclerNextCel (self:mid)))
                    (self:clear(1))
                )
            )(else
                (self:clear(1))
            )
        )(else
            (if ((send ((send client:mover)):peak) and (self:changed))
                (self:clear(0))
                (self:changed(0))
            )(else
                (if (== (send client:cel) (send client:lastCel()))
                    (send client:cel(0))
                    (self:cycleDone())
                )(else
                    (if ((send ((send client:mover)):completed))
                        (self:clear(0))
                    )
                )
            )
        )
    )


    (method (cycleDone)
        = completed 1
        (send client:cycler(0))
        (self:dispose())
        (send ((send client:mover)):motionCue())
    )

)
