3D Platformer
@Stage\n\nwhen stage clicked\nbroadcast (mouse_down v)\n\nwhen flag clicked\nset volume to (45) %\nset [@music? v] to [0]\n\nwhen [m v] key pressed\ntoggle music\n\ndefine toggle music\nif <(@music?) = [1]> then\n    stop music\nelse\n    start music\nend\n\nwhen I receive [start music v]\nstart music\n\ndefine start music\nset [@music? v] to [1]\nrepeat until <(@music?) = [0]>\n    play sound (@music_name) until done\nend\n\ndefine stop music\nset [@music? v] to [0]\nstop all sounds\n\nwhen I receive [restart music v]\nset [@music? v] to [0]\nstop all sounds\nwait (0) seconds\nstart music\n\nwhen I receive [stop music v]\nstop music\n\n@blank\n\nwhen flag clicked\nplay sound [\[Free Sound Effects\]2haha4 v] until done\n\n@Settings\n\nwhen flag clicked\nset @enums\n// [General settings]\nset [@shadows? v] to [1]\nset [@show_tris? v] to [0]\nset [@res v] to [2]\nset [@edit_mode? v] to [0]\nset [@show_prims/dynamic/objs v] to [0]\nset [@show_bsp_tree? v] to [0]\nset [@fps v] to [30]\nset [@glide/walk v] to [1]\nset [@first_person? v] to [1]\nset [@ground_plane? v] to [1]\nset [@mobile_controls v] to [1]\nset [@auto_disable_shadows_fps_thresh v] to [18]\n// [Camera settings]\nset [@c_roll v] to [0]\nset [@c_pitch v] to [0]\nset [@c_yaw v] to [0]\nset [@cam_tilt v] to [20]\nset [@camx v] to [0]\nset [@camy v] to [1]\nset [@camz v] to [10]\nset [@z_near v] to [-1.5]\nset [@z_far v] to [100]\nset [@cam_z_offset v] to [1.7]\nset [@z_clip_dist v] to [-0.01]\n// [Light direction and strength settings]\nset [@lightx v] to ((1) * ([sqrt v] of ((1) / (4)) ))\nset [@lighty v] to ((-1) * ([sqrt v] of ((5) / (12)) ))\nset [@lightz v] to ((-1) * ([sqrt v] of ((1) / (3)) ))\nset [@ambient_max v] to [0.65]\nset [@time_of_day v] to [12]\n// [Physics engine settings]\nset [@player_r v] to [0.2]\nset [@μ v] to [0.1]\nset [@penetration_thresh v] to [0.0001]\nset [@restitution v] to [0.2]\nset [@gravity_x v] to [0]\nset [@gravity v] to [-0.009]\nset [@ground_y v] to [0]\nset [@collision_sounds? v] to [1]\nset [@collision_pitch/volume? v] to [1]\n// [Player Start Location]\nset [@player_x v] to [0]\nset [@player_y v] to ((0.5) + (@player_r))\nset [@player_z v] to [0]\n// [BSP settings]\nset [@gen_bsp? v] to [1]\nset [@coplanar_thresh v] to [0.023]\n// [Other]\nset [@rot_speed v] to [1.5]\nset [@max_tilt v] to [20]\nset [@zn*180 v] to ((@z_near) * (180))\nset [@skybox_width v] to ((1063) * (2))\nset [@dev? v] to [0]\n\nwhen [v v] key pressed\ntoggle settings\n\ndefine show vars\nshow variable [@show_tris? v]\nshow variable [@tris visible v]\nshow variable [@fps v]\nshow variable [@cam_z_offset v]\nshow variable [@z_far v]\nshow variable [@show_prims/dynamic/objs v]\nshow variable [@shadows? v]\nshow variable [@time_of_day v]\nshow variable [@glide/walk v]\nshow variable [@player_x v]\nshow variable [@player_y v]\nshow variable [@player_z v]\nshow variable [@player_x_vel v]\nshow variable [@player_y_vel v]\nshow variable [@player_z_vel v]\nshow variable [@first_person? v]\nshow variable [@show_bsp_tree? v]\nshow variable [@mobile_controls v]\nshow variable [@bsp: split count v]\n\ndefine hide vars\nhide variable [@show_tris? v]\nhide variable [@tris visible v]\nhide variable [@fps v]\nhide variable [@cam_z_offset v]\nhide variable [@z_far v]\nhide variable [@show_prims/dynamic/objs v]\nhide variable [@shadows? v]\nhide variable [@time_of_day v]\nhide variable [@glide/walk v]\nhide variable [@player_x v]\nhide variable [@player_y v]\nhide variable [@player_z v]\nhide variable [@player_x_vel v]\nhide variable [@player_y_vel v]\nhide variable [@player_z_vel v]\nhide variable [@first_person? v]\nhide variable [@show_bsp_tree? v]\nhide variable [@mobile_controls v]\nhide variable [@bsp: split count v]\n\nwhen flag clicked\nhide\nset [_show_vars v] to [0]\nset [_show_fps v] to [1]\nhide vars\nshow variable [@fps v]\n\ndefine set @enums\nset [@enum p:shad_off_scale v] to [2]\nset [@enum p:sprite_scale_y v] to [3]\nset [@enum p:*subtree_root v] to [2]\nset [@enum p:radius v] to [4]\nset [@enum p:*node v] to [5]\nset [@enum p:*object v] to [6]\nset [@enum p:material v] to [7]\nset [@enum p:illumination v] to [8]\nset [@enum p:normal v] to [9]\nset [@enum p:*bsphere v] to [10]\nset [@enum p:zclip? v] to [11]\nset [@enum p:show_front? v] to [12]\nset [@enum p:size v] to [13]\nset [@enum v:size v] to [4]\nset [@enum o:hidden? v] to [11]\nset [@enum o:*vleft v] to [12]\nset [@enum o:*nleft v] to [14]\nset [@enum o:**pleft v] to [16]\nset [@enum o:dynamic_parent v] to [18]\nset [@enum o:*container_prim v] to [19]\nset [@enum o:*bsphere v] to [20]\nset [@enum o:size v] to [21]\nset [@enum t:middle v] to [1]\nset [@enum t:tail v] to [2]\nset [@enum t:ori v] to [3]\nset [@enum t:edge_a v] to [4]\nset [@enum t:parent v] to [8]\nset [@enum t:size v] to [9]\nset [@enum m:size v] to [9]\n\ndefine toggle settings\nif <(_show_vars) = [1]> then\n    set [_show_fps v] to [0]\n    hide vars\nelse\n    set [_show_fps v] to [1]\n    show vars\nend\nset [_show_vars v] to ((1) - (_show_vars))\n\nwhen I receive [toggle settings v]\ntoggle settings\n\nwhen [f v] key pressed\nif <(_show_fps) = [1]> then\n    hide variable [@fps v]\nelse\n    show variable [@fps v]\nend\nset [_show_fps v] to ((1) - (_show_fps))\n\ndefine // (label)\n\n@Setup\n\ndefine _tmp = SquaredDist ( A (ax) (ay) (az) B (bx) (by) (bz) )\nset [_tmp v] to (((((ax) - (bx)) * ((ax) - (bx))) + (((ay) - (by)) * ((ay) - (by)))) + (((az) - (bz)) * ((az) - (bz))))\n\ndefine _inside = point in tri (concise) (px) (py) (ax) (ay) (bx) (by) (cx) (cy)\nset [_inside? v] to <(((px) - (ax)) * ((by) - (ay))) > (((bx) - (ax)) * ((py) - (ay)))>\nif <<(((px) - (bx)) * ((cy) - (by))) > (((cx) - (bx)) * ((py) - (by)))> = (_inside?)> then\n    set [_inside? v] to <<(((px) - (cx)) * ((ay) - (cy))) > (((ax) - (cx)) * ((py) - (cy)))> = (_inside?)>\n    stop [this script v]\nend\nset [_inside? v] to \n\ndefine _*prim = primitives.add_polygon_from_idxs_tmp( *object (*obj) mat (mat) pen radius (pen radius) )\nset [_ptr v] to ((length of [idxs_poly v]) + (1))\nadd (item (1) of [_idxs_tmp v]) to [idxs_poly v]\nadd [] to [idxs_poly v]\nset [i v] to [2]\nrepeat ((length of [_idxs_tmp v]) - (1))\n    _ptr_to_node = idxs_poly.insert_after ( ((length of [idxs_poly v]) - (1)) (item (i) of [_idxs_tmp v]) )\n    change [i v] by (1)\nend\nreplace item (length of [idxs_poly v]) of [idxs_poly v] with (_ptr)\n_*prim = primitives.add_prim ( [POLYGON] (_ptr) [] [] (pen radius) *obj (*obj) material (mat) has_normal? <not <(length of [_idxs_tmp v]) < [3]>> )\n\ndefine Polygon Tessellation ( (node num) (direction) (principal_axis) )\nchange [debug v] by (1)\nset [_n v] to (node num)\nset [_n+1 v] to (((_n) mod (length of [_idxs_tmp v])) + (1))\nset [_n+2 v] to (((_n+1) mod (length of [_idxs_tmp v])) + (1))\ndelete all of [_tmp v]\nadd (item (_n) of [_idxs_tmp v]) to [_tmp v]\nadd (item (_n+1) of [_idxs_tmp v]) to [_tmp v]\nadd (item (_n+2) of [_idxs_tmp v]) to [_tmp v]\nif <(length of [_idxs_tmp v]) = [3]> then\n    idxs_tri.add_tri_indices ( (item (1) of [_tmp v]) (item (2) of [_tmp v]) (item (3) of [_tmp v]) )\n    stop [this script v]\nend\nif <(direction) > [0]> then\n    add_tri_to_tmp ( (item (1) of [_tmp v]) (item (2) of [_tmp v]) (item (3) of [_tmp v]) )\nelse\n    add_tri_to_tmp ( (item (3) of [_tmp v]) (item (2) of [_tmp v]) (item (1) of [_tmp v]) )\nend\ndelete ((10) + (principal_axis)) of [_tmp v]\ndelete ((7) + (principal_axis)) of [_tmp v]\ndelete ((4) + (principal_axis)) of [_tmp v]\n_angle = MvG's angle ( (item (8) of [_tmp v]) (item (9) of [_tmp v]) (item (6) of [_tmp v]) (item (7) of [_tmp v]) (item (4) of [_tmp v]) (item (5) of [_tmp v]) )\nif <(debug) > [300]> then\n    stop [this script v]\nend\nif <<[179.95] < (_angle)> and <(_angle) < [180.05]>> then\n    delete (_n+1) of [_idxs_tmp v]\n    if <(_n+1) < (_n)> then\n        change [_n v] by (-1)\n    end\n    Polygon Tessellation ( (_n) (direction) (principal_axis) )\n    stop [this script v]\nend\nif <<(_angle) > [180]> or <(_angle) < [0.05]>> then\n    Polygon Tessellation ( (_n+1) (direction) (principal_axis) )\n    stop [this script v]\nend\n_inside? = is point inside tri (item (4) of [_tmp v]) (item (5) of [_tmp v]) (item (6) of [_tmp v]) (item (7) of [_tmp v]) (item (8) of [_tmp v]) (item (9) of [_tmp v]) (((_n+2) mod (length of [_idxs_tmp v])) + (1))\nif <(_inside?) = [1]> then\n    Polygon Tessellation ( (_n+1) (direction) (principal_axis) )\nelse\n    idxs_tri.add_tri_indices ( (item (1) of [_tmp v]) (item (2) of [_tmp v]) (item (3) of [_tmp v]) )\n    delete (_n+1) of [_idxs_tmp v]\n    if <(_n+1) < (_n)> then\n        change [_n v] by (-1)\n    end\n    Polygon Tessellation ( (_n) (direction) (principal_axis) )\nend\n\nwhen flag clicked\nset [@rendering_active? v] to [0]\nset [@*player_obj v] to [0]\nset [@*player_prim v] to [0]\nset [@*player_shadow_prim v] to [0]\nset volume to (100) %\nhide\nsetup\n\ndefine _angle = MvG's angle ( (x1) (y1) (x2) (y2) (x3) (y3) )\nset [_x v] to ((x1) - (x2))\nset [_x2 v] to ((x3) - (x2))\nset [_y v] to ((y1) - (y2))\nset [_y2 v] to ((y3) - (y2))\nset [_dot v] to (((_x) * (_x2)) + ((_y) * (_y2)))\nset [_det v] to (((_x) * (_y2)) - ((_y) * (_x2)))\n_atan2 = atan2( (_det) (_dot) )\nset [_angle v] to (_atan2)\n\ndefine _idxs_tmp.set_range ( (left) (right) (step) <reverse?> )\ndelete all of [_idxs_tmp v]\nset [i v] to (left)\nrepeat until <(i) = (right)>\n    add (i) to [_idxs_tmp v]\n    repeat (step)\n        if <(i) = [null]> then\n            set [i v] to [null]\n        else\n            set [i v] to (item ((i) + (3)) of [vertex_buff v])\n        end\n    end\nend\nif <reverse?> then\n    set [i v] to [1]\n    repeat (length of [_idxs_tmp v])\n        insert (item (length of [_idxs_tmp v]) of [_idxs_tmp v]) at (i) of [_idxs_tmp v] \n        delete (length of [_idxs_tmp v]) of [_idxs_tmp v]\n        change [i v] by (1)\n    end\nend\n\ndefine add_tri_to_tmp ( (idx_1) (idx_2) (idx_3) )\nadd (item ((idx_1) + (0)) of [vertex_buff v]) to [_tmp v]\nadd (item ((idx_1) + (1)) of [vertex_buff v]) to [_tmp v]\nadd (item ((idx_1) + (2)) of [vertex_buff v]) to [_tmp v]\nadd (item ((idx_2) + (0)) of [vertex_buff v]) to [_tmp v]\nadd (item ((idx_2) + (1)) of [vertex_buff v]) to [_tmp v]\nadd (item ((idx_2) + (2)) of [vertex_buff v]) to [_tmp v]\nadd (item ((idx_3) + (0)) of [vertex_buff v]) to [_tmp v]\nadd (item ((idx_3) + (1)) of [vertex_buff v]) to [_tmp v]\nadd (item ((idx_3) + (2)) of [vertex_buff v]) to [_tmp v]\n\ndefine _x, _y, _z = calc_unit_normal (x1) (y1) (z1) (x2) (y2) (z2) (x3) (y3) (z3)\n_x, _y, _z = 3D_cross_prod ( ((x2) - (x1)) ((y2) - (y1)) ((z2) - (z1)) ((x3) - (x1)) ((y3) - (y1)) ((z3) - (z1)) )\nset [_tmp v] to ([sqrt v] of (((_x) * (_x)) + (((_y) * (_y)) + ((_z) * (_z)))) )\nset [_x v] to ((_x) / (_tmp))\nset [_y v] to ((_y) / (_tmp))\nset [_z v] to ((_z) / (_tmp))\n\ndefine draw_tri (x1) (y1) (x2) (y2) (x3) (y3)\npen up\ngo to x: ((x1) * (100)) y: ((y1) * (100))\npen down\ngo to x: ((x2) * (100)) y: ((y2) * (100))\ngo to x: ((x3) * (100)) y: ((y3) * (100))\ngo to x: ((x1) * (100)) y: ((y1) * (100))\nchange pen (color v) by (3)\n\ndefine _inside? = is point inside tri (x1) (y1) (x2) (y2) (x3) (y3) (start)\nset [i v] to (start)\nset [_inside? v] to [0]\nrepeat until <<(_inside?) = [1]> or <(i) = ((start) + ((length of [_idxs_tmp v]) - (3)))>>\n    set [_tmp v] to (item ((((i) - (1)) mod (length of [_idxs_tmp v])) + (1)) of [_idxs_tmp v])\n    _inside = point in tri (concise) (item (_tmp) of [vertex_buff v]) (item ((_tmp) + (1)) of [vertex_buff v]) (x1) (y1) (x2) (y2) (x3) (y3)\n    change [i v] by (1)\nend\n\ndefine idxs_tri.add_tri_indices ( (idx_1) (idx_2) (idx_3) )\nadd (idx_1) to [idxs_tri v]\nadd (idx_2) to [idxs_tri v]\nadd (idx_3) to [idxs_tri v]\n\ndefine setup scene objects\nset [@ground_y v] to [-1]\nMaterials.newMaterial ( label [Blue] pointer to secondary colour material [] sfx sound name [] texture costume name [] Colour (R,G,B,A) [0,140,255] no collider? <> bounciness (0-1) [0] )\nMaterials.newMaterial ( label [Yellow] pointer to secondary colour material [] sfx sound name [] texture costume name [] Colour (R,G,B,A) [230,255,20] no collider? <> bounciness (0-1) [] )\nMaterials.newMaterial ( label [Green] pointer to secondary colour material [] sfx sound name [] texture costume name [] Colour (R,G,B,A) [70,250,90] no collider? <> bounciness (0-1) [] )\nMaterials.newMaterial ( label [Red] pointer to secondary colour material [] sfx sound name [] texture costume name [] Colour (R,G,B,A) [255,0,0] no collider? <> bounciness (0-1) [] )\nGameObjects.createPlayer ( position [0] [1] [0] first person view? <> Fixed shadow? \nGameObjects.createCuboid ( Scale [2] [0.2] [2] Position [0] [0] [0] Rotation [] [] [] Material [Yellow] name [Start] )\nGameObjects.createCuboid ( Scale [1.6] [0.2] [1.2] Position [1.2] [1.4] [-2.5] Rotation [] [] [] Material [Blue] name [Platform 2] )\nGameObjects.createCuboid ( Scale [1.3] [0.2] [1.2] Position [0.6] [3.6] [-5.2] Rotation [] [] [] Material [Blue] name [Platform 3] )\nGameObjects.createCuboid ( Scale [0.5] [0.2] [3] Position [0] [5.2] [-9.2] Rotation [] [] [] Material [Blue] name [Platform 4] )\nGameObjects.createCuboid ( Scale [1.3] [0.2] [6.4] Position [0] [5.6] [-14.6] Rotation [] [] [] Material [Blue] name [Platform 5] )\nGameObjects.createCuboid ( Scale [2.4] [0.2] [3.4] Position [0] [5.2] [-20] Rotation [] [] [] Material [Blue] name [Platform 6] )\nGameObjects.createCuboid ( Scale [1.7] [0.2] [1.7] Position [0] [5.2] [-23] Rotation [] [] [] Material [Green] name [End] )\nGameObjects.createCone ( Radius [0.2] Height [0.3] Number of sides [4] Position [0] [5.3] [-8.6] Rotation [] [] [] Material [Red] name [Spike 1] )\nGameObjects.createCone ( Radius [0.2] Height [0.3] Number of sides [4] Position [0] [5.3] [-9.8] Rotation [] [] [] Material [Red] name [Spike 2] )\nGameObjects.createCuboid ( Scale [0.4] [0.4] [0.4] Position [0] [5.6] [-20] Rotation [] [] [] Material [Red] name [Enemy] )\nMaterials.newMaterial ( label [Eye] pointer to secondary colour material [] sfx sound name [] texture costume name [Eye] Colour (R,G,B,A) [] no collider? <> bounciness (0-1) [] )\nGameObjects.create3DPoint ( material name [Eye] radius [0.2] scale y [] position [0] [0] [-0.3] parent [Enemy] shadow offset dist [] name [Eye] )\nGameObjects.create3DLine ( Pt A [0] [5.2] [-23] Pt B [0] [6.4] [-23] material [Yellow] radius [0.02] parent [] name [Flag Pole] )\nMaterials.newMaterial ( label [Flag] pointer to secondary colour material [] sfx sound name [] texture costume name [] Colour (R,G,B,A) [70,250,90] no collider? <> bounciness (0-1) [] )\nMaterials.setDoubleSided (comma separated list of materials: [Flag] )\nGameObjects.createTri/Quad (Pt A [0] [6.1] [-23] Pt B [0] [6.4] [-23] Pt C [-0.5] [6.4] [-23] Pt D (leave blank if tri) [-0.5] [6.1] [-23] parent [Flag Pole] material [Flag] name [Flag Fabric] )\nMaterials.setSfx ( material [Yellow] sound effect label [Concrete Step] )\nMaterials.setSfx ( material [Blue] sound effect label [Concrete Step] )\nMaterials.setSfx ( material [Green] sound effect label [Concrete Step] )\nGameObjects.setDynamic ( object name [Enemy] parent object [] )\nGameObjects.setDynamic ( object name [Platform 3] parent object [] )\nGameObjects.setDynamic ( object name [Platform 5] parent object [] )\nGameObjects.offsetDynamicCenter ( object name [Platform 3] offset [0] [-1] [0] )\n\ndefine _*obj = GameObjects.instantiate ( position (x) (y) (z) rotation (α) (β) (γ) hidden? <hidden?> name (name) dynamic? <dynamic?> )\nset [_*obj v] to ((length of [gameobjects v]) + (1))\nset [_tmp v] to (name)\nset [i v] to [2]\nrepeat until <not <[_obj v] contains (_tmp)?>>\n    set [_tmp v] to (join (_tmp) (i))\n    change [i v] by (1)\nend\nadd (_tmp) to [gameobjects v]\nadd (x) to [gameobjects v]\nadd (y) to [gameobjects v]\nadd (z) to [gameobjects v]\nadd (α) to [gameobjects v]\nadd (β) to [gameobjects v]\nadd (γ) to [gameobjects v]\nadd [1] to [gameobjects v]\nadd [1] to [gameobjects v]\nadd [1] to [gameobjects v]\nadd (colour) to [gameobjects v]\nadd <<hidden?> = [1]> to [gameobjects v]\nadd [v_left] to [gameobjects v]\nadd [v_right] to [gameobjects v]\nadd [n_left] to [gameobjects v]\nadd [n_right] to [gameobjects v]\nadd [p_left] to [gameobjects v]\nadd [p_right] to [gameobjects v]\nif <dynamic?> then\n    add [ROOT] to [gameobjects v]\nelse\n    add [0] to [gameobjects v]\nend\nadd [] to [gameobjects v]\nadd [*bsphere] to [gameobjects v]\nif <not <<<<<<(x) = [0]> and <(y) = [0]>> and <(z) = [0]>> and <(α) = [0]>> and <(β) = [0]>> and <(γ) = [0]>>> then\n    GameObjects.set_updated ( (_*obj) )\nend\n\ndefine GameObjects.createPrismUsing@polygon ( height (height) Position (x) (y) (z) Rotation (yaw) (pitch) (roll) Material (mat) name (name) )\nset [_n v] to ((length of [@polygon v]) / (2))\nset [_*vstart v] to ((length of [vertex_buff v]) + (1))\n_*obj = GameObjects.instantiate ( position (x) (y) (z) rotation (yaw) (pitch) (roll) hidden? <> name (name) dynamic? <> )\nset [i v] to [1]\nset [_ptr v] to (@*vertex_buff_tail)\nrepeat (_n)\n    _ptr = vertex_buff.insert_after (xyz (item (i) of [@polygon v]) ((-1) * ((height) / (2))) (item ((i) + (1)) of [@polygon v]) *node (_ptr) *obj (_*obj) )\n    _ptr = vertex_buff.insert_after (xyz (item (i) of [@polygon v]) ((height) / (2)) (item ((i) + (1)) of [@polygon v]) *node (_ptr) *obj (_*obj) )\n    change [i v] by (2)\nend\nset [j v] to [0]\nrepeat (_n)\n    delete all of [_idxs_tmp v]\n    add ((_*vstart) + (j)) to [_idxs_tmp v]\n    add ((_*vstart) + (((j) + ((2) * (@enum v:SIZE))) mod (((2) * (@enum v:SIZE)) * (_n)))) to [_idxs_tmp v]\n    add ((_*vstart) + (((j) + ((3) * (@enum v:SIZE))) mod (((2) * (@enum v:SIZE)) * (_n)))) to [_idxs_tmp v]\n    add ((_*vstart) + (((j) + ((1) * (@enum v:SIZE))) mod (((2) * (@enum v:SIZE)) * (_n)))) to [_idxs_tmp v]\n    _*prim = primitives.add_polygon_from_idxs_tmp( *object (_*obj) mat (mat) pen radius [] )\n    change [j v] by ((2) * (@enum v:SIZE))\nend\n_idxs_tmp.set_range ( (_*vstart) [null] [2]  )\n_*prim = primitives.add_polygon_from_idxs_tmp( *object (_*obj) mat (mat) pen radius [] )\n_idxs_tmp.set_range ( ((_*vstart) + (@enum v:SIZE)) [null] [2] <> )\n_*prim = primitives.add_polygon_from_idxs_tmp( *object (_*obj) mat (mat) pen radius [] )\n\ndefine _ptr = vertex_buff.insert_after (xyz (x) (y) (z) *node (*node) *obj (*obj) )\nif <<(length of [vertex_buff v]) < (*node)> or <((*node) + (0)) = [0]>> then\n    set [_tmp v] to [null]\nelse\n    set [_tmp v] to (item ((*node) + (3)) of [vertex_buff v])\n    replace item ((*node) + (3)) of [vertex_buff v] with ((length of [vertex_buff v]) + (1))\nend\nadd (x) to [vertex_buff v]\nset [_ptr v] to (length of [vertex_buff v])\nadd (y) to [vertex_buff v]\nadd (z) to [vertex_buff v]\nadd (_tmp) to [vertex_buff v]\nif <not <(*obj) = [*obj]>> then\n    if <<(length of [vertex_buff v]) = [0]> or <(item ((*obj) + (@enum o:*VLEFT)) of [gameobjects v]) = [v_left]>> then\n        replace item (((@*vertex_buff_tail_obj) + (@enum o:*VLEFT)) + (1)) of [gameobjects v] with (_ptr)\n        replace item ((*obj) + (@enum o:*VLEFT)) of [gameobjects v] with (_ptr)\n        replace item (((*obj) + (@enum o:*VLEFT)) + (1)) of [gameobjects v] with [null]\n    end\nend\nif <(*node) = (@*vertex_buff_tail)> then\n    set [@*vertex_buff_tail v] to (_ptr)\n    if <not <(*obj) = (@*vertex_buff_tail_obj)>> then\n        set [@*vertex_buff_tail_obj v] to (*obj)\n    end\nend\n\ndefine setup\nreset all ()\nMaterials.newMaterial ( label [None] pointer to secondary colour material [] sfx sound name [] texture costume name [] Colour (R,G,B,A) [255,255,255] no collider? <> bounciness (0-1) [] )\nsetup scene objects\nbroadcast (init gameobject transforms v) and wait\nGameObjects.generate_bounding_spheres()\nprimitives.compute_normals()\nset [i v] to [1]\nrepeat (length of [vertex_buff v])\n    add (item (i) of [vertex_buff v]) to [vertex_world v]\n    change [i v] by (1)\nend\nbroadcast (world_transform v) and wait\nif <(@gen_BSP?) = [1]> then\n    broadcast (gen bsp v) and wait\nend\nprimitives.generate_bounding_spheres ()\nbroadcast (world_transform v) and wait\nbroadcast (final prim setup v) and wait\nrepeat ((length of [vertex_world v]) * (2))\n    add [] to [vertex v]\nend\nset [@days_since_2000 v] to (days since 2000)\nset [@rendering_active? v] to [1]\n\ndefine GameObjects.importFromOBJFile ( CW orientated? <is_clockwise?> scale (s) align_center? <center?> .obj file data (leave blank if using _OBJ list) (data) )\nif <not <(data) = []>> then\n    _OBJ.decode_from_data ( (data) )\nend\nset [_*vstart v] to ((length of [vertex_buff v]) + (1))\nset [_*vstart_obj v] to (_*vstart)\nset [_*nstart v] to ((length of [normal_buff v]) + (1))\nset [_*obj v] to [null]\nset [_*obj v] to [1]\nset [_radius v] to []\nset [_material v] to [1]\nrepeat until <(_*OBJ) = ((length of [_obj v]) + (1))>\n    _cmd,_*OBJ + 1 = _OBJ.read_line ( )\n    handle cmd (_cmd) <is_clockwise?>\nend\nvertex_buff.scale ( left (_*vstart_obj) right ((length of [vertex_buff v]) + (1)) scale (<(s) = []> + (s)) )\nif <center?> then\n    vertex_buff.center_range (*left (_*vstart_obj) *right ((length of [vertex_buff v]) + (1)) )\nend\nif <(length of [bsp.tree v]) > [0]> then\n    insert ((length of [bsp.tree v]) / (@enum t:SIZE)) at (1) of [bsp.tree v] \n    insert [2] at (1) of [bsp.tree v] \n    set [@bsp._*prims.tail v] to ((item # of [null] in [bsp.tree v]) - (2))\n    set [@gen_bsp? v] to [0]\n    set [i v] to [3]\n    repeat (item (2) of [bsp.tree v])\n        set [j v] to (item (i) of [bsp.tree v])\n        repeat until <<(item ((j) + (1)) of [bsp._*prims v]) = (item ((i) + (@enum t:TAIL)) of [bsp.tree v])> or <(j) = [null]>>\n            replace item ((item (j) of [bsp._*prims v]) + (@enum p:*NODE)) of [primitives v] with (i)\n            set [j v] to (item ((j) + (2)) of [bsp._*prims v])\n        end\n        change [i v] by (@enum t:SIZE)\n    end\nend\n\ndefine _cmd,_*OBJ + 1 = _OBJ.read_line ( )\nset [_cmd v] to (item (_*OBJ) of [_obj v])\nchange [_*obj v] by (1)\n\ndefine _split_buff = split ( (s) (delim) )\ndelete all of [_split_buff v]\nset [i v] to [1]\nset [_tmp2 v] to []\nrepeat (length of (s))\n    set [_tmp v] to (letter (i) of (s))\n    if <(_tmp) = (delim)> then\n        add (_tmp2) to [_split_buff v]\n        set [_tmp2 v] to []\n    else\n        set [_tmp2 v] to (join (_tmp2) (_tmp))\n    end\n    change [i v] by (1)\nend\nadd (_tmp2) to [_split_buff v]\n\ndefine _tmp = max_of_triple ( (a) (b) (c) )\nif <<(a) > (b)> and <(a) > (c)>> then\n    set [_tmp v] to (a)\nelse\n    if <<(b) > (a)> and <(b) > (c)>> then\n        set [_tmp v] to (b)\n    else\n        set [_tmp v] to (c)\n    end\nend\n\ndefine vertex_buff.center_range (*left (*l) *right (*r) )\ndelete all of [_tmp v]\nset [j v] to [0]\nrepeat (3)\n    set [_min v] to ((1) / (0))\n    set [_max v] to ((-1) / (0))\n    set [i v] to (*l)\n    repeat (((*r) - (*l)) / (4))\n        set [_tmp v] to (item ((i) + (j)) of [vertex_buff v])\n        if <(_tmp) < (_min)> then\n            set [_min v] to (_tmp)\n        end\n        if <(_tmp) > (_max)> then\n            set [_max v] to (_tmp)\n        end\n        set [i v] to (item ((i) + (3)) of [vertex_buff v])\n    end\n    add ((_max) - (_min)) to [_tmp v]\n    set [i v] to (*l)\n    repeat (((*r) - (*l)) / (4))\n        replace item ((i) + (j)) of [vertex_buff v] with ((item ((i) + (j)) of [vertex_buff v]) - (((_max) + (_min)) / (2)))\n        set [i v] to (item ((i) + (3)) of [vertex_buff v])\n    end\n    change [j v] by (1)\nend\n\ndefine _idxs_tmp.set_from_f_cmd ( (cmd) (idx_offset) <reverse?> )\n_split_buff = split ( (cmd) [ ] )\ndelete (1) of [_split_buff v]\ndelete all of [_tmp v]\nrepeat until <(length of [_split_buff v]) = [0]>\n    add (item ((<reverse?> * (length of [_split_buff v])) + <not <reverse?>>) of [_split_buff v]) to [_tmp v]\n    delete ((<reverse?> * (length of [_split_buff v])) + <not <reverse?>>) of [_split_buff v]\nend\ndelete all of [_idxs_tmp v]\nrepeat until <(length of [_tmp v]) = [0]>\n    _split_buff = split ( (item (1) of [_tmp v]) [/] )\n    add ((((item (1) of [_split_buff v]) - (1)) * (4)) + (idx_offset)) to [_idxs_tmp v]\n    delete (1) of [_tmp v]\nend\n\ndefine primitives.triangulate ( (*prim) )\nreplace item ((*prim) + (2)) of [primitives v] with ((length of [idxs_tri v]) + (1))\nset [_plane v] to [2]\n_winding_num = calc_winding_num ( (_plane) )\nif <([abs v] of (_winding_number) ) < [0.01]> then\n    set [_plane v] to [1]\n    _winding_num = calc_winding_num ( (_plane) )\n    if <([abs v] of (_winding_number) ) < [0.01]> then\n        set [_plane v] to [0]\n        _winding_num = calc_winding_num ( (_plane) )\n    end\nend\nset [debug v] to [0]\nPolygon Tessellation ( [1] (_winding_number) (_plane) )\nif <(debug) > [300]> then\n    primitives.add_prim_to_idxs_tmp ( (*prim) ((1) / (0)) )\n    debug_polygon_tesselation (_winding_number) (_plane)\n    ​​breakpoint​​\nend\nreplace item ((*prim) + (3)) of [primitives v] with ((length of [idxs_tri v]) + (1))\n\ndefine primitives.convert_and_triangulate_primitives()\ndelete all of [idxs_tri v]\nset [_ptr v] to [1]\nrepeat ((length of [primitives v]) / (@enum p:SIZE))\n    primitives.add_prim_to_idxs_tmp ( (_ptr) ((1) / (0)) )\n    if <(item (_ptr) of [primitives v]) = [POLYGON]> then\n        primitives.convert_prim ( (_ptr) )\n    end\n    change [_ptr v] by (@enum p:SIZE)\nend\n\ndefine primitives.add_prim_to_idxs_tmp ( (*prim) (max_len) )\ndelete all of [_idxs_tmp v]\nset [_tmp v] to (item (*prim) of [primitives v])\nif <(_tmp) = [POLYGON]> then\n    set [_tmp v] to (item ((*prim) + (1)) of [primitives v])\n    add (item (_tmp) of [idxs_poly v]) to [_idxs_tmp v]\n    set [_tmp v] to (item ((_tmp) + (1)) of [idxs_poly v])\n    repeat until <<(_tmp) = (item ((*prim) + (1)) of [primitives v])> or <(length of [_idxs_tmp v]) > (max_len)>>\n        add (item (_tmp) of [idxs_poly v]) to [_idxs_tmp v]\n        set [_tmp v] to (item ((_tmp) + (1)) of [idxs_poly v])\n    end\nelse\n    set [i v] to [1]\n    repeat ((<(_tmp) = [POINT]> * (1)) + ((<(_tmp) = [LINE]> * (2)) + ((<(_tmp) = [TRIANGLE]> * (3)) + (<(_tmp) = [QUAD]> * (4)))))\n        add (item ((*prim) + (i)) of [primitives v]) to [_idxs_tmp v]\n        change [i v] by (1)\n    end\nend\n\ndefine primitives.compute_normals()\ndelete all of [normal_buff v]\nset [i v] to [1]\nrepeat ((length of [primitives v]) / (@enum p:SIZE))\n    if <not <(item ((i) + (@enum p:NORMAL)) of [primitives v]) = [null]>> then\n        set [_x v] to (item (item ((i) + (1)) of [primitives v]) of [idxs_poly v])\n        set [_y v] to (item (item ((item ((i) + (1)) of [primitives v]) + (1)) of [idxs_poly v]) of [idxs_poly v])\n        set [_z v] to (item (item ((item ((item ((i) + (1)) of [primitives v]) + (1)) of [idxs_poly v]) + (1)) of [idxs_poly v]) of [idxs_poly v])\n        _x, _y, _z = calc_unit_normal (item (_x) of [vertex_buff v]) (item ((_x) + (1)) of [vertex_buff v]) (item ((_x) + (2)) of [vertex_buff v]) (item (_y) of [vertex_buff v]) (item ((_y) + (1)) of [vertex_buff v]) (item ((_y) + (2)) of [vertex_buff v]) (item (_z) of [vertex_buff v]) (item ((_z) + (1)) of [vertex_buff v]) (item ((_z) + (2)) of [vertex_buff v])\n        set [_*obj v] to (item ((i) + (@enum p:*OBJECT)) of [primitives v])\n        set [_ptr v] to ((length of [normal_buff v]) + (1))\n        if <<(length of [normal_buff v]) = [0]> or <(item ((_*obj) + (@enum o:*NLEFT)) of [gameobjects v]) = [n_left]>> then\n            if <(@*normal_buff_tail_obj) > [0]> then\n                replace item (((@*normal_buff_tail_obj) + (@enum o:*NLEFT)) + (1)) of [gameobjects v] with (_ptr)\n            end\n            replace item ((_*obj) + (@enum o:*NLEFT)) of [gameobjects v] with (_ptr)\n            replace item (((_*obj) + (@enum o:*NLEFT)) + (1)) of [gameobjects v] with [null]\n        end\n        if <not <(_*obj) = (@*normal_buff_tail_obj)>> then\n            set [@*normal_buff_tail_obj v] to (_*obj)\n        end\n        add (_x) to [normal_buff v]\n        add (_y) to [normal_buff v]\n        add (_z) to [normal_buff v]\n    end\n    change [i v] by (@enum p:SIZE)\nend\nset [i v] to [1]\nrepeat (length of [normal_buff v])\n    add (item (i) of [normal_buff v]) to [normal_world v]\n    change [i v] by (1)\nend\n\ndefine primitives.generate_shadows ()\nif <(@shadows?) = [1]> then\n    Materials.newMaterial ( label [Shadow] pointer to secondary colour material [] sfx sound name [] texture costume name [] Colour (R,G,B,A) (join (join ((77) * ((@ambient_max) + (0.1))) [,]) (join ((168) * ((@ambient_max) + (0.1))) (join [,] ((56) * ((@ambient_max) + (0.1)))))) no collider? <> bounciness (0-1) [] )\n    Materials.newMaterial ( label [Point Shadow] pointer to secondary colour material [] sfx sound name [] texture costume name [shadow] Colour (R,G,B,A) [] no collider? <> bounciness (0-1) [] )\nend\nset [@*shadow_seg v] to (length of [vertex_buff v])\nset [_*prim v] to [1]\nrepeat ((length of [primitives v]) / (@enum p:SIZE))\n    set [_tmp2 v] to (_*prim)\n    set [_*obj v] to (item ((_*prim) + (@enum p:*OBJECT)) of [primitives v])\n    if <(@shadows?) = [1]> then\n        if <(item (_*prim) of [primitives v]) = [POLYGON]> then\n            set [_tmp v] to ((length of [idxs_tri v]) + (1))\n            set [j v] to (item ((_*prim) + (2)) of [primitives v])\n            repeat until <(j) = (item ((_*prim) + (3)) of [primitives v])>\n                add ((item (j) of [idxs_tri v]) + (@*shadow_seg)) to [idxs_tri v]\n                change [j v] by (1)\n            end\n            _*prim = primitives.add_prim ( (item (_*prim) of [primitives v]) (item ((_*prim) + (1)) of [primitives v]) (_tmp) (length of [idxs_tri v]) [] *obj (_*obj) material [Shadow] has_normal? <> )\n        else\n            if <<(item (_*prim) of [primitives v]) = [TRIANGLE]> or <(item (_*prim) of [primitives v]) = [QUAD]>> then\n                _*prim = primitives.add_prim ( (item (_*prim) of [primitives v]) ((item ((_*prim) + (1)) of [primitives v]) + (@*shadow_seg)) ((item ((_*prim) + (2)) of [primitives v]) + (@*shadow_seg)) ((item ((_*prim) + (3)) of [primitives v]) + (@*shadow_seg)) ((item ((_*prim) + (4)) of [primitives v]) + (@*shadow_seg)) *obj (_*obj) material [Shadow] has_normal? <> )\n            else\n                if <(item (_*prim) of [primitives v]) = [LINE]> then\n                    _*prim = primitives.add_prim ( (item (_*prim) of [primitives v]) ((item ((_*prim) + (1)) of [primitives v]) + (@*shadow_seg)) ((item ((_*prim) + (2)) of [primitives v]) + (@*shadow_seg)) (item ((_*prim) + (3)) of [primitives v]) (item ((_*prim) + (4)) of [primitives v]) *obj (_*obj) material [Shadow] has_normal? <> )\n                end\n            end\n        end\n        add (_tmp2) to [@shadow_to_*prim v]\n    end\n    if <(item (_*prim) of [primitives v]) = [POINT]> then\n        if <<(@shadows?) = [1]> or <not <(item ((_*prim) + (@enum p:SHAD_OFF_SCALE)) of [primitives v]) = []>>> then\n            if <(_tmp2) = (@*player_prim)> then\n                set [_tmp v] to [Player Shadow]\n            else\n                set [_tmp v] to [Point Shadow]\n            end\n            _*prim = primitives.add_prim ( (item (_*prim) of [primitives v]) ((item ((_*prim) + (1)) of [primitives v]) + (@*shadow_seg)) (item ((_*prim) + (2)) of [primitives v]) (item ((_*prim) + (3)) of [primitives v]) (item ((_*prim) + (4)) of [primitives v]) *obj (_*obj) material (_tmp) has_normal? <> )\n            if <(@shadows?) = [0]> then\n                add (_tmp2) to [@shadow_to_*prim v]\n            end\n        end\n    end\n    if <(@shadows?) = [1]> then\n        replace item ((_*prim) + (@enum p:ILLUMINATION)) of [primitives v] with [100]\n    end\n    if <(_tmp2) = (@*player_prim)> then\n        set [@*player_shadow_prim v] to (_*prim)\n    end\n    set [_*prim v] to ((_tmp2) + (@enum p:SIZE))\nend\n\nwhen I receive [final prim setup v]\nadd [--dynamic data--] to [primitives v]\nset [*dynamic_seg v] to (length of [primitives v])\nprimitives.convert_and_triangulate_primitives()\nprimitives.generate_shadows ()\n\ndefine reset all ()\ndelete all of [_tmp v]\ndelete all of [_idxs_tmp v]\ndelete all of [_intersection_t_vals v]\ndelete all of [vertex_buff v]\nset [@*vertex_buff_tail v] to [0]\nset [@*vertex_buff_tail_obj v] to [0]\nset [@*normal_buff_tail_obj v] to [0]\nset [@gameobjects._*prims.tail v] to [0]\ndelete all of [vertex_world v]\ndelete all of [vertex v]\ndelete all of [primitives v]\ndelete all of [idxs_poly v]\ndelete all of [idxs_tri v]\ndelete all of [gameobjects v]\ndelete all of [@updated_objects v]\ndelete all of [normal_buff v]\ndelete all of [normal_world v]\ndelete all of [bsp.tree v]\ndelete all of [bsp._*prims v]\ndelete all of [bsphere_buff v]\ndelete all of [bsphere_world v]\ndelete all of [gameobjects._*prims v]\ndelete all of [materials v]\ndelete all of [@dynamic_obj_center_offset v]\ndelete all of [@shadow_to_*prim v]\ndelete all of [@dynamic_objects v]\n\ndefine GameObjects.create3DPoint ( material name (mat) radius (radius) scale y (scale y) position (x) (y) (z) parent (parent) shadow offset dist (shad_off_scale) name (name) )\nif <<(parent) = []> or <not <[gameobjects v] contains (parent)?>>> then\n    _*obj = GameObjects.instantiate ( position (x) (y) (z) rotation [0] [0] [0] hidden? <> name (name) dynamic? <> )\n    _ptr = vertex_buff.insert_after (xyz [0] [0] [0] *node (@*vertex_buff_tail) *obj (_*obj) )\nelse\n    set [_*obj v] to (item # of (parent) in [gameobjects v])\n    _ptr = vertex_buff.insert_after (xyz (x) (y) (z) *node (item ((_*obj) + (@enum o:*VLEFT)) of [gameobjects v]) *obj (_*obj) )\nend\nset [_ptr_to_vert v] to (_ptr)\ndelete all of [_idxs_tmp v]\nadd (_ptr) to [_idxs_tmp v]\n_*prim = primitives.add_polygon_from_idxs_tmp( *object (_*obj) mat (mat) pen radius (radius) )\nif <not <(scale y) = []>> then\n    replace item ((_*prim) + (@enum p:SPRITE_SCALE_Y)) of [primitives v] with (scale y)\nelse\n    replace item ((_*prim) + (@enum p:SPRITE_SCALE_Y)) of [primitives v] with []\nend\nreplace item ((_*prim) + (@enum p:SHAD_OFF_SCALE)) of [primitives v] with (shad_off_scale)\n\ndefine primitives.convert_prim ( (*prim) )\n_idx_tmp.remove_consecutive_duplicates()\nif <(length of [_idxs_tmp v]) > [4]> then\n    primitives.triangulate ( (*prim) )\nelse\n    replace item (*prim) of [primitives v] with [POINT]\n    replace item ((*prim) + (1)) of [primitives v] with (item (1) of [_idxs_tmp v])\n    if <(length of [_idxs_tmp v]) > [1]> then\n        replace item (*prim) of [primitives v] with [LINE]\n        replace item ((*prim) + (2)) of [primitives v] with (item (2) of [_idxs_tmp v])\n    end\n    if <(length of [_idxs_tmp v]) > [2]> then\n        replace item (*prim) of [primitives v] with [TRIANGLE]\n        replace item ((*prim) + (3)) of [primitives v] with (item (3) of [_idxs_tmp v])\n    end\n    if <(length of [_idxs_tmp v]) > [3]> then\n        replace item (*prim) of [primitives v] with [QUAD]\n        replace item ((*prim) + (4)) of [primitives v] with (item (4) of [_idxs_tmp v])\n    end\nend\n\ndefine _OBJ = exportScene ()\ndelete all of [_obj v]\nadd [# ChromeEngine v1] to [_obj v]\nadd [# https://scratch.mit.edu/projects/779272331] to [_obj v]\nset [_vert_count v] to [1]\ndelete all of [_new_vert_loc v]\nrepeat ((length of [vertex_buff v]) / (4))\n    add [] to [_new_vert_loc v]\nend\nset [_prim_count v] to [1]\ndelete all of [_new_prim_loc v]\nrepeat ((length of [primitives v]) / (@enum p:SIZE))\n    add [] to [_new_prim_loc v]\nend\nset [_*obj v] to [1]\nrepeat ((length of [gameobjects v]) / (@enum o:SIZE))\n    add (join [o ] (item (_*obj) of [gameobjects v])) to [_obj v]\n    set [i v] to (item ((_*obj) + (@enum o:*VLEFT)) of [gameobjects v])\n    repeat until <<(i) = (item (((_*obj) + (@enum o:*VLEFT)) + (1)) of [gameobjects v])> or <(i) = [null]>>\n        delete all of [_tmp v]\n        add [v] to [_tmp v]\n        add (item ((i) + (0)) of [vertex_buff v]) to [_tmp v]\n        add (item ((i) + (1)) of [vertex_buff v]) to [_tmp v]\n        add (item ((i) + (2)) of [vertex_buff v]) to [_tmp v]\n        _tmp = join_tmp ( delim [ ] )\n        add (_tmp) to [_obj v]\n        replace item ((((i) - (1)) / (4)) + (1)) of [_new_vert_loc v] with (_vert_count)\n        change [_vert_count v] by (1)\n        set [i v] to (item ((i) + (3)) of [vertex_buff v])\n    end\n    set [_material v] to [1]\n    repeat ((length of [materials v]) / (@enum m:SIZE))\n        add (join [usemtl ] (item (_material) of [materials v])) to [_obj v]\n        set [_*prim v] to [1]\n        set [_has_prim? v] to [0]\n        repeat until <(item (_*prim) of [primitives v]) = [--dynamic data--]>\n            if <<(item ((_*prim) + (@enum p:MATERIAL)) of [primitives v]) = (_material)> and <(item ((_*prim) + (@enum p:*OBJECT)) of [primitives v]) = (_*obj)>> then\n                set [_has_prim? v] to [1]\n                primitives.add_prim_to_idxs_tmp ( (_*prim) ((1) / (0)) )\n                if <<(length of [_idxs_tmp v]) < [3]> and <not <(item ((_*prim) + (@enum p:RADIUS)) of [primitives v]) = []>>> then\n                    add (join [fs ] (item ((_*prim) + (@enum p:RADIUS)) of [primitives v])) to [_obj v]\n                end\n                delete all of [_tmp v]\n                add [f] to [_tmp v]\n                repeat until <(length of [_idxs_tmp v]) = [0]>\n                    set [_tmp v] to ((((item (1) of [_idxs_tmp v]) - (1)) / (4)) + (1))\n                    add (item (_tmp) of [_new_vert_loc v]) to [_tmp v]\n                    delete (1) of [_idxs_tmp v]\n                end\n                _tmp = join_tmp ( delim [ ] )\n                add (_tmp) to [_obj v]\n                replace item ((((_*prim) - (1)) / (@enum p:SIZE)) + (1)) of [_new_prim_loc v] with (_prim_count)\n                change [_prim_count v] by (1)\n            end\n            change [_*prim v] by (@enum p:SIZE)\n        end\n        if <(_has_prim?) = [0]> then\n            delete (length of [_obj v]) of [_obj v]\n        end\n        change [_material v] by (6)\n    end\n    change [_*obj v] by (@enum o:SIZE)\nend\nset [i v] to [1]\nrepeat ((length of [bsp._*prims v]) / (4))\n    delete all of [_tmp v]\n    add [bp] to [_tmp v]\n    set [_tmp v] to ((((item (i) of [bsp._*prims v]) - (1)) / (@enum p:SIZE)) + (1))\n    add ((((item (_tmp) of [_new_prim_loc v]) - (1)) * (@enum p:SIZE)) + (1)) to [_tmp v]\n    add (item ((i) + (1)) of [bsp._*prims v]) to [_tmp v]\n    add (item ((i) + (2)) of [bsp._*prims v]) to [_tmp v]\n    add (item ((i) + (3)) of [bsp._*prims v]) to [_tmp v]\n    _tmp = join_tmp ( delim [ ] )\n    add (_tmp) to [_obj v]\n    change [i v] by (4)\nend\nset [i v] to [3]\nrepeat (item (2) of [bsp.tree v])\n    delete all of [_tmp v]\n    add [bt] to [_tmp v]\n    set [j v] to [0]\n    repeat (@enum t:SIZE)\n        add (item ((i) + (j)) of [bsp.tree v]) to [_tmp v]\n        change [j v] by (1)\n    end\n    _tmp = join_tmp ( delim [ ] )\n    add (_tmp) to [_obj v]\n    change [i v] by (@enum t:SIZE)\nend\n\ndefine _tmp = join_tmp ( delim (delim) )\nset [_tmp v] to []\nrepeat until <(length of [_tmp v]) = [0]>\n    if <(length of [_tmp v]) = [1]> then\n        set [_tmp v] to (join (_tmp) (item (1) of [_tmp v]))\n    else\n        set [_tmp v] to (join (_tmp) (join (item (1) of [_tmp v]) [ ]))\n    end\n    delete (1) of [_tmp v]\nend\n\ndefine handle cmd (cmd) <is_clockwise?>\n_split_buff = split ( (cmd) [ ] )\nset [_cmd v] to (item (1) of [_split_buff v])\ndelete (1) of [_split_buff v]\nif <(_cmd) = [o]> then\n    set [_*vstart v] to ((length of [vertex_buff v]) + (1))\n    set [_*nstart v] to ((length of [normal_buff v]) + (1))\n    _*obj = GameObjects.instantiate ( position [0] [0] [0] rotation [0] [0] [0] hidden? <> name (item (1) of [_split_buff v]) dynamic? <> )\n    stop [this script v]\nend\nif <(_cmd) = [v]> then\n    if <(_*obj) = [null]> then\n        _*obj = GameObjects.instantiate ( position [0] [0] [0] rotation [0] [0] [0] hidden? <> name [default] dynamic? <> )\n    end\n    _ptr = vertex_buff.insert_after (xyz ((item (1) of [_split_buff v]) + ()) ((item (2) of [_split_buff v]) + ()) ((item (3) of [_split_buff v]) + ()) *node (@*vertex_buff_tail) *obj (_*obj) )\n    stop [this script v]\nend\nif <(_cmd) = [f]> then\n    _idxs_tmp.set_from_f_cmd ( (cmd) (_*vstart_obj) <is_clockwise?> )\n    _*prim = primitives.add_polygon_from_idxs_tmp( *object (_*obj) mat (_material) pen radius (_radius) )\n    set [_radius v] to []\n    stop [this script v]\nend\nif <(_cmd) = [mtllib]> then\n    Materials.useMtlLib (item (1) of [_split_buff v])\nend\nif <(_cmd) = [usemtl]> then\n    if <[materials v] contains (item (1) of [_split_buff v])?> then\n        set [_material v] to (item (1) of [_split_buff v])\n    else\n        set [_material v] to [None]\n    end\n    stop [this script v]\nend\nif <(_cmd) = [bp]> then\n    repeat until <(length of [_split_buff v]) = [0]>\n        add (item (1) of [_split_buff v]) to [bsp._*prims v]\n        delete (1) of [_split_buff v]\n    end\n    stop [this script v]\nend\nif <(_cmd) = [bt]> then\n    repeat until <(length of [_split_buff v]) = [0]>\n        add (item (1) of [_split_buff v]) to [bsp.tree v]\n        delete (1) of [_split_buff v]\n    end\n    stop [this script v]\nend\nif <(_cmd) = [fs]> then\n    set [_radius v] to (item (1) of [_split_buff v])\n    stop [this script v]\nend\n\ndefine _winding_num = calc_winding_num ( (principal_plane) )\nset [_winding_number v] to [0]\nset [_n v] to (length of [_idxs_tmp v])\nset [i v] to [0]\nrepeat (length of [_idxs_tmp v])\n    delete all of [_tmp v]\n    add_tri_to_tmp ( (item ((((i) + (0)) mod (_n)) + (1)) of [_idxs_tmp v]) (item ((((i) + (1)) mod (_n)) + (1)) of [_idxs_tmp v]) (item ((((i) + (2)) mod (_n)) + (1)) of [_idxs_tmp v]) )\n    delete ((7) + (principal_plane)) of [_tmp v]\n    delete ((4) + (principal_plane)) of [_tmp v]\n    delete ((1) + (principal_plane)) of [_tmp v]\n    change [_winding_number v] by ((((item (3) of [_tmp v]) - (item (1) of [_tmp v])) * ((item (6) of [_tmp v]) - (item (2) of [_tmp v]))) - (((item (4) of [_tmp v]) - (item (2) of [_tmp v])) * ((item (5) of [_tmp v]) - (item (1) of [_tmp v]))))\n    change [i v] by (1)\nend\nset [_winding_number v] to ((_winding_number) / (length of [_idxs_tmp v]))\n\ndefine debug_polygon_tesselation (direction) (principal_axis)\nerase all\nset pen color to (#ff00c3)\nset pen size to (2)\nset [i v] to [1]\nrepeat ((length of [_idxs_tmp v]) + (1))\n    delete all of [_tmp v]\n    add (item ((item (i) of [_idxs_tmp v]) + (0)) of [vertex_buff v]) to [_tmp v]\n    add (item ((item (i) of [_idxs_tmp v]) + (1)) of [vertex_buff v]) to [_tmp v]\n    add (item ((item (i) of [_idxs_tmp v]) + (2)) of [vertex_buff v]) to [_tmp v]\n    delete ((1) + (principal_axis)) of [_tmp v]\n    go to x: ((item (1) of [_tmp v]) * (100)) y: ((item (2) of [_tmp v]) * (100))\n    pen down\n    set [i v] to (((i) mod (length of [_idxs_tmp v])) + (1))\n    change pen (color v) by (10)\nend\ngo to x: ((item (1) of [_tmp v]) * (100)) y: ((item (2) of [_tmp v]) * (100))\npen up\n\ndefine vertex_buff.scale ( left (*l) right (*r) scale (s) )\nset [i v] to (*l)\nrepeat (((*r) - (*l)) / (4))\n    set [j v] to [0]\n    repeat (3)\n        replace item ((i) + (j)) of [vertex_buff v] with ((item ((i) + (j)) of [vertex_buff v]) * (s))\n        change [j v] by (1)\n    end\n    set [i v] to (item ((i) + (3)) of [vertex_buff v])\nend\n\ndefine primitives.generate_bounding_spheres ()\nset [_*prim v] to [1]\nrepeat ((length of [primitives v]) / (@enum p:SIZE))\n    if <not <(item (_*prim) of [primitives v]) = [CONTAINER]>> then\n        primitives.add_prim_to_idxs_tmp ( (_*prim) ((1) / (0)) )\n        delete all of [_tmp v]\n        set [i v] to [1]\n        repeat (length of [_idxs_tmp v])\n            set [_tmp v] to (item (i) of [_idxs_tmp v])\n            add (item ((_tmp) + (0)) of [vertex_buff v]) to [_tmp v]\n            add (item ((_tmp) + (1)) of [vertex_buff v]) to [_tmp v]\n            add (item ((_tmp) + (2)) of [vertex_buff v]) to [_tmp v]\n            change [i v] by (1)\n        end\n        _x, _y, _z, _r = RitterSphere ( _tmp )\n        add (_x) to [bsphere_buff v]\n        replace item ((_*prim) + (@enum p:*BSPHERE)) of [primitives v] with (length of [bsphere_buff v])\n        add (_y) to [bsphere_buff v]\n        add (_z) to [bsphere_buff v]\n        if <(length of [_idxs_tmp v]) < [3]> then\n            change [_r v] by (item ((_*prim) + (@enum p:RADIUS)) of [primitives v])\n        end\n        add (_r) to [bsphere_buff v]\n        add (_*prim) to [bsphere_buff v]\n    end\n    change [_*prim v] by (@enum p:SIZE)\nend\ndelete all of [bsphere_world v]\nset [i v] to [1]\nrepeat (length of [bsphere_buff v])\n    add (item (i) of [bsphere_buff v]) to [bsphere_world v]\n    change [i v] by (1)\nend\n\ndefine _x, _y, _z, _r = RitterSphere ( _tmp )\n_x,_y,_z,_r = SphereFromDistantPoints (_tmp)\nset [i v] to [1]\nrepeat ((length of [_tmp v]) / (3))\n    _x,_y,_z,_r = SphereOfSphereAndPt ( Sphere (_x) (_y) (_z) (_r) Pt (item (i) of [_tmp v]) (item ((i) + (1)) of [_tmp v]) (item ((i) + (2)) of [_tmp v]) )\n    change [i v] by (3)\nend\n\ndefine _x,_y,_z,_r = SphereFromDistantPoints (_tmp)\n_min, _max = MostSeparatedPointsOnAABB (_tmp)\nset [_x v] to (((item (_min) of [_tmp v]) + (item (_max) of [_tmp v])) / (2))\nset [_y v] to (((item ((_min) + (1)) of [_tmp v]) + (item ((_max) + (1)) of [_tmp v])) / (2))\nset [_z v] to (((item ((_min) + (2)) of [_tmp v]) + (item ((_max) + (2)) of [_tmp v])) / (2))\nset [_r v] to ([sqrt v] of ((((item (_max) of [_tmp v]) - (_x)) * ((item (_max) of [_tmp v]) - (_x))) + ((((item ((_max) + (1)) of [_tmp v]) - (_y)) * ((item ((_max) + (1)) of [_tmp v]) - (_y))) + (((item ((_max) + (2)) of [_tmp v]) - (_z)) * ((item ((_max) + (2)) of [_tmp v]) - (_z))))) )\n\ndefine _min, _max = MostSeparatedPointsOnAABB (_tmp)\nset [_minx v] to [1]\nset [_miny v] to [1]\nset [_minz v] to [1]\nset [_maxx v] to [1]\nset [_maxy v] to [1]\nset [_maxz v] to [1]\nset [i v] to [1]\nrepeat ((length of [_tmp v]) / (3))\n    if <(item (i) of [_tmp v]) < (item (_minx) of [_tmp v])> then\n        set [_minx v] to (i)\n    end\n    if <(item (i) of [_tmp v]) > (item (_maxx) of [_tmp v])> then\n        set [_maxx v] to (i)\n    end\n    if <(item ((i) + (1)) of [_tmp v]) < (item ((_miny) + (1)) of [_tmp v])> then\n        set [_miny v] to (i)\n    end\n    if <(item ((i) + (1)) of [_tmp v]) > (item ((_maxy) + (1)) of [_tmp v])> then\n        set [_maxy v] to (i)\n    end\n    if <(item ((i) + (2)) of [_tmp v]) < (item ((_minz) + (2)) of [_tmp v])> then\n        set [_minz v] to (i)\n    end\n    if <(item ((i) + (2)) of [_tmp v]) > (item ((_maxz) + (2)) of [_tmp v])> then\n        set [_maxz v] to (i)\n    end\n    change [i v] by (3)\nend\n_tmp = SquaredDist ( A (item (_maxx) of [_tmp v]) (item ((_maxx) + (1)) of [_tmp v]) (item ((_maxx) + (2)) of [_tmp v]) B (item (_minx) of [_tmp v]) (item ((_minx) + (1)) of [_tmp v]) (item ((_minx) + (2)) of [_tmp v]) )\nset [_x v] to (_tmp)\n_tmp = SquaredDist ( A (item (_maxy) of [_tmp v]) (item ((_maxy) + (1)) of [_tmp v]) (item ((_maxy) + (2)) of [_tmp v]) B (item (_miny) of [_tmp v]) (item ((_miny) + (1)) of [_tmp v]) (item ((_miny) + (2)) of [_tmp v]) )\nset [_y v] to (_tmp)\n_tmp = SquaredDist ( A (item (_maxz) of [_tmp v]) (item ((_maxz) + (1)) of [_tmp v]) (item ((_maxz) + (2)) of [_tmp v]) B (item (_minz) of [_tmp v]) (item ((_minz) + (1)) of [_tmp v]) (item ((_minz) + (2)) of [_tmp v]) )\nset [_z v] to (_tmp)\nif <<(_x) > (_y)> and <(_x) > (_z)>> then\n    set [_min v] to (_minx)\n    set [_max v] to (_maxx)\nelse\n    if <(_y) > (_z)> then\n        set [_min v] to (_miny)\n        set [_max v] to (_maxy)\n    else\n        set [_min v] to (_minz)\n        set [_max v] to (_maxz)\n    end\nend\n\ndefine _x,_y,_z,_r = SphereOfSphereAndPt ( Sphere (sx) (sy) (sz) (sr) Pt (px) (py) (pz) )\nset [_tmp v] to ([sqrt v] of ((((px) - (sx)) * ((px) - (sx))) + ((((py) - (sy)) * ((py) - (sy))) + (((pz) - (sz)) * ((pz) - (sz))))) )\nif <(_tmp) > (sr)> then\n    set [_r v] to (((sr) + (_tmp)) / (2))\n    set [_tmp v] to (((_r) - (sr)) / (_tmp))\n    set [_x v] to ((sx) + (((px) - (sx)) * (_tmp)))\n    set [_y v] to ((sy) + (((py) - (sy)) * (_tmp)))\n    set [_z v] to ((sz) + (((pz) - (sz)) * (_tmp)))\nend\n\ndefine Materials.importFromMTL ( .MTL file data (mtl file) )\n_split_buff = split ( (mtl file) [ ] )\nrepeat until <(length of [_split_buff v]) = [0]>\n    import_mtl.handle_line ( (item (1) of [_split_buff v]) )\n    delete (1) of [_split_buff v]\nend\n\ndefine import_mtl.handle_line ( (line) )\nif <(line) = [newmtl]> then\n    Materials.newMaterial ( label (item (2) of [_split_buff v]) pointer to secondary colour material [] sfx sound name [] texture costume name [] Colour (R,G,B,A) [] no collider? <> bounciness (0-1) [] )\n    stop [this script v]\nend\nif <(line) = [Kd]> then\n    Materials.setLastKD ( (item (2) of [_split_buff v]) (item (3) of [_split_buff v]) (item (4) of [_split_buff v]) [] )\n    stop [this script v]\nend\nif <(line) = [d]> then\n    set [_tmp v] to (((length of [materials v]) - (@enum m:SIZE)) + (5))\n    replace item (_tmp) of [materials v] with ((item (_tmp) of [materials v]) + ((round ((item (2) of [_split_buff v]) * (255))) * (16777216)))\n    stop [this script v]\nend\n\ndefine Materials.useMtlLib (lib)\n\ndefine Materials.setLastKD ( (r) (g) (b) (a) )\nset [_tmp v] to ((a) - <(a) = [1]>)\nset [_tmp2 v] to (((length of [materials v]) - (@enum m:SIZE)) + (5))\nreplace item (_tmp2) of [materials v] with (((round ((_tmp) * (255))) * (16777216)) + (((round ((r) * (255))) * (65536)) + (((round ((g) * (255))) * (256)) + (round ((b) * (255))))))\nif <<(r) > (g)> and <(r) > (b)>> then\n    replace item ((_tmp2) + (1)) of [materials v] with (r)\nelse\n    if <(g) > (b)> then\n        replace item ((_tmp2) + (1)) of [materials v] with (g)\n    else\n        replace item ((_tmp2) + (1)) of [materials v] with (b)\n    end\nend\n\ndefine Materials.setDoubleSided (comma separated list of materials: (mat_double_list) )\n_split_buff = split ( (mat_double_list) [,] )\nrepeat until <(length of [_split_buff v]) = [0]>\n    set [_tmp v] to (item (1) of [_split_buff v])\n    delete (1) of [_split_buff v]\n    if <[materials v] contains (_tmp)?> then\n        replace item ((item # of (_tmp) in [materials v]) + (1)) of [materials v] with (item # of (_tmp) in [materials v])\n    end\nend\n\ndefine Materials.setSecondaryColour ( Material (mat) Colour (R,G,B,A) (rgba) )\nif <[materials v] contains (mat)?> then\n    replace item ((item # of (mat) in [materials v]) + (1)) of [materials v] with ((length of [materials v]) + (1))\n    Materials.newMaterial ( label (join (mat) [:secondary]) pointer to secondary colour material ((length of [materials v]) + (1)) sfx sound name [] texture costume name [] Colour (R,G,B,A) (rgba) no collider? <> bounciness (0-1) [] )\nend\n\ndefine GameObjects.create3DLine ( Pt A (ax) (ay) (az) Pt B (bx) (by) (bz) material (mat) radius (r) parent (parent) name (name) )\nif <<(parent) = []> or <not <[gameobjects v] contains (parent)?>>> then\n    _*obj = GameObjects.instantiate ( position [0] [0] [0] rotation [0] [0] [0] hidden? <> name (name) dynamic? <> )\n    set [_ptr_to_node v] to (@*vertex_buff_tail)\nelse\n    set [_*obj v] to (item # of (parent) in [gameobjects v])\n    set [_ptr_to_node v] to (item ((_*obj) + (@enum o:*VLEFT)) of [gameobjects v])\nend\n_ptr = vertex_buff.insert_after (xyz (ax) (ay) (az) *node (_ptr_to_node) *obj (_*obj) )\nset [_*vstart v] to (_ptr)\n_ptr = vertex_buff.insert_after (xyz (bx) (by) (bz) *node (_ptr) *obj (_*obj) )\ndelete all of [_idxs_tmp v]\nadd (_*vstart) to [_idxs_tmp v]\nadd (_ptr) to [_idxs_tmp v]\n_*prim = primitives.add_polygon_from_idxs_tmp( *object (_*obj) mat (mat) pen radius (r) )\n\ndefine _**prim = GameObjects._*prims.insert_after( (*prim) (*elem) )\nif <(*elem) = []> then\n    add (*prim) to [gameobjects._*prims v]\n    set [_**prim v] to (length of [gameobjects._*prims v])\n    add [null] to [gameobjects._*prims v]\n    if <(@GameObjects._*prims.tail) = [0]> then\n        set [@gameobjects._*prims.tail v] to [1]\n    else\n        replace item ((@GameObjects._*prims.tail) + (1)) of [gameobjects._*prims v] with (_**prim)\n        set [@gameobjects._*prims.tail v] to (_**prim)\n    end\nelse\n    set [_tmp v] to (item ((*elem) + (1)) of [gameobjects._*prims v])\n    add (*prim) to [gameobjects._*prims v]\n    set [_**prim v] to (length of [gameobjects._*prims v])\n    add (_tmp) to [gameobjects._*prims v]\n    replace item ((*elem) + (1)) of [gameobjects._*prims v] with (_**prim)\n    if <(*elem) = (@GameObjects._*prims.tail)> then\n        set [@gameobjects._*prims.tail v] to (_**prim)\n    end\nend\n\ndefine GameObjects.generate_bounding_spheres()\nset [_*obj v] to [1]\nrepeat ((length of [gameobjects v]) / (@enum o:SIZE))\n    delete all of [_tmp v]\n    set [i v] to (item ((_*obj) + (@enum o:*VLEFT)) of [gameobjects v])\n    set [_tmp v] to (item ((_*obj) + ((@enum o:*VLEFT) + (1))) of [gameobjects v])\n    repeat until <<(i) = (_tmp)> or <(i) = [null]>>\n        add (item ((i) + (0)) of [vertex_buff v]) to [_tmp v]\n        add (item ((i) + (1)) of [vertex_buff v]) to [_tmp v]\n        add (item ((i) + (2)) of [vertex_buff v]) to [_tmp v]\n        set [i v] to (item ((i) + (3)) of [vertex_buff v])\n    end\n    _x, _y, _z, _r = RitterSphere ( _tmp )\n    add (_x) to [bsphere_buff v]\n    set [_ptr v] to (length of [bsphere_buff v])\n    add (_y) to [bsphere_buff v]\n    add (_z) to [bsphere_buff v]\n    if <not <(length of [_tmp v]) > [6]>> then\n        change [_r v] by (item ((item (item ((_*obj) + (@enum o:**PLEFT)) of [gameobjects v]) of [gameobjects._*prims v]) + (@enum p:RADIUS)) of [primitives v])\n    end\n    add (_r) to [bsphere_buff v]\n    add (_*obj) to [bsphere_buff v]\n    replace item ((_*obj) + (@enum o:*BSPHERE)) of [gameobjects v] with (_ptr)\n    change [_*obj v] by (@enum o:SIZE)\nend\ndelete all of [bsphere_world v]\nset [i v] to [1]\nrepeat (length of [bsphere_buff v])\n    add (item (i) of [bsphere_buff v]) to [bsphere_world v]\n    change [i v] by (1)\nend\n\ndefine _idx_tmp.remove_consecutive_duplicates()\nif <(length of [_idxs_tmp v]) = [3]> then\n    set [_x v] to []\n    set [_y v] to []\n    set [_z v] to []\n    set [i v] to [1]\n    repeat (length of [_idxs_tmp v])\n        set [_tmp v] to (item (i) of [_idxs_tmp v])\n        set [_x2 v] to ((round ((item ((_tmp) + (0)) of [vertex_buff v]) * (10000))) / (10000))\n        set [_y2 v] to ((round ((item ((_tmp) + (1)) of [vertex_buff v]) * (10000))) / (10000))\n        set [_z2 v] to ((round ((item ((_tmp) + (2)) of [vertex_buff v]) * (10000))) / (10000))\n        if <<(_x2) = (_x)> and <<(_y2) = (_y)> and <(_z2) = (_z)>>> then\n            delete (i) of [_idxs_tmp v]\n            change [i v] by (-1)\n        end\n        set [_x v] to (_x2)\n        set [_y v] to (_y2)\n        set [_z v] to (_z2)\n        set [i v] to (((i) mod (length of [_idxs_tmp v])) + (1))\n    end\nend\n\ndefine GameObjects.setDynamic ( object name (obj) parent object (parent) )\nif <<not <[gameobjects v] contains (obj)?>> or <<not <(parent) = []>> and <not <[gameobjects v] contains (parent)?>>>> then\n    stop [this script v]\nend\nset [_*obj v] to (item # of (obj) in [gameobjects v])\nif <(parent) = []> then\n    replace item ((_*obj) + (@enum o:DYNAMIC_PARENT)) of [gameobjects v] with [ROOT]\nelse\n    replace item ((_*obj) + (@enum o:DYNAMIC_PARENT)) of [gameobjects v] with (item # of (parent) in [gameobjects v])\nend\nGameObjects.set_updated ( (_*obj) )\n\ndefine Materials.setSfx ( material (mat) sound effect label (sfx) )\nif <[materials v] contains (mat)?> then\n    replace item ((item # of (mat) in [materials v]) + (2)) of [materials v] with (sfx)\nend\n\ndefine Materials.newMaterial ( label (label) pointer to secondary colour material (*secondary) sfx sound name (sfx) texture costume name (tex) Colour (R,G,B,A) (rgba) no collider? <nocollider?> bounciness (0-1) (bounciness) )\nadd (label) to [materials v]\nadd (((0) * <(*secondary) = []>) + ((*secondary) * <not <(*secondary) = []>>)) to [materials v]\nif <(sfx) = []> then\n    add [null] to [materials v]\nelse\n    add (sfx) to [materials v]\nend\nif <(tex) = []> then\n    add [] to [materials v]\nelse\n    _tmp = costume_name_to_# ( (tex) )\n    add (_tmp) to [materials v]\nend\nadd [argb] to [materials v]\nadd [value] to [materials v]\nadd <<nocollider?> = [1]> to [materials v]\nadd (((@μ) * <(friction) = []>) + ((friction) * <not <(friction) = []>>)) to [materials v]\nadd (((@restitution) * <(bounciness) = []>) + ((bounciness) * <not <(bounciness) = []>>)) to [materials v]\n_split_buff = split ( (rgba) [,] )\nMaterials.setLastKD ( ((item (1) of [_split_buff v]) / (255)) ((item (2) of [_split_buff v]) / (255)) ((item (3) of [_split_buff v]) / (255)) ((item (4) of [_split_buff v]) / (255)) )\n\nwhen I receive [setup scene v]\nsetup\n\ndefine _OBJ.decode_from_data ( (data) )\ndelete all of [_obj v]\ndelete all of [_tmp v]\n_split_buff = split ( (data) [ ] )\nrepeat until <(length of [_split_buff v]) = [0]>\n    set [_tmp2 v] to (item (1) of [_split_buff v])\n    delete (1) of [_split_buff v]\n    if <[_obj_cmds v] contains (_tmp2)?> then\n        set [_cmd v] to (_tmp2)\n        if <(length of [_tmp v]) > [0]> then\n            _tmp = join_tmp ( delim [ ] )\n            add (_tmp) to [_obj v]\n            delete all of [_tmp v]\n        end\n    end\n    add (_tmp2) to [_tmp v]\nend\n_tmp = join_tmp ( delim [ ] )\nadd (_tmp) to [_obj v]\nadd [] to [_obj v]\n\ndefine GameObjects.createPlayer ( position (x) (y) (z) first person view? <first person?> Fixed shadow? <fixed_shadow>\nMaterials.newMaterial ( label [Player Shadow] pointer to secondary colour material [] sfx sound name [] texture costume name [shadow2] Colour (R,G,B,A) [] no collider? <> bounciness (0-1) [] )\nMaterials.newMaterial ( label [Player] pointer to secondary colour material [] sfx sound name [] texture costume name [ball] Colour (R,G,B,A) [] no collider? <> bounciness (0-1) [] )\nif <fixed_shadow> then\n    set [_tmp v] to (@player_r)\nelse\n    set [_tmp v] to []\nend\nGameObjects.create3DPoint ( material name [Player] radius (@player_r) scale y [] position (x) (y) (z) parent [] shadow offset dist (_tmp) name [Player] )\nGameObjects.setDynamic ( object name [Player] parent object [] )\nset [@*player_obj v] to (_*obj)\nset [@*player_prim v] to (_*prim)\nset [@first_person? v] to (<first person?> + ())\nset [@player_x v] to (x)\nset [@player_y v] to (y)\nset [@player_z v] to (z)\n\ndefine GameObjects.offsetDynamicCenter ( object name (obj) offset (x) (y) (z) )\nif <not <[gameobjects v] contains (obj)?>> then\n    stop [this script v]\nend\nset [_*obj v] to (item # of (obj) in [gameobjects v])\nif <<not <(item ((_*obj) + (@enum o:DYNAMIC_PARENT)) of [gameobjects v]) = [0]>> and <not <[@dynamic_obj_center_offset v] contains (join [*obj:] (_*obj))?>>> then\n    add (join [*obj:] (_*obj)) to [@dynamic_obj_center_offset v]\n    add (x) to [@dynamic_obj_center_offset v]\n    add (y) to [@dynamic_obj_center_offset v]\n    add (z) to [@dynamic_obj_center_offset v]\nend\n\ndefine GameObjects.createCuboid ( Scale (sx) (sy) (sz) Position (x) (y) (z) Rotation (yaw) (pitch) (roll) Material (mat) name (name) )\ndelete all of [@polygon v]\nadd ((-0.5) * (sx)) to [@polygon v]\nadd ((0.5) * (sz)) to [@polygon v]\nadd ((0.5) * (sx)) to [@polygon v]\nadd ((0.5) * (sz)) to [@polygon v]\nadd ((0.5) * (sx)) to [@polygon v]\nadd ((-0.5) * (sz)) to [@polygon v]\nadd ((-0.5) * (sx)) to [@polygon v]\nadd ((-0.5) * (sz)) to [@polygon v]\nGameObjects.createPrismUsing@polygon ( height (sy) Position (x) (y) (z) Rotation (yaw) (pitch) (roll) Material (mat) name (name) )\n\ndefine GameObjects.createCone ( Radius (r) Height (h) Number of sides (n) Position (x) (y) (z) Rotation (yaw) (pitch) (roll) Material (mat) name (name) )\nset [_*vstart v] to ((length of [vertex_buff v]) + (1))\n_*obj = GameObjects.instantiate ( position (x) (y) (z) rotation (yaw) (pitch) (roll) hidden? <> name (name) dynamic? <> )\nset [i v] to [0]\nrepeat (n)\n    set [_tmp v] to ((((i) + (0.5)) / (n)) * (360))\n    _ptr = vertex_buff.insert_after (xyz ((r) * ([cos v] of (_tmp) )) [0] ((r) * ([sin v] of (_tmp) )) *node (@*vertex_buff_tail) *obj (_*obj) )\n    change [i v] by (1)\nend\n_ptr = vertex_buff.insert_after (xyz [0] (h) [0] *node (@*vertex_buff_tail) *obj (_*obj) )\nset [_tmp2 v] to (_ptr)\n_idxs_tmp.set_range ( (_*vstart) (_tmp2) [1] <> )\n_*prim = primitives.add_polygon_from_idxs_tmp( *object (_*obj) mat (mat) pen radius [] )\nset [j v] to [0]\nrepeat (n)\n    delete all of [_idxs_tmp v]\n    add (_tmp2) to [_idxs_tmp v]\n    add ((_*vstart) + (((j) + (@enum v:SIZE)) mod ((@enum v:SIZE) * (n)))) to [_idxs_tmp v]\n    add ((_*vstart) + ((j) mod ((@enum v:SIZE) * (n)))) to [_idxs_tmp v]\n    _*prim = primitives.add_polygon_from_idxs_tmp( *object (_*obj) mat (mat) pen radius [] )\n    change [j v] by (4)\nend\n\ndefine _tmp = costume_name_to_# ( (name) )\nset [@temp v] to (name)\nbroadcast (render.change_costume_to_\(@tmp\) v) and wait\nif <([costume name v] of [render v]) = (name)> then\n    set [_tmp v] to ([costume # v] of [render v])\nelse\n    set [_tmp v] to [0]\nend\n\nwhen I receive [destroy shadows v]\nprimitives.destroy_shadows\n\ndefine primitives.destroy_shadows\nset [i v] to (*dynamic_seg)\nrepeat until <(length of [primitives v]) = (*dynamic_seg)>\n    repeat (@enum p:SIZE)\n        delete ((*dynamic_seg) + (1)) of [primitives v]\n    end\nend\n\nwhen I receive [generate shadows v]\nprimitives.generate_shadows ()\n\ndefine Materials.setPhysics ( material (mat) no collider? <nocollider> bounciness (bounciness) )\nif <[materials v] contains (mat)?> then\n    replace item ((item # of (mat) in [materials v]) + (6)) of [materials v] with <nocollider>\n    if <not <(bounciness) = []>> then\n        replace item ((item # of (mat) in [materials v]) + (8)) of [materials v] with (bounciness)\n    end\nend\n\ndefine GameObjects.createTri/Quad (Pt A (ax) (ay) (az) Pt B (bx) (by) (bz) Pt C (cx) (cy) (cz) Pt D (leave blank if tri) (dx) (dy) (dz) parent (parent) material (mat) name (name) )\nif <<(parent) = []> or <not <[gameobjects v] contains (parent)?>>> then\n    _*obj = GameObjects.instantiate ( position [0] [0] [0] rotation [0] [0] [0] hidden? <> name (name) dynamic? <> )\n    set [_ptr_to_node v] to (@*vertex_buff_tail)\nelse\n    set [_*obj v] to (item # of (parent) in [gameobjects v])\n    set [_ptr_to_node v] to (item ((_*obj) + (@enum o:*VLEFT)) of [gameobjects v])\nend\ndelete all of [_idxs_tmp v]\n_ptr = vertex_buff.insert_after (xyz (ax) (ay) (az) *node (_ptr_to_node) *obj (_*obj) )\nadd (_ptr) to [_idxs_tmp v]\n_ptr = vertex_buff.insert_after (xyz (bx) (by) (bz) *node (_ptr) *obj (_*obj) )\nadd (_ptr) to [_idxs_tmp v]\n_ptr = vertex_buff.insert_after (xyz (cx) (cy) (cz) *node (_ptr) *obj (_*obj) )\nadd (_ptr) to [_idxs_tmp v]\nif <not <(dx) = []>> then\n    _ptr = vertex_buff.insert_after (xyz (dx) (dy) (dz) *node (_ptr) *obj (_*obj) )\n    add (_ptr) to [_idxs_tmp v]\nend\n_*prim = primitives.add_polygon_from_idxs_tmp( *object (_*obj) mat (mat) pen radius [] )\n\ndefine // (label)\n\ndefine _atan2 = atan2( (y) (x) )\nif <(x) = [0]> then\n    set [_atan2 v] to ((<(y) < [0]> * (-90)) + (<not <(y) < [0]>> * (90)))\nelse\n    if <(x) < [0]> then\n        set [_atan2 v] to ((180) + ([atan v] of ((y) / (x)) ))\n    else\n        set [_atan2 v] to ([atan v] of ((y) / (x)) )\n    end\nend\nset [_atan2 v] to ((_atan2) mod (360))\n\ndefine _x, _y, _z = 3D_cross_prod ( (ax) (ay) (az) (bx) (by) (bz) )\nset [_x v] to (((ay) * (bz)) - ((az) * (by)))\nset [_y v] to (((az) * (bx)) - ((ax) * (bz)))\nset [_z v] to (((ax) * (by)) - ((ay) * (bx)))\n\ndefine Materials.setTexture ( material (mat) texture costume name (tex) )\n_tmp = costume_name_to_# ( (tex) )\nif <[materials v] contains (mat)?> then\n    replace item ((item # of (mat) in [materials v]) + (3)) of [materials v] with (_tmp)\nend\n\ndefine GameObjects.set_updated ( (*obj) )\nif <not <[@updated_objects v] contains (*obj)?>> then\n    add (*obj) to [@updated_objects v]\nend\n\ndefine _*prim = primitives.add_prim ( (type) (first) (second) (third) (fourth) *obj (*obj) material (material) has_normal? <has_normal?> )\nadd (type) to [primitives v]\nset [_*prim v] to (length of [primitives v])\nadd (first) to [primitives v]\nadd (second) to [primitives v]\nadd (third) to [primitives v]\nadd (fourth) to [primitives v]\nadd [*node] to [primitives v]\nadd (*obj) to [primitives v]\nif <<[materials v] contains (material)?> and <not <(material) = []>>> then\n    add (item # of (material) in [materials v]) to [primitives v]\nelse\n    add [1] to [primitives v]\nend\nadd [null] to [primitives v]\nif <has_normal?> then\n    repeat (3)\n        add [0] to [normal_buff v]\n    end\n    add ((length of [normal_buff v]) - (2)) to [primitives v]\nelse\n    add [null] to [primitives v]\nend\nadd [*bsphere] to [primitives v]\nadd [zclip?] to [primitives v]\nadd [show_front?] to [primitives v]\nif <not <(*obj) = [*obj]>> then\n    if <<(length of [gameobjects._*prims v]) = [0]> or <(item ((*obj) + (@enum o:**PLEFT)) of [gameobjects v]) = [p_left]>> then\n        set [_ptr v] to (((item ((item (@GameObjects._*prims.tail) of [gameobjects._*prims v]) + (@enum p:*OBJECT)) of [primitives v]) + (@enum o:**PLEFT)) + (1))\n        _**prim = GameObjects._*prims.insert_after( (_*prim) [] )\n        if <not <(_ptr) = ((@enum o:**PLEFT) + (1))>> then\n            replace item (_ptr) of [gameobjects v] with (_**prim)\n        end\n        replace item ((*obj) + (@enum o:**PLEFT)) of [gameobjects v] with (_**prim)\n        replace item (((*obj) + (@enum o:**PLEFT)) + (1)) of [gameobjects v] with [null]\n    else\n        _**prim = GameObjects._*prims.insert_after( (_*prim) (item ((*obj) + (@enum o:**PLEFT)) of [gameobjects v]) )\n    end\nend\n\ndefine _ptr_to_node = idxs_poly.insert_after ( (*node) (val) )\nset [_tmp v] to (item ((*node) + (1)) of [idxs_poly v])\nreplace item ((*node) + (1)) of [idxs_poly v] with ((length of [idxs_poly v]) + (1))\nadd (val) to [idxs_poly v]\nset [_ptr_to_node v] to (length of [idxs_poly v])\nadd (_tmp) to [idxs_poly v]\n\ndefine _dot = dot_prod (ax) (ay) (az) (bx) (by) (bz)\nset [_dot v] to (((ax) * (bx)) + (((ay) * (by)) + ((az) * (bz))))\n\n@BSP\n\nwhen flag clicked\nset [_frames_since_full_reinsert v] to [0]\nhide\n\ndefine bsp.gen ( (lowerbound) (upperbound) (parent_node) <right?> )\nif <<<(lowerbound) = [null]> or <(upperbound) = [null]>> or <(item ((upperbound) + (2)) of [bsp._*prims v]) = (lowerbound)>> then\n    stop [this script v]\nend\n_pivot = bsp.greedy_pivot_selection (lowerbound) (upperbound)\nif <(_pivot) = [null]> then\n    _tmp = bsp.tree.add_node ( (lowerbound) (upperbound) (parent_node) [null] [] [] )\nelse\n    set [_*pivot_prims_tail v] to (_pivot)\n    if <not <(upperbound) = (lowerbound)>> then\n        _upper, _*pivot_prims_tail = bsp.partition ( (lowerbound) (upperbound) )\n        set [_pivot v] to (_upper)\n    end\n    _*middle = bsp._*prims.group_by_orientation( (_pivot) (_*pivot_prims_tail) )\n    _tmp = bsp.tree.add_node ( (_pivot) (_*pivot_prims_tail) (parent_node) (_*middle) [] [] )\nend\nset [_ptr_to_node v] to (_tmp)\nif <not <(parent_node) = [null]>> then\n    _tmp = bsp.tree.set_edge ( (parent_node) [1] (_ptr_to_node) (<right?> + (1))\nend\nif <<(upperbound) = (lowerbound)> or <(_pivot) = [null]>> then\n    stop [this script v]\nend\nbsp.recurse on low&up ( (lowerbound) (_upper) (_*pivot_prims_tail) (upperbound) (_ptr_to_node)\n\ndefine bsp.__init__ ()\ndelete all of [_bsp.node_tombstones v]\ndelete all of [bsp.tree v]\nadd [2] to [bsp.tree v]\nadd [0] to [bsp.tree v]\ndelete all of [tmp v]\nrepeat (9)\n    add [0] to [tmp v]\nend\nset [@bsp: split count v] to [0]\nbsp._*prims.__init_non_dynamic__()\n\ndefine bsp.recurse on low&up ( (lowerbound) (*pivot_list_head) (*pivot_list_tail) (upperbound) (*parent_node)\nbsp.gen ( (lowerbound) (item ((*pivot_list_head) + (1)) of [bsp._*prims v]) (*parent_node)  )\nbsp.gen ( (item ((*pivot_list_tail) + (2)) of [bsp._*prims v]) (upperbound) (*parent_node)  )\n\nwhen I receive [gen bsp v]\nbsp.__init__ ()\nif <(length of [bsp._*prims v]) > [0]> then\n    bsp.gen ( [1] ((length of [bsp._*prims v]) - (3)) [null] <> )\nend\nbsp.handle_dynamic_objects ()\nvertex_buff = inverse_world_tranform()\n\ndefine _*prim = primitives.split_prim ( *prim (*prim) *intersectA (*a) *intersectB (*b) )\nchange [@bsp: split count v] by (1)\n_ptr_to_node = idxs_poly.insert_after ( (*a) (item (*a) of [idxs_poly v]) )\nset [_x v] to (_ptr_to_node)\n_ptr_to_node = idxs_poly.insert_after ( (*b) (item (*b) of [idxs_poly v]) )\nreplace item ((*a) + (1)) of [idxs_poly v] with (_ptr_to_node)\nreplace item ((*b) + (1)) of [idxs_poly v] with (_x)\n_*prim = primitives.add_prim ( [POLYGON] (*b) (item ((*prim) + (2)) of [primitives v]) (item ((*prim) + (3)) of [primitives v]) (item ((*prim) + (4)) of [primitives v]) (item ((*prim) + (@enum p:*OBJECT)) of [primitives v]) (item (item ((*prim) + (@enum p:MATERIAL)) of [primitives v]) of [materials v]) (item ((*prim) + (@enum p:NORMAL)) of [primitives v]) )\n\ndefine bsp._*prims.__init_non_dynamic__()\ndelete all of [bsp._*prims v]\nset [i v] to [0]\nset [_*prim v] to [1]\nrepeat until <not <(_*prim) < (length of [primitives v])>>\n    if <(item ((item ((_*prim) + (@enum p:*OBJECT)) of [primitives v]) + (@enum o:DYNAMIC_PARENT)) of [gameobjects v]) = [0]> then\n        add (_*prim) to [bsp._*prims v]\n        add ((((i) - (1)) * (4)) + (1)) to [bsp._*prims v]\n        add ((((i) + (1)) * (4)) + (1)) to [bsp._*prims v]\n        add [FRONT] to [bsp._*prims v]\n        change [i v] by (1)\n        if <not <(item ((_*prim) + (@enum p:NORMAL)) of [primitives v]) = [null]>> then\n            set [_tmp v] to (item ((_*prim) + (@enum p:MATERIAL)) of [primitives v])\n            if <<not <(_tmp) = [0]>> and <not <(item ((_tmp) + (1)) of [materials v]) = [0]>>> then\n                add (_*prim) to [bsp._*prims v]\n                add ((((i) - (1)) * (4)) + (1)) to [bsp._*prims v]\n                add ((((i) + (1)) * (4)) + (1)) to [bsp._*prims v]\n                add [BACK] to [bsp._*prims v]\n                change [i v] by (1)\n            end\n        end\n    end\n    change [_*prim v] by (@enum p:SIZE)\nend\nreplace item (2) of [bsp._*prims v] with [null]\nreplace item ((length of [bsp._*prims v]) - (1)) of [bsp._*prims v] with [null]\nset [@bsp._*prims.tail v] to (((length of [bsp._*prims v]) - (3)) * <(length of [bsp._*prims v]) > [0]>)\nbsp._*prims.randomize_order() [1] (@bsp._*prims.tail)\n\ndefine _upper, _*pivot_prims_tail = bsp.partition ( (l) (u) )\nset [_lower v] to (l)\nset [_upper v] to (u)\nset [_pivot v] to (item (u) of [bsp._*prims v])\nset [_pivot_ori v] to (item ((u) + (3)) of [bsp._*prims v])\nset [_*pivot_prims_tail v] to (u)\nidx_poly.add_prim_vert_to_tmp ( (item ((_pivot) + (1)) of [primitives v]) [1]\n_Nx, _Ny, _Nz = primitives.get_prim_normal ( (_pivot) )\nset [_node_curr v] to (item ((_upper) + (1)) of [bsp._*prims v])\nrepeat until <(_upper) = (_lower)>\n    _node_curr, _ori, _intersects = get_orientation_of_*poly_to_plane (P, N) ( *poly (item (_node_curr) of [bsp._*prims v]) plane (P,N) (item (1) of [tmp v]) (item (2) of [tmp v]) (item (3) of [tmp v]) (_Nx) (_Ny) (_Nz) do split?  **Prim (_node_curr) )\n    if <(_intersects?) = [0]> then\n        if <<(_ori) = [0]> or <(_ori) = [null]>> then\n            replace item (_upper) of [bsp._*prims v] with (item (_*pivot_prims_tail) of [bsp._*prims v])\n            replace item (_*pivot_prims_tail) of [bsp._*prims v] with (item (_node_curr) of [bsp._*prims v])\n            replace item ((_upper) + (3)) of [bsp._*prims v] with (item ((_*pivot_prims_tail) + (3)) of [bsp._*prims v])\n            replace item ((_*pivot_prims_tail) + (3)) of [bsp._*prims v] with (item ((_node_curr) + (3)) of [bsp._*prims v])\n            set [_tmp v] to (_node_curr)\n            set [_node_curr v] to (item ((_node_curr) + (1)) of [bsp._*prims v])\n            set [_upper v] to (_tmp)\n            if <<not <(_ori) = [null]>> or <(item ((item (_tmp) of [bsp._*prims v]) + (@enum p:NORMAL)) of [primitives v]) = [null]>> then\n                set [_*pivot_prims_tail v] to (item ((_*pivot_prims_tail) + (1)) of [bsp._*prims v])\n            end\n        else\n            bsp._*prims.swap ( *a (_node_curr) *b (_lower) )\n            set [_lower v] to (item ((_lower) + (2)) of [bsp._*prims v])\n        end\n    end\nend\nreplace item (_upper) of [bsp._*prims v] with (_pivot)\nreplace item ((_upper) + (3)) of [bsp._*prims v] with (_pivot_ori)\n\ndefine _pivot = bsp.greedy_pivot_selection (l) (u)\nset [_node_curr v] to (l)\nset [_pivot v] to [null]\nset [_min_splits v] to ((1) / (0))\n_min_splits, _pivot = test_prim_as_pivot (_node_curr) (l) (u)\nrepeat until <<(_node_curr) = (u)> or <(_min_splits) = [0]>>\n    set [_node_curr v] to (item ((_node_curr) + (2)) of [bsp._*prims v])\n    _min_splits, _pivot = test_prim_as_pivot (_node_curr) (l) (u)\nend\nif <not <(_pivot) = [null]>> then\n    bsp._*prims.swap ( *a (_pivot) *b (u) )\nend\n\ndefine _min_splits, _pivot = test_prim_as_pivot (**prim) (l) (u)\nif <(item ((item (**prim) of [bsp._*prims v]) + (@enum p:NORMAL)) of [primitives v]) = [null]> then\n    stop [this script v]\nend\nidx_poly.add_prim_vert_to_tmp ( (item ((item (**prim) of [bsp._*prims v]) + (1)) of [primitives v]) [1]\n_Nx, _Ny, _Nz = primitives.get_prim_normal ( (item (**prim) of [bsp._*prims v]) )\nset [j v] to (l)\nset [_split_count_tmp v] to [0]\nrepeat until <(j) = (item ((u) + (2)) of [bsp._*prims v])>\n    if <not <(j) = (**prim)>> then\n        _node_curr, _ori, _intersects = get_orientation_of_*poly_to_plane (P, N) ( *poly (item (j) of [bsp._*prims v]) plane (P,N) (item (1) of [tmp v]) (item (2) of [tmp v]) (item (3) of [tmp v]) (_Nx) (_Ny) (_Nz) do split? <> **Prim (j) )\n        if <(_intersects?) = [1]> then\n            change [_split_count_tmp v] by (1)\n            if <not <(_split_count_tmp) < (_min_splits)>> then\n                stop [this script v]\n            end\n        end\n    end\n    set [j v] to (item ((j) + (2)) of [bsp._*prims v])\nend\nset [_min_splits v] to (_split_count_tmp)\nset [_pivot v] to (**prim)\n\ndefine _ptr = vertex_world.insert_after ( prevNode (*node) data (x) (y) (z) *object (*obj) )\nif <<(length of [vertex_world v]) < (*node)> or <(*node) = [0]>> then\n    set [_tmp v] to [null]\nelse\n    set [_tmp v] to (item ((*node) + (3)) of [vertex_world v])\n    replace item ((*node) + (3)) of [vertex_world v] with ((length of [vertex_world v]) + (1))\nend\nadd (x) to [vertex_world v]\nset [_ptr v] to (length of [vertex_world v])\nadd (y) to [vertex_world v]\nadd (z) to [vertex_world v]\nadd (_tmp) to [vertex_world v]\nif <not <(*obj) = [*obj]>> then\n    if <<(length of [vertex_buff v]) = [0]> or <(item ((*obj) + (@enum o:*VLEFT)) of [gameobjects v]) = [v_left]>> then\n        replace item (((@*vertex_buff_tail_obj) + (@enum o:*VLEFT)) + (1)) of [gameobjects v] with (_ptr)\n        replace item ((*obj) + (@enum o:*VLEFT)) of [gameobjects v] with (_ptr)\n        replace item (((*obj) + (@enum o:*VLEFT)) + (1)) of [gameobjects v] with [null]\n    end\nend\nif <(*node) = (@*vertex_buff_tail)> then\n    set [@*vertex_buff_tail v] to (_ptr)\n    if <not <(*obj) = (@*vertex_buff_tail_obj)>> then\n        set [@*vertex_buff_tail_obj v] to (*obj)\n    end\nend\n\ndefine _**prim = bsp._*prims.insert_after ( (*prim) (*elem) (*mem_loc) (orientation) )\nif <(length of [bsp._*prims v]) = [0]> then\n    add (*prim) to [bsp._*prims v]\n    set [_**prim v] to (length of [bsp._*prims v])\n    add [null] to [bsp._*prims v]\n    add [null] to [bsp._*prims v]\n    add (orientation) to [bsp._*prims v]\n    set [@bsp._*prims.tail v] to (_**prim)\n    stop [this script v]\nend\nset [_tmp v] to (item ((*elem) + (2)) of [bsp._*prims v])\nif <(_tmp) = (*mem_loc)> then\n    replace item (*mem_loc) of [bsp._*prims v] with (*prim)\n    replace item ((*mem_loc) + (3)) of [bsp._*prims v] with (orientation)\n    stop [this script v]\nend\nif <(*mem_loc) = []> then\n    add (*prim) to [bsp._*prims v]\n    set [_**prim v] to (length of [bsp._*prims v])\n    add (*elem) to [bsp._*prims v]\n    add (_tmp) to [bsp._*prims v]\n    add (orientation) to [bsp._*prims v]\nelse\n    set [_**prim v] to (*mem_loc)\n    replace item (*mem_loc) of [bsp._*prims v] with (*prim)\n    replace item ((*mem_loc) + (1)) of [bsp._*prims v] with (*elem)\n    replace item ((*mem_loc) + (2)) of [bsp._*prims v] with (_tmp)\n    replace item ((*mem_loc) + (3)) of [bsp._*prims v] with (orientation)\nend\nif <<not <(_tmp) = (*mem_loc)>> and <not <(_tmp) = [null]>>> then\n    replace item ((_tmp) + (1)) of [bsp._*prims v] with (_**prim)\nend\nif <(_tmp) = [null]> then\n    set [@bsp._*prims.tail v] to (_**prim)\nend\nreplace item ((*elem) + (2)) of [bsp._*prims v] with (_**prim)\n\ndefine bsp._*prims.randomize_order() (*left) (*right)\n\nset [i v] to (*left)\nrepeat until <(i) > (*right)>\n    set [_tmp v] to ((([floor v] of (((pick random (i) to (length of [bsp._*prims v])) - (1)) / (4)) ) * (4)) + (1))\n    bsp._*prims.swap ( *a (*left) *b (_tmp) )\n    change [i v] by (4)\nend\n\ndefine _Nx, _Ny, _Nz = primitives.get_prim_normal ( (*prim) )\nset [_tmp v] to (item ((*prim) + (@enum p:NORMAL)) of [primitives v])\nset [_nx v] to (item (_tmp) of [normal_world v])\nset [_ny v] to (item ((_tmp) + (1)) of [normal_world v])\nset [_nz v] to (item ((_tmp) + (2)) of [normal_world v])\n\ndefine _node_curr, _ori, _intersects = get_orientation_of_*poly_to_plane (P, N) ( *poly (*poly) plane (P,N) (px) (py) (pz) (nx) (ny) (nz) do split? <do_split?> **Prim (**prim) )\nset [_intersects? v] to [0]\nset [_count v] to [0]\nset [_polyidx_prev v] to (item ((*poly) + (1)) of [primitives v])\nset [_polyidx_curr v] to (item ((_polyidx_prev) + (1)) of [idxs_poly v])\nidx_poly.add_prim_vert_to_tmp ( (_polyidx_prev) [3]\n_dot = dot_prod ((item (7) of [tmp v]) - (px)) ((item (8) of [tmp v]) - (py)) ((item (9) of [tmp v]) - (pz)) (nx) (ny) (nz)\nset [_dot_curr v] to (_dot)\nset [_sign_prev v] to (((-1) * <(_dot_curr) < ((-1) * (@coplanar_thresh))>) + <(_dot_curr) > (@coplanar_thresh)>)\nset [_ori v] to [null]\nif <not <([abs v] of (_dot_curr) ) < (@coplanar_thresh)>> then\n    set [_ori v] to <(_dot_curr) < [0]>\nend\ndelete all of [intersect v]\nrepeat until <<<(_polyidx_prev) = (item ((*poly) + (1)) of [primitives v])> and <(_count) > [0]>> or <(_polyidx_curr) = (_polyidx_prev)>>\n    idx_poly.add_prim_vert_to_tmp ( (_polyidx_prev) [2]\n    idx_poly.add_prim_vert_to_tmp ( (_polyidx_curr) [3]\n    _dot = dot_prod ((item (7) of [tmp v]) - (px)) ((item (8) of [tmp v]) - (py)) ((item (9) of [tmp v]) - (pz)) (nx) (ny) (nz)\n    set [_dot_prev v] to (_dot_curr)\n    set [_dot_curr v] to (_dot)\n    set [_sign_curr v] to (((-1) * <(_dot_curr) < ((-1) * (@coplanar_thresh))>) + <(_dot_curr) > (@coplanar_thresh)>)\n    if <<(_ori) = [null]> and <not <([abs v] of (_dot_curr) ) < (@coplanar_thresh)>>> then\n        set [_ori v] to <(_dot_curr) < [0]>\n    end\n    if <<not <(_sign_prev) = (_sign_curr)>> and <not <(_sign_curr) = [0]>>> then\n        set [_sign_prev v] to (_sign_curr)\n        if <not <([abs v] of (_dot_prev) ) < (@coplanar_thresh)>> then\n            if <do_split?> then\n                _dot = dot_prod ((item (7) of [tmp v]) - (item (4) of [tmp v])) ((item (8) of [tmp v]) - (item (5) of [tmp v])) ((item (9) of [tmp v]) - (item (6) of [tmp v])) (nx) (ny) (nz)\n                set [_α v] to ((-1) * ((_dot_curr) / (_dot)))\n                set [_x v] to ((item (7) of [tmp v]) + (((item (7) of [tmp v]) - (item (4) of [tmp v])) * (_α)))\n                set [_y v] to ((item (8) of [tmp v]) + (((item (8) of [tmp v]) - (item (5) of [tmp v])) * (_α)))\n                set [_z v] to ((item (9) of [tmp v]) + (((item (9) of [tmp v]) - (item (6) of [tmp v])) * (_α)))\n                set [_*obj v] to (item ((*poly) + (@enum p:*OBJECT)) of [primitives v])\n                _ptr = vertex_world.insert_after ( prevNode (item ((_*obj) + (@enum o:*VLEFT)) of [gameobjects v]) data (_x) (_y) (_z) *object (_*obj) )\n                _ptr_to_node = idxs_poly.insert_after ( (_polyidx_prev) (_ptr) )\n            end\n            add (_ptr_to_node) to [intersect v]\n        else\n            add (_polyidx_prev) to [intersect v]\n        end\n        if <(length of [intersect v]) = [2]> then\n            set [_intersects? v] to [1]\n            if <not <do_split?>> then\n                stop [this script v]\n            end\n            _*prim = primitives.split_prim ( *prim (*poly) *intersectA (item (1) of [intersect v]) *intersectB (item (2) of [intersect v]) )\n            _**prim = bsp._*prims.insert_after ( (_*prim) (**prim) [] (item ((**prim) + (3)) of [bsp._*prims v]) )\n            set [_polyidx_prev v] to ((length of [idxs_poly v]) - (1))\n            delete all of [intersect v]\n            set [_node_curr v] to (item ((_node_curr) + (2)) of [bsp._*prims v])\n        end\n    end\n    change [_count v] by (1)\n    set [_polyidx_prev v] to (_polyidx_curr)\n    set [_polyidx_curr v] to (item ((_polyidx_prev) + (1)) of [idxs_poly v])\nend\n\ndefine idx_poly.add_prim_vert_to_tmp ( (*idx_poly) (pos)\nset [_tmp v] to (item (*idx_poly) of [idxs_poly v])\nreplace item ((((pos) - (1)) * (3)) + (1)) of [tmp v] with (item (_tmp) of [vertex_world v])\nreplace item ((((pos) - (1)) * (3)) + (2)) of [tmp v] with (item ((_tmp) + (1)) of [vertex_world v])\nreplace item ((((pos) - (1)) * (3)) + (3)) of [tmp v] with (item ((_tmp) + (2)) of [vertex_world v])\n\nwhen I receive [bsp.reinsert_prims v]\nbsp.tree.reinsert_updated_objects\n\ndefine _tmp = bsp.tree.set_edge ( (*u) (w) (*v) (edge_index)\nset [_tmp v] to ((*u) + ((((edge_index) - (1)) * (2)) + (@enum t:EDGE_A)))\nreplace item (_tmp) of [bsp.tree v] with (w)\nreplace item ((_tmp) + (1)) of [bsp.tree v] with (*v)\n\ndefine _tmp = bsp.tree.add_node ( (*prim_list_head) (*prim_list_tail) (*parent) (*prim_list_middle) (*left_child) (*right_child) )\nreplace item (2) of [bsp.tree v] with ((item (2) of [bsp.tree v]) + (1))\nif <(length of [_bsp.node_tombstones v]) > [0]> then\n    set [_tmp v] to (item (1) of [_bsp.node_tombstones v])\n    delete (1) of [_bsp.node_tombstones v]\n    replace item (_tmp) of [bsp.tree v] with (*prim_list_head)\n    replace item ((_tmp) + (1)) of [bsp.tree v] with (*prim_list_middle)\n    replace item ((_tmp) + (2)) of [bsp.tree v] with (*prim_list_tail)\n    replace item ((_tmp) + (3)) of [bsp.tree v] with [-1]\n    replace item ((_tmp) + (4)) of [bsp.tree v] with []\n    replace item ((_tmp) + (5)) of [bsp.tree v] with (*left_child)\n    replace item ((_tmp) + (6)) of [bsp.tree v] with []\n    replace item ((_tmp) + (7)) of [bsp.tree v] with (*right_child)\n    replace item ((_tmp) + (8)) of [bsp.tree v] with (*parent)\nelse\n    add (*prim_list_head) to [bsp.tree v]\n    set [_tmp v] to (length of [bsp.tree v])\n    add (*prim_list_middle) to [bsp.tree v]\n    add (*prim_list_tail) to [bsp.tree v]\n    add [-1] to [bsp.tree v]\n    add [] to [bsp.tree v]\n    add (*left_child) to [bsp.tree v]\n    add [] to [bsp.tree v]\n    add (*right_child) to [bsp.tree v]\n    add (*parent) to [bsp.tree v]\nend\nif <not <(*prim_list_head) = [null]>> then\n    set [i v] to (*prim_list_head)\n    replace item ((item (i) of [bsp._*prims v]) + (@enum p:*NODE)) of [primitives v] with (_tmp)\n    repeat until <(i) = (*prim_list_tail)>\n        set [i v] to (item ((i) + (2)) of [bsp._*prims v])\n        replace item ((item (i) of [bsp._*prims v]) + (@enum p:*NODE)) of [primitives v] with (_tmp)\n    end\nend\n\ndefine bsp.tree.realloc_node ( (*node) (*new_loc) )\nset [_tmp2 v] to (item ((*node) + (@enum t:PARENT)) of [bsp.tree v])\nset [i v] to [0]\nrepeat (@enum t:SIZE)\n    replace item ((*new_loc) + (i)) of [bsp.tree v] with (item (*node) of [bsp.tree v])\n    delete (*node) of [bsp.tree v]\n    change [i v] by (1)\nend\nif <(item ((_tmp2) + ((@enum t:EDGE_A) + (1))) of [bsp.tree v]) = (*node)> then\n    _tmp = bsp.tree.set_edge ( (_tmp2) [1] (*new_loc) [1]\nelse\n    _tmp = bsp.tree.set_edge ( (_tmp2) [1] (*new_loc) [2]\nend\nset [i v] to ((*new_loc) + ((@enum t:EDGE_A) + (1)))\nrepeat (2)\n    if <not <(item (i) of [bsp.tree v]) = []>> then\n        replace item ((item (i) of [bsp.tree v]) + (@enum t:PARENT)) of [bsp.tree v] with (*new_loc)\n    end\n    change [i v] by (2)\nend\n\ndefine bsp.tree.remove_leaf_node ( (*node) )\nreplace item (2) of [bsp.tree v] with ((item (2) of [bsp.tree v]) + (-1))\nset [_tmp v] to (item ((*node) + (@enum t:PARENT)) of [bsp.tree v])\nif <(item ((_tmp) + ((@enum t:EDGE_A) + (1))) of [bsp.tree v]) = (*node)> then\n    _tmp = bsp.tree.set_edge ( (_tmp) [] [] [1]\nelse\n    _tmp = bsp.tree.set_edge ( (_tmp) [] [] [2]\nend\nif <(*node) = ((length of [bsp.tree v]) - ((@enum t:SIZE) + (1)))> then\n    repeat (@enum t:SIZE)\n        delete (*node) of [bsp.tree v]\n    end\nelse\n    add (*node) to [_bsp.node_tombstones v]\n    replace item (*node) of [bsp.tree v] with [TOMBSTONE]\nend\n\ndefine primitives.add_first_prim_vert_to_tmp ( (*prim) (pos)\nif <(item (*prim) of [primitives v]) = [POLYGON]> then\n    set [_tmp v] to (item (item ((*prim) + (1)) of [primitives v]) of [idxs_poly v])\nelse\n    set [_tmp v] to (item ((*prim) + (1)) of [primitives v])\nend\nif <<not <(_*player_container_prim) = [0]>> and <(*prim) = (_*player_container_prim)>> then\n    set [_x v] to ((@camX) - (item (_tmp) of [vertex_world v]))\n    set [_y v] to ((@camY) - (item ((_tmp) + (1)) of [vertex_world v]))\n    set [_z v] to ((@camZ) - (item ((_tmp) + (2)) of [vertex_world v]))\n    set [_tmp2 v] to (([sqrt v] of (((_x) * (_x)) + (((_y) * (_y)) + ((_z) * (_z)))) ) / (item ((*prim) + (@enum p:RADIUS)) of [primitives v]))\n    replace item ((((pos) - (1)) * (3)) + (1)) of [tmp v] with ((item (_tmp) of [vertex_world v]) + ((_x) / (_tmp2)))\n    replace item ((((pos) - (1)) * (3)) + (2)) of [tmp v] with ((item ((_tmp) + (1)) of [vertex_world v]) + ((_y) / (_tmp2)))\n    replace item ((((pos) - (1)) * (3)) + (3)) of [tmp v] with ((item ((_tmp) + (2)) of [vertex_world v]) + ((_z) / (_tmp2)))\nelse\n    replace item ((((pos) - (1)) * (3)) + (1)) of [tmp v] with (item (_tmp) of [vertex_world v])\n    replace item ((((pos) - (1)) * (3)) + (2)) of [tmp v] with (item ((_tmp) + (1)) of [vertex_world v])\n    replace item ((((pos) - (1)) * (3)) + (3)) of [tmp v] with (item ((_tmp) + (2)) of [vertex_world v])\nend\n\ndefine _tmp, _tmp2 = bsp._*prims.pop ( (*elem)\nset [_tmp v] to (item ((*elem) + (1)) of [bsp._*prims v])\nset [_tmp2 v] to (item ((*elem) + (2)) of [bsp._*prims v])\nif <not <(_tmp) = [null]>> then\n    replace item ((_tmp) + (2)) of [bsp._*prims v] with (_tmp2)\nend\nif <not <(_tmp2) = [null]>> then\n    replace item ((_tmp2) + (1)) of [bsp._*prims v] with (_tmp)\nelse\n    set [@bsp._*prims.tail v] to (_tmp)\nend\nset [_tmp v] to (item (*elem) of [bsp._*prims v])\nset [_tmp2 v] to (item ((*elem) + (3)) of [bsp._*prims v])\nreplace item (*elem) of [bsp._*prims v] with [TOMBSTONE]\nreplace item ((*elem) + (1)) of [bsp._*prims v] with []\nreplace item ((*elem) + (2)) of [bsp._*prims v] with []\nreplace item ((*elem) + (3)) of [bsp._*prims v] with []\n\ndefine _x, _y, z = apply_rot_matrix ( (x) (y) (z) )\nset [_x v] to ((((x) * (_rm1)) + ((y) * (_rm2))) + ((z) * (_rm3)))\nset [_y v] to (((x) * (_rm4)) + (((y) * (_rm5)) + ((z) * (_rm6))))\nset [_z v] to (((x) * (_rm7)) + (((y) * (_rm8)) + ((z) * (_rm9))))\n\ndefine set_inv_rot_matrix_αβγ( (cos α) (sin α) (cos β) (sin β) (cos γ) (sin γ) )\nset [_rm1 v] to (((cos α) * (cos γ)) + ((sin α) * ((sin β) * (sin γ))))\nset [_rm2 v] to ((cos β) * (sin γ))\nset [_rm3 v] to ((((cos α) * (sin β)) * (sin γ)) - ((cos γ) * (sin α)))\nset [_rm4 v] to ((((cos γ) * (sin α)) * (sin β)) - ((cos α) * (sin γ)))\nset [_rm5 v] to ((cos β) * (cos γ))\nset [_rm6 v] to (((cos α) * ((cos γ) * (sin β))) + ((sin α) * (sin γ)))\nset [_rm7 v] to ((cos β) * (sin α))\nset [_rm8 v] to ((-1) * (sin β))\nset [_rm9 v] to ((cos α) * (cos β))\n\ndefine _*middle = bsp._*prims.group_by_orientation( (*head) (*tail) )\ndelete all of [tmp2 v]\ndelete all of [tmp3 v]\n_Nx, _Ny, _Nz = primitives.get_prim_normal ( (item (*head) of [bsp._*prims v]) )\nset [_x v] to (_Nx)\nset [_y v] to (_Ny)\nset [_z v] to (_Nz)\nset [i v] to (*head)\nrepeat until <<(item ((i) + (1)) of [bsp._*prims v]) = (*tail)> or <(i) = [null]>>\n    _Nx, _Ny, _Nz = primitives.get_prim_normal ( (item (i) of [bsp._*prims v]) )\n    if <((((_x) * (_Nx)) + ((_y) * (_Ny))) + ((_z) * (_Nz))) > [0]> then\n        if <(item ((i) + (3)) of [bsp._*prims v]) = [FRONT]> then\n            add (item (i) of [bsp._*prims v]) to [tmp2 v]\n            add (item ((i) + (3)) of [bsp._*prims v]) to [tmp2 v]\n        else\n            add (item (i) of [bsp._*prims v]) to [tmp3 v]\n            add (item ((i) + (3)) of [bsp._*prims v]) to [tmp3 v]\n        end\n    else\n        if <(item ((i) + (3)) of [bsp._*prims v]) = [FRONT]> then\n            add (item (i) of [bsp._*prims v]) to [tmp3 v]\n            add (item ((i) + (3)) of [bsp._*prims v]) to [tmp3 v]\n        else\n            add (item (i) of [bsp._*prims v]) to [tmp2 v]\n            add (item ((i) + (3)) of [bsp._*prims v]) to [tmp2 v]\n        end\n    end\n    set [i v] to (item ((i) + (2)) of [bsp._*prims v])\nend\nset [i v] to (*head)\nrepeat ((length of [tmp2 v]) / (2))\n    replace item (i) of [bsp._*prims v] with (item (1) of [tmp2 v])\n    delete (1) of [tmp2 v]\n    replace item ((i) + (3)) of [bsp._*prims v] with (item (1) of [tmp2 v])\n    delete (1) of [tmp2 v]\n    set [i v] to (item ((i) + (2)) of [bsp._*prims v])\nend\nif <(length of [tmp3 v]) > [0]> then\n    set [_*middle v] to (i)\nelse\n    set [_*middle v] to [null]\nend\nrepeat ((length of [tmp3 v]) / (2))\n    replace item (i) of [bsp._*prims v] with (item (1) of [tmp3 v])\n    delete (1) of [tmp3 v]\n    replace item ((i) + (3)) of [bsp._*prims v] with (item (1) of [tmp3 v])\n    delete (1) of [tmp3 v]\n    set [i v] to (item ((i) + (2)) of [bsp._*prims v])\nend\n\ndefine bsp.handle_dynamic_objects ()\nif <(length of [bsp.tree v]) < [3]> then\n    _tmp = bsp.tree.add_node ( [null] [null] [null] [null] [] [] )\nend\nset [_*obj v] to [1]\ndelete all of [_dynamic _obj_queue v]\nrepeat ((length of [gameobjects v]) / (@enum o:SIZE))\n    if <not <(item ((_*obj) + (@enum o:DYNAMIC_PARENT)) of [gameobjects v]) = [0]>> then\n        add (_*obj) to [@dynamic_objects v]\n        add (_*obj) to [_dynamic _obj_queue v]\n    end\n    change [_*obj v] by (@enum o:SIZE)\nend\nrepeat until <(length of [_dynamic _obj_queue v]) = [0]>\n    set [_*obj v] to (item (1) of [_dynamic _obj_queue v])\n    delete (1) of [_dynamic _obj_queue v]\n    set [_dynamic_parent v] to (item ((_*obj) + (@enum o:DYNAMIC_PARENT)) of [gameobjects v])\n    if <<not <(_dynamic_parent) = [ROOT]>> and <(item ((_dynamic_parent) + (@enum o:*CONTAINER_PRIM)) of [gameobjects v]) = []>> then\n        add (_*obj) to [_dynamic _obj_queue v]\n    else\n        set [_tmp v] to (item ((_*obj) + (@enum o:*BSPHERE)) of [gameobjects v])\n        set [_tmp2 v] to (item ((_*obj) + (@enum o:*VLEFT)) of [gameobjects v])\n        if <[@dynamic_obj_center_offset v] contains (join [*obj:] (_*obj))?> then\n            set [_α v] to (item # of (join [*obj:] (_*obj)) in [@dynamic_obj_center_offset v])\n            add ((item ((_tmp) + (0)) of [bsphere_world v]) + (item ((_α) + (1)) of [@dynamic_obj_center_offset v])) to [vertex_world v]\n            set [_*vertex v] to (length of [vertex_world v])\n            add ((item ((_tmp) + (1)) of [bsphere_world v]) + (item ((_α) + (2)) of [@dynamic_obj_center_offset v])) to [vertex_world v]\n            add ((item ((_tmp) + (2)) of [bsphere_world v]) + (item ((_α) + (3)) of [@dynamic_obj_center_offset v])) to [vertex_world v]\n        else\n            add (item ((_tmp) + (0)) of [bsphere_world v]) to [vertex_world v]\n            set [_*vertex v] to (length of [vertex_world v])\n            add (item ((_tmp) + (1)) of [bsphere_world v]) to [vertex_world v]\n            add (item ((_tmp) + (2)) of [bsphere_world v]) to [vertex_world v]\n        end\n        add (item ((_tmp2) + (3)) of [vertex_world v]) to [vertex_world v]\n        replace item ((_tmp2) + (3)) of [vertex_world v] with (_*vertex)\n        set [j v] to (item ((_*obj) + (@enum o:**PLEFT)) of [gameobjects v])\n        set [_upper v] to (item ((_*obj) + ((@enum o:**PLEFT) + (1))) of [gameobjects v])\n        repeat until <<(j) = (_upper)> or <(j) = [null]>>\n            set [_*prim v] to (item (j) of [gameobjects._*prims v])\n            _**prim = bsp._*prims.insert_after ( (_*prim) (@bsp._*prims.tail) [] [FRONT] )\n            if <(j) = (item ((_*obj) + (@enum o:**PLEFT)) of [gameobjects v])> then\n                set [_lower v] to (_**prim)\n            end\n            if <not <(item ((_*prim) + (@enum p:NORMAL)) of [primitives v]) = [null]>> then\n                if <not <(item ((item ((_*prim) + (@enum p:MATERIAL)) of [primitives v]) + (1)) of [materials v]) = [0]>> then\n                    _**prim = bsp._*prims.insert_after ( (_*prim) (@bsp._*prims.tail) [] [BACK] )\n                end\n            end\n            set [j v] to (item ((j) + (1)) of [gameobjects._*prims v])\n        end\n        set [_root v] to ((length of [bsp.tree v]) + (1))\n        bsp._*prims.randomize_order() (_lower) ((_**prim) + (3))\n        bsp.gen ( (_lower) (_**prim) [null] <> )\n        _*prim = primitives.add_prim ( [CONTAINER] (_*vertex) (_root) [] (item ((item ((_*obj) + (@enum o:*BSPHERE)) of [gameobjects v]) + (3)) of [bsphere_world v]) (_*obj) [] [null] )\n        if <(_*obj) = (@*player_obj)> then\n            set [_*player_container_prim v] to (_*prim)\n        end\n        replace item ((_*obj) + (@enum o:*CONTAINER_PRIM)) of [gameobjects v] with (_*prim)\n        if <(_dynamic_parent) = [ROOT]> then\n            bsp.tree.insert_prim ( (_*prim) [] [3] [FRONT] level [1] local_var_stack [] )\n        else\n            bsp.tree.insert_prim ( (_*prim) [] (item ((item ((_dynamic_parent) + (@enum o:*CONTAINER_PRIM)) of [gameobjects v]) + (@enum p:*SUBTREE_ROOT)) of [primitives v]) [FRONT] level [1] local_var_stack [] )\n        end\n    end\nend\nif <[@dynamic_objects v] contains (@*player_obj)?> then\n    delete (item # of (@*player_obj) in [@dynamic_objects v]) of [@dynamic_objects v]\n    add (@*player_obj) to [@dynamic_objects v]\nend\n\ndefine _**prim = bsp.tree.remove_prim_from_node ( (*node) (*prim) )\nset [_*head v] to (item (*node) of [bsp.tree v])\nset [_**prim v] to (_*head)\nset [_*middle v] to (item ((*node) + (@enum t:MIDDLE)) of [bsp.tree v])\nset [_*pivot_prims_tail v] to (item ((*node) + (@enum t:TAIL)) of [bsp.tree v])\nif <(_*head) = (_*pivot_prims_tail)> then\n    bsp.tree.remove_leaf_node ( (*node) )\nelse\n    repeat until <(item (_**prim) of [bsp._*prims v]) = (*prim)>\n        set [_**prim v] to (item ((_**prim) + (2)) of [bsp._*prims v])\n    end\n    if <(_**prim) = (_*head)> then\n        replace item (*node) of [bsp.tree v] with (item ((_*head) + (2)) of [bsp._*prims v])\n    else\n        if <(_**prim) = (_*middle)> then\n            if <(_*middle) = (_*pivot_prims_tail)> then\n                replace item ((*node) + (@enum t:MIDDLE)) of [bsp.tree v] with [null]\n            else\n                replace item ((*node) + (@enum t:MIDDLE)) of [bsp.tree v] with (item ((_*middle) + (2)) of [bsp._*prims v])\n            end\n        end\n        if <(_**prim) = (_*pivot_prims_tail)> then\n            replace item ((*node) + (@enum t:TAIL)) of [bsp.tree v] with (item ((_*pivot_prims_tail) + (1)) of [bsp._*prims v])\n            set [_*pivot_prims_tail v] to (item ((_*pivot_prims_tail) + (1)) of [bsp._*prims v])\n        end\n    end\nend\n\ndefine bsp.tree.insert_prim ( (*prim) (old_**prim) (*root) (orientation) level (level) local_var_stack (stack:_current) )\nset [_current v] to (*root)\nprimitives.add_first_prim_vert_to_tmp ( (*prim) [2]\nset [_*prim v] to (item (item (_current) of [bsp.tree v]) of [bsp._*prims v])\nset [_r v] to (item ((*prim) + (@enum p:RADIUS)) of [primitives v])\nset [_orientation v] to [1]\nrepeat until <<(_current) = []> or <<(_orientation) = [0]> or <(item ((_*prim) + (@enum p:NORMAL)) of [primitives v]) = [null]>>>\n    primitives.add_first_prim_vert_to_tmp ( (_*prim) [1]\n    set [_tmp2 v] to (item ((_*prim) + (@enum p:NORMAL)) of [primitives v])\n    set [_dot v] to ((((item (4) of [tmp v]) - (item (1) of [tmp v])) * (item (_tmp2) of [normal_world v])) + ((((item (5) of [tmp v]) - (item (2) of [tmp v])) * (item ((_tmp2) + (1)) of [normal_world v])) + (((item (6) of [tmp v]) - (item (3) of [tmp v])) * (item ((_tmp2) + (2)) of [normal_world v]))))\n    if <<([abs v] of (_dot) ) < ((_r) * (0.9))> and <(*prim) = (_*player_container_prim)>> then\n    end\n    set [_orientation v] to (<(_dot) > [0]> - <(_dot) < [0]>)\n    set [_ptr_to_node v] to (_current)\n    if <not <(_orientation) = [0]>> then\n        set [_current v] to (item (((_current) + ((@enum t:EDGE_A) + (1))) + ((2) * <(_orientation) = [1]>)) of [bsp.tree v])\n        set [_*prim v] to (item (item (_current) of [bsp.tree v]) of [bsp._*prims v])\n    end\nend\nset [_orientation v] to ((_orientation) + <(_orientation) = [0]>)\nif <<(_current) = []> or <(item (_current) of [bsp.tree v]) = [TOMBSTONE]>> then\n    _**prim = bsp._*prims.insert_after ( (*prim) (@bsp._*prims.tail) (old_**prim) (orientation) )\n    _tmp = bsp.tree.add_node ( (_**prim) (_**prim) (_ptr_to_node) [null] [] [] )\n    set [_current v] to (_tmp)\n    _tmp = bsp.tree.set_edge ( (_ptr_to_node) [1] (_current) (<(_orientation) = [1]> + (1))\n    replace item ((*prim) + (@enum p:*NODE)) of [primitives v] with (_current)\nelse\n    if <(*prim) = (item ((@*player_obj) + (@enum o:*CONTAINER_PRIM)) of [gameobjects v])> then\n        _tmp = bsp.tree.try_to_insert_in_container ( *prim (*prim) old_**prim (old_**prim) orientation (orientation) level (level) )\n    else\n        set [_tmp v] to [0]\n    end\n    if <(_tmp) = [0]> then\n        if <(item (_current) of [bsp.tree v]) = [null]> then\n            _**prim = bsp._*prims.insert_after ( (*prim) (@bsp._*prims.tail) (old_**prim) (orientation) )\n            replace item ((_current) + (@enum t:TAIL)) of [bsp.tree v] with (_**prim)\n        else\n            _**prim = bsp._*prims.insert_after ( (*prim) (item (_current) of [bsp.tree v]) (old_**prim) (orientation) )\n        end\n        if <(item (_current) of [bsp.tree v]) = [null]> then\n            replace item (_current) of [bsp.tree v] with (_**prim)\n            replace item (2) of [bsp.tree v] with ((item (2) of [bsp.tree v]) + (1))\n            replace item ((_current) + (@enum t:TAIL)) of [bsp.tree v] with (_**prim)\n        else\n            if <(item (_current) of [bsp.tree v]) = (item ((_current) + (@enum t:TAIL)) of [bsp.tree v])> then\n                replace item ((_current) + (@enum t:TAIL)) of [bsp.tree v] with (_**prim)\n            end\n        end\n        replace item ((*prim) + (@enum p:*NODE)) of [primitives v] with (_current)\n    end\nend\nif <(level) > [1]> then\n    set [_current v] to (stack:_current)\nend\n\ndefine bsp._*prims.swap ( *a (*a) *b (*b) )\nset [_tmp2 v] to (item (*a) of [bsp._*prims v])\nreplace item (*a) of [bsp._*prims v] with (item (*b) of [bsp._*prims v])\nreplace item (*b) of [bsp._*prims v] with (_tmp2)\nset [_tmp2 v] to (item ((*a) + (3)) of [bsp._*prims v])\nreplace item ((*a) + (3)) of [bsp._*prims v] with (item ((*b) + (3)) of [bsp._*prims v])\nreplace item ((*b) + (3)) of [bsp._*prims v] with (_tmp2)\n\ndefine _**prim = GameObjects._*prims.insert_after( (*prim) (*elem) )\nif <(*elem) = []> then\n    add (*prim) to [gameobjects._*prims v]\n    set [_**prim v] to (length of [gameobjects._*prims v])\n    add [null] to [gameobjects._*prims v]\n    if <(@GameObjects._*prims.tail) = [0]> then\n        set [@gameobjects._*prims.tail v] to [1]\n    else\n        replace item ((@GameObjects._*prims.tail) + (1)) of [gameobjects._*prims v] with (_**prim)\n        set [@gameobjects._*prims.tail v] to (_**prim)\n    end\nelse\n    set [_tmp v] to (item ((*elem) + (1)) of [gameobjects._*prims v])\n    add (*prim) to [gameobjects._*prims v]\n    set [_**prim v] to (length of [gameobjects._*prims v])\n    add (_tmp) to [gameobjects._*prims v]\n    replace item ((*elem) + (1)) of [gameobjects._*prims v] with (_**prim)\nend\n\ndefine bsp.tree.reinsert_updated_objects\nset [_*update_obj v] to [1]\nrepeat (((length of [@dynamic_objects v]) * <(_frames_since_full_reinsert) = [5]>) + ((length of [@updated_objects v]) * <not <(_frames_since_full_reinsert) = [5]>>))\n    set [_*obj v] to (((item (_*update_obj) of [@dynamic_objects v]) * <(_frames_since_full_reinsert) = [5]>) + ((item (_*update_obj) of [@updated_objects v]) * <not <(_frames_since_full_reinsert) = [5]>>))\n    if <not <(item ((_*obj) + (@enum o:DYNAMIC_PARENT)) of [gameobjects v]) = [0]>> then\n        set [_tmp v] to (item ((_*obj) + (@enum o:*CONTAINER_PRIM)) of [gameobjects v])\n        _**prim = bsp.tree.remove_prim_from_node ( (item ((_tmp) + (@enum p:*NODE)) of [primitives v]) (_tmp) )\n        _tmp, _tmp2 = bsp._*prims.pop ( (_**prim)\n        set [_dynamic_parent v] to (item ((_*obj) + (@enum o:DYNAMIC_PARENT)) of [gameobjects v])\n        if <(_dynamic_parent) = [ROOT]> then\n            bsp.tree.insert_prim ( (_tmp) (_**prim) [3] (_tmp2) level [1] local_var_stack [] )\n        else\n            bsp.tree.insert_prim ( (_tmp) (_**prim) (item ((item ((_dynamic_parent) + (@enum o:*CONTAINER_PRIM)) of [gameobjects v]) + (@enum p:*SUBTREE_ROOT)) of [primitives v]) (_tmp2) level [1] local_var_stack [] )\n        end\n    end\n    change [_*update_obj v] by (1)\nend\n\nwhen I receive [bsp.sanity_check v]\nbsp._*prims.sanity_check ( [1] ((length of [bsp._*prims v]) - (3)) )\n\ndefine bsp._*prims.sanity_check ( (*left) (*right) )\nset [debug:i v] to (*left)\nset [debug:_tmp v] to [true]\nrepeat ((((*right) - (*left)) / (4)) + (1))\n    if <not <((item (DEBUG:i) of [bsp._*prims v]) mod (@enum p:SIZE)) = [1]>> then\n        ​​breakpoint​​\n    end\n    set [debug:_**prim v] to (item ((DEBUG:i) + (1)) of [bsp._*prims v])\n    if <not <(DEBUG:_**prim) = [null]>> then\n        set [debug:_tmp v] to <(item ((DEBUG:_**prim) + (2)) of [bsp._*prims v]) = (DEBUG:i)>\n        if <(DEBUG:_tmp) = [false]> then\n            ​​breakpoint​​\n        end\n    end\n    set [debug:_**prim v] to (item ((DEBUG:i) + (2)) of [bsp._*prims v])\n    if <not <(DEBUG:_**prim) = [null]>> then\n        set [debug:_tmp v] to <(item ((DEBUG:_**prim) + (1)) of [bsp._*prims v]) = (DEBUG:i)>\n        if <(DEBUG:_tmp) = [false]> then\n            ​​breakpoint​​\n        end\n    end\n    change [debug:i v] by (4)\nend\n\ndefine _tmp = bsp.tree.try_to_insert_in_container ( *prim (*prim) old_**prim (old_**prim) orientation (orientation) level (level) )\nset [_**prim v] to (item (_current) of [bsp.tree v])\nset [_*pivot_prims_tail v] to (item ((_current) + (2)) of [bsp.tree v])\nset [_tmp v] to (item ((*prim) + (1)) of [primitives v])\nset [_x v] to (item (_tmp) of [vertex_world v])\nset [_y v] to (item ((_tmp) + (1)) of [vertex_world v])\nset [_z v] to (item ((_tmp) + (2)) of [vertex_world v])\nset [_min v] to ((1) / (0))\nset [_tmp2 v] to [null]\nif <<not <(_**prim) = [TOMBSTONE]>> or <(item (_**prim) of [bsp._*prims v]) = [TOMBSTONE]>> then\n    repeat until <<(item ((_**prim) + (1)) of [bsp._*prims v]) = (_*pivot_prims_tail)> or <(_**prim) = [null]>>\n        set [_*prim v] to (item (_**prim) of [bsp._*prims v])\n        if <(item (_*prim) of [primitives v]) = [CONTAINER]> then\n            set [_tmp v] to (item ((_*prim) + (1)) of [primitives v])\n            set [_x2 v] to (item (_tmp) of [vertex_world v])\n            set [_y2 v] to (item ((_tmp) + (1)) of [vertex_world v])\n            set [_z2 v] to (item ((_tmp) + (2)) of [vertex_world v])\n            set [_dist v] to ([sqrt v] of ((((_x2) - (_x)) * ((_x2) - (_x))) + ((((_y2) - (_y)) * ((_y2) - (_y))) + (((_z2) - (_z)) * ((_z2) - (_z))))) )\n            if <(_dist) < (_min)> then\n                set [_min v] to (_dist)\n                set [_tmp2 v] to (_*prim)\n            end\n        end\n        set [_**prim v] to (item ((_**prim) + (2)) of [bsp._*prims v])\n    end\nend\nif <not <(_tmp2) = [null]>> then\n    bsp.tree.insert_prim ( (*prim) (old_**prim) (item ((_tmp2) + (@enum p:*SUBTREE_ROOT)) of [primitives v]) (orientation) level ((level) + (1)) local_var_stack (_current) )\n    set [_tmp v] to [1]\nelse\n    set [_tmp v] to [0]\nend\n\nif <(_frames_since_full_reinsert) = [5]> then\n    set [_frames_since_full_reinsert v] to [0]\nelse\n    change [_frames_since_full_reinsert v] by (1)\nend\n\ndefine _ptr_to_node = idxs_poly.insert_after ( (*node) (val) )\nset [_tmp v] to (item ((*node) + (1)) of [idxs_poly v])\nreplace item ((*node) + (1)) of [idxs_poly v] with ((length of [idxs_poly v]) + (1))\nadd (val) to [idxs_poly v]\nset [_ptr_to_node v] to (length of [idxs_poly v])\nadd (_tmp) to [idxs_poly v]\n\ndefine _*prim = primitives.add_prim ( (type) (first) (second) (third) (fourth) (*obj) (material) (*normal) )\nadd (type) to [primitives v]\nset [_*prim v] to (length of [primitives v])\nadd (first) to [primitives v]\nadd (second) to [primitives v]\nadd (third) to [primitives v]\nadd (fourth) to [primitives v]\nadd [*node] to [primitives v]\nadd (*obj) to [primitives v]\nadd (item # of (material) in [materials v]) to [primitives v]\nadd [illumination] to [primitives v]\nadd (*normal) to [primitives v]\nadd [*bsphere] to [primitives v]\nadd [zclip?] to [primitives v]\nadd [show_backside?] to [primitives v]\nif <not <(type) = [CONTAINER]>> then\n    _**prim = GameObjects._*prims.insert_after( (_*prim) (item ((*obj) + (@enum o:**PLEFT)) of [gameobjects v]) )\nend\n\nset [_z v] to (item ((_*prim) + (@enum p:*BSPHERE)) of [primitives v])\nset [_z v] to (((((@camX) - (item (_z) of [bsphere_world v])) * ((@camX) - (item (_z) of [bsphere_world v]))) + (((@camY) - (item ((_z) + (1)) of [bsphere_world v])) * ((@camY) - (item ((_z) + (1)) of [bsphere_world v])))) + (((@camZ) - (item ((_z) + (2)) of [bsphere_world v])) * ((@camZ) - (item ((_z) + (2)) of [bsphere_world v]))))\nset [_z2 v] to (((((@camX) - (item (4) of [tmp v])) * ((@camX) - (item (4) of [tmp v]))) + (((@camY) - (item (5) of [tmp v])) * ((@camY) - (item (5) of [tmp v])))) + (((@camZ) - (item (6) of [tmp v])) * ((@camZ) - (item (6) of [tmp v]))))\nset [_dot v] to (((_z) - (_z2)) * ((((@camX) - (item (1) of [tmp v])) * (item (_tmp2) of [normal_world v])) + ((((@camY) - (item (2) of [tmp v])) * (item ((_tmp2) + (1)) of [normal_world v])) + (((@camZ) - (item (3) of [tmp v])) * (item ((_tmp2) + (2)) of [normal_world v])))))\n\ndefine vertex_buff = inverse_world_tranform()\nrepeat until <(length of [vertex_buff v]) = (length of [vertex_world v])>\n    add [] to [vertex_buff v]\nend\nset [_*obj v] to [1]\nrepeat (length of [gameobjects v])\n    set [_x2 v] to (item ((_*obj) + (1)) of [gameobjects v])\n    set [_y2 v] to (item ((_*obj) + (2)) of [gameobjects v])\n    set [_z2 v] to (item ((_*obj) + (3)) of [gameobjects v])\n    set [_α v] to (item ((_*obj) + (4)) of [gameobjects v])\n    set [_β v] to (item ((_*obj) + (5)) of [gameobjects v])\n    set [_γ v] to (item ((_*obj) + (6)) of [gameobjects v])\n    set [_sx v] to (item ((_*obj) + (7)) of [gameobjects v])\n    set [_sy v] to (item ((_*obj) + (8)) of [gameobjects v])\n    set [_sz v] to (item ((_*obj) + (9)) of [gameobjects v])\n    set [j v] to (item ((_*obj) + (@enum o:*VLEFT)) of [gameobjects v])\n    set [_tmp v] to (item ((_*obj) + ((@enum o:*VLEFT) + (1))) of [gameobjects v])\n    set_inv_rot_matrix_αβγ( ([cos v] of (_α) ) ([sin v] of (_α) ) ([cos v] of (_β) ) ([sin v] of (_β) ) ([cos v] of (_γ) ) ([sin v] of (_γ) ) )\n    repeat until <<(j) = (_tmp)> or <(j) = [null]>>\n        _x, _y, z = apply_rot_matrix ( ((item (j) of [vertex_world v]) - (_x2)) ((item ((j) + (1)) of [vertex_world v]) - (_y2)) ((item ((j) + (2)) of [vertex_world v]) - (_z2)) )\n        replace item (j) of [vertex_buff v] with ((_x) / (_sx))\n        replace item ((j) + (1)) of [vertex_buff v] with ((_y) / (_sy))\n        replace item ((j) + (2)) of [vertex_buff v] with ((_z) / (_sz))\n        replace item ((j) + (3)) of [vertex_buff v] with (item ((j) + (3)) of [vertex_world v])\n        set [j v] to (item ((j) + (3)) of [vertex_world v])\n    end\n    change [_*obj v] by (@enum o:SIZE)\nend\n\ndefine _dot = dot_prod (ax) (ay) (az) (bx) (by) (bz)\nset [_dot v] to (((ax) * (bx)) + (((ay) * (by)) + ((az) * (bz))))\n\n@Render\n\ndefine Render Triangle (x1) (y1) (x2) (y2) (x3) (y3)\n\ndefine Azex 2 (ina) (inb) (inc) (ind) (ine) (inf) (inr) (a) (b) (c) (d) (e) (f)\nif <<(_A) < (_B)> and <(_A) < (_C)>> then\n    set [_a v] to ((0.5) - ((inr) / ((4) * ([sqrt v] of (((ina) * (ina)) + ((inb) * (inb))) ))))\nelse\n    if <(_B) < (_C)> then\n        set [_a v] to ((0.5) - ((inr) / ((4) * ([sqrt v] of (((inc) * (inc)) + ((ind) * (ind))) ))))\n    else\n        set [_a v] to ((0.5) - ((inr) / ((4) * ([sqrt v] of (((ine) * (ine)) + ((inf) * (inf))) ))))\n    end\nend\nset pen size to (inr)\npen down\nset [_b v] to (_A)\nrepeat ((-1) - (([ln v] of (inr) ) / ([ln v] of (_A) )))\n    set pen size to (((_A) * (inr)) + (2))\n    go to x: ((a) + ((_A) * (ina))) y: ((b) + ((_A) * (inb)))\n    go to x: ((c) + ((_A) * (inc))) y: ((d) + ((_A) * (ind)))\n    go to x: ((e) + ((_A) * (ine))) y: ((f) + ((_A) * (inf)))\n    go to x: ((a) + ((_A) * (ina))) y: ((b) + ((_A) * (inb)))\n    set [_a v] to ((_A) * (_B))\nend\nset pen size to (2.5)\ngo to x: (a) y: (b)\ngo to x: (c) y: (d)\ngo to x: (e) y: (f)\ngo to x: (a) y: (b)\npen up\n\ndefine STTF2 (inner) (p1.x') (p1.y') (p2.x') (p2.y') (θ_base) (size)\nset [△f v] to ((-17.63348937376391) / ([ln v] of ((((p2.x') * (p2.x')) + ((p2.y') * (p2.y'))) / (((p1.x') * (p1.x')) + ((p1.y') * (p1.y')))) ))\nset [△tmp v] to ((1) - ([e ^ v] of ((-28.65260025725912) / (△f)) ))\nset [△w v] to ((((((((180) * <not <(p2.y') < [0]>>) - ([atan v] of ((p2.x') / (p2.y')) )) + (θ_base)) + (180)) mod (360)) - (180)) / (([e ^ v] of (([ln v] of ((1) - ([e ^ v] of ((-37.46934494414107) / (△f)) )) ) * (2)) ) - ((△tmp) * (△tmp))))\npoint in direction (((θ_base) + ((△w) * ((△tmp) * (△tmp)))) + (90))\nset [fisheye v] effect to ((△f) - (100))\nset [whirl v] effect to (△w)\nswitch costume to (<((size) / ((1) - (△tmp))) < [100]> + (1))\nset size to ((size) / ((1) - (△tmp))) %\n\ndefine STTF2 (x1) (y1) (x2) (y2) (x3) (y3) (tex)\nset [△a v] to ((((x1) - (x3)) * ((x1) - (x3))) + (((y1) - (y3)) * ((y1) - (y3))))\nset [△b v] to ((((x3) - (x2)) * ((x3) - (x2))) + (((y3) - (y2)) * ((y3) - (y2))))\nset [△c v] to ((((x2) - (x1)) * ((x2) - (x1))) + (((y2) - (y1)) * ((y2) - (y1))))\nswitch costume to (small v)\nset size to ((1) / (0)) %\nif <<(△a) > (△b)> and <(△a) > (△c)>> then\n    go to x: ((((x1) + (x3)) / (2)) + ((10.392304845413262) * ((y3) - (y1)))) y: ((((y3) + (y1)) / (2)) - ((10.392304845413262) * ((x3) - (x1))))\n    STTF2 (inner) ((x1) - (x position)) ((y1) - (y position)) ((x2) - (x position)) ((y2) - (y position)) (((180) * <not <(x3) < (x1)>>) - ([atan v] of (((y3) - (y1)) / ((x3) - (x1))) )) (([sqrt v] of (△a) ) / (0.24605149764209298))\n    switch costume to (tex)\nelse\n    if <(△b) > (△c)> then\n        go to x: ((((x3) + (x2)) / (2)) + ((10.392304845413262) * ((y2) - (y3)))) y: ((((y3) + (y2)) / (2)) - ((10.392304845413262) * ((x2) - (x3))))\n        STTF2 (inner) ((x3) - (x position)) ((y3) - (y position)) ((x1) - (x position)) ((y1) - (y position)) (((180) * <not <(x2) < (x3)>>) - ([atan v] of (((y2) - (y3)) / ((x2) - (x3))) )) (([sqrt v] of (△b) ) / (0.24605149764209298))\n        switch costume to ((tex) + (1))\n    else\n        go to x: ((((x2) + (x1)) / (2)) + ((10.392304845413262) * ((y1) - (y2)))) y: ((((y2) + (y1)) / (2)) - ((10.392304845413262) * ((x1) - (x2))))\n        STTF2 (inner) ((x2) - (x position)) ((y2) - (y position)) ((x3) - (x position)) ((y3) - (y position)) (((180) * <not <(x1) < (x2)>>) - ([atan v] of (((y1) - (y2)) / ((x1) - (x2))) )) (([sqrt v] of (△c) ) / (0.24605149764209298))\n        switch costume to ((tex) + (2))\n    end\nend\nstamp\n\ndefine bsp._*prims.insertion_sort_by_point_prim_z( *left = **prim, *right = *pivot_prims_tail)\nset [_tmp v] to [0]\nset [j v] to (_**prim)\nrepeat until <<(j) = (_*pivot_prims_tail)> or <(j) = [null]>>\n    set [i v] to (j)\n    set [j v] to (item ((j) + (2)) of [bsp._*prims v])\n    repeat until <<not <(item ((item ((item (i) of [bsp._*prims v]) + (1)) of [primitives v]) + (2)) of [vertex v]) > (item ((item ((item (j) of [bsp._*prims v]) + (1)) of [primitives v]) + (2)) of [vertex v])>> or <(i) = (item ((_**prim) + (1)) of [bsp._*prims v])>>\n        set [i v] to (item ((i) + (1)) of [bsp._*prims v])\n    end\n    if <not <(i) = (item ((j) + (1)) of [bsp._*prims v])>> then\n        set [_tmp v] to (item ((j) + (1)) of [bsp._*prims v])\n        set [_tmp2 v] to (item ((_**prim) + (1)) of [bsp._*prims v])\n        if <(j) = (_*pivot_prims_tail)> then\n            set [_*pivot_prims_tail v] to (item ((_*pivot_prims_tail) + (1)) of [bsp._*prims v])\n        end\n        if <(j) = (@bsp._*prims.tail)> then\n            set [@bsp._*prims.tail v] to (item ((@bsp._*prims.tail) + (1)) of [bsp._*prims v])\n        end\n        replace item ((_tmp) + (2)) of [bsp._*prims v] with (item ((j) + (2)) of [bsp._*prims v])\n        if <not <(item ((j) + (2)) of [bsp._*prims v]) = [null]>> then\n            replace item ((item ((j) + (2)) of [bsp._*prims v]) + (1)) of [bsp._*prims v] with (_tmp)\n        end\n        replace item ((j) + (1)) of [bsp._*prims v] with (i)\n        if <not <(i) = [null]>> then\n            replace item ((item ((i) + (2)) of [bsp._*prims v]) + (1)) of [bsp._*prims v] with (j)\n            replace item ((j) + (2)) of [bsp._*prims v] with (item ((i) + (2)) of [bsp._*prims v])\n            replace item ((i) + (2)) of [bsp._*prims v] with (j)\n        else\n            replace item ((_**prim) + (1)) of [bsp._*prims v] with (j)\n            replace item ((j) + (2)) of [bsp._*prims v] with (_**prim)\n        end\n        if <(i) = (_tmp2)> then\n            set [_**prim v] to (j)\n        end\n        set [j v] to (_tmp)\n    end\nend\n\ndefine draw line from x (x1) y (y1) to x (x2) y (y2) start width (start size) end width (end size)\nif <([abs v] of ((start size) - (end size)) ) < [0.1]> then\n    go to x: (x1) y: (y1)\n    set pen size to (1)\n    pen down\n    set pen size to (start size)\n    go to x: (x2) y: (y2)\n    pen up\nelse\n    set [_tmp v] to (([sqrt v] of ((((x2) - (x1)) * ((x2) - (x1))) + (((y2) - (y1)) * ((y2) - (y1)))) ) * (2))\n    if <(end size) > (start size)> then\n        int draw line (x1) (y1) (x2) (y2) (start size) (end size) (((y2) - (y1)) / (_tmp)) (((x1) - (x2)) / (_tmp)) ((end size) - (start size)) ((x2) - (x1)) ((y2) - (y1))\n    else\n        int draw line (x2) (y2) (x1) (y1) (end size) (start size) (((y1) - (y2)) / (_tmp)) (((x2) - (x1)) / (_tmp)) ((start size) - (end size)) ((x1) - (x2)) ((y1) - (y2))\n    end\nend\n\ndefine int draw line (x1) (y1) (x2) (y2) (start size) (end size) (x normal) (y normal) (size diff) (x diff) (y diff)\nset [_x v] to (x1)\nset [_y v] to (y1)\nif <(start size) > [1]> then\n    set [_α v] to (start size)\nelse\n    set [_α v] to [1]\nend\nif <(_α) < (end size)> then\n    repeat until <((_α) * (2)) > (end size)>\n        set [_t1 v] to ((((2) * (_α)) - (start size)) / (size diff))\n        set [_x2 v] to ((x1) + ((x diff) * (_t1)))\n        set [_y2 v] to ((y1) + ((y diff) * (_t1)))\n        set pen size to (1)\n        go to x: ((_x2) - ((_α) * (x normal))) y: ((_y2) - ((_α) * (y normal)))\n        pen down\n        set pen size to (_α)\n        go to x: (_x) y: (_y)\n        go to x: ((_x2) + ((_α) * (x normal))) y: ((_y2) + ((_α) * (y normal)))\n        pen up\n        set [_x v] to (_x2)\n        set [_y v] to (_y2)\n        set [_α v] to ((_α) * (2))\n    end\n    go to x: ((x2) - (((end size) - (_α)) * (x normal))) y: ((y2) - (((end size) - (_α)) * (y normal)))\n    set pen size to (1)\n    pen down\n    set pen size to (_α)\n    go to x: (_x) y: (_y)\n    go to x: ((x2) + (((end size) - (_α)) * (x normal))) y: ((y2) + (((end size) - (_α)) * (y normal)))\n    pen up\n    go to x: (x2) y: (y2)\n    set pen size to (end size)\n    pen down\n    pen up\nend\n\nwhen flag clicked\ndelete all of [_δt_buffer v]\nswitch costume to (paint-brush v)\nhide\nset [_shadows_turned_off v] to [0]\nset [_elapsed_time v] to [0]\nforever\n    tick ()\nend\n\nwhen I receive [world_transform v]\nrender.world_tranform()\n\ndefine render.view_tranform_and_screen_projection ()\nset rot_matrix_γβα ( ([cos v] of (@C_roll) ) ([sin v] of (@C_roll) ) ([cos v] of (@C_pitch) ) ([sin v] of (@C_pitch) ) ([cos v] of (@C_yaw) ) ([sin v] of (@C_yaw) ) )\nset [i v] to [1]\nrepeat ((length of [vertex_world v]) / (@enum v:SIZE))\n    set [_x v] to ((item (i) of [vertex_world v]) - (@camX))\n    set [_y v] to ((item ((i) + (1)) of [vertex_world v]) - (@camY))\n    set [_z v] to ((item ((i) + (2)) of [vertex_world v]) - (@camZ))\n    replace item (i) of [vertex v] with ((((_x) * (_rm1)) + ((_y) * (_rm2))) + ((_z) * (_rm3)))\n    replace item ((i) + (1)) of [vertex v] with (((_x) * (_rm4)) + (((_y) * (_rm5)) + ((_z) * (_rm6))))\n    replace item ((i) + (2)) of [vertex v] with (((_x) * (_rm7)) + (((_y) * (_rm8)) + ((_z) * (_rm9))))\n    change [i v] by (@enum v:SIZE)\nend\nend timing [view transform]\nif <(@shadows?) = [1]> then\n    start timing [view transform \(shadows\)]\n    _x, _y, z = apply_rot_matrix ( [0] [1] [0] )\n    set [_nx v] to (_x)\n    set [_ny v] to (_y)\n    set [_nz v] to (_z)\n    _x, _y, z = apply_rot_matrix ( (@lightX) (@lightY) (@lightZ) )\n    set [_lightx_rot v] to (_x)\n    set [_lighty_rot v] to (_y)\n    set [_lightz_rot v] to (_z)\n    _x, _y, z = apply_rot_matrix ( ((-1) * (@camX)) ((@ground_y) - (@camY)) ((-1) * (@camZ)) )\n    set [_tmp2 v] to ((-1) * (((_lightX_rot) * (_Nx)) + (((_lightY_rot) * (_Ny)) + ((_lightZ_rot) * (_Nz)))))\n    set [i v] to [1]\n    repeat ((length of [vertex_world v]) / (@enum v:SIZE))\n        set [_tmp v] to (((((item (i) of [vertex v]) - (_x)) * (_Nx)) + ((((item ((i) + (1)) of [vertex v]) - (_y)) * (_Ny)) + (((item ((i) + (2)) of [vertex v]) - (_z)) * (_Nz)))) / (_tmp2))\n        replace item ((i) + (@*shadow_seg)) of [vertex v] with ((item (i) of [vertex v]) + ((_tmp) * (_lightX_rot)))\n        replace item (((i) + (@*shadow_seg)) + (1)) of [vertex v] with ((item ((i) + (1)) of [vertex v]) + ((_tmp) * (_lightY_rot)))\n        replace item (((i) + (@*shadow_seg)) + (2)) of [vertex v] with ((item ((i) + (2)) of [vertex v]) + ((_tmp) * (_lightZ_rot)))\n        change [i v] by (@enum v:SIZE)\n    end\n    end timing [view transform \(shadows\)]\nend\n_x, _y, z = apply_rot_matrix ( [0] [-1] [0] )\nset [_shad_off_x v] to (_x)\nset [_shad_off_y v] to (_y)\nset [_shad_off_z v] to (_z)\n\ndefine bsp.traversal ( (*root) (bsp._stack.len) local_var_stack: (stack:current) (stack:_**prim) (stack:_*pivot_prims_tail) (stack:_dot) (stack:_tmp2) )\nif <(length of [bsp.tree v]) < (*root)> then\n    stop [this script v]\nend\nset [_current v] to (*root)\nrepeat until <<(_current) = []> and <(length of [bsp._stack v]) = (bsp._stack.len)>>\n    repeat until <(_current) = []>\n        insert (_current) at (1) of [bsp._stack v] \n        set [_tmp v] to (item (item (_current) of [bsp.tree v]) of [bsp._*prims v])\n        set [_tmp2 v] to (item ((_tmp) + (@enum p:NORMAL)) of [primitives v])\n        if <(_tmp2) = [null]> then\n            set [_current v] to []\n        else\n            if <(item (_tmp) of [primitives v]) = [POLYGON]> then\n                set [_tmp v] to (item (item ((_tmp) + (1)) of [primitives v]) of [idxs_poly v])\n            else\n                set [_tmp v] to (item ((_tmp) + (1)) of [primitives v])\n            end\n            set [_dot v] to ((((@camX) - (item (_tmp) of [vertex_world v])) * (item (_tmp2) of [normal_world v])) + ((((@camY) - (item ((_tmp) + (1)) of [vertex_world v])) * (item ((_tmp2) + (1)) of [normal_world v])) + (((@camZ) - (item ((_tmp) + (2)) of [vertex_world v])) * (item ((_tmp2) + (2)) of [normal_world v]))))\n            replace item ((_current) + (@enum t:ORI)) of [bsp.tree v] with <(_dot) < [0]>\n            set [_current v] to (item (((_current) + ((@enum t:EDGE_A) + (1))) + ((2) * <(_dot) < [0]>)) of [bsp.tree v])\n        end\n    end\n    set [_current v] to (item (1) of [bsp._stack v])\n    delete (1) of [bsp._stack v]\n    if <not <(item ((_current) + (@enum t:ORI)) of [bsp.tree v]) = [1]>> then\n        set [_**prim v] to (item (_current) of [bsp.tree v])\n        if <(item ((_current) + (@enum t:MIDDLE)) of [bsp.tree v]) = [null]> then\n            set [_*pivot_prims_tail v] to (item ((_current) + (@enum t:TAIL)) of [bsp.tree v])\n        else\n            set [_*pivot_prims_tail v] to (item ((item ((_current) + (@enum t:MIDDLE)) of [bsp.tree v]) + (1)) of [bsp._*prims v])\n        end\n    else\n        set [_**prim v] to (item ((_current) + (@enum t:MIDDLE)) of [bsp.tree v])\n        set [_*pivot_prims_tail v] to (item ((_current) + (@enum t:TAIL)) of [bsp.tree v])\n    end\n    if <(item ((item (item (_current) of [bsp.tree v]) of [bsp._*prims v]) + (@enum p:NORMAL)) of [primitives v]) = [null]> then\n        bsp._*prims.insertion_sort_by_point_prim_z( *left = **prim, *right = *pivot_prims_tail)\n        if <not <(_tmp) = [0]>> then\n            if <not <(item ((_current) + (@enum t:ORI)) of [bsp.tree v]) = [1]>> then\n                replace item (_current) of [bsp.tree v] with (_**prim)\n                if <(item ((_current) + (@enum t:MIDDLE)) of [bsp.tree v]) = [null]> then\n                    replace item ((_current) + (@enum t:TAIL)) of [bsp.tree v] with (_*pivot_prims_tail)\n                end\n            else\n                replace item ((_current) + (@enum t:MIDDLE)) of [bsp.tree v] with (_**prim)\n                replace item ((_current) + (@enum t:TAIL)) of [bsp.tree v] with (_*pivot_prims_tail)\n            end\n        end\n    end\n    if <not <(_**prim) = [null]>> then\n        set [_tmp v] to (item ((item (_**prim) of [bsp._*prims v]) + (@enum p:NORMAL)) of [primitives v])\n        if <(_tmp) = [null]> then\n            set [_tmp2 v] to (((@ambient_max) / ((0.7) + ((0.3) * <(@ambient_max) > [0.7]>))) * ((_darkness_fac) * (100)))\n        else\n            set [_dot v] to (((item (_tmp) of [normal_world v]) * (@lightX)) + (((item ((_tmp) + (1)) of [normal_world v]) * (@lightY)) + ((item ((_tmp) + (2)) of [normal_world v]) * (@lightZ))))\n            set [_tmp2 v] to ((((@ambient_max) * (_darkness_fac)) + (<(_dot) < [0]> * (((_dot) * (-1)) * ((_darkness_fac) - ((@ambient_max) * (_darkness_fac)))))) * (100))\n        end\n        repeat until <<(item ((_**prim) + (1)) of [bsp._*prims v]) = (_*pivot_prims_tail)> or <(_**prim) = [null]>>\n            set [_*prim v] to (item (_**prim) of [bsp._*prims v])\n            if <(item (_*prim) of [primitives v]) = [CONTAINER]> then\n                bsp.traversal ( (item ((_*prim) + (@enum p:*SUBTREE_ROOT)) of [primitives v]) (length of [bsp._stack v]) local_var_stack: (_current) (_**prim) (_*pivot_prims_tail) (_dot) (_tmp2) )\n            else\n                if <(item ((item ((_*prim) + (@enum p:*OBJECT)) of [primitives v]) + (@enum o:HIDDEN?)) of [gameobjects v]) = [0]> then\n                    add (_*prim) to [depth order v]\n                    replace item ((_*prim) + (@enum p:ILLUMINATION)) of [primitives v] with (_tmp2)\n                    replace item ((_*prim) + (@enum p:SHOW_FRONT?)) of [primitives v] with <(item ((_**prim) + (3)) of [bsp._*prims v]) = [FRONT]>\n                end\n            end\n            set [_**prim v] to (item ((_**prim) + (2)) of [bsp._*prims v])\n        end\n    end\n    set [_current v] to (item (((_current) + ((@enum t:EDGE_A) + (1))) + (<(item ((_current) + (@enum t:ORI)) of [bsp.tree v]) = [0]> * (2))) of [bsp.tree v])\nend\nif <not <(stack:current) = []>> then\n    set [_current v] to (stack:current)\n    set [_**prim v] to (stack:_**prim)\n    set [_*pivot_prims_tail v] to (stack:_*pivot_prims_tail)\n    set [_dot v] to (stack:_dot)\n    set [_tmp2 v] to (stack:_tmp2)\nend\nif <(*root) = [3]> then\n    end timing [bsp traversal]\n    if <(@shadows?) = [1]> then\n        start timing [insert shadows]\n        render.depth_buffer.insert_shadows ()\n        end timing [insert shadows]\n    end\nend\n\ndefine render.primitive_shader()\ndelete all of [depth order v]\n_x, _y, z = apply_rot_matrix ( (@lightX) (@lightY) (@lightZ) )\nset [_lightx_view v] to (_x)\nset [_lighty_view v] to (_y)\nset [_lightz_view v] to (_z)\nset_inv_rot_matrix_γβα ( ([cos v] of (@C_roll) ) ([sin v] of (@C_roll) ) ([cos v] of (@C_pitch) ) ([sin v] of (@C_pitch) ) ([cos v] of (@C_yaw) ) ([sin v] of (@C_yaw) ) )\n_x, _y, z = apply_rot_matrix ( [0] [0] [-1] )\nset [_camdirx v] to (_x)\nset [_camdiry v] to (_y)\nset [_camdirz v] to (_z)\nbroadcast (bsp.reinsert_prims v)\n\ndefine start timing (timing label)\nif <[timings v] contains (timing label)?> then\n    set [_tmp v] to (item # of (timing label) in [timings v])\n    replace item ((_tmp) + (1)) of [timings v] with (days since 2000)\n    replace item ((_tmp) + (2)) of [timings v] with ((item ((_tmp) + (2)) of [timings v]) + (1))\nelse\n    add (timing label) to [timings v]\n    add (days since 2000) to [timings v]\n    add [0] to [timings v]\n    add [0] to [timings v]\nend\nif <(timer) = [5]> then\n    delete all of [timings v]\nend\n\ndefine end timing (timing label)\nset [_tmp v] to (days since 2000)\nset [_tmp2 v] to (item # of (timing label) in [timings v])\nreplace item ((_tmp2) + (3)) of [timings v] with ((((86400) * ((_tmp) - (item ((_tmp2) + (1)) of [timings v]))) - ((3.71) / (1000000))) + (item ((_tmp2) + (3)) of [timings v]))\n\ndefine render.rasterisation ()\nset [_mouse_touching_textured_tri v] to [0]\nset [_shadow v] to (item # of [Shadow] in [materials v])\nrender.rasterisation.skybox ()\nswitch costume to (small v)\nset size to ((1) / (0)) %\nset [i v] to [1]\nrepeat (length of [depth order v])\n    set [_*prim v] to (item (i) of [depth order v])\n    set [_mat v] to (item ((_*prim) + (@enum p:MATERIAL)) of [primitives v])\n    if (item ((_*prim) + (@enum p:SHOW_FRONT?)) of [primitives v]) then\n        set pen color to (item ((_mat) + (4)) of [materials v])\n        set pen (brightness v) to ((item ((_*prim) + (@enum p:ILLUMINATION)) of [primitives v]) * (item ((_mat) + (5)) of [materials v]))\n    else\n        set pen color to (item ((item ((_mat) + (1)) of [materials v]) + (4)) of [materials v])\n        set pen (brightness v) to ((item ((_*prim) + (@enum p:ILLUMINATION)) of [primitives v]) * (item ((item ((_mat) + (1)) of [materials v]) + (5)) of [materials v]))\n    end\n    set [_α v] to (item ((_*prim) + (1)) of [primitives v])\n    if <(item (_*prim) of [primitives v]) = [TRIANGLE]> then\n        set [_β v] to (item ((_*prim) + (2)) of [primitives v])\n        set [_γ v] to (item ((_*prim) + (3)) of [primitives v])\n        z-clip triangle and fill (item (_α) of [vertex v]) (item ((_α) + (1)) of [vertex v]) (item ((_α) + (2)) of [vertex v]) . (item (_β) of [vertex v]) (item ((_β) + (1)) of [vertex v]) (item ((_β) + (2)) of [vertex v]) . (item (_γ) of [vertex v]) (item ((_γ) + (1)) of [vertex v]) (item ((_γ) + (2)) of [vertex v]) z clip distance (@z_clip_dist) texture (item ((_mat) + (3)) of [materials v])\n    else\n        if <(item (_*prim) of [primitives v]) = [QUAD]> then\n            set [_β v] to (item ((_*prim) + (2)) of [primitives v])\n            set [_γ v] to (item ((_*prim) + (3)) of [primitives v])\n            set [_δ v] to (item ((_*prim) + (4)) of [primitives v])\n            set [_tmp v] to (item ((_mat) + (3)) of [materials v])\n            z-clip triangle and fill (item (_β) of [vertex v]) (item ((_β) + (1)) of [vertex v]) (item ((_β) + (2)) of [vertex v]) . (item (_γ) of [vertex v]) (item ((_γ) + (1)) of [vertex v]) (item ((_γ) + (2)) of [vertex v]) . (item (_α) of [vertex v]) (item ((_α) + (1)) of [vertex v]) (item ((_α) + (2)) of [vertex v]) z clip distance (@z_clip_dist) texture (_tmp)\n            z-clip triangle and fill (item (_δ) of [vertex v]) (item ((_δ) + (1)) of [vertex v]) (item ((_δ) + (2)) of [vertex v]) . (item (_α) of [vertex v]) (item ((_α) + (1)) of [vertex v]) (item ((_α) + (2)) of [vertex v]) . (item (_γ) of [vertex v]) (item ((_γ) + (1)) of [vertex v]) (item ((_γ) + (2)) of [vertex v]) z clip distance (@z_clip_dist) texture (<not <(_tmp) = []>> * ((_tmp) + (3)))\n        else\n            if <(item (_*prim) of [primitives v]) = [LINE]> then\n                set [_β v] to (item ((_*prim) + (2)) of [primitives v])\n                z clip line and fill ( (item (_α) of [vertex v]) (item ((_α) + (1)) of [vertex v]) (item ((_α) + (2)) of [vertex v]) . (item (_β) of [vertex v]) (item ((_β) + (1)) of [vertex v]) (item ((_β) + (2)) of [vertex v]) z clip distance (@z_clip_dist) diameter ((2) * (item ((_*prim) + (@enum p:RADIUS)) of [primitives v])) )\n            else\n                if <(item (_*prim) of [primitives v]) = [POINT]> then\n                    if <(item ((_α) + (2)) of [vertex v]) < (@z_clip_dist)> then\n                        if <(item ((_mat) + (3)) of [materials v]) = []> then\n                            set [_z v] to ((@zN*180) / (item ((_α) + (2)) of [vertex v]))\n                            go to x: ((item (_α) of [vertex v]) * (_z)) y: ((item ((_α) + (1)) of [vertex v]) * (_z))\n                            set pen size to (((2) * (item ((_*prim) + (@enum p:RADIUS)) of [primitives v])) * (_z))\n                            pen down\n                            pen up\n                        else\n                            set [_β v] to (item ((_*prim) + (@enum p:SPRITE_SCALE_Y)) of [primitives v])\n                            if <(_*prim) = (@*player_prim)> then\n                                if <<(@first_person?) = [0]> or <(@edit_mode?) = [1]>> then\n                                    set [_z v] to (item ((_α) + (2)) of [vertex v])\n                                    set [_γ v] to (item ((_*prim) + (@enum p:RADIUS)) of [primitives v])\n                                    set [_x2 v] to ((_lightX_view) * (-1))\n                                    set [_y2 v] to ((_lightY_view) * (-1))\n                                    set [_z2 v] to ((1) - (_lightZ_view))\n                                    _atan2 = atan2( (_y2) ((-1) * (_x2)) )\n                                    render_sprite (((item (_α) of [vertex v]) * (@zN*180)) / (_z)) (((item ((_α) + (1)) of [vertex v]) * (@zN*180)) / (_z)) ((2) * ((item ((_*prim) + (@enum p:RADIUS)) of [primitives v]) * ((@zN*180) / (_z)))) (item ((_mat) + (3)) of [materials v]) (item ((_*prim) + (@enum p:SPRITE_SCALE_Y)) of [primitives v]) (_atan2) (((item ((_*prim) + (@enum p:ILLUMINATION)) of [primitives v]) * (1.1)) - (100)) costume_width [100]\n                                    set [ghost v] effect to ((100) - ((((_tmp2) / (2)) * ((_tmp2) / (2))) * (100)))\n                                    set [_tmp2 v] to ([sqrt v] of (((_x2) * (_x2)) + (((_y2) * (_y2)) + ((_z2) * (_z2)))) )\n                                    set [_z v] to ((@zN*180) / ((_z) + ((_γ) * ((_z2) / (_tmp2)))))\n                                    set [_x v] to ((item (_α) of [vertex v]) + ((_γ) * ((_x2) / (_tmp2))))\n                                    set [_y v] to ((item ((_α) + (1)) of [vertex v]) + ((_γ) * ((_y2) / (_tmp2))))\n                                    render_sprite ((_x) * (_z)) ((_y) * (_z)) ((item ((_*prim) + (@enum p:RADIUS)) of [primitives v]) * (_z)) [specular] (item ((_*prim) + (@enum p:SPRITE_SCALE_Y)) of [primitives v]) [90] (((item ((_*prim) + (@enum p:ILLUMINATION)) of [primitives v]) - (100)) + (15)) costume_width [100]\n                                    set [ghost v] effect to (0)\n                                end\n                            else\n                                set [_z v] to ((@zN*180) / (item ((_α) + (2)) of [vertex v]))\n                                render_sprite ((item (_α) of [vertex v]) * (_z)) ((item ((_α) + (1)) of [vertex v]) * (_z)) ((2) * ((item ((_*prim) + (@enum p:RADIUS)) of [primitives v]) * (_z))) (item ((_mat) + (3)) of [materials v]) (item ((_*prim) + (@enum p:SPRITE_SCALE_Y)) of [primitives v]) [90] (((item ((_*prim) + (@enum p:ILLUMINATION)) of [primitives v]) * (1)) - (100)) costume_width ((100) - ((36) * <<(_tmp) = [shadow]> or <(_tmp) = [shadow2]>>))\n                            end\n                        end\n                    end\n                else\n                    set [j v] to (item ((_*prim) + (2)) of [primitives v])\n                    repeat (((item ((_*prim) + (3)) of [primitives v]) - (j)) / (3))\n                        set [_α v] to (item (j) of [idxs_tri v])\n                        set [_β v] to (item ((j) + (1)) of [idxs_tri v])\n                        set [_γ v] to (item ((j) + (2)) of [idxs_tri v])\n                        z-clip triangle and fill (item (_α) of [vertex v]) (item ((_α) + (1)) of [vertex v]) (item ((_α) + (2)) of [vertex v]) . (item (_β) of [vertex v]) (item ((_β) + (1)) of [vertex v]) (item ((_β) + (2)) of [vertex v]) . (item (_γ) of [vertex v]) (item ((_γ) + (1)) of [vertex v]) (item ((_γ) + (2)) of [vertex v]) z clip distance (@z_clip_dist) texture (item ((_mat) + (3)) of [materials v])\n                        change [j v] by (3)\n                    end\n                end\n            end\n        end\n    end\n    change [i v] by (1)\nend\nif <not <(@show_prims/dynamic/objs) = [0]>> then\n    render.visualise_primitives\nend\nif <(@show_BSP_tree?) = [1]> then\n    render.show_bsp_tree ()\nend\nset size to (100) %\nswitch costume to (paint-brush v)\n\ndefine tick ()\nif <(@rendering_active?) = [1]> then\n    set [_tri_counter v] to [0]\n    set [_darkness_fac v] to ((([sin v] of (((@time_of_day) / (24)) * (180)) ) + (0.2)) / (1.2))\n    set [_tmp v] to ((((@time_of_day) / (24)) * (360)) - (90))\n    if <([abs v] of ((@time_of_day) - (12)) ) < [6]> then\n        set [@lightx v] to (((-1) * ([cos v] of (_tmp) )) / ([sqrt v] of ((3) / (2)) ))\n        set [@lighty v] to (((-1) * ([sin v] of (_tmp) )) / ([sqrt v] of ((3) / (2)) ))\n        set [@lightz v] to ((-1) * ([sqrt v] of ((1) / (3)) ))\n    else\n        set [@lightx v] to (((-1) * ([cos v] of (_tmp) )) / ([sqrt v] of ((3) / (2)) ))\n        set [@lighty v] to (((1) * ([sin v] of (_tmp) )) / ([sqrt v] of ((3) / (2)) ))\n        set [@lightz v] to ((1) * ([sqrt v] of ((1) / (3)) ))\n    end\n    erase all\n    start timing [world transform]\n    render.world_tranform()\n    end timing [world transform]\n    start timing [view transform]\n    render.view_tranform_and_screen_projection ()\n    start timing [bsp reinsert]\n    render.primitive_shader()\nend\nbroadcast (wait for bsp.reinsert broadcast v)\n\ndefine _x, _y, _z = apply_rot_matrix + trans (x) (y) (z) (tx) (ty) (tz)\nset [_x v] to ((((x) * (_rm1)) + ((y) * (_rm2))) + (((z) * (_rm3)) + (tx)))\nset [_y v] to (((x) * (_rm4)) + (((y) * (_rm5)) + (((z) * (_rm6)) + (ty))))\nset [_z v] to (((x) * (_rm7)) + (((y) * (_rm8)) + (((z) * (_rm9)) + (tz))))\n\ndefine render_sprite (x) (y) (size) (*costume) (scaley) (rotation) (brightness) costume_width (costume_width)\nif <<<([abs v] of (x) ) > ((240) + ((size) / (2)))> or <([abs v] of (y) ) > ((180) + ((size) / (2)))>> or <<(scaley) < [0.03]> and <not <(scaley) = []>>>> then\n    stop [this script v]\nend\nset [brightness v] effect to (brightness)\npoint in direction (rotation)\nswitch costume to (small v)\nset size to ((1) / (0)) %\ngo to x: (x) y: ((y) + (((-0.5) * ((((scaley) / (2)) - (0.64)) * (size))) * <not <(scaley) = []>>))\nif <((size) * ((100) / (costume_width))) < [100]> then\n    switch costume to (big v)\nelse\n    switch costume to (small v)\nend\nset size to ((size) * ((100) / (costume_width))) %\nswitch costume to (*costume)\nif <not <<(scaley) = []> or <(scaley) = [1]>>> then\n    set [fisheye v] effect to ((100) * (([abs v] of ((-0.1249387366) / ([log v] of ((1) - ((scaley) / (4))) )) ) - (1)))\nend\nshow\nstamp\nhide\nswitch costume to (small v)\nset size to ((1) / (0)) %\npoint in direction (90)\nclear graphic effects\n\ndefine render_tri (x1) (y1) (x2) (y2) (x3) (y3) (tex)\nif <<<<<(x1) > [240]> and <(x2) > [240]>> and <(x3) > [240]>> or <<<(x1) < [-240]> and <(x2) < [-240]>> and <(x3) < [-240]>>> or <<<<(y1) > [180]> and <(y2) > [180]>> and <(y3) > [180]>> or <<<(y1) < [-180]> and <(y2) < [-180]>> and <(y3) < [-180]>>>> then\n    stop [this script v]\nend\nif <not <((tex) + (0)) = [0]>> then\n    set [brightness v] effect to ((((item ((_*prim) + (@enum p:ILLUMINATION)) of [primitives v]) * (item ((_mat) + (5)) of [materials v])) * (1.8)) - (80))\n    STTF2 (x1) (y1) (x2) (y2) (x3) (y3) (tex)\n    if <touching (mouse-pointer v)?> then\n        set [_mouse_touching_textured_tri v] to [1]\n    end\n    clear graphic effects\n    switch costume to (small v)\n    set size to ((1) / (0)) %\n    point in direction (90)\n    stop [this script v]\nend\nif <(@show_tris?) = [1]> then\n    change pen (color v) by ((2) * ((i) + (j)))\nend\nchange [_tri_counter v] by (1)\nset [_a v] to ([sqrt v] of ((((x2) - (x3)) * ((x2) - (x3))) + (((y2) - (y3)) * ((y2) - (y3)))) )\nset [_b v] to ([sqrt v] of ((((x3) - (x1)) * ((x3) - (x1))) + (((y3) - (y1)) * ((y3) - (y1)))) )\nset [_c v] to ([sqrt v] of ((((x2) - (x1)) * ((x2) - (x1))) + (((y2) - (y1)) * ((y2) - (y1)))) )\nset [_p v] to ((_A) + ((_B) + (_C)))\ngo to x: (((((_A) * (x1)) + ((_B) * (x2))) + ((_C) * (x3))) / (_P)) y: (((((_A) * (y1)) + ((_B) * (y2))) + ((_C) * (y3))) / (_P))\nAzex 2 ((x position) - (x1)) ((y position) - (y1)) ((x position) - (x2)) ((y position) - (y2)) ((x position) - (x3)) ((y position) - (y3)) ([sqrt v] of ((((((_C) + (_B)) - (_A)) * (((_A) + (_C)) - (_B))) * ((_P) - ((_C) * (2)))) / (_P)) ) (x1) (y1) (x2) (y2) (x3) (y3)\n\ndefine _x, _y, z = apply_rot_matrix ( (x) (y) (z) )\nset [_x v] to ((((x) * (_rm1)) + ((y) * (_rm2))) + ((z) * (_rm3)))\nset [_y v] to (((x) * (_rm4)) + (((y) * (_rm5)) + ((z) * (_rm6))))\nset [_z v] to (((x) * (_rm7)) + (((y) * (_rm8)) + ((z) * (_rm9))))\n\nwhen I receive [wait for bsp.reinsert broadcast v]\ntick.secondhalf()\n\ndefine set_inv_rot_matrix_γβα ( (cos γ) (sin γ) (cos β) (sin β) (cos α) (sin α) )\nset [_rm1 v] to (((cos α) * (cos γ)) - ((sin α) * ((sin β) * (sin γ))))\nset [_rm2 v] to ((((sin α) * (sin β)) * (cos γ)) + ((cos α) * (sin γ)))\nset [_rm3 v] to ((-1) * ((cos β) * (sin α)))\nset [_rm4 v] to ((-1) * ((cos β) * (sin γ)))\nset [_rm5 v] to ((cos β) * (cos γ))\nset [_rm6 v] to (sin β)\nset [_rm7 v] to (((cos γ) * (sin α)) + (((cos α) * (sin β)) * (sin γ)))\nset [_rm8 v] to (((sin α) * (sin γ)) - ((cos α) * ((cos γ) * (sin β))))\nset [_rm9 v] to ((cos α) * (cos β))\n\ndefine z-clip triangle and fill (ax) (ay) (az) . (bx) (by) (bz) . (cx) (cy) (cz) z clip distance (z) texture (tex)\nif <(((az) + ((bz) + (cz))) / (-3)) > (@z_far)> then\n    stop [this script v]\nend\nif <(<(az) < (z)> + (<(bz) < (z)> + <(cz) < (z)>)) > [1]> then\n    if <<(az) < (z)> = <(bz) < (z)>> then\n        if <(cz) < (z)> then\n            render_tri ((ax) * ((@zN*180) / (az))) ((ay) * ((@zN*180) / (az))) ((bx) * ((@zN*180) / (bz))) ((by) * ((@zN*180) / (bz))) ((cx) * ((@zN*180) / (cz))) ((cy) * ((@zN*180) / (cz))) (tex)\n        else\n            set [_t1 v] to (((z) - (bz)) / ((cz) - (bz)))\n            set [_t2 v] to (((z) - (az)) / ((cz) - (az)))\n            render_tri (((bx) + ((_t1) * ((cx) - (bx)))) * ((@zN*180) / (z))) (((by) + ((_t1) * ((cy) - (by)))) * ((@zN*180) / (z))) ((ax) * ((@zN*180) / (az))) ((ay) * ((@zN*180) / (az))) ((bx) * ((@zN*180) / (bz))) ((by) * ((@zN*180) / (bz))) (tex)\n            render_tri (((bx) + ((_t1) * ((cx) - (bx)))) * ((@zN*180) / (z))) (((by) + ((_t1) * ((cy) - (by)))) * ((@zN*180) / (z))) (((ax) + ((_t2) * ((cx) - (ax)))) * ((@zN*180) / (z))) (((ay) + ((_t2) * ((cy) - (ay)))) * ((@zN*180) / (z))) ((ax) * ((@zN*180) / (az))) ((ay) * ((@zN*180) / (az))) (tex)\n        end\n    else\n        set [_t1 v] to (((z) - (az)) / ((bz) - (az)))\n        if <(az) < (z)> then\n            set [_t2 v] to (((z) - (cz)) / ((bz) - (cz)))\n            render_tri (((ax) + ((_t1) * ((bx) - (ax)))) * ((@zN*180) / (z))) (((ay) + ((_t1) * ((by) - (ay)))) * ((@zN*180) / (z))) ((cx) * ((@zN*180) / (cz))) ((cy) * ((@zN*180) / (cz))) ((ax) * ((@zN*180) / (az))) ((ay) * ((@zN*180) / (az))) (tex)\n            render_tri (((ax) + ((_t1) * ((bx) - (ax)))) * ((@zN*180) / (z))) (((ay) + ((_t1) * ((by) - (ay)))) * ((@zN*180) / (z))) (((cx) + ((_t2) * ((bx) - (cx)))) * ((@zN*180) / (z))) (((cy) + ((_t2) * ((by) - (cy)))) * ((@zN*180) / (z))) ((cx) * ((@zN*180) / (cz))) ((cy) * ((@zN*180) / (cz))) (tex)\n        else\n            set [_t2 v] to (((z) - (cz)) / ((az) - (cz)))\n            render_tri (((cx) + ((_t2) * ((ax) - (cx)))) * ((@zN*180) / (z))) (((cy) + ((_t2) * ((ay) - (cy)))) * ((@zN*180) / (z))) ((bx) * ((@zN*180) / (bz))) ((by) * ((@zN*180) / (bz))) ((cx) * ((@zN*180) / (cz))) ((cy) * ((@zN*180) / (cz))) (tex)\n            render_tri (((cx) + ((_t2) * ((ax) - (cx)))) * ((@zN*180) / (z))) (((cy) + ((_t2) * ((ay) - (cy)))) * ((@zN*180) / (z))) (((ax) + ((_t1) * ((bx) - (ax)))) * ((@zN*180) / (z))) (((ay) + ((_t1) * ((by) - (ay)))) * ((@zN*180) / (z))) ((bx) * ((@zN*180) / (bz))) ((by) * ((@zN*180) / (bz))) (tex)\n        end\n    end\nelse\n    if <<(az) < (z)> = <(bz) < (z)>> then\n        if <(cz) < (z)> then\n            set [_t1 v] to (((z) - (bz)) / ((cz) - (bz)))\n            set [_t2 v] to (((z) - (az)) / ((cz) - (az)))\n            render_tri (((ax) + ((_t2) * ((cx) - (ax)))) * ((@zN*180) / (z))) (((ay) + ((_t2) * ((cy) - (ay)))) * ((@zN*180) / (z))) (((bx) + ((_t1) * ((cx) - (bx)))) * ((@zN*180) / (z))) (((by) + ((_t1) * ((cy) - (by)))) * ((@zN*180) / (z))) ((cx) * ((@zN*180) / (cz))) ((cy) * ((@zN*180) / (cz))) (tex)\n        end\n    else\n        set [_t1 v] to (((z) - (az)) / ((bz) - (az)))\n        if <(az) < (z)> then\n            set [_t2 v] to (((z) - (az)) / ((cz) - (az)))\n            render_tri (((ax) + ((_t1) * ((bx) - (ax)))) * ((@zN*180) / (z))) (((ay) + ((_t1) * ((by) - (ay)))) * ((@zN*180) / (z))) (((ax) + ((_t2) * ((cx) - (ax)))) * ((@zN*180) / (z))) (((ay) + ((_t2) * ((cy) - (ay)))) * ((@zN*180) / (z))) ((ax) * ((@zN*180) / (az))) ((ay) * ((@zN*180) / (az))) (tex)\n        else\n            set [_t2 v] to (((z) - (bz)) / ((cz) - (bz)))\n            render_tri (((bx) + ((_t2) * ((cx) - (bx)))) * ((@zN*180) / (z))) (((by) + ((_t2) * ((cy) - (by)))) * ((@zN*180) / (z))) (((ax) + ((_t1) * ((bx) - (ax)))) * ((@zN*180) / (z))) (((ay) + ((_t1) * ((by) - (ay)))) * ((@zN*180) / (z))) ((bx) * ((@zN*180) / (bz))) ((by) * ((@zN*180) / (bz))) (tex)\n        end\n    end\nend\n\ndefine set rot_matrix_γβα ( (cos γ) (sin γ) (cos β) (sin β) (cos α) (sin α) )\nset [_rm1 v] to (((cos α) * (cos γ)) - ((sin α) * ((sin β) * (sin γ))))\nset [_rm2 v] to ((-1) * ((cos β) * (sin γ)))\nset [_rm3 v] to ((((cos α) * (sin β)) * (sin γ)) + ((sin α) * (cos γ)))\nset [_rm4 v] to ((((sin α) * (sin β)) * (cos γ)) + ((cos α) * (sin γ)))\nset [_rm5 v] to ((cos β) * (cos γ))\nset [_rm6 v] to (((sin α) * (sin γ)) - ((cos α) * ((sin β) * (cos γ))))\nset [_rm7 v] to ((-1) * ((cos β) * (sin α)))\nset [_rm8 v] to (sin β)\nset [_rm9 v] to ((cos α) * (cos β))\n\ndefine render.rasterisation.skybox ()\nif <(@C_pitch) < [0]> then\n    switch backdrop to (sky v)\nelse\n    switch backdrop to (ground v)\nend\nrender_sprite (((((((@C_yaw) + (@W_yaw)) / (360)) + (0.5)) mod (1)) - (0.5)) * ((@skybox_width) * (-1))) (([tan v] of ((@C_pitch) + (@W_pitch)) ) * ((-1) * (@zN*180))) ((@skybox_width) - (0)) [skybox_day] [] [90] (((100) * (_darkness_fac)) - (100)) costume_width ((@skybox_width) / (2))\nset [ghost v] effect to ((100) * ([sin v] of (((@time_of_day) / (24)) * (180)) ))\nrender_sprite (((((((@C_yaw) + (@W_yaw)) / (360)) + (0.5)) mod (1)) - (0.5)) * ((@skybox_width) * (-1))) (([tan v] of ((@C_pitch) + (@W_pitch)) ) * ((-1) * (@zN*180))) ((@skybox_width) - (2)) [skybox_night] [] [90] [0] costume_width ((@skybox_width) / (2))\nset [ghost v] effect to (0)\nrender_sprite ((((((@C_yaw) + (@W_yaw)) / (360)) mod (1)) - (0.5)) * ((@skybox_width) * (-1))) (([tan v] of ((@C_pitch) + (@W_pitch)) ) * ((-1) * (@zN*180))) ((@skybox_width) - (1)) [skybox_day] [] [90] (((100) * (_darkness_fac)) - (100)) costume_width ((@skybox_width) / (2))\nset [ghost v] effect to ((100) * ([sin v] of (((@time_of_day) / (24)) * (180)) ))\nrender_sprite ((((((@C_yaw) + (@W_yaw)) / (360)) mod (1)) - (0.5)) * ((@skybox_width) * (-1))) (([tan v] of ((@C_pitch) + (@W_pitch)) ) * ((-1) * (@zN*180))) ((@skybox_width) - (4)) [skybox_night] [] [90] [0] costume_width ((@skybox_width) / (2))\nset [ghost v] effect to (0)\nif <(@ground_plane?) = [1]> then\n    render_sprite ((((((@C_yaw) + (@W_yaw)) / (360)) mod (1)) - (0.5)) * ((@skybox_width) * (-1))) (([tan v] of ((@C_pitch) + (@W_pitch)) ) * ((-1) * (@zN*180))) ((@skybox_width) - (0)) [ground] [] [90] ((-100) + ((100) * ([sin v] of (((@time_of_day) / (24)) * (180)) ))) costume_width ((@skybox_width) / (2))\n    render_sprite (((((((@C_yaw) + (@W_yaw)) / (360)) + (0.5)) mod (1)) - (0.5)) * ((@skybox_width) * (-1))) (([tan v] of ((@C_pitch) + (@W_pitch)) ) * ((-1) * (@zN*180))) ((@skybox_width) - (0)) [ground] [] [90] ((-100) + ((100) * ([sin v] of (((@time_of_day) / (24)) * (180)) ))) costume_width ((@skybox_width) / (2))\nend\nif <(_lightZ_view) > [0]> then\n    set [ghost v] effect to (0)\n    set [_tmp v] to (((_lightX_view) * (@zN*180)) / (_lightZ_view))\n    set [_tmp2 v] to (((_lightY_view) * (@zN*180)) / (_lightZ_view))\n    if <([abs v] of ((@time_of_day) - (12)) ) < [6]> then\n        set [_α v] to ((0.5) * ([sqrt v] of (((_tmp) * (_tmp)) + ((_tmp2) * (_tmp2))) ))\n        render_sprite (_tmp) (_tmp2) [150] [sun] [] [90] [0] costume_width [208]\n        set [ghost v] effect to (_α)\n        render_sprite ((0.4) * (_tmp)) ((0.4) * (_tmp2)) [18] [flare] [] [90] [0] costume_width [51]\n        set [ghost v] effect to (_α)\n        render_sprite ((-0.2) * (_tmp)) ((-0.2) * (_tmp2)) [15] [flare2] [] [90] [0] costume_width [102]\n        set [ghost v] effect to (_α)\n        render_sprite ((-0.8) * (_tmp)) ((-0.8) * (_tmp2)) [10] [flare] [] [90] [0] costume_width [51]\n        set [ghost v] effect to (_α)\n        render_sprite ((-1.4) * (_tmp)) ((-1.4) * (_tmp2)) [8] [flare2] [] [90] [0] costume_width [102]\n    else\n        render_sprite (_tmp) (_tmp2) [100] [moon] [] [90] [0] costume_width [281]\n    end\nend\nclear graphic effects\n\ndefine z clip line and fill ( (ax) (ay) (az) . (bx) (by) (bz) z clip distance (z) diameter (diameter) )\nif <<(az) < (z)> or <(bz) < (z)>> then\n    set [_t1 v] to (((z) - (az)) / ((bz) - (az)))\n    if <(az) > (z)> then\n        draw line from x (((ax) + ((_t1) * ((bx) - (ax)))) * ((@zN*180) / (z))) y (((ay) + ((_t1) * ((by) - (ay)))) * ((@zN*180) / (z))) to x ((bx) * ((@zN*180) / (bz))) y ((by) * ((@zN*180) / (bz))) start width ((diameter) * ((@zN*180) / (z))) end width ((diameter) * ((@zN*180) / (bz)))\n    else\n        if <(bz) > (z)> then\n            draw line from x ((ax) * ((@zN*180) / (az))) y ((ay) * ((@zN*180) / (az))) to x (((ax) + ((_t1) * ((bx) - (ax)))) * ((@zN*180) / (z))) y (((ay) + ((_t1) * ((by) - (ay)))) * ((@zN*180) / (z))) start width ((diameter) * ((@zN*180) / (az))) end width (((diameter) + ((_t1) * ((end_w) - (diameter)))) * ((@zN*180) / (z)))\n        else\n            draw line from x ((ax) * ((@zN*180) / (az))) y ((ay) * ((@zN*180) / (az))) to x ((bx) * ((@zN*180) / (bz))) y ((by) * ((@zN*180) / (bz))) start width ((diameter) * ((@zN*180) / (az))) end width ((diameter) * ((@zN*180) / (bz)))\n        end\n    end\nend\n\ndefine render.visualise_primitives\nset rot_matrix_γβα ( ([cos v] of (@C_roll) ) ([sin v] of (@C_roll) ) ([cos v] of (@C_pitch) ) ([sin v] of (@C_pitch) ) ([cos v] of (@C_yaw) ) ([sin v] of (@C_yaw) ) )\nset [brightness v] effect to (-100)\nshow\nset [i v] to [1]\nrepeat ((((length of [gameobjects v]) / (@enum o:SIZE)) * <(@show_prims/dynamic/objs) = [3]>) + (((*dynamic_seg) / (@enum p:SIZE)) * <(@show_prims/dynamic/objs) < [3]>))\n    if <<(@show_prims/dynamic/objs) = [3]> or <<<not <(item (i) of [primitives v]) = [CONTAINER]>> and <(@show_prims/dynamic/objs) = [1]>> or <<(item (i) of [primitives v]) = [CONTAINER]> and <(@show_prims/dynamic/objs) = [2]>>>> then\n        if <<<<(@show_prims/dynamic/objs) = [3]> and <(item ((i) + (@enum o:HIDDEN?)) of [gameobjects v]) = [0]>> or <<(@show_prims/dynamic/objs) = [1]> and <(item ((item ((i) + (@enum p:*OBJECT)) of [primitives v]) + (@enum o:HIDDEN?)) of [gameobjects v]) = [0]>>> or <(@show_prims/dynamic/objs) = [2]>> then\n            if <(@show_prims/dynamic/objs) = [2]> then\n                set [_tmp v] to (item ((i) + (1)) of [primitives v])\n                set [_x v] to (item (_tmp) of [vertex_world v])\n                set [_y v] to (item ((_tmp) + (1)) of [vertex_world v])\n                set [_z v] to (item ((_tmp) + (2)) of [vertex_world v])\n            else\n                set [_tmp v] to (((item ((i) + (@enum o:*BSPHERE)) of [gameobjects v]) * <(@show_prims/dynamic/objs) = [3]>) + ((item ((i) + (@enum p:*BSPHERE)) of [primitives v]) * <(@show_prims/dynamic/objs) < [3]>))\n                set [_x v] to (item (_tmp) of [bsphere_world v])\n                set [_y v] to (item ((_tmp) + (1)) of [bsphere_world v])\n                set [_z v] to (item ((_tmp) + (2)) of [bsphere_world v])\n            end\n            _x, _y, z = apply_rot_matrix ( ((_x) - (@camX)) ((_y) - (@camY)) ((_z) - (@camZ)) )\n            if <(@show_prims/dynamic/objs) = [2]> then\n                set [_α v] to [7]\n                set [_β v] to [container]\n            else\n                set [_α v] to ((((2) * (item ((_tmp) + (3)) of [bsphere_world v])) * (@zN*180)) / (_z))\n                set [_β v] to [bsphere]\n            end\n            render_sprite (((_x) * (@zN*180)) / (_z)) (((_y) * (@zN*180)) / (_z)) (_α) (_β) [] [90] [] costume_width [100]\n            if <key ((join [shift] []) v) pressed?> then\n                if <key ((join [<] []) v) pressed?> then\n                    set [_tmp v] to (((i) * <(@show_prims/dynamic/objs) = [3]>) + ((item ((item ((i) + (@enum p:*NODE)) of [primitives v]) + (@enum t:PARENT)) of [bsp.tree v]) * <(@show_prims/dynamic/objs) < [3]>))\n                else\n                    set [_tmp v] to (((i) * <(@show_prims/dynamic/objs) = [3]>) + ((item ((i) + (@enum p:*NODE)) of [primitives v]) * <(@show_prims/dynamic/objs) < [3]>))\n                end\n            else\n                if <key ((join [<] []) v) pressed?> then\n                    set [_tmp v] to (((i) * <(@show_prims/dynamic/objs) = [3]>) + ((item ((i) + (@enum p:*BSPHERE)) of [primitives v]) * <(@show_prims/dynamic/objs) < [3]>))\n                else\n                    set [_tmp v] to (((i) * <(@show_prims/dynamic/objs) = [3]>) + ((i) * <(@show_prims/dynamic/objs) < [3]>))\n                end\n            end\n            render_number ( value (_tmp) x (((_x) * (@zN*180)) / (_z)) y (((_y) * (@zN*180)) / (_z)) size ((((0.01) * ((((6) * (@zN*180)) / (_z)) * <(_z) < [0]>)) * <(_α) < [8]>) + (((0.04) * (_α)) * <not <(_α) < [8]>>)) )\n        end\n    end\n    change [i v] by (((@enum o:SIZE) * <(@show_prims/dynamic/objs) = [3]>) + ((@enum p:SIZE) * <(@show_prims/dynamic/objs) < [3]>))\nend\nclear graphic effects\nswitch costume to (paint-brush v)\nhide\n\ndefine render_number ( value (value) x (x) y (y) size (size) )\nif <<([abs v] of (x) ) > ((240) + ((size) / (2)))> or <([abs v] of (y) ) > ((180) + ((size) / (2)))>> then\n    stop [this script v]\nend\ngo to x: ((x) - (((length of (value)) / (2)) * (size))) y: (y)\nif <(((size) / (13)) * (100)) < [100]> then\n    switch costume to (big v)\nelse\n    switch costume to (small v)\nend\nset size to (((size) / (13)) * (100)) %\nset [_tmp v] to [1]\nrepeat (length of (value))\n    switch costume to (join [text_] (letter (_tmp) of (value)))\n    stamp\n    change x by (size)\n    change [_tmp v] by (1)\nend\n\nif <not <((item (i) of [bsp._*prims v]) mod (@enum p:SIZE)) = [1]>> then\n    ​​breakpoint​​\nend\n\ndefine tick.secondhalf()\nif <(@rendering_active?) = [1]> then\n    delete all of [bsp._stack v]\n    end timing [bsp reinsert]\n    start timing [bsp traversal]\n    bsp.traversal ( [3] [0] local_var_stack: [] [] [] [] [] )\n    start timing [rasterisation]\n    render.rasterisation ()\n    end timing [rasterisation]\n    switch costume to (paint-brush v)\n    set [@tris visible v] to (_tri_counter)\n    set [_tmp v] to (((days since 2000) - (@days_since_2000)) * (86400))\n    change [_elapsed_time v] by (_tmp)\n    set [@time v] to (([floor v] of ((_elapsed_time) * (10)) ) / (10))\n    if <(length of [_δt_buffer v]) > [5]> then\n        delete (1) of [_δt_buffer v]\n    end\n    add (_tmp) to [_δt_buffer v]\n    set [@fps v] to [0]\n    set [i v] to [1]\n    repeat (length of [_δt_buffer v])\n        change [@fps v] by (item (i) of [_δt_buffer v])\n        change [i v] by (1)\n    end\n    set [@fps v] to (([floor v] of (((1) / ((@fps) / (length of [_δt_buffer v]))) * (10)) ) / (10))\n    if <<<(@fps) < (@auto_disable_shadows_fps_thresh)> and <(_elapsed_time) > [3]>> and <<(@shadows?) = [1]> and <(_shadows_turned_off) = [0]>>> then\n        set [_shadows_turned_off v] to [1]\n        set [@shadows? v] to [0]\n    end\n    set [@days_since_2000 v] to (days since 2000)\n    broadcast (physics v)\n    broadcast (game logic v)\nelse\n    set [@days_since_2000 v] to (days since 2000)\nend\nbroadcast (gui v)\n\ndefine render.depth_buffer.insert_shadows ()\nset [_*prim v] to ((*dynamic_seg) + (1))\nset [i v] to [1]\nrepeat (((length of [primitives v]) - (*dynamic_seg)) / (@enum p:SIZE))\n    if <(item ((item ((_*prim) + (@enum p:*OBJECT)) of [primitives v]) + (@enum o:HIDDEN?)) of [gameobjects v]) = [0]> then\n        set [_tmp v] to (item ((_*prim) + (@enum p:NORMAL)) of [primitives v])\n        if <<((((@lightX) * (item (_tmp) of [normal_world v])) + ((@lightY) * (item ((_tmp) + (1)) of [normal_world v]))) + ((@lightZ) * (item ((_tmp) + (2)) of [normal_world v]))) < [0]> or <(item ((_*prim) + (@enum p:NORMAL)) of [primitives v]) = [null]>> then\n            if <<not <(item (_*prim) of [primitives v]) = [CONTAINER]>> and <not <<(@first_person?) = [1]> and <(_*prim) = (@*player_shadow_prim)>>>> then\n                replace item ((_*prim) + (@enum p:ILLUMINATION)) of [primitives v] with (((((_darkness_fac) + (0.17)) * ((_darkness_fac) + (0.17))) - (0.3689)) * (100))\n                insert (_*prim) at (1) of [depth order v] \n                if <<(item (_*prim) of [primitives v]) = [POINT]> or <(item (_*prim) of [primitives v]) = [LINE]>> then\n                    set [_α v] to (item ((_*prim) + (1)) of [primitives v])\n                    set [_β v] to (item ((_*prim) + (@enum p:SHAD_OFF_SCALE)) of [primitives v])\n                    if <<not <(_β) = []>> and <(item (_*prim) of [primitives v]) = [POINT]>> then\n                        set [_z v] to ((item (((_α) - (@*shadow_seg)) + (2)) of [vertex v]) + ((_shad_off_z) * (_β)))\n                        set [_x v] to ((item ((_α) - (@*shadow_seg)) of [vertex v]) + ((_shad_off_x) * (_β)))\n                        set [_y v] to ((item (((_α) - (@*shadow_seg)) + (1)) of [vertex v]) + ((_shad_off_y) * (_β)))\n                        replace item (_α) of [vertex v] with (_x)\n                        replace item ((_α) + (1)) of [vertex v] with (_y)\n                        replace item ((_α) + (2)) of [vertex v] with (_z)\n                        delete (1) of [depth order v]\n                        insert (_*prim) at (item # of (item (i) of [@shadow_to_*prim v]) in [depth order v]) of [depth order v] \n                    else\n                        set [_z v] to (item ((_α) + (2)) of [vertex v])\n                        set [_x v] to (item (_α) of [vertex v])\n                        set [_y v] to (item ((_α) + (1)) of [vertex v])\n                    end\n                    set [_tmp v] to ([sqrt v] of ((((_x) * (_x)) + ((_y) * (_y))) + ((_z) * (_z))) )\n                    set [_tmp v] to (((((_shad_off_x) * (_x)) + ((_shad_off_y) * (_y))) + ((_shad_off_z) * (_z))) / (_tmp))\n                    if <(item (_*prim) of [primitives v]) = [POINT]> then\n                        replace item ((_*prim) + (@enum p:SPRITE_SCALE_Y)) of [primitives v] with (_tmp)\n                    else\n                        replace item ((_*prim) + (@enum p:RADIUS)) of [primitives v] with (([sqrt v] of (_tmp) ) * (item (((_*prim) - (*dynamic_seg)) + (@enum p:RADIUS)) of [primitives v]))\n                    end\n                end\n            end\n        end\n    end\n    change [_*prim v] by (@enum p:SIZE)\n    change [i v] by (1)\nend\n\nwhen I receive [render.change_costume_to_\(@tmp\) v]\nswitch costume to (@temp)\n\ndefine set rot_matrix_αβγ ( (cos α) (sin α) (cos β) (sin β) (cos γ) (sin γ) )\nset [_rm1 v] to (((cos α) * (cos γ)) + ((sin α) * ((sin β) * (sin γ))))\nset [_rm2 v] to ((((cos γ) * (sin α)) * (sin β)) - ((cos α) * (sin γ)))\nset [_rm3 v] to ((cos β) * (sin α))\nset [_rm4 v] to ((cos β) * (sin γ))\nset [_rm5 v] to ((cos β) * (cos γ))\nset [_rm6 v] to ((-1) * (sin β))\nset [_rm7 v] to ((((cos α) * (sin β)) * (sin γ)) - ((sin α) * (cos γ)))\nset [_rm8 v] to (((sin α) * (sin γ)) + ((cos α) * ((sin β) * (cos γ))))\nset [_rm9 v] to ((cos α) * (cos β))\n\ndefine render.show_bsp_tree ()\nswitch costume to (ballgreen v)\nset pen color to (#1d0063)\nrender.draw_binary_tree ( *node [3] node xy [0] [140] parent xy [] [] depth [1] )\npen up\n\ndefine render.draw_binary_tree ( *node (*node) node xy (nx) (ny) parent xy (px) (py) depth (depth) )\nif <(*node) = []> then\n    stop [this script v]\nend\npen up\nset [_tmp v] to ((40) / ([sqrt v] of (depth) ))\nset size to ((_tmp) * (0.5)) %\nif <not <(depth) = [1]>> then\n    go to x: (px) y: (py)\n    pen down\n    go to x: (nx) y: (ny)\n    go to x: (px) y: (py)\n    stamp\nelse\n    go to x: (nx) y: (ny)\n    stamp\nend\nrender.draw_binary_tree ( *node (item ((*node) + ((@enum t:EDGE_A) + (1))) of [bsp.tree v]) node xy ((nx) - (_tmp)) ((ny) - (20)) parent xy (nx) (ny) depth ((depth) + (1)) )\nrender.draw_binary_tree ( *node (item ((*node) + ((@enum t:EDGE_A) + (3))) of [bsp.tree v]) node xy ((nx) + (_tmp)) ((ny) - (20)) parent xy (nx) (ny) depth ((depth) + (1)) )\n\ndefine render.world_tranform()\nset [i v] to [1]\nrepeat (length of [@updated_objects v])\n    set [_*obj v] to (item (i) of [@updated_objects v])\n    set [_x2 v] to (item ((_*obj) + (1)) of [gameobjects v])\n    set [_y2 v] to (item ((_*obj) + (2)) of [gameobjects v])\n    set [_z2 v] to (item ((_*obj) + (3)) of [gameobjects v])\n    set [_α v] to (item ((_*obj) + (4)) of [gameobjects v])\n    set [_β v] to (item ((_*obj) + (5)) of [gameobjects v])\n    set [_γ v] to (item ((_*obj) + (6)) of [gameobjects v])\n    set [_sx v] to (item ((_*obj) + (7)) of [gameobjects v])\n    set [_sy v] to (item ((_*obj) + (8)) of [gameobjects v])\n    set [_sz v] to (item ((_*obj) + (9)) of [gameobjects v])\n    set [_scale_mag v] to ([sqrt v] of (((_sx) * (_sx)) + (((_sy) * (_sy)) + ((_sz) * (_sz)))) )\n    if <<(_sx) > (_sy)> and <(_sx) > (_sz)>> then\n        set [_scale_max v] to (_sx)\n    else\n        if <(_sy) > (_sz)> then\n            set [_scale_max v] to (_sy)\n        else\n            set [_scale_max v] to (_sz)\n        end\n    end\n    set rot_matrix_αβγ ( ([cos v] of (_α) ) ([sin v] of (_α) ) ([cos v] of (_β) ) ([sin v] of (_β) ) ([cos v] of (_γ) ) ([sin v] of (_γ) ) )\n    set [j v] to (item ((_*obj) + (@enum o:*VLEFT)) of [gameobjects v])\n    if <not <(j) = [v_left]>> then\n        set [_tmp v] to (item ((_*obj) + ((@enum o:*VLEFT) + (1))) of [gameobjects v])\n        repeat until <<(j) = (_tmp)> or <(j) = [null]>>\n            _x, _y, _z = apply_rot_matrix + trans ((_sx) * (item (j) of [vertex_buff v])) ((_sy) * (item ((j) + (1)) of [vertex_buff v])) ((_sz) * (item ((j) + (2)) of [vertex_buff v])) (_x2) (_y2) (_z2)\n            replace item (j) of [vertex_world v] with (_x)\n            replace item ((j) + (1)) of [vertex_world v] with (_y)\n            replace item ((j) + (2)) of [vertex_world v] with (_z)\n            set [j v] to (item ((j) + (3)) of [vertex_buff v])\n        end\n    end\n    set [j v] to (item ((_*obj) + (@enum o:*NLEFT)) of [gameobjects v])\n    set [_tmp v] to (item ((_*obj) + ((@enum o:*NLEFT) + (1))) of [gameobjects v])\n    repeat until <<(j) = (_tmp)> or <(j) > (length of [normal_world v])>>\n        _x, _y, z = apply_rot_matrix ( (item (j) of [normal_buff v]) (item ((j) + (1)) of [normal_buff v]) (item ((j) + (2)) of [normal_buff v]) )\n        replace item (j) of [normal_world v] with (_x)\n        replace item ((j) + (1)) of [normal_world v] with (_y)\n        replace item ((j) + (2)) of [normal_world v] with (_z)\n        change [j v] by (3)\n    end\n    set [_tmp2 v] to (item ((_*obj) + (@enum o:*BSPHERE)) of [gameobjects v])\n    _x, _y, _z = apply_rot_matrix + trans ((_sx) * (item (_tmp2) of [bsphere_buff v])) ((_sy) * (item ((_tmp2) + (1)) of [bsphere_buff v])) ((_sz) * (item ((_tmp2) + (2)) of [bsphere_buff v])) (_x2) (_y2) (_z2)\n    replace item (_tmp2) of [bsphere_world v] with (_x)\n    replace item ((_tmp2) + (1)) of [bsphere_world v] with (_y)\n    replace item ((_tmp2) + (2)) of [bsphere_world v] with (_z)\n    replace item ((_tmp2) + (3)) of [bsphere_world v] with ((_scale_max) * (item ((_tmp2) + (3)) of [bsphere_buff v]))\n    set [j v] to (item ((_*obj) + (@enum o:**PLEFT)) of [gameobjects v])\n    set [_tmp v] to (item ((_*obj) + ((@enum o:**PLEFT) + (1))) of [gameobjects v])\n    repeat until <<(j) = (_tmp)> or <(j) = [null]>>\n        set [_tmp2 v] to (item ((item (j) of [gameobjects._*prims v]) + (@enum p:*BSPHERE)) of [primitives v])\n        if <not <((_tmp2) + (0)) = [0]>> then\n            _x, _y, _z = apply_rot_matrix + trans ((_sx) * (item (_tmp2) of [bsphere_buff v])) ((_sy) * (item ((_tmp2) + (1)) of [bsphere_buff v])) ((_sz) * (item ((_tmp2) + (2)) of [bsphere_buff v])) (_x2) (_y2) (_z2)\n            replace item (_tmp2) of [bsphere_world v] with (_x)\n            replace item ((_tmp2) + (1)) of [bsphere_world v] with (_y)\n            replace item ((_tmp2) + (2)) of [bsphere_world v] with (_z)\n            set [_*normal v] to (item ((item (j) of [gameobjects._*prims v]) + (@enum p:NORMAL)) of [primitives v])\n            if <not <(_*normal) = [null]>> then\n                set [_dot v] to (((_sx) * (item (_*normal) of [normal_buff v])) + (((_sy) * (item ((_*normal) + (1)) of [normal_buff v])) + ((_sz) * (item ((_*normal) + (2)) of [normal_buff v]))))\n                set [_x v] to ((_sx) - ((_dot) * (item (_*normal) of [normal_buff v])))\n                set [_y v] to ((_sy) - ((_dot) * (item ((_*normal) + (1)) of [normal_buff v])))\n                set [_z v] to ((_sz) - ((_dot) * (item ((_*normal) + (2)) of [normal_buff v])))\n                if <<(_x) > (_y)> and <(_x) > (_z)>> then\n                    set [_scale v] to (_x)\n                else\n                    if <(_y) > (_z)> then\n                        set [_scale v] to (_y)\n                    else\n                        set [_scale v] to (_z)\n                    end\n                end\n                replace item ((_tmp2) + (3)) of [bsphere_world v] with ((_scale) * (item ((_tmp2) + (3)) of [bsphere_buff v]))\n            else\n                replace item ((_tmp2) + (3)) of [bsphere_world v] with ((_scale_max) * (item ((_tmp2) + (3)) of [bsphere_buff v]))\n            end\n        end\n        set [j v] to (item ((j) + (1)) of [gameobjects._*prims v])\n    end\n    change [i v] by (1)\nend\n\ndefine _x, _y, _z = 3D_cross_prod ( (ax) (ay) (az) (bx) (by) (bz) )\nset [_x v] to (((ay) * (bz)) - ((az) * (by)))\nset [_y v] to (((az) * (bx)) - ((ax) * (bz)))\nset [_z v] to (((ax) * (by)) - ((ay) * (bx)))\n\ndefine _atan2 = atan2( (y) (x) )\nif <(x) = [0]> then\n    set [_atan2 v] to ((<(y) < [0]> * (-90)) + (<not <(y) < [0]>> * (90)))\nelse\n    if <(x) < [0]> then\n        set [_atan2 v] to ((180) + ([atan v] of ((y) / (x)) ))\n    else\n        set [_atan2 v] to ([atan v] of ((y) / (x)) )\n    end\nend\nset [_atan2 v] to ((_atan2) mod (360))\n\ndefine _dot = dot_prod (ax) (ay) (az) (bx) (by) (bz)\nset [_dot v] to (((ax) * (bx)) + (((ay) * (by)) + ((az) * (bz))))\n\nwhen flag clicked\nsay [ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh]\n\n@Physics\n\ndefine add collision forces (normal: (nx) (ny) (nz) *prim (*prim) )\nset [_*obj v] to (item ((*prim) + (@enum p:*OBJECT)) of [primitives v])\nif <[@updated_objects v] contains (_*obj)?> then\n    set [_tmp v] to (item # of (join [*obj:] (_*obj)) in [@updated_objects_prev_ori v])\n    set [_x v] to (((item ((_*obj) + (1)) of [gameobjects v]) - (item ((_tmp) + (1)) of [@updated_objects_prev_ori v])) * ((@fps) / (30)))\n    set [_y v] to (((item ((_*obj) + (2)) of [gameobjects v]) - (item ((_tmp) + (2)) of [@updated_objects_prev_ori v])) * ((@fps) / (30)))\n    set [_z v] to (((item ((_*obj) + (3)) of [gameobjects v]) - (item ((_tmp) + (3)) of [@updated_objects_prev_ori v])) * ((@fps) / (30)))\n    set [_α v] to ((((((item ((_*obj) + (4)) of [gameobjects v]) - (item ((_tmp) + (4)) of [@updated_objects_prev_ori v])) + (180)) mod (360)) - (180)) * (((3.141) / (180)) * ((@fps) / (30))))\n    set [_β v] to ((((((item ((_*obj) + (5)) of [gameobjects v]) - (item ((_tmp) + (5)) of [@updated_objects_prev_ori v])) + (180)) mod (360)) - (180)) * (((3.141) / (180)) * ((@fps) / (30))))\n    set [_γ v] to ((((((item ((_*obj) + (6)) of [gameobjects v]) - (item ((_tmp) + (6)) of [@updated_objects_prev_ori v])) + (180)) mod (360)) - (180)) * (((3.141) / (180)) * ((@fps) / (30))))\n    set [_rx v] to ((@player_x) - (item ((_*obj) + (1)) of [gameobjects v]))\n    set [_ry v] to ((@player_y) - (item ((_*obj) + (2)) of [gameobjects v]))\n    set [_rz v] to ((@player_z) - (item ((_*obj) + (3)) of [gameobjects v]))\n    set [_x v] to ((_x) + (((_α) * (_rz)) - ((_γ) * (_ry))))\n    set [_y v] to ((_y) + (((_γ) * (_rx)) - ((_β) * (_rz))))\n    set [_z v] to ((_z) + (((_β) * (_ry)) - ((_α) * (_rx))))\nelse\n    set [_x v] to [0]\n    set [_y v] to [0]\n    set [_z v] to [0]\nend\nset [_tmp2 v] to ((-1) * ((((@player_x_vel) - (_x)) * (nx)) + ((((@player_y_vel) - (_y)) * (ny)) + (((@player_z_vel) - (_z)) * (nz)))))\nif <(_tmp2) > [0]> then\n    add (item (_*obj) of [gameobjects v]) to [@player forces v]\n    add (*prim) to [@player forces v]\n    set [_restitution v] to (item ((item ((*prim) + (@enum p:MATERIAL)) of [primitives v]) + (8)) of [materials v])\n    add (((1) + ((_restitution) * (1.15))) * ((_tmp2) * (nx))) to [@player forces v]\n    add (((1) + ((_restitution) * (1.15))) * ((_tmp2) * (ny))) to [@player forces v]\n    add (((1) + ((_restitution) * (1.15))) * ((_tmp2) * (nz))) to [@player forces v]\nend\nset [_tmp2 v] to ((-1) * ((((_player_x_vel_physical) - (_x)) * (nx)) + ((((_player_y_vel_physical) - (_y)) * (ny)) + (((_player_z_vel_physical) - (_z)) * (nz)))))\nadd tangential forces (((_player_x_vel_physical) - (_x)) + ((_tmp2) * (nx))) (((_player_y_vel_physical) - (_y)) + ((_tmp2) * (ny))) (((_player_z_vel_physical) - (_z)) + ((_tmp2) * (nz))) ((_tmp2) * (nx)) ((_tmp2) * (ny)) ((_tmp2) * (nz)) *prim (*prim)\n\ndefine _tmp = vec_length ( (x) (y) )\nset [_tmp v] to ([sqrt v] of (((x) * (x)) + ((y) * (y))) )\n\ndefine _tmp = clamp ( (value) (min) (max) )\nif <(value) < (min)> then\n    set [_tmp v] to (min)\nelse\n    if <(value) > (max)> then\n        set [_tmp v] to (max)\n    else\n        set [_tmp v] to (value)\n    end\nend\n\ndefine Add collision and pos. correction if min TOI (A= Closest pt polygon, B= closest pt sphere: Ax-Bx (ax-bx) Ay-By (ay-by) Az-Bz (az-bz) sphere Centre: (cx) (cy) (cz) )\nset [_tmp v] to ([sqrt v] of (((ax-bx) * (ax-bx)) + (((ay-by) * (ay-by)) + ((az-bz) * (az-bz)))) )\nif <(_tmp) > [0]> then\n    if <(_tmp) > (@penetration_thresh)> then\n        set [_new_sphere_x v] to ((cx) + (ax-bx))\n        set [_new_sphere_y v] to ((cy) + (ay-by))\n        set [_new_sphere_z v] to ((cz) + (az-bz))\n    else\n        set [_new_sphere_x v] to (cx)\n        set [_new_sphere_y v] to (cy)\n        set [_new_sphere_z v] to (cz)\n    end\n    set [_tmp2 v] to ([sqrt v] of ((((_new_sphere_x) - (_b_x_old)) * ((_new_sphere_x) - (_b_x_old))) + ((((_new_sphere_y) - (_b_y_old)) * ((_new_sphere_y) - (_b_y_old))) + (((_new_sphere_z) - (_b_z_old)) * ((_new_sphere_z) - (_b_z_old))))) )\n    add (_tmp2) to [_collision_candidates v]\n    if <(_tmp2) < (_min_toi_val)> then\n        set [_min_toi_idx v] to (length of [_collision_candidates v])\n        set [_min_toi_val v] to (_tmp2)\n    end\n    add (_new_sphere_x) to [_collision_candidates v]\n    add (_new_sphere_y) to [_collision_candidates v]\n    add (_new_sphere_z) to [_collision_candidates v]\n    add (ax-bx) to [_collision_candidates v]\n    add (ay-by) to [_collision_candidates v]\n    add (az-bz) to [_collision_candidates v]\n    add (_tmp) to [_collision_candidates v]\n    add (_*prim) to [_collision_candidates v]\nend\n\ndefine add tangential forces (vtx) (vty) (vtz) (nx) (ny) (nz) *prim (*prim)\nset [_tmp v] to ([sqrt v] of (((nx) * (nx)) + (((ny) * (ny)) + ((nz) * (nz)))) )\nset [_tmp2 v] to ([sqrt v] of (((vtx) * (vtx)) + (((vty) * (vty)) + ((vtz) * (vtz)))) )\nadd (join [t:] (item (item ((*prim) + (@enum p:*OBJECT)) of [primitives v]) of [gameobjects v])) to [@player forces v]\nadd (join [t:] (*prim)) to [@player forces v]\nif <([abs v] of (_tmp2) ) > ((_µ) * (_tmp))> then\n    set [_tmp v] to (((_µ) * (_tmp)) / ([abs v] of (_tmp2) ))\n    add ((-1) * ((vtx) * (_tmp))) to [@player forces v]\n    add ((-1) * ((vty) * (_tmp))) to [@player forces v]\n    add ((-1) * ((vtz) * (_tmp))) to [@player forces v]\nelse\n    add (((-1) * (vtx)) * (_µ)) to [@player forces v]\n    add (((-1) * (vty)) * (_µ)) to [@player forces v]\n    add (((-1) * (vtz)) * (_µ)) to [@player forces v]\nend\n\nwhen I receive [physics v]\nif <(@edit_mode?) = [0]> then\n    physics\nend\n\nwhen flag clicked\nset [_counter v] to [0]\nhide\nswitch costume to (force v)\ndelete all of [@player forces v]\nset [_player_x_vel_physical v] to [0]\nset [_player_y_vel_physical v] to [0]\nset [_player_z_vel_physical v] to [0]\nset [_player_x_vel_controlled v] to [0]\nset [_player_y_vel_controlled v] to [0]\nset [_player_z_vel_controlled v] to [0]\ndelete all of [_debug v]\ndelete all of [@player_forces_controlled v]\nrepeat (3)\n    add [0] to [@player_forces_controlled v]\nend\n\ndefine _Collision = sphere-polygon collision test ( *prim (*prim) Normal (nx) (ny) (nz) sphere (x) (y) (z) (r) )\ndelete all of [_collision v]\ndelete all of [idxs_tmp v]\nset [_tmp v] to (item (*prim) of [primitives v])\nif <(_tmp) = [POLYGON]> then\n    set [_tmp2 v] to (item (item ((*prim) + (1)) of [primitives v]) of [idxs_poly v])\nelse\n    set [_tmp2 v] to (item ((*prim) + (1)) of [primitives v])\nend\nset [_dist_to_plane v] to ((((x) - (item (_tmp2) of [vertex_world v])) * (nx)) + ((((y) - (item ((_tmp2) + (1)) of [vertex_world v])) * (ny)) + (((z) - (item ((_tmp2) + (2)) of [vertex_world v])) * (nz))))\nif <([abs v] of (_dist_to_plane) ) > (r)> then\n    stop [this script v]\nend\nif <(_tmp) = [POLYGON]> then\n    set [_tmp v] to (item ((*prim) + (1)) of [primitives v])\n    add (item (_tmp) of [idxs_poly v]) to [idxs_tmp v]\n    set [_tmp v] to (item ((_tmp) + (1)) of [idxs_poly v])\n    repeat until <(_tmp) = (item ((*prim) + (1)) of [primitives v])>\n        add (item (_tmp) of [idxs_poly v]) to [idxs_tmp v]\n        set [_tmp v] to (item ((_tmp) + (1)) of [idxs_poly v])\n    end\nelse\n    set [i v] to [1]\n    repeat ((<(_tmp) = [POINT]> * (1)) + ((<(_tmp) = [LINE]> * (2)) + ((<(_tmp) = [TRIANGLE]> * (3)) + (<(_tmp) = [QUAD]> * (4)))))\n        add (item ((*prim) + (i)) of [primitives v]) to [idxs_tmp v]\n        change [i v] by (1)\n    end\nend\ndelete all of [_poly v]\nset [i v] to [1]\nrepeat (length of [idxs_tmp v])\n    add (item (item (i) of [idxs_tmp v]) of [vertex_world v]) to [_poly v]\n    add (item ((item (i) of [idxs_tmp v]) + (1)) of [vertex_world v]) to [_poly v]\n    add (item ((item (i) of [idxs_tmp v]) + (2)) of [vertex_world v]) to [_poly v]\n    change [i v] by (1)\nend\n_intersects,_edge_idx,_x,_y,_z, = testPolygonEdgeSphereIntersection (sphere x (x) y (y) z (z) r (r) )\nif <(_intersects?) = [0]> then\n    set [_x v] to ((x) - ((_dist_to_plane) * (nx)))\n    set [_y v] to ((y) - ((_dist_to_plane) * (ny)))\n    set [_z v] to ((z) - ((_dist_to_plane) * (nz)))\n    set [_edge_idx v] to [NULL]\n    set [i v] to (length of [_poly v])\n    if <([abs v] of (ny) ) > (@coplanar_thresh)> then\n        repeat ((length of [_poly v]) / (3))\n            delete ((i) - (1)) of [_poly v]\n            change [i v] by (-3)\n        end\n        _intersects = PointInPolygon ( (_x) (_z) )\n    else\n        if <([abs v] of (nz) ) > (@coplanar_thresh)> then\n            repeat ((length of [_poly v]) / (3))\n                delete (i) of [_poly v]\n                change [i v] by (-3)\n            end\n            _intersects = PointInPolygon ( (_x) (_y) )\n        else\n            repeat ((length of [_poly v]) / (3))\n                delete ((i) - (2)) of [_poly v]\n                change [i v] by (-3)\n            end\n            _intersects = PointInPolygon ( (_y) (_z) )\n        end\n    end\n    if <(_intersects?) = [1]> then\n        add (_x) to [_collision v]\n        add (_y) to [_collision v]\n        add (_z) to [_collision v]\n        set [_tmp v] to ((r) * (([abs v] of (_dist_to_plane) ) / (_dist_to_plane)))\n        add ((x) - ((_tmp) * (nx))) to [_collision v]\n        add ((y) - ((_tmp) * (ny))) to [_collision v]\n        add ((z) - ((_tmp) * (nz))) to [_collision v]\n    end\nelse\n    add (_x) to [_collision v]\n    add (_y) to [_collision v]\n    add (_z) to [_collision v]\n    set [_x v] to ((x) - (_x))\n    set [_y v] to ((y) - (_y))\n    set [_y v] to ((z) - (_z))\n    set [_tmp v] to ([sqrt v] of (((_x) * (_x)) + (((_y) * (_y)) + ((_z) * (_z)))) )\n    add ((x) + (((_x) / (_tmp)) * (r))) to [_collision v]\n    add ((y) + (((_y) / (_tmp)) * (r))) to [_collision v]\n    add ((z) + (((_z) / (_tmp)) * (r))) to [_collision v]\nend\nif <(_intersects?) = [1]> then\n    add (_t) to [_collision v]\n    add (_edge_idx) to [_collision v]\n    add (_dist_to_plane) to [_collision v]\nend\n\ndefine _intersects = PointInPolygon ( (cx) (cy) )\nif <(length of [_poly v]) = [6]> then\n    _intersects = PointInTri (cx) (cy) (item (1) of [_poly v]) (item (2) of [_poly v]) (item (3) of [_poly v]) (item (4) of [_poly v]) (item (5) of [_poly v]) (item (6) of [_poly v])\nelse\n    if <(length of [_poly v]) < [15]> then\n        _intersects = PointInPoly (method1) ( (cx) (cy) )\n    else\n        set [_low v] to [1]\n        set [_high v] to ((length of [_poly v]) + (1))\n        repeat until <((_low) + (2)) = (_high)>\n            set [_mid v] to (((round ((((_low) + (_high)) + (2)) / (4))) * (2)) - (1))\n            set [_tmp v] to ((((cx) - (item (1) of [_poly v])) * ((item ((_mid) + (1)) of [_poly v]) - (item (2) of [_poly v]))) - (((item (_mid) of [_poly v]) - (item (1) of [_poly v])) * ((cy) - (item (2) of [_poly v]))))\n            if <(_tmp) < [0]> then\n                set [_low v] to (_mid)\n            else\n                set [_high v] to (_mid)\n            end\n        end\n        if <<(_low) = [1]> or <(_high) = ((length of [_poly v]) + (1))>> then\n            set [_intersects? v] to [0]\n        else\n            set [_intersects? v] to <(((cx) - (item (_low) of [_poly v])) * ((item ((_high) + (1)) of [_poly v]) - (item ((_low) + (1)) of [_poly v]))) < (((item (_high) of [_poly v]) - (item (_low) of [_poly v])) * ((cy) - (item ((_low) + (1)) of [_poly v])))>\n        end\n    end\nend\n\ndefine _x,_y,_z,_t,_intersects = IntersectionLineSegmentSphere( segment AB (ax) (ay) (az) (bx) (by) (bz) Sphere (cx) (cy) (cz) (cr) )\nset [_t v] to ((((((cx) - (ax)) * ((bx) - (ax))) + (((cy) - (ay)) * ((by) - (ay)))) + (((cz) - (az)) * ((bz) - (az)))) / ((((bx) - (ax)) * ((bx) - (ax))) + ((((by) - (ay)) * ((by) - (ay))) + (((bz) - (az)) * ((bz) - (az))))))\nset [_t v] to (<(_t) > [1]> + (<<not <(_t) < [0]>> and <not <(_t) > [1]>>> * (_t)))\nif <<not <(_t) < [0]>> and <(_t) < [1]>> then\n    set [_x v] to ((ax) + ((_t) * ((bx) - (ax))))\n    set [_y v] to ((ay) + ((_t) * ((by) - (ay))))\n    set [_z v] to ((az) + ((_t) * ((bz) - (az))))\n    set [_intersects? v] to <not <((((cx) - (_x)) * ((cx) - (_x))) + ((((cy) - (_y)) * ((cy) - (_y))) + (((cz) - (_z)) * ((cz) - (_z))))) > ((cr) * (cr))>>\nelse\n    set [_intersects? v] to [0]\nend\n\ndefine _intersects = PointInTri (px) (py) (ax) (ay) (bx) (by) (cx) (cy)\nset [_tmp v] to <(((px) - (ax)) * ((by) - (ay))) < (((bx) - (ax)) * ((py) - (ay)))>\nif <<(((px) - (bx)) * ((cy) - (by))) < (((cx) - (bx)) * ((py) - (by)))> = (_tmp)> then\n    set [_intersects? v] to <<(((px) - (cx)) * ((ay) - (cy))) < (((ax) - (cx)) * ((py) - (cy)))> = (_tmp)>\n    stop [this script v]\nend\nset [_intersects? v] to [false]\n\ndefine start timing (timing label)\nif <[timings v] contains (timing label)?> then\n    set [_tmp v] to (item # of (timing label) in [timings v])\n    replace item ((_tmp) + (1)) of [timings v] with (days since 2000)\n    replace item ((_tmp) + (2)) of [timings v] with ((item ((_tmp) + (2)) of [timings v]) + (1))\nelse\n    add (timing label) to [timings v]\n    add (days since 2000) to [timings v]\n    add [0] to [timings v]\n    add [0] to [timings v]\nend\n\ndefine end timing (timing label)\nset [_tmp v] to (days since 2000)\nset [_tmp2 v] to (item # of (timing label) in [timings v])\nreplace item ((_tmp2) + (3)) of [timings v] with ((((86400) * ((_tmp) - (item ((_tmp2) + (1)) of [timings v]))) - ((3.71) / (1000000))) + (item ((_tmp2) + (3)) of [timings v]))\n\ndefine physics\nstart timing [physics]\nchange [_counter v] by (1)\nset [i v] to [1]\nset [_delta_t v] to ((((30) / (@fps)) * <(@fps) > [6]>) + ((5) * <not <(@fps) > [6]>>))\nrepeat ((length of [@player forces v]) / (5))\n    change [_player_x_vel_physical v] by (item ((i) + (2)) of [@player forces v])\n    change [_player_y_vel_physical v] by (item ((i) + (3)) of [@player forces v])\n    change [_player_z_vel_physical v] by (item ((i) + (4)) of [@player forces v])\n    change [i v] by (5)\nend\nchange [_player_x_vel_controlled v] by (item (1) of [@player_forces_controlled v])\nchange [_player_y_vel_controlled v] by (item (2) of [@player_forces_controlled v])\nchange [_player_z_vel_controlled v] by (item (3) of [@player_forces_controlled v])\nset [@player_x_vel v] to (((_player_x_vel_controlled) * (_delta_t)) + (_player_x_vel_physical))\nset [@player_y_vel v] to (((_player_y_vel_controlled) * ((_delta_t) * (_delta_t))) + (_player_y_vel_physical))\nset [@player_z_vel v] to (((_player_z_vel_controlled) * (_delta_t)) + (_player_z_vel_physical))\nset [_tmp v] to ([10 ^ v] of (([log v] of (0.99) ) * (_delta_t)) )\nset [_player_x_vel_physical v] to ((_player_x_vel_physical) * (_tmp))\nset [_player_y_vel_physical v] to ((_player_y_vel_physical) * (_tmp))\nset [_player_z_vel_physical v] to ((_player_z_vel_physical) * (_tmp))\nset [_tmp v] to ([10 ^ v] of (([log v] of (0.5) ) * (_delta_t)) )\nset [_player_x_vel_controlled v] to ((_player_x_vel_controlled) * (_tmp))\nset [_player_y_vel_controlled v] to ((_player_y_vel_controlled) * (_tmp))\nset [_player_z_vel_controlled v] to ((_player_z_vel_controlled) * (_tmp))\nset [_µ v] to (((1) * <(@glide/walk) = [1]>) + ((@μ) * <(@glide/walk) = [0]>))\ndelete all of [@player forces v]\nset [_b_x_old v] to (@player_x)\nset [_b_y_old v] to (@player_y)\nset [_b_z_old v] to (@player_z)\nchange [@player_x v] by ((@player_x_vel) * (_delta_t))\nchange [@player_y v] by ((@player_y_vel) * (_delta_t))\nchange [@player_z v] by ((@player_z_vel) * (_delta_t))\nCollision Resolution: Detect all collisions and resolve collision with min Time Of Impact\nif <(length of [_collision_candidates v]) > [0]> then\n    Collision Resolution: Resolve all remaining collisions in random order\nend\nset_inv_rot_matrix ( ([cos v] of (@W_roll) ) ([sin v] of (@W_roll) ) ([cos v] of (@W_pitch) ) ([sin v] of (@W_pitch) ) ([cos v] of (@W_yaw) ) ([sin v] of (@W_yaw) ) )\n_x, _y, z = apply_rot_matrix ( [0] (@gravity) [0] )\nadd [gravity] to [@player forces v]\nadd [] to [@player forces v]\nadd ((_x) * (_delta_t)) to [@player forces v]\nadd ((_y) * (_delta_t)) to [@player forces v]\nadd ((_z) * (_delta_t)) to [@player forces v]\nget primitive below player\nend timing [physics]\n\ndefine _intersects = PointInPoly (method1) ( (px) (py) )\nset [_tmp v] to <(((px) - (item (1) of [_poly v])) * ((item (4) of [_poly v]) - (item (2) of [_poly v]))) > (((py) - (item (2) of [_poly v])) * ((item (3) of [_poly v]) - (item (1) of [_poly v])))>\nset [i v] to [3]\nrepeat (((length of [_poly v]) / (2)) - (1))\n    if <not <<(((px) - (item (i) of [_poly v])) * ((item ((((i) + (2)) mod (length of [_poly v])) + (1)) of [_poly v]) - (item ((i) + (1)) of [_poly v]))) > (((py) - (item ((i) + (1)) of [_poly v])) * ((item ((((i) + (1)) mod (length of [_poly v])) + (1)) of [_poly v]) - (item (i) of [_poly v])))> = (_tmp)>> then\n        set [_intersects? v] to [0]\n        stop [this script v]\n    end\n    change [i v] by (2)\nend\nset [_intersects? v] to [1]\n\ndefine sphere-bounded polygon test ( sphere (x) (y) (z) (r) poly bounding-sphere (x2) (y2) (z2) (r2) )\nif <([sqrt v] of ((((x) - (x2)) * ((x) - (x2))) + ((((y) - (y2)) * ((y) - (y2))) + (((z) - (z2)) * ((z) - (z2))))) ) < ((r) + (r2))> then\n    set [_*normal v] to (item ((_*prim) + (@enum p:NORMAL)) of [primitives v])\n    _Collision = sphere-polygon collision test ( *prim (_*prim) Normal (item (_*normal) of [normal_world v]) (item ((_*normal) + (1)) of [normal_world v]) (item ((_*normal) + (2)) of [normal_world v]) sphere (x) (y) (z) (r) )\n    if <(length of [_collision v]) > [0]> then\n        Add collision and pos. correction if min TOI (A= Closest pt polygon, B= closest pt sphere: Ax-Bx ((item (1) of [_collision v]) - (item (4) of [_collision v])) Ay-By ((item (2) of [_collision v]) - (item (5) of [_collision v])) Az-Bz ((item (3) of [_collision v]) - (item (6) of [_collision v])) sphere Centre: (x) (y) (z) )\n        change [_num_collisions v] by (1)\n    end\nend\n\ndefine set_inv_rot_matrix ( (cos γ) (sin γ) (cos β) (sin β) (cos α) (sin α) )\nset [_rm1 v] to (((cos α) * (cos γ)) - ((sin α) * ((sin β) * (sin γ))))\nset [_rm2 v] to ((((sin α) * (sin β)) * (cos γ)) + ((cos α) * (sin γ)))\nset [_rm3 v] to ((-1) * ((cos β) * (sin α)))\nset [_rm4 v] to ((-1) * ((cos β) * (sin γ)))\nset [_rm5 v] to ((cos β) * (cos γ))\nset [_rm6 v] to (sin β)\nset [_rm7 v] to ((((cos α) * (sin β)) * (sin γ)) + ((sin α) * (cos γ)))\nset [_rm8 v] to (((sin α) * (sin γ)) - ((cos α) * ((sin β) * (cos γ))))\nset [_rm9 v] to ((cos α) * (cos β))\n\ndefine _x, _y, z = apply_rot_matrix ( (x) (y) (z) )\nset [_x v] to ((((x) * (_rm1)) + ((y) * (_rm2))) + ((z) * (_rm3)))\nset [_y v] to (((x) * (_rm4)) + (((y) * (_rm5)) + ((z) * (_rm6))))\nset [_z v] to (((x) * (_rm7)) + (((y) * (_rm8)) + ((z) * (_rm9))))\n\ndefine get primitive below player\nset [@ground_force v] to [0]\nset [i v] to [1]\nrepeat ((length of [@player forces v]) / (5))\n    set [_tmp v] to ([sqrt v] of ((((item ((i) + (2)) of [@player forces v]) * (item ((i) + (2)) of [@player forces v])) + ((item ((i) + (3)) of [@player forces v]) * (item ((i) + (3)) of [@player forces v]))) + ((item ((i) + (4)) of [@player forces v]) * (item ((i) + (4)) of [@player forces v]))) )\n    if <(_tmp) > [0.002]> then\n        set [_tmp2 v] to ((item ((i) + (3)) of [@player forces v]) / (_tmp))\n        if <(_tmp2) > (@ground_force)> then\n            set [@ground_force v] to (_tmp2)\n            set [@ground_force_label v] to (item ((i) + (1)) of [@player forces v])\n        end\n    end\n    change [i v] by (5)\nend\n\nwhen I receive [physics.set_zero_velocity v]\nset [_player_x_vel_controlled v] to [0]\nset [_player_y_vel_controlled v] to [0]\nset [_player_z_vel_controlled v] to [0]\nset [_player_x_vel_physical v] to [0]\nset [_player_y_vel_physical v] to [0]\nset [_player_z_vel_physical v] to [0]\nset [@player_x_vel v] to [0]\nset [@player_y_vel v] to [0]\nset [@player_z_vel v] to [0]\n\ndefine _intersects,_edge_idx,_x,_y,_z, = testPolygonEdgeSphereIntersection (sphere x (x) y (y) z (z) r (r) )\nset [j v] to [1]\nrepeat ((length of [_poly v]) / (3))\n    set [i v] to (j)\n    set [j v] to ((((i) + (2)) mod (length of [_poly v])) + (1))\n    _x,_y,_z,_t,_intersects = IntersectionLineSegmentSphere( segment AB (item (i) of [_poly v]) (item ((i) + (1)) of [_poly v]) (item ((i) + (2)) of [_poly v]) (item (j) of [_poly v]) (item ((j) + (1)) of [_poly v]) (item ((j) + (2)) of [_poly v]) Sphere (x) (y) (z) [] )\n    if <(_intersects?) = [1]> then\n        set [_edge_idx v] to ((((i) - (1)) / (3)) + (1))\n        stop [this script v]\n    end\nend\n\ndefine Collision Resolution: Detect all collisions and resolve collision with min Time Of Impact\nset [_px v] to ((@player_x) - (_b_x_old))\nset [_py v] to ((@player_y) - (_b_y_old))\nset [_pz v] to ((@player_z) - (_b_z_old))\nset [_squared_dist v] to (((_px) * (_px)) + (((_py) * (_py)) + ((_pz) * (_pz))))\nset [_use_anti_tunneling v] to <(_squared_dist) > ((@player_r) * (@player_r))>\nset [_num_collisions v] to [0]\nset [_mtl_tex_id v] to (item # of [MTL_TEX] in [materials v])\ndelete all of [_collision v]\ndelete all of [_collision_candidates v]\nobject level collision check\nprim level collision check\nif <(length of [_collision_candidates v]) > [0]> then\n    set [_tmp v] to (item ((_min_toi_idx) + (7)) of [_collision_candidates v])\n    if <(_tmp) > (@penetration_thresh)> then\n        set [@player_x v] to (item ((_min_toi_idx) + (1)) of [_collision_candidates v])\n        set [@player_y v] to (item ((_min_toi_idx) + (2)) of [_collision_candidates v])\n        set [@player_z v] to (item ((_min_toi_idx) + (3)) of [_collision_candidates v])\n    end\n    add collision forces (normal: ((item ((_min_toi_idx) + (4)) of [_collision_candidates v]) / (_tmp)) ((item ((_min_toi_idx) + (5)) of [_collision_candidates v]) / (_tmp)) ((item ((_min_toi_idx) + (6)) of [_collision_candidates v]) / (_tmp)) *prim (item ((_min_toi_idx) + (8)) of [_collision_candidates v]) )\n    repeat (9)\n        delete (_min_toi_idx) of [_collision_candidates v]\n    end\nend\n\ndefine Collision Resolution: Resolve all remaining collisions in random order\ndelete all of [_collision_candidates_*prims v]\nset [i v] to [1]\nrepeat ((length of [_collision_candidates v]) / (9))\n    add (item ((i) + (8)) of [_collision_candidates v]) to [_collision_candidates_*prims v]\n    change [i v] by (9)\nend\ndelete all of [_collision_candidates v]\nrepeat until <(length of [_collision_candidates_*prims v]) = [0]>\n    set [_*prim v] to (item (1) of [_collision_candidates_*prims v])\n    set [_tmp v] to (item ((_*prim) + (@enum p:*BSPHERE)) of [primitives v])\n    sphere-bounded polygon test ( sphere (@player_x) (@player_y) (@player_z) (@player_r) poly bounding-sphere (item (_tmp) of [bsphere_world v]) (item ((_tmp) + (1)) of [bsphere_world v]) (item ((_tmp) + (2)) of [bsphere_world v]) (item ((_tmp) + (3)) of [bsphere_world v]) )\n    delete (1) of [_collision_candidates_*prims v]\n    if <(length of [_collision v]) > [0]> then\n        set [i v] to ((length of [_collision_candidates v]) - (8))\n        set [_tmp v] to (item ((i) + (7)) of [_collision_candidates v])\n        if <(_tmp) > (@penetration_thresh)> then\n            set [@player_x v] to (item ((i) + (1)) of [_collision_candidates v])\n            set [@player_y v] to (item ((i) + (2)) of [_collision_candidates v])\n            set [@player_z v] to (item ((i) + (3)) of [_collision_candidates v])\n        end\n        add collision forces (normal: ((item ((i) + (4)) of [_collision_candidates v]) / (_tmp)) ((item ((i) + (5)) of [_collision_candidates v]) / (_tmp)) ((item ((i) + (6)) of [_collision_candidates v]) / (_tmp)) *prim (item ((i) + (8)) of [_collision_candidates v]) )\n    end\nend\n\ndefine object level collision check\ndelete all of [_collision_candidates_*prims v]\nset [_*obj v] to [1]\nrepeat (length of [gameobjects v])\n    if <<not <(_*obj) = (@*player_obj)>> and <(item ((_*obj) + (@enum o:HIDDEN?)) of [gameobjects v]) = [0]>> then\n        set [_tmp v] to (item ((_*obj) + (@enum o:*BSPHERE)) of [gameobjects v])\n        set [_x v] to (item (_tmp) of [bsphere_world v])\n        set [_y v] to (item ((_tmp) + (1)) of [bsphere_world v])\n        set [_z v] to (item ((_tmp) + (2)) of [bsphere_world v])\n        if <(_use_anti_tunneling) = [1]> then\n            set [_t v] to (((((_x) - (_b_x_old)) * (_px)) + ((((_y) - (_b_y_old)) * (_py)) + (((_z) - (_b_z_old)) * (_pz)))) / (_squared_dist))\n            set [_t v] to (((((_t) * <(_t) > [0]>) * <(_t) < [1]>) + <not <(_t) < [1]>>) - ((0.01) * <(_t) > [0.01]>))\n            set [_x2 v] to ((_b_x_old) + ((_px) * (_t)))\n            set [_y2 v] to ((_b_y_old) + ((_py) * (_t)))\n            set [_z2 v] to ((_b_z_old) + ((_pz) * (_t)))\n            set [_tmp v] to <([sqrt v] of ((((_x2) - (_x)) * ((_x2) - (_x))) + ((((_y2) - (_y)) * ((_y2) - (_y))) + (((_z2) - (_z)) * ((_z2) - (_z))))) ) < ((@player_r) + (item ((_tmp) + (3)) of [bsphere_world v]))>\n        else\n            set [_tmp v] to <([sqrt v] of ((((@player_x) - (_x)) * ((@player_x) - (_x))) + ((((@player_y) - (_y)) * ((@player_y) - (_y))) + (((@player_z) - (_z)) * ((@player_z) - (_z))))) ) < ((@player_r) + (item ((_tmp) + (3)) of [bsphere_world v]))>\n        end\n        if <(_tmp) = [1]> then\n            set [j v] to (item ((_*obj) + (@enum o:**PLEFT)) of [gameobjects v])\n            set [_tmp v] to (item ((_*obj) + ((@enum o:**PLEFT) + (1))) of [gameobjects v])\n            repeat until <<(j) = (_tmp)> or <(j) = [null]>>\n                set [_*prim v] to (item (j) of [gameobjects._*prims v])\n                if <<not <(item ((_*prim) + (@enum p:NORMAL)) of [primitives v]) = [null]>> and <(item ((item ((_*prim) + (@enum p:MATERIAL)) of [primitives v]) + (6)) of [materials v]) = [0]>> then\n                    add (_*prim) to [_collision_candidates_*prims v]\n                end\n                set [j v] to (item ((j) + (1)) of [gameobjects._*prims v])\n            end\n        end\n    end\n    change [_*obj v] by (@enum o:SIZE)\nend\n\ndefine prim level collision check\nset [_min_toi_val v] to ((1) / (0))\nset [_candidate_idx v] to [1]\nrepeat (length of [_collision_candidates_*prims v])\n    set [_*prim v] to (item (_candidate_idx) of [_collision_candidates_*prims v])\n    set [_tmp v] to (item ((_*prim) + (@enum p:*BSPHERE)) of [primitives v])\n    if <(_use_anti_tunneling) = [1]> then\n        if <(item (_*prim) of [primitives v]) = [POLYGON]> then\n            set [_tmp2 v] to (item (item ((_*prim) + (1)) of [primitives v]) of [idxs_poly v])\n        else\n            set [_tmp2 v] to (item ((_*prim) + (1)) of [primitives v])\n        end\n        set [_tmp3 v] to (item ((_*prim) + (@enum p:NORMAL)) of [primitives v])\n        set [_nx v] to (item (_tmp3) of [normal_world v])\n        set [_ny v] to (item ((_tmp3) + (1)) of [normal_world v])\n        set [_nz v] to (item ((_tmp3) + (2)) of [normal_world v])\n        set [_t v] to (((((item (_tmp2) of [vertex_world v]) - (_b_x_old)) * (_Nx)) + ((((item ((_tmp2) + (1)) of [vertex_world v]) - (_b_y_old)) * (_Ny)) + (((item ((_tmp2) + (2)) of [vertex_world v]) - (_b_z_old)) * (_Nz)))) / (((_Nx) * ((@player_x) - (_b_x_old))) + (((_Ny) * ((@player_y) - (_b_y_old))) + ((_Nz) * ((@player_z) - (_b_z_old))))))\n        set [_t v] to (((((_t) * <(_t) > [0]>) * <(_t) < [1]>) + <not <(_t) < [1]>>) - ((0.01) * <(_t) > [0.01]>))\n        set [_prev_len v] to (length of [_collision v])\n        sphere-bounded polygon test ( sphere ((_b_x_old) + (((@player_x) - (_b_x_old)) * (_t))) ((_b_y_old) + (((@player_y) - (_b_y_old)) * (_t))) ((_b_z_old) + (((@player_z) - (_b_z_old)) * (_t))) (@player_r) poly bounding-sphere (item (_tmp) of [bsphere_world v]) (item ((_tmp) + (1)) of [bsphere_world v]) (item ((_tmp) + (2)) of [bsphere_world v]) (item ((_tmp) + (3)) of [bsphere_world v]) )\n    else\n        sphere-bounded polygon test ( sphere (@player_x) (@player_y) (@player_z) (@player_r) poly bounding-sphere (item (_tmp) of [bsphere_world v]) (item ((_tmp) + (1)) of [bsphere_world v]) (item ((_tmp) + (2)) of [bsphere_world v]) (item ((_tmp) + (3)) of [bsphere_world v]) )\n    end\n    change [_candidate_idx v] by (1)\nend\nif <<((@player_y) - (@player_r)) < (@ground_y)> and <(@ground_plane?) = [1]>> then\n    set [_*prim v] to [ground]\n    Add collision and pos. correction if min TOI (A= Closest pt polygon, B= closest pt sphere: Ax-Bx [0] Ay-By ((@ground_y) - ((@player_y) - (@player_r))) Az-Bz [0] sphere Centre: (@player_x) (@player_y) (@player_z) )\nend\n\n@Logic\n\ndefine Controllers.targetGameObjWithOffset ( object name (object name) offset (tx) (ty) (tz) interpolate movement? <lerp?>\nset [_*obj v] to (item # of (object name) in [gameobjects v])\nif <not <(_*obj) = [0]>> then\n    set [_tmp v] to [0.4]\n    set_inv_rot_matrix ( ([cos v] of (@C_roll) ) ([sin v] of (@C_roll) ) ([cos v] of (@C_pitch) ) ([sin v] of (@C_pitch) ) ([cos v] of (@C_yaw) ) ([sin v] of (@C_yaw) ) )\n    _x, _y, z = apply_rot_matrix ( (tx) (ty) (tz) )\n    set [@camx v] to (((@camX) * ((1) - (_tmp))) + (((item ((_*obj) + (1)) of [gameobjects v]) + (_x)) * (_tmp)))\n    set [@camy v] to (((@camY) * ((1) - (_tmp))) + (((item ((_*obj) + (2)) of [gameobjects v]) + (_y)) * (_tmp)))\n    set [@camz v] to (((@camZ) * ((1) - (_tmp))) + (((item ((_*obj) + (3)) of [gameobjects v]) + (_z)) * (_tmp)))\nend\n\nwhen flag clicked\nreset timer\ndelete all of [_mouse_pos v]\nrepeat (2)\n    add [0] to [_mouse_pos v]\nend\nhide\nset [_w_xrot v] to [0]\nset [_w_yrot v] to [0]\nset [_rot_velx v] to [0]\nset [_rot_vely v] to [0]\nset [_rot_velz v] to [0]\nset [_velyaw v] to [0]\nset [_velpitch v] to [0]\nset [_sound_start_time v] to [0]\nset [_current_sound_duration v] to [0]\nset [@splashscreenvisible? v] to [1]\nset [_prev_shadows? v] to (@shadows?)\nset [_time_mouse_down v] to (days since 2000)\nset [_button_activated v] to [0]\nset [_jump? v] to [0]\nset volume to (80) %\nstart sound [Splash intro v]\n\nwhen I receive [game logic v]\nlogic\n\ndefine Play Logic\nControllers.playerController ( speed [1] jump height [1.6] glide/walk mode \nif <key (r v) pressed?> then\n    reset player\nend\nif <(_has_started?) = [0]> then\n    if <(([abs v] of (item (1) of [@player_forces_controlled v]) ) + (([abs v] of (item (2) of [@player_forces_controlled v]) ) + ([abs v] of (item (3) of [@player_forces_controlled v]) ))) > [0]> then\n        set [_has_started? v] to [1]\n        set [_start_time v] to (days since 2000)\n    end\nend\nif <key (any v) pressed?> then\n    set [@mobile_controls v] to [0]\nend\n\ndefine GameObjects.transform ( object name (obj) translate (x) (y) (z) rotate (α) (β) (γ) )\nif <not <[gameobjects v] contains (obj)?>> then\n    stop [this script v]\nend\nset [_*obj v] to (item # of (obj) in [gameobjects v])\nGameObjects.set_updated ( (_*obj) )\nreplace item ((_*obj) + (1)) of [gameobjects v] with ((item ((_*obj) + (1)) of [gameobjects v]) + (x))\nreplace item ((_*obj) + (2)) of [gameobjects v] with ((item ((_*obj) + (2)) of [gameobjects v]) + (y))\nreplace item ((_*obj) + (3)) of [gameobjects v] with ((item ((_*obj) + (3)) of [gameobjects v]) + (z))\nreplace item ((_*obj) + (4)) of [gameobjects v] with (((item ((_*obj) + (4)) of [gameobjects v]) + (α)) mod (360))\nreplace item ((_*obj) + (5)) of [gameobjects v] with (((item ((_*obj) + (5)) of [gameobjects v]) + (β)) mod (360))\nreplace item ((_*obj) + (6)) of [gameobjects v] with (((item ((_*obj) + (6)) of [gameobjects v]) + (γ)) mod (360))\n\ndefine start timing (timing label)\nif <[timings v] contains (timing label)?> then\n    set [_tmp v] to (item # of (timing label) in [timings v])\n    replace item ((_tmp) + (1)) of [timings v] with (days since 2000)\n    replace item ((_tmp) + (2)) of [timings v] with ((item ((_tmp) + (2)) of [timings v]) + (1))\nelse\n    add (timing label) to [timings v]\n    add (days since 2000) to [timings v]\n    add [0] to [timings v]\n    add [0] to [timings v]\nend\nif <(timer) = [5]> then\n    delete all of [timings v]\nend\n\ndefine end timing (timing label)\nset [_tmp v] to (days since 2000)\nset [_tmp2 v] to (item # of (timing label) in [timings v])\nreplace item ((_tmp2) + (3)) of [timings v] with ((((86400) * ((_tmp) - (item ((_tmp2) + (1)) of [timings v]))) - ((3.71) / (1000000))) + (item ((_tmp2) + (3)) of [timings v]))\n\ndefine _tmp = atan2 (y) (x)\nset [_tmp v] to (([atan v] of ((y) / (x)) ) + ((180) * <(x) < [0]>))\n\ndefine set_inv_rot_matrix ( (cos γ) (sin γ) (cos β) (sin β) (cos α) (sin α) )\nset [_rm1 v] to (((cos α) * (cos γ)) - ((sin α) * ((sin β) * (sin γ))))\nset [_rm2 v] to ((((sin α) * (sin β)) * (cos γ)) + ((cos α) * (sin γ)))\nset [_rm3 v] to ((-1) * ((cos β) * (sin α)))\nset [_rm4 v] to ((-1) * ((cos β) * (sin γ)))\nset [_rm5 v] to ((cos β) * (cos γ))\nset [_rm6 v] to (sin β)\nset [_rm7 v] to ((((cos α) * (sin β)) * (sin γ)) + ((sin α) * (cos γ)))\nset [_rm8 v] to (((sin α) * (sin γ)) - ((cos α) * ((sin β) * (cos γ))))\nset [_rm9 v] to ((cos α) * (cos β))\n\ndefine _x, _y, z = apply_rot_matrix ( (x) (y) (z) )\nset [_x v] to ((((x) * (_rm1)) + ((y) * (_rm2))) + ((z) * (_rm3)))\nset [_y v] to (((x) * (_rm4)) + (((y) * (_rm5)) + ((z) * (_rm6))))\nset [_z v] to (((x) * (_rm7)) + (((y) * (_rm8)) + ((z) * (_rm9))))\n\ndefine Edit logic\nControllers.freeLook ()\n\ndefine Controllers.freeLook ()\nset [_rot_velx v] to ((_rot_velX) * (0.6))\nset [_rot_vely v] to ((_rot_velY) * (0.6))\nset [_rot_velz v] to ((_rot_velZ) * (0.6))\nset [_dx v] to ((<key (d v) pressed?> - <key (a v) pressed?>) * (0.1))\nset [_dy v] to ((<key (e v) pressed?> - <key (q v) pressed?>) * (0.1))\nset [_dz v] to ((<key (w v) pressed?> - <key (s v) pressed?>) * (0.1))\n_dx, _dy, _dz = Controllers.xyz movement in cam direction ( (_dx) (_dy) (_dz) )\nchange [_rot_velx v] by (_dx)\nchange [_rot_vely v] by (_dy)\nchange [_rot_velz v] by (_dz)\nControllers.camera_rotation()\nchange [@camx v] by (_rot_velX)\nchange [@camy v] by (_rot_velY)\nchange [@camz v] by (_rot_velZ)\nset [@player_x v] to (@camX)\nset [@player_y v] to (@camY)\nset [@player_z v] to (@camZ)\n\ndefine logic\nstart timing [Logic]\nif <<<mouse down?> and <([_prev_mouse_down? v] of [gui v]) = [0]>> and <(_using_joystick?) = [0]>> then\n    replace item (1) of [_mouse_pos v] with (mouse x)\n    replace item (2) of [_mouse_pos v] with (mouse y)\nend\nif <not <(_prev_shadows?) = (@shadows?)>> then\n    if <(@shadows?) = [1]> then\n        broadcast (generate shadows v)\n    else\n        broadcast (destroy shadows v)\n    end\nend\nif <(@splashScreenVisible?) = [1]> then\n    if <<(timer) > [3]> or <<(@rendering_active?) = [1]> and <mouse down?>>> then\n        set [@splashscreenvisible? v] to [0]\n        stop all sounds\n        if <(@edit_mode?) = [0]> then\n            broadcast (start game v)\n        end\n    end\nend\ndelete all of [interactions v]\ndelete all of [@updated_objects v]\ndelete all of [@updated_objects_prev_ori v]\nif <(@edit_mode?) = [1]> then\n    if <<key (p v) pressed?> and <not <[_prev_keys_down v] contains [p]?>>> then\n        set [@edit_mode? v] to [0]\n        broadcast (start game v)\n    else\n        Edit logic\n    end\nelse\n    if <<key (p v) pressed?> and <not <[_prev_keys_down v] contains [p]?>>> then\n        set [@edit_mode? v] to [1]\n        broadcast (stop music v)\n    else\n        Play Logic\n    end\nend\nPlay and Edit Logic\nif <[@updated_objects v] contains (@*player_obj)?> then\n    delete (item # of (@*player_obj) in [@updated_objects v]) of [@updated_objects v]\nend\nif <not <(@*player_obj) = [0]>> then\n    GameObjects.set_updated ( (@*player_obj) )\nend\nstore prev_frame keys down\nset [_prev_shadows? v] to (@shadows?)\nend timing [Logic]\n\ndefine GameObjects.setPosition ( object name (obj) position (x) (y) (z) )\nif <not <[gameobjects v] contains (obj)?>> then\n    stop [this script v]\nend\nset [_*obj v] to (item # of (obj) in [gameobjects v])\nset [_x v] to <<not <(x) = []>> and <not <(x) = (item ((_*obj) + (1)) of [gameobjects v])>>>\nset [_y v] to <<not <(y) = []>> and <not <(y) = (item ((_*obj) + (2)) of [gameobjects v])>>>\nset [_z v] to <<not <(z) = []>> and <not <(z) = (item ((_*obj) + (3)) of [gameobjects v])>>>\nif <<<(_x) = [1]> or <(_y) = [1]>> or <(_z) = [1]>> then\n    GameObjects.set_updated ( (_*obj) )\nend\nif <not <(x) = []>> then\n    replace item ((_*obj) + (1)) of [gameobjects v] with (x)\nend\nif <not <(y) = []>> then\n    replace item ((_*obj) + (2)) of [gameobjects v] with (y)\nend\nif <not <(z) = []>> then\n    replace item ((_*obj) + (3)) of [gameobjects v] with (z)\nend\n\ndefine GameObjects.setRotation ( object name (obj) rotation (yaw, pitch, roll) (α) (β) (γ) )\nif <not <[gameobjects v] contains (obj)?>> then\n    stop [this script v]\nend\nset [_*obj v] to (item # of (obj) in [gameobjects v])\nGameObjects.set_updated ( (_*obj) )\nif <not <(α) = []>> then\n    replace item ((_*obj) + (4)) of [gameobjects v] with (α)\nend\nif <not <(β) = []>> then\n    replace item ((_*obj) + (5)) of [gameobjects v] with (β)\nend\nif <not <(γ) = []>> then\n    replace item ((_*obj) + (6)) of [gameobjects v] with (γ)\nend\n\nwhen I receive [init gameobject transforms v]\nGameObjects.setup()\n\ndefine store prev_frame keys down\ndelete all of [_prev_keys_down v]\nset [i v] to [1]\nrepeat (length of [_keys v])\n    set [_tmp v] to (item (i) of [_keys v])\n    if <key ((_tmp) v) pressed?> then\n        add (_tmp) to [_prev_keys_down v]\n    end\n    change [i v] by (1)\nend\nif <mouse down?> then\n    add [mouse] to [_prev_keys_down v]\nend\n\ndefine Controllers.playerController ( speed (speed) jump height (jump height) glide/walk mode <glide/walk>\nControllers.camera_rotation()\nif <[gameobjects v] contains [Player]?> then\n    GameObjects.setPosition ( object name [Player] position (@player_x) (@player_y) (@player_z) )\n    Controllers.targetGameObjWithOffset ( object name [Player] offset [0] ((<(@first_person?) = [0]> * (0.4)) + (<(@first_person?) = [1]> * (0.6))) ((<(@first_person?) = [0]> * (@cam_z_offset)) + (<(@first_person?) = [1]> * (0))) interpolate movement? \nend\nif <(@mobile_controls) = [1]> then\n    Controllers.joystick_movement()\nend\nControllers.movementControls ( speed (speed) glide/walk mode? <glide/walk> jump height (jump height) )\nif <(@ground_force) > [0]> then\n    set [_start_height v] to (@player_y)\nend\nif <<not <(@*player_shadow_prim) = [0]>> and <not <(item ((@*player_shadow_prim) + (@enum p:SHAD_OFF_SCALE)) of [primitives v]) = []>>> then\n    replace item ((@*player_shadow_prim) + (@enum p:SHAD_OFF_SCALE)) of [primitives v] with (((([abs v] of ((@player_y) - (_start_height)) ) + (@player_r)) * <(@ground_force) = [0]>) + (((@player_r) * (1.2)) * <not <(@ground_force) = [0]>>))\n    replace item ((@*player_shadow_prim) + (@enum p:RADIUS)) of [primitives v] with ((((@player_r) * (((90) - ([atan v] of ((0.1) * ([abs v] of ((@player_y) - (_start_height)) )) )) / (90))) * <(@ground_force) = [0]>) + ((@player_r) * <not <(@ground_force) = [0]>>))\nend\nset [_prev_isgrounded? v] to (@ground_force)\n\ndefine _dx, _dy, _dz = Controllers.xyz movement in cam direction ( (x) (y) (z) )\nset [_dx v] to [0]\nset [_dy v] to [0]\nset [_dz v] to [0]\nset [_tmp v] to ((30) / (@fps))\nset_inv_rot_matrix ( ([cos v] of (@C_roll) ) ([sin v] of (@C_roll) ) ([cos v] of (@C_pitch) ) ([sin v] of (@C_pitch) ) ([cos v] of (@C_yaw) ) ([sin v] of (@C_yaw) ) )\n_x, _y, z = apply_rot_matrix ( (_tmp) [0] [0] )\nchange [_dx v] by ((x) * (_x))\nchange [_dy v] by ((x) * (_y))\nchange [_dz v] by ((x) * (_z))\n_x, _y, z = apply_rot_matrix ( [0] (_tmp) [0] )\nchange [_dx v] by ((y) * (_x))\nchange [_dy v] by ((y) * (_y))\nchange [_dz v] by ((y) * (_z))\n_x, _y, z = apply_rot_matrix ( [0] [0] ((-1) * (_tmp)) )\nchange [_dx v] by ((z) * (_x))\nchange [_dy v] by ((z) * (_y))\nchange [_dz v] by ((z) * (_z))\n\ndefine Controllers.camera_rotation()\nset [_tmp v] to ((30) / (@fps))\nset [_velyaw v] to ((_velYaw) * (0.6))\nset [_velpitch v] to ((_velPitch) * (0.6))\nif <<(_using_joystick?) = [0]> and <mouse down?>> then\n    set [_velyaw v] to ((_velYaw) * (0.9))\n    set [_velpitch v] to ((_velPitch) * (0.9))\n    change [_velyaw v] by ((((mouse x) - (item (1) of [_mouse_pos v])) / (80)) * (_tmp))\n    change [_velpitch v] by ((((mouse y) - (item (2) of [_mouse_pos v])) / (-80)) * (_tmp))\nelse\n    change [_velyaw v] by ((<key (right arrow v) pressed?> - <key (left arrow v) pressed?>) * ((1.2) * (_tmp)))\n    change [_velpitch v] by ((<key (down arrow v) pressed?> - <key (up arrow v) pressed?>) * ((1.2) * (_tmp)))\nend\nchange [@c_yaw v] by (_velYaw)\nchange [@c_pitch v] by (_velPitch)\nif <([abs v] of (@C_pitch) ) > [90]> then\n    set [@c_pitch v] to (((@C_pitch) / ([abs v] of (@C_pitch) )) * (90))\nend\n\ndefine _interacted = Interactions.checkInteractionBetweenObjects ( object 1 name (obj1) object 2 name (obj2) interaction distance (dist) label (label) add to Interactions list? <add_to_list?>\nif <<not <[gameobjects v] contains (obj1)?>> or <not <[gameobjects v] contains (obj2)?>>> then\n    stop [this script v]\nend\nset [_tmp v] to (item ((item # of (obj1) in [gameobjects v]) + (@enum o:*BSPHERE)) of [gameobjects v])\nset [_tmp2 v] to (item ((item # of (obj2) in [gameobjects v]) + (@enum o:*BSPHERE)) of [gameobjects v])\nset [_x v] to (item ((_tmp) + (0)) of [bsphere_world v])\nset [_y v] to (item ((_tmp) + (1)) of [bsphere_world v])\nset [_z v] to (item ((_tmp) + (2)) of [bsphere_world v])\nset [_x2 v] to (item ((_tmp2) + (0)) of [bsphere_world v])\nset [_y2 v] to (item ((_tmp2) + (1)) of [bsphere_world v])\nset [_z2 v] to (item ((_tmp2) + (2)) of [bsphere_world v])\nset [_dist v] to ([sqrt v] of ((((_x) - (_x2)) * ((_x) - (_x2))) + ((((_y) - (_y2)) * ((_y) - (_y2))) + (((_z) - (_z2)) * ((_z) - (_z2))))) )\nset [_interacted v] to [0]\nif <(dist) = []> then\n    if <(_dist) < ((item ((_tmp) + (3)) of [bsphere_world v]) + (item ((_tmp2) + (3)) of [bsphere_world v]))> then\n        if <add_to_list?> then\n            add (label) to [interactions v]\n            add (_dist) to [interactions v]\n        end\n        set [_interacted v] to [1]\n    end\nelse\n    if <(_dist) < (dist)> then\n        if <add_to_list?> then\n            add (label) to [interactions v]\n            add (_dist) to [interactions v]\n        end\n        set [_interacted v] to [1]\n    end\nend\n\ndefine GameState.new_state ( state label (lable) initial value (value) )\nadd (lable) to [gamestate v]\nadd (value) to [gamestate v]\n\ndefine GameObjects.setup()\nreset timer\n\ndefine Materials.setColour ( material name (mat) rgba (r) (g) (b) (a) )\nif <not <[materials v] contains (mat)?>> then\n    stop [this script v]\nend\nset [_tmp v] to (item # of (mat) in [materials v])\nset [_tmp2 v] to (item ((_tmp) + (4)) of [materials v])\nset [_a v] to ([floor v] of ((_tmp2) / (16777216)) )\nset [_tmp2 v] to ((_tmp2) mod (16777216))\nset [_r v] to ([floor v] of ((_tmp2) / (65536)) )\nset [_tmp2 v] to ((_tmp2) mod (65536))\nset [_g v] to ([floor v] of ((_tmp2) / (256)) )\nset [_b v] to ((_tmp2) mod (256))\nif <not <(a) = []>> then\n    set [_a v] to (a)\nend\nif <not <(r) = []>> then\n    set [_r v] to (r)\nend\nif <not <(g) = []>> then\n    set [_g v] to (g)\nend\nif <not <(b) = []>> then\n    set [_b v] to (b)\nend\nreplace item ((_tmp) + (4)) of [materials v] with (((round (_a)) * (16777216)) + (((round (_r)) * (65536)) + (((round (_g)) * (256)) + (round (_b)))))\nif <<(_r) > (_g)> and <(_r) > (_b)>> then\n    replace item ((_tmp) + (5)) of [materials v] with ((_r) / (255))\nelse\n    if <(_g) > (_b)> then\n        replace item ((_tmp) + (5)) of [materials v] with ((_g) / (255))\n    else\n        replace item ((_tmp) + (5)) of [materials v] with ((_b) / (255))\n    end\nend\n\ndefine _yaw, _pitch = euler angle from direction vector ( (dx) (dy) (dz) )\nset [_yaw v] to (((180) * <(dz) > [0]>) + ([atan v] of ((dx) / (dz)) ))\nset [_pitch v] to ([asin v] of ((dy) / ([sqrt v] of (((dx) * (dx)) + (((dy) * (dy)) + ((dz) * (dz)))) )) )\n\ndefine GameObjects.pointTowardsPosition ( object name (obj) Position (x) (y) (z) )\nif <not <[gameobjects v] contains (obj)?>> then\n    stop [this script v]\nend\nset [_*obj v] to (item # of (obj) in [gameobjects v])\n_yaw, _pitch = euler angle from direction vector ( ((x) - (item ((_*obj) + (1)) of [gameobjects v])) ((y) - (item ((_*obj) + (2)) of [gameobjects v])) ((z) - (item ((_*obj) + (3)) of [gameobjects v])) )\nGameObjects.setRotation ( object name (obj) rotation (yaw, pitch, roll) (_yaw) (_pitch) [0] )\n\ndefine GameObjects.pointTowardsObject ( object 1 name (obj1) object 2 name (obj2) )\nif <not <[gameobjects v] contains (obj2)?>> then\n    stop [this script v]\nend\nset [_*obj v] to (item # of (obj2) in [gameobjects v])\nGameObjects.pointTowardsPosition ( object name (obj1) Position (item ((_*obj) + (1)) of [gameobjects v]) (item ((_*obj) + (2)) of [gameobjects v]) (item ((_*obj) + (3)) of [gameobjects v]) )\n\ndefine GameObjects.move ( object name (obj) steps (steps) )\nif <not <[gameobjects v] contains (obj)?>> then\n    stop [this script v]\nend\nset [_*obj v] to (item # of (obj) in [gameobjects v])\n_dx, _dy, _dz = direction vector from euler angle ( (item ((_*obj) + (4)) of [gameobjects v]) (item ((_*obj) + (5)) of [gameobjects v]) )\nGameObjects.transform ( object name (obj) translate ((_dx) * (steps)) ((_dy) * (steps)) ((_dz) * (steps)) rotate [] [] [] )\n\ndefine _dx, _dy, _dz = direction vector from euler angle ( (yaw) (pitch) )\nset [_dx v] to ((-1) * (([cos v] of (pitch) ) * ([sin v] of (yaw) )))\nset [_dy v] to ([sin v] of (pitch) )\nset [_dz v] to ((-1) * (([cos v] of (yaw) ) * ([cos v] of (pitch) )))\n\ndefine _dist = GameObjects.distanceBetween ( object 1 (obj1) object 2 (obj2) )\nif <<not <[gameobjects v] contains (obj1)?>> or <not <[gameobjects v] contains (obj2)?>>> then\n    stop [this script v]\nend\nset [_*obj v] to (item # of (obj1) in [gameobjects v])\nset [_tmp v] to (item # of (obj2) in [gameobjects v])\nset [_x v] to ((item ((_*obj) + (1)) of [gameobjects v]) - (item ((_tmp) + (1)) of [gameobjects v]))\nset [_y v] to ((item ((_*obj) + (2)) of [gameobjects v]) - (item ((_tmp) + (2)) of [gameobjects v]))\nset [_z v] to ((item ((_*obj) + (3)) of [gameobjects v]) - (item ((_tmp) + (4)) of [gameobjects v]))\nset [_dist v] to ([sqrt v] of (((_x) * (_x)) + (((_y) * (_y)) + ((_z) * (_z)))) )\n\ndefine _x, _y, _z = GameObjects.getPosition ( object name (obj) )\nif <not <[gameobjects v] contains (obj)?>> then\n    stop [this script v]\nend\nset [_*obj v] to (item # of (obj) in [gameobjects v])\nset [_x v] to (item ((_*obj) + (1)) of [gameobjects v])\nset [_y v] to (item ((_*obj) + (2)) of [gameobjects v])\nset [_z v] to (item ((_*obj) + (3)) of [gameobjects v])\n\ndefine Play and Edit Logic\nset [_time v] to (round ((((days since 2000) - (_start_time)) * (86400)) * (10)))\nGameObjects.setPosition ( object name [Platform 3] position [0.6] ((3.6) + ((1.8) * ([cos v] of ((timer) * (50)) ))) ((-5.2) + ((-1.4) * ([sin v] of ((timer) * (50)) ))) )\nGameObjects.setRotation ( object name [Platform 5] rotation (yaw, pitch, roll) (([sin v] of ((timer) * (30)) ) * (90)) [] [] )\n_interacted = Interactions.checkInteractionBetweenObjects ( object 1 name [Player] object 2 name [Enemy] interaction distance [10] label [] add to Interactions list? <>\nif <(_interacted) = [1]> then\n    GameObjects.pointTowardsPosition ( object name [Enemy] Position (@player_x) [] (@player_z) )\n    GameObjects.setRotation ( object name [Enemy] rotation (yaw, pitch, roll) [] [0] [] )\n    if <<([abs v] of ((@player_x) - (0)) ) < [1.25]> and <([abs v] of ((@player_z) - (-20)) ) < [1.85]>> then\n        GameObjects.move ( object name [Enemy] steps ((0.04) * ([_delta_t v] of [physics v])) )\n    end\nend\n_touching? = Interactions.playerIsTouching? ( object name [Spike 1] label [hazard] )\n_touching? = Interactions.playerIsTouching? ( object name [Spike 2] label [hazard] )\n_touching? = Interactions.playerIsTouching? ( object name [Enemy] label [hazard] )\nif <<[interactions v] contains [hazard]?> or <<(@player_y) < ((@ground_y) + (1))> and <(@edit_mode?) = [0]>>> then\n    reset player\nend\n_touching? = Interactions.playerIsTouching? ( object name [End] label [] )\nif <<<(_touching?) = [1]> and <not <(has_won) = [1]>>> or <<key (9 v) pressed?> and <(username) = [Chrome_Cat]>>> then\n    set [has_won v] to [1]\n    start sound [win_sound v]\n    hide list [chromeengine tutorial link v]\n    set [time v] to (_time)\n    broadcast (SAVE TIME TO CLOUD v)\nend\n\nwhen I receive [start game v]\nstart sound [game begin v]\nset [@game_start_time v] to (days since 2000)\nset [@music_name v] to [1]\nbroadcast (start music v)\nGameObjects.setup()\nif <[gameobjects v] contains [Player]?> then\n    set [_tmp v] to (item # of [Player] in [gameobjects v])\n    set [@player_x v] to (item ((_tmp) + (1)) of [gameobjects v])\n    set [@player_y v] to (item ((_tmp) + (2)) of [gameobjects v])\n    set [@player_z v] to (item ((_tmp) + (3)) of [gameobjects v])\nend\n\ndefine _touching? = Interactions.playerIsTouching? ( object name (obj) label (label) )\nif <not <[gameobjects v] contains (obj)?>> then\n    stop [this script v]\nend\nif <<[@player forces v] contains (obj)?> or <[@player forces v] contains (join [t:] (obj))?>> then\n    add (label) to [interactions v]\n    add [touching] to [interactions v]\n    set [_touching? v] to [1]\nelse\n    set [_touching? v] to [0]\nend\n\ndefine GameObjects.setVisibility ( object name (obj) visible? <visible?> )\nif <not <[gameobjects v] contains (obj)?>> then\n    stop [this script v]\nend\nreplace item ((item # of (obj) in [gameobjects v]) + (@enum o:HIDDEN?)) of [gameobjects v] with <not <visible?>>\n\ndefine GameObjects.setScale ( object name (obj) scale xyz (sx) (sy) (sz) )\nif <not <[gameobjects v] contains (obj)?>> then\n    stop [this script v]\nend\nset [_*obj v] to (item # of (obj) in [gameobjects v])\nGameObjects.set_updated ( (_*obj) )\nif <not <(sx) = []>> then\n    replace item ((_*obj) + (7)) of [gameobjects v] with (sx)\nend\nif <not <(sy) = []>> then\n    replace item ((_*obj) + (8)) of [gameobjects v] with (sy)\nend\nif <not <(sz) = []>> then\n    replace item ((_*obj) + (9)) of [gameobjects v] with (sz)\nend\n\ndefine GameObjects.SetZeroVelocityUpdate ( object name (obj) )\nset [_*obj v] to (item # of (obj) in [gameobjects v])\nif <<not <[gameobjects v] contains (obj)?>> or <not <[@updated_objects_prev_ori v] contains (join [*obj:] (_*obj))?>>> then\n    stop [this script v]\nend\nset [_tmp v] to (item # of (join [*obj:] (_*obj)) in [@updated_objects_prev_ori v])\nreplace item ((_tmp) + (1)) of [@updated_objects_prev_ori v] with (item ((_*obj) + (1)) of [gameobjects v])\nreplace item ((_tmp) + (2)) of [@updated_objects_prev_ori v] with (item ((_*obj) + (2)) of [gameobjects v])\nreplace item ((_tmp) + (3)) of [@updated_objects_prev_ori v] with (item ((_*obj) + (3)) of [gameobjects v])\nreplace item ((_tmp) + (4)) of [@updated_objects_prev_ori v] with (item ((_*obj) + (4)) of [gameobjects v])\nreplace item ((_tmp) + (5)) of [@updated_objects_prev_ori v] with (item ((_*obj) + (5)) of [gameobjects v])\nreplace item ((_tmp) + (6)) of [@updated_objects_prev_ori v] with (item ((_*obj) + (6)) of [gameobjects v])\n\nwhen I receive [start edit v]\nbroadcast (stop music v)\n\ndefine start timing (timing label)\nif <[timings v] contains (timing label)?> then\n    set [_tmp v] to (item # of (timing label) in [timings v])\n    replace item ((_tmp) + (1)) of [timings v] with (days since 2000)\n    replace item ((_tmp) + (2)) of [timings v] with ((item ((_tmp) + (2)) of [timings v]) + (1))\nelse\n    add (timing label) to [timings v]\n    add (days since 2000) to [timings v]\n    add [0] to [timings v]\n    add [0] to [timings v]\nend\n\ndefine end timing (timing label)\nset [_tmp v] to (days since 2000)\nset [_tmp2 v] to (item # of (timing label) in [timings v])\nreplace item ((_tmp2) + (3)) of [timings v] with ((((86400) * ((_tmp) - (item ((_tmp2) + (1)) of [timings v]))) - ((3.71) / (1000000))) + (item ((_tmp2) + (3)) of [timings v]))\n\ndefine GameObjects.unset_updated( (*obj) )\nif <<<(*obj) > [0]> and <(*obj) < (length of [gameobjects v])>> and <[@updated_objects v] contains (*obj)?>> then\n    delete (item # of (*obj) in [@updated_objects v]) of [@updated_objects v]\n    set [_tmp v] to (item # of (join [*obj:] (*obj)) in [@updated_objects_prev_ori v])\n    repeat (8)\n        delete (_tmp) of [@updated_objects_prev_ori v]\n    end\nend\n\ndefine GameState.setup()\ndelete all of [gamestate v]\n\nwhen flag clicked\nswitch costume to (thumbnail v)\nset [has_won v] to [0]\nshow list [chromeengine tutorial link v]\nset [_has_started? v] to [0]\nset [state:@game_won v] to []\nset [_using_joystick? v] to [0]\n\ndefine Controllers.movementControls ( speed (speed) glide/walk mode? <glide/walk> jump height (jump height) )\nset [_dy v] to [0]\nif <(_using_joystick?) = [1]> then\n    set [_dx v] to (((mouse x) - (item (1) of [_mouse_pos v])) / (40))\n    set [_dz v] to (((mouse y) - (item (2) of [_mouse_pos v])) / (40))\nelse\n    set [_dx v] to (<key (d v) pressed?> - <key (a v) pressed?>)\n    set [_dz v] to (<key (w v) pressed?> - <key (s v) pressed?>)\nend\nif <([abs v] of (@C_pitch) ) = [90]> then\n    _dx, _dy, _dz = Controllers.xyz movement in cam direction ( (_dx) (_dz) (_dy) )\nelse\n    _dx, _dy, _dz = Controllers.xyz movement in cam direction ( (_dx) (_dy) (_dz) )\nend\nset [_dy v] to [0]\nif <<(@mobile_controls) = [0]> or <([sqrt v] of (((_dx) * (_dx)) + ((_dz) * (_dz))) ) > [1]>> then\n    set [_tmp v] to ((1) / ([sqrt v] of (((_dx) * (_dx)) + ((_dz) * (_dz))) ))\n    set [_dx v] to ((_dx) * (_tmp))\n    set [_dz v] to ((_dz) * (_tmp))\nend\nset [_dx v] to ((_dx) * ((speed) * ((1) / (190))))\nset [_dz v] to ((_dz) * ((speed) * ((1) / (190))))\nset [_dy v] to ((([atan v] of (@ground_force) ) / (45)) * ((jump height) * (((@gravity) * (-12.5)) * <<key (space v) pressed?> or <(_jump?) = [1]>>)))\ndelete all of [@player_forces_controlled v]\nadd [controller] to [@player forces v]\nadd [] to [@player forces v]\nif <glide/walk> then\n    add [0] to [@player forces v]\n    add (_dy) to [@player forces v]\n    add [0] to [@player forces v]\n    add ((_dx) * (7)) to [@player_forces_controlled v]\n    add [0] to [@player_forces_controlled v]\n    add ((_dz) * (7)) to [@player_forces_controlled v]\nelse\n    add ((_dx) * (_tmp)) to [@player forces v]\n    add (_dy) to [@player forces v]\n    add ((_dz) * (_tmp)) to [@player forces v]\n    add [0] to [@player_forces_controlled v]\n    add [0] to [@player_forces_controlled v]\n    add [0] to [@player_forces_controlled v]\nend\nif <<glide/walk> and <<<not <(@ground_force) = [0]>> and <(((days since 2000) * (86400)) - (_sound_start_time)) > [0.3]>> and <<<not <(_dx) = [0]>> or <not <(_dy) = [0]>>> or <<not <(_dz) = [0]>> or <<(@ground_force) = [1]> and <(_prev_isGrounded?) = [0]>>>>>> then\n    if <(@ground_force_label) = [ground]> then\n        set [_tmp v] to [Grass Step]\n    else\n        set [_tmp v] to (@ground_force_label)\n        if < (@ground_force_label) contains [t:]?> then\n            set [_tmp v] to (join (letter (3) of (_tmp)) (join (letter (4) of (_tmp)) (join (letter (5) of (_tmp)) (join (letter (6) of (_tmp)) (letter (7) of (_tmp))))))\n        end\n        set [_tmp v] to (item ((item ((_tmp) + (@enum p:MATERIAL)) of [primitives v]) + (2)) of [materials v])\n    end\n    start sound (join (_tmp) (join [ ] (pick random (1) to (4))))\n    set [_sound_start_time v] to ((days since 2000) * (86400))\nend\n\ndefine Controllers.joystick_movement()\nset [ghost v] effect to (0)\nswitch costume to (big v)\nif <<mouse down?> and <(_using_joystick?) = [1]>> then\n    go to x: (item (1) of [_mouse_pos v]) y: (item (2) of [_mouse_pos v])\nelse\n    go to x: (-160) y: (-105)\nend\nset size to (35) %\nswitch costume to (joystick outer v)\nstamp\nswitch costume to (joystick inner v)\nif <(_using_joystick?) = [1]> then\n    if <mouse down?> then\n        point towards (mouse-pointer v)\n        move ((<(distance to [mouse-pointer v]) > [33]> * (33)) + (<not <(distance to [mouse-pointer v]) > [33]>> * (distance to [mouse-pointer v]))) steps\n    else\n        set [_using_joystick? v] to [0]\n    end\nend\nif <<<(_using_joystick?) = [0]> and <mouse down?>> and <touching (mouse-pointer v)?>> then\n    set [_using_joystick? v] to [1]\nend\nstamp\ngo to x: (165) y: (-112)\npoint in direction (90)\nset size to (75) %\nset [ghost v] effect to (60)\nswitch costume to (jump button v)\nif <<mouse down?> and <touching (mouse-pointer v)?>> then\n    switch costume to (jump button2 v)\n    set [_jump? v] to [1]\nelse\n    set [_jump? v] to [0]\nend\nstamp\nswitch costume to (thumbnail v)\n\ndefine reset player\nshow list [chromeengine tutorial link v]\nset [@player_x v] to [0]\nset [@player_y v] to [1]\nset [@player_z v] to [0]\nset [_has_started? v] to [0]\nset [has_won v] to [0]\nstart sound [death_sound v]\nreset timer\n\ndefine GameObjects.set_updated ( (*obj) )\nif <<<(*obj) > [0]> and <(*obj) < (length of [gameobjects v])>> and <not <[@updated_objects v] contains (*obj)?>>> then\n    add (*obj) to [@updated_objects v]\n    add (join [*obj:] (*obj)) to [@updated_objects_prev_ori v]\n    add (item ((*obj) + (1)) of [gameobjects v]) to [@updated_objects_prev_ori v]\n    add (item ((*obj) + (2)) of [gameobjects v]) to [@updated_objects_prev_ori v]\n    add (item ((*obj) + (3)) of [gameobjects v]) to [@updated_objects_prev_ori v]\n    add (item ((*obj) + (4)) of [gameobjects v]) to [@updated_objects_prev_ori v]\n    add (item ((*obj) + (5)) of [gameobjects v]) to [@updated_objects_prev_ori v]\n    add (item ((*obj) + (6)) of [gameobjects v]) to [@updated_objects_prev_ori v]\nend\n\ndefine Materials.SetTexture ( mat (mat) texture costume name/# (tex) )\nif <[materials v] contains (mat)?> then\n    replace item ((item # of (mat) in [materials v]) + (3)) of [materials v] with (tex)\nend\n\ndefine GameState.toggle_boolean_state ( state label (label) )\n_tmp = GameState.get_value ( state label (label) )\nGameState.set ( state label (label) state value <(_tmp) = [0]> )\n\ndefine GameState.set ( state label (label) state value (value) )\nif <[gamestate v] contains (label)?> then\n    replace item ((item # of (label) in [gamestate v]) + (1)) of [gamestate v] with (value)\nend\n\ndefine _tmp = GameState.get_value ( state label (label) )\nset [_tmp v] to (item ((item # of (label) in [gamestate v]) + (1)) of [gamestate v])\n\n@GUI\n\nwhen flag clicked\nclear graphic effects\nhide\nswitch costume to (trophy v)\nset [_prev_mouse_down? v] to [0]\n\nwhen I receive [gui v]\ngui_main()\n\ndefine gui_main()\nshow\nif <not <(@splashScreenVisible?) = [1]>> then\n    Game GUI\nend\nengine_GUI ()\nset [_prev_mouse_down? v] to <mouse down?>\nswitch costume to (gui thumbnail v)\nhide\n\ndefine GUI.scaleOnTouch ( scale factor (scale factor) )\nif <touching (mouse-pointer v)?> then\n    set size to ((scale factor) * (size)) %\nelse\n    set size to (size) %\nend\n\ndefine GUI.reset\nset size to (100) %\ngo to x: (0) y: (0)\nclear graphic effects\n\ndefine GUI.BroadcastOnClick ( message label (message label) )\nif <<<touching (mouse-pointer v)?> and <mouse down?>> and <not <(_prev_mouse_down?) = [1]>>> then\n    broadcast (message label)\nend\n\ndefine engine_GUI ()\nGUI.reset\npoint in direction (90)\nif <(@splashScreenVisible?) = [1]> then\n    go to x: (0) y: (0)\n    set size to (100) %\n    switch costume to (splash screen bg v)\n    stamp\n    set [ghost v] effect to (((1) - ((timer) * (2))) * (100))\n    switch costume to (splash screen fg v)\n    stamp\n    set [ghost v] effect to (0)\n    go to x: (40) y: (-126)\n    switch costume to (join [loading] ((([floor v] of ((timer) * (30)) ) mod (16)) + (1)))\n    set size to (50) %\n    stamp\nelse\n    switch costume to (gui bg v)\n    stamp\n    set size to (130) %\n    if <(@edit_mode?) = [1]> then\n        switch costume to (play v)\n    else\n        switch costume to (stop v)\n    end\n    go to x: (-212) y: (-167)\n    GUI.scaleOnTouch ( scale factor [1.3] )\n    if <<<touching (mouse-pointer v)?> and <mouse down?>> and <not <(_prev_mouse_down?) = [1]>>> then\n        start sound [pop v]\n        if <(@edit_mode?) = [1]> then\n            broadcast (start game v)\n        else\n            broadcast (start edit v)\n        end\n        set [@edit_mode? v] to <(@edit_mode?) = [0]>\n    end\n    stamp\n    change x by (25)\n    set size to (130) %\n    switch costume to (settings v)\n    GUI.scaleOnTouch ( scale factor [1.3] )\n    GUI.BroadcastOnClick ( message label [toggle settings] )\n    stamp\n    change x by (25)\n    set size to (130) %\n    switch costume to (trophy v)\n    GUI.scaleOnTouch ( scale factor [1.3] )\n    GUI.BroadcastOnClick ( message label [toggle leaderboard] )\n    stamp\nend\nGUI.reset\n\ndefine GUI.set/toggleStateOnClick ( (state label) (state value) <toggle?> )\nif <<<touching (mouse-pointer v)?> and <mouse down?>> and <not <(_prev_mouse_down?) = [1]>>> then\n    if <toggle?> then\n        GameState.toggle_boolean_state ( state label (state label) )\n    else\n        if <not <(state label) = []>> then\n            GameState.set ( state label (state label) state value (state value) )\n        end\n    end\nend\n\ndefine GUI.playSoundOnClick ( sound label (sound) )\nif <<<touching (mouse-pointer v)?> and <mouse down?>> and <not <(_prev_mouse_down?) = [1]>>> then\n    start sound (sound)\nend\n\ndefine Game GUI\nif <(has_won) = [1]> then\n    set size to (100) %\n    go to x: (0) y: (0)\n    if <(STATE:@game_won) = [WORLD RECORD]> then\n        switch costume to (world record v)\n    else\n        switch costume to (win screen v)\n    end\n    stamp\nend\nif <<(has_won) = [0]> and <([_has_started? v] of [logic v]) = [1]>> then\n    set [_tmp v] to (([_time v] of [logic v]) / (10))\n    repeat ((3) - (length of ([floor v] of (_tmp) )))\n        set [_tmp v] to (join [0] (_tmp))\n    end\n    if <(_tmp) = ([floor v] of (_tmp) )> then\n        set [_tmp v] to (join (_tmp) [.0])\n    end\n    GUI.write_number ( value (_tmp) pos [150] [155] size [20] )\nend\n\ndefine GUI.write_number ( value (value) pos (x) (y) size (size) )\ngo to x: (x) y: (y)\nset size to (((size) / (42)) * (100)) %\nset [_tmp v] to [1]\nset [_tmp2 v] to ((size) * (1.15))\nrepeat (length of (value))\n    if <(letter (_tmp) of (value)) = [.]> then\n        switch costume to (splash screen bg v)\n        set size to (((size) / (42)) * (40)) %\n        change y by ((-0.4) * (size))\n        set [_tmp2 v] to ((size) * (0.45))\n    end\n    switch costume to (join [char_] (letter (_tmp) of (value)))\n    stamp\n    change x by (_tmp2)\n    change [_tmp v] by (1)\nend\n\ndefine _tmp = GameState.get_value ( state label (label) )\nset [_tmp v] to (item ((item # of (label) in [gamestate v]) + (1)) of [gamestate v])\n\ndefine GameState.set ( state label (label) state value (value) )\nif <[gamestate v] contains (label)?> then\n    replace item ((item # of (label) in [gamestate v]) + (1)) of [gamestate v] with (value)\nend\n\ndefine GameState.toggle_boolean_state ( state label (label) )\n_tmp = GameState.get_value ( state label (label) )\nGameState.set ( state label (label) state value <(_tmp) = [0]> )\n\n@Timing\n\nwhen flag clicked\nhide\ndelete all of [timings v]\nshow list [timing report v]\ngo to x: (178) y: (156)\nset size to (100) %\nswitch costume to (timer v)\n\ndefine get percentage times\nhide list [timing report v]\nset [i v] to [0]\nset [_total real time v] to [0]\nrepeat ((length of [timings v]) / (4))\n    change [_total real time v] by (item (((i) * (4)) + (4)) of [timings v])\n    change [i v] by (1)\nend\ndelete all of [timing report v]\nset [i v] to [1]\nrepeat ((length of [timings v]) / (4))\n    set [_tmp v] to (([floor v] of (((item ((i) + (3)) of [timings v]) / (item ((i) + (2)) of [timings v])) * ([10 ^ v] of (5) )) ) / ([10 ^ v] of (2) ))\n    set [_tmp v] to (join (_tmp) (join [ms  ] (join (round (((item ((i) + (3)) of [timings v]) / (_total real time)) * (100))) [%])))\n    add (join (item (i) of [timings v]) (join [:  ] (_tmp))) to [timing report v]\n    change [i v] by (4)\nend\n\nwhen [t v] key pressed\nget percentage times\n\ndefine end timing (timing label)\nset [_tmp v] to (days since 2000)\nset [_tmp2 v] to (item # of (timing label) in [timings v])\nreplace item ((_tmp2) + (3)) of [timings v] with ((((86400) * ((_tmp) - (item ((_tmp2) + (1)) of [timings v]))) - ((3.71) / (1000000))) + (item ((_tmp2) + (3)) of [timings v]))\n\ndefine start timing (timing label)\nif <[timings v] contains (timing label)?> then\n    set [_tmp v] to (item # of (timing label) in [timings v])\n    replace item ((_tmp) + (1)) of [timings v] with (days since 2000)\n    replace item ((_tmp) + (2)) of [timings v] with ((item ((_tmp) + (2)) of [timings v]) + (1))\nelse\n    add (timing label) to [timings v]\n    add (days since 2000) to [timings v]\n    add [0] to [timings v]\n    add [0] to [timings v]\nend\nif <(timer) = [5]> then\n    delete all of [timings v]\nend\n\n@Cloud List\n\ndefine write (val) to encoded\nset [letter # v] to [1]\nrepeat (length of (val))\n    set [c v] to (letter (letter #) of (val))\n    switch costume to (join (c) [_])\n    set [c v] to (item # of (c) in [codes v])\n    if <(costume [name v]) = [lower]> then\n        set [encoded v] to (join (encoded) (c))\n    else\n        set [encoded v] to (join (encoded) ((c) + (26)))\n        switch costume to (lower v)\n    end\n    change [letter # v] by (1)\nend\nset [encoded v] to (join (encoded) [00])\n\ndefine value = read from encoded\nset [value v] to []\nforever\n    set [idx v] to (join (letter (letter #) of (encoded)) (letter ((letter #) + (1)) of (encoded)))\n    change [letter # v] by (2)\n    if <(idx) < [1]> then\n        stop [this script v]\n    end\n    set [value v] to (join (value) (item (idx) of [codes v]))\nend\n\ndefine Begin Encode/Decode (encoded)\nset [encoded v] to (encoded)\nset [letter # v] to [1]\n\nwhen flag clicked\nswitch costume to (lower v)\nhide\n\nwhen I receive [cloud list - save v]\nhide\nSave\nshow\nwrite to cloud [0.1]\nhide\n\ndefine write number (val) to encoded\nset [encoded v] to (join (encoded) (join (length of (val)) (val)))\n\nwhen I receive [cloud list - load v]\nLoad\n\ndefine Save\nBegin Encode/Decode []\nset [cvar id v] to [1]\nrepeat ((length of [cloud list v]) / (2))\n    write (item (cvar id) of [cloud list v]) to encoded\n    change [cvar id v] by (1)\n    write number (item (cvar id) of [cloud list v]) to encoded\n    change [cvar id v] by (1)\nend\nset [idx v] to [1]\ndelete all of [cloud out v]\nset [c v] to []\nrepeat (length of (encoded))\n    set [c v] to (join (c) (letter (idx) of (encoded)))\n    change [idx v] by (1)\n    if <(length of (c)) > [255]> then\n        add (c) to [cloud out v]\n        set [c v] to []\n    end\nend\nif <(length of (c)) > [0]> then\n    add (c) to [cloud out v]\nend\n\ndefine write to cloud (wait)\nset [☁ cloud lock v] to (lock id)\nwait (wait) seconds\nif <not <(join [a] (☁ cloud list 1)) = (join [a] (item (1) of [cloud out v]))>> then\n    set [☁ cloud list 1 v] to (item (1) of [cloud out v])\n    wait (wait) seconds\nend\nif <not <(join [a] (☁ cloud list 2)) = (join [a] (item (2) of [cloud out v]))>> then\n    set [☁ cloud list 2 v] to (item (2) of [cloud out v])\n    wait (wait) seconds\nend\nif <not <(join [a] (☁ cloud list 3)) = (join [a] (item (3) of [cloud out v]))>> then\n    set [☁ cloud list 3 v] to (item (3) of [cloud out v])\n    wait (wait) seconds\nend\nif <not <(join [a] (☁ cloud list 4)) = (join [a] (item (4) of [cloud out v]))>> then\n    set [☁ cloud list 4 v] to (item (4) of [cloud out v])\n    wait (wait) seconds\nend\nif <not <(join [a] (☁ cloud list 5)) = (join [a] (item (5) of [cloud out v]))>> then\n    set [☁ cloud list 5 v] to (item (5) of [cloud out v])\n    wait (wait) seconds\nend\nif <not <(join [a] (☁ cloud list 6)) = (join [a] (item (6) of [cloud out v]))>> then\n    set [☁ cloud list 6 v] to (item (6) of [cloud out v])\n    wait (wait) seconds\nend\nif <not <(join [a] (☁ cloud list 7)) = (join [a] (item (7) of [cloud out v]))>> then\n    set [☁ cloud list 7 v] to (item (7) of [cloud out v])\n    wait (wait) seconds\nend\n\ndefine value = read number from encoded\nset [value v] to []\nset [idx v] to (letter (letter #) of (encoded))\nif <(idx) = []> then\n    stop [this script v]\nend\nchange [letter # v] by (1)\nrepeat (idx)\n    set [value v] to (join (value) (letter (letter #) of (encoded)))\n    change [letter # v] by (1)\nend\n\ndefine Load\ndelete all of [cloud list v]\nset [encoded v] to (☁ cloud list 1)\nset [encoded v] to (join (encoded) (☁ cloud list 2))\nset [encoded v] to (join (encoded) (☁ cloud list 3))\nset [encoded v] to (join (encoded) (☁ cloud list 4))\nset [encoded v] to (join (encoded) (☁ cloud list 5))\nset [encoded v] to (join (encoded) (☁ cloud list 6))\nset [encoded v] to (join (encoded) (☁ cloud list 7))\nBegin Encode/Decode (encoded)\nrepeat until <(letter #) > (length of (encoded))>\n    value = read from encoded\n    add (value) to [cloud list v]\n    value = read number from encoded\n    add (value) to [cloud list v]\nend\n\nwhen I receive [cloud - lock v]\nset [lock id v] to (pick random (0) to (10000000000))\nforever\n    read lock (☁ cloud lock)\n    set [value v] to (encoded)\n    set [encoded v] to []\n    repeat until <(value) = (encoded)>\n        wait (0.7) seconds\n        read lock (☁ cloud lock)\n    end\n    set [☁ cloud lock v] to (lock id)\n    read lock (lock id)\n    set [value v] to (encoded)\n    wait (0.7) seconds\n    read lock (☁ cloud lock)\n    if <(value) = (encoded)> then\n        set [☁ cloud lock v] to (lock id)\n        stop [other scripts in sprite v]\n        show\n        stop [this script v]\n    end\n    wait (pick random (0) to (2.0)) seconds\nend\n\ndefine read lock (lock)\nset [encoded v] to (join [lock] (☁ cloud list 2))\nset [encoded v] to (join (encoded) (☁ cloud list 2))\nset [encoded v] to (join (encoded) (☁ cloud list 3))\nset [encoded v] to (join (encoded) (☁ cloud list 4))\nset [encoded v] to (join (encoded) (☁ cloud list 5))\nset [encoded v] to (join (encoded) (☁ cloud list 6))\nset [encoded v] to (join (encoded) (☁ cloud list 7))\nset [encoded v] to (join (encoded) (lock))\n\nset [☁ cloud list 1 v] to []\nset [☁ cloud list 2 v] to []\n\nwhen I receive [cloud - lock v]\nswitch costume to (lower v)\nshow\ngo to x: (0) y: (0)\ngo to [front v] layer\nforever\n    wait (0.7) seconds\n    hide\n    wait (0.3) seconds\n    show\nend\n\n@Leaderboard\n\nwhen I receive [show high score table v]\nbroadcast (CLOUD LIST - Load v)\nbroadcast (Show high score table - 2 v)\n\ndefine Show Top 25\nshow variable [☁ latest v]\nshow variable [☁ fastest v]\nset [_highscore table open v] to [1]\ndelete all of [top 25 v]\nset [i v] to [1]\nrepeat (25)\n    format (i)\n    add (format) to [top 25 v]\n    change [i v] by (2)\nend\nhide list [top 25 v]\n\ndefine format (i)\nset [format v] to (item (i) of [cloud list v])\nif <(format) = []> then\n    stop [this script v]\nend\nset [format v] to (join ((item ((i) + (1)) of [cloud list v]) / (10)) (join [ ... ] (format)))\n\nwhen I receive [save time to cloud v]\nset [☁ latest v] to (TIME)\nif <(TIME) < (☁ FASTEST)> then\n    wait (0.1) seconds\n    set [☁ fastest v] to (TIME)\n    set [state:@game_won v] to [WORLD RECORD]\nend\nset [cloud_needs_updating? v] to []\nSave to Top 25 (username) (TIME)\nif <(cloud_needs_updating?) = > then\n    wait (0.1) seconds\n    broadcast (CLOUD LIST - Load v)\n    broadcast (SAVE TIME TO CLOUD - 2 v)\nend\n\ndefine Save to Top 25 (user) (time)\nset [i v] to [1]\nrepeat (25)\n    if <<(item (i) of [cloud list v]) = []> or <(time) < (item ((i) + (1)) of [cloud list v])>> then\n        insert (time) at (i) of [cloud list v] \n        insert (user) at (i) of [cloud list v] \n        change [i v] by (2)\n        repeat until <<(i) > [50]> or <(item (i) of [cloud list v]) = (user)>>\n            change [i v] by (2)\n        end\n        delete (i) of [cloud list v]\n        delete (i) of [cloud list v]\n        set [cloud_needs_updating? v] to \n        stop [this script v]\n    end\n    if <(item (i) of [cloud list v]) = (user)> then\n        stop [this script v]\n    end\n    change [i v] by (2)\nend\n\nwhen flag clicked\nhide variable [time v]\nhide variable [☁ fastest v]\nhide variable [☁ latest v]\nhide\nHide Top 25\nbroadcast (CLOUD LIST - Load v)\n\nwhen I receive [new game v]\nshow list [top 25 v]\n\nwhen I receive [hide highscore table v]\nHide Top 25\n\ndefine Hide Top 25\nset [_highscore table open v] to [0]\nhide variable [☁ latest v]\nhide variable [☁ fastest v]\nshow list [top 25 v]\n\ndefine reset\nset [cloud_needs_updating? v] to []\ndelete all of [top 25 v]\ndelete all of [cloud list v]\nrepeat (8)\n    add [] to [cloud list v]\nend\nset [☁ fastest v] to [1000]\nset [☁ latest v] to []\nbroadcast (CLOUD LIST - Save v)\n\nwhen I receive [toggle leaderboard v]\nif <(_highscore table open) = [1]> then\n    Hide Top 25\nelse\n    broadcast (CLOUD LIST - Load v)\n    broadcast (Show high score table - 2 v)\nend\n\nwhen I receive [save time to cloud - 2 v]\nset [cloud_needs_updating? v] to []\nSave to Top 25 (username) (TIME)\nif <(cloud_needs_updating?) = > then\n    broadcast (CLOUD LIST - Save v)\nend\n\nwhen I receive [show high score table - 2 v]\nShow Top 25\n\nwhen flag clicked\nsay [TROLL] for (10000000000000) seconds\n\nwhen I start as a clone\nsay [TROLL] for (10000000000000) seconds\n\n@Sprite1\n\nwhen this sprite clicked\nstop all sounds\nplay sound [Press Start v] until done\n\n@Sprite2\n\nwhen flag clicked\nplay sound [recording1 v] until done\n\n@Screenshot 2022-09-04 211430\n\n
this is not mine