Portal by lilgreenland (fixed by 1DS1DS)
@Stage\n\nwhen flag clicked\nbroadcast (initialization v)\nset volume to (10) %\nwait (8) seconds\nset [music v] to [0]\nbroadcast (music v)\n\ndefine player settings\nset [x v] to [2700]\nset [y v] to [-100]\nset [last x v] to (X)\nset [last y v] to (Y)\nset [alive v] to [1]\nset [vx v] to [0]\nset [vy v] to [0]\n\nwhen I receive [player alive v]\nset [health v] to [100]\nset [alive v] to [1]\nset [vx v] to [0]\nset [vy v] to [0]\nstart sound [player spawn v]\n\nwhen I receive [player dead v]\nset [alive v] to [0]\nset [vx v] to [0]\nset [vy v] to [0]\nstart sound [player death v]\n\ndefine pause check\nif <key (p v) pressed?> then\n    set [pause v] to [1]\n    add [pause] to [graphics type v]\n    create clone of (graphics v)\n    wait until <not <key (p v) pressed?>>\n    wait until <key (p v) pressed?>\n    wait until <not <key (p v) pressed?>>\n    set [pause v] to [0]\nend\n\ndefine setup\nerase all\nswitch backdrop to (day v)\nclear graphic effects\ndelete (all) of [x-spawn v]\ndelete (all) of [y-spawn v]\ndelete (all) of [type-spawn v]\ndelete (all) of [info-spawn v]\nset [m fire v] to [b]\nset [m look v] to [1]\nset [level v] to [1]\nset [cycle fire cd v] to [25]\nset [broadcast cd v] to [0]\nset [pause v] to [0]\nset [cycle v] to [0]\nset [portal? v] to [0]\nset [p gun? v] to [0]\nset [health v] to [100]\nset [rotate v] to [0]\nset [xc v] to [0]\nset [yc v] to [0]\nbroadcast (new level v)\nbroadcast (level name v)\nplayer settings\nphysics constants\nhide settings\n\ndefine physics constants\nset [elasticity v] to [0.1]\nset [g v] to [-0.4]\nset [ax v] to [0.4]\nset [jump v] to [-5]\nset [vx< v] to [6]\nset [friction v] to [0.75]\nset [min v v] to [0.07]\n\nwhen [h v] key pressed\nbroadcast (display v)\nif <(show settings?) = [1]> then\n    hide settings\n    wait (0.1) seconds\nelse\n    show settings\n    wait (0.1) seconds\nend\n\ndefine None\nif <(x1) > [0]> then\n    set [angle v] to ([atan v] of ((y1) / (x1)) )\nelse\n    if <<<(y1) > [0]> or <(y1) = [0]>> and <(x1) < [0]>> then\n        set [angle v] to (([atan v] of ((y1) / (x1)) ) + (180))\n    else\n        if <<(y1) < [0]> and <(x1) < [0]>> then\n            set [angle v] to (([atan v] of ((y1) / (x1)) ) - (180))\n        else\n            if <<(y1) > [0]> and <(x1) = [0]>> then\n                set [angle v] to [90]\n            else\n                if <<(y1) < [0]> and <(x1) = [0]>> then\n                    set [angle v] to [-90]\n                else\n                    if <<(y1) = [0]> and <(x1) = [0]>> then\n                        set [angle v] to [0]\n                    end\n                end\n            end\n        end\n    end\nend\n\ndefine check execute order, sort layers\nset [cycle v] to [0]\ndelete (all) of [layers v]\nshow list [layers v]\nbroadcast (layers v)\nrepeat (110)\n    wait (0) seconds\n    change [cycle v] by (1)\nend\nhide list [layers v]\n\nwhen I receive [play sound v]\nset [talking v] to [1]\nplay sound (sound file) until done\nset [talking v] to [0]\n\nwhen I receive [portal v]\nrepeat (10)\n    set [detect up v] to [0]\n    set [detect down v] to [0]\n    set [detect left v] to [0]\n    set [detect right v] to [0]\nend\n\nwhen [l v] key pressed\nask [enter level] and wait\nif <<(answer) > [0]> and <[18] > (answer)>> then\n    set [level v] to ((answer) - (1))\n    add [next level] to [graphics type v]\n    create clone of (graphics v)\nelse\nend\n\nwhen I receive [physics v]\nphysics constants\n\ndefine None\na2tan ((Y) - (y)) ((X) - (x))\nset [vx v] to (() - (((2) + ((0.015) * (([abs v] of ((X) - (x)) ) + ([abs v] of ((Y) - (y)) )))) * ([sin v] of (Angle) )))\nset [vy v] to (() - (((2) + ((0.015) * (([abs v] of ((X) - (x)) ) + ([abs v] of ((Y) - (y)) )))) * ([cos v] of (Angle) )))\nchange [x v] by (Vx)\nchange [y v] by (Vy)\nif <<([abs v] of ((X) - (x)) ) < [2]> and <([abs v] of ((Y) - (y)) ) < [2]>> then\n    if <(detect down) = [1]> then\n        change [y v] by (-1)\n        change [x v] by (() - (Vx))\n        change [save point y v] by (-1)\n    else\n        broadcast (player alive v)\n    end\nend\n\nwhen I receive [initialization v]\nsetup\nwait (0.2) seconds\nforever\n    pause check\n    change [cycle v] by (1)\n    set [last x v] to (X)\n    set [last y v] to (Y)\n    mouse look\n    if <(alive) = [1]> then\n        crouch\n        if <(detect down) = [1]> then\n            if <(crouch) = [0]> then\n                Lf-Rt controls (ground) (Vx)\n                Up-Dn controls\n            else\n                set [vx v] to ((Vx) * (friction))\n            end\n        else\n            change [vy v] by (() - (G))\n            Lf-Rt controls (air)\n        end\n        player max speed (15)\n        map collision (detect up) (detect down) (detect left) (detect right) (Vx) (Vy)\n    else\n        respawn to x= ((save point x) + (Xc)) , y= ((save point y) + (Yc))\n    end\n    broadcast (cycle: position v)\n    fire portals\n    broadcast (fix cycle v)\nend\n\ndefine None\nif <key (a v) pressed?> then\n    if <(vx) < (Vx<)> then\n        if <(vx) < [0]> then\n            set [vx v] to ((vx) * (friction))\n        end\n        change [vx v] by (Ax)\n    else\n        set [vx v] to ((vx) * (0.95))\n    end\nelse\n    if <key (d v) pressed?> then\n        if <(vx) > (() - (Vx<))> then\n            if <(vx) > [0]> then\n                set [vx v] to ((vx) * (friction))\n            end\n            change [vx v] by ((Ax) * (-1))\n        else\n            set [vx v] to ((vx) * (0.95))\n        end\n    else\n        set [vx v] to ((vx) * (friction))\n    end\nend\n\nwhen I receive [rotate v]\nset [detect up v] to [0]\nset [detect down v] to [0]\nset [detect left v] to [0]\nset [detect right v] to [0]\n\ndefine crouch\nif <key (s v) pressed?> then\n    if <(crouch) = [0]> then\n        set [crouch v] to [-6]\n    else\n        set [crouch v] to [-11]\n    end\nelse\n    if <(crouch) = [-11]> then\n        set [crouch v] to [-6]\n    else\n        set [crouch v] to [0]\n    end\nend\n\ndefine None\nif <(Vx) > (max speed)> then\n    set [vx v] to (max speed)\nelse\n    if <(Vx) < (() - (max speed))> then\n        set [vx v] to (() - (max speed))\n    end\nend\nif <(Vy) > (max speed)> then\n    set [vy v] to (max speed)\nelse\n    if <(Vy) < (() - (max speed))> then\n        set [vy v] to (() - (max speed))\n    end\nend\n\nset [elasticity v] to [0.1]\nset [g v] to [-0.4]\nset [ax v] to [0.325]\nset [jump v] to [-5]\nset [vx< v] to [6]\nset [friction v] to [0.75]\nset [min v v] to [0.07]\n\ndefine None\nif <<<(u) = [1]> and <(d) = [1]>> and <<(r) = [1]> and <(l) = [1]>>> then\n    if <(rotate) = [yes]> then\n        broadcast (player dead v)\n    end\nend\nif <<(l) = [1]> and <(vx) > [0]>> then\n    set [vx v] to (([abs v] of (vx) ) * ((-1) * (elasticity)))\nelse\n    if <<(r) = [1]> and <(vx) < [0]>> then\n        set [vx v] to (([abs v] of (vx) ) * (elasticity))\n    else\n        change [x v] by (vx)\n    end\nend\nif <<(u) = [1]> and <(vy) < [0]>> then\n    set [vy v] to (([abs v] of (vy) ) * ((elasticity) * (0.4)))\nelse\n    if <<(d) = [1]> and <(vy) > [0]>> then\n        set [vy v] to [0]\n    else\n        change [yc v] by (() - (vy))\n    end\nend\n\nwhen I receive [layers v]\nwait until <(cycle) = [0]>\ngo to [front v] layer\nadd [stage] to [layers v]\n\ncheck execute order, sort layers\n\ndefine fire portals\nif <mouse down?> then\n    if <(m fire) = [b]> then\n        broadcast (Fire blue portal v)\n    else\n        broadcast (Fire red portal v)\n    end\nend\nif <key (e v) pressed?> then\n    broadcast (Fire blue portal v)\nend\nif <key (q v) pressed?> then\n    broadcast (Fire red portal v)\nend\n\ndefine mouse look\nif <key (f v) pressed?> then\n    if <(cycle fire CD) < (cycle)> then\n        set [cycle fire cd v] to ((cycle) + (15))\n        if <(font message?) = [0]> then\n            broadcast (toggle mouse look message v)\n        end\n        if <(m look) = [1]> then\n            start sound [button_synth_negative_02 v]\n            set [m look v] to [0]\n        else\n            start sound [button press positive v]\n            set [m look v] to [1]\n        end\n    end\nend\nif <(m look) = [1]> then\n    mouse look ([floor v] of (((mouse x) * (0.08)) - ((Xc) * (0.92))) ) ([floor v] of (((mouse y) * (0.08)) - ((Yc) * (0.92))) )\nelse\n    mouse look ([floor v] of ((Xc) * (-0.95)) ) ([floor v] of ((Yc) * ((((Yc) * (Yc)) / (30000)) - (1))) )\nend\n\nmouse look ([floor v] of (((mouse x) * (0.06)) - ((Xc) * (0.94))) ) ([floor v] of (((mouse y) * (0.06)) - ((Yc) * (0.94))) )\n\ndefine None\nif <([abs v] of (xm) ) < [180]> then\n    change [x v] by ((() - (xm)) - (Xc))\n    set [xc v] to (() - (xm))\nelse\n    if <(xm) > [0]> then\n        change [x v] by ((-180) - (Xc))\n        set [xc v] to [-180]\n    else\n        change [x v] by ((180) - (Xc))\n        set [xc v] to [180]\n    end\nend\nif <([abs v] of (ym) ) < [120]> then\n    change [y v] by ((() - (ym)) - (Yc))\n    set [yc v] to (() - (ym))\nelse\n    if <(ym) > [0]> then\n        change [y v] by ((-120) - (Yc))\n        set [yc v] to [-120]\n    else\n        change [y v] by ((120) - (Yc))\n        set [yc v] to [120]\n    end\nend\n\ndefine show settings\nshow variable [vx v]\nshow variable [vy v]\nshow variable [x v]\nshow variable [y v]\nshow variable [elasticity v]\nshow variable [fy v]\nshow variable [detect down v]\nshow variable [detect up v]\nshow variable [detect left v]\nshow variable [detect right v]\nshow variable [g v]\nshow variable [level v]\nshow variable [jump v]\nshow variable [friction v]\nshow variable [health v]\nshow variable [cycle v]\nshow variable [vx< v]\nshow variable [ax v]\nshow variable [xc v]\nshow variable [yc v]\nset [show settings? v] to [1]\n\ndefine hide settings\nhide variable [vx v]\nhide variable [vy v]\nhide variable [x v]\nhide variable [y v]\nhide variable [elasticity v]\nhide variable [fy v]\nhide variable [detect left v]\nhide variable [detect right v]\nhide variable [detect down v]\nhide variable [detect up v]\nhide variable [g v]\nhide variable [level v]\nhide variable [jump v]\nhide variable [friction v]\nhide variable [health v]\nhide variable [cycle v]\nhide variable [vx< v]\nhide variable [ax v]\nhide variable [xc v]\nhide variable [yc v]\nshow list [layers v]\nset [show settings? v] to [0]\n\ndefine Up-Dn controls\nif <<key (space v) pressed?> or <key (w v) pressed?>> then\n    if <(Vy) < [0]> then\n        set [vy v] to (((Vy) * (0.5)) + (jump))\n    else\n        set [vy v] to (jump)\n    end\nend\n\ndefine Lf-Rt controls (air)\nif <key (a v) pressed?> then\n    if <(Vx) < [2]> then\n        if <(Vx) < [0]> then\n            change [vx v] by ((0.2) * (Ax))\n        end\n        change [vx v] by (Ax)\n    end\nelse\n    if <key (d v) pressed?> then\n        if <(Vx) > [-2]> then\n            if <(Vx) > [0]> then\n                change [vx v] by ((-0.2) * (Ax))\n            end\n            change [vx v] by (() - (Ax))\n        end\n    end\nend\n\nwhen I receive [fix cycle v]\nforever\n    broadcast (cycle v)\nend\n\n@graphics\n\nwhen I receive [initialization v]\ngo to x: (0) y: (0)\nset rotation style [all around v]\npoint in direction (90)\ndelete (all) of [graphics type v]\nset size to (100) %\nset volume to (20) %\nhide\n\ndefine portal fail red\nshow\nswitch costume to (pfr v)\ngo to x: ([portal fail x v] of [portal red v]) y: ([portal fail y v] of [portal red v])\nrepeat (5)\n    change [ghost v] effect by (20)\nend\n\nwhen I receive [end v]\nshow\nswitch costume to (thumbnail grey simple end v)\ngo to [front v] layer\nset size to (100) %\nwait (0) seconds\nstop [all v]\n\ndefine p1\nshow\nswitch costume to (p1 v)\npoint in direction ([direction v] of [player v])\nrepeat (10)\n    go to x: (Xc) y: ((Yc) + (crouch))\n    change [ghost v] effect by (10)\nend\n\ndefine p2\nshow\nswitch costume to (p2 v)\npoint in direction ([direction v] of [player v])\nrepeat (10)\n    go to x: (Xc) y: ((Yc) + (crouch))\n    change [ghost v] effect by (10)\nend\n\ndefine pause\nshow\nswitch costume to (pause 3d v)\nwait until <(pause) = [0]>\n\ndefine graphics chooser\nif <(.type) = [p1]> then\n    p1\nelse\n    if <(.type) = [p2]> then\n        p2\n    else\n        if <(.type) = [pause]> then\n            pause\n        else\n            if <(.type) = [pfb]> then\n                portal fail blue\n            else\n                if <(.type) = [pfr]> then\n                    portal fail red\n                else\n                    if <(.type) = [next level]> then\n                        next level\n                    end\n                end\n            end\n        end\n    end\nend\n\nwhen I start as a clone\nclear graphic effects\nset [.type v] to (item (last) of [graphics type v])\ndelete (last) of [graphics type v]\ngraphics chooser\ndelete this clone\n\ndefine portal fail blue\nshow\nswitch costume to (pfb v)\ngo to x: ([portal fail x v] of [portal blue v]) y: ([portal fail y v] of [portal blue v])\nrepeat (5)\n    change [ghost v] effect by (20)\nend\n\ndefine flash light\nset [ghost v] effect to (5)\nshow\nswitch costume to (size trick v)\nset size to (230) %\nswitch costume to (flashlight v)\nforever\n    point towards (mouse-pointer v)\nend\n\ndefine next level\nset [ghost v] effect to (100)\nshow\nswitch costume to (level transition v)\nwait (0.4) seconds\nrepeat (10)\n    change [ghost v] effect by (-10)\nend\nset [ghost v] effect to (0)\nchange [level v] by (1)\nbroadcast (new level v)\nwait (1) seconds\nstart sound [door_close v]\nwait (0.5) seconds\nrepeat (100)\n    change [ghost v] effect by (1)\nend\nbroadcast (level name v)\n\nwhen I receive [layers v]\nwait until <(cycle) = [100]>\ngo to [front v] layer\nadd [graphics] to [layers v]\n\nif <(portal blue on) = [1]> then\n    if <(portal red on) = [1]> then\nelse\n    if <(portal red on) = [1]> then\n        if <(m look) = [1]> then\n            if <not <(costume [number v]) = [1]>> then\n                switch costume to (mlook v)\n            end\n        else\n            if <not <(costume [number v]) = [1]>> then\n                switch costume to (mlook v)\n            end\n        end\n    else\n        if <(m look) = [1]> then\n            if <not <(costume [number v]) = [1]>> then\n                switch costume to (mlook v)\n            end\n        else\n            if <not <(costume [number v]) = [1]>> then\n                switch costume to (mlook v)\n            end\n        end\n    end\nend\n\ndefine HUD\nshow\nforever\n    if <(m look) = [1]> then\n        if <not <(costume [number v]) = [1]>> then\n            switch costume to (mlook on v)\n        end\n    else\n        if <not <(costume [number v]) = [2]>> then\n            switch costume to (mlook off v)\n        end\n    end\n    wait (0.3) seconds\nend\n\ndefine thumbnail\nshow\nswitch costume to (thumbnail grey large v)\n\nwhen flag clicked\n\nbroadcast (layers v)\n\n@BSH1's Font Engine\n\nwhen I receive [initialization v]\nset rotation style [don't rotate v]\nclear graphic effects\nset [ghost v] effect to (40)\nhide\nset [font message? v] to [0]\n\nCheck Length [do not use] (text) (size) (x)\n\nwhen I receive [layers v]\nwait until <(cycle) = [94]>\ngo to [front v] layer\nadd [font] to [layers v]\n\nwhen I receive [clear vector v]\ndelete this clone\n\ndefine Calculate Spacing! [do not use]\ndelete (all) of [spacing v]\nswitch costume to (case_sense v)\nadd [0] to [spacing v]\nrepeat (95)\n    next costume\n    go to x: (0) y: (0)\n    repeat until <touching (_edge_ v)?>\n        change x by (1)\n    end\n    add (((100) - (x position)) + (181)) to [spacing v]\nend\nadd [46] to [spacing v]\n\nwhen I start as a clone\nshow\nset [costume v] to (costume [number v])\nswitch costume to (o v)\nset size to (GS) %\nswitch costume to (costume)\n\ndefine None\nset [gs v] to (size)\nswitch costume to (o v)\nhide\nset size to (size) %\ngo to x: (x) y: (y)\nset [counter! v] to [0]\nrepeat (length of (text))\n    if <(x position) > ((240) - ((0.1) * (size)))> then\n        set x to (x)\n        change y by ((-0.65) * (size))\n    end\n    change [counter! v] by (1)\n    if <(letter (Counter!) of (text)) = [ ]> then\n        if <not <(x position) = (x)>> then\n            change x by ((0.5) * (size))\n        end\n    else\n        switch costume to (case_sense v)\n        switch costume to (letter (Counter!) of (text))\n        if <(costume [number v]) = [1]> then\n            switch costume to (join (letter (Counter!) of (text)) [2])\n        end\n        create clone of (_myself_ v)\n        change x by ((((item (costume [number v]) of [spacing v]) * (0.01)) * (size)) + ((0.05) * (size)))\n    end\n    wait (0) seconds\nend\nhide\n\ndefine None\nset [counter2! v] to ((Counter!) + (1))\nset [temp length v] to [0]\nrepeat until <<(Counter2!) > (length of (text))> or <(letter (Counter2!) of (text)) = [ ]>>\n    switch costume to (case_sense v)\n    switch costume to (letter (Counter!) of (text))\n    if <(costume [number v]) = [1]> then\n        switch costume to (join (letter (Counter!) of (text)) [2])\n    end\n    change [temp length v] by (((item (costume [number v]) of [spacing v]) / (100)) * (size))\n    change [counter2! v] by (1)\nend\nif <((x position) + (Temp Length)) > ((240) - (((15) / (100)) * (size)))> then\n    set x to (x)\n    change y by (((-65) / (100)) * (size))\nend\n\ndefine Paragraph!\nchange y by ((-1) * (GS))\n\nwhen I receive [level name v]\nif <(font message?) = [0]> then\n    set [font message? v] to [1]\n    broadcast (Clear Vector v)\n    Animate Text: [Test Chamber ] At [ (-215) (160) ] In font size (17)\n    change y by (-20)\n    wait (0.5) seconds\n    if <(level) > [9]> then\n        Animate Text: (level) At [ (-178) (y position) ] In font size (100)\n    else\n        Animate Text: (join [0] (level)) At [ (-178) (y position) ] In font size (100)\n    end\n    wait (0.5) seconds\n    change y by (-55)\n    Animate Text: ([costume name v] of [map v]) At [ (-206) (y position) ] In font size (40)\n    wait (3) seconds\n    broadcast (Clear Vector v)\n    set [font message? v] to [0]\nend\n\nwhen I receive [toggle mouse look message v]\nif <(font message?) = [0]> then\n    set [font message? v] to [1]\n    broadcast (Clear Vector v)\n    if <(m look) = [1]> then\n        Animate Text: [mouse look on] At [ (-100) (160) ] In font size (50)\n    else\n        Animate Text: [mouse look off] At [ (-100) (160) ] In font size (50)\n    end\n    wait (1) seconds\n    broadcast (Clear Vector v)\n    set [font message? v] to [0]\nend\n\n@no portals\n\nwhen I receive [initialization v]\nset [ghost v] effect to (100)\nset volume to (20) %\nhide\nset rotation style [all around v]\npoint in direction (90)\nswitch costume to (size trick v)\nset size to (500) %\nswitch costume to (level)\nwait (0.5) seconds\nshow\n\nwhen I receive [layers v]\nwait until <(cycle) = [90]>\ngo to [front v] layer\nadd [background] to [layers v]\n\nwhen I receive [new level v]\npoint in direction (90)\nswitch costume to (level)\n\nwhen I receive [cycle: position v]\ngo to x: ([floor v] of (X) ) y: ([floor v] of (Y) )\n\ndefine None\nset [save point x v] to (((sx) * ([cos v] of (degrees) )) + ((sy) * ([sin v] of (degrees) )))\nset [save point y v] to (((sy) * ([cos v] of (degrees) )) - ((sx) * ([sin v] of (degrees) )))\nset [x v] to (((x) * ([cos v] of (degrees) )) + ((y) * ([sin v] of (degrees) )))\nset [y v] to (((y) * ([cos v] of (degrees) )) - ((x) * ([sin v] of (degrees) )))\n\nwhen I receive [rotate v]\nturn right (rotate) degrees\ngo to x: ([floor v] of (X) ) y: ([floor v] of (Y) )\n\nwhen I receive [display v]\nif <(show settings?) = [1]> then\n    set [ghost v] effect to (50)\nelse\n    set [ghost v] effect to (100)\nend\n\n@damage\n\nwhen I receive [initialization v]\ngo to x: (0) y: (0)\nswitch costume to (red damage v)\nset size to (100) %\nset [ghost v] effect to (100)\nhide\n\nwhen I receive [layers v]\nwait until <(cycle) = [88]>\ngo to [front v] layer\nadd [damage] to [layers v]\n\nwhen I receive [player dead v]\nshow\nset [ghost v] effect to (50)\n\nwhen I receive [player alive v]\nset [ghost v] effect to (100)\nhide\n\nwhen I receive [damage v]\nshow\nset [ghost v] effect to (((0.5) * (health)) + (50))\nif <(health) < [1]> then\n    set [alive v] to [0]\n    broadcast (player dead v)\n    set [ghost v] effect to (0)\nelse\n    wait (0.5) seconds\n    repeat until <(health) > [100]>\n        if <(pause) = [0]> then\n            wait (0.2) seconds\n            change [health v] by (10)\n            set [ghost v] effect to (((0.5) * (health)) + (50))\n        end\n    end\n    set [health v] to [100]\n    set [ghost v] effect to (((0.5) * (health)) + (50))\n    hide\nend\n\n@portal blue\n\ndefine None\nif <(x1) > [0]> then\n    set [angle v] to ([atan v] of ((y1) / (x1)) )\nelse\n    if <<<(y1) > [0]> or <(y1) = [0]>> and <(x1) < [0]>> then\n        set [angle v] to (([atan v] of ((y1) / (x1)) ) + (180))\n    else\n        if <<(y1) < [0]> and <(x1) < [0]>> then\n            set [angle v] to (([atan v] of ((y1) / (x1)) ) - (180))\n        else\n            if <<(y1) > [0]> and <(x1) = [0]>> then\n                set [angle v] to [90]\n            else\n                if <<(y1) < [0]> and <(x1) = [0]>> then\n                    set [angle v] to [-90]\n                else\n                    if <<(y1) = [0]> and <(x1) = [0]>> then\n                        set [angle v] to [0]\n                    end\n                end\n            end\n        end\n    end\nend\n\nwhen I receive [initialization v]\nset volume to (20) %\nset rotation style [all around v]\nhide\nset [.show? v] to [0]\nclear graphic effects\nset [ghost v] effect to (10)\nswitch costume to (light blue v)\nset size to (153) %\nset [portal fail x v] to [0]\nset [portal fail y v] to [0]\nset [portal blue on v] to [0]\nwait (1) seconds\nset [portal blue on v] to [1]\n\nwhen I receive [fizzler v]\nclose portal\n\nwhen I receive [portal blue goto v]\nset size to (153) %\nset [ghost v] effect to (0)\nset [portal blue on v] to [1]\nset [.x v] to (item (last) of [x-spawn v])\nset [.y v] to (item (last) of [y-spawn v])\nset [.dir v] to (item (last) of [info-spawn v])\npoint in direction (.dir)\ndelete (last) of [x-spawn v]\ndelete (last) of [y-spawn v]\ndelete (last) of [info-spawn v]\nif <<([abs v] of ((Y) + (.y)) ) > [180]> or <([abs v] of ((X) + (.x)) ) > [240]>> then\n    hide\n    set [.show? v] to [0]\nelse\n    show\n    set [.show? v] to [1]\n    go to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\nend\n\nwhen I receive [cycle v]\nif <(portal blue on) = [1]> then\n    if <<([abs v] of ((Y) + (.y)) ) > [180]> or <([abs v] of ((X) + (.x)) ) > [240]>> then\n        if <(.show?) = [1]> then\n            hide\n            set [.show? v] to [0]\n        end\n    else\n        if <(.show?) = [0]> then\n            show\n            set [.show? v] to [1]\n        end\n        go to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\n    end\nend\n\nwhen I receive [player dead v]\nclose portal\n\nwhen I receive [p fire r v]\ncostume open closed\n\ndefine None\nset [.x v] to (((x) * ([cos v] of (degrees) )) + ((y) * ([sin v] of (degrees) )))\nset [.y v] to (((y) * ([cos v] of (degrees) )) - ((x) * ([sin v] of (degrees) )))\n\ndefine move until hit map (turbo)\nset [.dir v] to [off]\nif <touching (map v)?> then\n    hide\n    set [.show? v] to [0]\n    start sound [portal_invalid_surface3 v]\nelse\n    repeat until <<touching (map v)?> or <<touching (_edge_ v)?> or <<touching (door v)?> or <touching (fizzler v)?>>>>\n        change x by (.Vx)\n        if <touching (map v)?> then\n            if <(.Vx) > [0]> then\n                set [.dir v] to [-90]\n            else\n                set [.dir v] to [90]\n            end\n        else\n            change y by (.Vy)\n            if <touching (map v)?> then\n                if <(.Vy) > [0]> then\n                    set [.dir v] to [180]\n                else\n                    set [.dir v] to [0]\n                end\n            end\n        end\n    end\n    fire or fizzle\n    if <(portal color) = [r]> then\n        set [portal color v] to [b]\n        broadcast (portal gun v)\n    end\nend\n\nwhen I receive [layers v]\nwait until <(cycle) = [84]>\ngo to [front v] layer\nadd [portal 1] to [layers v]\n\nwhen I receive [p fire b v]\nrepeat (4)\n    change size by (30)\nend\nif <touching (fizzler v)?> then\n    set [xfizzf v] to (.x)\n    set [yfizzf v] to (.y)\n    broadcast (fizzler flash v)\n    hide\n    set [.show? v] to [0]\n    start sound [portal_invalid_surface3 v]\n    set [portal blue on v] to [0]\nend\n\nwhen I receive [new level v]\npoint in direction (90)\nset [portal blue on v] to [0]\nhide\nset [.show? v] to [0]\n\nwhen I receive [fire blue portal v]\nif <(cycle fire CD) < (cycle)> then\n    if <<(alive) = [1]> and <(p gun?) = [1]>> then\n        set [cycle fire cd v] to ((cycle) + (15))\n        set size to (1) %\n        show\n        set [.show? v] to [1]\n        set [.vy v] to ([cos v] of ([direction v] of [player v]) )\n        set [.vx v] to ([sin v] of ([direction v] of [player v]) )\n        go to x: (Xc) y: ((Yc) + (crouch))\n        move until hit map (turbo)\n        add [p1] to [graphics type v]\n        create clone of (graphics v)\n    end\nend\n\nif <(.dir) = [off]> then\nend\n\nwhen I receive [rotate v]\nrotate (rotate) degrees (.x) (.y)\nturn right (rotate) degrees\ngo to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\n\ndefine None\nif <(speed) > [10]> then\n    start sound [portalexit v]\nend\nif <(dir) = [-90]> then\n    set [vx v] to ((speed) + (2))\n    set [vy v] to [-2]\nelse\n    if <(dir) = [90]> then\n        set [vx v] to ((-2) - (10))\n        set [vy v] to [-2]\n    else\n        if <(dir) = [180]> then\n            set [vx v] to [0]\n            if <(speed) > [9]> then\n                set [vy v] to [9]\n            else\n                if <(speed) < [-9]> then\n                    set [vy v] to [-9]\n                else\n                    set [vy v] to (speed)\n                end\n            end\n        else\n            if <(dir) = [0]> then\n                if <(speed) > [3]> then\n                    set [vy v] to ((-1.1) - (speed))\n                else\n                    set [vy v] to [-2]\n                    change [y v] by (-25)\n                end\n                set [vx v] to [0]\n            else\n                set [vx v] to ((0) - (((2) + (speed)) * ([sin v] of (dir) )))\n                set [vy v] to ((0) - (((2) + (speed)) * ([cos v] of (dir) )))\n            end\n        end\n    end\nend\n\nwhen I receive [touch blue portal v]\nif <<(alive) = [1]> and <<(portal?) = [0]> and <(portal red on) = [1]>>> then\n    set [portal? v] to [1]\n    if <([abs v] of ((X) - ((Xc) - ([.x v] of [portal red v]))) ) < [180]> then\n        change [xc v] by ((X) - ((Xc) - ([.x v] of [portal red v])))\n    else\n        broadcast (teleport v)\n        if <((X) - ((Xc) - ([.x v] of [portal red v]))) > [0]> then\n            set [x v] to ((() - (([.x v] of [portal red v]) - (Xc))) + (180))\n            change [xc v] by (180)\n        else\n            set [x v] to ((() - (([.x v] of [portal red v]) - (Xc))) - (180))\n            change [xc v] by (-180)\n        end\n    end\n    if <([abs v] of ((Y) - ((Yc) - ([.y v] of [portal red v]))) ) < [140]> then\n        change [yc v] by ((Y) - ((Yc) - ([.y v] of [portal red v])))\n    else\n        broadcast (teleport v)\n        if <((Y) - ((Yc) - ([.y v] of [portal red v]))) > [0]> then\n            set [y v] to ((() - (([.y v] of [portal red v]) - (Yc))) + (180))\n            change [yc v] by (180)\n        else\n            set [y v] to ((() - (([.y v] of [portal red v]) - (Yc))) - (180))\n            change [yc v] by (-180)\n        end\n    end\n    exiting the portal with a direction = ([.dir v] of [portal red v]) , speed= ([sqrt v] of (((Vx) * (Vx)) + ((Vy) * (Vy))) )\n    broadcast (portal v)\nend\n\ndefine fire or fizzle\nif <<<touching (no portals v)?> or <touching (_edge_ v)?>> or <<<touching (door v)?> or <touching (fizzler v)?>> or <touching (portal red v)?>>> then\n    set size to (153) %\n    set [xfizzf v] to ([floor v] of ((x position) - (X)) )\n    set [yfizzf v] to ([floor v] of ((y position) - (Y)) )\n    broadcast (fizzler flash v)\n    start sound [portal_invalid_surface3 v]\n    set [.dir v] to (direction)\n    set [portal fail x v] to (x position)\n    set [portal fail y v] to (y position)\n    add [pfb] to [graphics type v]\n    create clone of (graphics v)\n    if <(portal blue on) = [0]> then\n        hide\n        set [.show? v] to [0]\n    end\nelse\n    start sound [portal blue fire v]\n    angle check\n    set [portal blue on v] to [1]\n    set [m fire v] to [r]\n    costume open closed\n    broadcast (P fire B v)\nend\n\ndefine angle check\nset [.x v] to ([floor v] of ((x position) - (X)) )\nset [.y v] to ([floor v] of ((y position) - (Y)) )\nset [portal blue on v] to [0]\nrepeat (length of [z panel angle v])\n    change [portal blue on v] by (1)\n    if <<<(.y) > ((item (portal blue on) of [y panel v]) - (50))> and <(.y) < ((item (portal blue on) of [y panel v]) + (50))>> and <<(.x) > ((item (portal blue on) of [x panel v]) - (50))> and <(.x) < ((item (portal blue on) of [x panel v]) + (50))>>> then\n        set [.dir v] to (item (portal blue on) of [z panel angle v])\n        set [.x v] to ([floor v] of (item (portal blue on) of [x panel v]) )\n        set [.y v] to ([floor v] of (item (portal blue on) of [y panel v]) )\n    end\nend\npoint in direction (.dir)\n\ndefine close portal\nif <(portal blue on) = [1]> then\n    set [portal blue on v] to [0]\n    repeat (4)\n        change size by (-30)\n        go to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\n    end\n    hide\n    set [.show? v] to [0]\nend\n\ndefine costume open closed\nif <(portal red on) = [1]> then\n    set [ghost v] effect to (0)\nelse\n    set [ghost v] effect to (70)\nend\n\n@portal red\n\nwhen I receive [initialization v]\nset volume to (20) %\nset rotation style [all around v]\nhide\nset [.show? v] to [0]\nclear graphic effects\nset [ghost v] effect to (10)\nswitch costume to (orangerd v)\nset size to (153) %\nset [portal red on v] to [0]\n\nwhen I receive [new level v]\npoint in direction (90)\nset [portal red on v] to [0]\nhide\n\nwhen I receive [p fire b v]\ncostume open closed\n\nwhen I receive [layers v]\nwait until <(cycle) = [83]>\ngo to [front v] layer\nadd [portal 2] to [layers v]\n\ndefine None\nif <(x1) > [0]> then\n    set [angle v] to ([atan v] of ((y1) / (x1)) )\nelse\n    if <<<(y1) > [0]> or <(y1) = [0]>> and <(x1) < [0]>> then\n        set [angle v] to (([atan v] of ((y1) / (x1)) ) + (180))\n    else\n        if <<(y1) < [0]> and <(x1) < [0]>> then\n            set [angle v] to (([atan v] of ((y1) / (x1)) ) - (180))\n        else\n            if <<(y1) > [0]> and <(x1) = [0]>> then\n                set [angle v] to [90]\n            else\n                if <<(y1) < [0]> and <(x1) = [0]>> then\n                    set [angle v] to [-90]\n                else\n                    if <<(y1) = [0]> and <(x1) = [0]>> then\n                        set [angle v] to [0]\n                    end\n                end\n            end\n        end\n    end\nend\n\ndefine close portal\nif <(portal red on) = [1]> then\n    set [portal red on v] to [0]\n    repeat (4)\n        change size by (-30)\n        go to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\n    end\n    hide\n    set [.show? v] to [0]\nend\n\nwhen I receive [fizzler v]\nclose portal\n\nwhen I receive [player dead v]\nclose portal\n\ndefine costume open closed\nif <(portal blue on) = [1]> then\n    set [ghost v] effect to (0)\nelse\n    set [ghost v] effect to (70)\nend\n\nwhen I receive [cycle v]\nif <(portal red on) = [1]> then\n    if <<([abs v] of ((Y) + (.y)) ) > [180]> or <([abs v] of ((X) + (.x)) ) > [240]>> then\n        if <(.show?) = [1]> then\n            hide\n            set [.show? v] to [0]\n        end\n    else\n        if <(.show?) = [0]> then\n            show\n            set [.show? v] to [1]\n        end\n        go to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\n    end\nend\n\ndefine map edge?\nif <<<touching (no portals v)?> or <touching (_edge_ v)?>> or <<touching (door v)?> or <<touching (fizzler v)?> or <touching (portal blue v)?>>>> then\n    set size to (153) %\n    set [xfizzf v] to ([floor v] of ((x position) - (X)) )\n    set [yfizzf v] to ([floor v] of ((y position) - (Y)) )\n    broadcast (fizzler flash v)\n    start sound [portal_invalid_surface3 v]\n    set [.dir v] to (direction)\n    set [portal fail x v] to (x position)\n    set [portal fail y v] to (y position)\n    add [pfr] to [graphics type v]\n    create clone of (graphics v)\n    if <(portal red on) = [0]> then\n        hide\n        set [.show? v] to [0]\n    end\nelse\n    angle check\n    start sound [portal red fire v]\n    set [portal red on v] to [1]\n    set [m fire v] to [b]\n    costume open closed\n    broadcast (P fire R v)\nend\n\ndefine angle check\nset [.x v] to ([floor v] of ((x position) - (X)) )\nset [.y v] to ([floor v] of ((y position) - (Y)) )\nset [portal red on v] to [0]\nrepeat (length of [z panel angle v])\n    change [portal red on v] by (1)\n    if <<<(.y) > ((item (portal red on) of [y panel v]) - (50))> and <(.y) < ((item (portal red on) of [y panel v]) + (50))>> and <<(.x) > ((item (portal red on) of [x panel v]) - (50))> and <(.x) < ((item (portal red on) of [x panel v]) + (50))>>> then\n        set [.dir v] to (item (portal red on) of [z panel angle v])\n        set [.x v] to ([floor v] of (item (portal red on) of [x panel v]) )\n        set [.y v] to ([floor v] of (item (portal red on) of [y panel v]) )\n    end\nend\npoint in direction (.dir)\n\nwhen I receive [p fire r v]\nrepeat (4)\n    change size by (30)\nend\nif <touching (fizzler v)?> then\n    set [xfizzf v] to (.x)\n    set [yfizzf v] to (.y)\n    broadcast (fizzler flash v)\n    hide\n    set [.show? v] to [0]\n    start sound [portal_invalid_surface3 v]\n    set [portal red on v] to [0]\nend\n\ndefine None\nset [.x v] to (((x) * ([cos v] of (degrees) )) + ((y) * ([sin v] of (degrees) )))\nset [.y v] to (((y) * ([cos v] of (degrees) )) - ((x) * ([sin v] of (degrees) )))\n\nwhen I receive [rotate v]\nrotate (rotate) degrees (.x) (.y)\nturn right (rotate) degrees\ngo to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\n\nwhen I receive [portal red goto v]\nset size to (153) %\nset [ghost v] effect to (0)\nset [portal red on v] to [1]\nset [.x v] to (item (last) of [x-spawn v])\nset [.y v] to (item (last) of [y-spawn v])\nset [.dir v] to (item (last) of [info-spawn v])\npoint in direction (.dir)\ndelete (last) of [x-spawn v]\ndelete (last) of [y-spawn v]\ndelete (last) of [info-spawn v]\nif <<([abs v] of ((Y) + (.y)) ) > [180]> or <([abs v] of ((X) + (.x)) ) > [240]>> then\n    hide\n    set [.show? v] to [0]\nelse\n    show\n    set [.show? v] to [1]\n    go to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\nend\n\nwhen I receive [fire red portal v]\nif <(cycle fire CD) < (cycle)> then\n    if <<(alive) = [1]> and <(p gun?) = [1]>> then\n        set [cycle fire cd v] to ((cycle) + (15))\n        set size to (1) %\n        show\n        set [.show? v] to [1]\n        set [.vy v] to ([cos v] of ([direction v] of [player v]) )\n        set [.vx v] to ([sin v] of ([direction v] of [player v]) )\n        go to x: (Xc) y: ((Yc) + (crouch))\n        move until hit map (turbo)\n        add [p2] to [graphics type v]\n        create clone of (graphics v)\n    end\nend\n\ndefine None\nif <(Vx) > (max speed)> then\n    set [vx v] to (max speed)\nelse\n    if <(Vx) < (() - (max speed))> then\n        set [vx v] to (() - (max speed))\n    end\nend\nif <(Vy) > (max speed)> then\n    set [vy v] to (max speed)\nelse\n    if <(Vy) < (() - (max speed))> then\n        set [vy v] to (() - (max speed))\n    end\nend\n\ndefine None\nif <(speed) > [10]> then\n    start sound [portalexit v]\nend\nif <(dir) = [-90]> then\n    set [vx v] to ((speed) + (2))\n    set [vy v] to [-3]\nelse\n    if <(dir) = [90]> then\n        set [vx v] to ((-2) - (speed))\n        set [vy v] to [-3]\n    else\n        if <(dir) = [180]> then\n            set [vx v] to [0]\n            if <(speed) > [9]> then\n                set [vy v] to [9]\n            else\n                if <(speed) < [-9]> then\n                    set [vy v] to [-9]\n                else\n                    set [vy v] to (speed)\n                end\n            end\n        else\n            if <(dir) = [0]> then\n                if <(speed) > [3]> then\n                    set [vy v] to ((-1.1) - (speed))\n                else\n                    set [vy v] to [-2]\n                    change [y v] by (-25)\n                end\n                set [vx v] to [0]\n            else\n                set [vx v] to ((0) - (((2) + (speed)) * ([sin v] of (dir) )))\n                set [vy v] to ((0) - (((2) + (speed)) * ([cos v] of (dir) )))\n            end\n        end\n    end\nend\n\ndefine move until hit map (turbo)\nset [.dir v] to [off]\nif <touching (map v)?> then\n    hide\n    set [.show? v] to [0]\n    start sound [portal_invalid_surface3 v]\nelse\n    repeat until <<touching (map v)?> or <<touching (_edge_ v)?> or <<touching (door v)?> or <touching (fizzler v)?>>>>\n        change x by (.Vx)\n        if <touching (map v)?> then\n            if <(.Vx) > [0]> then\n                set [.dir v] to [-90]\n            else\n                set [.dir v] to [90]\n            end\n        else\n            change y by (.Vy)\n            if <touching (map v)?> then\n                if <(.Vy) > [0]> then\n                    set [.dir v] to [180]\n                else\n                    set [.dir v] to [0]\n                end\n            end\n        end\n    end\n    map edge?\n    if <(portal color) = [b]> then\n        set [portal color v] to [r]\n        broadcast (portal gun v)\n    end\nend\n\nwhen I receive [touch red portal v]\nif <<(alive) = [1]> and <<(portal?) = [0]> and <(portal blue on) = [1]>>> then\n    set [portal? v] to [1]\n    if <([abs v] of ((X) - ((Xc) - ([.x v] of [portal blue v]))) ) < [180]> then\n        change [xc v] by ((X) - ((Xc) - ([.x v] of [portal blue v])))\n    else\n        broadcast (teleport v)\n        if <((X) - ((Xc) - ([.x v] of [portal blue v]))) > [0]> then\n            set [x v] to ((() - (([.x v] of [portal blue v]) - (Xc))) + (180))\n            change [xc v] by (180)\n        else\n            set [x v] to ((() - (([.x v] of [portal blue v]) - (Xc))) - (180))\n            change [xc v] by (-180)\n        end\n    end\n    if <([abs v] of ((Y) - ((Yc) - ([.y v] of [portal blue v]))) ) < [140]> then\n        change [yc v] by ((Y) - ((Yc) - ([.y v] of [portal blue v])))\n    else\n        broadcast (teleport v)\n        if <((Y) - ((Yc) - ([.y v] of [portal blue v]))) > [0]> then\n            set [y v] to ((() - (([.y v] of [portal blue v]) - (Yc))) + (180))\n            change [yc v] by (180)\n        else\n            set [y v] to ((() - (([.y v] of [portal blue v]) - (Yc))) - (180))\n            change [yc v] by (-180)\n        end\n    end\n    exiting the portal with a direction = ([.dir v] of [portal blue v]) , speed= ([sqrt v] of (((Vx) * (Vx)) + ((Vy) * (Vy))) )\n    broadcast (portal v)\nend\n\nplayer max speed (12)\n\n@Map\n\ndefine None\nif <(color) = [blue]> then\n    add (x) to [x-spawn v]\n    add (y) to [y-spawn v]\n    add (dir) to [info-spawn v]\n    broadcast (Portal Blue goto v)\nelse\n    add (x) to [x-spawn v]\n    add (y) to [y-spawn v]\n    add (dir) to [info-spawn v]\n    broadcast (Portal Red goto v)\nend\n\ndefine None\nadd (x) to [x-spawn v]\nadd (y) to [y-spawn v]\nadd (type) to [type-spawn v]\nadd (rotation) to [info-spawn v]\ncreate clone of (door v)\n\ndefine None\nadd (x) to [x-spawn v]\nadd (y) to [y-spawn v]\nadd (dir) to [type-spawn v]\ncreate clone of (turret v)\n\ndefine None\nadd (x) to [x-spawn v]\nadd (y) to [y-spawn v]\nadd (type) to [type-spawn v]\ncreate clone of (items v)\n\ndefine None\nadd (x) to [x-spawn v]\nadd (y) to [y-spawn v]\nadd (track) to [type-spawn v]\nadd (lock) to [info-spawn v]\ncreate clone of (platform v)\n\ndefine None\nadd (x) to [x-spawn v]\nadd (y) to [y-spawn v]\nadd (lock) to [type-spawn v]\nadd (costume) to [info-spawn v]\ncreate clone of (fizzler v)\n\ndefine None\nadd (x) to [x-spawn v]\nadd (y) to [y-spawn v]\nadd (lock) to [type-spawn v]\ncreate clone of (button v)\n\nwhen I receive [initialization v]\nhide\nset volume to (20) %\nset rotation style [all around v]\ngo to x: (2500) y: (180)\npoint in direction (90)\nclear graphic effects\nswitch costume to (size trick v)\nset size to (500) %\nswitch costume to (aperture science v)\nwait (0.5) seconds\nshow\n\nwhen I receive [layers v]\nwait until <(cycle) = [80]>\ngo to [front v] layer\nadd [Map] to [layers v]\n\ndefine level the end\nset [x v] to [1200]\nset [y v] to [213]\nset [save point x v] to (X)\nset [save point y v] to (Y)\nspawn turret: direction= (-90) , x= (-950) , y= (-231)\nspawn turret: direction= (-90) , x= (-650) , y= (-231)\nspawn turret: direction= (-90) , x= (-370) , y= (-231)\nspawn turret: direction= (-90) , x= (-370) , y= (-191)\nspawn turret: direction= (-90) , x= (-370) , y= (-151)\nspawn turret: direction= (-90) , x= (-370) , y= (-111)\nspawn turret: direction= (-90) , x= (-370) , y= (-71)\nspawn turret: direction= (90) , x= (-820) , y= (-122)\nforever\n    check if below (600)\nend\n\ndefine level doors, switches, and turrets\nset [x v] to [742]\nset [y v] to [214]\nset [save point x v] to (X)\nset [save point y v] to (Y)\ndelete (all) of [locks v]\nadd [1] to [locks v]\nadd [1] to [locks v]\nadd [1] to [locks v]\nadd [0] to [locks v]\nspawn turret: direction= (90) , x= (-577) , y= (-232)\nwait (1) seconds\nspawn switch: x= (-493) , y= (-358) , lock type= (1) rotation= (1)\nspawn switch: x= (872) , y= (-372) , lock type= (2) rotation= (1)\nspawn switch: x= (455) , y= (-275) , lock type= (3) rotation= (1)\nwait (1) seconds\nspawn door: x= (-400) , y= (-340) , lock type= (1) rotation= (1)\nspawn door: x= (1004) , y= (-213) , lock type= (2) rotation= (1)\nwait (1) seconds\nspawn item: type= [3] at x= (-235) , y= (-339)\nwait (1) seconds\nspawn platform, x= (557) , y= (-289) , track= (4) , lock= (-3)\nwait (1) seconds\nspawn turret: direction= (-90) , x= (783) , y= (-393)\nwait (1) seconds\nspawn fizzler, x= (87) , y= (-340) , lock= (4) , costume= (1)\nforever\n    check if below (800)\nend\n\ndefine level aperture science\nset [p gun? v] to [0]\nset [portal color v] to [p]\nbroadcast (portal gun v)\nset [x v] to [1200]\nset [y v] to [-100]\nset [save point x v] to (X)\nset [save point y v] to (Y)\ndelete (all) of [locks v]\nadd [1] to [locks v]\nadd [1] to [locks v]\nportal goto: x= (-834) , y= (-160) , direction= (-90) , color= [blue]\nwait (1) seconds\nportal goto: x= (-678) , y= (-160) , direction= (90) , color= [red]\nwait (1) seconds\nspawn item: type= [1] at x= (276) , y= (176)\nspawn item: type= [2] at x= (867) , y= (176)\nwait (1) seconds\nspawn platform, x= (873) , y= (141) , track= (3) , lock= (-1)\nwait (1) seconds\nspawn fizzler, x= (837) , y= (171) , lock= (-2) , costume= (2)\nforever\n    if <<<[484] > ((X) - (Xc))> and <((X) - (Xc)) > [430]>> and <<[231] > ((Y) - (Yc))> and <((Y) - (Yc)) > [120]>>> then\n        if <[1] > (Vy)> then\n            set [vy v] to [-15]\n        end\n    end\nend\n\ndefine level conservation of momentum\nset [x v] to [405]\nset [y v] to [62]\nset [save point x v] to (X)\nset [save point y v] to (Y)\ndelete (all) of [locks v]\nadd [1] to [locks v]\nspawn platform, x= (-284) , y= (-182) , track= (5) , lock= (1)\nforever\n    check if below (600)\n    if <key (s v) pressed?> then\n        portal goto: x= (-237) , y= (-190) , direction= (0) , color= [blue]\n        portal goto: x= (-68) , y= (-90) , direction= (0) , color= [red]\n    end\nend\n\ndefine level just a fling\nset [x v] to [1074]\nset [y v] to [213]\nset [save point x v] to (X)\nset [save point y v] to (Y)\nadd angled panel: x= (-372) , y= (-220) , angle= (45)\ndelete (all) of [locks v]\nadd [1] to [locks v]\nadd [1] to [locks v]\nspawn fizzler, x= (-917) , y= (-213) , lock= (-2) , costume= (1)\nwait (1) seconds\nspawn door: x= (808) , y= (-213) , lock type= (1) rotation= (1)\nspawn door: x= (14) , y= (-200) , lock type= (2) rotation= (1)\nwait (1) seconds\nspawn switch: x= (715) , y= (-231) , lock type= (1) rotation= (1)\nspawn switch: x= (63) , y= (-118) , lock type= (2) rotation= (1)\nwait (1) seconds\nspawn turret: direction= (-90) , x= (-590) , y= (-141)\nspawn turret: direction= (-90) , x= (1008) , y= (-264)\nspawn turret: direction= (90) , x= (216) , y= (-472)\nforever\n    check if below (600)\nend\n\ndefine level: cubes squared\nset [x v] to [742]\nset [y v] to [214]\nset [save point x v] to (X)\nset [save point y v] to (Y)\nadd angled panel: x= (-368) , y= (-389) , angle= (50)\ndelete (all) of [locks v]\nadd [1] to [locks v]\nadd [1] to [locks v]\nadd [1] to [locks v]\nspawn cube: x= (-676) , y= (-213)\nspawn cube: x= (170) , y= (-288)\nwait (1) seconds\nspawn button: x= (-493) , y= (-340) , lock type= (1)\nspawn button: x= (25) , y= (-310) , lock type= (2)\nspawn button: x= (250) , y= (-288) , lock type= (3)\nwait (1) seconds\nspawn fizzler, x= (-405) , y= (-340) , lock= (-1) , costume= (1)\nspawn fizzler, x= (100) , y= (-273) , lock= (-3) , costume= (2)\nwait (1) seconds\nspawn door: x= (342) , y= (-288) , lock type= (2) rotation= (1)\nforever\n    check if below (600)\nend\n\ndefine level ballistic trajectory\nset [x v] to [399]\nset [y v] to [112]\nset [save point x v] to (X)\nset [save point y v] to (Y)\nadd angled panel: x= (-296) , y= (-108) , angle= (35)\ndelete (all) of [locks v]\nadd [1] to [locks v]\nspawn platform, x= (-639) , y= (-200) , track= (7) , lock= (1)\nforever\n    if <<<[283] > ((X) - (Xc))> and <((X) - (Xc)) > [90]>> and <[145] < ((Y) - (Yc))>> then\n        if <(alive) = [1]> then\n            broadcast (player dead v)\n        end\n    end\n    check if below (600)\nend\n\ndefine level Weighted Storage Cube\nset [x v] to [399]\nset [y v] to [112]\nset [save point x v] to (X)\nset [save point y v] to (Y)\ndelete (all) of [locks v]\nadd [1] to [locks v]\nadd [1] to [locks v]\nadd [1] to [locks v]\nspawn button: x= (-279) , y= (-112) , lock type= (1)\nspawn button: x= (152) , y= (-112) , lock type= (2)\nwait (1) seconds\nspawn door: x= (-191) , y= (-109) , lock type= (1) rotation= (1)\nspawn door: x= (289) , y= (-112) , lock type= (2) rotation= (1)\nwait (1) seconds\nspawn cube: x= (61) , y= (-112)\nwait (1) seconds\nspawn fizzler, x= (289) , y= (-112) , lock= (-3) , costume= (1)\nforever\n    check if below (600)\nend\n\ndefine None\nadd (x) to [x-spawn v]\nadd (y) to [y-spawn v]\nadd (type) to [type-spawn v]\nadd (rotation) to [info-spawn v]\ncreate clone of (switch v)\n\ndefine level: upside down\nset [p gun? v] to [0]\nset [portal color v] to [p]\nbroadcast (portal gun v)\nset [x v] to [568]\nset [y v] to [112]\nset [save point x v] to (X)\nset [save point y v] to (Y)\ndelete (all) of [locks v]\nadd [1] to [locks v]\nadd [1] to [locks v]\nset [rotate v] to [0]\nspawn switch: x= (-253) , y= (-27) , lock type= (1) rotation= (1)\nspawn switch: x= (137) , y= (-278) , lock type= (2) rotation= (1)\nwait (1) seconds\nspawn door: x= (-171) , y= (-13) , lock type= (1) rotation= (1)\nspawn door: x= (141) , y= (-113) , lock type= (2) rotation= (1)\nwait (1) seconds\nspawn item: type= [3] at x= (17) , y= (-373)\nforever\n    rotate\nend\n\ndefine level asteroid\nset [p gun? v] to [0]\nset [portal color v] to [p]\nbroadcast (portal gun v)\nset [x v] to [109]\nset [y v] to [-234]\nset [save point x v] to (X)\nset [save point y v] to (Y)\ndelete (all) of [locks v]\nadd [1] to [locks v]\nset [rotate v] to [0]\nforever\n    rotate\nend\n\nwhen I receive [cycle: position v]\ngo to x: ([floor v] of (X) ) y: ([floor v] of (Y) )\n\nwhen I receive [new level v]\nwait (0.1) seconds\nset [talking v] to [1]\nplay sound ([costume name v] of [map v]) until done\nset [talking v] to [0]\n\ndefine level out of reach\nset [x v] to [568]\nset [y v] to [112]\nset [save point x v] to (X)\nset [save point y v] to (Y)\ndelete (all) of [locks v]\nadd [1] to [locks v]\nadd [1] to [locks v]\nadd [1] to [locks v]\nspawn button: x= (-226) , y= (-112) , lock type= (1)\nspawn button: x= (-337) , y= (-8) , lock type= (2)\nwait (1) seconds\nspawn fizzler, x= (-408) , y= (-43) , lock= (-2) , costume= (5)\nspawn fizzler, x= (-129) , y= (-112) , lock= (-3) , costume= (1)\nwait (1) seconds\nspawn door: x= (-129) , y= (-112) , lock type= (1) rotation= (1)\nwait (5) seconds\nspawn cube: x= (-472) , y= (-7)\nforever\n    if <<<[733] > ((X) - (Xc))> and <((X) - (Xc)) > [695]>> and <((Y) - (Yc)) > [100]>> then\n        set [vy v] to [-15]\n    end\nend\n\ndefine level material emancipation grid\nset [x v] to [612]\nset [y v] to [136]\nset [save point x v] to (X)\nset [save point y v] to (Y)\nadd angled panel: x= (-213) , y= (-155) , angle= (50)\ndelete (all) of [locks v]\nadd [0] to [locks v]\nadd [0] to [locks v]\nspawn fizzler, x= (-13) , y= (48) , lock= (2) , costume= (5)\nspawn fizzler, x= (-105) , y= (13) , lock= (1) , costume= (1)\nspawn fizzler, x= (-120) , y= (-60) , lock= (2) , costume= (1)\nspawn fizzler, x= (-120) , y= (-120) , lock= (2) , costume= (1)\nwait (1) seconds\nspawn switch: x= (200) , y= (-204) , lock type= (1) rotation= (1)\nwait (1) seconds\nspawn platform, x= (93) , y= (-220) , track= (6) , lock= (1)\nforever\n    check if below (700)\nend\n\ndefine None\nadd (x) to [x panel v]\nadd (y) to [y panel v]\nadd (a) to [z panel angle v]\n\ndefine level platformer\nset [x v] to [1236]\nset [y v] to [213]\nset [save point x v] to (X)\nset [save point y v] to (Y)\ndelete (all) of [locks v]\nadd [1] to [locks v]\nadd [1] to [locks v]\nspawn fizzler, x= (-921) , y= (-200) , lock= (-2) , costume= (2)\nwait (1) seconds\nspawn turret: direction= (-90) , x= (-858) , y= (-231)\nspawn turret: direction= (90) , x= (-71) , y= (61)\nwait (1) seconds\nspawn platform, x= (-647) , y= (-66) , track= (2) , lock= (-2)\nspawn platform, x= (-597) , y= (-66) , track= (1) , lock= (-2)\nwait (1) seconds\nspawn switch: x= (136) , y= (7) , lock type= (1) rotation= (1)\nspawn switch: x= (-586) , y= (-231) , lock type= (2) rotation= (1)\nwait (1) seconds\nspawn door: x= (181) , y= (24) , lock type= (1) rotation= (1)\nspawn door: x= (344) , y= (24) , lock type= (-1) rotation= (1)\nforever\n    check if below (600)\nend\n\ndefine level construction work\nset [x v] to [330]\nset [y v] to [338]\nset [save point x v] to (X)\nset [save point y v] to (Y)\ndelete (all) of [locks v]\nadd [1] to [locks v]\nforever\n    check if below (600)\nend\n\nwhen I receive [rotate v]\nturn right (rotate) degrees\ngo to x: ([floor v] of (X) ) y: ([floor v] of (Y) )\n\ndefine None\nset [save point x v] to (((sx) * ([cos v] of (degrees) )) + ((sy) * ([sin v] of (degrees) )))\nset [save point y v] to (((sy) * ([cos v] of (degrees) )) - ((sx) * ([sin v] of (degrees) )))\nset [x v] to (((x) * ([cos v] of (degrees) )) + ((y) * ([sin v] of (degrees) )))\nset [y v] to (((y) * ([cos v] of (degrees) )) - ((x) * ([sin v] of (degrees) )))\nset [vx v] to (((vx) * ([cos v] of (degrees) )) + ((vy) * ([sin v] of (degrees) )))\nset [vy v] to (((vy) * ([cos v] of (degrees) )) - ((vx) * ([sin v] of (degrees) )))\n\ndefine rotate\nif <(rotate) = [0]> then\n    if <key (q v) pressed?> then\n        set [rotate v] to [-30]\n        repeat (3)\n            change [x v] by ((0) - (Xc))\n            set [xc v] to [0]\n            change [y v] by ((0) - (Yc))\n            set [yc v] to [0]\n            rotate (rotate) degrees (X) (Y) (save point x) (save point y) (Vx) (Vy)\n            broadcast (rotate v)\n        end\n        wait (0) seconds\n        set [rotate v] to [0]\n    else\n        if <key (e v) pressed?> then\n            set [rotate v] to [30]\n            repeat (3)\n                change [x v] by ((0) - (Xc))\n                set [xc v] to [0]\n                change [y v] by ((0) - (Yc))\n                set [yc v] to [0]\n                rotate (rotate) degrees (X) (Y) (save point x) (save point y) (Vx) (Vy)\n                broadcast (rotate v)\n            end\n            wait (0) seconds\n            set [rotate v] to [0]\n        end\n    end\nend\n\ndefine portal maps\nif <(level) = [1]> then\n    level aperture science\nend\nif <(level) = [2]> then\n    level doors, switches, and turrets\nend\nif <(level) = [3]> then\n    level conservation of momentum\nend\nif <(level) = [4]> then\n    level ballistic trajectory\nend\nif <(level) = [5]> then\n    level just a fling\nend\nif <(level) = [6]> then\n    level Weighted Storage Cube\nend\nif <(level) = [7]> then\n    cube2\nend\nif <(level) = [8]> then\n    level out of reach\nend\nif <(level) = [9]> then\n    level material emancipation grid\nend\nif <(level) = [10]> then\n    level platformer\nend\nif <(level) = [11]> then\n    level: cubes squared\nend\nif <(level) = [12]> then\n    skyscrape\nend\nif <(level) = [13]> then\n    level uprising\nend\nif <(level) = [14]> then\n    level construction work\nend\n\nwhen I receive [new level v]\nall levels setup\nif <(level) < [15]> then\n    portal maps\nelse\n    ref frame maps\nend\nif <<(level) < [1]> or <(level) > [17]>> then\n    broadcast (end v)\nend\n\ndefine all levels setup\nswitch costume to (level)\npoint in direction (90)\nset [p gun? v] to [1]\nset [portal color v] to [b]\nbroadcast (portal gun v)\nset [xc v] to [0]\nset [yc v] to [0]\ndelete (all) of [x panel v]\ndelete (all) of [y panel v]\ndelete (all) of [z panel angle v]\n\ndefine None\nif <((Y) - (Yc)) > (y min)> then\n    if <(alive) = [1]> then\n        set [alive v] to [0]\n        broadcast (player dead v)\n    end\nend\n\ndefine ref frame maps\nif <(level) = [15]> then\n    level the end\nend\nif <(level) = [16]> then\n    level: upside down\nend\nif <(level) = [17]> then\n    level asteroid\nend\n\ndefine cube2\nset [x v] to [399]\nset [y v] to [112]\nset [save point x v] to (X)\nset [save point y v] to (Y)\ndelete (all) of [locks v]\nadd [1] to [locks v]\nadd [1] to [locks v]\nspawn cube: x= (-325) , y= (-112)\nspawn cube: x= (61) , y= (-63)\nwait (1) seconds\nspawn fizzler, x= (-119) , y= (-63) , lock= (-1) , costume= (1)\nspawn fizzler, x= (214) , y= (-10) , lock= (-2) , costume= (1)\nspawn fizzler, x= (438) , y= (-10) , lock= (-3) , costume= (1)\nwait (1) seconds\nspawn button: x= (242) , y= (-10) , lock type= (2)\nwait (1) seconds\nspawn door: x= (438) , y= (-10) , lock type= (2) rotation= (1)\nwait (1) seconds\nforever\n    check if below (135)\nend\n\ndefine skyscrape\nset [x v] to [630]\nset [y v] to [-118]\nset [save point x v] to (X)\nset [save point y v] to (Y)\nadd angled panel: x= (-746) , y= (-129) , angle= (-50)\nadd angled panel: x= (-638) , y= (-129) , angle= (50)\ndelete (all) of [locks v]\nadd [1] to [locks v]\nadd [1] to [locks v]\nspawn fizzler, x= (-337) , y= (-30) , lock= (-1) , costume= (3)\nspawn fizzler, x= (13) , y= (-41) , lock= (-1) , costume= (1)\nspawn fizzler, x= (-920) , y= (-25) , lock= (-1) , costume= (3)\nwait (1) seconds\nspawn cube: x= (-284) , y= (-49)\nwait (1) seconds\nspawn button: x= (-24) , y= (-50) , lock type= (2)\nwait (1) seconds\nspawn door: x= (13) , y= (-41) , lock type= (-2) rotation= (1)\nspawn door: x= (-921) , y= (-35) , lock type= (2) rotation= (1)\nwait (1) seconds\nspawn turret: direction= (-90) , x= (52) , y= (-59)\nforever\n    check if below (660)\nend\n\ndefine level uprising\nset [x v] to [1054]\nset [y v] to [-828]\nset [save point x v] to (X)\nset [save point y v] to (Y)\ndelete (all) of [locks v]\nadd [0] to [locks v]\nadd [0] to [locks v]\nadd [1] to [locks v]\nadd [1] to [locks v]\nadd [1] to [locks v]\nspawn platform, x= (-290) , y= (6) , track= (8) , lock= (1)\nspawn platform, x= (487) , y= (-300) , track= (9) , lock= (3)\nwait (1) seconds\nspawn switch: x= (-65) , y= (46) , lock type= (1) rotation= (1)\nwait (1) seconds\nspawn turret: direction= (-90) , x= (-158) , y= (60)\nspawn turret: direction= (-90) , x= (280) , y= (2)\nwait (1) seconds\nspawn cube: x= (670) , y= (21)\nwait (1) seconds\nspawn button: x= (351) , y= (88) , lock type= (2)\nspawn button: x= (198) , y= (-56) , lock type= (4)\nwait (1) seconds\nspawn fizzler, x= (487) , y= (-25) , lock= (-3) , costume= (5)\nspawn fizzler, x= (187) , y= (-25) , lock= (2) , costume= (5)\nwait (1) seconds\nspawn door: x= (-23) , y= (68) , lock type= (4) rotation= (1)\nforever\n    if <<<[411] > ((X) - (Xc))> and <((X) - (Xc)) > [355]>> and <((Y) - (Yc)) > [220]>> then\n        if <[1] > (Vy)> then\n            set [vy v] to [-15]\n        end\n    end\nend\n\ndefine None\nadd (x) to [x-spawn v]\nadd (y) to [y-spawn v]\ncreate clone of (cube v)\n\ndefine None\nadd (x) to [x-spawn v]\nadd (y) to [y-spawn v]\nadd (color) to [type-spawn v]\nadd (angle) to [info-spawn v]\ncreate clone of (panel v)\n\n@fizzler\n\nwhen I receive [initialization v]\nset volume to (20) %\nset rotation style [all around v]\ngo to x: (0) y: (0)\npoint in direction (90)\nswitch costume to (1 v)\nset size to (100) %\nclear graphic effects\nhide\nset [.show? v] to [0]\nset [.on? v] to [x]\nset [.type v] to [0]\n\nwhen I receive [layers v]\nwait until <(cycle) = [71]>\ngo to [front v] layer\nadd [fizzler] to [layers v]\n\nwhen I receive [rotate v]\nrotate (rotate) degrees (.x) (.y)\nturn right (rotate) degrees\ngo to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\n\ndefine None\nset [.x v] to (((x) * ([cos v] of (degrees) )) + ((y) * ([sin v] of (degrees) )))\nset [.y v] to (((y) * ([cos v] of (degrees) )) - ((x) * ([sin v] of (degrees) )))\n\ndefine touching player\nif <touching (player v)?> then\n    set [xfizzf v] to (.x)\n    set [yfizzf v] to (.y)\n    set size to (100) %\n    set [ghost v] effect to (0)\n    broadcast (fizzler flash v)\n    if <<(portal blue on) = [1]> or <(portal red on) = [1]>> then\n        start sound [fizzle v]\n        broadcast (fizzler v)\n    end\nend\n\nwhen I receive [switch v]\nif <not <(.on?) = [x]>> then\n    if <(item ([abs v] of (.type) ) of [locks v]) = [0]> then\n        if <(.type) > [0]> then\n            open\n        else\n            close\n        end\n    else\n        if <(.type) > [0]> then\n            close\n        else\n            open\n        end\n    end\nend\n\ndefine open\nif <(.on?) = [0]> then\n    hide\n    set [.show? v] to [0]\n    set [.on? v] to [1]\n    go to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\n    set [ghost v] effect to (100)\n    wait (0) seconds\n    repeat (5)\n        change [ghost v] effect by (-20)\n    end\n    wait (0) seconds\n    set [ghost v] effect to (0)\nend\n\ndefine close\nif <(.on?) = [1]> then\n    repeat (5)\n        change [ghost v] effect by (20)\n    end\n    wait (0) seconds\n    set [.on? v] to [0]\n    hide\n    set [.show? v] to [0]\nend\n\nwhen I start as a clone\npoint in direction (90)\nset [.x v] to (item (last) of [x-spawn v])\nset [.y v] to (item (last) of [y-spawn v])\nset [.type v] to (item (last) of [type-spawn v])\nswitch costume to (item (last) of [info-spawn v])\ndelete (last) of [x-spawn v]\ndelete (last) of [y-spawn v]\ndelete (last) of [type-spawn v]\ndelete (last) of [info-spawn v]\nif <(item ([abs v] of (.type) ) of [locks v]) = [0]> then\n    set [.on? v] to [1]\nelse\n    set [.on? v] to [0]\nend\nif <(.type) < [0]> then\n    if <(.on?) = [1]> then\n        set [.on? v] to [0]\n    else\n        set [.on? v] to [1]\n    end\nend\nif <(.on?) = [1]> then\n    go to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\nelse\n    hide\n    set [.show? v] to [0]\nend\n\nwhen I receive [cycle v]\nif <(.on?) = [1]> then\n    if <<([abs v] of ((Y) + (.y)) ) > [180]> or <([abs v] of ((X) + (.x)) ) > [240]>> then\n        if <(.show?) = [1]> then\n            hide\n            set [.show? v] to [0]\n        end\n    else\n        go to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\n        if <(.show?) = [0]> then\n            show\n            set [.show? v] to [1]\n        end\n        touching player\n    end\nend\n\nwhen I receive [new level v]\ndelete this clone\n\nwhen I receive [fizzler flash v]\nif <<<(.x) > ((Xfizzf) - (50))> and <(.x) < ((Xfizzf) + (50))>> and <<(.y) > ((Yfizzf) - (50))> and <(.y) < ((Yfizzf) + (50))>>> then\n    repeat (4)\n        change [ghost v] effect by (40)\n        change size by (40)\n        wait (0) seconds\n        change [ghost v] effect by (-40)\n        change size by (-40)\n    end\n    set size to (100) %\n    set [ghost v] effect to (0)\nend\n\ndefine track camera\nrepeat (10)\n    if <(.show?) = [1]> then\n        set [xc v] to (.x)\n        set [yc v] to (.y)\n    end\nend\n\ntrack camera\n\n@foreground\n\nwhen I receive [initialization v]\nset volume to (20) %\nhide\nset rotation style [all around v]\npoint in direction (90)\nswitch costume to (size trick v)\nset size to (500) %\nswitch costume to (level)\nwait (0.5) seconds\nshow\n\nwhen I receive [layers v]\nwait until <(cycle) = [70]>\ngo to [front v] layer\nadd [background] to [layers v]\n\nwhen I receive [new level v]\npoint in direction (90)\nswitch costume to (level)\n\nwhen I receive [cycle: position v]\ngo to x: ([floor v] of (X) ) y: ([floor v] of (Y) )\n\ndefine None\nset [save point x v] to (((sx) * ([cos v] of (degrees) )) + ((sy) * ([sin v] of (degrees) )))\nset [save point y v] to (((sy) * ([cos v] of (degrees) )) - ((sx) * ([sin v] of (degrees) )))\nset [x v] to (((x) * ([cos v] of (degrees) )) + ((y) * ([sin v] of (degrees) )))\nset [y v] to (((y) * ([cos v] of (degrees) )) - ((x) * ([sin v] of (degrees) )))\n\nwhen I receive [rotate v]\nturn right (rotate) degrees\ngo to x: ([floor v] of (X) ) y: ([floor v] of (Y) )\n\n@platform\n\nwhen I receive [initialization v]\nset rotation style [all around v]\npoint in direction (90)\nset size to (100) %\nswitch costume to (base on v)\nclear graphic effects\nhide\nset [.show? v] to [x]\nset [.contact v] to [0]\nset [.on? v] to [x]\n\ndefine None\nadd (cycles) to [.track v]\nadd (vx) to [.track v]\nadd (vy) to [.track v]\n\ndefine load track\ndelete (all) of [.track v]\nif <(item (last) of [type-spawn v]) = [1]> then\n    track 1\nelse\n    if <(item (last) of [type-spawn v]) = [2]> then\n        track 2\n    else\n        if <(item (last) of [type-spawn v]) = [3]> then\n            track 3\n        else\n            if <(item (last) of [type-spawn v]) = [4]> then\n                track 4\n            else\n                if <(item (last) of [type-spawn v]) = [5]> then\n                    track 5\n                else\n                    if <(item (last) of [type-spawn v]) = [6]> then\n                        track 6\n                    else\n                        if <(item (last) of [type-spawn v]) = [7]> then\n                            track 7\n                        else\n                            if <(item (last) of [type-spawn v]) = [8]> then\n                                track 8\n                            else\n                                if <(item (last) of [type-spawn v]) = [9]> then\n                                    track 9\n                                else\n                                end\n                            end\n                        end\n                    end\n                end\n            end\n        end\n    end\nend\n\ndefine track 2\npath: Vx= (0) , Vy= (-2) , cycles= (88)\npath: Vx= (0) , Vy= (0) , cycles= (40)\npath: Vx= (0) , Vy= (2) , cycles= (88)\npath: Vx= (0) , Vy= (0) , cycles= (40)\n\ndefine track 4\npath: Vx= (2) , Vy= (0) , cycles= (115)\npath: Vx= (0) , Vy= (0) , cycles= (40)\npath: Vx= (-2) , Vy= (0) , cycles= (115)\npath: Vx= (0) , Vy= (0) , cycles= (40)\n\ndefine track 1\npath: Vx= (2) , Vy= (0) , cycles= (88)\npath: Vx= (0) , Vy= (0) , cycles= (40)\npath: Vx= (-2) , Vy= (0) , cycles= (88)\npath: Vx= (0) , Vy= (0) , cycles= (40)\n\ndefine check if on\nif <(.lock) = [0]> then\n    set [.on? v] to [1]\nelse\n    if <(item ([abs v] of (.lock) ) of [locks v]) = [0]> then\n        set [.on? v] to [0]\n        switch costume to (base off v)\n    else\n        set [.on? v] to [1]\n        switch costume to (base on v)\n    end\n    if <(.lock) < [0]> then\n        if <(.on?) = [1]> then\n            set [.on? v] to [0]\n            switch costume to (base off v)\n        else\n            set [.on? v] to [1]\n            switch costume to (base on v)\n        end\n    end\nend\n\ndefine track 5\npath: Vx= (0) , Vy= (2) , cycles= (42)\npath: Vx= (0) , Vy= (0) , cycles= (40)\npath: Vx= (0) , Vy= (-2) , cycles= (42)\npath: Vx= (0) , Vy= (0) , cycles= (40)\n\nwhen I receive [switch v]\nif <not <(.show?) = [x]>> then\n    check if on\nend\n\nwhen I receive [layers v]\nwait until <(cycle) = [65]>\ngo to [front v] layer\nadd [platform] to [layers v]\n\nwhen I receive [cycle: position v]\nif <not <(.show?) = [x]>> then\n    if <(.on?) = [1]> then\n        get node\n        change [.x v] by (.Vx)\n        change [.y v] by (.Vy)\n    end\n    if <<([abs v] of ((Y) + (.y)) ) > [180]> or <([abs v] of ((X) + (.x)) ) > [240]>> then\n        if <(.show?) = [1]> then\n            hide\n            set [.show? v] to [0]\n        end\n    else\n        if <(.show?) = [0]> then\n            show\n            set [.show? v] to [1]\n        end\n        go to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\n        touching player\n    end\nend\n\nwhen I receive [new level v]\ndelete this clone\n\nwhen I receive [rotate v]\nrotate (rotate) degrees (.x) (.y)\nturn right (rotate) degrees\ngo to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\n\ndefine None\nset [.x v] to (((x) * ([cos v] of (degrees) )) + ((y) * ([sin v] of (degrees) )))\nset [.y v] to (((y) * ([cos v] of (degrees) )) - ((x) * ([sin v] of (degrees) )))\n\nwhen I start as a clone\npoint in direction (90)\nset [.x v] to (item (last) of [x-spawn v])\nset [.y v] to (item (last) of [y-spawn v])\nset [.lock v] to (item (last) of [info-spawn v])\nload track\ndelete (last) of [x-spawn v]\ndelete (last) of [y-spawn v]\ndelete (last) of [type-spawn v]\ndelete (last) of [info-spawn v]\nset [.show? v] to [0]\nset [.count v] to [0]\nset [.max count v] to [-1]\nset [.node v] to [-2]\nset [.contact2 v] to [0]\nget node\ncheck if on\n\ndefine touching player\nif <<<((Xc) - (X)) > (((.x) - (.Vx)) - (27))> and <((Xc) - (X)) < ((.x) + ((27) - (.Vx)))>> and <<((Yc) - (Y)) > ((.y) + (25))> and <((Yc) - (Y)) < ((.y) + (37))>>> then\n    if <(.on?) = [1]> then\n        set [.player vx v] to (.Vx)\n        set [.player vy v] to (.Vy)\n    else\n        set [.player vx v] to [0]\n        set [.player vy v] to [0]\n    end\n    if <(.contact) = [0]> then\n        set [.contact v] to [1]\n        change [vx v] by (.player Vx)\n        change [vy v] by (.player Vy)\n    end\n    Player move\n    set [.contact2 v] to [0]\nelse\n    if <(.contact) = [1]> then\n        change [.contact2 v] by (1)\n        if <(.contact2) > [3]> then\n            change [vx v] by (() - (.player Vx))\n            change [vy v] by (() - (.player Vy))\n            set [.player vx v] to [0]\n            set [.player vy v] to [0]\n            set [.contact v] to [0]\n        else\n            Player move\n        end\n    end\nend\n\ndefine track 6\npath: Vx= (0) , Vy= (0) , cycles= (60)\npath: Vx= (-1) , Vy= (1) , cycles= (100)\npath: Vx= (0) , Vy= (0) , cycles= (20)\npath: Vx= (-2) , Vy= (0) , cycles= (108)\npath: Vx= (0) , Vy= (0) , cycles= (40)\npath: Vx= (2) , Vy= (0) , cycles= (108)\npath: Vx= (0) , Vy= (0) , cycles= (20)\npath: Vx= (1) , Vy= (-1) , cycles= (100)\n\ndefine Player move\nif <<<(.Vx) < [0]> and <(detect left) = [0]>> or <<(.Vx) > [0]> and <(detect right) = [0]>>> then\n    change [xc v] by (.player Vx)\nelse\n    set [.player vx v] to [0]\nend\nchange [yc v] by (.player Vy)\n\ndefine get node\nif <(.count) > (.max count)> then\n    set [.count v] to [0]\n    change [.node v] by (3)\n    if <(.node) > (length of [.track v])> then\n        set [.node v] to [1]\n    end\n    set [.max count v] to (item (.node) of [.track v])\n    set [.vx v] to (item ((.node) + (1)) of [.track v])\n    set [.vy v] to (item ((.node) + (2)) of [.track v])\nelse\n    change [.count v] by (1)\nend\n\ndefine track 7\npath: Vx= (0) , Vy= (0) , cycles= (50)\npath: Vx= (0) , Vy= (5) , cycles= (40)\npath: Vx= (0) , Vy= (0) , cycles= (50)\npath: Vx= (0) , Vy= (-5) , cycles= (40)\n\npath: Vx= (0) , Vy= (0) , cycles= (50)\npath: Vx= (0) , Vy= (2) , cycles= (1)\npath: Vx= (0) , Vy= (6) , cycles= (30)\npath: Vx= (0) , Vy= (2) , cycles= (1)\npath: Vx= (0) , Vy= (0) , cycles= (50)\npath: Vx= (0) , Vy= (-2) , cycles= (1)\npath: Vx= (0) , Vy= (-6) , cycles= (30)\npath: Vx= (0) , Vy= (-2) , cycles= (1)\n\npath: Vx= (0) , Vy= (2) , cycles= (1)\npath: Vx= (0) , Vy= (2) , cycles= (1)\npath: Vx= (0) , Vy= (-2) , cycles= (1)\npath: Vx= (0) , Vy= (-2) , cycles= (1)\n\ndefine track 3\npath: Vx= (0) , Vy= (0) , cycles= (25)\npath: Vx= (0) , Vy= (-3) , cycles= (117)\npath: Vx= (0) , Vy= (0) , cycles= (50)\npath: Vx= (0) , Vy= (3) , cycles= (117)\npath: Vx= (0) , Vy= (0) , cycles= (50)\npath: Vx= (0) , Vy= (3) , cycles= (143)\npath: Vx= (0) , Vy= (0) , cycles= (50)\npath: Vx= (0) , Vy= (-3) , cycles= (143)\npath: Vx= (0) , Vy= (0) , cycles= (25)\n\ndefine track 8\npath: Vx= (0) , Vy= (0) , cycles= (100)\npath: Vx= (0) , Vy= (3) , cycles= (150)\npath: Vx= (0) , Vy= (0) , cycles= (100)\npath: Vx= (0) , Vy= (-3) , cycles= (150)\n\ndefine track 9\npath: Vx= (0) , Vy= (0) , cycles= (75)\npath: Vx= (0) , Vy= (4) , cycles= (70)\npath: Vx= (0) , Vy= (0) , cycles= (75)\npath: Vx= (0) , Vy= (-4) , cycles= (70)\n\n@player\n\nwhen I receive [initialization v]\nhide\nswitch costume to (p v)\nset size to (28) %\npoint in direction (90)\ngo to x: (0) y: (0)\nset rotation style [all around v]\nset volume to (10) %\nwait (0.7) seconds\nshow\n\nwhen I receive [player dead v]\nset [ghost v] effect to (96)\n\nwhen I receive [player alive v]\nclear graphic effects\n\nwhen I receive [layers v]\nwait until <(cycle) = [59]>\ngo to [front v] layer\nadd [player] to [layers v]\n\nwhen I receive [cycle: position v]\ngo to x: (Xc) y: ((Yc) + (crouch))\npoint towards (mouse-pointer v)\n\nwhen I receive [portal gun v]\nif <(portal color) = [b]> then\n    switch costume to (bot+gun b v)\nelse\n    if <(portal color) = [r]> then\n        switch costume to (bot+gun r v)\n    else\n        if <(portal color) = [p]> then\n            switch costume to (p v)\n        end\n    end\nend\n\nwhen I receive [portal v]\nportal sound\nwait (0.1) seconds\nwait until <<not <<touching (portal blue v)?> or <touching (portal red v)?>>> and <(p legs?) = [0]>>\nwait (0.1) seconds\nset [portal? v] to [0]\n\ndefine portal sound\nif <(((Vx) * (Vx)) + ((Vy) * (Vy))) > [100]> then\n    start sound [portalexit v]\nend\n\n@legs\n\nwhen I receive [initialization v]\nhide\nset volume to (4) %\nset rotation style [left-right v]\ngo to x: (0) y: (-7)\nswitch costume to (bot rest v)\nset [.count v] to [1]\nset size to (18) %\nclear graphic effects\nwait (0.7) seconds\nshow\n\ndefine walk backwards\nfootsteps\nswitch costume to (join [mech legs] (.count))\nchange [.count v] by (-1)\nif <(.count) < [1]> then\n    set [.count v] to [13]\nend\n\ndefine walk forwards\nfootsteps\nswitch costume to (join [mech legs] (.count))\nchange [.count v] by (1)\nif <(.count) > [13]> then\n    set [.count v] to [1]\nend\n\ndefine touching portals\nif <<touching (portal blue v)?> or <touching (portal red v)?>> then\n    set [p legs? v] to [1]\nelse\n    set [p legs? v] to [0]\nend\n\nwhen I receive [player alive v]\nclear graphic effects\n\nwhen I receive [player dead v]\nset [ghost v] effect to (80)\n\nwhen I receive [layers v]\nwait until <(cycle) = [58]>\ngo to [front v] layer\nadd [legs] to [layers v]\n\nwhen I receive [cycle: position v]\ngo to x: (Xc) y: (((Yc) - (7)) + (crouch))\n\nwhen I receive [cycle v]\nif <(alive) = [1]> then\n    point towards (mouse-pointer v)\n    if <(crouch) = [0]> then\n        if <(detect down) = [1]> then\n            if <(Vx) > [0.5]> then\n                if <(direction) > [0]> then\n                    walk backwards\n                else\n                    walk forwards\n                end\n            else\n                if <(Vx) < [-0.5]> then\n                    if <(direction) > [0]> then\n                        walk forwards\n                    else\n                        walk backwards\n                    end\n                else\n                    if <not <(costume [number v]) = [1]>> then\n                        switch costume to (mech legs rest v)\n                        set [.count v] to [0]\n                    end\n                end\n            end\n        else\n            if <not <(costume [number v]) = [2]>> then\n                switch costume to (mech legs jump v)\n            end\n        end\n    else\n        if <(crouch) = [-11]> then\n            if <not <(costume [number v]) = [4]>> then\n                switch costume to (mech legs crouch v)\n            end\n        else\n            switch costume to (mech legs crouch2 v)\n        end\n    end\n    touching portals\nend\n\ndefine footsteps\nif <<(.count) = [1]> or <(.count) = [7]>> then\n    start sound (join [fs_fm_black_tile_0] (pick random (1) to (9)))\nend\n\n@bullet\n\nwhen I receive [initialization v]\nset rotation style [don't rotate v]\nset volume to (20) %\nswitch costume to (size trick v)\nset size to (2) %\nclear graphic effects\nset [.show? v] to [0]\nhide\nset [.timer v] to [x]\nset [.portal v] to [0]\nset [.temp v] to [0]\ndelete (all) of [b x-spawn v]\ndelete (all) of [b y-spawn v]\ndelete (all) of [b angle-spawn v]\ndelete (all) of [b speed-spawn v]\n\ndefine delete if slow\nif <<((.Vx) * (.Vx)) < [3]> and <((.Vy) * (.Vy)) < [3]>> then\n    delete this clone\nend\n\ndefine collision w player\nif <<touching (player v)?> or <touching (legs v)?>> then\n    if <(alive) = [1]> then\n        set [.temp v] to (() - ([sqrt v] of ((((Vx) - (.Vx)) * ((Vx) - (.Vx))) + (((Vy) - (.Vy)) * ((Vy) - (.Vy)))) ))\n        a2tan (([y position v] of [player v]) - (y position)) (([x position v] of [player v]) - (x position))\n        change [vx v] by ((-0.5) * (.Vx))\n        change [vy v] by ((-0.5) * (.Vy))\n        change [health v] by (-34)\n        broadcast (damage v)\n        set volume to ((-20) * (.temp)) %\n        start sound (join [pin] (pick random (1) to (4)))\n        delete this clone\n    end\nend\n\ndefine collision w NPC\nif <touching (npc1 v)?> then\n    set [.timer v] to [-10]\n    set [.vx v] to [0]\n    set [.vy v] to [0]\n    set size to ((30) * (size)) %\n    switch costume to (collision v)\nend\n\ndefine None\nif <(x1) > [0]> then\n    set [angle v] to ([atan v] of ((y1) / (x1)) )\nelse\n    if <<<(y1) > [0]> or <(y1) = [0]>> and <(x1) < [0]>> then\n        set [angle v] to (([atan v] of ((y1) / (x1)) ) + (180))\n    else\n        if <<(y1) < [0]> and <(x1) < [0]>> then\n            set [angle v] to (([atan v] of ((y1) / (x1)) ) - (180))\n        else\n            if <<(y1) > [0]> and <(x1) = [0]>> then\n                set [angle v] to [90]\n            else\n                if <<(y1) < [0]> and <(x1) = [0]>> then\n                    set [angle v] to [-90]\n                else\n                    if <<(y1) = [0]> and <(x1) = [0]>> then\n                        set [angle v] to [0]\n                    end\n                end\n            end\n        end\n    end\nend\n\nwhen I start as a clone\nswitch costume to (b v)\nset [.timer v] to [0]\nset [.vx v] to ((item (last) of [b speed-spawn v]) * ([sin v] of (item (last) of [b angle-spawn v]) ))\nset [.vy v] to ((item (last) of [b speed-spawn v]) * ([cos v] of (item (last) of [b angle-spawn v]) ))\nset [.x v] to ((item (last) of [b x-spawn v]) + (.Vx))\nset [.y v] to ((item (last) of [b y-spawn v]) + ((.Vy) + (G)))\ndelete (last) of [b x-spawn v]\ndelete (last) of [b y-spawn v]\ndelete (last) of [b speed-spawn v]\ndelete (last) of [b angle-spawn v]\n\nwhen I receive [layers v]\nwait until <(cycle) = [49]>\ngo to [front v] layer\nadd [bullet] to [layers v]\n\ndefine collision with map, ...\nif <touching (map v)?> then\n    delete this clone\nelse\n    change x by (.Vx)\n    if <<touching (map v)?> or <<touching (cube v)?> or <<touching (door v)?> or <touching (turret v)?>>>> then\n        set [.vx v] to (() - (.Vx))\n        set [.vx v] to ((0.4) * (.Vx))\n        set [.vy v] to ((0.4) * (.Vy))\n        delete if slow\n        change x by (.Vx)\n    else\n        change x by (() - (.Vx))\n    end\n    change y by (.Vy)\n    if <<touching (map v)?> or <<touching (cube v)?> or <<touching (door v)?> or <touching (turret v)?>>>> then\n        set [.vy v] to (() - (.Vy))\n        set [.vx v] to ((0.4) * (.Vx))\n        set [.vy v] to ((0.4) * (.Vy))\n        delete if slow\n        change y by (.Vy)\n    else\n        change y by (() - (.Vy))\n    end\nend\n\nwhen I receive [new level v]\ndelete this clone\n\ndefine collision with portals\nif <(.portal) = [1]> then\n    if <not <<touching (portal blue v)?> or <touching (portal red v)?>>> then\n        set [.portal v] to [0]\n    end\nelse\n    if <<touching (portal blue v)?> and <(portal red on) = [1]>> then\n        set [.portal v] to [1]\n        exiting the portal with a direction = ([.dir v] of [portal red v])\n        set [.x v] to ([.x v] of [portal red v])\n        set [.y v] to ([.y v] of [portal red v])\n    else\n        if <<touching (portal red v)?> and <(portal blue on) = [1]>> then\n            set [.portal v] to [1]\n            exiting the portal with a direction = ([.dir v] of [portal blue v])\n            set [.x v] to ([.x v] of [portal blue v])\n            set [.y v] to ([.y v] of [portal blue v])\n        else\n            collision with map, ...\n        end\n    end\nend\n\nset [.temp v] to (() - ([sqrt v] of ((((Vx) - (.Vx)) * ((Vx) - (.Vx))) + (((Vy) - (.Vy)) * ((Vy) - (.Vy)))) ))\na2tan (([y position v] of [player v]) - (y position)) (([x position v] of [player v]) - (x position))\nchange [vx v] by (((0.5) * (.temp)) * ([sin v] of (angle) ))\nchange [vy v] by (((0.5) * (.temp)) * ([cos v] of (angle) ))\nchange [.vx v] by (((1) * (.temp)) * ([sin v] of ((angle) + (180)) ))\nchange [.vy v] by (((1) * (.temp)) * ([cos v] of ((angle) + (180)) ))\nchange [.x v] by (.Vx)\nchange [.y v] by (.Vy)\nchange [health v] by (-34)\nbroadcast (damage v)\nset volume to ((-20) * (.temp)) %\nstart sound (join [pin] (pick random (1) to (4)))\ndelete this clone\n\nwhen I receive [cycle v]\nif <not <(.timer) = [x]>> then\n    change [.timer v] by (1)\n    if <(.timer) > [100]> then\n        delete this clone\n    end\n    change [.vy v] by (G)\n    change [.x v] by (.Vx)\n    change [.y v] by (.Vy)\n    if <<([abs v] of ((Y) + (.y)) ) > [180]> or <([abs v] of ((X) + (.x)) ) > [240]>> then\n        if <(.show?) = [1]> then\n            hide\n            set [.show? v] to [0]\n        end\n    else\n        if <(.show?) = [0]> then\n            show\n            set [.show? v] to [1]\n        end\n        go to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\n        collision with portals\n        collision w player\n    end\nend\n\nchange [.x v] by (.Vx)\nchange [.y v] by (.Vy)\ngo to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\ncollision with portals\ncollision w player\n\ndefine None\nif <(dir) = [-90]> then\n    set [.vx v] to (() - ([sqrt v] of (((.Vx) * (.Vx)) + ((.Vy) * (.Vy))) ))\n    set [.vy v] to [0]\nelse\n    if <(dir) = [90]> then\n        set [.vx v] to ([sqrt v] of (((.Vx) * (.Vx)) + ((.Vy) * (.Vy))) )\n        set [.vy v] to [0]\n    else\n        if <(dir) = [180]> then\n            set [.vy v] to (() - ([sqrt v] of (((.Vx) * (.Vx)) + ((.Vy) * (.Vy))) ))\n            set [.vx v] to [0]\n        else\n            if <(dir) = [0]> then\n                set [.vy v] to ([sqrt v] of (((.Vx) * (.Vx)) + ((.Vy) * (.Vy))) )\n                set [.vx v] to [0]\n            end\n        end\n    end\nend\n\n@turret\n\ndefine calculate angle and fire: speed= (gbs) abs(gravity)= (g) dx= (x) dy= (y)\nset [a v] to ((((gbs) * (gbs)) * ((gbs) * (gbs))) - ((g) * (((g) * ((x) * (x))) + (((2) * (y)) * ((gbs) * (gbs))))))\nif <<not <((g) * (x)) = [0]>> and <(A) > [0]>> then\n    set [a v] to ([atan v] of (((((gbs) * (gbs)) - ([sqrt v] of (A) )) / ((g) * (x))) * (-1)) )\n    if <(x) > [0]> then\n        change [a v] by (90)\n    else\n        change [a v] by (-90)\n    end\n    if <<(A) > (.range)> and <(A) < ((.range) + (90))>> then\n        Fire from x= (.x) , y= (.y) , angle= (A) , speed= (gbs)\n        mode = active\n    else\n        set [a v] to ((A) mod (360))\n        if <<(A) > (.range)> and <(A) < ((.range) + (90))>> then\n            Fire from x= (.x) , y= (.y) , angle= (A) , speed= (gbs)\n            mode = active\n        else\n            mode = searching\n        end\n    end\nelse\n    mode = searching\nend\n\ndefine exiting the portal with a direction = (dir)\nif <(dir) = [-90]> then\n    set [.vx v] to ((-4) - ([sqrt v] of (((.Vx) * (.Vx)) + ((.Vy) * (.Vy))) ))\n    set [.vy v] to [2]\nelse\n    if <(dir) = [90]> then\n        set [.vx v] to ((4) + ([sqrt v] of (((.Vx) * (.Vx)) + ((.Vy) * (.Vy))) ))\n        set [.vy v] to [2]\n    else\n        if <(dir) = [180]> then\n            set [.vy v] to ((-4) - ([sqrt v] of (((.Vx) * (.Vx)) + ((.Vy) * (.Vy))) ))\n            set [.vx v] to [0]\n        else\n            if <(dir) = [0]> then\n                set [.vy v] to ((4) + ([sqrt v] of (((.Vx) * (.Vx)) + ((.Vy) * (.Vy))) ))\n                set [.vx v] to [0]\n            end\n        end\n    end\nend\nif <(.state) = [alive]> then\n    set [.state v] to [2]\n    mode = death\nend\n\ndefine a2tan (x1) (y1)\nif <(x1) > [0]> then\n    set [.angle v] to ([atan v] of ((y1) / (x1)) )\nelse\n    if <<<(y1) > [0]> or <(y1) = [0]>> and <(x1) < [0]>> then\n        set [.angle v] to (([atan v] of ((y1) / (x1)) ) + (180))\n    else\n        if <<(y1) < [0]> and <(x1) < [0]>> then\n            set [.angle v] to (([atan v] of ((y1) / (x1)) ) - (180))\n        else\n            if <<(y1) > [0]> and <(x1) = [0]>> then\n                set [.angle v] to [90]\n            else\n                if <<(y1) < [0]> and <(x1) = [0]>> then\n                    set [.angle v] to [-90]\n                else\n                    if <<(y1) = [0]> and <(x1) = [0]>> then\n                        set [.angle v] to [0]\n                    end\n                end\n            end\n        end\n    end\nend\n\ndefine move out of map\nif <touching (map v)?> then\n    change y by (2)\n    change [.y v] by (2)\n    if <touching (map v)?> then\n        change y by (2)\n        change [.y v] by (2)\n        if <touching (map v)?> then\n            change y by (2)\n            change [.y v] by (2)\n            if <touching (map v)?> then\n                change y by (2)\n                change [.y v] by (2)\n            end\n        end\n    end\nend\n\ndefine mode = searching\nif <not <(.mode) = [s]>> then\n    set [.mode v] to [s]\n    if <(talking) = [0]> then\n        if <not <(pick random (1) to (3)) = [1]>> then\n            set [sound file v] to (join [Tsearch] (pick random (1) to (5)))\n            broadcast (play sound v)\n        end\n    end\nend\n\nwhen I receive [new level v]\ndelete this clone\n\nwhen I receive [layers v]\nwait until <(cycle) = [48]>\ngo to [front v] layer\nadd [turret] to [layers v]\n\ndefine Fire from x= (x) , y= (y) , angle= (a) , speed= (s)\nstart sound [Portal2_sfx_turret_machine_gun.mp3 v]\nadd (x) to [b x-spawn v]\nadd ((y) + (3)) to [b y-spawn v]\nadd (a) to [b angle-spawn v]\nadd (s) to [b speed-spawn v]\ncreate clone of (bullet v)\n\ndefine touching portals\nif <(portal?) = [0]> then\n    if <touching (portal blue v)?> then\n        if <<(.portal) = [0]> and <(portal red on) = [1]>> then\n            exiting the portal with a direction = ([.dir v] of [portal red v])\n            set [.x v] to ([.x v] of [portal red v])\n            set [.y v] to ([.y v] of [portal red v])\n            set [.portal v] to [1]\n        end\n    else\n        if <touching (portal red v)?> then\n            if <<(.portal) = [0]> and <(portal blue on) = [1]>> then\n                set [.portal v] to [1]\n                exiting the portal with a direction = ([.dir v] of [portal blue v])\n                set [.x v] to ([.x v] of [portal blue v])\n                set [.y v] to ([.y v] of [portal blue v])\n            end\n        else\n            if <(.portal) = [1]> then\n                set [.portal v] to [0]\n            end\n        end\n    end\nend\n\ndefine blast\nchange [.state v] by (1)\nif <(.state) = [-1]> then\n    delete this clone\nend\nif <<([abs v] of ((Y) + (.y)) ) > [180]> or <([abs v] of ((X) + (.x)) ) > [240]>> then\n    if <(.show?) = [1]> then\n        hide\n        set [.show? v] to [0]\n    end\nelse\n    if <(.show?) = [0]> then\n        show\n        set [.show? v] to [1]\n    end\n    go to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\nend\n\ndefine player max speed (max speed)\nif <(Vx) > (max speed)> then\n    set [vx v] to (max speed)\nelse\n    if <(Vx) < (() - (max speed))> then\n        set [vx v] to (() - (max speed))\n    end\nend\nif <(Vy) > (max speed)> then\n    set [vy v] to (max speed)\nelse\n    if <(Vy) < (() - (max speed))> then\n        set [vy v] to (() - (max speed))\n    end\nend\n\ndefine rotate (degrees) degrees (x) (y)\nset [.x v] to (((x) * ([cos v] of (degrees) )) + ((y) * ([sin v] of (degrees) )))\nset [.y v] to (((y) * ([cos v] of (degrees) )) - ((x) * ([sin v] of (degrees) )))\n\nwhen I receive [initialization v]\nset rotation style [all around v]\npoint in direction (90)\nset volume to (70) %\nset size to (20) %\nswitch costume to (base v)\nclear graphic effects\nhide\nset [.show? v] to [0]\nset [.state v] to [X]\nset [.spin v] to ((pick random (1) to (-1)) * (pick random (3) to (15)))\nset [.vx v] to [0]\nset [.vy v] to [0]\nset [.portal v] to [0]\nset [talking v] to [0]\nset [.mode v] to [s]\n\nwhen I start as a clone\npoint in direction (90)\nset [.state v] to [alive]\nset [.x v] to (item (last) of [x-spawn v])\nset [.y v] to (item (last) of [y-spawn v])\nset [.range v] to ((item (last) of [type-spawn v]) - (45))\nif <<(.range) > [0]> and <(.range) < [180]>> then\n    switch costume to (turretr v)\nelse\n    switch costume to (turretl v)\nend\ndelete (last) of [x-spawn v]\ndelete (last) of [y-spawn v]\ndelete (last) of [type-spawn v]\nswitch costume to (turret v)\n\ndefine should I fire?\nif <((cycle) mod (7)) = [0]> then\n    if <<(alive) = [1]> and <([abs v] of (((X) - (Xc)) + (.x)) ) < [245]>> then\n        calculate angle and fire: speed= (14) abs(gravity)= ((-1) * (G)) dx= (((-5) * (Vx)) - (((X) - (Xc)) + (.x))) dy= (((-5) * (Vy)) - (((Y) - (Yc)) + ((.y) + (5))))\n    end\nend\n\nwhen I receive [rotate v]\nrotate (rotate) degrees (.x) (.y)\nturn right (rotate) degrees\ngo to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\n\ndefine normal\nif <<([abs v] of ((Y) + (.y)) ) > [180]> or <([abs v] of ((X) + (.x)) ) > [240]>> then\n    if <(.show?) = [1]> then\n        hide\n        mode = searching\n        set [.show? v] to [0]\n    end\nelse\n    if <(.show?) = [0]> then\n        show\n        set [.show? v] to [1]\n    end\n    go to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\n    touching player\n    player pick up\n    touching portals\n    touching fizzler\n    touching bullet\nend\nshould I fire?\n\ndefine mode = death\nif <(talking) = [0]> then\n    death fix\n    if <not <(deathfix) = [1]>> then\n        set [sound file v] to (join [Tdeath] (pick random (1) to (4)))\n        broadcast (play sound v)\n        wait (1) seconds\n        delete this clone\n    end\nend\n\ndefine mode = active\nif <not <(.mode) = [a]>> then\n    set [.mode v] to [a]\n    if <(talking) = [0]> then\n        if <not <(pick random (1) to (3)) = [1]>> then\n            set [sound file v] to (join [Tactive] (pick random (1) to (3)))\n            broadcast (play sound v)\n        end\n    end\nend\n\ndefine mode = shot at\nif <(talking) = [0]> then\n    set [sound file v] to [Tnoshoot1]\n    broadcast (play sound v)\nend\n\ndefine bounce map\nchange x by (.Vx)\nif <touching (map v)?> then\n    set [.vx v] to ((-0.7) * (.Vx))\n    change x by (.Vx)\n    set [.spin v] to ((pick random (1) to (-1)) * (pick random (3) to (15)))\nelse\n    change x by (() - (.Vx))\nend\nchange y by (.Vy)\nif <touching (map v)?> then\n    set [.vy v] to (((-0.7) * (.Vy)) + (1))\n    change y by (.Vy)\n    set [.spin v] to ((pick random (1) to (-1)) * (pick random (3) to (15)))\nelse\n    change y by (() - (.Vy))\nend\n\ndefine speed control\nset [.vx v] to ((.Vx) * (0.95))\nif <(.Vx) > [8]> then\n    set [.vx v] to [8]\nelse\n    if <(.Vx) < [-8]> then\n        set [.vx v] to [-8]\n    end\nend\nset [.vy v] to ((.Vy) * (0.95))\nif <(.Vy) > [8]> then\n    set [.vy v] to [8]\nelse\n    if <(.Vy) < [-8]> then\n        set [.vy v] to [-8]\n    end\nend\n\ndefine falling\nif <(.portal) = [0]> then\n    if <<touching (map v)?> and <not <<touching (portal blue v)?> or <touching (portal red v)?>>>> then\n        move out of map\n    else\n        turn right (.spin) degrees\n        change [.vy v] by (G)\n        bounce map\n        change [.x v] by (.Vx)\n        change [.y v] by (.Vy)\n    end\nelse\n    change [.x v] by (.Vx)\n    change [.y v] by (.Vy)\nend\n\ndefine touching bullet\nif <touching (bullet v)?> then\n    if <(.portal) = [0]> then\n        set [.vx v] to (pick random (pick random (-4) to (-2)) to (pick random (2) to (4)))\n        set [.vy v] to (pick random (2) to (4))\n        if <(.state) = [alive]> then\n            set [.state v] to [40]\n            mode = shot at\n        end\n        set [.spin v] to [2]\n    end\nend\n\ndefine touching fizzler\nif <touching (fizzler v)?> then\n    set [.state v] to [91]\n    set [xfizzf v] to (.x)\n    set [yfizzf v] to (.y)\n    broadcast (fizzler flash v)\nend\n\ndefine player holding\nif <(alive) = [1]> then\n    show\n    go to x: (((20) * ([cos v] of (([direction v] of [player v]) - (90)) )) + (Xc)) y: ((((20) * ([sin v] of (([direction v] of [player v]) + (90)) )) + (Yc)) + (crouch))\n    set [.x v] to ([floor v] of ((x position) - (X)) )\n    set [.y v] to ([floor v] of ((y position) - (Y)) )\n    touching fizzler\n    player drop\nelse\n    set [.state v] to [2]\nend\n\ndefine death\nif <(.state) > [0]> then\n    change [.state v] by (1)\n    speed control\n    falling\n    if <<([abs v] of ((Y) + (.y)) ) > [180]> or <([abs v] of ((X) + (.x)) ) > [240]>> then\n        if <(.show?) = [1]> then\n            hide\n            set [.show? v] to [0]\n        end\n    else\n        if <(.show?) = [0]> then\n            show\n            set [.show? v] to [1]\n        end\n        go to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\n        touching player\n        touching portals\n        touching fizzler\n        if <((cycle) mod (10)) = [0]> then\n            if <(costume [number v]) = [1]> then\n                Fire from x= (.x) , y= (.y) , angle= (direction) , speed= (7)\n            else\n                Fire from x= (.x) , y= (.y) , angle= ((direction) - (180)) , speed= (7)\n            end\n        end\n    end\n    if <(.state) > [90]> then\n        broadcast (kill turret v)\n        switch costume to (blast v)\n    end\n    player pick up\nelse\n    blast\nend\n\ndefine player pick up\nif <<key (s v) pressed?> and <(distance to [player v]) < [50]>> then\n    if <(cycle fire CD) < (cycle)> then\n        if <(alive) = [1]> then\n            set [cycle fire cd v] to ((cycle) + (15))\n            set [.state v] to [hold]\n            set [vx v] to ((0.5) * ((Vx) + (.Vy)))\n            set [vy v] to ((0.5) * ((Vy) + (.Vx)))\n        end\n    end\nend\n\ndefine player drop\nif <key (s v) pressed?> then\n    change size by (10)\n    if <not <<touching (map v)?> or <touching (door v)?>>> then\n        if <(cycle fire CD) < (cycle)> then\n            set [cycle fire cd v] to ((cycle) + (15))\n            set [.state v] to [2]\n        end\n    end\n    change size by (-10)\nend\n\ndefine touching player\nif <<(distance to [player v]) < [25]> or <touching (legs v)?>> then\n    if <(alive) = [1]> then\n        if <(.state) = [alive]> then\n            set [.state v] to [2]\n            mode = death\n        end\n        calculate collision with player (Vx) (Vy) (4)\n        set [.spin v] to ((pick random (1) to (-1)) * (pick random (3) to (15)))\n        falling\n    end\nend\n\ndefine calculate collision with player (p vx) (p vy) (knock)\na2tan ((x position) - ([x position v] of [player v])) ((y position) - (([y position v] of [player v]) - (7)))\nset [vx v] to ((.Vx) + ((knock) * ([cos v] of (.angle) )))\nset [vy v] to ((.Vy) + ((knock) * ([sin v] of (.angle) )))\nplayer max speed (5)\nset [.vx v] to ((() - (p vx)) + ((knock) * ([cos v] of (.angle) )))\nset [.vy v] to ((() - (p vy)) + ((knock) * ([sin v] of (.angle) )))\n\nwhen I receive [cycle v]\nif <not <(.state) = [X]>> then\n    if <(.state) = [hold]> then\n        player holding\n    else\n        if <(.state) = [alive]> then\n            normal\n        else\n            set [talking v] to [0]\n            death\n        end\n    end\nend\n\nsay [dead]\n\nsay [Hello!] for (2) seconds\n\ndefine death fix\nset [deathfix v] to (pick random (1) to (4))\n\nset [sound file v] to (join [Tdeath] (pick random (1) to (4)))\nbroadcast (play sound v)\nwait (1) seconds\ndelete this clone\n\nset [sound file v] to (join [Tdeath] (pick random (1) to (4)))\nbroadcast (play sound v)\n\nwait (1) seconds\n\ndelete this clone\n\nblast\n\nwhen I receive [kill turret v]\nif <(costume [name v]) = [blast]> then\n    set [sound file v] to (join [Tdeath] (pick random (1) to (4)))\n    broadcast (play sound v)\n    if <(.show?) = [1]> then\n        set volume to (70) %\n    else\n        set volume to (25) %\n    end\n    start sound [short boom v]\n    set [.state v] to [-6]\n    wait (1) seconds\n    delete this clone\nend\n\nwait (1) seconds\ndelete this clone\n\nset [.state v] to [89]\nwait (1) seconds\n\n@items\n\nwhen I receive [initialization v]\nset rotation style [all around v]\npoint in direction (90)\nset volume to (20) %\nset [.type v] to [0]\nset [.timer v] to [0]\nset size to (80) %\nswitch costume to (size trick v)\nclear graphic effects\nhide\nset [.show? v] to [0]\n\nwhen I start as a clone\nsetup clone\n\ndefine setup clone\npoint in direction (90)\nset [.x v] to (item (last) of [x-spawn v])\nset [.y v] to (item (last) of [y-spawn v])\nset [.type v] to (item (last) of [type-spawn v])\ndelete (last) of [x-spawn v]\ndelete (last) of [y-spawn v]\ndelete (last) of [type-spawn v]\nswitch costume to (.type)\nif <<<(.type) = [2]> or <(.type) = [3]>> and <(show settings?) = [0]>> then\n    set [ghost v] effect to (100)\nelse\n    if <(.type) = [1]> then\n        forever\n            change [ghost v] effect by ((5) * ([sin v] of ((300) * (timer)) ))\n        end\n    end\nend\n\ndefine touching player\nif <<touching (player v)?> or <touching (legs v)?>> then\n    if <(alive) = [1]> then\n        type selection\n    end\nend\n\nwhen I receive [layers v]\nwait until <(cycle) = [47]>\ngo to [front v] layer\nadd [items] to [layers v]\n\nwhen I receive [cycle v]\nif <not <(.type) = [0]>> then\n    if <<([abs v] of ((Y) + (.y)) ) > [180]> or <([abs v] of ((X) + (.x)) ) > [240]>> then\n        if <(.show?) = [1]> then\n            hide\n            set [.show? v] to [0]\n        end\n    else\n        go to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\n        if <(.show?) = [0]> then\n            show\n            set [.show? v] to [1]\n        end\n        touching player\n    end\nend\n\nwhen I receive [rotate v]\nrotate (rotate) degrees (.x) (.y)\nturn right (rotate) degrees\ngo to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\n\nwhen I receive [new level v]\ndelete this clone\n\nwhen I receive [display v]\nif <<(.type) = [2]> or <(.type) = [3]>> then\n    if <(show settings?) = [1]> then\n        set [ghost v] effect to (50)\n    else\n        set [ghost v] effect to (100)\n    end\nend\n\ndefine None\nset [.x v] to (((x) * ([cos v] of (degrees) )) + ((y) * ([sin v] of (degrees) )))\nset [.y v] to (((y) * ([cos v] of (degrees) )) - ((x) * ([sin v] of (degrees) )))\n\ndefine None\nreplace item (1) of [locks v] with (lock value)\nbroadcast (switch v)\nset [save point x v] to (X)\nset [save point y v] to (Y)\ndelete this clone\n\ndefine P gun\nset [p gun? v] to [1]\nset [portal color v] to [b]\nstart sound [portalgun_powerup1 v]\nstart sound [GLaDOS_01_part1_get_portal_gun v]\nbroadcast (portal gun v)\nset [portal blue on v] to [0]\nset [portal red on v] to [0]\nset [save point x v] to (X)\nset [save point y v] to (Y)\ndelete this clone\n\ndefine type selection\nif <(.type) = [1]> then\n    P gun\nelse\n    if <(.type) = [2]> then\n        switch trigger (0)\n    else\n        if <(.type) = [3]> then\n            switch trigger (1)\n        else\n        end\n    end\nend\n\ndefine player death\nset [alive v] to [0]\nbroadcast (player dead v)\n\nplayer death\n\n@exit\n\nwhen I receive [initialization v]\nset rotation style [all around v]\nset size to (88) %\nswitch costume to (25 v)\nclear graphic effects\nhide\nset volume to (50) %\nset [.show? v] to [0]\nset [.open? v] to [0]\n\nwhen I receive [cycle v]\nif <<([abs v] of ((Y) + (.y)) ) > [180]> or <([abs v] of ((X) + (.x)) ) > [240]>> then\n    if <(.show?) = [1]> then\n        hide\n        set [.show? v] to [0]\n    end\nelse\n    go to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\n    if <(.show?) = [0]> then\n        show\n        set [.show? v] to [1]\n    end\n    touching player\n    animate\nend\n\nwhen I receive [layers v]\nwait until <(cycle) = [46]>\ngo to [front v] layer\nadd [exit] to [layers v]\n\nwhen I receive [new level v]\npoint in direction (90)\nswitch costume to (25 v)\nhide\nset [.show? v] to [0]\nset [.open? v] to [0]\nset [.x v] to (item (level) of [.x pos v])\nset [.y v] to (item (level) of [.y pos v])\nchange [.y v] by (-8)\n\ndefine animate\nif <(.open?) = [1]> then\n    switch costume to ((costume [number v]) - (1))\n    if <(costume [number v]) = [12]> then\n        start sound [door_open v]\n    end\n    if <(costume [number v]) = [1]> then\n        set [.open? v] to [-1]\n        add [next level] to [graphics type v]\n        create clone of (graphics v)\n    end\nend\n\ndefine touching player\nif <touching (player v)?> then\n    if <(alive) = [1]> then\n        if <(.open?) = [0]> then\n            set [rotate v] to [no]\n            set [.open? v] to [1]\n        end\n    end\nend\n\nwhen I receive [rotate v]\nrotate (rotate) degrees (.x) (.y)\nturn right (rotate) degrees\ngo to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\n\ndefine None\nset [.x v] to (((x) * ([cos v] of (degrees) )) + ((y) * ([sin v] of (degrees) )))\nset [.y v] to (((y) * ([cos v] of (degrees) )) - ((x) * ([sin v] of (degrees) )))\n\ndelete (all) of [.x pos v]\ndelete (all) of [.y pos v]\nset [.x v] to [-1054]\nadd (.x) to [.x pos v]\nset [.y v] to [-213]\nadd (.y) to [.y pos v]\n\ndelete (all) of [.x pos v]\nadd [1150] to [.x pos v]\nadd [1069] to [.x pos v]\nadd [247] to [.x pos v]\nadd [48] to [.x pos v]\nadd [1130] to [.x pos v]\nadd [376] to [.x pos v]\nadd [763] to [.x pos v]\nadd [93] to [.x pos v]\nadd [-339] to [.x pos v]\nadd [959] to [.x pos v]\nwait (0) seconds\nadd [400] to [.x pos v]\nadd [-1029] to [.x pos v]\nadd [-116] to [.x pos v]\nadd [-106] to [.x pos v]\nadd [173] to [.x pos v]\nadd [334] to [.x pos v]\nadd [-87] to [.x pos v]\n\ndelete (all) of [.y pos v]\nadd [-213] to [.y pos v]\nadd [-213] to [.y pos v]\nadd [-64] to [.y pos v]\nadd [12] to [.y pos v]\nadd [-248] to [.y pos v]\nadd [-112] to [.y pos v]\nadd [-67] to [.y pos v]\nadd [-112] to [.y pos v]\nadd [112] to [.y pos v]\nadd [-230] to [.y pos v]\nwait (0) seconds\nadd [-288] to [.y pos v]\nadd [-106] to [.y pos v]\nadd [494] to [.y pos v]\nadd [289] to [.y pos v]\nadd [-213] to [.y pos v]\nadd [-112] to [.y pos v]\nadd [90] to [.y pos v]\n\n@door\n\nwhen I receive [initialization v]\nset volume to (20) %\nset rotation style [all around v]\npoint in direction (90)\ngo to x: (0) y: (0)\nswitch costume to (size trick v)\nset size to (500) %\nclear graphic effects\nhide\nset [.show? v] to [0]\nset [.on? v] to [x]\nset [.type v] to [0]\nset [.opening? v] to [0]\n\nwhen I receive [layers v]\nwait until <(cycle) = [44]>\ngo to [front v] layer\nadd [door] to [layers v]\n\nwhen I receive [cycle v]\nif <(.on?) = [1]> then\n    if <<([abs v] of ((Y) + (.y)) ) > [180]> or <([abs v] of ((X) + (.x)) ) > [240]>> then\n        if <(.show?) = [1]> then\n            hide\n            set [.show? v] to [0]\n        end\n    else\n        go to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\n        if <(.show?) = [0]> then\n            show\n            set [.show? v] to [1]\n        end\n    end\nend\n\ndefine close door\nif <(.on?) = [0]> then\n    hide\n    set [.show? v] to [0]\n    set [.on? v] to [1]\n    go to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\n    start sound [door_close v]\n    switch costume to (door7 open v)\n    wait (0) seconds\n    repeat (5)\n        switch costume to ((costume [number v]) - (1))\n    end\n    wait (0) seconds\n    switch costume to (door1 closed v)\nend\n\ndefine open door\nif <(.on?) = [1]> then\n    start sound [door_open v]\n    switch costume to (door1 closed v)\n    wait (0) seconds\n    repeat (5)\n        next costume\n    end\n    wait (0) seconds\n    switch costume to (door7 open v)\n    set [.on? v] to [0]\n    hide\n    set [.show? v] to [0]\nend\n\nwhen I receive [switch v]\nif <not <(.on?) = [x]>> then\n    if <(item ([abs v] of (.type) ) of [locks v]) = [0]> then\n        if <(.type) > [0]> then\n            open door\n        else\n            close door\n        end\n    else\n        if <(.type) > [0]> then\n            close door\n        else\n            open door\n        end\n    end\nend\n\nwhen I start as a clone\nif <(item (last) of [info-spawn v]) = [0]> then\n    point in direction (0)\nelse\n    if <(item (last) of [info-spawn v]) = [180]> then\n        point in direction (180)\n    else\n        if <(item (last) of [info-spawn v]) = [-90]> then\n            point in direction (-90)\n        else\n            point in direction (90)\n        end\n    end\nend\nset [.x v] to (item (last) of [x-spawn v])\nset [.y v] to ((item (last) of [y-spawn v]) + (2))\nset [.type v] to (item (last) of [type-spawn v])\ndelete (last) of [x-spawn v]\ndelete (last) of [y-spawn v]\ndelete (last) of [type-spawn v]\ndelete (last) of [info-spawn v]\nif <(item ([abs v] of (.type) ) of [locks v]) = [0]> then\n    if <(.type) > [0]> then\n        switch costume to (door7 open v)\n        set [.on? v] to [0]\n        hide\n        set [.show? v] to [0]\n    else\n        switch costume to (door1 closed v)\n        set [.on? v] to [1]\n        hide\n        set [.show? v] to [0]\n    end\nelse\n    if <(.type) > [0]> then\n        switch costume to (door1 closed v)\n        set [.on? v] to [1]\n        hide\n        set [.show? v] to [0]\n    else\n        switch costume to (door7 open v)\n        set [.on? v] to [0]\n        hide\n        set [.show? v] to [0]\n    end\nend\n\ndefine None\nset [.x v] to (((x) * ([cos v] of (degrees) )) + ((y) * ([sin v] of (degrees) )))\nset [.y v] to (((y) * ([cos v] of (degrees) )) - ((x) * ([sin v] of (degrees) )))\n\nwhen I receive [rotate v]\nrotate (rotate) degrees (.x) (.y)\nturn right (rotate) degrees\ngo to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\n\nwhen I receive [new level v]\ndelete this clone\n\n@switch\n\nwhen I receive [initialization v]\ngo to x: (0) y: (0)\nset rotation style [all around v]\npoint in direction (90)\nswitch costume to (size trick v)\nset size to (90) %\nclear graphic effects\nhide\nset volume to (20) %\nset [.show? v] to [0]\nset [.on? v] to [x]\nset [.type v] to [0]\n\nwhen I receive [new level v]\ndelete this clone\n\nwhen I receive [cycle v]\nif <not <(.on?) = [x]>> then\n    if <<([abs v] of ((Y) + (.y)) ) > [180]> or <([abs v] of ((X) + (.x)) ) > [240]>> then\n        if <(.show?) = [1]> then\n            hide\n            set [.show? v] to [0]\n        end\n    else\n        go to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\n        if <(.show?) = [0]> then\n            show\n            set [.show? v] to [1]\n        end\n        touching player\n    end\nend\n\nwhen I receive [rotate v]\nrotate (rotate) degrees (.x) (.y)\nturn right (rotate) degrees\ngo to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\n\nwhen I start as a clone\nif <(item (last) of [info-spawn v]) = [0]> then\n    point in direction (0)\nelse\n    if <(item (last) of [info-spawn v]) = [180]> then\n        point in direction (180)\n    else\n        if <(item (last) of [info-spawn v]) = [-90]> then\n            point in direction (-90)\n        else\n            point in direction (90)\n        end\n    end\nend\nset [.x v] to (item (last) of [x-spawn v])\nset [.y v] to (item (last) of [y-spawn v])\nset [.type v] to (item (last) of [type-spawn v])\ndelete (last) of [x-spawn v]\ndelete (last) of [y-spawn v]\ndelete (last) of [type-spawn v]\ndelete (last) of [info-spawn v]\nif <(item (.type) of [locks v]) > [0]> then\n    set [.on? v] to [1]\n    switch costume to (.on?)\nelse\n    set [.on? v] to [0]\n    switch costume to (.on?)\nend\n\ndefine None\nset [.x v] to (((x) * ([cos v] of (degrees) )) + ((y) * ([sin v] of (degrees) )))\nset [.y v] to (((y) * ([cos v] of (degrees) )) - ((x) * ([sin v] of (degrees) )))\n\ndefine touching player\nif <key (s v) pressed?> then\n    if <<<((Xc) - (X)) > (((.x) - (.Vx)) - (27))> and <((Xc) - (X)) < ((.x) + ((27) - (.Vx)))>> and <<((Yc) - (Y)) > ((.y) + (-50))> and <((Yc) - (Y)) < ((.y) + (50))>>> then\n        if <(cycle fire CD) < (cycle)> then\n            if <(alive) = [1]> then\n                set [save point x v] to ((X) - (Xc))\n                set [save point y v] to ((Y) - (Yc))\n                set [cycle fire cd v] to ((cycle) + (15))\n                if <(.on?) = [1]> then\n                    set [.on? v] to [0]\n                    switch costume to (0 v)\n                    replace item (.type) of [locks v] with ((item (.type) of [locks v]) - (1))\n                    start sound [button press positive v]\n                else\n                    set [.on? v] to [1]\n                    switch costume to (1 v)\n                    replace item (.type) of [locks v] with ((item (.type) of [locks v]) + (1))\n                    start sound [button_synth_negative_02 v]\n                end\n                broadcast (switch v)\n            end\n        end\n    end\nend\n\nwhen I receive [layers v]\nwait until <(cycle) = [42]>\ngo to [front v] layer\nadd [switch] to [layers v]\n\n@button\n\nwhen I receive [initialization v]\ngo to x: (0) y: (-50)\nset rotation style [all around v]\npoint in direction (90)\nswitch costume to (size trick v)\nset size to (100) %\nclear graphic effects\nhide\nset volume to (10) %\nset [.show? v] to [0]\nset [.on? v] to [x]\nset [.type v] to [0]\n\nwhen I receive [new level v]\ndelete this clone\n\nwhen I receive [layers v]\nwait until <(cycle) = [41]>\ngo to [front v] layer\nadd [button] to [layers v]\n\nwhen I receive [rotate v]\nrotate (rotate) degrees (.x) (.y)\nturn right (rotate) degrees\ngo to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\n\nwhen I start as a clone\npoint in direction (90)\nset [.x v] to (item (last) of [x-spawn v])\nset [.y v] to ((item (last) of [y-spawn v]) - (23))\nset [.type v] to (item (last) of [type-spawn v])\ndelete (last) of [x-spawn v]\ndelete (last) of [y-spawn v]\ndelete (last) of [type-spawn v]\nset [.on? v] to [0]\nswitch costume to (.on?)\n\ndefine None\nset [.x v] to (((x) * ([cos v] of (degrees) )) + ((y) * ([sin v] of (degrees) )))\nset [.y v] to (((y) * ([cos v] of (degrees) )) - ((x) * ([sin v] of (degrees) )))\n\ndefine touching player or cube\nif <((Y) + (.y)) < [160]> then\n    if <<<<touching (legs v)?> or <touching (player v)?>> and <(alive) = [1]>> or <touching (cube v)?>> then\n        if <(.on?) = [0]> then\n            if <(broadcast CD) < (cycle)> then\n                set [broadcast cd v] to ((cycle) + (9))\n                set [.on? v] to [1]\n                switch costume to (1 v)\n                start sound [portal_button_up_01 v]\n                replace item (.type) of [locks v] with ((item (.type) of [locks v]) - (1))\n                broadcast (switch v)\n                set [save point x v] to (() - (.x))\n                set [save point y v] to (() - ((.y) + (27)))\n                if <touching (cube v)?> then\n                    broadcast (cube on button v)\n                end\n            end\n        end\n    else\n        if <(.on?) = [1]> then\n            if <(broadcast CD) < (cycle)> then\n                set [broadcast cd v] to ((cycle) + (9))\n                set [.on? v] to [0]\n                switch costume to (0 v)\n                start sound [portal_button_down_01 v]\n                replace item (.type) of [locks v] with ((item (.type) of [locks v]) + (1))\n                broadcast (switch v)\n            end\n        end\n    end\nend\n\nwhen I receive [cycle: position v]\ngo to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\n\nwhen I receive [cycle v]\nif <not <(.on?) = [x]>> then\n    if <<([abs v] of ((Y) + (.y)) ) > [180]> or <([abs v] of ((X) + (.x)) ) > [240]>> then\n        if <(.show?) = [1]> then\n            hide\n            set [.show? v] to [0]\n        end\n    else\n        if <(.show?) = [0]> then\n            show\n            set [.show? v] to [1]\n            set [broadcast cd v] to ((cycle) + (15))\n        else\n            touching player or cube\n        end\n    end\nend\n\n@up bumper\n\nwhen I receive [layers v]\nwait until <(cycle) = [26]>\ngo to [front v] layer\nadd [up bumper] to [layers v]\n\nwhen I receive [cycle: position v]\ngo to x: (Xc) y: ((Yc) + ([abs v] of (Vy) ))\n\nwhen I receive [cycle v]\nif <touching (portal blue v)?> then\n    broadcast (touch blue portal v)\nelse\n    if <touching (portal red v)?> then\n        broadcast (touch red portal v)\n    end\nend\nif <<touching (map v)?> or <touching (door v)?>> then\n    set [detect up v] to [1]\nelse\n    set [detect up v] to [0]\nend\n\nwhen I receive [display v]\nif <(show settings?) = [1]> then\n    set [ghost v] effect to (0)\nelse\n    set [ghost v] effect to (100)\nend\n\nwhen I receive [initialization v]\nset [ghost v] effect to (100)\npoint in direction (90)\ngo to (player v)\nset size to (100) %\nshow\n\n@left bumper\n\nwhen I receive [initialization v]\nset [ghost v] effect to (100)\npoint in direction (90)\nset size to (100) %\nshow\ngo to (player v)\n\nwhen I receive [layers v]\nwait until <(cycle) = [25]>\ngo to [front v] layer\nadd [left bumper] to [layers v]\n\nwhen I receive [display v]\nif <(show settings?) = [1]> then\n    set [ghost v] effect to (0)\nelse\n    set [ghost v] effect to (100)\nend\n\nwhen I receive [cycle v]\nif <<touching (map v)?> or <touching (door v)?>> then\n    set [detect left v] to [1]\nelse\n    set [detect left v] to [0]\nend\nif <touching (portal blue v)?> then\n    broadcast (touch blue portal v)\nelse\n    if <touching (portal red v)?> then\n        broadcast (touch red portal v)\n    end\nend\n\nwhen I receive [cycle: position v]\ngo to x: ((Xc) - ([abs v] of ((Vx) * (0.5)) )) y: (Yc)\n\n@right bumper\n\nwhen I receive [initialization v]\nset [ghost v] effect to (100)\npoint in direction (90)\nset size to (100) %\nshow\ngo to (player v)\n\nwhen I receive [layers v]\nwait until <(cycle) = [24]>\ngo to [front v] layer\nadd [right bumper] to [layers v]\n\nwhen I receive [display v]\nif <(show settings?) = [1]> then\n    set [ghost v] effect to (0)\nelse\n    set [ghost v] effect to (100)\nend\n\nwhen I receive [cycle v]\nif <<touching (map v)?> or <touching (door v)?>> then\n    set [detect right v] to [1]\nelse\n    set [detect right v] to [0]\nend\nif <touching (portal blue v)?> then\n    broadcast (touch blue portal v)\nelse\n    if <touching (portal red v)?> then\n        broadcast (touch red portal v)\n    end\nend\n\nwhen I receive [cycle: position v]\ngo to x: ((Xc) + ([abs v] of ((Vx) * (0.5)) )) y: (Yc)\n\n@down bumper\n\nwhen I receive [initialization v]\nset [ghost v] effect to (100)\npoint in direction (90)\nset size to (100) %\nshow\nswitch costume to (down b v)\ngo to (player v)\n\nwhen I receive [display v]\nif <(show settings?) = [1]> then\n    set [ghost v] effect to (0)\nelse\n    set [ghost v] effect to (100)\nend\n\nwhen I receive [layers v]\nwait until <(cycle) = [23]>\ngo to [front v] layer\nadd [down bumper] to [layers v]\n\nwhen I receive [rotate v]\nif <<touching (map v)?> or <touching (door v)?>> then\n    change [y v] by (-6)\nend\n\ndefine sound: landing\nif <(Vy) > [3]> then\n    if <<(alive) = [1]> and <<(rotate) = [no]> or <(rotate) = [0]>>> then\n        if <not <<touching (portal blue v)?> or <touching (portal red v)?>>> then\n            set volume to ((2) * ((Vy) - (3))) %\n            start sound (join [fs_fm_black_tile_0] (pick random (1) to (9)))\n        end\n    end\nend\n\nwhen I receive [cycle: position v]\ngo to x: (Xc) y: (Yc)\n\ndefine unlevel ground adjust\nif <(alive) = [1]> then\n    set [.adjust v] to [0]\n    change y by (1)\n    move up if touching ground\n    if <not <<touching (map v)?> or <touching (platform v)?>>> then\n        change [yc v] by (.adjust)\n        if <([abs v] of (Vx) ) > [7]> then\n            if <(Vx) > [0]> then\n                change [vy v] by (((-0.06) * (7)) * (.adjust))\n            else\n                change [vy v] by (((-0.06) * (-7)) * (.adjust))\n            end\n        else\n            change [vy v] by (((-0.06) * ([abs v] of (Vx) )) * (.adjust))\n            set [vx v] to ((Vx) * ((1) - ((0.02) * (.adjust))))\n        end\n    end\nend\n\nwhen I receive [cycle v]\nif <touching (portal blue v)?> then\n    broadcast (touch blue portal v)\nelse\n    if <touching (portal red v)?> then\n        broadcast (touch red portal v)\n    end\nend\n\ndefine move up if touching ground\nif <<touching (map v)?> or <touching (platform v)?>> then\n    change [.adjust v] by (1)\n    change y by (1)\n    if <(.adjust) < [30]> then\n        move up if touching ground\n    end\nend\n\nif <<touching (map v)?> or <<touching (door v)?> or <touching (platform v)?>>> then\n    set [detect down v] to [1]\nelse\nend\n\nwhen flag clicked\nforever\n    if <<touching (map v)?> or <<touching (door v)?> or <touching (platform v)?>>> then\n        sound: landing\n        unlevel ground adjust\n        set [detect down v] to [1]\n    else\n        set [detect down v] to [0]\n    end\nend\n\n@cube\n\nwhen I receive [layers v]\nwait until <(cycle) = [19]>\ngo to [front v] layer\nadd [cube] to [layers v]\n\nwhen I receive [initialization v]\nset rotation style [don't rotate v]\npoint in direction (90)\nset volume to (20) %\nswitch costume to (cube v)\nset size to (80) %\nclear graphic effects\nhide\nset [.show? v] to [0]\nset [.portal v] to [0]\nset [.x v] to [-2701]\nset [.y v] to [231]\nset [.vx v] to [0]\nset [.vy v] to [0]\nset [.state v] to [x]\n\ndefine delete if off screen and falling\nif <(.state) = [fall]> then\n    start sound [fizzle v]\n    set [.state v] to [respawn]\nend\n\ndefine exiting the portal with a direction = (dir) , speed= (speed)\nif <(dir) = [-90]> then\n    set [.vx v] to ((-2) - (speed))\n    set [.vy v] to [3]\nelse\n    if <(dir) = [90]> then\n        set [.vx v] to ((2) + (speed))\n        set [.vy v] to [3]\n    else\n        if <(dir) = [180]> then\n            set [.vy v] to ((0) - (speed))\n            set [.vx v] to [0]\n        else\n            if <(dir) = [0]> then\n                set [.vy v] to ((3) + (speed))\n                set [.vx v] to [0]\n            else\n                set [.vx v] to (((2) + (speed)) * ([sin v] of (dir) ))\n                set [.vy v] to (((2) + (speed)) * ([cos v] of (dir) ))\n            end\n        end\n    end\nend\n\ndefine move out of map X (dx)\nif <touching (map v)?> then\n    change x by (dx)\n    change [.x v] by (dx)\n    if <touching (map v)?> then\n        change x by (dx)\n        change [.x v] by (dx)\n        if <touching (map v)?> then\n            change x by (dx)\n            change [.x v] by (dx)\n            if <touching (map v)?> then\n                change x by (dx)\n                change [.x v] by (dx)\n                if <touching (map v)?> then\n                    change x by (dx)\n                    change [.x v] by (dx)\n                    if <touching (map v)?> then\n                        change x by (dx)\n                        change [.x v] by (dx)\n                        if <touching (map v)?> then\n                            change x by (dx)\n                            change [.x v] by (dx)\n                            if <touching (map v)?> then\n                                change x by (dx)\n                                change [.x v] by (dx)\n                                if <touching (map v)?> then\n                                    change x by (dx)\n                                    change [.x v] by (dx)\n                                end\n                            end\n                        end\n                    end\n                end\n            end\n        end\n    end\nend\n\ndefine move out of map Y (dy)\nif <touching (map v)?> then\n    change y by (dy)\n    change [.y v] by (dy)\n    if <touching (map v)?> then\n        change y by (dy)\n        change [.y v] by (dy)\n        if <touching (map v)?> then\n            change y by (dy)\n            change [.y v] by (dy)\n            if <touching (map v)?> then\n                change y by (dy)\n                change [.y v] by (dy)\n                if <touching (map v)?> then\n                    change y by (dy)\n                    change [.y v] by (dy)\n                    if <touching (map v)?> then\n                        change y by (dy)\n                        change [.y v] by (dy)\n                        if <touching (map v)?> then\n                            change y by (dy)\n                            change [.y v] by (dy)\n                            if <touching (map v)?> then\n                                change y by (dy)\n                                change [.y v] by (dy)\n                                if <touching (map v)?> then\n                                    change y by (dy)\n                                    change [.y v] by (dy)\n                                end\n                            end\n                        end\n                    end\n                end\n            end\n        end\n    end\nend\n\nwhen I receive [new level v]\ndelete this clone\n\nwhen I receive [player dead v]\nif <not <(.state) = [x]>> then\n    set [.state v] to [respawn]\nend\n\nbroadcast (player dead v)\n\ndefine player collision\nif <touching (right bumper v)?> then\n    set [detect right v] to [1]\nend\nif <touching (left bumper v)?> then\n    set [detect left v] to [1]\nend\nif <touching (down bumper v)?> then\n    repeat (10)\n        set [detect down v] to [1]\n    end\nend\n\ndefine Y wall check\nchange [.vy v] by (G)\nchange [.y v] by (.Vy)\nset y to ([floor v] of ((Y) + (.y)) )\nif <<touching (map v)?> and <(.portal) = [0]>> then\n    move back 1 cycle and floor position\n    if <(.Vy) > [0]> then\n        move out of map Y (-1)\n        set [.vy v] to ((-0.4) * (.Vy))\n        set [.vx v] to ((0.4) * (.Vx))\n    else\n        change y by (-6)\n        change [.y v] by (-6)\n        move out of map Y (1)\n        set mode to sitting\n    end\nend\n\ndefine X wall check\nchange [.x v] by (.Vx)\nset x to ([floor v] of ((X) + (.x)) )\nif <<<touching (map v)?> or <touching (door v)?>> and <(.portal) = [0]>> then\n    move back 1 cycle and floor position\n    if <(.Vx) > [0]> then\n        move out of map X (-1)\n    else\n        move out of map X (1)\n    end\n    set [.vx v] to ((-0.4) * (.Vx))\nend\n\nwhen I receive [cycle: position v]\nif <(.state) = [sit]> then\n    go to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\nend\n\ndefine pick up?\nif <<key (s v) pressed?> and <(distance to [player v]) < [40]>> then\n    if <(cycle fire CD) < (cycle)> then\n        if <(alive) = [1]> then\n            set [cycle fire cd v] to ((cycle) + (15))\n            set [.state v] to [hold]\n            set [vx v] to ((0.5) * ((Vx) + (.Vy)))\n            set [vy v] to ((0.5) * ((Vy) + (.Vx)))\n        end\n    end\nend\n\ndefine touching map\nif <touching (map v)?> then\n    start sound [fizzle v]\n    set [.state v] to [respawn]\nend\n\ndefine touching fizzler?\nif <touching (fizzler v)?> then\n    start sound [fizzle v]\n    set [.state v] to [respawn]\n    set [xfizzf v] to (.x)\n    set [yfizzf v] to (.y)\n    broadcast (fizzler flash v)\nend\n\ndefine drop?\nif <key (s v) pressed?> then\n    change size by (10)\n    if <not <<<touching (map v)?> or <touching (door v)?>> or <touching (turret v)?>>> then\n        if <(cycle fire CD) < (cycle)> then\n            if <(alive) = [1]> then\n                set [cycle fire cd v] to ((cycle) + (15))\n                set [.state v] to [fall]\n                set [.x v] to ([floor v] of ((() - (X)) + (x position)) )\n                set [.y v] to ([floor v] of ((() - (Y)) + (y position)) )\n                set [.vx v] to (() - (Vx))\n                set [.vy v] to (() - (Vy))\n            end\n        end\n    end\n    change size by (-10)\nend\n\ndefine rotate (degrees) degrees (x) (y)\nset [.x v] to (((x) * ([cos v] of (degrees) )) + ((y) * ([sin v] of (degrees) )))\nset [.y v] to (((y) * ([cos v] of (degrees) )) - ((x) * ([sin v] of (degrees) )))\n\ndefine state = respawn\nchange [.show? v] by (1)\nhide\nif <(.show?) > [80]> then\n    spawn cube: x= (.x start) , y= ((.y start) + (17))\nend\n\ndefine spawn cube: x= (x) , y= (y)\nadd (x) to [x-spawn v]\nadd (y) to [y-spawn v]\nset [.show? v] to [0]\nset [.portal v] to [0]\nset [.vx v] to [0]\nset [.vy v] to [0]\nset [.state v] to [x]\ncreate clone of (_myself_ v)\ndelete this clone\n\nwhen I start as a clone\npoint in direction (90)\nset [.x v] to (item (last) of [x-spawn v])\nset [.y v] to ((item (last) of [y-spawn v]) - (17))\ndelete (last) of [x-spawn v]\ndelete (last) of [y-spawn v]\nset [.x start v] to (.x)\nset [.y start v] to (.y)\nif <([costume name v] of [map v]) = [out of reach]> then\n    switch costume to (companion cube v)\nend\nspawning graphics\n\ndefine spawning graphics\nset [.portal v] to [100]\nset [ghost v] effect to (100)\nrepeat (10)\n    if <<([abs v] of ((Y) + (.y)) ) > [180]> or <([abs v] of ((X) + (.x)) ) > [240]>> then\n        if <(.show?) = [1]> then\n            hide\n            set [.show? v] to [0]\n        end\n    else\n        go to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + ((.y) + (.portal))) )\n        if <(.show?) = [0]> then\n            show\n            set [.show? v] to [1]\n        end\n    end\n    change [.portal v] by (-10)\n    change [ghost v] effect by (-10)\nend\nclear graphic effects\nset [.portal v] to [0]\nset mode to sitting\n\nstart sound [portal_close2 v]\n\nwhen I receive [rotate v]\nif <not <(.state) = [hold]>> then\n    rotate (rotate) degrees (.x) (.y)\n    go to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\nend\n\nwhen I receive [cycle v]\nif <not <(.state) = [x]>> then\n    if <(.state) = [respawn]> then\n        state = respawn\n    else\n        if <(.state) = [hold]> then\n            state = hold\n        else\n            if <<([abs v] of ((Y) + (.y)) ) > [180]> or <([abs v] of ((X) + (.x)) ) > [240]>> then\n                if <(.show?) = [1]> then\n                    hide\n                    set [.show? v] to [0]\n                end\n                delete if off screen and falling\n            else\n                if <(.show?) = [0]> then\n                    show\n                    set [.show? v] to [1]\n                end\n                if <(.state) = [fall]> then\n                    falling\n                else\n                    player collision\n                end\n                touching portals\n                touching fizzler?\n                pick up?\n            end\n        end\n    end\nend\n\nif <touching (map v)?> then\n    if <(.state) = [respawn?]> then\n        set [.state v] to [respawn]\n    else\n        set [.state v] to [respawn?]\n    end\nend\n\ndefine state = hold\nif <(alive) = [1]> then\n    show\n    go to x: (((20) * ([cos v] of (([direction v] of [player v]) - (90)) )) + (Xc)) y: ((((20) * ([sin v] of (([direction v] of [player v]) + (90)) )) + (Yc)) + (crouch))\n    set [.x v] to ([floor v] of ((x position) - (X)) )\n    set [.y v] to ([floor v] of ((y position) - (Y)) )\n    drop?\n    touching fizzler?\nelse\n    set [.state v] to [respawn]\nend\n\ndefine move back 1 cycle and floor position\nset [.x v] to ([floor v] of ((.x) - (.Vx)) )\nset [.y v] to ([floor v] of ((.y) - (.Vy)) )\nchange [.vy v] by (() - (G))\ngo to x: ([floor v] of ((X) + (.x)) ) y: ([floor v] of ((Y) + (.y)) )\n\nwhen I receive [cube on button v]\nif <<(.state) = [fall]> or <(.state) = [sit]>> then\n    if <((((.x) + (save point x)) * ((.x) + (save point x))) + (((.y) + (save point y)) * ((.y) + (save point y)))) < [1000]> then\n        if <touching (button v)?> then\n            set [.x v] to ((0) - (save point x))\n            set [.y v] to ((0) - ((save point y) + (20)))\n            set mode to sitting\n        end\n    end\nend\n\ndefine falling\nmax speed (7)\nX wall check\nY wall check\nif <touching (button v)?> then\n    if <(.portal) = [0]> then\n        if <((((.x) + (save point x)) * ((.x) + (save point x))) + (((.y) + (save point y)) * ((.y) + (save point y)))) < [1000]> then\n            set [.vx v] to [0]\n            set [.vy v] to [0]\n            broadcast (cube on button v)\n        end\n    end\nend\n\ndefine max speed (max)\nif <(.Vx) > (max)> then\n    set [.vx v] to (max)\nelse\n    if <(.Vx) < (() - (max))> then\n        set [.vx v] to (() - (max))\n    end\nend\nif <(.Vy) > (max)> then\n    set [.vy v] to (max)\nelse\n    if <(.Vy) < (() - (max))> then\n        set [.vy v] to (() - (max))\n    end\nend\n\ndefine set mode to sitting\nset [.state v] to [sit]\nset [.vx v] to [0]\nset [.vy v] to [0]\nset [.x v] to ([floor v] of (.x) )\nset [.y v] to ([floor v] of (.y) )\nif <(.show?) = [1]> then\n    if <not <<touching (portal blue v)?> or <touching (portal red v)?>>> then\n        set volume to ((15) - ((0.05) * (distance to [player v]))) %\n        start sound (join [phys_cube_md_0] (pick random (1) to (4)))\n    end\nend\n\ndefine touching portals\nif <(portal?) = [0]> then\n    if <touching (portal blue v)?> then\n        set [.state v] to [fall]\n        if <<(.portal) = [0]> and <(portal red on) = [1]>> then\n            exiting the portal with a direction = ([.dir v] of [portal red v]) , speed= ([sqrt v] of (((.Vx) * (.Vx)) + ((.Vy) * (.Vy))) )\n            set [.x v] to ([floor v] of ([.x v] of [portal red v]) )\n            set [.y v] to ([floor v] of ([.y v] of [portal red v]) )\n            set [.portal v] to [1]\n        end\n    else\n        if <touching (portal red v)?> then\n            set [.state v] to [fall]\n            if <<(.portal) = [0]> and <(portal blue on) = [1]>> then\n                exiting the portal with a direction = ([.dir v] of [portal blue v]) , speed= ([sqrt v] of (((.Vx) * (.Vx)) + ((.Vy) * (.Vy))) )\n                set [.x v] to ([floor v] of ([.x v] of [portal blue v]) )\n                set [.y v] to ([floor v] of ([.y v] of [portal blue v]) )\n                set [.portal v] to [1]\n            end\n        else\n            if <(.portal) = [1]> then\n                set [.portal v] to [0]\n            end\n        end\n    end\nend\n\nforever\nend\n\nforever\nend\n\n@background\n\nwhen I receive [initialization v]\nset volume to (20) %\nhide\nset rotation style [all around v]\npoint in direction (90)\nswitch costume to (size trick v)\nset size to (500) %\nswitch costume to (level)\nwait (0.5) seconds\nshow\n\nwhen I receive [layers v]\nwait until <(cycle) = [9]>\ngo to [front v] layer\nadd [background] to [layers v]\n\nwhen [m v] key pressed\nbroadcast (music v)\n\nwhen I receive [music v]\nif <(music) = [1]> then\n    set [music v] to [0]\n    stop all sounds\nelse\n    set [music v] to [1]\n    forever\n        if <(level) < [16]> then\n            play sound [There_She_Is v] until done\n        else\n            stop all sounds\n            play sound [Technical_difficulties v] until done\n        end\n    end\nend\n\nwhen I receive [new level v]\nrepeat (5)\n    wait (0) seconds\n    change volume by (-4)\nend\nset volume to (0) %\nwait (2) seconds\nwait until <(talking) = [0]>\nwait (0.5) seconds\nrepeat (20)\n    wait (0.1) seconds\n    change volume by (1)\nend\n\nwhen I receive [new level v]\npoint in direction (90)\nswitch costume to (level)\n\ndefine rotate (degrees) degrees (x) (y) (sx) (sy)\nset [save point x v] to (((sx) * ([cos v] of (degrees) )) + ((sy) * ([sin v] of (degrees) )))\nset [save point y v] to (((sy) * ([cos v] of (degrees) )) - ((sx) * ([sin v] of (degrees) )))\nset [x v] to (((x) * ([cos v] of (degrees) )) + ((y) * ([sin v] of (degrees) )))\nset [y v] to (((y) * ([cos v] of (degrees) )) - ((x) * ([sin v] of (degrees) )))\n\nwhen I receive [rotate v]\nturn right (rotate) degrees\ngo to x: ([floor v] of (X) ) y: ([floor v] of (Y) )\n\nwhen [right arrow v] key pressed\n\nwhen [left arrow v] key pressed\n\nrepeat (3)\n    set [rotate v] to [30]\n    rotate (rotate) degrees (X) (Y) (save point x) (save point y)\n    broadcast (rotate v)\nend\nwait (0) seconds\nset [rotate v] to [0]\n\nrepeat (3)\n    set [rotate v] to [-30]\n    rotate (rotate) degrees (X) (Y) (save point x) (save point y)\n    broadcast (rotate v)\nend\nwait (0) seconds\nset [rotate v] to [0]\n\nwhen I receive [cycle: position v]\ngo to x: ([floor v] of (X) ) y: ([floor v] of (Y) )\n\n@fullscreen hack\n\nwhen I receive [initialization v]\nset volume to (20) %\nhide\nset rotation style [all around v]\npoint in direction (90)\nswitch costume to (size trick v)\nset size to (500) %\nswitch costume to (level)\nwait (0.5) seconds\nshow\n\nwhen I receive [layers v]\nwait until <(cycle) = [8]>\ngo to [front v] layer\nadd [background] to [layers v]\n\nwhen I receive [cycle: position v]\n\ngo to x: ([floor v] of (X) ) y: ([floor v] of (Y) )\n\nwhen I receive [rotate v]\n\nturn right (rotate) degrees\ngo to x: ([floor v] of (X) ) y: ([floor v] of (Y) )\n\nwhen I receive [new level v]\npoint in direction (90)\nswitch costume to (level)\n\n@weather\n\nwhen I receive [initialization v]\nset rotation style [all around v]\npoint in direction (90)\nclear graphic effects\nswitch costume to (size trick v)\nhide\nset [weather v] to [on]\n\nwhen I receive [layers v]\nwait until <(cycle) = [5]>\ngo to [front v] layer\nadd [weather] to [layers v]\n\nwhen I receive [cycle: position v]\nchange x by ((([floor v] of (X) ) - ([floor v] of (last x) )) + (.Vx))\nchange y by ((([floor v] of (Y) ) - ([floor v] of (last y) )) + (.Vy))\ntouching edge\n\nwhen I start as a clone\nshow\nset size to (30) %\nswitch costume to (weather)\ngo to x: (pick random (-235) to (235)) y: (pick random (-175) to (175))\n\nwhen I receive [teleport v]\nwait (0.05) seconds\ngo to x: (pick random (-235) to (235)) y: (pick random (-175) to (175))\n\nwhen I receive [rotate v]\nturn right (rotate) degrees\nrotate (rotate) degrees (.Vx) (.Vy)\ngo to x: (pick random (-235) to (235)) y: (pick random (-175) to (175))\n\ndefine None\nset [.vx v] to (((x) * ([cos v] of (degrees) )) + ((y) * ([sin v] of (degrees) )))\nset [.vy v] to (((y) * ([cos v] of (degrees) )) - ((x) * ([sin v] of (degrees) )))\n\ndefine touching edge\nif <(y position) < [-179]> then\n    set y to (179)\n    set x to (pick random (-239) to (239))\nelse\n    if <(y position) > [179]> then\n        set y to (-179)\n        set x to (pick random (-239) to (239))\n    end\nend\nif <(x position) < [-239]> then\n    set x to (239)\n    set y to (pick random (-179) to (179))\nelse\n    if <(x position) > [239]> then\n        set x to (-239)\n        set y to (pick random (-179) to (179))\n    end\nend\n\ndefine None\nset [.vx v] to [0]\nset [.vy v] to (speed)\nset [weather v] to [snow]\nrepeat (flakes)\n    wait (0) seconds\n    create clone of (_myself_ v)\nend\n\ndefine None\nset [.vx v] to [0]\nset [.vy v] to (speed)\nset [weather v] to [rain long]\nrepeat (drops)\n    wait (0) seconds\n    create clone of (_myself_ v)\nend\n\nwhen I receive [new level v]\nwait (1) seconds\nset up weather for level ([costume name v] of [map v])\n\ndefine set up weather for level []\nif <not <(weather) = [off]>> then\n    point in direction (90)\n    switch backdrop to (day v)\n    if <(map) = [Aperture Science]> then\n        rain (25) (-3)\n    else\n        if <(map) = [doors, switches, and turrets]> then\n            rain (30) (-4)\n        else\n            if <(map) = [just a fling]> then\n                rain (25) (-3)\n            else\n                if <(map) = [platformer]> then\n                    rain (35) (-5)\n                else\n                    if <(map) = [skyscrape]> then\n                        night rain (35) (-5)\n                    else\n                        if <(map) = [asteroid]> then\n                            rain (30) (-4)\n                        else\n                            if <(map) = [uprising]> then\n                                night rain (30) (-5)\n                            else\n                            end\n                        end\n                    end\n                end\n            end\n        end\n    end\nend\n\nwhen [r v] key pressed\nshow variable [weather v]\nif <(weather) = [off]> then\n    set [weather v] to [on]\n    set up weather for level ([costume name v] of [map v])\nelse\n    set [weather v] to [off]\n    broadcast (end weather v)\nend\nwait (1) seconds\nhide variable [weather v]\n\nwhen I receive [end weather v]\ndelete this clone\n\nwhen I receive [new level v]\ndelete this clone\n\ndefine None\nset [.vx v] to [0]\nset [.vy v] to (speed)\nset [weather v] to [rain]\nrepeat (drops)\n    wait (0) seconds\n    create clone of (_myself_ v)\nend\n\ndefine None\nset [.x v] to (((x) * ([cos v] of (degrees) )) + ((y) * ([sin v] of (degrees) )))\nset [.y v] to (((y) * ([cos v] of (degrees) )) - ((x) * ([sin v] of (degrees) )))\n\nwait (0.1) seconds\n\ndefine None\nswitch backdrop to (night v)\nset [.vx v] to [0]\nset [.vy v] to (speed)\nset [weather v] to [rain night]\nrepeat (drops)\n    wait (0) seconds\n    create clone of (_myself_ v)\nend\nforever\n    wait (pick random (1) to (17)) seconds\n    switch backdrop to (day v)\n    wait (0) seconds\n    switch backdrop to (night v)\nend\n\n@unused graphics\n\nhide\n\n
               2-D side scrolling puzzler          17 levels\n                       Instructions are also in game,\n                    \nmove = WASD        F = mouse look off/on\nportals = mouse or Q,E    (once you find the portal gun)\nP = pause               M = music off/on\nR = rain on/off         H = physics engine      L = level select