Stickman Platformer

Instructions: Cat Caves Aka CATacombs (idea by @cookie_pedia)\n\nArrow keys to move in an ever changing world. Can you find your way out? \n\nScratch team removed the ability to view unshared projects. https://scratch.mit.edu/projects/697174868/ \nWe the community protested but they did not listen.\n\n\n\nComment below: TOAGGA is awesome!!!\n\nAlso it's not anime coin\nit's AMINECOINE\n\nOr comment: Bob12 is awesome!!

@Stage\n\nwhen flag clicked\ninit\n\nwhen I receive [change game state v]\nif <<(@game state) = [transition.to_game]> or <(@game state) = [game]>> then\n    if <not <(backdrop [name v]) = [sky]>> then\n        switch backdrop to (sky v)\n        broadcast (change music v)\n    end\nelse\n    if < (@game state) contains [transition.to_]?> then\n        if <not <(backdrop [name v]) = [title]>> then\n            switch backdrop to (title v)\n            broadcast (change music v)\n        end\n    end\nend\n\nwhen [e v] key pressed\nif <(username) = [amylaser]> then\n    set [@unlocked_levels v] to (=max_levels)\n    if <(@game state) = [game]> then\n        if <(@player state) = [pause]> then\n            set [@player state v] to [camera_return]\n        else\n            set [@player state v] to [pause]\n        end\n        broadcast (change player state v)\n    end\nend\n\nwhen I receive [change_volume2 v]\nset volume to ((100) * (@sound_on?)) %\n\nwhen [m v] key pressed\nif <(@game state) = [game]> then\n    set [@player state v] to [pause]\n    set [@game state v] to [transition.target_title]\n    broadcast (change game state v)\nend\n\ndefine init_levels\ndelete all of [level spawns v]\nrepeat ((=max_levels) * (2))\n    add [] to [level spawns v]\nend\nadd level spawn [1] [-65] [-38]\nadd level spawn [2] [80] [1081]\nadd level spawn [3] [720] [2700]\nadd level spawn [4] [150] [3627]\n\ndefine add level spawn (level#) (x) (y)\nreplace item ((level#) * (2)) of [level spawns v] with (y)\nreplace item (((level#) * (2)) - (1)) of [level spawns v] with (x)\n\ndefine init\nset [@camera x v] to [0]\nset [@camera y v] to [0]\nset [@game state v] to [transition.target_title]\nset [@player state v] to [pause]\nset [@is_salmon_collected? v] to [0]\nset [=max_levels v] to [4]\nset [=panel_width v] to [480]\nset [=panel_height v] to [360]\nset [=level_width_panels v] to [4]\nset [=level_height_panels v] to [3]\nset [=level_width_px v] to ((=level_width_panels) * (=panel_width))\nset [=level_height_px v] to ((=level_height_panels) * (=panel_height))\nset [=map_width_panels v] to (=level_width_panels)\nset [=map_height_panels v] to ((=level_height_panels) * (=max_levels))\nset [=map_width_px v] to ((=map_width_panels) * (=panel_width))\nset [=map_height_px v] to ((=map_height_panels) * (=panel_height))\nset [@sound_on? v] to [1]\nset [@curr_level v] to [1]\nset [@unlocked_levels v] to [1]\nset [@score.overall v] to [0]\nset [@score.level v] to [0]\nset [@camera_speed v] to [10]\nhide variable [@camera_speed v]\nhide variable [@camera x v]\nhide variable [@camera y v]\nhide variable [@player.x v]\nhide variable [@player.y v]\nset volume to (100) %\nswitch backdrop to (sky v)\ndelete all of [score_per_level v]\nrepeat (=max_levels)\n    add [0] to [score_per_level v]\nend\ninit_levels\n\nwhen [r v] key pressed\nif <(@game state) = [game]> then\n    set [@player state v] to [pause]\n    set [@game state v] to [transition.target_game]\n    broadcast (change game state v)\nend\n\nwhen I receive [tick v]\nif <(@player state) = [pause]> then\n    if <key (up arrow v) pressed?> then\n        change [@camera y v] by (@camera_speed)\n    end\n    if <key (down arrow v) pressed?> then\n        change [@camera y v] by ((0) - (@camera_speed))\n    end\n    if <key (left arrow v) pressed?> then\n        change [@camera x v] by ((0) - (@camera_speed))\n    end\n    if <key (right arrow v) pressed?> then\n        change [@camera x v] by (@camera_speed)\n    end\nend\n\nwhen I receive [change player state v]\nif <(@player state) = [pause]> then\n    show variable [@camera_speed v]\n    show variable [@camera x v]\n    show variable [@camera y v]\n    show variable [@player.x v]\n    show variable [@player.y v]\nelse\n    hide variable [@camera_speed v]\n    hide variable [@camera x v]\n    hide variable [@camera y v]\n    hide variable [@player.x v]\n    hide variable [@player.y v]\n    if <<(@player state) = [win]> and <(@curr_level) = (@unlocked_levels)>> then\n        change [@unlocked_levels v] by (1)\n    end\nend\n\nwhen I receive [change music v]\nif <(@game state) = [transition.to_game]> then\n    stop [other scripts in sprite v]\n    forever\n        play sound [SMG2 - Battle Belt Galaxy v] until done\n    end\nelse\n    stop [other scripts in sprite v]\n    forever\n        play sound [Fork Lifter - Rhythm Heaven Fever.mp3 v] until done\n    end\nend\n\n@player hitbox\n\ndefine get_keyboard_input\nset [@input.down v] to <<<key (down arrow v) pressed?> or <key (s v) pressed?>> or <<mouse down?> and <(mouse y) < ((y position) - (60))>>>\nset [@input.up v] to <<<key (up arrow v) pressed?> or <key (w v) pressed?>> or <<mouse down?> and <(mouse y) > ((y position) + (60))>>>\nset [@input.left v] to <<<key (left arrow v) pressed?> or <key (a v) pressed?>> or <<mouse down?> and <(mouse x) < ((x position) - (70))>>>\nset [@input.right v] to <<<key (right arrow v) pressed?> or <key (d v) pressed?>> or <<mouse down?> and <(mouse x) > ((x position) + (70))>>>\nset [@input.action v] to <<key (space v) pressed?> or <<mouse down?> and <(distance to [mouse-pointer v]) < [100]>>>\nif <(@Input.ACTION) = [true]> then\n    if <<<(@player state) = [go]> or <(@player state) = [talk]>> and <(~timer.action) = [0]>> then\n        set [~timer.action v] to [20]\n        broadcast (player action v)\n    end\nend\nif <(~timer.action) > [0]> then\n    change [~timer.action v] by (-1)\nend\n\nwhen I receive [player attack v]\nif <<(@player state) = [go]> and <(~air time) < [1]>> then\n    set [@player state v] to [attack]\n    set [@player.animation_type v] to [attack]\n    start sound [Rip v]\nend\n\ndefine respawn\nhide\nset [@camera x v] to (@checkpt_x)\nset [@camera y v] to (@checkpt_y)\nif <(@camera x) > ((=map_width_px) - (=panel_width))> then\n    set [@camera x v] to ((=map_width_px) - (=panel_width))\nelse\n    if <(@camera x) < [0]> then\n        set [@camera x v] to [0]\n    end\nend\nset [@player.x v] to (@checkpt_x)\nset [@player.y v] to (@checkpt_y)\nset [@player.xvel v] to [0]\nset [@player.yvel v] to [0]\nset [@player.animation_type v] to [idle]\nset [~move_mode v] to [walk]\nset [~timer.hurt v] to [0]\nset [~air time v] to [0]\nset [@player state v] to [go]\nset [@player.is_invincible v] to [0]\ngo to x: ((@player.x) - (@camera x)) y: ((@player.y) - (@camera y))\n\nwhen I receive [change_volume2 v]\nset volume to ((100) * (@sound_on?)) %\n\ndefine init\nhide\nset rotation style [don't rotate v]\nset size to (60) %\nset [ghost v] effect to (100)\nset volume to (100) %\nset [@player.x v] to [0]\nset [@player.y v] to [0]\nset [@player.xvel v] to [0]\nset [@player.yvel v] to [0]\nset [~max_health v] to [3]\nset [@player.health v] to (~max_health)\nset [@player.is_invincible v] to [0]\nset [~force.climb v] to [4]\nset [~force.jump v] to [11]\nset [~force.leftright v] to [9]\nset [~force.gravity v] to [-1.1]\nset [~force.push v] to [4]\nset [~friction v] to [0.5]\nset [~camera.max_dist v] to [50]\nset [~camera.springiness v] to [0.2]\nset [~move_mode v] to [walk]\nset [~slope v] to [0]\nset [~slope.max v] to [12]\nset [~air time v] to [0]\nset [~player.yvel_min v] to [-30]\nset [~timer.action v] to [0]\nset [~timer.hurt v] to [0]\n\ndefine update wrapper\ngo to x: ((@player.x) - (@camera x)) y: ((@player.y) - (@camera y))\nget_keyboard_input\nif <<(@player state) = [go]> or <(@player state) = [hurt]>> then\n    update_player_vec <(@Input.UP) = [true]> <(@Input.DOWN) = [true]> <(@Input.LEFT) = [true]> <(@Input.RIGHT) = [true]> (~move_mode)\nend\nif <<<(@player state) = [go]> or <(@player state) = [hurt]>> or <<(@player state) = [stunned]> or <(@player state) = [camera_return]>>> then\n    update_camera_pos\nend\nupdate_costume <(@Input.UP) = [true]> <(@Input.DOWN) = [true]> <(@Input.LEFT) = [true]> <(@Input.RIGHT) = [true]> ((@player.xvel) / ([abs v] of (@player.xvel) )) ((@player.yvel) / ([abs v] of (@player.yvel) ))\ngo to x: ((@player.x) - (@camera x)) y: ((@player.y) - (@camera y))\nif <<([abs v] of (((@player.x) - (@camera x)) - (x position)) ) < [10]> and <([abs v] of (((@player.y) - (@camera y)) - (y position)) ) < [10]>> then\n    show\n    if <<(@player state) = [camera_return]> and <<([abs v] of (x position) ) < [220]> and <([abs v] of (y position) ) < [160]>>> then\n        set [@player state v] to [go]\n    end\nelse\n    hide\nend\nif <(~timer.hurt) > [0]> then\n    change [~timer.hurt v] by (-1)\nelse\n    set [~timer.hurt v] to [0]\n    if <not <<(@player state) = [stunned]> or <(@player state) = [win]>>> then\n        set [@player.is_invincible v] to [0]\n    end\nend\n\ndefine state_behavior.drowning\nchange [@player.health v] by (-1)\nstart sound [Plunge v]\nrepeat until <not <touching (water v)?>>\n    change y by (1)\n    change [@player.y v] by (1)\nend\nstart sound [Meow2 v]\nwait (2) seconds\nif <(@player.health) < [1]> then\n    start sound [Oops v]\n    set [@game state v] to [transition.target_game]\n    broadcast (change game state v)\nelse\n    set [@player state v] to [respawn]\n    broadcast (change player state v)\nend\n\ndefine update_player_vec <up> <down> <left> <right> (mode)\nif <(mode) = [walk]> then\n    if <<<up> and <(~air time) = [0]>> and <(@player state) = [go]>> then\n        set [@player.yvel v] to (~FORCE.Jump)\n        start sound [Jump v]\n    else\n        set [@player.yvel v] to ((@player.yvel) + (~FORCE.Gravity))\n        if <(@player.yvel) < (~player.yvel_min)> then\n            set [@player.yvel v] to (~player.yvel_min)\n        end\n    end\n    if <<<left> or <right>> and <(@player state) = [go]>> then\n        set [@player.xvel v] to ((~FORCE.LeftRight) * (<right> - <left>))\n        if <(~slope) > (~slope.max)> then\n            if <up> then\n                set [@player.yvel v] to (~FORCE.Climb)\n            else\n                set [@player.yvel v] to (~FORCE.Gravity)\n            end\n            set [~air time v] to [1]\n        end\n    else\n        if <<(~air time) < [2]> or <(@player state) = [go]>> then\n            set [@player.xvel v] to ((@player.xvel) * (~FRICTION))\n        end\n    end\nend\ncheck_vertical_collision (@player.yvel) ((@player.yvel) / ([abs v] of (@player.yvel) )) (y position)\ncheck_horizontal_collision (@player.xvel) (x position) (y position) ((@player.xvel) / ([abs v] of (@player.xvel) ))\nif <(@player.y) < ((([floor v] of ((@curr_level) / (=map_width_panels)) ) - (0.5)) * (=level_height_px))> then\n    set [@player state v] to [respawn]\n    broadcast (change player state v)\nend\n\nwhen flag clicked\ninit\n\ndefine update_camera_pos\nset [@camera x v] to (round ((@camera x) + ((~CAMERA.springiness) * (((@player.x) + (((@player.xvel) / (~FORCE.LeftRight)) * (~CAMERA.max_dist))) - (@camera x)))))\nset [@camera y v] to (round ((@camera y) + ((~CAMERA.springiness) * (((@player.y) + (((@player.yvel) / (~FORCE.Jump)) * (~CAMERA.max_dist))) - (@camera y)))))\nif <(@camera x) > ((=map_width_px) - (=panel_width))> then\n    set [@camera x v] to ((=map_width_px) - (=panel_width))\nelse\n    if <(@camera x) < [0]> then\n        set [@camera x v] to [0]\n    end\nend\n\ndefine check_horizontal_collision (vel_x) (abs_x) (abs_y) (dir_vel_x)\nset [~slope v] to [0]\nchange x by (vel_x)\nrepeat until <<not <<touching (level hitbox v)?> or <touching (objects v)?>>> or <(~slope) > (~slope.max)>>\n    change y by (1)\n    change [~slope v] by (1)\nend\nif <(~slope) > (~slope.max)> then\n    set y to (abs_y)\n    set [@player.xvel v] to [0]\n    repeat until <not <<touching (level hitbox v)?> or <touching (objects v)?>>>\n        change [@player.xvel v] by (1)\n        change x by (((((@player.xvel) mod (2)) * (2)) - (1)) * (@player.xvel))\n    end\n    set [@player.xvel v] to [0]\nelse\n    change x by ((0) - (round (((~slope) / (~slope.max)) * (vel_x))))\n    change y by ((0) - (round (((~slope) / (~slope.max)) * (~slope))))\nend\nset [@player.x v] to ((@player.x) + ((x position) - (abs_x)))\nset [@player.y v] to ((@player.y) + ((y position) - (abs_y)))\n\ndefine check_vertical_collision (vel_y) (dir_vel_y) (abs_y)\nchange [~air time v] by (1)\nchange y by (vel_y)\nif <<touching (level hitbox v)?> or <touching (objects v)?>> then\n    set [@player.yvel v] to [0]\n    repeat until <not <<touching (level hitbox v)?> or <touching (objects v)?>>>\n        if <(dir_vel_y) < [0]> then\n            set [~air time v] to [0]\n        end\n        change [@player.yvel v] by (1)\n        change y by (((((@player.yvel) mod (2)) * (2)) - (1)) * (@player.yvel))\n    end\n    set [@player.yvel v] to [0]\nend\nset [@player.y v] to ((@player.y) + ((y position) - (abs_y)))\n\ndefine update_costume <up> <down> <left> <right> (xdir) (ydir)\nif <(@player state) = [win]> then\n    set [@player.animation_type v] to [win]\nelse\n    if <(@player state) = [drowning]> then\n        set [@player.animation_type v] to [water]\n    else\n        if <(@player state) = [hurt]> then\n            set [@player.animation_type v] to [hurt]\n            if <(~air time) < [1]> then\n                set [@player state v] to [go]\n                if <(@player.health) < [1]> then\n                    set [@player state v] to [stunned]\n                end\n                broadcast (change player state v)\n            end\n        else\n            if <<<(~slope) > (~slope.max)> and <<left> or <right>>> and <(~air time) > [0]>> then\n                if <up> then\n                    set [@player.animation_type v] to [climb]\n                else\n                    set [@player.animation_type v] to [cling]\n                end\n            else\n                if <(@player state) = [stunned]> then\n                    set [@player.animation_type v] to [stunned]\n                else\n                    if <(@player state) = [attack]> then\n                        set [@player.animation_type v] to [attack]\n                    else\n                        if <(~air time) > [1]> then\n                            if <(ydir) > [0]> then\n                                set [@player.animation_type v] to [jump]\n                                if <(~air time) > [8]> then\n                                    set [@player.animation_type v] to [jump2]\n                                end\n                            else\n                                set [@player.animation_type v] to [fall]\n                            end\n                        else\n                            if <not <<left> = <right>>> then\n                                set [@player.animation_type v] to [walk]\n                            else\n                                set [@player.animation_type v] to [idle]\n                            end\n                        end\n                    end\n                end\n            end\n        end\n    end\nend\n\ndefine state_behavior.hurt\nif <<(~timer.hurt) = [0]> and <(@player.is_invincible) = [0]>> then\n    set [~timer.hurt v] to [60]\n    set [@player.is_invincible v] to [1]\n    change [@player.health v] by (-1)\n    start sound [Meow2 v]\n    start sound [Pew v]\n    set [@player.xvel v] to [0]\n    change x by (30)\n    if <<touching (rats v)?> or <touching (spikes v)?>> then\n        change [@player.xvel v] by ((0) - (~FORCE.LeftRight))\n    end\n    change x by (-60)\n    if <<touching (rats v)?> or <touching (spikes v)?>> then\n        change [@player.xvel v] by (~FORCE.LeftRight)\n    end\n    change x by (10)\n    set [@player.yvel v] to ((~FORCE.Jump) - (3))\nend\n\nwhen I receive [change game state v]\nif <(@game state) = [transition.target_game]> then\n    hide\n    set [@player state v] to [pause]\n    set [@player.health v] to (~max_health)\n    set [@checkpt_x v] to (item (((@curr_level) * (2)) - (1)) of [level spawns v])\n    set [@checkpt_y v] to (item ((@curr_level) * (2)) of [level spawns v])\n    respawn\nelse\n    if <(@game state) = [transition.to_game]> then\nend\n\nwhen I receive [change player state v]\nif <(@player state) = [respawn]> then\n    respawn\n    start sound [Oops v]\nelse\n    if <(@player state) = [drowning]> then\n        state_behavior.drowning\n    else\n        if <(@player state) = [hurt]> then\n            state_behavior.hurt\n        else\n            if <(@player state) = [stunned]> then\n                set [@player.is_invincible v] to [1]\n                start sound [Oops v]\n                wait (2) seconds\n                set [@game state v] to [transition.target_game]\n                broadcast (change game state v)\n            else\n                if <(@player state) = [win]> then\n                    set [@player.is_invincible v] to [1]\n                    start sound [Tada v]\n                end\n            end\n        end\n    end\nend\n\n@player visual\n\ndefine init\nhide\nset rotation style [left-right v]\npoint in direction (90)\nswitch costume to (idle v)\nset size to (70) %\nset [ghost v] effect to (0)\nset [~animation.frame v] to [0]\nset [@is_salmon_collected? v] to [0]\n\nwhen flag clicked\ninit\n\nwhen I receive [change game state v]\nif <(@game state) = [transition.to_game]> then\n    init\n    go to (player hitbox v)\n    show\n    go to [front v] layer\n    go [backward v] (6) layers\nelse\n    if < (@game state) contains [transition.to_]?> then\n        stop [other scripts in sprite v]\n        hide\n    else\n        if <(@game state) = [game]> then\n            forever\n                if <(@player.animation_type) = [walk]> then\n                    play sound [Gallop v] until done\n                else\n                    if <(@player.animation_type) = [climb]> then\n                        play sound [Shaker v] until done\n                    end\n                end\n            end\n        end\n    end\nend\n\ndefine animate <left> <right>\ngo to (player hitbox v)\nif <touching (_edge_ v)?> then\n    hide\nelse\n    show\n    if <right> then\n        point in direction (90)\n    else\n        if <left> then\n            point in direction (-90)\n        end\n    end\n    switch costume to (@player.animation_type)\n    if <<<(@player.animation_type) = [idle]> or <(@player.animation_type) = [cling]>> or <(@player.animation_type) = [win]>> then\n        set [~animation.frame v] to (((~animation.frame) + (0.05)) mod (2))\n    else\n        if <<(@player.animation_type) = [walk]> or <(@player.animation_type) = [climb]>> then\n            set [~animation.frame v] to (((~animation.frame) + (0.5)) mod (5))\n        else\n            if <(@player.animation_type) = [water]> then\n                set [~animation.frame v] to (((~animation.frame) + (0.5)) mod (6))\n            else\n                if <(@player.animation_type) = [stunned]> then\n                    set [~animation.frame v] to (((~animation.frame) + (0.5)) mod (4))\n                else\n                    if <(@player.animation_type) = [attack]> then\n                        if <mouse down?> then\n                            point in direction ((90) * (([abs v] of ((mouse x) - (x position)) ) / ((mouse x) - (x position))))\n                        end\n                        set [~animation.frame v] to (((~animation.frame) + (0.5)) mod (9))\n                        if <(~animation.frame) > [8]> then\n                            set [@player state v] to [go]\n                        end\n                    else\n                        set [~animation.frame v] to [0]\n                    end\n                end\n            end\n        end\n    end\n    switch costume to ((costume [number v]) + ([floor v] of (~animation.frame) ))\nend\nif <<([~timer.hurt v] of [player hitbox v]) > [0]> and <not <(@player.animation_type) = [stunned]>>> then\n    set [ghost v] effect to ((30) * ((round (([~timer.hurt v] of [player hitbox v]) / (5))) mod (2)))\nelse\n    set [ghost v] effect to (0)\nend\n\nwhen I receive [tick v]\nanimate <(@Input.LEFT) = [true]> <(@Input.RIGHT) = [true]>\n\n@level visual\n\nwhen I receive [tick v]\nif <(~panel_set.row_ID) > [0]> then\n    scroll\nend\n\nwhen flag clicked\ninit\n\ndefine scroll\nset [~x v] to ((=panel_width) - (((@camera x) + (((~panel_set.col_ID) mod (2)) * (=panel_width))) mod ((2) * (=panel_width))))\nset [~y v] to ((=panel_height) - (((@camera y) + (((~panel_set.row_ID) mod (2)) * (=panel_height))) mod ((2) * (=panel_height))))\ngo to x: (~x) y: (~y)\nupdate_costume\n\ndefine update_costume\nset [~costume.col_id v] to ([floor v] of (((((~x) + (@camera x)) + ((=panel_width) / (2))) / (=map_width_px)) * (=map_width_panels)) )\nset [~costume.row_id v] to ([floor v] of (((((~y) + (@camera y)) + ((=panel_height) / (2))) / (=map_height_px)) * (=map_height_panels)) )\nset [~costume.target_id v] to ((((=map_width_panels) * (~costume.row_ID)) + (~costume.col_ID)) + (1))\nif <<<(~costume.row_ID) > [-1]> and <(~costume.row_ID) < (=map_height_panels)>> and <<(~costume.col_ID) > [-1]> and <(~costume.col_ID) < (=map_width_panels)>>> then\n    show\n    if <not <(costume [number v]) = (~costume.target_ID)>> then\n        switch costume to (~costume.target_ID)\n    end\n    if <<([abs v] of ((x position) - (~x)) ) < [5]> and <([abs v] of ((y position) - (~y)) ) < [5]>> then\n        show\n    else\n        hide\n    end\nelse\n    hide\nend\n\ndefine init\nhide\nswitch costume to (lvl1_\(0,0\) v)\nset size to (100) %\ngo to x: (0) y: (0)\nset rotation style [don't rotate v]\nset [~panel_set.row_id v] to [0]\nset [~panel_set.col_id v] to [0]\nrepeat (2)\n    change [~panel_set.row_id v] by (1)\n    set [~panel_set.col_id v] to [0]\n    repeat (2)\n        change [~panel_set.col_id v] by (1)\n        create clone of (_myself_ v)\n    end\nend\nset [~panel_set.row_id v] to [0]\nset [~panel_set.col_id v] to [0]\nset [~costume.col_id v] to [-1]\nset [~costume.row_id v] to [-1]\n\nwhen I receive [change game state v]\nif <(~panel_set.row_ID) > [0]> then\n    if <(@game state) = [transition.to_game]> then\n        scroll\n        show\n        go to [back v] layer\n        wait (0.1) seconds\n        scroll\n    else\n        if < (@game state) contains [transition.to_]?> then\n            stop [other scripts in sprite v]\n            hide\n        end\n    end\nend\n\n@level hitbox\n\nwhen I receive [tick v]\nif <(~panel_set.row_ID) > [0]> then\n    scroll\nend\n\nwhen flag clicked\ninit\n\ndefine scroll\nset [~x v] to ((=panel_width) - (((@camera x) + (((~panel_set.col_ID) mod (2)) * (=panel_width))) mod ((2) * (=panel_width))))\nset [~y v] to ((=panel_height) - (((@camera y) + (((~panel_set.row_ID) mod (2)) * (=panel_height))) mod ((2) * (=panel_height))))\ngo to x: (~x) y: (~y)\nupdate_costume\n\ndefine update_costume\nset [~costume.col_id v] to ([floor v] of (((((~x) + (@camera x)) + ((=panel_width) / (2))) / (=map_width_px)) * (=map_width_panels)) )\nset [~costume.row_id v] to ([floor v] of (((((~y) + (@camera y)) + ((=panel_height) / (2))) / (=map_height_px)) * (=map_height_panels)) )\nset [~costume.target_id v] to ((((=map_width_panels) * (~costume.row_ID)) + (~costume.col_ID)) + (1))\nif <<<(~costume.row_ID) > [-1]> and <(~costume.row_ID) < (=map_height_panels)>> and <<(~costume.col_ID) > [-1]> and <(~costume.col_ID) < (=map_width_panels)>>> then\n    show\n    if <not <(costume [number v]) = (~costume.target_ID)>> then\n        switch costume to (~costume.target_ID)\n    end\n    if <<([abs v] of ((x position) - (~x)) ) < [10]> and <([abs v] of ((y position) - (~y)) ) < [10]>> then\n        show\n    else\n        hide\n    end\nelse\n    hide\nend\n\nwhen I receive [change game state v]\nif <(~panel_set.row_ID) > [0]> then\n    if <(@game state) = [transition.to_game]> then\n        wait (0.1) seconds\n        scroll\n        show\n        go to [back v] layer\n    else\n        if < (@game state) contains [transition.to_]?> then\n            stop [other scripts in sprite v]\n            hide\n        end\n    end\nend\n\ndefine init\nhide\nset size to (100) %\ngo to x: (0) y: (0)\nset rotation style [don't rotate v]\nset [~panel_set.row_id v] to [0]\nset [~panel_set.col_id v] to [0]\nswitch costume to (lvl1_\(0,0\) v)\nset [ghost v] effect to (100)\nrepeat (2)\n    change [~panel_set.row_id v] by (1)\n    set [~panel_set.col_id v] to [0]\n    repeat (2)\n        change [~panel_set.col_id v] by (1)\n        create clone of (_myself_ v)\n    end\nend\nset [~panel_set.row_id v] to [0]\nset [~panel_set.col_id v] to [0]\n\n@dialogue\n\nwhen flag clicked\ninit\n\ndefine dialogue\nif <<(@player state) = [go]> or <(@player state) = [talk]>> then\n    show\n    go to [front v] layer\n    if <not <(~text.opened_index) = (~text.index)>> then\n        set [@player state v] to [talk]\n        set [~text.opened_index v] to (~text.index)\n        switch costume to (item (~text.index) of [~locations v])\n        start sound [Meow v]\n        animate_in (~text.BOUNCE)\n    else\n        start sound [Suction Cup v]\n        if <not <(letter (1) of (costume [name v])) = [_]>> then\n            next costume\n            animate_in (~text.BOUNCE)\n        else\n            set [~text.opened_index v] to [0]\n            animate_out (~text.BOUNCE)\n            set [@player state v] to [go]\n        end\n    end\nend\n\ndefine animate_in (bounce)\nset [~text.bounce_vel v] to [10]\nset size to (~text.MIN_SIZE) %\nrepeat until <([abs v] of (~text.bounce_vel) ) < [0.01]>\n    set [~text.bounce_vel v] to (((~text.bounce_vel) * (bounce)) + (((~text.MAX_SIZE) - (size)) * ((1) - (bounce))))\n    change size by (~text.bounce_vel)\nend\n\ndefine check_player_dialogue (stride)\nset [~text.index v] to [1]\nset [~text.dist v] to (~text.MAX_DIST)\nrepeat until <<(~text.index) > (length of [~locations v])> or <(~text.dist) < (~text.MAX_DIST)>>\n    set [~text.x v] to (item ((~text.index) + (1)) of [~locations v])\n    set [~text.y v] to (item ((~text.index) + (2)) of [~locations v])\n    get_dist (~text.x) (~text.y) (([x position v] of [player hitbox v]) + (@camera x)) (([y position v] of [player hitbox v]) + (@camera y))\n    change [~text.index v] by (stride)\nend\nif <(~text.dist) < (~text.MAX_DIST)> then\n    change [~text.index v] by ((0) - (stride))\nend\n\nwhen I receive [player action v]\nif <(~text.dist) < (~text.MAX_DIST)> then\n    dialogue\nelse\n    broadcast (player attack v)\nend\n\ndefine get_dist (x1) (y1) (x2) (y2)\nset [~text.dist v] to ([sqrt v] of ((((x1) - (x2)) * ((x1) - (x2))) + (((y1) - (y2)) * ((y1) - (y2)))) )\n\ndefine animate_out (bounce)\nrepeat (2)\n    set size to ((~text.BOUNCE) * (size)) %\nend\nhide\n\nwhen I receive [tick v]\ncheck_player_dialogue [3]\nif <(~text.dist) < (~text.MAX_DIST)> then\n    go to x: ((~text.x) - (@camera x)) y: (((~text.y) - (@camera y)) + (60))\n    set [@show icon v] to [1]\nelse\n    set [@show icon v] to [0]\n    if <(~text.opened_index) > [0]> then\n        animate_out (~text.BOUNCE)\n    end\n    set [~text.opened_index v] to [0]\n    if <(@player state) = [talk]> then\n        set [@player state v] to [go]\n    end\nend\n\ndefine add_location | title: (title) x: (x) y: (y)\nadd (title) to [~locations v]\nadd (x) to [~locations v]\nadd (y) to [~locations v]\n\ndefine init\nhide\nset volume to (100) %\nshow list [~locations v]\nset [~text.min_size v] to [40]\nset [~text.bounce v] to [0.5]\nset [~text.max_size v] to [100]\nset [~text.max_dist v] to [30]\nset [~text.opened_index v] to [0]\nset size to (~text.MIN_SIZE) %\ndelete all of [~locations v]\nadd_location | title: [intro] x: [-70] y: [-38]\nadd_location | title: [tutorial_climb] x: [150] y: [32]\nadd_location | title: [tutorial_attack] x: [440] y: [92]\nadd_location | title: [hint_water] x: [860] y: [32]\nadd_location | title: [tutorial_push] x: [980] y: [342]\nadd_location | title: [tutorial_cut] x: [760] y: [1260]\n\nwhen I receive [change_volume2 v]\nset volume to ((100) * (@sound_on?)) %\n\nwhen I receive [change game state v]\nif <<not <(@game state) = [transition.to_game]>> and < (@game state) contains [transition.to_]?>> then\n    stop [other scripts in sprite v]\n    hide\nend\n\n@water\n\nwhen I receive [tick v]\nif <(~panel_set.row_ID) > [0]> then\n    scroll\nend\n\nwhen flag clicked\ninit\n\ndefine scroll\nset [~x v] to (round ((=panel_width) - (((@camera x) + (((~panel_set.col_ID) mod (2)) * (=panel_width))) mod ((2) * (=panel_width)))))\nset [~y v] to (round ((=panel_height) - (((@camera y) + (((~panel_set.row_ID) mod (2)) * (=panel_height))) mod ((2) * (=panel_height)))))\nanimate [3] [5]\nupdate_costume\ngo to x: (~x) y: (~y)\nif <<([abs v] of ((~x) - (x position)) ) < [5]> and <([abs v] of ((~y) - (y position)) ) < [5]>> then\n    show\n    check_player_collision\nelse\n    hide\nend\n\ndefine update_costume\nset [~costume.col_id v] to ([floor v] of (((((~x) + (@camera x)) + ((=panel_width) / (2))) / (=map_width_px)) * (=map_width_panels)) )\nset [~costume.row_id v] to ([floor v] of (((((~y) + (@camera y)) + ((=panel_height) / (2))) / (=map_height_px)) * (=map_height_panels)) )\nset [~costume.target_id v] to ((((=map_width_panels) * (~costume.row_ID)) + (~costume.col_ID)) + (1))\nif <<<(~costume.row_ID) > [-1]> and <(~costume.row_ID) < (=map_height_panels)>> and <<(~costume.col_ID) > [-1]> and <(~costume.col_ID) < (=map_width_panels)>>> then\n    show\n    if <not <(costume [number v]) = (~costume.target_ID)>> then\n        switch costume to (~costume.target_ID)\n    end\nelse\n    hide\nend\n\nwhen I receive [change game state v]\nif <(~panel_set.row_ID) > [0]> then\n    if <(@game state) = [transition.to_game]> then\n        wait (0.1) seconds\n        scroll\n        go to [front v] layer\n        go [backward v] (6) layers\n    else\n        if < (@game state) contains [transition.to_]?> then\n            stop [other scripts in sprite v]\n            hide\n        end\n    end\nend\n\ndefine init\nhide\nset size to (100) %\ngo to x: (0) y: (0)\nset rotation style [don't rotate v]\nset [~panel_set.row_id v] to [0]\nset [~panel_set.col_id v] to [0]\nset [ghost v] effect to (40)\nswitch costume to (lvl1_\(0,0\) v)\nrepeat (2)\n    change [~panel_set.row_id v] by (1)\n    repeat (2)\n        change [~panel_set.col_id v] by (1)\n        create clone of (_myself_ v)\n        next costume\n    end\nend\nset [~panel_set.row_id v] to [0]\nset [~panel_set.col_id v] to [0]\nset [~animation.timer v] to [0]\n\ndefine check_player_collision\nif <<touching (player hitbox v)?> and <not <(@player state) = [drowning]>>> then\n    set [@player state v] to [drowning]\n    broadcast (change player state v)\nend\n\ndefine animate (range) (speed)\nset [~animation.timer v] to (((~animation.timer) + (speed)) mod (360))\nchange [~y v] by (([sin v] of (~animation.timer) ) * (range))\n\n@icons\n\nwhen flag clicked\nset [@show icon v] to [0]\nset [~icon.animation_speed v] to [0.05]\nhide\nset size to (100) %\n\nwhen I receive [tick v]\nanimate\n\ndefine animate\nif <<(@show icon) = [1]> and <(@player state) = [go]>> then\n    if <(~icon.animation_frame) = [-1]> then\n        set [~icon.animation_frame v] to [0]\n        switch costume to (space v)\n        show\n    end\n    go to x: ([x position v] of [player hitbox v]) y: (([y position v] of [player hitbox v]) + (50))\n    set [~icon.animation_frame v] to (((~icon.animation_frame) + (~icon.animation_speed)) mod (2))\n    set [~icon.target_costume v] to (([floor v] of (~icon.animation_frame) ) + (1))\n    if <not <(costume [number v]) = (~icon.target_costume)>> then\n        switch costume to (~icon.target_costume)\n    end\nelse\n    set [~icon.animation_frame v] to [-1]\n    hide\nend\n\nwhen I receive [change game state v]\nif <(@game state) = [game]> then\n    stop [other scripts in sprite v]\n    set [@show icon v] to [0]\n    set [~icon.animation_frame v] to [0]\n    go to [front v] layer\n    go [backward v] (2) layers\n    hide\nelse\n    if < (@game state) contains [transition.to_]?> then\n        stop [other scripts in sprite v]\n        hide\n    end\nend\n\n@score fish\n\nwhen flag clicked\ninit\nset [~id v] to [0]\nset [~level v] to [0]\n\ndefine animate_idle (speed)\nturn right (([sin v] of (~animation_frame) ) * (2)) degrees\nchange size by (([sin v] of ((~animation_frame) * (5)) ) * (2))\nset [~animation_frame v] to (((~animation_frame) + (speed)) mod (360))\n\nwhen I receive [change game state v]\nif <(@game state) = [game]> then\n    if <(~ID) > [0]> then\n        reset\n        show\n        go to [front v] layer\n        go [backward v] (3) layers\n    else\n        switch costume to (join [fish] (@curr_level))\n        reset timer\n        show\n        go to [front v] layer\n        set [@score.level v] to [0]\n        show variable [@score.level v]\n    end\nelse\n    if < (@game state) contains [transition.target_]?> then\n        hide variable [@score.level v]\n    else\n        if < (@game state) contains [transition.to_]?> then\n            hide\n        end\n    end\nend\n\ndefine animate_collect\npoint in direction (90)\nif <(size) < [120]> then\n    change [~y v] by (1)\n    change size by (1)\n    change [ghost v] effect by (5)\nelse\n    if <not <(~type) = [salmon]>> then\n        set [ghost v] effect to (0)\n        switch costume to (collected v)\n        set size to (100) %\n        show\n        go to [front v] layer\n        go to x: (-205) y: ((125) - ((~ID.in_level) * (20)))\n    end\nend\n\ndefine scroll\ngo to x: ((~x) - (@camera x)) y: ((~y) - (@camera y))\nif <<([abs v] of (((~x) - (@camera x)) - (x position)) ) < [5]> and <([abs v] of (((~y) - (@camera y)) - (y position)) ) < [5]>> then\n    show\n    if <(~collected?) = [0]> then\n        animate_idle (~ROTATE_SPEED)\n        check_cat_collision [30]\n    end\nelse\n    hide\nend\nif <(~collected?) = [1]> then\n    animate_collect\nend\n\nwhen I receive [tick v]\nif <(~ID) = [0]> then\n    check_win_condition\nelse\n    if <(@curr_level) = (~level)> then\n        if <not <(costume [name v]) = [collected]>> then\n            scroll\n        end\n    else\n        hide\n    end\nend\n\nwhen I start as a clone\nreset\n\ndefine init\nhide\nswitch costume to (fish1 v)\nset size to (100) %\nset [ghost v] effect to (0)\nset volume to (100) %\ngo to x: (0) y: (0)\nset rotation style [all around v]\npoint in direction (90)\nshow list [~locations v]\nset [~rotate_speed v] to [5]\nset [~animation_frame v] to [0]\nset [~collected? v] to [0]\nset [~id v] to [0]\nset [~type v] to [0]\nset [~level v] to [0]\nset [~fish_points v] to [100]\nset [~id.in_level v] to [0]\nhide variable [@score.level v]\ndelete all of [~locations v]\nadd location | x: [300] y: [170] level: [1] type: [tuna] desc: [near spawn]\nadd location | x: [550] y: [545] level: [1] type: [tuna] desc: [middle tower roof]\nadd location | x: [790] y: [60] level: [1] type: [tuna] desc: [beach]\nadd location | x: [980] y: [530] level: [1] type: [tuna] desc: [right tower]\nadd location | x: [1400] y: [80] level: [1] type: [salmon] desc: [tree]\nadd location | x: [32] y: [1473] level: [2] type: [tuna] desc: [ledge above spawn]\nadd location | x: [367] y: [1698] level: [2] type: [tuna] desc: [midair above tree near spawn]\nadd location | x: [720] y: [1138] level: [2] type: [tuna] desc: [cave under tree]\nadd location | x: [775] y: [1655] level: [2] type: [tuna] desc: [middle ledge near tree]\nadd location | x: [1165] y: [1125] level: [2] type: [tuna] desc: [right cave by spikes]\nadd location | x: [1542] y: [1098] level: [2] type: [tuna] desc: [right wall above water]\nadd location | x: [1537] y: [1748] level: [2] type: [salmon] desc: [right high ledge]\nadd location | x: [685] y: [2918] level: [3] type: [tuna] desc: [above spawn tree]\nadd location | x: [95] y: [2828] level: [3] type: [tuna] desc: [upper left cave]\nadd location | x: [-25] y: [2118] level: [3] type: [tuna] desc: [bottom left secret tunnel]\nadd location | x: [1095] y: [2638] level: [3] type: [tuna] desc: [right chute pocket]\nadd location | x: [1135] y: [2848] level: [3] type: [tuna] desc: [upper right spike sandwich]\nadd location | x: [1275] y: [2248] level: [3] type: [tuna] desc: [right secret tunnel]\nadd location | x: [718] y: [2318] level: [3] type: [salmon] desc: [bottom middle cave boxes]\nadd location | x: [460] y: [3836] level: [4] type: [tuna] desc: [left mast]\nadd location | x: [850] y: [3886] level: [4] type: [tuna] desc: [middle mast]\nadd location | x: [530] y: [3526] level: [4] type: [tuna] desc: [upper tier left room]\nadd location | x: [1320] y: [3406] level: [4] type: [tuna] desc: [middle tier right room]\nadd location | x: [1040] y: [3286] level: [4] type: [tuna] desc: [bottom tier right room]\nadd location | x: [1530] y: [3266] level: [4] type: [tuna] desc: [outer right wall above water]\nadd location | x: [1430] y: [3786] level: [4] type: [tuna] desc: [upper right cabin roof]\nadd location | x: [35] y: [3295] level: [4] type: [tuna] desc: [left above water]\nadd location | x: [888] y: [3286] level: [4] type: [salmon] desc: [bottom tier middle hall]\n\ndefine check_cat_collision (dist_thresh)\nif <touching (player hitbox v)?> then\n    set [~collected? v] to [1]\n    change [@score.level v] by (~fish_points)\n    if <(~type) = [salmon]> then\n        set [@is_salmon_collected? v] to [1]\n        change [@score.level v] by ((~fish_points) * (4))\n    end\n    change [~y v] by (30)\n    set size to (100) %\n    start sound [Chomp v]\n    start sound [Coin v]\nend\n\ndefine add location | x: (x) y: (y) level: (level) type: (type) desc: (d)\nset [~id v] to ((length of [~locations v]) + (1))\nswitch costume to (type)\nset [~type v] to (type)\nadd (x) to [~locations v]\nadd (y) to [~locations v]\nif <not <(level) = (~level)>> then\n    set [~level v] to (level)\n    set [~id.in_level v] to [0]\nend\nif <not <(type) = [salmon]>> then\n    change [~id.in_level v] by (1)\nend\ncreate clone of (_myself_ v)\nset [~id v] to [0]\nset [~type v] to [0]\n\nwhen I receive [change_volume2 v]\nset volume to ((100) * (@sound_on?)) %\n\ndefine reset\nset [~x v] to (item (~ID) of [~locations v])\nset [~y v] to (item ((~ID) + (1)) of [~locations v])\nset [~animation_frame v] to [0]\nset [~collected? v] to [0]\nswitch costume to (~type)\nset size to (100) %\nset [ghost v] effect to (0)\ngo to x: ((~x) - (@camera x)) y: ((~y) - (@camera y))\npoint in direction (90)\n\ndefine update_score.level\nif <(timer) > [1]> then\n    reset timer\n    change [@score.level v] by (-1)\n    if <(@score.level) < [0]> then\n        set [@score.level v] to [0]\n    end\nend\n\ndefine update_score.overall\nif <(@score.level) > (item (@curr_level) of [score_per_level v])> then\n    replace item (@curr_level) of [score_per_level v] with (@score.level)\nend\nset [@score.overall v] to [0]\nset [~level v] to [0]\nrepeat (length of [score_per_level v])\n    change [~level v] by (1)\n    change [@score.overall v] by (item (~level) of [score_per_level v])\nend\n\ndefine check_win_condition\nif <(@is_salmon_collected?) = [1]> then\n    if <not <(@player state) = [win]>> then\n        update_score.overall\n        set [@player state v] to [win]\n        broadcast (change player state v)\n    end\nend\nif <not <(@player state) = [win]>> then\n    update_score.level\nend\n\n@checkpoints\n\nwhen flag clicked\ninit\n\ndefine check_player_dist (stride)\nset [~checkpt.index v] to [1]\nset [~checkpt.dist v] to (~checkpt.MAX_DIST)\nrepeat until <<(~checkpt.index) > (length of [~locations v])> or <(~checkpt.dist) < (~checkpt.MAX_DIST)>>\n    set [~checkpt.x v] to (item (~checkpt.index) of [~locations v])\n    set [~checkpt.y v] to (item ((~checkpt.index) + (1)) of [~locations v])\n    get_dist (~checkpt.x) (~checkpt.y) (([x position v] of [player hitbox v]) + (@camera x)) (([y position v] of [player hitbox v]) + (@camera y))\n    change [~checkpt.index v] by (stride)\nend\nif <(~checkpt.dist) < (~checkpt.MAX_DIST)> then\n    change [~checkpt.index v] by ((0) - (stride))\n    set [@checkpt_x v] to (~checkpt.x)\n    set [@checkpt_y v] to (~checkpt.y)\nend\n\ndefine get_dist (x1) (y1) (x2) (y2)\nset [~checkpt.dist v] to ([sqrt v] of ((((x1) - (x2)) * ((x1) - (x2))) + (((y1) - (y2)) * ((y1) - (y2)))) )\n\nwhen I receive [tick v]\ncheck_player_dist [2]\nupdate_checkpt\n\ndefine add location | x: (x) y: (y) desc: (desc)\nadd (x) to [~locations v]\nadd (y) to [~locations v]\n\ndefine init\nhide\nset size to (100) %\ngo to x: (0) y: (0)\nshow list [~locations v]\nset [@checkpt_x v] to [0]\nset [@checkpt_y v] to [0]\nset [~checkpt.max_dist v] to [50]\nset [~checkpt.spawn_index v] to [0]\nset [~timer v] to [0]\nset [ghost v] effect to (100)\nshow\ngo to [front v] layer\ndelete all of [~locations v]\nadd location | x: [840] y: [32] desc: [lvl1 beach]\nadd location | x: [960] y: [342] desc: [lvl1 right tower]\nadd location | x: [696] y: [1260] desc: [lvl2 coconut tree]\nadd location | x: [1198] y: [1094] desc: [lvl2 hidden cave]\nadd location | x: [1428] y: [1378] desc: [lvl2 spike ledge]\nadd location | x: [105] y: [2572] desc: [lvl3 west cave]\nadd location | x: [1275] y: [2767] desc: [lvl3 east cave]\nadd location | x: [720] y: [2237] desc: [lvl3 mid box cave]\nadd location | x: [965] y: [3860] desc: [lvl4 right mast]\nadd location | x: [1235] y: [3371] desc: [lvl4 mid tier right room]\nadd location | x: [350] y: [3371] desc: [lvl4 mid tier left room]\n\ndefine update_checkpt\nif <(~checkpt.dist) < (~checkpt.MAX_DIST)> then\n    if <not <(~checkpt.spawn_index) = (~checkpt.index)>> then\n        set [~checkpt.spawn_index v] to (~checkpt.index)\n        set [~timer v] to [80]\n        set [ghost v] effect to (100)\n    end\nend\nif <(~timer) > [0]> then\n    change [~timer v] by (-1)\n    if <(~timer) > [74]> then\n        change [ghost v] effect by (-20)\n    end\n    if <[49] > (~timer)> then\n        change [ghost v] effect by (2)\n    end\nend\n\nwhen I receive [change game state v]\nif <(@game state) = [game]> then\n    set [ghost v] effect to (100)\n    show\n    go to [front v] layer\nelse\n    if < (@game state) contains [transition.to_]?> then\n        stop [other scripts in sprite v]\n        hide\n    end\nend\n\n@buttons\n\nwhen flag clicked\nset [~action v] to [0]\nset [~timer v] to [0]\nhide\ngo to x: (0) y: (0)\nset rotation style [don't rotate v]\nset size to (80) %\nset volume to (100) %\n\ndefine add_button | action: (act) skin (skin) x: (x) y: (y)\nset [~action v] to (act)\nswitch costume to (skin)\nset [~costume v] to (costume [number v])\nset [~x v] to (x)\nset [~y v] to (y)\ngo to x: (x) y: (y)\ncreate clone of (_myself_ v)\nset [~action v] to [0]\n\nwhen this sprite clicked\nif <(~action) = [button.locked_level]> then\n    start sound [Crunch v]\n    set size to (105) %\nelse\n    if <(~action) = [button.start_level]> then\n        start sound [Connect v]\n        set size to (105) %\n    else\n        start sound [Suction Cup v]\n        set size to (105) %\n    end\nend\nbroadcast (~action)\n\nwhen I start as a clone\nshow\ngo to [front v] layer\ngo [backward v] (1) layers\nset volume to ((100) * (@sound_on?)) %\nrepeat until <(@game state) = [game]>\n    animate (0.5) (100) (120)\nend\n\ndefine animate (bounce) (min_size) (max_size)\nif <touching (mouse-pointer v)?> then\n    if <(size) < ((min_size) + (1))> then\n        start sound [Wood Tap v]\n    end\n    change size by (((max_size) - (size)) * (bounce))\nelse\n    change size by (((min_size) - (size)) * (bounce))\nend\n\ndefine animate_out (bounce)\nif <not <(~action) = [0]>> then\n    stop [other scripts in sprite v]\n    repeat (5)\n        set size to ((bounce) * (size)) %\n    end\n    hide\n    delete this clone\nend\n\nwhen I receive [change game state v]\nif <(~action) = [0]> then\n    if <(@game state) = [title]> then\n        add_button | action: [button.level_select] skin [start] x: [0] y: [-120]\n        add_button | action: [button.leaderboard] skin [leader] x: [75] y: [-120]\n        add_button | action: [change_volume] skin (join [sound] (@sound_on?)) x: [-75] y: [-120]\n    else\n        if <(@game state) = [game]> then\n            add_button | action: [button.help] skin [help] x: [125] y: [140]\n            add_button | action: [button.reset] skin [reset] x: [165] y: [140]\n            add_button | action: [button.title] skin [back] x: [205] y: [140]\n        else\n            if <(@game state) = [leaderboard]> then\n                add_button | action: [button.title] skin [back] x: [-200] y: [140]\n            else\n                if <(@game state) = [level_select]> then\n                    set [@curr_level v] to [1]\n                    add_button | action: [button.prev_lvl_thumb] skin [prev] x: [-200] y: [0]\n                    add_button | action: [button.next_lvl_thumb] skin [next] x: [200] y: [0]\n                    add_button | action: [button.reset] skin [level1] x: [0] y: [0]\n                    add_button | action: [button.title] skin [back] x: [-200] y: [140]\n                else\n                    animate_out [0.5]\n                end\n            end\n        end\n    end\nelse\n    animate_out [0.5]\nend\n\nwhen I receive [change_volume v]\nif <(~action) = [change_volume]> then\n    set [@sound_on? v] to ((1) - (@sound_on?))\n    switch costume to (join [sound] (@sound_on?))\n    broadcast (change_volume2 v)\nend\n\nwhen I receive [button.prev_lvl_thumb v]\nif <<(~action) = [button.reset]> or <(~action) = [button.locked_level]>> then\n    set [@curr_level v] to (((=max_levels) - (((((=max_levels) - (@curr_level)) + (1)) mod (=max_levels)) + (1))) + (1))\n    if <(@curr_level) > (@unlocked_levels)> then\n        set [~action v] to [button.locked_level]\n        switch costume to (join [locked] (@curr_level))\n    else\n        set [~action v] to [button.reset]\n        switch costume to (join [level] (@curr_level))\n    end\n    set size to (80) %\nend\n\nwhen I receive [tick v]\nif <<(@game state) = [game]> and <not <(~action) = [0]>>> then\n    animate (0.5) (100) (120)\nend\n\nwhen I receive [button.help v]\nif <(~action) = [button.help]> then\n    if <<(costume [name v]) = [help]> or <(costume [name v]) = [help2]>> then\n        next costume\n        go to [front v] layer\n        go to x: (0) y: (0)\n    else\n        switch costume to (help v)\n        go to [front v] layer\n        go [backward v] (3) layers\n        go to x: (125) y: (140)\n    end\nend\n\nwhen I receive [button.next_lvl_thumb v]\nif <<(~action) = [button.reset]> or <(~action) = [button.locked_level]>> then\n    set [@curr_level v] to (((@curr_level) mod (=max_levels)) + (1))\n    if <(@curr_level) > (@unlocked_levels)> then\n        set [~action v] to [button.locked_level]\n        switch costume to (join [locked] (@curr_level))\n    else\n        set [~action v] to [button.reset]\n        switch costume to (join [level] (@curr_level))\n    end\n    set size to (80) %\nend\n\nwhen I receive [change_volume2 v]\nset volume to ((100) * (@sound_on?)) %\n\nwhen I receive [button.reset v]\nif <(~action) = [0]> then\n    set [@game state v] to [transition.target_game]\n    broadcast (change game state v)\nelse\n    animate_out [0.5]\nend\n\nwhen I receive [button.title v]\nif <(~action) = [0]> then\n    set [@game state v] to [transition.target_title]\n    broadcast (change game state v)\nelse\n    animate_out [0.5]\nend\n\nwhen I receive [button.leaderboard v]\nif <(~action) = [0]> then\n    set [@game state v] to [transition.target_leaderboard]\n    broadcast (change game state v)\nelse\n    animate_out [0.5]\nend\n\nwhen I receive [button.level_select v]\nif <(~action) = [0]> then\n    set [@game state v] to [transition.target_level_select]\n    broadcast (change game state v)\nelse\n    animate_out [0.5]\nend\n\nwhen I receive [change player state v]\nif <(@player state) = [win]> then\n    if <(~action) = [0]> then\n        wait (2) seconds\n        add_button | action: [button.level_select] skin [win] x: [0] y: [0]\n    else\n        delete this clone\n    end\nend\n\n@rats\n\nwhen flag clicked\ninit\n\ndefine scroll\nswitch costume to (hitbox v)\nif <<([abs v] of (x position) ) < [220]> and <([abs v] of (y position) ) < [160]>> then\n    if <<([abs v] of (((~x) - (@camera x)) - (x position)) ) < [10]> and <([abs v] of (((~y) - (@camera y)) - (y position)) ) < [10]>> then\n        if <not <<(@player state) = [pause]> or <(@player state) = [talk]>>> then\n            update_pos\n        end\n    end\nend\ngo to x: ((~x) - (@camera x)) y: ((~y) - (@camera y))\nif <<([abs v] of (((~x) - (@camera x)) - (x position)) ) < [10]> and <([abs v] of (((~y) - (@camera y)) - (y position)) ) < [10]>> then\n    show\nelse\n    hide\nend\nanimate\n\nwhen I receive [tick v]\nif <<(~ID) > [0]> and <(~health) > [0]>> then\n    scroll\nend\n\nwhen I start as a clone\nreset\n\ndefine init\nset rotation style [left-right v]\npoint in direction (90)\nhide\nswitch costume to (idle v)\nset [ghost v] effect to (0)\nset size to (60) %\nshow list [~locations v]\nset [~id v] to [0]\nset [~force.gravity v] to [-1.1]\nset [~force.move v] to [5]\nset [~vel_x v] to [0]\nset [~vel_y v] to [0]\nset [~x v] to [0]\nset [~y v] to [0]\nset [~slope.max v] to [5]\nset [~animation.type v] to [idle]\nset [~animation.frame v] to [0]\nset [~max_health v] to [2]\nset [~health v] to (~max_health)\nset [~timer.hurt v] to [0]\ndelete all of [~locations v]\nadd location | x: [640] y: [32] desc: [lvl1 beach]\nadd location | x: [550] y: [350] desc: [lvl1 mid tower]\nadd location | x: [460] y: [1110] desc: [lvl2 rock island1]\nadd location | x: [1186] y: [1392] desc: [lvl2 cave top]\nadd location | x: [80] y: [2239] desc: [lvl3 left ledge]\nadd location | x: [490] y: [2099] desc: [lvl3 middle box cave, left entrance]\nadd location | x: [1272] y: [2099] desc: [lvl3 right tunnel to box cave]\nadd location | x: [1090] y: [2339] desc: [lvl3 right cave]\nadd location | x: [400] y: [3626] desc: [lvl4 left deck]\nadd location | x: [820] y: [3626] desc: [lvl4 right deck]\nadd location | x: [530] y: [3806] desc: [lvl4 left mast]\nadd location | x: [1240] y: [3754] desc: [lvl4 cabin roof]\nadd location | x: [670] y: [3244] desc: [lvl4 bottom tier hall]\nadd location | x: [1280] y: [3244] desc: [lvl4 bottom tier right room]\n\ndefine add location | x: (x) y: (y) desc: (desc)\nset [~id v] to ((length of [~locations v]) + (1))\nadd (x) to [~locations v]\nadd (y) to [~locations v]\ncreate clone of (_myself_ v)\nset [~id v] to [0]\n\ndefine update_pos\nupdate_vec (x position) (y position) (([abs v] of (([x position v] of [player hitbox v]) - (x position)) ) / (([x position v] of [player hitbox v]) - (x position)))\nswitch costume to (hitbox v)\ncheck_horizontal_collision (x position) (y position) (~vel_x) (([abs v] of (~vel_x) ) / (~vel_x))\ncheck_vertical_collision (y position) (([abs v] of (~vel_y) ) / (~vel_y))\n\ndefine check_vertical_collision (abs_y) (dir_y)\nchange y by (~vel_y)\nrepeat until <not <<touching (level hitbox v)?> or <touching (objects v)?>>>\n    change y by ((0) - (dir_y))\n    set [~vel_y v] to [0]\nend\nchange [~y v] by ((y position) - (abs_y))\n\ndefine check_horizontal_collision (abs_x) (abs_y) (vel_x) (dir_vel_x)\nset [~slope v] to [0]\nchange x by (vel_x)\nrepeat until <<not <<touching (level hitbox v)?> or <touching (objects v)?>>> or <(~slope) > (~slope.max)>>\n    change y by (1)\n    change [~slope v] by (1)\nend\nif <(~slope) > (~slope.max)> then\n    set y to (abs_y)\n    set [~vel_x v] to [0]\n    repeat until <not <<touching (level hitbox v)?> or <touching (objects v)?>>>\n        change [~vel_x v] by (1)\n        change x by (((((~vel_x) mod (2)) * (2)) - (1)) * (~vel_x))\n    end\n    set [~vel_x v] to [0]\nelse\n    set [~vel_x v] to ((vel_x) - (((~slope) * (1.5)) * (dir_vel_x)))\nend\nchange [~x v] by ((x position) - (abs_x))\nchange [~y v] by ((y position) - (abs_y))\n\ndefine reset\nset [~x v] to (item (~ID) of [~locations v])\nset [~y v] to (item ((~ID) + (1)) of [~locations v])\nset [~vel_y v] to [0]\nset [~health v] to (~max_health)\nset [~timer.hurt v] to [0]\nset [~timer.attack v] to [0]\nset [~animation.type v] to [idle]\ngo to x: ((~x) - (@camera x)) y: ((~y) - (@camera y))\nset [ghost v] effect to (0)\nswitch costume to (idle v)\ngo to [front v] layer\ngo [backward v] (7) layers\n\ndefine update_vec (abs_x) (abs_y) (dir_of_player)\nif <<<(distance to [player hitbox v]) < [200]> and <(~timer.hurt) = [0]>> and <(~health) > [0.5]>> then\n    switch costume to (attackbox v)\n    set y to ([y position v] of [player hitbox v])\n    if <not <touching (player hitbox v)?>> then\n        set [~vel_x v] to ((~FORCE.move) * (dir_of_player))\n        set [~animation.type v] to [walk]\n        set [~timer.attack v] to [10]\n    else\n        if <([abs v] of ((abs_y) - ([y position v] of [player hitbox v])) ) < [50]> then\n            set [~vel_x v] to [0]\n        end\n    end\n    set y to (abs_y)\nelse\n    set [~vel_x v] to ((~vel_x) * (0.5))\nend\nchange [~vel_y v] by (~FORCE.gravity)\nif <(~health) > [0.5]> then\n    check_is_attacking_player (dir_of_player)\n    check_player_is_attacking (dir_of_player)\n    if <touching (water v)?> then\n        set [~timer.hurt v] to [100]\n        set [~animation.type v] to [die]\n        set [~health v] to [0.5]\n        start sound [Squeaky Toy v]\n        start sound [Plunge v]\n    end\nend\n\ndefine animate\nif <(~animation.type) = [walk]> then\n    if <(~vel_x) > [0]> then\n        point in direction (90)\n    else\n        if <(~vel_x) < [0]> then\n            point in direction (-90)\n        end\n    end\n    if <(~vel_x) = [0]> then\n        set [~animation.type v] to [idle]\n    end\nend\nswitch costume to (~animation.type)\nif <(~animation.type) = [idle]> then\n    set [~animation.frame v] to (((~animation.frame) + (0.05)) mod (2))\nelse\n    if <(~animation.type) = [walk]> then\n        set [~animation.frame v] to (((~animation.frame) + (0.5)) mod (5))\n    else\n        if <(~animation.type) = [attack]> then\n            set [~animation.frame v] to (((~animation.frame) + (0.5)) mod (5))\n            if <([floor v] of (~animation.frame) ) = [4]> then\n                set [~animation.type v] to [idle]\n            end\n        else\n            if <(~animation.type) = [hurt]> then\n                set [~animation.frame v] to [0]\n                if <(~vel_y) = [0]> then\n                    set [~animation.type v] to [idle]\n                end\n            else\n                set [~animation.frame v] to [0]\n            end\n        end\n    end\nend\nswitch costume to ((costume [number v]) + ([floor v] of (~animation.frame) ))\nif <(~timer.hurt) > [0]> then\n    change [~timer.hurt v] by (-1)\nend\nif <(~timer.attack) > [0]> then\n    change [~timer.attack v] by (-1)\nend\nif <(~animation.type) = [die]> then\n    set [ghost v] effect to ((100) - (~timer.hurt))\n    if <(~timer.hurt) = [0]> then\n        hide\n        set [~health v] to [0]\n    end\nelse\n    if <(~timer.hurt) > [0]> then\n        set [ghost v] effect to ((30) * ((round ((~timer.hurt) / (5))) mod (2)))\n    else\n        set [ghost v] effect to (0)\n    end\nend\n\nwhen I receive [change game state v]\nif <(~ID) > [0]> then\n    if <(@game state) = [transition.to_game]> then\n        hide\n        wait (0.1) seconds\n        reset\n        scroll\n    else\n        if < (@game state) contains [transition.to_]?> then\n            stop [other scripts in sprite v]\n            hide\n        else\n            if <(@game state) = [game]> then\n                repeat until <not <(@game state) = [game]>>\n                    if <<(~animation.type) = [walk]> and <<([abs v] of (x position) ) < [220]> and <([abs v] of (y position) ) < [160]>>> then\n                        play sound [Gallop v] until done\n                    end\n                end\n            end\n        end\n    end\nend\n\ndefine check_player_is_attacking (dir_of_player)\nif <<(~timer.hurt) = [0]> and <(@player state) = [attack]>> then\n    if <<(([direction v] of [player visual v]) * (dir_of_player)) < [0]> and <<(distance to [player hitbox v]) < [80]> and <([abs v] of (([y position v] of [player hitbox v]) - (y position)) ) < [30]>>> then\n        if <(~timer.hurt) = [0]> then\n            change [~health v] by (-1)\n            set [~timer.hurt v] to [30]\n            set [~timer.attack v] to [30]\n            start sound [Pew v]\n            set [~vel_x v] to ((~FORCE.move) * ((0) - (dir_of_player)))\n            set [~vel_y v] to (~FORCE.move)\n            if <(~health) < [1]> then\n                set [~timer.hurt v] to [100]\n                set [~animation.type v] to [die]\n                set [~health v] to [0.5]\n                start sound [Squeaky Toy v]\n            else\n                set [~animation.type v] to [hurt]\n            end\n        end\n    end\nend\n\ndefine check_is_attacking_player (dir_of_player)\nif <(@player.is_invincible) = [0]> then\n    if <(~timer.attack) = [0]> then\n        switch costume to (attackbox v)\n        if <<touching (player hitbox v)?> and <((direction) * (dir_of_player)) > [0]>> then\n            set [~timer.attack v] to [30]\n            set [~animation.type v] to [attack]\n            start sound [Rip v]\n            set [@player state v] to [hurt]\n            broadcast (change player state v)\n        end\n    end\nend\n\n@objects\n\nwhen flag clicked\ninit\n\ndefine scroll\nif <<([abs v] of (x position) ) < [220]> and <([abs v] of (y position) ) < [160]>> then\n    if <<([abs v] of (((~x) - (@camera x)) - (x position)) ) < [10]> and <([abs v] of (((~y) - (@camera y)) - (y position)) ) < [10]>> then\n        if <not <<(@player state) = [pause]> or <(@player state) = [talk]>>> then\n            update_pos (item ((~ID) + (4)) of [~locations v])\n            camera_magnet (@player state)\n        end\n    end\nend\ngo to x: ((~x) - (@camera x)) y: ((~y) - (@camera y))\nif <<([abs v] of (((~x) - (@camera x)) - (x position)) ) < [10]> and <([abs v] of (((~y) - (@camera y)) - (y position)) ) < [10]>> then\n    show\nelse\n    hide\nend\n\nwhen I receive [tick v]\nif <(~ID) > [0]> then\n    scroll\nend\n\nwhen I start as a clone\nreset\n\ndefine init\nset rotation style [all around v]\npoint in direction (90)\nhide\nset size to (100) %\nshow list [~locations v]\nset [~static? v] to [0]\nset [~pushable? v] to [0]\nset [~id v] to [0]\nset [~force.gravity v] to [-1.1]\nset [~force.friction v] to [0.5]\nset [~force.push v] to [4]\nset [~vel_x v] to [0]\nset [~vel_y v] to [0]\nset [~x v] to [0]\nset [~y v] to [0]\nset [~is_player_pushing? v] to [0]\nset [~in_water? v] to [0]\nset [~slope.max v] to [5]\nset [@camera x v] to [0]\ndelete all of [~locations v]\nadd location | x: [1050] y: [342] static? [0] pushable? [1] costume: [crate] desc: [lvl1]\nadd location | x: [890] y: [1365] static? [1] pushable? [1] costume: [coconut] desc: [lvl2]\nadd location | x: [220] y: [2575] static? [0] pushable? [1] costume: [crate] desc: [lvl3 west cave]\nadd location | x: [1260] y: [2339] static? [0] pushable? [1] costume: [crate] desc: [lvl3 east]\nadd location | x: [965] y: [3625] static? [0] pushable? [1] costume: [crate] desc: [lvl4 deck]\nadd location | x: [935] y: [3370] static? [0] pushable? [1] costume: [crate] desc: [lvl4 inside]\n\ndefine add location | x: (x) y: (y) static? (h) pushable? (p) costume: (c) desc: (d)\nset [~id v] to ((length of [~locations v]) + (1))\nadd (x) to [~locations v]\nadd (y) to [~locations v]\nadd (h) to [~locations v]\nadd (p) to [~locations v]\nadd (c) to [~locations v]\nswitch costume to (c)\ncreate clone of (_myself_ v)\nset [~id v] to [0]\n\ndefine update_pos (costume)\nif <(~static?) = [0]> then\n    switch costume to (join (costume) [_hitbox])\n    check_vertical_collision (y position)\n    if <(~pushable?) = [1]> then\n        update_vec (x position) (([abs v] of (([x position v] of [player hitbox v]) - (x position)) ) / (([x position v] of [player hitbox v]) - (x position)))\n        check_horizontal_collision (x position) (y position) (~vel_x) (([abs v] of (~vel_x) ) / (~vel_x))\n    end\n    switch costume to (costume)\n    check_water_collision\nelse\n    if <(~in_water?) = [1]> then\n        animate [0.25] [5]\n    end\nend\n\nwhen I receive [player action v]\nif <<(~ID) > [0]> and <(distance to [player hitbox v]) < [70]>> then\n    wait until <(@player state) = [attack]>\n    set [~static? v] to [0]\nend\n\ndefine check_vertical_collision (abs_y)\nchange [~vel_y v] by (~FORCE.gravity)\nchange y by (~vel_y)\nrepeat until <not <touching (level hitbox v)?>>\n    change y by (1)\n    set [~vel_y v] to [0]\nend\nchange [~y v] by ((y position) - (abs_y))\n\ndefine check_horizontal_collision (abs_x) (abs_y) (vel_x) (dir_vel_x)\nset [~slope v] to [0]\nchange x by (vel_x)\nrepeat until <<not <touching (level hitbox v)?>> or <(~slope) > (~slope.max)>>\n    change y by (1)\n    change [~slope v] by (1)\nend\nif <(~slope) > (~slope.max)> then\n    set y to (abs_y)\n    set [~vel_x v] to [0]\n    repeat until <not <touching (level hitbox v)?>>\n        change [~vel_x v] by (1)\n        change x by (((((~vel_x) mod (2)) * (2)) - (1)) * (~vel_x))\n    end\n    set [~vel_x v] to [0]\nelse\n    set [~vel_x v] to ((vel_x) - (((~slope) * (1.5)) * (dir_vel_x)))\nend\nchange [~x v] by ((x position) - (abs_x))\nchange [~y v] by ((y position) - (abs_y))\nif <(costume [name v]) = [ball_hitbox]> then\n    turn right ((x position) - (abs_x)) degrees\nend\ngo to x: (abs_x) y: (abs_y)\nif <(~is_player_pushing?) = [1]> then\n    set [@player.xvel v] to (~vel_x)\n    change [@player.x v] by ((x position) - (abs_x))\n    change [@player.y v] by ((y position) - (abs_y))\nend\n\ndefine reset\nset [~x v] to (item (~ID) of [~locations v])\nset [~y v] to (item ((~ID) + (1)) of [~locations v])\nset [~static? v] to (item ((~ID) + (2)) of [~locations v])\nset [~pushable? v] to (item ((~ID) + (3)) of [~locations v])\nswitch costume to (item ((~ID) + (4)) of [~locations v])\nset [~vel_y v] to [0]\nset [~in_water? v] to [0]\nset [~is_player_pushing? v] to [0]\nset [~animation.timer v] to [0]\ngo to [back v] layer\ngo [forward v] (10) layers\n\ndefine update_vec (abs_x) (dir_of_player)\nchange x by (((2.5) * (~FORCE.push)) * (dir_of_player))\nif <<<<<(@Input.LEFT) = [true]> and <(dir_of_player) = [1]>> or <<(@Input.RIGHT) = [true]> and <(dir_of_player) = [-1]>>> and <(@player.yvel) = [0]>> and <touching (player hitbox v)?>> then\n    set [~is_player_pushing? v] to [1]\nelse\n    set [~is_player_pushing? v] to [0]\nend\nset x to (abs_x)\nif <(~is_player_pushing?) = [1]> then\n    set [~vel_x v] to ((~FORCE.push) * (<(@Input.RIGHT) = [true]> - <(@Input.LEFT) = [true]>))\nelse\n    set [~vel_x v] to ((~vel_x) * (~FORCE.friction))\nend\n\nwhen I receive [change game state v]\nif <(~ID) > [0]> then\n    if <(@game state) = [transition.to_game]> then\n        hide\n        wait (0.1) seconds\n        reset\n        scroll\n    else\n        if < (@game state) contains [transition.to_]?> then\n            stop [other scripts in sprite v]\n            hide\n        else\n            if <(@game state) = [game]> then\n                repeat until <not <(@game state) = [game]>>\n                    if <(~is_player_pushing?) = [1]> then\n                        play sound [Ocean Wave v] until done\n                    end\n                end\n            end\n        end\n    end\nend\n\ndefine check_water_collision\nif <<(~in_water?) = [0]> and <touching (water v)?>> then\n    set [~in_water? v] to [1]\n    start sound [Plunge v]\nelse\n    if <<(~in_water?) = [1]> and <(~vel_y) = [0]>> then\n        set [~static? v] to [1]\n        set [~vel_y v] to [0]\n    end\nend\n\ndefine camera_magnet (player_state)\nif <<(~static?) = [0]> and <<(~vel_y) < ((5) * (~FORCE.gravity))> and <(y position) < [0]>>> then\n    set [@player state v] to [camera_magnet]\n    change [@camera x v] by ((0.5) * ((~x) - (@camera x)))\n    change [@camera y v] by ((0.5) * ((~y) - (@camera y)))\nelse\n    if <<<(@player state) = [camera_magnet]> and <(~vel_y) = [0]>> and <(~animation.timer) > [150]>> then\n        set [@player state v] to [camera_return]\n    end\nend\n\ndefine animate (range) (speed)\nset [~animation.timer v] to (((~animation.timer) + (speed)) mod (360))\nchange [~y v] by (([sin v] of (~animation.timer) ) * (range))\n\n@spikes\n\nwhen I receive [tick v]\nif <(~panel_set.row_ID) > [0]> then\n    scroll\nend\n\nwhen flag clicked\ninit\n\ndefine scroll\nset [~x v] to (round ((=panel_width) - (((@camera x) + (((~panel_set.col_ID) mod (2)) * (=panel_width))) mod ((2) * (=panel_width)))))\nset [~y v] to (round ((=panel_height) - (((@camera y) + (((~panel_set.row_ID) mod (2)) * (=panel_height))) mod ((2) * (=panel_height)))))\nupdate_costume\ngo to x: (~x) y: (~y)\nif <<(round ((~x) - (x position))) < [5]> and <(round ((~y) - (y position))) < [5]>> then\n    check_player_collision\nelse\n    hide\nend\n\ndefine update_costume\nset [~costume.col_id v] to ([floor v] of (((((~x) + (@camera x)) + ((=panel_width) / (2))) / (=map_width_px)) * (=map_width_panels)) )\nset [~costume.row_id v] to ([floor v] of (((((~y) + (@camera y)) + ((=panel_height) / (2))) / (=map_height_px)) * (=map_height_panels)) )\nset [~costume.target_id v] to ((((=map_width_panels) * (~costume.row_ID)) + (~costume.col_ID)) + (1))\nif <<<(~costume.row_ID) > [-1]> and <(~costume.row_ID) < (=map_height_panels)>> and <<(~costume.col_ID) > [-1]> and <(~costume.col_ID) < (=map_width_panels)>>> then\n    show\n    if <not <(costume [number v]) = (~costume.target_ID)>> then\n        switch costume to (~costume.target_ID)\n    end\n    animate [2] [5]\nelse\n    hide\nend\n\nwhen I receive [change game state v]\nif <(~panel_set.row_ID) > [0]> then\n    if <(@game state) = [transition.to_game]> then\n        wait (0.1) seconds\n        scroll\n        show\n        go to [front v] layer\n        go [backward v] (4) layers\n    else\n        if < (@game state) contains [transition.to_]?> then\n            stop [other scripts in sprite v]\n            hide\n        end\n    end\nend\n\ndefine init\nhide\nset size to (100) %\ngo to x: (0) y: (0)\nset rotation style [don't rotate v]\nset [~panel_set.row_id v] to [0]\nset [~panel_set.col_id v] to [0]\nset [~animation.timer v] to [0]\nclear graphic effects\nswitch costume to (lvl1_\(0,0\) v)\nrepeat (2)\n    change [~panel_set.row_id v] by (1)\n    repeat (2)\n        change [~panel_set.col_id v] by (1)\n        create clone of (_myself_ v)\n        next costume\n    end\nend\nset [~panel_set.row_id v] to [0]\nset [~panel_set.col_id v] to [0]\n\ndefine check_player_collision\nif <(@player.is_invincible) = [0]> then\n    if <touching (player hitbox v)?> then\n        set [@player state v] to [hurt]\n        broadcast (change player state v)\n    end\nend\n\ndefine animate (range) (speed)\nset [~animation.timer v] to (((~animation.timer) + (speed)) mod (360))\nchange [color v] effect by (([sin v] of (~animation.timer) ) * (range))\n\n@false walls\n\nwhen I receive [tick v]\nif <(~panel_set.row_ID) > [0]> then\n    scroll\nend\n\nwhen flag clicked\ninit\n\ndefine scroll\nset [~x v] to (round ((=panel_width) - (((@camera x) + (((~panel_set.col_ID) mod (2)) * (=panel_width))) mod ((2) * (=panel_width)))))\nset [~y v] to (round ((=panel_height) - (((@camera y) + (((~panel_set.row_ID) mod (2)) * (=panel_height))) mod ((2) * (=panel_height)))))\nupdate_costume\ngo to x: (~x) y: (~y)\nif <<([abs v] of ((~x) - (x position)) ) < [5]> and <([abs v] of ((~y) - (y position)) ) < [5]>> then\n    check_player_collision\nelse\n    hide\nend\n\ndefine update_costume\nset [~costume.col_id v] to ([floor v] of (((((~x) + (@camera x)) + ((=panel_width) / (2))) / (=map_width_px)) * (=map_width_panels)) )\nset [~costume.row_id v] to ([floor v] of (((((~y) + (@camera y)) + ((=panel_height) / (2))) / (=map_height_px)) * (=map_height_panels)) )\nset [~costume.target_id v] to ((((=map_width_panels) * (~costume.row_ID)) + (~costume.col_ID)) + (1))\nif <<<(~costume.row_ID) > [-1]> and <(~costume.row_ID) < (=map_height_panels)>> and <<(~costume.col_ID) > [-1]> and <(~costume.col_ID) < (=map_width_panels)>>> then\n    show\n    if <not <(costume [number v]) = (~costume.target_ID)>> then\n        switch costume to (~costume.target_ID)\n    end\nelse\n    hide\nend\n\nwhen I receive [change game state v]\nif <(~panel_set.row_ID) > [0]> then\n    if <(@game state) = [transition.to_game]> then\n        wait (0.1) seconds\n        scroll\n        show\n        go to [front v] layer\n        go [backward v] (4) layers\n    else\n        if < (@game state) contains [transition.to_]?> then\n            stop [other scripts in sprite v]\n            hide\n        end\n    end\nend\n\ndefine init\nhide\nset size to (100) %\ngo to x: (0) y: (0)\nset rotation style [don't rotate v]\nset [~panel_set.row_id v] to [0]\nset [~panel_set.col_id v] to [0]\nset [~animation.timer v] to [0]\nclear graphic effects\nswitch costume to (lvl1_\(0,0\) v)\nrepeat (2)\n    change [~panel_set.row_id v] by (1)\n    repeat (2)\n        change [~panel_set.col_id v] by (1)\n        create clone of (_myself_ v)\n        next costume\n    end\nend\nset [~panel_set.row_id v] to [0]\nset [~panel_set.col_id v] to [0]\n\ndefine check_player_collision\nif <touching (player hitbox v)?> then\n    if <(~animation.timer) = [0]> then\n        set [~animation.timer v] to [1]\n        set [ghost v] effect to (40)\n    end\nelse\n    if <(~animation.timer) = [1]> then\n        set [~animation.timer v] to [0]\n        set [ghost v] effect to (0)\n    end\nend\n\n@overlay\n\nwhen flag clicked\ngo to x: (0) y: (0)\npoint in direction (90)\nset rotation style [all around v]\nset [~angle v] to [0]\nhide\n\ndefine title | wiggle: (v) turn: (dr) d_size (ds) d_popup (ds') x: (x) y: (y) size: (s)\ngo to x: (x) y: (y)\nswitch costume to (title v)\nshow\ngo to [front v] layer\ngo [backward v] (1) layers\nset size to (100) %\nrepeat (10)\n    set [~angle v] to (((~angle) + (v)) mod (360))\n    turn right (([sin v] of ((~angle) + (100)) ) * (dr)) degrees\n    set size to ((size) + (((s) - (size)) * (ds'))) %\nend\nforever\n    set [~angle v] to (((~angle) + (v)) mod (360))\n    turn right (([sin v] of ((~angle) + (100)) ) * (dr)) degrees\n    change size by (([sin v] of (~angle) ) * (ds))\nend\n\nwhen I receive [change game state v]\nif <(@game state) = [transition.to_game]> then\n    stop [other scripts in sprite v]\n    go to x: (0) y: (0)\n    point in direction (90)\n    switch costume to (health3 v)\n    set size to (100) %\n    show\nelse\n    if <(@game state) = [game]> then\n        go to [front v] layer\n    else\n        if <<(@game state) = [transition.to_title]> or <(@game state) = [title]>> then\n            title | wiggle: (10) turn: (0.5) d_size (0.5) d_popup (1) x: (0) y: (50) size: (100)\n        else\n            stop [other scripts in sprite v]\n            if <(costume [name v]) = [title]> then\n                animate_out\n            else\n                hide\n            end\n        end\n    end\nend\n\ndefine animate_out\nrepeat (2)\n    set size to ((0.5) * (size)) %\nend\nhide\n\nwhen I receive [change player state v]\nif <(@player state) = [pause]> then\n    switch costume to (edit v)\n    go to [front v] layer\nend\n\nswitch costume to (thumbnail v)\nset size to (100) %\ngo to x: (0) y: (0)\npoint in direction (90)\nset rotation style [all around v]\nshow\ngo to [front v] layer\n\nwhen I receive [tick v]\nif <not <(@player state) = [pause]>> then\n    if <not <(costume [name v]) = (join [health] (@player.health))>> then\n        switch costume to (join [health] (@player.health))\n        go to [front v] layer\n    end\nend\n\n@leaderboard\n\nwhen flag clicked\nhide\nset [~leaderboard_max_rank v] to [5]\nset [~bounce_vel v] to [10]\nset size to (100) %\ngo to x: (0) y: (0)\n\ndefine encode_str (string)\nset [~i v] to [0]\nset [~temp v] to []\nrepeat (length of (string))\n    change [~i v] by (1)\n    switch costume to (? v)\n    switch costume to (letter (~i) of (string))\n    set [~temp v] to (join (~temp) ((costume [number v]) + (10)))\nend\n\ndefine decode_str (string)\nset [~i v] to [1]\nset [~temp v] to []\nrepeat until <(~i) > (length of (string))>\n    switch costume to (space v)\n    set [~char v] to ((join (letter (~i) of (string)) (letter ((~i) + (1)) of (string))) - (10))\n    if <(~char) > [0]> then\n        switch costume to (~char)\n    end\n    set [~temp v] to (join (~temp) (costume [name v]))\n    change [~i v] by (2)\nend\n\ndefine get_cloud_leaderboard\ndelete all of [leaderboard v]\nrepeat ((2) * (~leaderboard_max_rank))\n    add [] to [leaderboard v]\nend\ndecode_leader_entry (☁ leader1) [1]\ndecode_leader_entry (☁ leader2) [2]\ndecode_leader_entry (☁ leader3) [3]\ndecode_leader_entry (☁ leader4) [4]\ndecode_leader_entry (☁ leader5) [5]\n\ndefine update_leaderboard (name) (score)\nget_cloud_leaderboard\nif <[leaderboard v] contains (name)?> then\n    set [~i v] to (item # of (name) in [leaderboard v])\n    if <(score) > (item ((~i) + (1)) of [leaderboard v])> then\n        repeat (2)\n            delete (~i) of [leaderboard v]\n        end\n    else\n        stop [this script v]\n    end\nend\nset [~i v] to [1]\nrepeat until <(~i) > ((~leaderboard_max_rank) * (2))>\n    if <(score) > (item ((~i) + (1)) of [leaderboard v])> then\n        insert (name) at (~i) of [leaderboard v] \n        insert (score) at ((~i) + (1)) of [leaderboard v] \n        set [~i v] to ((~leaderboard_max_rank) * (2))\n        repeat until <not <(length of [leaderboard v]) > ((~leaderboard_max_rank) * (2))>>\n            delete (length of [leaderboard v]) of [leaderboard v]\n        end\n        write_cloud_leaderboard\n        stop [this script v]\n    end\n    change [~i v] by (2)\nend\n\ndefine encode_name&score (name) (score)\nset [~temp v] to ((length of (name)) + (10))\nset [~temp v] to (join (~temp) (name))\nset [~temp v] to (join (~temp) (score))\nencode_str (~temp)\n\ndefine decode_leader_entry (enc) (rank)\nset [~temp v] to (enc)\nif <(enc) = [0]> then\n    encode_name&score [-] [0]\nend\ndecode_str (~temp)\nset [~i v] to ((join (letter (1) of (~temp)) (letter (2) of (~temp))) - (10))\nset [~char v] to [2]\nreplace item (((rank) * (2)) - (1)) of [leaderboard v] with []\nrepeat (~i)\n    change [~char v] by (1)\n    replace item (((rank) * (2)) - (1)) of [leaderboard v] with (join (item (((rank) * (2)) - (1)) of [leaderboard v]) (letter (~char) of (~temp)))\nend\nreplace item ((rank) * (2)) of [leaderboard v] with []\nrepeat ((length of (~temp)) - ((2) + (~i)))\n    change [~char v] by (1)\n    replace item ((rank) * (2)) of [leaderboard v] with (join (item ((rank) * (2)) of [leaderboard v]) (letter (~char) of (~temp)))\nend\n\ndefine animate_in (bounce) (min_size) (max_size)\nset [~bounce_vel v] to [10]\nset size to (bounce) %\nclear graphic effects\nswitch costume to (background v)\ngo to x: (0) y: (0)\nshow\ngo to [front v] layer\nrepeat until <([abs v] of (~bounce_vel) ) < [0.01]>\n    set [~bounce_vel v] to (((~bounce_vel) * (bounce)) + (((max_size) - (size)) * ((1) - (bounce))))\n    change size by (~bounce_vel)\nend\n\ndefine animate_out\nclear graphic effects\nswitch costume to (background v)\ngo to x: (0) y: (0)\nshow\nset size to (100) %\nrepeat (2)\n    set size to ((0.5) * (size)) %\nend\nhide\n\ndefine display_leader_entry (rank)\nprint (join (join (rank) [. ]) (item (((rank) * (2)) - (1)) of [leaderboard v])) [-135] ((-25) * ((rank) - (1))) [80] [200] [25]\nprint (item ((rank) * (2)) of [leaderboard v]) [55] ((-25) * ((rank) - (1))) [80] [200] [200]\n\ndefine print (text) (lx) (ly) (size) (color) (rx)\nset size to (size) %\nset [brightness v] effect to (color)\ngo to x: (lx) y: (ly)\nset [~char v] to [0]\nrepeat (length of (text))\n    change [~char v] by (1)\n    if <(x position) < (rx)> then\n        switch costume to (space v)\n        switch costume to (letter (~char) of (text))\n        stamp\n        change x by ((item ((costume [number v]) - (1)) of [~font_widths v]) * ((size) / (100)))\n    else\n        switch costume to (. v)\n        repeat (3)\n            stamp\n            change x by ((item ((costume [number v]) - (1)) of [~font_widths v]) * ((size) / (100)))\n        end\n        stop [this script v]\n    end\nend\n\nwhen I receive [change game state v]\nif <(@game state) = [transition.to_title]> then\n    stop [other scripts in sprite v]\n    erase all\nelse\n    if <(@game state) = [leaderboard]> then\n        update_leaderboard (username) (@score.overall)\n        switch costume to (background v)\n        animate_in [0.5] [40] [110]\n        stamp\n        hide\n        set [~i v] to [0]\n        repeat (~leaderboard_max_rank)\n            change [~i v] by (1)\n            display_leader_entry (~i)\n        end\n        print [Your current score:] [-135] [-125] [80] [200] [25]\n        print (@score.overall) [55] [-125] [80] [200] [200]\n    else\n        if <(@game state) = [level_select]> then\n            update_leaderboard (username) (@score.overall)\n        end\n    end\nend\n\nwhen [f v] key pressed\nif <(username) = [amylaser]> then\n    switch backdrop to (title v)\n    set_font_widths\n    erase all\n    print [Test 1234567890 quick, brown foxes jump - over the lazy_dog. Hello?!] [-200] [-125] [80] [200] [240]\nend\n\ndefine set_font_widths\ndelete all of [~font_widths v]\nswitch costume to (1 v)\nset size to (100) %\nset [brightness v] effect to (200)\nshow\ngo to [front v] layer\nrepeat until <(costume [name v]) = [space]>\n    erase all\n    go to x: (0) y: (-100)\n    stamp\n    repeat until <not <touching color (#ffffff)?>>\n        change x by (1)\n    end\n    change x by (2)\n    add (x position) to [~font_widths v]\n    next costume\nend\nadd [8] to [~font_widths v]\n\ndefine write_cloud_leaderboard\nencode_name&score (item (1) of [leaderboard v]) (item (2) of [leaderboard v])\nif <not <(☁ leader1) = (~temp)>> then\n    set [☁ leader1 v] to (~temp)\n    wait (0.1) seconds\nend\nencode_name&score (item (3) of [leaderboard v]) (item (4) of [leaderboard v])\nif <not <(☁ leader2) = (~temp)>> then\n    set [☁ leader2 v] to (~temp)\n    wait (0.1) seconds\nend\nencode_name&score (item (5) of [leaderboard v]) (item (6) of [leaderboard v])\nif <not <(☁ leader3) = (~temp)>> then\n    set [☁ leader3 v] to (~temp)\n    wait (0.1) seconds\nend\nencode_name&score (item (7) of [leaderboard v]) (item (8) of [leaderboard v])\nif <not <(☁ leader4) = (~temp)>> then\n    set [☁ leader4 v] to (~temp)\n    wait (0.1) seconds\nend\nencode_name&score (item (9) of [leaderboard v]) (item (10) of [leaderboard v])\nif <not <(☁ leader5) = (~temp)>> then\n    set [☁ leader5 v] to (~temp)\nend\n\ndefine reset_leaderboard\nset [☁ leader1 v] to [0]\nset [☁ leader2 v] to [0]\nset [☁ leader3 v] to [0]\nset [☁ leader4 v] to [0]\nset [☁ leader5 v] to [0]\nupdate_leaderboard [WitherCroxly] [4302]\nupdate_leaderboard [dandelion308] [4296]\nupdate_leaderboard [earth7] [4295]\nupdate_leaderboard [amylaser_beta] [4283]\nupdate_leaderboard [lolimnotanoob] [4276]\n\n@parallax\n\nwhen flag clicked\ninit\n\nwhen I receive [tick v]\nif <(~col_ID) > [0]> then\n    scroll\nend\n\nwhen I receive [change game state v]\nif <<(@game state) = [transition.to_game]> or <(@game state) = [game]>> then\n    if <(~col_ID) > [0]> then\n        switch costume to (join [level] (@curr_level))\n        show\n        go to [back v] layer\n        wait (0.1) seconds\n        scroll\n    else\n        stop [other scripts in sprite v]\n        hide\n    end\nelse\n    if <<not < (@game state) contains [transition.target]?>> and << (@game state) contains [title]?> or < (@game state) contains [level_select]?>>> then\n        title_visuals\n    else\n        stop [other scripts in sprite v]\n        hide\n    end\nend\n\ndefine init\nhide\nswitch costume to (title v)\ngo to x: (0) y: (0)\nset rotation style [don't rotate v]\nset [~col_id v] to [0]\nrepeat (2)\n    change [~col_id v] by (1)\n    create clone of (_myself_ v)\nend\nset [~col_id v] to [0]\n\ndefine title_visuals\nif <(~col_ID) > [0]> then\n    hide\nelse\n    switch costume to (title v)\n    show\n    go to [back v] layer\n    forever\n        turn right (5) degrees\n        go to x: (([cos v] of (direction) ) * (5)) y: (([sin v] of (direction) ) * (5))\n    end\nend\n\ndefine scroll\nset x to (((=panel_width) * ((~col_ID) - (1))) - (((=panel_width) / (=level_width_px)) * (@camera x)))\nset y to ((0) - (((=level_height_px) / (=map_height_px)) * ((@camera y) - (item ((@curr_level) * (2)) of [level spawns v]))))\n\n@transitions\n\nwhen flag clicked\ngo to x: (0) y: (0)\nset size to (100) %\nhide\n\nwhen I receive [change game state v]\ncheck transition from [transition.target_game] to [transition.to_game] to [game]\ncheck transition from [transition.target_title] to [transition.to_title] to [title]\ncheck transition from [transition.target_leaderboard] to [transition.to_leaderboard] to [leaderboard]\ncheck transition from [transition.target_level_select] to [transition.to_level_select] to [level_select]\n\ndefine fade in\nset [ghost v] effect to (100)\nshow\nrepeat (10)\n    go to [front v] layer\n    change [ghost v] effect by (-10)\nend\n\ndefine fade out\nset [ghost v] effect to (0)\nshow\nrepeat (10)\n    go to [front v] layer\n    change [ghost v] effect by (10)\nend\nhide\n\ndefine check transition from (start) to (bridge) to (end)\nif <(@game state) = (start)> then\n    fade in\n    set [@game state v] to (bridge)\n    broadcast (change game state v)\nelse\n    if <(@game state) = (bridge)> then\n        wait (1) seconds\n        fade out\n        set [@game state v] to (end)\n        broadcast (change game state v)\n    end\nend\n\n@logo3\n\nwhen flag clicked\nhide\ngo to x: (0) y: (0)\nswitch costume to (backdrop1 v)\nset [ghost v] effect to (0)\nshow\ngo to [front v] layer\nset [_cloneid v] to [0]\nrepeat (2)\n    change [_cloneid v] by (1)\n    create clone of (_myself_ v)\nend\nwait (3.5) seconds\nset [@game state v] to [transition.target_title]\nbroadcast (change game state v)\nfade [-1] [10]\nhide\n\nwhen I receive [end logo v]\nrepeat (10)\n    change [ghost v] effect by (10)\nend\ndelete this clone\n\nwhen I start as a clone\nshow\ngo to [front v] layer\nif <(_cloneID) = [1]> then\n    switch costume to (costume1 v)\n    fade in and out [0] [1.8]\nelse\n    switch costume to (costume2 v)\n    fade in and out [0.5] [0.8]\nend\n\ndefine fade in and out (delay) (pause)\nset [ghost v] effect to (100)\nwait (delay) seconds\nfade [1] [5]\nwait (pause) seconds\nfade [-1] [5]\ndelete this clone\n\ndefine fade (in\(1\)/out\(-1\)) (speed)\nrepeat ((100) / (speed))\n    change [ghost v] effect by (((0) - (in\(1\)/out\(-1\))) * (speed))\nend\n\nset [@game state v] to [transition.target_title]\nbroadcast (change game state v)\n\n