Creation - Platformer

Instructions:                       (Fullscreen Recommended)\n\nMake Your Own Platformer with Creation!\n\nClick on the left side of the screen to open the Menu, where you can select tiles to place, change your room,\nsave/load your levels, and Play your level.\n\nWhen playing, use arrow keys to move.\n\nShare level codes here:\nhttps://scratch.mit.edu/discuss/topic/367176/\n\nPlease give me feedback in the comments!\n---\nShortcuts                              ~This Section is Very Useful~\nWASD: Change Room\n0-9: Change Style\nArrow Keys: Change & Rotate Tile\nQ: Eraser\nSpace: Open Menu\n\n - Music from Mario Galaxy 2\n - All Coding and Art by Me.

@Stage\n\nwhen flag clicked\nset [number of styles v] to [2]\nif <<(username) = [04tmoody]> and <key (any v) pressed?>> then\n    hide variable [display: room v]\n    switch backdrop to (thumbnail v)\nelse\n    set [mode v] to [Edit]\n    broadcast (Edit v)\n    forever\n        switch backdrop to ((Style) + (1))\n    end\nend\n\nwhen flag clicked\nforever\n    play sound [Staff Credits - Super Mario Galaxy 2 v] until done\nend\n\n@level\n\ndefine Generate Level\ndelete all of [level \(whole\) v]\nAdd Blocks [1.1] from [0] [0] to [11] [0] in room [1] [1]\nAdd Blocks [2.1] from [0] [1] to [11] [1] in room [1] [1]\n\ndefine Draw Level\nset [brightness v] effect to (0)\nerase all\nset [i v] to [1]\nrepeat until <(i) > (length of [level \(whole\) v])>\n    if <<(item ((i) + (1)) of [level \(whole\) v]) = (Room X)> and <(item ((i) + (2)) of [level \(whole\) v]) = (Room Y)>> then\n        Set direction (round (((item (i) of [level \(whole\) v]) mod (1)) * (10)))\n        switch costume to ((((Style) - (1)) * (13)) + (round (item (i) of [level \(whole\) v])))\n        go to x: ((item ((i) + (3)) of [level \(whole\) v]) * (40)) y: ((item ((i) + (4)) of [level \(whole\) v]) * (40))\n        stamp\n    end\n    change [i v] by (5)\nend\n\ndefine Add Block (type) at (x) (y) in room (room x) (room y)\nadd (type) to [level \(whole\) v]\nadd (room x) to [level \(whole\) v]\nadd (room y) to [level \(whole\) v]\nadd ((x) - (5.5)) to [level \(whole\) v]\nadd ((y) - (4)) to [level \(whole\) v]\n\ndefine Add Blocks (type) from (x) (y) to (x2) (y2) in room (room x) (room y)\nset [i v] to (x)\nrepeat (((x2) - (x)) + (1))\n    set [j v] to (y)\n    repeat (((y2) - (y)) + (1))\n        Add Block (type) at (i) (j) in room (room x) (room y)\n        change [j v] by (1)\n    end\n    change [i v] by (1)\nend\n\nwhen I receive [draw room v]\nDraw Level\n\nwhen I receive [edit v]\n\nwhen I receive [edit v]\nDraw Level\nshow\nset [tile v] to [1]\nset [tile direction v] to [90]\nforever\n    if <(Mode) = [Play]> then\n        erase all\n        set size to (200) %\n        hide\n        set [room x v] to [1]\n        set [room y v] to [1]\n        Draw Level\n        broadcast (Get Room Data v)\n        wait until <not <(Mode) = [Play]>>\n    else\n        show\n        if <(Editing?) = [1]> then\n            if <<(Tile) = [5]> or <(Tile) = [6]>> then\n                point in direction (90)\n            else\n                point in direction (Tile Direction)\n            end\n            switch costume to ((Tile) + (((Style) - (1)) * (13)))\n            set [brightness v] effect to (10)\n            go to x: (((round (((mouse x) - (20)) / (40))) * (40)) + (20)) y: ((round ((mouse y) / (40))) * (40))\n            if <(x position) > [220]> then\n                set x to (220)\n            end\n            if <(y position) > [160]> then\n                set y to (160)\n            end\n            if <<mouse down?> and <(mouse x) > [-215]>> then\n                Delete Block At (((x position) / (40)) + (5.5)) (((y position) / (40)) + (4)) in room (Room X) (Room Y)\n                if <not <(Tile) = [13]>> then\n                    Get Direction (direction)\n                    Add Block ((Tile) + (dir)) at (((x position) / (40)) + (5.5)) (((y position) / (40)) + (4)) in room (Room X) (Room Y)\n                end\n                Draw Level\n            end\n        else\n            wait until <(Editing?) = [0.5]>\n            Draw Level\n        end\n    end\nend\n\ndefine Delete Block At (x) (y) in room (roomx) (roomy)\nset [delete v] to [0]\nset [i v] to [1]\nrepeat until <(i) > (length of [level \(whole\) v])>\n    if <<((x) - (5.5)) = (item ((i) + (3)) of [level \(whole\) v])> and <((y) - (4)) = (item ((i) + (4)) of [level \(whole\) v])>> then\n        if <<(roomx) = (item ((i) + (1)) of [level \(whole\) v])> and <(roomy) = (item ((i) + (2)) of [level \(whole\) v])>> then\n            set [delete v] to (i)\n        end\n    end\n    change [i v] by (5)\nend\nrepeat (5)\n    delete (delete) of [level \(whole\) v]\nend\n\ndefine Set direction (dir)\nif <(dir) = [1]> then\n    point in direction (90)\nend\nif <(dir) = [2]> then\n    point in direction (180)\nend\nif <(dir) = [3]> then\n    point in direction (-90)\nend\nif <(dir) = [4]> then\n    point in direction (0)\nend\n\ndefine Get Direction (dir)\nif <(dir) = [90]> then\n    set [dir v] to [0.1]\nend\nif <(dir) = [180]> then\n    set [dir v] to [0.2]\nend\nif <(dir) = [-90]> then\n    set [dir v] to [0.3]\nend\nif <(dir) = [0]> then\n    set [dir v] to [0.4]\nend\n\nwhen [w v] key pressed\nif <<(Mode) = [Edit]> and <(Editing?) = [1]>> then\n    change [room y v] by (1)\n    if <(Room Y) > [9]> then\n        set [room y v] to [9]\n    end\n    Draw Level\nend\n\nwhen [a v] key pressed\nif <<(Mode) = [Edit]> and <(Editing?) = [1]>> then\n    change [room x v] by (-1)\n    if <[0] > (Room X)> then\n        set [room x v] to [0]\n    end\n    Draw Level\nend\n\nwhen [s v] key pressed\nif <<(Mode) = [Edit]> and <(Editing?) = [1]>> then\n    change [room y v] by (-1)\n    if <[0] > (Room Y)> then\n        set [room y v] to [0]\n    end\n    Draw Level\nend\n\nwhen [d v] key pressed\nif <<(Mode) = [Edit]> and <(Editing?) = [1]>> then\n    change [room x v] by (1)\n    if <(Room X) > [9]> then\n        set [room x v] to [9]\n    end\n    Draw Level\nend\n\nwhen [1 v] key pressed\nset [style v] to [1]\nDraw Level\n\nwhen [2 v] key pressed\nset [style v] to [2]\nDraw Level\n\nwhen [left arrow v] key pressed\nturn left (90) degrees\nset [tile direction v] to (direction)\n\nwhen [right arrow v] key pressed\nturn left (-90) degrees\nset [tile direction v] to (direction)\n\nwhen [up arrow v] key pressed\nchange [tile v] by (1)\nif <(Tile) > [13]> then\n    set [tile v] to [1]\nend\n\nwhen [down arrow v] key pressed\nchange [tile v] by (-1)\nif <[1] > (Tile)> then\n    set [tile v] to [13]\nend\n\nwhen [q v] key pressed\nset [tile v] to [13]\n\nwhen flag clicked\nerase all\nhide\nset [style v] to [1]\nGenerate Level\n\n@player\n\nwhen flag clicked\nhide\n\ndefine Update Collisions\ndelete all of [collisions v]\nset [i v] to [1]\nrepeat until <(i) > (length of [level \(room\) v])>\n    if <<(((item ((i) + (1)) of [level \(room\) v]) + (1)) * (40)) > (x position)> and <((x position) + (40)) > ((item ((i) + (1)) of [level \(room\) v]) * (40))>> then\n        if <<(((item ((i) + (2)) of [level \(room\) v]) + (1)) * (40)) > (y position)> and <((y position) + (40)) > ((item ((i) + (2)) of [level \(room\) v]) * (40))>> then\n            set [type v] to (round (item (i) of [level \(room\) v]))\n            if <<(Type) = [1]> or <<(Type) = [2]> or <<(Type) = [3]> or <(Type) = [5]>>>> then\n                add [1] to [collisions v]\n            end\n            if <<(Type) = [4]> or <<(Type) = [9]> or <(Type) = [10]>>> then\n                add [2] to [collisions v]\n            end\n            if <(Type) = [5]> then\n                add [3] to [collisions v]\n            end\n            if <<(Type) = [6]> and <(((y position) + (1)) - (yv)) > (((item ((i) + (2)) of [level \(room\) v]) + (1)) * (40))>> then\n                add [4] to [collisions v]\n            end\n            if <<(Type) = [7]> or <(Type) = [8]>> then\n                add [5] to [collisions v]\n            end\n            if <(Type) = [11]> then\n                add [6] to [collisions v]\n            end\n            if <(Type) = [12]> then\n                set [checkpoint x v] to ((item ((i) + (1)) of [level \(room\) v]) * (40))\n                set [checkpoint y v] to ((item ((i) + (2)) of [level \(room\) v]) * (40))\n                set [checkpoint room x v] to (Room X)\n                set [checkpoint room y v] to (Room Y)\n            end\n        end\n    end\n    change [i v] by (3)\nend\n\nwhen I receive [get room data v]\nGet Room Data\n\ndefine Get Room Data\ndelete all of [level \(room\) v]\nset [i v] to [1]\nrepeat until <(i) > (length of [level \(whole\) v])>\n    if <<(item ((i) + (1)) of [level \(whole\) v]) = (Room X)> and <(item ((i) + (2)) of [level \(whole\) v]) = (Room Y)>> then\n        add (item ((i) + (0)) of [level \(whole\) v]) to [level \(room\) v]\n        add (item ((i) + (3)) of [level \(whole\) v]) to [level \(room\) v]\n        add (item ((i) + (4)) of [level \(whole\) v]) to [level \(room\) v]\n    end\n    change [i v] by (5)\nend\n\ndefine Reset\ngo to x: (Checkpoint X) y: (Checkpoint Y)\nset [room x v] to (Checkpoint Room X)\nset [room y v] to (Checkpoint Room Y)\nset [xv v] to [0]\nset [yv v] to [0]\nGet Room Data\nbroadcast (Draw Room v)\n\ndefine Change Y by (yv)\nset [can jump? v] to [0]\nchange y by (yv)\nUpdate Collisions\nif <<[collisions v] contains [1]?> or <[collisions v] contains [4]?>> then\n    repeat until <not <<[collisions v] contains [1]?> or <[collisions v] contains [4]?>>>\n        if <(yv) < [0]> then\n            set [can jump? v] to [1]\n        end\n        change y by (() - (([abs v] of (yv) ) / (yv)))\n        Update Collisions\n    end\n    set [yv v] to [0]\nend\n\ndefine Change X by (xv)\nchange x by (xv)\nUpdate Collisions\nrepeat until <not <[collisions v] contains [1]?>>\n    set [xv v] to [0]\n    change x by (() - (([abs v] of (xv) ) / (xv)))\n    Update Collisions\nend\n\ndefine Change Room X by (xv)\nchange [room x v] by (xv)\nGet Room Data\nset x to ((240) * (() - (xv)))\nUpdate Collisions\nif <<not <[collisions v] contains [1]?>> and <(length of [level \(room\) v]) > [0]>> then\n    broadcast (Draw Room v)\nelse\n    set [xv v] to [0]\n    change [room x v] by (() - (xv))\n    set x to ((240) * (xv))\n    Get Room Data\nend\n\ndefine Change Room Y by (yv)\nchange [room y v] by (yv)\nGet Room Data\nset y to ((180) * (() - (yv)))\nUpdate Collisions\nif <<not <[collisions v] contains [1]?>> and <(length of [level \(room\) v]) > [0]>> then\n    broadcast (Draw Room v)\nelse\n    set [yv v] to [0]\n    if <(yv) < [0]> then\n        set [can jump? v] to [1]\n    end\n    change [room y v] by (() - (yv))\n    set y to ((180) * (yv))\n    Get Room Data\nend\n\ndefine Ground Physics\nif <<key (left arrow v) pressed?> or <<mouse down?> and <(mouse x) < (x position)>>> then\n    change [xv v] by (-4)\nend\nif <<key (right arrow v) pressed?> or <<mouse down?> and <(x position) < (mouse x)>>> then\n    change [xv v] by (4)\nend\nset [xv v] to ((xv) * (0.7))\nChange X by (round (xv))\nchange [yv v] by (-1)\nif <<<key (up arrow v) pressed?> or <<mouse down?> and <(mouse y) > (y position)>>> and <(can jump?) = [1]>> then\n    set [yv v] to [14]\nend\nchange y by (-1)\nUpdate Collisions\nif <<[collisions v] contains [3]?> and <(yv) < [0]>> then\n    set [yv v] to [16]\nend\nchange y by (1)\nChange Y by (round (yv))\nif <[-240] > (x position)> then\n    Change Room X by [-1]\nend\nif <(x position) > [240]> then\n    Change Room X by [1]\nend\nif <[-180] > (y position)> then\n    Change Room Y by [-1]\nend\nif <(y position) > [180]> then\n    Change Room Y by [1]\nend\nif <[collisions v] contains [2]?> then\n    Reset\nend\n\ndefine Water Physics\nif <<key (left arrow v) pressed?> or <<mouse down?> and <(mouse x) < (x position)>>> then\n    change [xv v] by (-4)\nend\nif <<key (right arrow v) pressed?> or <<mouse down?> and <(x position) < (mouse x)>>> then\n    change [xv v] by (4)\nend\nset [xv v] to ((xv) * (0.7))\nChange X by (round (xv))\nset [yv v] to ((((yv) + (1)) * (0.9)) - (1))\nif <<key (down arrow v) pressed?> or <<mouse down?> and <(y position) > (mouse y)>>> then\n    change [yv v] by (-1)\nend\nif <<key (up arrow v) pressed?> or <<mouse down?> and <(mouse y) > (y position)>>> then\n    change [yv v] by (1)\nend\nChange Y by (round (yv))\nif <[-240] > (x position)> then\n    Change Room X by [-1]\nend\nif <(x position) > [240]> then\n    Change Room X by [1]\nend\nif <[-180] > (y position)> then\n    Change Room Y by [-1]\nend\nif <(y position) > [180]> then\n    Change Room Y by [1]\nend\nif <[collisions v] contains [2]?> then\n    Reset\nend\n\nwhen I receive [you win \(2\) v]\nset [checkpoint x v] to [0]\nset [checkpoint y v] to [0]\nset [checkpoint room x v] to [1]\nset [checkpoint room y v] to [1]\nReset\n\nwhen I receive [edit v]\nset size to (200) %\nswitch costume to (player a v)\nshow\nset [checkpoint x v] to [0]\nset [checkpoint y v] to [0]\nset [checkpoint room x v] to [1]\nset [checkpoint room y v] to [1]\nReset\nforever\n    if <(Mode) = [Play]> then\n        show\n        Update Collisions\n        if <[collisions v] contains [5]?> then\n            Water Physics\n        else\n            Ground Physics\n        end\n    else\n        set [checkpoint x v] to [0]\n        set [checkpoint y v] to [0]\n        set [checkpoint room x v] to [1]\n        set [checkpoint room y v] to [1]\n        Reset\n        wait until <(Mode) = [Play]>\n    end\nend\n\nwhen I receive [edit v]\nforever\n    if <(Mode) = [Edit]> then\n        set size to (200) %\n        switch costume to (player a v)\n        go to x: (0) y: (0)\n        if <<(Room X) = [1]> and <(Room Y) = [1]>> then\n            show\n        else\n            hide\n        end\n    else\n        Update Collisions\n        if <[collisions v] contains [6]?> then\n            broadcast (You Win v)\n            repeat until <not <[collisions v] contains [6]?>>\n                Update Collisions\n            end\n        end\n    end\nend\n\n@Messages\n\nwhen flag clicked\nhide\ngo to [front v] layer\n\nwhen I receive [you win v]\ngo to x: (0) y: (0)\nswitch costume to (costume1 v)\nset [ghost v] effect to (100)\nshow\nrepeat (10)\n    change [ghost v] effect by (-10)\nend\nwait (0.5) seconds\nbroadcast (You Win \(2\) v)\n\nwhen I receive [you win \(2\) v]\nwait (0.5) seconds\nrepeat (10)\n    change [ghost v] effect by (10)\nend\nhide\n\nwhen I receive [checkpoint v]\ngo to x: (0) y: (40)\nswitch costume to (costume2 v)\nset [ghost v] effect to (100)\nshow\nrepeat (10)\n    change [ghost v] effect by (-10)\n    change y by (-4)\nend\nwait (0.5) seconds\nrepeat (10)\n    change [ghost v] effect by (10)\n    change y by (4)\nend\nhide\n\n@Menu\n\nwhen flag clicked\nhide\n\ndefine Generate Menu\nswitch costume to (dirt v)\ngo to x: (-170) y: (50)\nrepeat until <(costume [number v]) = [18]>\n    create clone of (_myself_ v)\n    change x by (80)\n    if <(x position) > [200]> then\n        set x to (-170)\n        change y by (-50)\n    end\n    next costume\nend\nif <(Mode) = [Edit]> then\n    go to x: (0) y: (0)\n    repeat (4)\n        next costume\n        create clone of (_myself_ v)\n    end\nend\nchange y by (20)\nswitch costume to (save v)\nrepeat (2)\n    create clone of (_myself_ v)\n    next costume\nend\nswitch costume to (change style v)\ngo to x: (0) y: (0)\ncreate clone of (_myself_ v)\nswitch costume to (open v)\ngo to x: (460) y: (0)\nset size to (100) %\n\nwhen I start as a clone\ngo to [front v] layer\nif <<(costume [number v]) > [2]> and <(costume [number v]) < [16]>> then\n    set [id v] to ((costume [number v]) - (2))\n    set size to (200) %\n    forever\n        switch costume to ((id) + ((2) + ((<(Style) > [1]> * ((9) + (Number of Styles))) + (((Style) - (1)) * (13)))))\n        point in direction (Tile Direction)\n        if <<(id) = [5]> or <(id) = [6]>> then\n            point in direction (90)\n        end\n        if <touching (mouse-pointer v)?> then\n            say (item ((costume [number v]) - (2)) of [info v])\n            if <mouse down?> then\n                set [tile v] to (id)\n            end\n        else\n            say []\n        end\n        if <(Tile) = (id)> then\n            set size to (220) %\n        else\n            set size to (180) %\n        end\n    end\nend\nif <(costume [number v]) = [16]> then\n    forever\n        point in direction (Tile Direction)\n        if <<touching (mouse-pointer v)?> and <mouse down?>> then\n            turn right (90) degrees\n            set [tile direction v] to (direction)\n            wait until <not <mouse down?>>\n        end\n    end\nend\nif <(costume [number v]) = [17]> then\n    forever\n        point in direction (90)\n        if <(Mode) = [Edit]> then\n            switch costume to (play v)\n        else\n            switch costume to (edit v)\n        end\n        if <<touching (mouse-pointer v)?> and <mouse down?>> then\n            if <(Mode) = [Edit]> then\n                switch costume to (edit v)\n                set [mode v] to [Play]\n                broadcast (Get Room Data v)\n            else\n                set [mode v] to [Edit]\n                switch costume to (play v)\n            end\n            wait until <not <mouse down?>>\n        end\n    end\nend\nif <<(costume [number v]) > [18]> and <(costume [number v]) < [23]>> then\n    forever\n        point in direction (90)\n        if <<touching (mouse-pointer v)?> and <mouse down?>> then\n            if <(costume [number v]) = [19]> then\n                change [room y v] by (1)\n            else\n                if <(costume [number v]) = [20]> then\n                    change [room y v] by (-1)\n                else\n                    if <(costume [number v]) = [21]> then\n                        change [room x v] by (1)\n                    else\n                        if <(costume [number v]) = [22]> then\n                            change [room x v] by (-1)\n                        end\n                    end\n                end\n            end\n            if <[0] > (Room X)> then\n                set [room x v] to [0]\n            end\n            if <[0] > (Room Y)> then\n                set [room y v] to [0]\n            end\n            if <(Room X) > [9]> then\n                set [room x v] to [9]\n            end\n            if <(Room Y) > [9]> then\n                set [room y v] to [9]\n            end\n            set [display: room v] to (join [Room: ] (join (Room X) (join [-] (Room Y))))\n            wait until <not <mouse down?>>\n        end\n    end\nend\nif <<(costume [number v]) > [22]> and <(costume [number v]) < [25]>> then\n    forever\n        point in direction (90)\n        if <<touching (mouse-pointer v)?> and <mouse down?>> then\n            if <(costume [number v]) = [23]> then\n                broadcast (Save v)\n                Save\n                delete all of [save code: v]\n                add [Triple click the following code and press ctr+c to copy it.] to [save code: v]\n                add (Save Code) to [save code: v]\n                hide list [save code: v]\n            else\n                broadcast (Load v)\n                ask [Enter a save code:] and wait\n                Load (answer)\n            end\n        end\n    end\nend\nif <(costume [number v]) = [25]> then\n    forever\n        switch costume to ((24) + (Style))\n        if <touching (mouse-pointer v)?> then\n            set [brightness v] effect to (-20)\n            if <mouse down?> then\n                change [style v] by (1)\n                if <(Style) > (Number of Styles)> then\n                    set [style v] to [1]\n                end\n                wait until <not <mouse down?>>\n            end\n        else\n            set [brightness v] effect to (0)\n        end\n    end\nend\n\nwhen I receive [close menu v]\ndelete this clone\n\nwhen I receive [edit v]\nshow list [save code: v]\nhide variable [display: room v]\ngo to [front v] layer\nset size to (100) %\ngo to x: (0) y: (0)\nswitch costume to (closed v)\nset [editing? v] to [1]\nshow\nforever\n    if <<touching (mouse-pointer v)?> or <key (space v) pressed?>> then\n        set [ghost v] effect to (0)\n        if <<mouse down?> or <key (space v) pressed?>> then\n            set [editing? v] to [0]\n            switch costume to (open v)\n            repeat (23)\n                change x by (20)\n            end\n            Generate Menu\n            set [display: room v] to (join [Room: ] (join (Room X) (join [-] (Room Y))))\n            show variable [display: room v]\n            set [old mode v] to (Mode)\n            wait until <<key (space v) pressed?> or <<<mouse down?> and <(mouse x) > [220]>> or <not <(Mode) = (old mode)>>>>\n            broadcast (Close Menu v)\n            switch costume to (closed v)\n            hide variable [display: room v]\n            set [editing? v] to [0.5]\n            show list [save code: v]\n            repeat (23)\n                change x by (-20)\n            end\n            set [editing? v] to [1]\n        end\n    else\n        set [ghost v] effect to (50)\n    end\nend\n\nwhen I receive [save v]\nif <<(costume [number v]) > [22]> and <(costume [number v]) < [25]>> then\n    hide\nend\n\ndefine Save\nset [save code v] to []\nset [i v] to [0]\nrepeat until <(i) > (length of [level \(whole\) v])>\n    change [i v] by (1)\n    set [save code v] to (join (Save Code) (join [/] (item (i) of [level \(whole\) v])))\nend\n\nwhen I receive [load v]\nif <<(costume [number v]) > [22]> and <(costume [number v]) < [25]>> then\n    hide\nend\n\ndefine Load (code)\ndelete all of [level \(whole\) v]\nset [i v] to [0]\nset [j v] to [0]\nrepeat until <(i) > (length of (code))>\n    change [i v] by (1)\n    if <(letter (i) of (code)) = [/]> then\n        change [j v] by (1)\n        add [] to [level \(whole\) v]\n    else\n        replace item (j) of [level \(whole\) v] with (join (item (j) of [level \(whole\) v]) (letter (i) of (code)))\n    end\nend\nrepeat until <not <(item (length of [level \(whole\) v]) of [level \(whole\) v]) = []>>\n    delete (length of [level \(whole\) v]) of [level \(whole\) v]\nend\n\n