Switch Swap: A Platformer.

Instructions: Use the arrow keys or drag the cursor to move. Touch a switch to flip it, causing the red and blue platforms switch. Touch the portal to reach the next level. Find the key to win.

@Stage\n\nwhen flag clicked\nhide variable [level v]\n\nbroadcast (turn page v)\n\nwhen I receive [turn page v]\nforever\n    play sound [Flip-Swap Galaxy v] until done\nend\n\nswitch backdrop to (backdrop1 v)\n\nswitch backdrop to (on/off)\n\n@Improved2\n\nwhen I receive [turn page v]\nif <(Title) > [0]> then\n    hide\n    stop [this script v]\nend\nReset Level\nforever\n    switch costume to (hitbox v)\n    Controls - Jump, Crouch\n    Gravity\n    Check Hit Ceiling / Floor <(speed y) > [0]>\n    if <(y position) < [-180]> then\n        Reset Level\n    end\n    Controls - Left and Right\n    if <(speed x) < [-0.5]> then\n        Walk (-90) (speed x) max step (([ceiling v] of ([abs v] of ((speed x) * (1.3)) ) ) + (1))\n    else\n        if <(speed x) > [0.5]> then\n            Walk (90) (speed x) max step (([ceiling v] of ([abs v] of ((speed x) * (1.3)) ) ) + (1))\n        else\n            set [frame v] to [0]\n        end\n    end\n    Set Costume\n    broadcast (tick v)\nend\n\nchange [wall jump v] by (-1)\n\ndefine Controls - Left and Right\nset [speed x v] to ((speed x) * (0.7))\nif <<key (left arrow v) pressed?> or <(left key pressed) = [1]>> then\n    change [speed x v] by (-2)\nend\nif <<key (right arrow v) pressed?> or <(right key pressed) = [1]>> then\n    change [speed x v] by (2)\nend\n\ndefine Walk (direction) (speed) max step (step)\npoint in direction (direction)\nchange x by (speed)\nchange [frame v] by (([abs v] of (speed) ) / (8))\nset [slope v] to [0]\nGet Touching <(in platforrm) = [1]>\nrepeat until <<(slope) = (step)> or <(touch) = [0]>>\n    change y by (1)\n    change [slope v] by (1)\n    Get Touching <(in platforrm) = [1]>\nend\nif <(slope) = (step)> then\n    change x by ((0) - (speed))\n    change y by ((0) - (slope))\n    if <<(touch) = [1]> and <(in platforrm) = [1]>> then\n        set [in platforrm v] to [2]\n        Walk (direction) (speed) max step (step)\n        if <(speed x) = [0]> then\n            set [in platforrm v] to [1]\n        end\n    else\n        set [speed x v] to [0]\n    end\nend\n\nif <<<<key (up arrow v) pressed?> or <(up key pressed) = [1]>> and <([abs v] of (speed) ) > [3.5]>> and <(touch) > [1]>> then\n    set [speed x v] to ((-1.2) * (speed))\n    set [speed y v] to [11]\n    set [falling? v] to [6]\n    set [wall jump v] to [15]\nend\n\ndefine Controls - Jump, Crouch\nif <<key (up arrow v) pressed?> or <<(up key pressed) = [1]> or <touching (bounce v)?>>> then\n    if <<(jump key) = [0]> and <(falling?) < [3]>> then\n        set [speed y v] to [14]\n        set [falling? v] to [6]\n        set [jump key v] to [1]\n    end\nelse\n    set [jump key v] to [0]\nend\nif <<key (down arrow v) pressed?> or <(down key pressed) = [1]>> then\n    set [in platforrm v] to [2]\nend\n\ndefine Gravity\nif <<(speed y) < [4]> or <<key (up arrow v) pressed?> or <(up key pressed) = [1]>>> then\n    change [speed y v] by (-1)\nelse\n    change [speed y v] by (-2)\nend\nchange y by (speed y)\nchange [falling? v] by (1)\n\ndefine Check Hit Ceiling / Floor <up?>\nGet Touching \nif <(touch) = [0]> then\n    set [in platforrm v] to [1]\nelse\n    if <<up?> and <(touch) = [1]>> then\n        set [in platforrm v] to [2]\n    end\nend\nrepeat until <(touch) < (in platforrm)>\n    if <up?> then\n        change y by (-1)\n    else\n        change y by (1)\n        set [falling? v] to [0]\n    end\n    Get Touching <not <up?>>\n    set [speed y v] to [0]\nend\n\ndefine Get Touching <check platform?>\nif <<touching (ground v)?> or <<<touching (platforms v)?> and <(on/off) = [1]>> or <<touching (platforms2 v)?> and <(on/off) = [0]>>>> then\n    set [touch v] to [9]\nelse\n    if  then\n        set [touch v] to [1]\n    else\n        set [touch v] to [0]\n    end\nend\nif <<<touching (platforms3 v)?> and <(on/off) = [1]>> or <<touching (platforms4 v)?> and <(on/off) = [0]>>> then\n    start sound [Pew v]\n    Reset Level\nend\nif <<touching (sprite8 v)?> and <(portal open?) = [1]>> then\n    repeat (10)\n        turn right (15) degrees\n        change [ghost v] effect by (10)\n        wait (0) seconds\n    end\n    start sound [Teleport2 v]\n    clear graphic effects\n    broadcast (next level v)\n    point in direction (90)\n    change [level v] by (1)\n    Reset Level\nend\n\ndefine Reset Level\nset size to (25) %\nset rotation style [all around v]\npoint in direction (90)\ngo to x: (146) y: (200)\ngo to x: (-160) y: (-108)\nreset timer\nshow\nset [speed x v] to [0]\nset [speed y v] to [0]\nset [falling? v] to [10]\nset [in platforrm v] to [1]\nset [frame v] to [0]\nset [wall jump v] to [0]\nbroadcast (spawn enemies v)\n\ndefine Set Costume\nif <(falling?) < [6]> then\n    if <(frame) = [0]> then\n        switch costume to (costume13 v)\n    else\n        switch costume to ([floor v] of ((1) + ((frame) mod (12))) )\n    end\nelse\n    if <(speed y) > [0]> then\n        switch costume to (costume13 v)\n    else\n        switch costume to (costume13 v)\n    end\nend\n\nwhen flag clicked\nset [level v] to [1]\n\nset [jump key v] to [1]\n\nset [falling? v] to [6]\n\nwhen I receive [reset level v]\nReset Level\n\nwhen I receive [bounce v]\nset [speed y v] to [10]\nset [falling? v] to [6]\nset [jump key v] to [1]\n\nbroadcast (tick v) and wait\n\nwhen I receive [next level v]\n\nstop [other scripts in sprite v]\n\n@Ground\n\nwhen flag clicked\ngo to x: (0) y: (0)\nforever\n    switch costume to (Level)\nend\n\n@Sprite1\n\nwhen flag clicked\nhide\n\nwhen I receive [turn page v]\ngo to x: (0) y: (0)\nshow\nset [ghost v] effect to (50)\ngo to [front v] layer\nif <(Mobile?) = [0]> then\n    hide\nend\n\n@Sprite2\n\nwhen flag clicked\nhide\nset [left key pressed v] to [0]\nset [right key pressed v] to [0]\nset [down key pressed v] to [0]\nset [down key pressed v] to [0]\n\nif <<(direction) > [44]> and <(direction) < [91]>> then\n\nwhen I receive [turn page v]\ngo to x: (0) y: (0)\nset [left key pressed v] to [0]\nset [right key pressed v] to [0]\nset [down key pressed v] to [0]\nset [down key pressed v] to [0]\nshow\nset [ghost v] effect to (50)\ngo to [front v] layer\nforever\n    go to x: (0) y: (0)\n    set [left key pressed v] to [0]\n    set [right key pressed v] to [0]\n    set [up key pressed v] to [0]\n    set [down key pressed v] to [0]\n    if <(Mobile?) = [0]> then\n        hide\n        stop [this script v]\n    end\n    if <mouse down?> then\n        go to x: (0) y: (0)\n        point towards (mouse-pointer v)\n        move (28) steps\n        if <<(direction) > [-60]> and <(direction) < [60]>> then\n            set [up key pressed v] to [1]\n        else\n            if <<(direction) < [-120]> or <(direction) > [120]>> then\n                set [down key pressed v] to [1]\n            end\n        end\n        if <<(direction) > [30]> and <(direction) < [150]>> then\n            set [right key pressed v] to [1]\n        else\n            if <<(direction) > [-150]> and <(direction) < [-30]>> then\n                set [left key pressed v] to [1]\n            end\n        end\n    end\nend\n\n@Platforms\n\nwhen flag clicked\nshow\ngo to x: (0) y: (0)\nforever\n    switch costume to (Level)\nend\n\nwhen I receive [spawn enemies v]\ngo to [back v] layer\ngo to x: (0) y: (0)\nforever\n    if <(on/off) = [0]> then\n        set [ghost v] effect to (50)\n    else\n        clear graphic effects\n    end\nend\n\nhide\n\nhide\n\nshow\n\n@Sprite3\n\nwhen flag clicked\nshow\npoint in direction (90)\nhide variable [level v]\nhide variable [mobile? v]\ngo to [front v] layer\nswitch costume to (costume1 v)\ngo to x: (0) y: (0)\nset [id v] to [0]\nrepeat (3)\n    change [id v] by (1)\n    create clone of (_myself_ v)\nend\nforever\n    set [id v] to [0]\n    create clone of (_myself_ v)\nend\n\nwhen I start as a clone\nif <(id) = [0]> then\n    go to [front v] layer\n    go [forward v] (1) layers\n    go to x: (pick random (-240) to (240)) y: (-480)\n    point in direction (90)\n    set rotation style [all around v]\n    switch costume to (pick random (5) to (6))\n    show\n    set [ghost v] effect to (50)\n    repeat (40)\n        turn right (3) degrees\n        change y by (10)\n    end\n    repeat until <touching (_edge_ v)?>\n        turn right (3) degrees\n        change y by (10)\n    end\n    change y by (10)\n    delete this clone\nelse\n    if <(id) = [1]> then\n        go to [front v] layer\n        go to x: (0) y: (0)\n        switch costume to (costume5 v)\n        show\n    else\n        if <(id) = [2]> then\n            go to [front v] layer\n            go to x: (-100) y: (0)\n            switch costume to (costume2 v)\n            show\n            forever\n                if <touching (mouse-pointer v)?> then\n                    set [brightness v] effect to (50)\n                    if <mouse down?> then\n                        set [mobile? v] to [1]\n                        start sound [Collect v]\n                        broadcast (turn page v)\n                    end\n                else\n                    clear graphic effects\n                end\n            end\n        else\n            if <(id) = [3]> then\n                go to [front v] layer\n                go to x: (100) y: (0)\n                switch costume to (costume3 v)\n                show\n                forever\n                    if <touching (mouse-pointer v)?> then\n                        set [brightness v] effect to (50)\n                        if <mouse down?> then\n                            set [mobile? v] to [0]\n                            start sound [Collect v]\n                            broadcast (turn page v)\n                        end\n                    else\n                        clear graphic effects\n                    end\n                end\n            end\n        end\n    end\nend\n\nchange y by (10)\n\nrepeat until <not <touching (_edge_ v)?>>\n\nrepeat (40)\n    change y by (10)\nend\nrepeat until <touching (_edge_ v)?>\n    change y by (10)\nend\nchange y by (10)\ndelete this clone\n\nset [ghost v] effect to (50)\n\nforever\n    go to [front v] layer\nend\n\nset [mobile? v] to [0]\n\nwhen I receive [turn page v]\nhide\nstop [other scripts in sprite v]\ndelete this clone\n\n@Logo\n\nwhen flag clicked\ngo to x: (0) y: (0)\nforever\n    set [ghost v] effect to (100)\n    go to [front v] layer\n    show\nend\n\n@Sprite6\n\nwhen flag clicked\nhide\nset [portal open? v] to [1]\n\ndefine Create key (x) (y) (level)\nif <(Level) = (level)> then\n    go to x: (x) y: (y)\n    set [dizzy v] to [0]\n    set [level in v] to (Level)\n    create clone of (_myself_ v)\nend\n\nwhen I start as a clone\nhide\nshow\nset [speed x v] to [0]\nset [portal open? v] to [0]\nset size to (50) %\nset rotation style [left-right v]\nset [level in v] to (Level)\nset [speed y v] to [0]\nset [start x v] to (x position)\nset [start y v] to (y position)\nforever\n    switch costume to (costume15 v)\n    Controls - Jump, Crouch\n    Gravity\n    Check Hit Ceiling / Floor <(speed y) > [0]>\nend\n\ndefine Check Hit Ceiling / Floor <up?>\nGet Touching \nif <(touch) = [0]> then\n    set [in platforrm v] to [1]\nelse\n    if <<up?> and <(touch) = [1]>> then\n        set [in platforrm v] to [2]\n    end\nend\nrepeat until <(touch) < (in platforrm)>\n    if <up?> then\n        change y by (-1)\n    else\n        change y by (1)\n        set [falling? v] to [0]\n    end\n    Get Touching <not <up?>>\n    set [speed y v] to [0]\nend\n\ndefine Gravity\nif <(speed y) < [4]> then\n    change [speed y v] by (-1)\nelse\n    change [speed y v] by (-2)\nend\nchange y by (speed y)\nchange [falling? v] by (1)\n\ndefine Controls - Jump, Crouch\n\ndefine Walk (direction) (speed) max step (step)\npoint in direction (direction)\nchange x by (speed)\nchange [frame v] by (([abs v] of (speed) ) / (4))\nset [slope2 v] to [0]\nGet Touching <(in platforrm) = [1]>\nrepeat until <<(slope2) = (step)> or <(touch) = [0]>>\n    change y by (1)\n    change [slope2 v] by (1)\n    Get Touching <(in platforrm) = [1]>\nend\nif <(slope2) = (step)> then\n    change x by ((0) - (speed))\n    change y by ((0) - (slope2))\n    if <<(touch) = [1]> and <(in platforrm) = [1]>> then\n        set [in platforrm v] to [2]\n        Walk (direction) (speed) max step (step)\n        if <(speed x) = [0]> then\n            set [in platforrm v] to [1]\n        end\n    end\nend\n\nwhen I start as a clone\nforever\n    if <touching (improved2 v)?> then\n        set [portal open? v] to [1]\n        start sound [Collect v]\n        delete this clone\n    end\nend\n\n\n\nset [speed x v] to [0]\n\nrepeat (10)\n\nwhen I receive [tick v]\n\ndefine Set Costume\nif <(falling?) < [6]> then\n    if <(frame) = [0]> then\n        switch costume to (costume3 v)\n    else\n        switch costume to ([floor v] of ((1) + ((frame) mod (13))) )\n    end\nelse\n    if <(speed y) > [0]> then\n        switch costume to (costume3 v)\n    else\n        switch costume to (costume3 v)\n    end\nend\n\nswitch costume to (costume16 v)\n\n\n\nset [ghost v] effect to (100)\n\nhide\ndelete this clone\n\n\n\nstop [other scripts in sprite v]\n\nhide\n\nwhen I receive [spawn enemies v]\ndelete this clone\n\nswitch costume to (costume15 v)\n\nrepeat (10)\n\nif <<([abs v] of (speed x) ) > [4]> and <(falling?) = [0]>> then\n    set [speed y v] to [25]\n    set [falling? v] to [6]\n    set [jump key v] to [1]\nend\n\n\n\nwhen I receive [spawn enemies v]\ngo to x: (0) y: (0)\nhide\nwait (0.1) seconds\nif <(Level) = [10]> then\n    Create key (150) (100) (10)\nend\n\ndefine Get Touching <check platform?>\nif  then\n    set [touch v] to [9]\nelse\n    if <<check platform?> and <<<touching (platforms v)?> and <(on/off) = [1]>> or <<touching (platforms2 v)?> and <(on/off) = [0]>>>> then\n        set [touch v] to [1]\n    else\n        set [touch v] to [0]\n    end\nend\n\nCreate key (196) (124) (19)\n\nwhen I receive [reset level v]\ndelete this clone\n\n\n\nwhen I receive [tick v]\n\nwhen I receive [tick v]\n\nforever\n\nwhen I receive [tick v]\n\nwhen I start as a clone\nforever\n    if <not <(Level) = (level in)>> then\n        delete this clone\n    end\nend\n\nCreate key (0) (-25) (5)\n\nif <<touching (improved2 v)?> and <(([y position v] of [improved2 v]) - (15)) > (y position)>> then\n    broadcast (bounce v)\n    switch costume to (costume14 v)\n    switch costume to (costume2 v)\n    start sound [pop2 v]\n    wait (0.1) seconds\n    delete this clone\nend\nSet Costume\n\nCreate key (200) (100) (10)\n\nCreate key (0) (-100) (19)\n\nCreate key (190) (100) (19)\n\nCreate key (-100) (-100) (11)\n\nCreate key (0) (-100) (11)\nCreate key (0) (-100) (11)\n\n@Sprite8\n\nwhen flag clicked\nhide\nforever\n    repeat (20)\n        change [fisheye v] effect by (25)\n        switch costume to (Level)\n    end\n    repeat (20)\n        change [fisheye v] effect by (-25)\n        switch costume to (Level)\n    end\nend\n\nwhen I receive [spawn enemies v]\nshow\ngo to x: (0) y: (0)\nif <(Level) = [10]> then\n    set [portal open? v] to [0]\n    set [brightness v] effect to (-50)\n    wait until <(portal open?) = [1]>\n    set [brightness v] effect to (0)\nend\nif <(Level) = [11]> then\n    hide\nend\n\nwait (0) seconds\nnext costume\n\nif <(Level) = [19]> then\n    hide\nend\n\nturn right (15) degrees\n\n@Sprite9\n\nwhen flag clicked\nhide\n\nwhen I receive [spawn enemies v]\ngo to [back v] layer\nswitch costume to (off v)\nshow\ngo to x: (item (Level) of [switch xpos v]) y: (item (Level) of [switch ypos v])\nforever\n    wait until <touching (improved2 v)?>\n    start sound [Coin v]\n    if <(on/off) = [0]> then\n        set [on/off v] to [1]\n    else\n        set [on/off v] to [0]\n    end\n    next costume\n    wait until <not <touching (improved2 v)?>>\nend\n\nforever\n\n\n\ngo to [back v] layer\n\nwhen I receive [tick v]\nswitch costume to (on/off)\n\nset [on/off v] to [0]\n\n@Sprite10\n\nwhen flag clicked\nhide\n\nwhen I receive [next level v]\ngo to [front v] layer\nshow\ngo to x: (0) y: (0)\nset [ghost v] effect to (100)\nrepeat (5)\n    change [ghost v] effect by (-20)\nend\nbroadcast (fade out v)\n\nwhen I receive [fade out v]\nrepeat (5)\n    change [ghost v] effect by (20)\nend\nhide\n\n@Platforms2\n\nwhen flag clicked\nshow\ngo to x: (0) y: (0)\nforever\n    switch costume to (Level)\nend\n\nwhen I receive [spawn enemies v]\ngo to [back v] layer\ngo to x: (0) y: (0)\nwait (0) seconds\nforever\n    if <(on/off) = [0]> then\n        clear graphic effects\n    else\n        set [ghost v] effect to (50)\n    end\nend\n\nhide\n\nshow\n\nhide\n\n@Sprite4\n\nwhen flag clicked\nhide\n\nwhen I receive [spawn enemies v]\ngo to [back v] layer\nswitch costume to (off v)\nwait (0) seconds\nset [on/off v] to [0]\nshow\ngo to x: (item (Level) of [x pos v]) y: (item (Level) of [y pos v])\nif <(item (Level) of [x pos v]) = [-]> then\n    hide\nend\nforever\n    wait until <touching (improved2 v)?>\n    start sound [Coin v]\n    if <(on/off) = [0]> then\n        set [on/off v] to [1]\n    else\n        set [on/off v] to [0]\n    end\n    next costume\n    wait until <not <touching (improved2 v)?>>\nend\n\nforever\n\n\n\ngo to [back v] layer\n\nwhen I receive [tick v]\nswitch costume to (on/off)\n\n@Platforms3\n\nwhen flag clicked\nshow\ngo to x: (0) y: (0)\nforever\n    switch costume to (Level)\nend\n\nwhen I receive [spawn enemies v]\ngo to x: (0) y: (0)\ngo to [back v] layer\nforever\n    if <(on/off) = [0]> then\n        set [ghost v] effect to (50)\n    else\n        clear graphic effects\n    end\nend\n\nhide\n\nhide\n\nshow\n\n@Platforms4\n\nwhen flag clicked\nshow\ngo to x: (0) y: (0)\nforever\n    switch costume to (Level)\nend\n\nwhen I receive [spawn enemies v]\ngo to [back v] layer\ngo to x: (0) y: (0)\nforever\n    if <(on/off) = [0]> then\n        clear graphic effects\n    else\n        set [ghost v] effect to (50)\n    end\nend\n\nhide\n\nshow\n\nhide\n\n@Sprite5\n\nwhen flag clicked\nhide\n\nwhen I receive [turn page v]\nshow\ngo to x: (205) y: (157)\nforever\n    switch costume to (Level)\n    if <(Level) = [11]> then\n        hide\n    end\nend\n\n