Source Code - A Platformer


@Stage\n\nwhen flag clicked\nforever\n    switch backdrop to (Level)\nend\n\nwhen flag clicked\nforever\n    play sound [Inferno v] until done\nend\n\n@Hitbox\n\nwhen flag clicked\nshow\ngo to x: (-200) y: (0)\nset [speed y v] to [0]\nforever\n    change [speed y v] by (-1)\n    set [speed x v] to ((Speed X) * (0.8))\n    change y by (Speed Y)\n    Touch ground <(Speed Y) > [0]>\n    if <(Walljump) > [0]> then\n        change [walljump v] by (-1.)\n    else\n        if <<key (d v) pressed?> or <<key (right arrow v) pressed?> or <<mouse down?> and <(x position) < (mouse x)>>>> then\n            change [speed x v] by (1.5)\n            start sound [High Whoosh v]\n        end\n        if <<key (a v) pressed?> or <<key (left arrow v) pressed?> or <<mouse down?> and <(mouse x) < (x position)>>>> then\n            change [speed x v] by (-1.5)\n        end\n    end\n    if <<<key (w v) pressed?> or <<key (up arrow v) pressed?> or <<mouse down?> and <(y position) < (mouse y)>>>> and <(falling?) < [3]>> then\n        set [speed y v] to [15]\n    end\n    if <(Speed X) < [-0.5]> then\n        Walk [5] (Speed X)\n    else\n        if <[0.5] < (Speed X)> then\n            Walk [5] (Speed X)\n        end\n    end\nend\n\ndefine Touch ground <up?>\nchange [falling? v] by (1)\nrepeat until <not <touching (ground hitbox v)?>>\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    set [speed y v] to [0]\nend\n\ndefine Walk (x) (speed)\nchange x by (speed)\nset [slope v] to [0]\nrepeat until <<(slope) = [8]> or <not <touching (ground hitbox v)?>>>\n    change y by (1)\n    change [slope v] by (1)\nend\nif <(slope) = [8]> then\n    change x by ((0) - (speed))\n    change y by ((0) - (slope))\n    if <<<key (w v) pressed?> or <<key (up arrow v) pressed?> or <<mouse down?> and <(y position) < (mouse y)>>>> and <([abs v] of (speed) ) > [3]>> then\n        if <(Walljump) = [0]> then\n            set [speed x v] to ((-2) * (speed))\n            set [speed y v] to [11]\n            set [falling? v] to [6]\n        else\n            set [speed x v] to [0]\n        end\n    end\nend\n\nwhen flag clicked\nforever\n    if <<[230] < (x position)> or <<touching (lava v)?> or <touching (spikes v)?>>> then\n        wait (0.0000001) seconds\n        if <[230] < (x position)> then\n            change [level v] by (1)\n        else\n            start sound [Crunch v]\n        end\n        set [falling? v] to [0]\n        set [speed y v] to [0]\n        set [speed x v] to [0]\n        set [walljump v] to [0]\n        set [slope v] to [0]\n        go to x: (-200) y: (0)\n    end\nend\n\nwhen flag clicked\nforever\n    set [ghost v] effect to (0100)\nend\n\nif <key (left arrow v) pressed?> then\n    point in direction (-90)\nend\nset rotation style [left-right v]\n\nwhen flag clicked\nforever\n    if <<touching (lava v)?> or <touching (spikes v)?>> then\n        broadcast (die v) and wait\n        wait until <not <<[230] < (x position)> or <<touching (lava v)?> or <touching (spikes v)?>>>>\n    end\nend\n\nwhen flag clicked\nshow\ngo to x: (-200) y: (0)\nset [speed y v] to [0]\nforever\n    if <(Walljump) > [0]> then\n    if <<<key (w v) pressed?> or <<key (up arrow v) pressed?> or <<mouse down?> and <(y position) < (mouse y)>>>> and <(falling?) < [3]>> then\n        play sound [Low Whoosh v] until done\n    end\n    if <(Speed X) < [-0.5]> then\nend\n\n@Ground Graphics\n\nwhen flag clicked\nforever\n    switch costume to (Level)\nend\n\n@Ground Hitbox\n\nwhen flag clicked\nforever\n    set [ghost v] effect to (100)\n    switch costume to (Level)\nend\n\n@Spikes\n\nwhen flag clicked\nset [level v] to [1]\nforever\n    switch costume to (Level)\n    go to [front v] layer\n    go [backward v] (1) layers\nend\n\n@Lava\n\nwhen flag clicked\ngo to x: (0) y: (15)\nforever\n    switch costume to (Level)\nend\n\nwhen flag clicked\nforever\n    repeat (30)\n        change y by (-0.8)\n    end\n    repeat (30)\n        change y by (0.8)\n    end\nend\n\n@Player Graphics\n\nwhen flag clicked\nforever\n    set [dir v] to (direction)\n    go to [front v] layer\n    go to (hitbox v)\n    if <<(Pressed) = [1]> or <(Pressed) = [3]>> then\n        switch costume to (geometry-6 v)\n    else\n        if <(Pressed) = [2]> then\n            switch costume to (geometry-4 v)\n        else\n            if <<(Pressed) = [4]> or <(Pressed) = [6]>> then\n                switch costume to (geometry-5 v)\n            else\n                switch costume to (geometry-3 v)\n            end\n        end\n    end\nend\n\nwhen flag clicked\nforever\n    if <<<<mouse down?> and <(x position) < (mouse x)>> or <<key (right arrow v) pressed?> or <key (d v) pressed?>>> and <<<mouse down?> and <(y position) < (mouse y)>> or <<key (up arrow v) pressed?> or <key (w v) pressed?>>>> then\n        set [pressed v] to [3]\n        point in direction (90)\n    else\n        if <<<<mouse down?> and <(mouse x) < (x position)>> or <<key (left arrow v) pressed?> or <key (a v) pressed?>>> and <<<mouse down?> and <(y position) < (mouse y)>> or <<key (up arrow v) pressed?> or <key (w v) pressed?>>>> then\n            set [pressed v] to [1]\n            point in direction (-90)\n        else\n            if <<<mouse down?> and <(y position) < (mouse y)>> or <<key (up arrow v) pressed?> or <key (w v) pressed?>>> then\n                set [pressed v] to [2]\n            else\n                if <<<mouse down?> and <(x position) < (mouse x)>> or <<key (right arrow v) pressed?> or <key (d v) pressed?>>> then\n                    set [pressed v] to [6]\n                    point in direction (90)\n                else\n                    if <<<mouse down?> and <(mouse x) < (x position)>> or <<key (left arrow v) pressed?> or <key (a v) pressed?>>> then\n                        set [pressed v] to [4]\n                        point in direction (-90)\n                    else\n                        set [pressed v] to [5]\n                    end\n                end\n            end\n        end\n    end\nend\n\nif <key (left arrow v) pressed?> then\n    point in direction (-90)\nelse\nend\nset rotation style [left-right v]\n\nif <key (left arrow v) pressed?> then\nelse\n    point in direction (90)\nend\nset rotation style [left-right v]\n\nif <key (left arrow v) pressed?> then\nelse\n    point in direction (90)\nend\nset rotation style [left-right v]\n\nif <key (left arrow v) pressed?> then\nelse\n    point in direction (90)\nend\nset rotation style [left-right v]\n\nif <key (left arrow v) pressed?> then\n    point in direction (-90)\nend\nset rotation style [left-right v]\n\nif <key (left arrow v) pressed?> then\nelse\n    point in direction (90)\nend\nset rotation style [left-right v]\n\n@Thumbnail\n\nwhen flag clicked\nforever\n    set [ghost v] effect to (0100)\n    show\n    go to [front v] layer\nend\n\n@Test\n\nwhen flag clicked\nforever\n    switch costume to (Level)\n    show\n    go to [back v] layer\n    go to x: (0) y: (0)\n    if <touching (player graphics v)?> then\n        set [ghost v] effect to (35)\n    else\n        set [ghost v] effect to (0)\n    end\nend\n\n@Collision Particles\n\ndefine Smooth Glide x: (x) y: (y) speed: (speed)\nrepeat until <<(round (x position)) = (round (x))> and <(round (y position)) = (round (y))>>\n    change x by (((round (x)) - (round (x position))) / (speed))\n    change y by (((round (y)) - (round (y position))) / (speed))\nend\ngo to x: (x) y: (y)\n\nwhen I receive [message1 v]\n\nwhen I start as a clone\nshow\ngo to (player graphics v)\nSmooth Glide x: ((x position) + (pick random (-90) to (90))) y: ((y position) + (pick random (20) to (35))) speed: (5)\nwait (0) seconds\nrepeat (10)\n    change [ghost v] effect by (10)\nend\ndelete this clone\n\ndefine yes\nrepeat (20)\n    create clone of (_myself_ v)\nend\n\nwhen I start as a clone\nshow\ngo to (player graphics v)\nshow\nset [ghost v] effect to (0)\nwait (0.2) seconds\nrepeat (10)\n    change [ghost v] effect by (10)\nend\ndelete this clone\n\nchange y by (-20)\n\npoint in direction (pick random (-90) to (90))\n\nwhen flag clicked\nwait (0.1) seconds\nforever\n    go to (player graphics v)\n    if <touching (ground hitbox v)?> then\n        yes\n        wait until <not <touching (ground hitbox v)?>>\n    end\nend\n\nwhen flag clicked\nforever\n    go to (player graphics v)\n    show\n    set [ghost v] effect to (100)\nend\n\nwhen I start as a clone\nforever\n    go to [front v] layer\n    go [backward v] (2) layers\nend\n\nwhen I start as a clone\nwait (2) seconds\ndelete this clone\n\nwhen [e v] key pressed\nbroadcast (c v)\nstop [other scripts in sprite v]\nhide\ndelete this clone\n\nwhen I receive [a v]\ndelete this clone\n\n@Walking Particles\n\ndefine Smooth Glide x: (x) y: (y) speed: (speed)\nrepeat until <<(round (x position)) = (round (x))> and <(round (y position)) = (round (y))>>\n    change x by (((round (x)) - (round (x position))) / (speed))\n    change y by (((round (y)) - (round (y position))) / (speed))\nend\ngo to x: (x) y: (y)\n\nwhen I receive [message1 v]\n\ndefine yes\nrepeat (20)\n\nwhen I start as a clone\n\nchange y by (-20)\nshow\ngo to (player graphics v)\nshow\nset [ghost v] effect to (0)\nwait (0.2) seconds\nrepeat (10)\n    change [ghost v] effect by (10)\nend\ndelete this clone\n\nwhen flag clicked\nwait (0.1) seconds\nforever\n    if <touching (ground graphics v)?> then\n        go to (player graphics v)\n        create clone of (_myself_ v)\n    end\nend\n\nwhen flag clicked\nforever\n    go to (player graphics v)\n    show\n    set [ghost v] effect to (100)\nend\n\nwhen I start as a clone\nforever\n    go to [front v] layer\n    go [backward v] (4) layers\nend\n\nwhen I start as a clone\nif <not <(Pressed) = [5]>> then\n    if <(dir) = [-90]> then\n        show\n        go to (player graphics v)\n        go [backward v] (0) layers\n        set [ghost v] effect to (0)\n        Smooth Glide x: ((x position) + (pick random (-30) to (0))) y: ((y position) + (pick random (0) to (10))) speed: (5)\n        wait (0) seconds\n        repeat (10)\n            change [ghost v] effect by (10)\n        end\n        delete this clone\n    else\n        show\n        set [ghost v] effect to (0)\n        go to (player graphics v)\n        Smooth Glide x: ((x position) + (pick random (0) to (30))) y: ((y position) + (pick random (0) to (10))) speed: (5)\n        wait (0) seconds\n        repeat (10)\n            change [ghost v] effect by (10)\n        end\n        delete this clone\n    end\nelse\nend\ndelete this clone\n\nshow\ngo to (player graphics v)\nSmooth Glide x: ((x position) + (pick random (-90) to (90))) y: ((y position) + (pick random (0) to (35))) speed: (5)\nwait (0) seconds\nrepeat (10)\n    change [ghost v] effect by (10)\nend\ndelete this clone\n\nif <(dir) = [-90]> then\nend\n\nwait (0.01) seconds\n\nwhen I start as a clone\nwait (2) seconds\ndelete this clone\n\nwhen [e v] key pressed\nstop [other scripts in sprite v]\n\nwhen [e v] key pressed\nbroadcast (b v)\nstop [other scripts in sprite v]\nhide\ndelete this clone\n\nwhen I receive [a v]\ndelete this clone\n\n@Death Particles\n\ndefine Smooth Glide x: (x) y: (y) speed: (speed)\nrepeat until <<(round (x position)) = (round (x))> and <(round (y position)) = (round (y))>>\n    change x by (((round (x)) - (round (x position))) / (speed))\n    change y by (((round (y)) - (round (y position))) / (speed))\nend\ngo to x: (x) y: (y)\n\nwhen I receive [die v]\nif <(c) = [0]> then\n    yes\nend\n\ndefine yes\nset [c v] to [1]\ngo to (player graphics v)\nrepeat (20)\n    create clone of (_myself_ v)\nend\nset [c v] to [0]\n\nwhen I start as a clone\nshow\nset [ghost v] effect to (0)\ngo to (player graphics v)\nSmooth Glide x: ((x position) + (pick random (-90) to (90))) y: ((y position) + (pick random (-25) to (0))) speed: (3)\nrepeat (5)\n    change [ghost v] effect by (20)\nend\ndelete this clone\n\nwhen flag clicked\nhide\n\nwhen flag clicked\nforever\n    show\n    set [ghost v] effect to (100)\nend\n\nwhen I start as a clone\nforever\n    go to [front v] layer\n    go [backward v] (0) layers\nend\n\nwhen I start as a clone\nwait (2) seconds\ndelete this clone\n\nwhen [e v] key pressed\nbroadcast (a v)\nforever\n    stop [other scripts in sprite v]\n    hide\n    delete this clone\nend\n\nwhen I receive [a v]\ndelete this clone\n\n