Jons Platformer

Instructions: arrow keys to move  \nspace / up arrow to jump

@Stage\n\nwhen flag clicked\nset volume to (80) %\nbroadcast (levelstart v)\nforever\n    play sound [Jake Kaufman - Shovel Knight Original Soundtrack - 43 The Inner Struggle \(Tower\).mp3 v] until done\nend\n\n@Player\n\nwhen flag clicked\nset size to (100) %\nhide\ngo to x: (-200) y: (-108)\n\ndefine Physics\nif <not <(Restrict Movement) = [1]>> then\n    set [old_costume v] to (costume [number v])\n    switch costume to (sensor v)\n    change y by (yVel)\n    change y by (-1)\n    if <touching (level v)?> then\n        if <(yVel) < [.1]> then\n            set [ycollision v] to [1]\n            set [xglide v] to [0]\n            set [yvel v] to [0]\n            if <[0] = (Double Jump)> then\n                set [jump v] to (Jump Height)\n            else\n                set [jump v] to [2]\n            end\n            goUp\n        else\n            set [yvel v] to [0]\n            set [jump v] to [0]\n            goDown\n        end\n    else\n        set [ycollision v] to [0]\n        change [yvel v] by ((0) - (Gravity))\n    end\n    if <not <<key (up arrow v) pressed?> or <key (space v) pressed?>>> then\n        set [spacepressed v] to [0]\n    end\n    if <<[0] < (jump)> and <<key (up arrow v) pressed?> or <key (space v) pressed?>>> then\n        if <[0] = (Double Jump)> then\n            if <(Jump Height) = (jump)> then\n                set [yvel v] to (Jump Height)\n                set volume to (50) %\n                start sound [Jump13 v]\n            end\n            change [jump v] by (-1)\n            change [yvel v] by (((Gravity) / (4)) * (3))\n        else\n            if <[0] = (spacepressed)> then\n                set [yvel v] to (Jump Height)\n                change [jump v] by (-1)\n                set [spacepressed v] to [1]\n            end\n        end\n    else\n        if <[0] = (Double Jump)> then\n            set [jump v] to [0]\n        end\n    end\n    if <<key (left arrow v) pressed?> or <key (right arrow v) pressed?>> then\n        if <key (right arrow v) pressed?> then\n            point in direction (90)\n            change [xvel v] by (Speed)\n        end\n        if <key (left arrow v) pressed?> then\n            point in direction (-90)\n            change [xvel v] by ((0) - (Speed))\n        end\n    else\n        set [xvel v] to ((0.75) * (xVel))\n    end\n    set [xvel v] to ((0.7) * (xVel))\n    change x by (xVel)\n    if <touching (level v)?> then\n        change x by ((0) - (xVel))\n        set [xvel v] to [0]\n        if <not <(round (xVel)) = [0]>> then\n            if <[0] < (xVel)> then\n                change x by (1)\n                if <touching (black top v)?> then\n                    change x by (-1)\n                else\n                    change x by (1)\n                    if <touching (black top v)?> then\n                        change x by (-1)\n                    else\n                        change x by (1)\n                        if <touching (black top v)?> then\n                            change x by (-1)\n                        end\n                    end\n                end\n            else\n                change x by (-1)\n                if <touching (black top v)?> then\n                    change x by (1)\n                else\n                    change x by (-1)\n                    if <touching (black top v)?> then\n                        change x by (1)\n                    else\n                        change x by (-1)\n                        if <touching (black top v)?> then\n                            change x by (1)\n                        end\n                    end\n                end\n            end\n        end\n    end\n    if <<(xVel) < [.5]> and <[-.5] < (xVel)>> then\n        set [xvel v] to [0]\n    end\n    if <<not <touching (portalb v)?>> and <not <touching (portalr v)?>>> then\n        set [j v] to [0]\n    end\n    switch costume to (old_costume)\n    broadcast (render v)\nend\n\ndefine goUp\nrepeat (16)\n    if <touching (level v)?> then\n        change y by (1)\n    end\nend\nif <touching (level v)?> then\n    change y by (-16)\nend\n\ndefine varReset\nset [d v] to [0]\nset [xvel v] to [0]\nset [yvel v] to [0]\nset [jump v] to [5]\nset [speed v] to [1.3]\nset [gravity v] to [0.25]\nset [jump height v] to [5]\ngo to x: (-200) y: (-90)\n\nwhen I receive [die v]\nvarReset\n\ndefine goDown\nrepeat (16)\n    if <touching (level v)?> then\n        change y by (-1)\n    end\nend\nif <touching (level v)?> then\n    change y by (16)\nend\n\nwhen flag clicked\nswitch costume to (idol v)\n\nwhen flag clicked\nset [jumpcos v] to [no]\nset [jumped? v] to [no]\nswitch costume to (idol v)\nforever\n    if <(ycollision) = [1]> then\n        switch costume to (run1 v)\n        if <<key (left arrow v) pressed?> or <key (right arrow v) pressed?>> then\n            switch costume to (run1 v)\n            wait (0.2) seconds\n            set volume to (50) %\n            start sound [Hit_Hurt2 v]\n            switch costume to (run2 v)\n            wait (0.2) seconds\n        end\n    else\n        JumpCostume (2)\n        wait until <(ycollision) = [1]>\n        switch costume to (idol v)\n    end\nend\n\ndefine None\nswitch costume to (costume?)\n\nwhen I receive [levelstart v]\nhide\nshow\nvarReset\nforever\n    Physics\n    if <(y position) < [-160]> then\n        broadcast (die v)\n    end\nend\n\nwhen [r v] key pressed\nvarReset\n\n@Thumbnail\n\nwhen flag clicked\nset size to (1600) %\nhide\ngo to x: (0) y: (5)\n\nshow\ngo to [front v] layer\n\n@Tiles\n\ndefine Render\nset [a v] to [0]\nset [b v] to [0]\nset [orbx v] to [0]\nset [orby v] to [0]\ngo to x: (-232) y: (-172)\nshow\nerase all\nbroadcast (show v) and wait\nrepeat (23)\n    repeat (30)\n        switch costume to (render v)\n        if <touching color (#666666)?> then\n            switch costume to (dirt v)\n            stamp\n        else\n            if <touching color (#b2b2b2)?> then\n                switch costume to (grass v)\n                stamp\n            else\n                if <touching color (#001966)?> then\n                    switch costume to (win v)\n                    create clone of (_myself_ v)\n                else\n                    if <touching color (#ff0000)?> then\n                        switch costume to (grassspike v)\n                        create clone of (_myself_ v)\n                    else\n                    end\n                end\n            end\n        end\n        change x by (16)\n    end\n    set x to (-232)\n    change y by (16)\nend\nbroadcast (hide v)\nhide\n\nwhen flag clicked\nRender\ndelete this clone\n\nwhen I receive [resettiles v]\nRender\n\nwhen I start as a clone\nif <(costume [number v]) = [4]> then\n    switch costume to (grassspike v)\n    forever\n        if <touching (player v)?> then\n            broadcast (die v)\n        end\n    end\nend\nif <(costume [number v]) = [5]> then\n    wait until <touching (player v)?>\n    change [level v] by (1)\n    reset\nend\n\nwhen I receive [level v]\ndelete this clone\n\ndefine reset\nbroadcast (level v)\nbroadcast (ResetTiles v)\nbroadcast (levelstart v)\n\n@Level\n\nwhen flag clicked\nset [level v] to [1]\ngo to x: (0) y: (-4)\n\nwhen I receive [show v]\nclear graphic effects\n\nwhen I receive [hide v]\nset [ghost v] effect to (100)\n\nwhen I receive [levelstart v]\nswitch costume to (Level)\n\n