Sparky - Platformer Engine
@Stage\n\nwhen flag clicked\nbroadcast (progressEnded v)\nbroadcast (hide_stage v)\nbroadcast (SparkyHide v)\nbroadcast (deleteBlock v)\nbroadcast (showStartButtons v)\nswitch backdrop to (startscreen v)\n\nwhen I receive [sparkyisdead v]\nswitch backdrop to (dead v)\nwait (0.5) seconds\nswitch backdrop to (background v)\n\nwhen I receive [gameending v]\nswitch backdrop to (ending v)\n\n@monster1\n\nwhen I start as a clone\ngo to x: (xPos) y: (yPos)\nset [original v] to [0]\n\nwhen flag clicked\nset [original v] to [1]\nhide\n\nwhen I receive [deleteblock v]\ndelete this clone\n\nwhen I receive [showblock v]\nif <(original) = [0]> then\n    show\nend\n\n@Sparky\n\nwhen I receive [sparkysetposition v]\nif <(original) = [0]> then\n    go to x: (xPosSparky) y: (yPosSparky)\n    set [jump v] to [0]\n    set [vx v] to [0]\n    set [vy v] to [-0.1]\nend\n\nwhen I receive [sparkyhide v]\nif <(original) = [0]> then\n    set [pausesparky v] to [1]\n    hide\nend\n\nwhen flag clicked\nset [pausesparky v] to [0]\nset [original v] to [1]\nhide\n\nwhen I receive [showblock v]\nif <(original) = [0]> then\n    set [pausesparky v] to [0]\n    show\n    wait (0.1) seconds\n    forever\n        if <(pauseSparky) = [0]> then\n            DoPhysics\n        end\n    end\nend\n\nwhen I start as a clone\nset [id v] to (nextID)\nchange [nextid v] by (1)\nset [touchingice v] to [0]\nset [xpossparky v] to (xPos)\nset [ypossparky v] to (yPos)\nset [original v] to [0]\nhide\nbroadcast (sparkysetposition v)\n\ndefine avoidGround\nrepeat until <<not <touching (ice v)?>> and <not <touching (door v)?>>>\n    if <(vy) > [0]> then\n        change y by (-1)\n        set [vy v] to [0.1]\n    else\n        change y by (1)\n        set [vy v] to [-0.1]\n        set [jump v] to [0]\n    end\n    set [touchingice v] to [1]\nend\nif <(touchingIce) = [1  ]> then\n    set [xpos v] to (x position)\n    set [ypos v] to (y position)\n    broadcast (touchedice v)\n    set [touchingice v] to [0]\nend\nrepeat until <not <touching (ground v)?>>\n    if <(vy) > [0]> then\n        change y by (-1)\n        set [vy v] to [0.1]\n    else\n        change y by (1)\n        set [vy v] to [-0.1]\n        set [jump v] to [0]\n    end\nend\n\nwhen I receive [deleteblock v]\ndelete this clone\n\ndefine Turn Sparky Right\nif <(costume [number v]) = [2]> then\n    switch costume to (right v)\n    Adjust Sparky by 1 pixel\nend\n\ndefine Turn Sparky Left\nif <(costume [number v]) = [1]> then\n    switch costume to (left v)\n    Adjust Sparky by 1 pixel\nend\n\ndefine avoidHParts\nset [numofpixelssparkywasmoved v] to [0]\nchange y by (1)\nif <<touching (ground v)?> or <<touching (ice v)?> or <touching (door v)?>>> then\n    change y by (-1)\n    repeat until <<<<not <touching (ground v)?>> and <not <touching (ice v)?>>> and <not <touching (door v)?>>> or <(numOfPixelsSparkywasMoved) > [30]>>\n        if <(vx) > [0]> then\n            change x by (-1)\n        else\n            change x by (1)\n        end\n        change [numofpixelssparkywasmoved v] by (1)\n        if <(numOfPixelsSparkywasMoved) > [20]> then\n            SparkyDead\n        end\n    end\nelse\n    change y by (-1)\nend\n\ndefine Adjust Sparky by 1 pixel\nif <<touching (door v)?> or <<touching (ground v)?> or <touching (ice v)?>>> then\n    change x by (1)\n    if <<touching (door v)?> or <<touching (ground v)?> or <touching (ice v)?>>> then\n        change x by (-2)\n        if <<touching (door v)?> or <<touching (ground v)?> or <touching (ice v)?>>> then\n            change x by (1)\n            change y by (1)\n            if <<touching (door v)?> or <<touching (ground v)?> or <touching (ice v)?>>> then\n                change y by (-2)\n            end\n        end\n    end\nend\n\ndefine SparkyDead\nset [pickupcount v] to (initialePickupCount)\nbroadcast (showblock v)\nbroadcast (sparkysetposition v)\nbroadcast (sparkyisdead v)\n\ndefine DoPhysics\nif <<key (left arrow v) pressed?> or <<mouse down?> and <<[60] > (mouse y)> and <[0] > (mouse x)>>>> then\n    set [vx v] to [-3]\n    Turn Sparky Right\nend\nif <<key (right arrow v) pressed?> or <<mouse down?> and <<[60] > (mouse y)> and <[0] < (mouse x)>>>> then\n    set [vx v] to [3]\n    Turn Sparky Left\nend\nif <key (r v) pressed?> then\n    SparkyDead\nend\nif <touching (water v)?> then\n    set [jump v] to [0]\n    set [vy v] to [-1]\n    if <<<key (space v) pressed?> or <key (up arrow v) pressed?>> or <<mouse down?> and <(mouse y) > [-30]>>> then\n        set [vy v] to [1]\n    end\nelse\n    change [vy v] by (-0.5)\n    if <<(vy) < [0]> and <(vy) > [-1           ]>> then\n        if <<<key (space v) pressed?> or <key (up arrow v) pressed?>> or <<mouse down?> and <(mouse y) > [-30]>>> then\n            if <(jump) = [0]> then\n                set [vy v] to [8]\n                set [jump v] to [1]\n            end\n        end\n    end\nend\nchange x by (vx)\nset [vx v] to ((vx) * (0.5))\navoidHParts\nchange y by (vy)\navoidGround\nif <touching (monster1 v)?> then\n    SparkyDead\nend\nif <touching (lava v)?> then\n    SparkyDead\nend\nif <(y position) < [-175]> then\n    SparkyDead\nend\nif <touching (monster2 v)?> then\n    SparkyDead\nend\nif <touching (deathball v)?> then\n    SparkyDead\nend\nif <touching (pickuppoint v)?> then\n    broadcast (touchedpickup v)\nend\nset [sparkyrealx v] to (x position)\nset [sparkyrealy v] to (y position)\n\n@ground\n\nwhen flag clicked\nset [original v] to [1]\nhide\n\nwhen I start as a clone\ngo to x: (xPos) y: (yPos)\nset [original v] to [0]\nhide\n\nwhen I receive [showblock v]\nif <(original) = [0]> then\n    show\nend\n\nwhen I receive [deleteblock v]\ndelete this clone\n\n@water\n\nwhen I start as a clone\ngo to x: (xPos) y: (yPos)\nset [original v] to [0]\n\nwhen I receive [showblock v]\nif <(original) = [0]> then\n    show\nend\n\nwhen flag clicked\nset [original v] to [1]\nhide\n\nwhen I receive [deleteblock v]\ndelete this clone\n\n@Lava\n\nwhen I start as a clone\ngo to x: (xPos) y: (yPos)\nset [original v] to [0]\n\nwhen flag clicked\nset [original v] to [1]\nhide\n\nwhen I receive [deleteblock v]\ndelete this clone\n\nwhen I receive [showblock v]\nif <(original) = [0]> then\n    show\nend\n\n@pickupPoint\n\nwhen I receive [showblock v]\nif <(original) = [0]> then\n    show\nend\n\nwhen I receive [deleteblock v]\ndelete this clone\n\nwhen I start as a clone\ngo to x: (xPos) y: (yPos)\nset [original v] to [0]\nchange [pickupcount v] by (1)\n\nwhen flag clicked\nset [original v] to [1]\nhide\n\nwhen I receive [touchedpickup v]\nif <touching (sparky v)?> then\n    change [pickupcount v] by (-1)\n    if <(pickupCount) = [0]> then\n        broadcast (noPickupsLeft v)\n        broadcast (openAllGates v)\n    end\n    start sound [pop v]\n    hide\nend\n\n@Goal\n\nwhen I receive [showblock v]\nif <(original) = [0]> then\n    switch costume to (costume1 v)\n    show\nend\n\nwhen I receive [nopickupsleft v]\nswitch costume to (costume2 v)\n\nwhen I receive [deleteblock v]\ndelete this clone\n\nwhen I start as a clone\nswitch costume to (costume1 v)\ngo to x: (xPos) y: (yPos)\nset [original v] to [0]\nforever\n    wait (0.3) seconds\n    if <touching (sparky v)?> then\n        if <(pickupCount) = [0]> then\n            broadcast (nextLevel v) and wait\n            broadcast (show_stage v) and wait\n            broadcast (createStage v) and wait\n            broadcast (hide_stage v) and wait\n        end\n    end\nend\n\nwhen flag clicked\nset [original v] to [1]\nhide\n\n@Levels\n\nwhen I receive [show_stage v]\ngo to x: (0) y: (0)\nset size to (400) %\nshow\ngo to [front v] layer\n\nwhen I receive [hide_stage v]\nhide\n\nwhen I receive [nextlevel v]\nnext costume\nif <(costume [number v]) = [46]> then\n    switch backdrop to (ending v)\n    broadcast (sparkyhide v)\n    stop [all v]\nend\n\nwhen flag clicked\nswitch costume to ((0) + (1))\n\n@levelCreator\n\ndefine checkCompilation\nif <(totalBlockNum) > [300]> then\n    compilationError [Warning! There are too many blocks in the level. Scratch is limited to 300 blocks \(about half the screen\)]\nend\nif <(totalSparkies) > [1]> then\n    compilationError [Warning! Your level has more than 1 sparky block \(gray block\). Ignoring extra sparkies.]\nend\nif <(totalSparkies) < [1]> then\n    compilationError [Error! Your level does not contain any Sparky block \(gray block\). Please add one.]\nend\nif <(totalGoalBlocks) > [1]> then\n    compilationError [Warning! you have more than 1 exit block \(purple block\). Please edit your level.]\nend\nif <(totalGoalBlocks) < [1]> then\n    compilationError [Error! you don't have any exit blocks \(purple block\). How do you expect to finish the level?]\nend\nif <(isSparkyHasEnoughSpace) > [0]> then\n    compilationError [Error! Sparky does not have enough space. Sparky block needs an empty space above him. ]\nend\n\ndefine compilationError (message)\nshow\nsay (message) for (10) seconds\nhide\n\ndefine CreateBlock\nif <touching color (#ffffff)?> then\n\ndefine CreateBlock\n\nwhen I receive [createstage v]\ndelete (all) of [spritey v]\ndelete (all) of [spritex v]\nswitch backdrop to (background v)\nset [nextid v] to [1]\nset [totalblocknum v] to [0]\nset [issparkyhasenoughspace v] to [0]\nset [totalsparkies v] to [0]\nset [totalgoalblocks v] to [0]\nbroadcast (progressstart v)\nset [pickupcount v] to [0]\nbroadcast (deleteblock v) and wait\nbroadcast (progressnext v)\nbroadcast (sparkyhide v) and wait\nbroadcast (progressnext v)\nbroadcast (show_stage v) and wait\ngo to x: (2) y: (-2)\nhide\nset [ypos v] to [164]\nset [xpos v] to [-248]\nbroadcast (progressnext v)\nrepeat (22)\n    broadcast (progressnext v)\n    repeat (30)\n        CreateBlock\n        change x by (4)\n        change [xpos v] by (16)\n    end\n    change y by (-4)\n    change [ypos v] by (-16)\n    set [xpos v] to [-248]\n    change x by (-120)\nend\nbroadcast (hide_stage v)\nbroadcast (progressnext v)\nshow_blocks\nbroadcast (progressnext v)\ncheckCompilation\nbroadcast (progressnext v)\nset [initialepickupcount v] to (pickupCount)\nif <(initialePickupCount) = [0]> then\n    broadcast (nopickupsleft v)\nend\nbroadcast (progressnext v)\nbroadcast (progressended v)\nbroadcast (sparkystartphysics v)\nbroadcast (sparkyshow v) and wait\n\ndefine show_blocks\nbroadcast (showblock v)\n\n@progress\n\nwhen I receive [progressstart v]\ngo to x: (0) y: (100)\nswitch costume to (costume1 v)\ngo to [front v] layer\nshow\nbroadcast (progressShowOtherPart v) and wait\nsay (join (join (join [Level ] ([costume # v] of [levels v])) [: ]) ([costume name v] of [levels v]))\n\nwhen I receive [progressnext v]\nnext costume\n\nwhen I receive [progressended v]\nswitch costume to (costume34 v)\nwait (0.1) seconds\nhide\n\n@ice\n\nwhen I start as a clone\ngo to x: (xPos) y: (yPos)\nset [original v] to [0]\nhide\n\nwhen I receive [showblock v]\nif <(original) = [0]> then\n    show\n    wait (0.5) seconds\n    StartIceLifecycle\nend\n\nwhen flag clicked\nset [original v] to [1]\nhide\n\ndefine StartIceLifecycle\nswitch costume to (costume1 v)\nset [wastouched v] to [0]\nrepeat until <(wasTouched) = [1]>\n    wait (0.5) seconds\nend\nrepeat (5)\n    next costume\n    wait (0.2) seconds\nend\nhide\n\nwhen I receive [deleteblock v]\ndelete this clone\n\nwhen I receive [touchedice v]\nif <(wasTouched) = [0]> then\n    set [debug v] to (xPos)\n    if <<[14] > ([abs v] of ((xPos) - (x position)) )> and <([abs v] of (((yPos) - (y position)) - (16)) ) < [3]>> then\n        set [wastouched v] to [1]\n    end\nend\n\n@monster2\n\ndefine DoPhysics\nif <(isGoRight) = [0]> then\n    change x by (-3)\nelse\n    change x by (3)\nend\navoidHParts\nTurn to direction\nif <touching (lava v)?> then\n    SparkyDead\nend\nif <(y position) < [-175]> then\n    SparkyDead\nend\nchange y by (vy)\navoidGround\nif <touching (water v)?> then\n    set [vy v] to [-1]\nelse\n    change [vy v] by (-0.5)\nend\n\ndefine avoidHParts\nchange y by (1)\nif <<touching (door v)?> or <<touching (_edge_ v)?> or <<touching (ice v)?> or <touching (ground v)?>>>> then\n    change y by (-1)\n    if <<touching (door v)?> or <<touching (_edge_ v)?> or <<touching (ice v)?> or <touching (ground v)?>>>> then\n        if <(isGoRight) = [0]> then\n            set [isgoright v] to [1]\n        else\n            set [isgoright v] to [0]\n        end\n        repeat until <<not <touching (door v)?>> and <<not <touching (_edge_ v)?>> and <<not <touching (ground v)?>> and <not <touching (ice v)?>>>>>\n            if <(isGoRight) = [1]> then\n                change x by (1)\n            else\n                change x by (-1)\n            end\n        end\n    end\nelse\n    change y by (-1)\nend\n\nwhen flag clicked\nset [pausesparky v] to [0]\nset [original v] to [1]\nhide\n\nwhen I receive [sparkyhide v]\nHideSparky\n\nwhen I start as a clone\nset [id v] to (nextID)\nchange [nextid v] by (1)\ninsert (yPos) at (ID) of [spritey v] \ninsert (xPos) at (ID) of [spritex v] \nset [xpossparky v] to (xPos)\nset [ypossparky v] to (yPos)\nset [original v] to [0]\nhide\nbroadcast (sparkySetPosition v)\n\ndefine HideSparky\nif <(original) = [0]> then\n    set [pausesparky v] to [1]\n    hide\nend\n\nwhen I receive [deleteblock v]\ndelete this clone\n\nwhen I receive [showblock v]\nif <(original) = [0]> then\n    set [pausesparky v] to [0]\n    show\n    wait (0.1) seconds\n    forever\n        if <(pauseSparky) = [0]> then\n            DoPhysics\n        end\n    end\nend\n\ndefine SparkyDead\nHideSparky\n\nwhen I receive [sparkysetposition v]\nif <(original) = [0]> then\n    go to x: (xPosSparky) y: (yPosSparky)\n    set [jump v] to [0]\n    set [vx v] to [0]\n    set [vy v] to [0]\n    if <(x position) > [0]> then\n        set [isgoright v] to [0]\n        switch costume to (left v)\n    else\n        set [isgoright v] to [1]\n        switch costume to (right v)\n    end\nend\n\ndefine Turn Sparky Right\nif <(costume [number v]) = [2]> then\n    switch costume to (right v)\n    Adjust Sparky by 1 pixel\nend\n\ndefine Turn Sparky Left\nif <(costume [number v]) = [1]> then\n    switch costume to (left v)\n    Adjust Sparky by 1 pixel\nend\n\ndefine Adjust Sparky by 1 pixel\nif <<touching (door v)?> or <<touching (ground v)?> or <touching (ice v)?>>> then\n    change x by (1)\n    if <<touching (door v)?> or <<touching (ground v)?> or <touching (ice v)?>>> then\n        change x by (-2)\n        if <<touching (door v)?> or <<touching (ground v)?> or <touching (ice v)?>>> then\n            change x by (1)\n            change y by (1)\n            if <<touching (door v)?> or <<touching (ground v)?> or <touching (ice v)?>>> then\n                change y by (-2)\n            end\n        end\n    end\nend\n\ndefine Turn to direction\nif <(isGoRight) = [0]> then\n    Turn Sparky Left\nelse\n    Turn Sparky Right\nend\n\ndefine avoidGround\nrepeat until <<not <touching (ice v)?>> and <not <touching (door v)?>>>\n    change y by (1)\n    set [vy v] to [-0.1]\n    set [touchingice v] to [1]\nend\nif <(touchingIce) = [1]> then\n    if <(pick random (1) to (3)) = [1]> then\n        set [xpos v] to (x position)\n        set [ypos v] to (y position)\n        broadcast (touchedIce v)\n        set [touchingice v] to [0]\n    end\nend\nrepeat until <not <touching (ground v)?>>\n    change y by (1)\n    set [vy v] to [-0.1]\nend\n\n@progress2\n\nwhen I receive [progressshowotherpart v]\ngo to x: (0) y: (-20)\nswitch costume to (costume1 v)\ngo to [front v] layer\n\nshow\n\nwhen I receive [progressended v]\nhide\n\n@Normal\n\nwhen this sprite clicked\nset [gamelevel v] to [0]\nswitch backdrop to (background v)\nbroadcast (createStage v) and wait\n\nwhen I receive [deleteblock v]\nhide\n\nwhen I receive [showstartbuttons v]\nshow\n\n@Challenging\n\nwhen this sprite clicked\nset [gamelevel v] to [1]\nswitch backdrop to (background v)\nbroadcast (createStage v) and wait\n\nwhen I receive [deleteblock v]\nhide\n\nwhen I receive [showstartbuttons v]\nshow\n\n@Insane!!\n\nwhen this sprite clicked\nset [gamelevel v] to [2]\nswitch backdrop to (background v)\nbroadcast (createStage v) and wait\n\nwhen I receive [deleteblock v]\nhide\n\nwhen I receive [showstartbuttons v]\nshow\n\n@deathBall\n\ndefine MoveDeathBall\nif <(deathBallVertical) = [0]> then\n    change x by (deathBallGoingForward)\nelse\n    change y by (deathBallGoingForward)\nend\nif <(deathBallIsPlaying) = [1]> then\n    if <<(x position) < ((sparkyRealX) + (5))> and <(x position) > ((sparkyRealX) - (5))>> then\n        start sound [Shotgun_Blast-Jim_Rogers-1914772763.mp3 v]\n        set [deathballisplaying v] to [2]\n        set [deathballvertical v] to [1]\n        if <(y position) < (sparkyRealY)> then\n            set [deathballgoingforward v] to [5]\n        else\n            set [deathballgoingforward v] to [-5]\n        end\n    end\n    if <<(y position) < ((sparkyRealY) + (5))> and <(y position) > ((sparkyRealY) - (5))>> then\n        start sound [Shotgun_Blast-Jim_Rogers-1914772763.mp3 v]\n        set [deathballisplaying v] to [2]\n        set [deathballvertical v] to [0]\n        if <(x position) < (sparkyRealX)> then\n            set [deathballgoingforward v] to [5]\n        else\n            set [deathballgoingforward v] to [-5]\n        end\n    end\nend\nif <touching (_edge_ v)?> then\n    change [numofdeathballs v] by (-1)\n    delete this clone\nend\n\ndefine HideDeathBall\nset [deathballisplaying v] to [0]\ndelete this clone\n\nwhen I receive [hide_stage v]\nHideDeathBall\n\nwhen I receive [deleteblock v]\nHideDeathBall\n\nwhen I receive [sparkyisdead v]\ndelete this clone\n\ndefine InitDeathBall\nchange [numofdeathballs v] by (1)\nset [deathballisplaying v] to [1]\nset [isstartposfair v] to [0]\nrepeat until <(isStartPosFair) = [1]>\n    SetStartPosition\nend\nif <(deathBallVertical) = [0]> then\n    if <[1] = (deathBallGoingForward)> then\n        go to x: (-235) y: (pick random (-150) to (150))\n    else\n        go to x: (235) y: (pick random (-150) to (150))\n    end\nelse\n    if <[1] = (deathBallGoingForward)> then\n        go to x: (pick random (-220) to (220)) y: (-175)\n    else\n        go to x: (pick random (-220) to (220)) y: (175)\n    end\nend\nshow\n\nwhen I start as a clone\nInitDeathBall\nrepeat until <(deathBallIsPlaying) = [0]>\n    MoveDeathBall\nend\nhide\n\nwhen flag clicked\nhide\n\ndefine SetStartPosition\nset [isstartposfair v] to [1]\nif <[1] = (pick random (1) to (2))> then\n    set [deathballgoingforward v] to [1]\nelse\n    set [deathballgoingforward v] to [-1]\nend\nset [deathballvertical v] to (pick random (0) to (1))\nif <<(sparkyRealX) > [180]> and <<(deathBallVertical) = [0]> and <(deathBallGoingForward) = [-1]>>> then\n    set [isstartposfair v] to [0]\nend\nif <<(sparkyRealX) < [-180]> and <<(deathBallVertical) = [0]> and <(deathBallGoingForward) = [1]>>> then\n    set [isstartposfair v] to [0]\nend\nif <<(sparkyRealY) > [120]> and <<(deathBallVertical) = [1]> and <(deathBallGoingForward) = [-1]>>> then\n    set [isstartposfair v] to [0]\nend\nif <<(sparkyRealY) < [-120]> and <<(deathBallVertical) = [1]> and <(deathBallGoingForward) = [1]>>> then\n    set [isstartposfair v] to [0]\nend\n\nwhen I receive [showblock v]\nset [deathballisplaying v] to [1]\n\nwhen I receive [createstage v]\nset [original v] to [1]\nset [numofdeathballs v] to [0]\nif <(gameLEvel) = [0  ]> then\nelse\n    if <(gameLEvel) = [1]> then\n        forever\n            wait (pick random (8) to (12)) seconds\n            if <(deathBallIsPlaying) > [0]> then\n                create clone of (_myself_ v)\n            end\n        end\n    else\n        forever\n            wait (pick random (2) to (5)) seconds\n            if <(deathBallIsPlaying) > [0]> then\n                create clone of (_myself_ v)\n            end\n        end\n    end\nend\n\nset tempo to (100)\nset instrument to (10 v)\nplay note (60) for (0.5) beats\nplay note (60) for (0.4) beats\nplay note (60) for (0.1) beats\nplay note (60) for (0.4) beats\nrest for (0.1) beats\nplay note (63) for (0.4) beats\nplay note (62) for (0.1) beats\nplay note (62) for (0.4) beats\nplay note (60) for (0.1) beats\nplay note (60) for (0.4) beats\nplay note (59) for (0.1) beats\nplay note (60) for (0.4) beats\n\n@Door\n\nwhen I start as a clone\ngo to x: (xPos) y: (yPos)\nset [original v] to [0]\nset [doororiginallyopened v] to (doorStartsOpened)\nset [sparkyisdead v] to [0]\nhide\n\nwhen I receive [touchedice v]\nif <<[14] > ([abs v] of ((xPos) - (x position)) )> and <([abs v] of (((yPos) - (y position)) - (16)) ) < [3]>> then\n    set [wastouched v] to [1]\nend\n\ndefine switchOpenState\nif <(isOpen) = [0]> then\n    set [isopen v] to [1]\nelse\n    set [isopen v] to [0]\nend\n\nwhen flag clicked\nset [original v] to [1]\nset [wastouched v] to [0]\nset [sparkyisdead v] to [0]\nhide\n\ndefine StartIceLifecycle\nforever\n    wait (0.1) seconds\n    if <(isOpen) = [1]> then\n        repeat until <(costume [number v]) = [1]>\n            switch costume to ((costume [number v]) - (1))\n            wait (0.1) seconds\n        end\n    else\n        repeat until <(costume [number v]) = [5]>\n            switch costume to ((costume [number v]) + (1))\n            wait (0.1) seconds\n        end\n    end\nend\n\nset [sparkyisdead v] to [1]\nset [isopen v] to (doorOriginallyOpened)\nset [wastouched v] to [0]\nset [sparkyisdead v] to [0]\nif <(sparkyIsDead) = [0]> then\nend\n\ndefine StartLifecycle\nif <(original) = [0]> then\n    set [wastouched v] to [0]\n    show\n    if <(doorOriginallyOpened) = [1]> then\n        set [isopen v] to [1]\n        switch costume to (costume1 v)\n    else\n        set [isopen v] to [0]\n        switch costume to (costume10 v)\n    end\n    wait (0.5) seconds\n    StartIceLifecycle\nend\n\nwhen I receive [showblock v]\nStartLifecycle\n\ndefine StartWasTouchedWatcher\nwait (1) seconds\nforever\n    wait (0.1) seconds\n    if <(wasTouched) = [1]> then\n        wait (0.5) seconds\n        set [isopen v] to [0]\n        set [wastouched v] to [0]\n    end\nend\n\nwhen I receive [touchedportal v]\nswitchOpenState\n\nwhen I start as a clone\nStartWasTouchedWatcher\n\nwhen I receive [openallgates v]\nset [isopen v] to [1]\n\nwhen I receive [deleteblock v]\ndelete this clone\n\nwhen I receive [door_startwastouchedwatcher v]\nStartWasTouchedWatcher\n\nwhen I receive [sparkyisdead v]\nstop [other scripts in sprite v]\nbroadcast (door_startWasTouchedWatcher v)\nStartLifecycle\n\n@button\n\nwhen I receive [showblock v]\nif <(original) = [0]> then\n    switch costume to (costume1 v)\n    show\nend\n\nwhen I receive [deleteblock v]\ndelete this clone\n\nwhen flag clicked\nset [original v] to [1]\nhide\n\nwait (0.1) seconds\n\nwhen I start as a clone\ngo [backward v] (300) layers\nswitch costume to (costume1 v)\ngo to x: (xPos) y: (yPos)\nset [original v] to [0]\nforever\n    if <touching (sparky v)?> then\n        broadcast (touchedPortal v)\n        start sound [hand clap v]\n        wait until <not <touching (sparky v)?>>\n    end\n    if <touching (monster2 v)?> then\n        broadcast (touchedPortal v)\n        start sound [hand clap v]\n        wait until <not <touching (monster2 v)?>>\n    end\nend\n\n@דמות1\n\nwhen flag clicked\ngo to [front v] layer\nset size to (80) %\nset [ghost v] effect to (90)\nset [range v] to ((size) / (2.5))\nforever\n    go to x: (-172) y: (-112)\n    switch costume to (stick v)\n    repeat until <not <mouse down?>>\n        Keyboard Controls\n    end\n    repeat until <mouse down?>\n        Keyboard Controls\n    end\n    if <(size) > (distance to [mouse-pointer v])> then\n        Stick Activated\n    end\nend\n\ndefine Keyboard Controls\nset [stick x v] to (<key (right arrow v) pressed?> - <key (left arrow v) pressed?>)\nif <key (space v) pressed?> then\n    change [stick button v] by (1)\nelse\n    set [stick button v] to [0]\nend\n\ndefine Stick Activated\ngo to (mouse-pointer v)\nset [stick button v] to []\nrepeat until <((1.5) * (size)) < (distance to [mouse-pointer v])>\n    Detect Stick Movement\n    Detect Stick Button\nend\n\ndefine Detect Stick Movement\nset [stick x v] to (((mouse x) - (x position)) / (range))\nif <[1] < ([abs v] of (STICK X) )> then\n    set [stick x v] to ((STICK X) / ([abs v] of (STICK X) ))\nend\n\ndefine Detect Stick Button\nif <mouse down?> then\n    if <[] < (STICK BUTTON)> then\n        change [stick button v] by (1)\n    end\nelse\n    set [stick button v] to [0]\nend\n\n
KEYS\n======\nUse arrow keys / space.\nUse R to restart level.\n\nINSTRUCTIONS\n==============\nHelp Sparky take all the pickups and go into the exit point.\n