o3djs.require("o3djs.util");o3djs.require("o3djs.math");o3djs.require("o3djs.rendergraph");o3djs.require("o3djs.primitives");o3djs.require("o3djs.camera");o3djs.require("o3djs.pack");o3djs.require("o3djs.scene");o3djs.require("o3djs.io");o3djs.require("o3djs.fps");o3djs.require("o3djs.loader");o3djs.require("o3djs.canvas");var g_o3d;var g_math;var g_client;var g_pack;var g_finished=false;var g_camera;var g_fpsManager;var g_fogParams;var g_fogColor;var hacky_dragging=false;var hacky_last_mouse_coords={x:0,y:0};var hacky_drag_button;function unload(){if(g_client){g_client.cleanup()}}function init(){o3djs.util.makeClients(initStep2)}function initStep2(a){var j=a[0];g_o3d=j.o3d;g_math=o3djs.math;g_client=j.client;g_pack=g_client.createPack();var f=[1,1,1,1];var h=g_pack.createObject("Transform");var k=g_pack.createObject("Transform");var o=o3djs.rendergraph.createBasicView(g_pack,h,g_client.renderGraphRoot,f);o.zOrderedState.getStateParam("CullMode").value=g_o3d.State.CULL_NONE;o.zOrderedState.getStateParam("ZWriteEnable").value=false;init_ui_view_info(o,k);var n=_create_phys_world();var c=new Scene(o,j);if(typeof(game_init)!=="undefined"){game_init(c,n)}var e=[];function m(s){var q=o3djs.event.getEventKeyChar(s);var p={charCode:q};return p}function i(q,p){o3djs.event.addEventListener(q,p,function(s){var t=m(s);e.push([p,t])})}function l(q,p){o3djs.event.addEventListener(q,p,function(s){e.push([p,s])})}l(j,"mousedown");l(j,"mouseup");l(j,"mousemove");document.onkeydown=function(p){var q=m(p);e.push(["keydown",q])};var d=declare_process({update:function(y){if(1){for(var v=0;v<e.length;v++){_fire_event(c,e[v][0],e[v][1])}e.splice(0,e.length)}if(1){var t=1/60;n.Step(t,10);if(1){for(var x=n.m_bodyList;x;x=x.m_next){if(!x.IsFrozen()&&!x.IsStatic()){var u=x.GetUserData();if(u&&u.update_transform){u.update_transform(x)}}}}if(1){for(var w=n.GetContactList();w;w=w.GetNext()){var p=w.GetShape1().GetBody(),z=w.GetShape2().GetBody();var s=p.GetUserData(),q=z.GetUserData();if(s&&s.on_contact){s.on_contact(q,z)}if(q&&q.on_contact){q.on_contact(s,p)}}}}if(1){c.camera.update()}}});process_manager.add(new d());g_client.setTickCallback(globalOnTick);g_client.setRenderCallback(globalOnRender)}function globalOnTick(a){process_manager.tick(a.elapsedTime)}function globalOnRender(a){if(g_fpsManager){g_fpsManager.update(a)}}function Scene(a,c){this.view_info=a;this.camera=new OrthoCamera(a);this.root_node=a.pack.createObject("Transform");this.root_node.parent=a.treeRoot;this._input_listeners={mousedown:new Signal(),mouseup:new Signal(),mousemove:new Signal(),keydown:new Signal(),keyup:new Signal()}}Scene.prototype.set_clear_color=function(a){if(a){this.view_info.clearBuffer.clearColorFlag=true;this.view_info.clearBuffer.clearColor=a}else{this.view_info.clearBuffer.clearColorFlag=false}};Scene.prototype.listen=function(a,d,c){return this._input_listeners[a].connect(d,c)};Scene.prototype.unlisten=function(a,c){return this._input_listeners[a].disconnect(c)};Scene.prototype.fire_event=function(a,c){return this._input_listeners[a].fire(c)};Signal=Class.create({initialize:function(){this._listeners=[]},connect:function(d,c){var a=[d,c];this._listeners.push(a);return a},disconnect:function(d){var a=this._listeners;for(var c=0;c<a.length;++c){if(a[c]==d){a.splice(c,1);return}}},fire:function(){var c=this._listeners;for(var e=0;e<c.length;++e){var a=c[e];var d=a[0],f=a[1];f.apply(d,arguments)}}});function OrthoCamera(a){this._view_info=a;this._center=[0,0];this._width=700;this._height=500;this._near=0.001;this._far=1000;this._view_info.drawContext.view=g_math.matrix4.lookAt([0,0,1],[0,0,0],[0,1,0]);this._dirty=true}OrthoCamera.prototype.set_center=function(a){this._center=[a[0],a[1]];this._dirty=true};OrthoCamera.prototype.get_center=function(){return[this._center[0],this._center[1]]};OrthoCamera.prototype.update=function(){if(this._dirty){this._view_info.drawContext.projection=g_math.matrix4.orthographic(this._center[0]-this._width*0.5+0.5,this._center[0]+this._width*0.5+0.5,this._center[1]+this._height*0.5+0.5,this._center[1]-this._height*0.5+0.5,this._near,this._far);this._dirty=false}};function _create_phys_world(){var a=new b2AABB();a.minVertex.Set(-1000,-1000);a.maxVertex.Set(5000,1000);var e=new b2Vec2(0,200);var d=true;var c=new b2World(a,e,d);return c}function _fire_event(d,a,c){if(!send_ui_mouse_event(a,c)){d.fire_event(a,c)}}if(!window.console){console={debug:function(){}}}Process=Class.create({initialize:function(){this._started=false;this._dead=false;this.next=null},on_start:function(){},on_end:function(){},update:function(a){},kill:function(){this._dead=true}});var declare_process=function(a){if(a.constructor){a.initialize=a.constructor;delete a.constructor}return Class.create(Process,a)};var process_manager={};process_manager._list=[];process_manager.add=function(a){process_manager._list.push(a)};process_manager.tick=function(e){for(var a=0;a<process_manager._list.length;++a){var d=process_manager._list[a];if(d._dead){d.on_end();d._started=false;d._dead=false;if(d.next){var c=d.next;process_manager._list[a]=c;d.next=null;d=c;--a}else{process_manager._list.splice(a,1);--a;continue}}if(!d._started){d._started=true;d.on_start()}d.update(e)}};var WaitProcess=declare_process({constructor:function(a){this._duration=a},on_start:function(){this._time=0},update:function(a){this._time+=a;if(this._time>this._duration){this.kill()}}});function AssetLoader(){this.complete=false;this._loader_finished=false;this._num_loading_sounds=0;this._loading_top_scores=false;this._loader=o3djs.loader.createLoader(o3djs.util.curry(this._on_loader_finish,this));this._assets={}}AssetLoader.prototype.loadTexture=function(e,c,a){var d=this;this._loader.loadTexture(e,c,function(h,f){if(a){a(h,f)}if(f){console.debug("Error loading texture <"+c+"> ");console.debug(f)}else{if(h){d._assets[c]=h}}})};AssetLoader.prototype.loadTextFile=function(d,a,e){var c=this;this._loader.loadTextFile(d,a,function(h,f){if(e){e(h,f)}if(f){console.debug("Error loading text file <"+a+"> ");console.debug(f)}else{if(texture){c._assets[a]=h}}})};AssetLoader.prototype.loadTopScores=function(){this._loading_top_scores=true;this._top_scores=new TopScores();this._top_scores.load_callback=o3djs.util.curry(function(a){a._loading_top_scores=false;a._check_all_finished();a._assets.__topscores__=a._top_scores.get_top_scores()},this);this._top_scores.request_scores()};AssetLoader.prototype.finish=function(){this._loader.finish()};AssetLoader.prototype.get=function(a){return this._assets[a]};AssetLoader.prototype._on_loader_finish=function(a){a._loader_finished=true;a._check_all_finished()};AssetLoader.prototype._check_all_finished=function(){if(this._loader_finished&&!this._num_loading_sounds&&!this._loading_top_scores){this.complete=true}};_ui_view_info=null;function init_ui_view_info(a,c){_ui_view_info=o3djs.rendergraph.createBasicView(g_pack,c,g_client.renderGraphRoot);_ui_view_info.root.priority=a.root.priority+1;_ui_view_info.clearBuffer.clearColorFlag=false;_ui_view_info.zOrderedState.getStateParam("CullMode").value=g_o3d.State.CULL_NONE;_ui_view_info.zOrderedState.getStateParam("ZWriteEnable").value=false;_ui_view_info.drawContext.projection=g_math.matrix4.orthographic(0+0.5,700+0.5,500+0.5,0+0.5,0.001,1000);_ui_view_info.drawContext.view=g_math.matrix4.lookAt([0,0,1],[0,0,0],[0,1,0])}function UIRegistrar(){this._bank=[]}UIRegistrar.prototype.register=function(a){this._bank.push(a)};UIRegistrar.prototype.unregister=function(c){for(var a=0;a<this._bank.length;a++){if(this._bank[a]==c){this._bank.splice(a,1);return}}};UIRegistrar.prototype._dispatch_mouse_event=function(c,d){for(var a=0;a<this._bank.length;a++){if(this._bank[a][c]&&this._bank[a].hit_test(d)){if(this._bank[a][c](d)){return true}}}return false};UIRegistrar.prototype.on_mouse_down=function(a){return this._dispatch_mouse_event("on_mouse_down",a)};UIRegistrar.prototype.on_mouse_up=function(a){return this._dispatch_mouse_event("on_mouse_up",a)};_ui_registrar=new UIRegistrar();function _register_control(a){_ui_registrar.register(a)}function _unregister_control(a){_ui_registrar.unregister(a)}function send_ui_mouse_event(c,a){if(c=="mousedown"){return _ui_registrar.on_mouse_down(a)}else{if(c=="mouseup"){return _ui_registrar.on_mouse_up(a)}else{}}}function UISticker(d,a,f,c,e){if(e==null||typeof(e)=="undefined"){e=true}this.image=new TexImage(d,_ui_view_info,_ui_view_info.treeRoot,null,e);if(!a){a=0}if(!f){f=0}this.image.transform.translate([a,f,0]);_register_control(this);this._on_mouse_down=null;this._on_mouse_up=null;this._x=a;this._y=f;this._width=this.image.sampler.texture.width;this._height=this.image.sampler.texture.height;if(c){this._width=c[0];this._height=c[1]}}UISticker.prototype.destroy=function(){this.image.destroy();delete this.image;_unregister_control(this)};UISticker.prototype.hit_test=function(a){if((a.x>=this._x)&&(a.x<=(this._x+this._width))){if((a.y>=this._y)&&(a.y<=(this._y+this._height))){return true}}return false};function UIText(d,a,e,c){this._canvas_lib=o3djs.canvas.create(g_pack,_ui_view_info.treeRoot,_ui_view_info);this._text_canvas=this._canvas_lib.createXYQuad(a,e,0,320,256,true);this._text_canvas.canvas.clear([1,1,1,0]);if(!c){this._paint=g_pack.createObject("CanvasPaint");this._paint.color=[1,0.5,0,1];this._paint.textSize=30;this._paint.textTypeface="Arial";this._paint.textAlign=g_o3d.CanvasPaint.LEFT;this._paint.setShadow(3,3,3,[0,0,0,0.8]);this._paint.shader=null}else{this._paint=c}this.set_text(d)}UIText.prototype.set_text=function(a){this._text_canvas.canvas.clear([1,1,1,0]);this._text_canvas.canvas.drawText(a,0,this._paint.textSize,this._paint);this._text_canvas.updateTexture()};UIText.prototype.destroy=function(){this._text_canvas.transform.parent=null;delete this._text_canvas;delete this._canvas_lib;g_pack.removeObject(this._paint)};(function(){TopScores=Class.create({initialize:function(){this._url="top_scores.asp";this._scores=null;this.load_callback=null},request_scores:function(){var e=null;try{e=new XMLHttpRequest()}catch(d){try{e=new ActiveXObject("Msxml2.XMLHTTP")}catch(a){try{e=new ActiveXObject("Microsoft.XMLHTTP")}catch(c){e=false}}}e.open("GET",this._url,true);e.onreadystatechange=o3djs.util.curry(function(f){if(e.readyState!=4){return}if(e.status==200){var j=e.responseText.split(",");var k=[];for(var h=0;h<j.length-1;h+=2){k.push({name:j[h],shots:j[h+1]})}f._scores=k;if(f.load_callback){f.load_callback()}}},this);e.send(null)},is_loaded:function(){return this._scores},get_top_scores:function(){return this._scores}})})();(function(){var m=declare_process({constructor:function(o,n){this._scene=o;this._phys_world=n;this._asset_loader=new AssetLoader();this._asset_loader.loadTexture(g_pack,"img/loading_screen-01.png");this._asset_loader.loadTexture(g_pack,"img/loading-01.png");this._asset_loader.finish()},on_start:function(){},on_end:function(){},update:function(p){if(this._asset_loader.complete){e.asset_loader=this._asset_loader;var n=new a(this._scene,this._phys_world);var o=new e(this._scene,n.asset_loader);o.next=n;this.next=o;this.kill()}}});var e=declare_process({asset_loader:null,constructor:function(o,n){this._scene=o;this._loader=n;this._wallpaper=new UISticker(e.asset_loader.get("img/loading_screen-01.png"));this._loading_text=new UISticker(e.asset_loader.get("img/loading-01.png"),350,250+128-27,null,false)},on_start:function(){this._scene.set_clear_color([1,0,0,1]);this._time=0},on_end:function(){this._wallpaper.destroy();this._loading_text.destroy()},update:function(n){this._time+=n;if(this._time>0.5){if(this._loader.complete){this.kill()}}}});var l=declare_process({constructor:function(o,n){this._ball=o;this._camera=n},update:function(v){var q=100;var u=this._ball.get_position();var n=this._camera.get_center();var o=[u[0]-n[0],u[1]-n[1]];var t=Math.sqrt(o[0]*o[0]+o[1]*o[1]);if(t>q){o[0]/=t;o[1]/=t;var s=Math.pow((t-q)*0.05,2);if(s>100){s=100}var p=[o[0]*s,o[1]*s];var w=[n[0]+p[0],n[1]+p[1]];this._camera.set_center(w)}}});var k=declare_process({constructor:function(o,n){this._start_pos=n.get_center();this._target_pos=o;this._duration=3;this._time=0;this._camera=n},update:function(v){this._time+=v;var s=this._time/this._duration;if(s>=1){this._camera.set_center(this._target_pos);this.kill()}else{s=1-Math.pow(1-s,4);var n=this._target_pos;var p=this._start_pos;var o=[n[0]-p[0],n[1]-p[1]];var u=Math.sqrt(o[0]*o[0]+o[1]*o[1]);o[0]/=u;o[1]/=u;var t=u*s;var v=[o[0]*t,o[1]*t];var q=[p[0]+v[0],p[1]+v[1]];this._camera.set_center(q)}}});var i=declare_process({_fire_flag:false,constructor:function(q,p,o,n){this._main_state=q;this._scene=p;this._phys_world=o;this._ball_position=n},on_start:function(){this._time=0;var n=this._ball_position;this._main_state.cannon.set_position(n);this._mousedown_handle=this._scene.listen("keydown",this,this._on_key_down)},on_end:function(){if(this._mousedown_handle){this._scene.unlisten("keydown",this._mousedown_handle);delete this._mousedown_handle}},update:function(n){this._time+=n;if(this._fire_flag){game_scoring.shot_fired(this._main_state.cannon.get_aim_angle(),this._main_state.cannon.get_aim_power());this.next=new h(this._main_state,this._scene,this._phys_world,this._main_state.cannon.get_ball_position(),this._main_state.cannon.get_ball_velocity());this.kill()}},_on_key_down:function(s){var p=1;var q=5;var o=s.charCode;if(o==37){this._main_state.cannon.set_aim_angle(this._main_state.cannon.get_aim_angle()+p)}else{if(o==38){var n=this._clamp_aim_power(this._main_state.cannon.get_aim_power()+q);this._main_state.cannon.set_aim_power(n);set_power_bar(n)}else{if(o==39){this._main_state.cannon.set_aim_angle(this._main_state.cannon.get_aim_angle()-p)}else{if(o==40){var n=this._clamp_aim_power(this._main_state.cannon.get_aim_power()-q);this._main_state.cannon.set_aim_power(n);set_power_bar(n)}else{if(o==32){this._fire_flag=true}}}}}},_clamp_aim_power:function(n){return Math.min(Math.max(n,0),100)}});var h=declare_process({constructor:function(s,q,o,n,p){this._main_state=s;this._scene=q;this._phys_world=o;this._starting_cannon_position=n;this._ball_position=n;this._ball_velocity=p},on_start:function(){this._time=0;this._ball=new game_objects.CannonBall(this._scene,this._main_state.asset_loader,this._phys_world,this._ball_position,this._ball_velocity);this._main_state.cannon.spawn_fire_effect();this._camera_follow_process=new l(this._ball,this._scene.camera);process_manager.add(this._camera_follow_process)},on_end:function(){this._early_cleanup()},update:function(n){this._time+=n;if(!game_objects.Chest.get_chest_count()&&!game_objects.Chest.get_active_count()){game_scoring.shot_ended();this._main_state.target_achieved();this._early_cleanup();this.kill()}else{if(this._ball.body.IsFrozen()){game_scoring.shot_ended();this.next=new k(this._starting_cannon_position,this._scene.camera);this.next.next=new i(this._main_state,this._scene,this._phys_world,this._starting_cannon_position);this.kill()}else{if(this._is_stable()&&!game_objects.Chest.get_active_count()){game_scoring.shot_ended();this.next=new i(this._main_state,this._scene,this._phys_world,this._ball.get_position());this.kill()}}}},_is_stable:function(){var o=false;for(var n=this._phys_world.m_bodyList;n;n=n.m_next){if(n==this._phys_world.m_groundBody){continue}if(!n.IsStatic()&&!n.IsFrozen()&&!n.IsSleeping()){o=true;break}}return !o},_early_cleanup:function(){if(this._camera_follow_process){this._camera_follow_process.kill();delete this._camera_follow_process}if(this._ball){this._ball.remove();delete this._ball}}});var j=declare_process({constructor:function(o,n,p){this._scene=o;this._phys_world=n;this._level_index=p;this.asset_loader=new AssetLoader();this.asset_loader.loadTexture(g_pack,"img/debug.png");this.asset_loader.loadTexture(g_pack,"img/blackhole.png");this.asset_loader.loadTexture(g_pack,"img/whitehole-01.png");this.asset_loader.loadTexture(g_pack,"img/test_boomcrate.png");this.asset_loader.loadTexture(g_pack,"img/crate_square_rubber-01.png");this.asset_loader.loadTexture(g_pack,"img/gold_gear_blackcube-01.png");this.asset_loader.loadTexture(g_pack,"img/cannon_ball.png");this.asset_loader.loadTexture(g_pack,"img/crate_square-01-01.png");this.asset_loader.loadTexture(g_pack,"img/crate_square_skeleton-01-01.png");this.asset_loader.loadTexture(g_pack,"img/crate_square_metal-01.png");this.asset_loader.loadTexture(g_pack,"img/cannonB_wheel-01.png");this.asset_loader.loadTexture(g_pack,"img/cannonB-01.png");this.asset_loader.loadTexture(g_pack,"img/power_bar3.png");this.asset_loader.loadTexture(g_pack,"img/time_8px_64x16.png");this.asset_loader.loadTexture(g_pack,"img/shots_8px_64x16.png");this.asset_loader.loadTexture(g_pack,"img/power_8px_64x16.png");this.asset_loader.loadTexture(g_pack,"img/power_bar_rounded2-01.png");this.asset_loader.loadTexture(g_pack,"img/omg.png");this.asset_loader.loadTexture(g_pack,"img/dirt_tile.png");this.asset_loader.loadTexture(g_pack,"img/grass_top_tile.png");this.asset_loader.loadTexture(g_pack,"img/tree_cartoony-01.png");this.asset_loader.loadTexture(g_pack,"img/cloud1-01.png");this.asset_loader.loadTexture(g_pack,"img/cloud2-01.png");this.asset_loader.loadTexture(g_pack,"img/vine_128x64-01.png");this.asset_loader.finish();this._level_loader=new LevelLoader(this._scene,this._phys_world,this.asset_loader)},on_start:function(){this._time=0;this._scene.set_clear_color([0.56,0.76,1,1]);this._level_loader.create(get_level_data(this._level_index));this.cannon=new game_objects.Cannon(this._scene,this.asset_loader,this._phys_world,[0,0]);process_manager.add(new i(this,this._scene,this._phys_world,this._level_loader.get_player_start_pos()));this._scene.camera.set_center(this._level_loader.get_player_start_pos());this._chest_count_widget=new ChestCountWidget(this.asset_loader,[10,5]);this._shot_count_widget=new HudShotCountWidget(this.asset_loader,[300,4]);this._level_time_widget=new HudTimeWidget(this.asset_loader,[410,4]);create_power_bar(this.asset_loader,[500,4]);set_power_bar(this.cannon.get_aim_power());game_scoring.level_begin();this._shot_count_widget.force_update()},on_end:function(){game_scoring.level_end();this._level_loader.destroy();delete this._level_loader;this.cannon.remove();delete this.cannon;destroy_power_bar();this._chest_count_widget.destroy();delete this._chest_count_widget;this._shot_count_widget.destroy();delete this._shot_count_widget;this._level_time_widget.destroy();delete this._level_time_widget},update:function(n){this._time+=n;this._level_time_widget.set_time(game_scoring.get_level_time())},target_achieved:function(){if(this._level_index+1<get_level_count()){var n=new j(this._scene,this._phys_world,this._level_index+1);this.next=n.create_loading_state()}else{this.next=new d(this._scene,this._phys_world).create_loading_state()}this.kill()},create_loading_state:function(){var n=new e(this._scene,this.asset_loader);n.next=this;return n}});var a=declare_process({constructor:function(o,n){this._scene=o;this.phys_world=n;this.asset_loader=new AssetLoader();this.asset_loader.loadTexture(g_pack,"img/IntroScreen_TechniBlox_1024x512-01.png");this.asset_loader.loadTexture(g_pack,"img/playbutton2_rollover-01.png");this.asset_loader.loadTexture(g_pack,"img/loading-01.png");this.asset_loader.finish()},on_start:function(){this._time=0;this._scene.set_clear_color([0.5,0.5,0.5,1]);this.image=new UISticker(this.asset_loader.get("img/IntroScreen_TechniBlox_1024x512-01.png"),0,0);this._test_sticker=new UISticker(this.asset_loader.get("img/playbutton2_rollover-01.png"),500,350,[128,42]);this._test_sticker.on_mouse_down=o3djs.util.curry(function(n,p){var o=new c(n._scene,n.phys_world,0);n.next=o.create_loading_state();n.kill()},this)},on_end:function(){this.image.destroy();this._test_sticker.destroy()},update:function(n){this._time+=n}});var c=declare_process({constructor:function(o,n){this._scene=o;this._phys_world=n;this._text_widgets=[];this.asset_loader=new AssetLoader();this.asset_loader.loadTopScores();this.asset_loader.loadTexture(g_pack,"img/loading_screen-01.png");this.asset_loader.loadTexture(g_pack,"img/playbutton2_rollover-01.png");this.asset_loader.finish()},on_start:function(){this._time=0;this._scene.set_clear_color([0.5,0.5,0.5,1]);this.image=new UISticker(this.asset_loader.get("img/loading_screen-01.png"),0,0);this._test_sticker=new UISticker(this.asset_loader.get("img/playbutton2_rollover-01.png"),500,350,[128,42]);this._test_sticker.on_mouse_down=o3djs.util.curry(function(t,v){var u=new j(t._scene,t._phys_world,0);t.next=u.create_loading_state();t.kill()},this);var n=this.asset_loader.get("__topscores__");this._text_widgets.push(new UIText("~TOP SCORES~",200,20,this._make_caption_font()));var q=10;for(var o=n.length;o<q;o++){n.push({name:"---",shots:""})}for(var o=0;o<n.length&&o<q;o++){var p=n[o];var s=60+o*30;this._text_widgets.push(new UIText(this._lpad(""+(o+1)+".",3),120,s,this._make_score_entry_font()));this._text_widgets.push(new UIText(p.name.substr(0,20),170,s,this._make_score_entry_font()));this._text_widgets.push(new UIText(this._lpad((""+p.shots).substr(0,5),5),500,s,this._make_score_entry_font()))}},on_end:function(){this.image.destroy();this._test_sticker.destroy();for(var n=0;n<this._text_widgets.length;n++){this._text_widgets[n].destroy()}this._text_widgets=[]},update:function(n){this._time+=n},_make_caption_font:function(){var n=g_pack.createObject("CanvasPaint");n.color=[1,1,0.5,1];n.textSize=26;n.textTypeface="Verdana";n.textStyle=g_o3d.CanvasPaint.BOLD;n.textAlign=g_o3d.CanvasPaint.LEFT;n.setShadow(3,3,3,[0,0,0,0.8]);n.shader=null;return n},_make_score_entry_font:function(){var n=g_pack.createObject("CanvasPaint");n.color=[1,1,1,1];n.textSize=18;n.textTypeface="Courier New";n.textStyle=g_o3d.CanvasPaint.BOLD;n.textAlign=g_o3d.CanvasPaint.LEFT;n.setShadow(2,0,1,[0,0,0,0.5]);n.shader=null;return n},_lpad:function(q,p){var o=" ";var n=q;while(n.length<p){n=o+n}return n},create_loading_state:function(){var n=new e(this._scene,this.asset_loader);n.next=this;return n}});var d=declare_process({constructor:function(o,n){this._scene=o;this.phys_world=n;this.asset_loader=new AssetLoader();this.asset_loader.loadTexture(g_pack,"img/closing_screen_techniblox_1024x512-01.png");this.asset_loader.loadTexture(g_pack,"img/playagain.png");this.asset_loader.loadTexture(g_pack,"img/loading-01.png");this.asset_loader.finish()},on_start:function(){this._time=0;this._scene.set_clear_color([0.5,0.5,0.5,1]);this._wallpaper=new UISticker(this.asset_loader.get("img/closing_screen_techniblox_1024x512-01.png"),0,0);this._test_sticker=new UISticker(this.asset_loader.get("img/playagain.png"),320,310,[260,48]);this._test_sticker.on_mouse_down=o3djs.util.curry(function(p,s){game_scoring.reset();var q=new j(p._scene,p.phys_world,0);p.next=q.create_loading_state();p.kill()},this);var o=[0.1,0.3,1,1];var n=g_pack.createObject("CanvasPaint");n.color=o;n.textSize=32;n.textTypeface="Courier New";n.textStyle=g_o3d.CanvasPaint.BOLD;n.textAlign=g_o3d.CanvasPaint.LEFT;n.setShadow(2,0,2,[0,0,0,0.5]);n.shader=null;this._shots_widget=new UIText(""+game_scoring.get_total_shots(),490,150,n);this._time_widget=new TimeWidget([490,218],game_scoring.get_total_time(),o);document.getElementById("submit_score_block").style.display="block";document.getElementById("game_data").value=game_scoring.get_info()},on_end:function(){this._wallpaper.destroy();this._test_sticker.destroy();this._shots_widget.destroy();delete this._shots_widget;this._time_widget.destroy();delete this._time_widget;document.getElementById("submit_score_block").style.display="none";document.getElementById("game_data").value=""},update:function(n){this._time+=n},create_loading_state:function(){var n=new e(this._scene,this.asset_loader);n.next=this;return n}});var f=declare_process({on_start:function(){this.start();this.reset()},update:function(n){if(this._on){this.time+=n}},reset:function(){this.time=0},start:function(){this._on=true},stop:function(){this._on=false}});GameScoring=Class.create({initialize:function(){this.reset();this._level_clock=new f();process_manager.add(this._level_clock);this.on_shot_fired=new Signal()},reset:function(){this._total_shots=0;this._level_shots=0;this._total_time=0;this._log=[]},level_begin:function(){this._log.push([]);this._level_clock.stop();this._level_clock.reset();this._level_shots=0},level_end:function(){this._level_clock.stop();this._total_shots+=this._level_shots;this._total_time+=this._level_clock.time},shot_fired:function(o,n){this._log[this._log.length-1].push([o,n,this._level_clock.time]);if(!this._level_shots){this._level_clock.start()}this._level_shots++;this.on_shot_fired.fire()},shot_ended:function(){this._log[this._log.length-1][this._log[this._log.length-1].length-1].push(this._level_clock.time)},get_level_shots:function(){return this._level_shots},get_total_shots:function(){return this._total_shots},get_total_time:function(){return this._total_time},get_level_time:function(){return this._level_clock.time},get_info:function(){var t="",n=this._log;for(var q=0;q<n.length;q++){for(var p=0;p<n[q].length;p++){for(var o=0;o<n[q][p].length;o++){t+=n[q][p][o]+" "}}t+="/"}return this.get_total_shots()+","+this.get_total_time()+","+this._enc(t)},_enc:function(q){var p="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";var n="";var y,w,u,x,v,t,s;var o=0;while(o<q.length){y=q.charCodeAt(o++);w=q.charCodeAt(o++);u=q.charCodeAt(o++);x=y>>2;v=((y&3)<<4)|(w>>4);t=((w&15)<<2)|(u>>6);s=u&63;if(isNaN(w)){t=s=64}else{if(isNaN(u)){s=64}}n=n+p.charAt(x)+p.charAt(v)+p.charAt(t)+p.charAt(s)}return n}});game_scoring=new GameScoring();game_init=function(o,n){var p=new m(o,n);process_manager.add(p)}})();(function(){game_objects={};function a(q,u,s,m,w,t,l,o,v){if(typeof(o)=="undefined"){o=true}var p=new b2BoxDef();if(!o){p.density=v}p.extents.Set(m,w);p.restitution=l;p.friction=0.4;var n=new b2BodyDef();n.userData=t;n.AddShape(p);n.position.Set(u,s);return q.CreateBody(n)}function k(q,m,s,l,o){var p=new b2CircleDef();p.radius=l;p.density=5;p.restitution=0.3;p.friction=0.5;var n=new b2BodyDef();n.AddShape(p);n.position.Set(m,s);n.userData=o;n.angularDamping=0.5;return q.CreateBody(n)}game_objects.FirstTestObject=Class.create({_static:true,_debug_name:"FirstTestObject",_texture_url:"img/debug.png",_size:[64,64],_restitution:0,_density:1,_destroyed:false,_last_pos:null,_last_rot:null,initialize:function(o,n,l,p){this._scene=o;this._asset_loader=n;this._phys_world=l;var m=n.get(this._texture_url);this.image=new TexImage(m,o.view_info,o.root_node,this._size,false);this.body=this._create_body(l,p);this.update_transform(this.body)},_create_body:function(l,m){return a(l,m[0],m[1],this._size[0]/2,this._size[1]/2,this,this._restitution,this._static,this._density)},remove:function(){if(this._destroyed){return}this._destroyed=true;this.image.destroy();this.image=null;this.body.m_world.DestroyBody(this.body);this.body=null},update_transform:function(l){var n=l.GetOriginPosition();this.image.transform.identity();this.image.transform.translate(n.x,n.y,0);if(!this._no_graphics_rotation){var m=l.GetRotation();this.image.transform.rotateZ(m)}},get_position:function(){var l=this.body.GetOriginPosition();return[l.x,l.y]}});var e=declare_process({constructor:function(l){this._obj=l},update:function(l){this._obj.remove();this._obj=null;this.kill()}});game_objects.BaseCrate=Class.create(game_objects.FirstTestObject,{_size:[32,32],_static:false,_restitution:0.3});game_objects.Crate=Class.create(game_objects.BaseCrate,{_debug_name:"Crate",_texture_url:"img/crate_square-01-01.png",_density:0.5});game_objects.MetalCrate=Class.create(game_objects.BaseCrate,{_debug_name:"MetalCrate",_texture_url:"img/crate_square_metal-01.png",_restitution:0.1,_density:5});game_objects.BouncyCrate=Class.create(game_objects.BaseCrate,{_debug_name:"BouncyCrate",_texture_url:"img/crate_square_rubber-01.png",_static:true,_restitution:0,_bounce_impulse:100000,on_contact:function(n,m){if(n&&n._debug_name=="CannonBall"){var o=this.body.GetOriginPosition();var l=m.GetOriginPosition();var p=l.Copy();p.Subtract(o);p.Normalize();if(Math.abs(p.x)>Math.abs(p.y)){if(p.x<0){p=new b2Vec2(-1,0)}else{p=new b2Vec2(1,0)}}else{if(p.y<0){p=new b2Vec2(0,-1)}else{p=new b2Vec2(0,1)}}var q=p.Copy();q.Multiply(this._bounce_impulse);m.ApplyImpulse(q,m.GetOriginPosition());play_sound("sound/spring_3.mp3")}}});game_objects.TouchyCrate=Class.create(game_objects.BaseCrate,{_debug_name:"TouchyCrate",_texture_url:"img/crate_square_skeleton-01-01.png",on_contact:function(m,l){if(m&&m._debug_name=="CannonBall"){if(!this._remove_queued){this._remove_queued=true;var n=new WaitProcess(0.2);n.next=new e(this);process_manager.add(n);play_sound("sound/_SMASH.mp3")}}}});game_objects.BoomCrate=Class.create(game_objects.BaseCrate,{_debug_name:"BoomCrate",_texture_url:"img/crate_square_skeleton-01-01.png",on_contact:function(m,l){if(m&&m._debug_name=="CannonBall"){if(!this._remove_queued){this._remove_queued=true;c(this._scene,this._asset_loader,this.get_position());f(this._phys_world,this.get_position());var n=new WaitProcess(0.2);n.next=new e(this);process_manager.add(n);play_sound("sound/_SMASH.mp3")}}}});function j(s,q,t,o,p,n,m){game_objects.Chest._inc_active_count();var l=spawn_scale_and_fade_image(s,q.get(o),t,p,n,m);l.next=new i();process_manager.add(l)}function d(m,l,n){j(m,l,n,"img/whitehole-01.png",3,0.5,0.8)}function c(m,l,n){j(m,l,n,"img/blackhole.png",1.5,0.4,0.8)}function f(s,t){for(var p=s.m_bodyList;p;p=p.m_next){if(!p.IsStatic()&&!p.IsFrozen()&&p!=s.m_groundBody){var o=p.GetUserData();var v=new b2Vec2(t[0],t[1]);var u=p.GetOriginPosition();var n=u.Copy();n.Subtract(v);var l=n.Length();n.Normalize();var q=200000;if(l>100){q=0}var m=n.Copy();m.Multiply(q);p.WakeUp();p.ApplyImpulse(m,p.GetOriginPosition())}}}var i=declare_process({update:function(l){game_objects.Chest._dec_active_count();this.kill()}});var h=declare_process({_cycle_length:1.5,constructor:function(){this._time=0;this._glow_object=[];this._reference_index=1},add_glow_object:function(l,m){var n=[l,m];this._glow_object.push(n);return n},remove_glow_object:function(m){for(var l=0;l<this._glow_object.length;l++){if(this._glow_object[l]==m){this._glow_object.splice(l,1);break}}},on_start:function(){},on_end:function(){for(var l=0;l<this._glow_object.length;l++){this._glow_object[l][0].remove()}},update:function(o){this._time+=o;for(var n=0;n<this._glow_object.length;n++){var l=1*(Math.sin(this._time*(2*Math.PI)/this._cycle_length));if(l<0){l=l*-1}r=this._glow_object[n][1][0]+((1-this._glow_object[n][1][0])*l);g=this._glow_object[n][1][1]+((1-this._glow_object[n][1][1])*l);b=this._glow_object[n][1][2]+((1-this._glow_object[n][1][2])*l);this._glow_object[n][0].image.setColor(r,g,b,this._glow_object[n][1][3])}}});game_objects.Chest=Class.create(game_objects.FirstTestObject,{_debug_name:"Chest",_texture_url:"img/gold_gear_blackcube-01.png",_static:false,_size:[32,32],initialize:function($super,n,m,l,o){$super(n,m,l,o,false);this.my_number=game_objects.Chest.debug_count++;game_objects.Chest._inc_chest_count();if(!game_objects.Chest._glow_game_state_add_to_process_manager){process_manager.add(game_objects.Chest._glow_game_state);game_objects.Chest._glow_game_state_add_to_process_manager=true}this._glow_object=game_objects.Chest._glow_game_state.add_glow_object(this,[163/255,221/255,255/255,1])},remove:function($super){if(!this._destroyed){game_objects.Chest._dec_chest_count()}$super(arguments)},on_contact:function(m,l){if(m&&m._debug_name=="CannonBall"){if(!this._remove_queued){this._remove_queued=true;d(this._scene,this._asset_loader,this.get_position());this._spawn_spin_effect();game_objects.Chest._glow_game_state.remove_glow_object(this._glow_object);this.remove();play_sound("sound/coin_3.mp3")}}},_spawn_spin_effect:function(){var o=this.get_position();var n=this._asset_loader.get(this._texture_url);var m=new TexImage(n,this._scene.view_info,this._scene.root_node,this._size,false);m.transform.translate([o[0],o[1],0]);var l=declare_process({on_start:function(){this._time=0},on_end:function(){m.destroy();delete m},update:function(s){this._time+=s;var q=1;var p=this._time/q;if(p>=1){this.kill()}else{m.scaleTransform.rotateZ(s*10);m.scaleTransform.scale([1-s*0.9,1-s*0.9,1]);m.transform.translate([s*-200,s*-200,0]);m.setColor(1,1,1,1-p)}}});process_manager.add(new l())}});game_objects.Chest._glow_game_state=new h();game_objects.Chest._glow_game_state_add_to_process_manager=false;game_objects.Chest.debug_count=1;game_objects.Chest._active_count=0;game_objects.Chest._chest_count=0;game_objects.Chest.chest_count_changed=new Signal();game_objects.Chest.get_active_count=function(){return game_objects.Chest._active_count};game_objects.Chest._inc_active_count=function(){game_objects.Chest._active_count++};game_objects.Chest._dec_active_count=function(){game_objects.Chest._active_count--};game_objects.Chest.get_chest_count=function(){return game_objects.Chest._chest_count};game_objects.Chest._inc_chest_count=function(){game_objects.Chest._chest_count++;game_objects.Chest.chest_count_changed.fire(game_objects.Chest._chest_count)};game_objects.Chest._dec_chest_count=function(){game_objects.Chest._chest_count--;game_objects.Chest.chest_count_changed.fire(game_objects.Chest._chest_count)};game_objects.Cannon=Class.create({_barrel_texture_url:"img/cannonB-01.png",_base_texture_url:"img/cannonB_wheel-01.png",_barrel_size:[32,24],_aim_angle:15,_aim_power:50,_min_fire_speed:150,_max_fire_speed:400,initialize:function(q,p,n,s){this._scene=q;this._asset_loader=p;var m=p.get(this._barrel_texture_url);var o=p.get(this._base_texture_url);var l=[24,24];this._pos=s;this._barrel_image=new TexImage(m,q.view_info,q.root_node,this._barrel_size,true);this._base_image=new TexImage(o,q.view_info,q.root_node,l,false);this.set_position(s);this.set_aim_angle(this._aim_angle)},remove:function(){this._barrel_image.destroy();this._barrel_image=null;this._base_image.destroy();this._base_image=null},get_ball_position:function(){return this._pos},get_ball_velocity:function(){var m=this._get_fire_speed();var l=this.get_aim_vector();return[m*l[0],m*l[1]]},_get_fire_speed:function(){return this._aim_power/100*(this._max_fire_speed-this._min_fire_speed)+this._min_fire_speed},get_final_angle:function(){return -this._aim_angle/100*Math.PI},get_aim_vector:function(){var l=this.get_final_angle();return[Math.cos(l),Math.sin(l)]},get_aim_angle:function(){return this._aim_angle},set_aim_angle:function(l){l=Math.min(Math.max(l,0),100);this._aim_angle=l;this._barrel_image.transform.identity();this._barrel_image.transform.translate(this._pos[0],this._pos[1],0);var n=[0,-8];this._barrel_image.transform.translate(n[0],n[1],0);this._barrel_image.transform.rotateZ(this.get_final_angle());var m=[16,12];this._barrel_image.transform.translate(-m[0],-m[1],0)},get_aim_power:function(){return this._aim_power},set_aim_power:function(l){this._aim_power=l},get_position:function(){return this._pos},set_position:function(l){this._pos=l;this._base_image.transform.identity();this._base_image.transform.translate(this._pos[0],this._pos[1],0);this.set_aim_angle(this._aim_angle)},get_muzzle_pos:function(){var l=this.get_aim_vector();return[this._pos[0]+l[0]*this._barrel_size[0],this._pos[1]+l[1]*this._barrel_size[0]]},spawn_fire_effect:function(){var n=this.get_muzzle_pos();var l=this.get_aim_vector();var o=0;for(var m=0;m<o;m++){var p=Math.min(this.get_aim_power()/300,1)*0.25+0.05;var q=[n[0]+l[0]*m*5,n[1]+l[1]*m*5];q[0]+=Math.random()*20-10;q[1]+=Math.random()*20-10;process_manager.add(spawn_scale_and_fade_image(this._scene,this._asset_loader.get("img/whitehole-01.png"),q,3,0.5,p*(o-m)/o))}play_sound("sound/_SMASH.mp3")}});game_objects.CannonBall=Class.create(game_objects.FirstTestObject,{_debug_name:"CannonBall",_texture_url:"img/cannon_ball.png",_no_graphics_rotation:true,_static:false,_restitution:0.3,_radius:8,initialize:function($super,o,n,l,p,m){this._size=[this._radius*2,this._radius*2];$super(o,n,l,p,false);this.body.SetLinearVelocity(new b2Vec2(m[0],m[1]))},_create_body:function(l,m){return k(l,m[0],m[1],this._radius,this)},on_contact:function(m,l){}});ScaleAndFadeOutImageProcess=declare_process({constructor:function(n,m,l){this._image=n;this._duration=m;this._start_alpha=l},on_start:function(){this._time=0},on_end:function(){this._image.destroy();delete this._image},update:function(m){this._time+=m;var l=this._time/this._duration;if(l>=1){this.kill()}else{this._image.transform.scale([1.01,1.01,1]);this._image.setColor(1,1,1,this._start_alpha*(1-l))}}});spawn_scale_and_fade_image=function(o,s,t,n,p,q){if(typeof(p)=="undefined"){p=1}if(typeof(q)=="undefined"){q=1}var u=[s.width,s.height];var m=new TexImage(s,o.view_info,o.root_node,u,false);m.transform.translate(t[0],t[1],0);m.transform.scale([p,p,1]);var l=new ScaleAndFadeOutImageProcess(m,n,q);return l}})();(function(){TexImage=function(f,c,j,h,i){var d=a(c.zOrderedDrawList);this.transform=g_pack.createObject("Transform");this.transform.parent=j;this.scaleTransform=g_pack.createObject("Transform");this.scaleTransform.parent=this.transform;this.sampler=g_pack.createObject("Sampler");this.sampler.addressModeU=g_o3d.Sampler.CLAMP;this.sampler.addressModeV=g_o3d.Sampler.CLAMP;this.paramSampler=this.scaleTransform.createParam("texSampler0","ParamSampler");this.paramSampler.value=this.sampler;this.paramColorMult=this.scaleTransform.createParam("colorMult","ParamFloat4");this.setColor(1,1,1,1);this.sampler.texture=f;this.scaleTransform.addShape(d);var e=[f.width,f.height];if(h){e=h}if(i){this.scaleTransform.translate(e[0]/2,e[1]/2,0)}this.scaleTransform.scale(e[0],-e[1],1)};TexImage.prototype.setColor=function(f,e,c,d){this.paramColorMult.set(f,e,c,d)};TexImage.prototype.destroy=function(){this.transform.parent=null;g_pack.removeObject(this.scaleTransform);g_pack.removeObject(this.transform);g_pack.removeObject(this.sampler)};var a=function(f){var e;if(TexImage._effect){e=TexImage._effect}else{e=g_pack.createObject("Effect");o3djs.effect.loadEffect(e,"shaders/texture-colormult.js");TexImage._effect=e}var d=g_pack.createObject("Material");d.effect=e;d.drawList=f;e.createUniformParameters(d);d.getParam("colorMult").value=[1,1,1,1];var c=o3djs.primitives.createPlane(g_pack,d,1,1,1,1,[[1,0,0,0],[0,0,1,0],[0,-1,0,0],[0,0,0,1]]);return c}})();(function(){var c=null;create_power_bar=function(d,e){c=new a(d,e)};destroy_power_bar=function(){c.destroy()};set_power_bar=function(d){if(c){c.set_power(d)}};var a=Class.create({initialize:function(d,f,e){this._bar_background=new UISticker(d.get("img/omg.png"),f[0],f[1]+6);this._bar=new UISticker(d.get("img/power_bar3.png"),f[0]+20,f[1]+21,null,false);this._label=new UISticker(d.get("img/power_8px_64x16.png"),f[0]+0,f[1]+0);this._max_width=141;this._cur_texture_width=this._bar.image.sampler.texture.width;if(e){this._max_width=e}this._bar.image.setColor(156/255,234/255,165/255,1)},destroy:function(){this._bar.destroy();this._label.destroy();delete this._label},set_power:function(e){e=e/100;e=Math.max(Math.min(e,1),0.01);var f=(this._max_width*e)/this._cur_texture_width;this._bar.image.scaleTransform.scale(f,1,1);var d=((this._cur_texture_width*f)/2)-(this._cur_texture_width/2);this._bar.image.transform.translate([d,0,0]);this._cur_texture_width=this._cur_texture_width*f}});ChestCountWidget=Class.create({_size:32,_off_alpha:0.4,_on_alpha:1,_marg:0,_sep:2,initialize:function(f,j){this._asset_loader=f;this._pos=j;this._initial_count=game_objects.Chest.get_chest_count();this._remaining=this._initial_count;this._stickers=[];for(var d=0;d<this._initial_count;d++){var h=this._get_icon_pos(d);var e=new UISticker(f.get("img/gold_gear_blackcube-01.png"),h[0],h[1]);e.image.transform.scale([this._size/e.image.sampler.texture.width,this._size/e.image.sampler.texture.height,1]);e.image.setColor(1,0.5,0.5,this._off_alpha);this._stickers.push(e)}this._sig_handle=game_objects.Chest.chest_count_changed.connect(this,this._on_chest_count_changed)},destroy:function(){if(this._sig_handle){game_objects.Chest.chest_count_changed.disconnect(this._sig_handle);delete this._sig_handle}for(var d=0;d<this._stickers.length;d++){this._stickers[d].destroy()}delete this._stickers},_on_chest_count_changed:function(d){this._update_stickers(d)},_update_stickers:function(e){var d=this._initial_count-this._remaining;var h=this._remaining-e;this._remaining=e;for(var f=d;f<d+h;f++){this._stickers[f].image.setColor(1,1,1,this._on_alpha);this._spawn_effect(f)}},_spawn_effect:function(d){var f=this._get_icon_pos(d);var e=new UISticker(this._asset_loader.get("img/gold_gear_blackcube-01.png"),f[0]+this._size/2,f[1]+this._size/2,null,false);e.image.transform.scale([this._size/e.image.sampler.texture.width,this._size/e.image.sampler.texture.height,1]);process_manager.add(new ScaleAndFadeOutImageProcess(e.image,1,1))},_get_icon_pos:function(d){var e=this._size+this._sep;return[this._pos[0]+this._marg+d*e,this._pos[1]+this._marg]}});make_ui_font_paint=function(d){var e=g_pack.createObject("CanvasPaint");e.color=d;e.textSize=18;e.textTypeface="Courier New";e.textStyle=g_o3d.CanvasPaint.BOLD;e.textAlign=g_o3d.CanvasPaint.LEFT;e.setShadow(2,0,1,[0,0,0,0.5]);e.shader=null;return e};HudShotCountWidget=Class.create({initialize:function(e,f){this._asset_loader=e;this._pos=f;this._label=new UISticker(e.get("img/shots_8px_64x16.png"),f[0]+0,f[1]+0);var d=make_ui_font_paint([1,1,0,1]);this._text=new UIText("",f[0]+0,f[1]+10,d);this._shot_sig_handle=game_scoring.on_shot_fired.connect(this,this._on_shot_fired)},destroy:function(){this._text.destroy();delete this._text;this._label.destroy();delete this._label;if(this._shot_sig_handle){game_scoring.on_shot_fired.disconnect(this._shot_sig_handle);delete this._shot_sig_handle}},force_update:function(){this._on_shot_fired()},_on_shot_fired:function(){var f=game_scoring.get_level_shots(),d=(game_scoring.get_total_shots()+game_scoring.get_level_shots());var e=""+f+" ("+d+")";this._text.set_text(e)}});TimeWidget=Class.create({_time:-1,_text_value:null,initialize:function(h,d,f){if(!f){f=[1,1,0,1]}var e=make_ui_font_paint(f);this._text=new UIText("",h[0],h[1],e);if(!d){d=0}this.set_time(d)},destroy:function(){this._text.destroy();delete this._text},set_time:function(e){if(e!=this._time){this._time=e;var d=this._format_time(this._time);if(d!=this._text_value){this._text.set_text(d);this._text_value=d}}},_format_time:function(f){var d=Math.floor(f);var e=Math.floor(d/60);d-=e*60;if(d<10){d="0"+d}return e+":"+d}});HudTimeWidget=Class.create({initialize:function(e,f,d){this._label=new UISticker(e.get("img/time_8px_64x16.png"),f[0]+0,f[1]+0);this._time_widget=new TimeWidget([f[0]+0,f[1]+10],d)},destroy:function(){this._time_widget.destroy();delete this._time_widget;this._label.destroy();delete this._label},set_time:function(d){this._time_widget.set_time(d)}})})();_level=[{tile_data:[0,0,0,12,0,0,0,1,0,12,1,0,0,2,0,12,2,0,0,3,0,12,3,0,0,4,0,12,4,0,0,5,0,1,5,1,2,5,1,3,5,1,4,5,1,5,5,1,6,5,1,7,5,1,8,5,1,9,5,1,10,5,1,11,5,1,12,5,0],texture_data:{front:[],back:[1,100,60,2,250,100,1,500,75,0,282,90]},game_object_data:[[1,[544,304]],[0,[544-32,304]],[0,[544-32,304-32]],[0,[544-32,304-64]],[3,[768-16,304]]],player_start_pos:[4*64+32,5*64-4],extra:{tile_size:64}},{tile_data:[12,0,0,12,1,0,12,2,0,12,3,0,12,4,0,0,5,1,1,5,1,2,5,1,3,5,1,4,5,1,5,5,1,6,5,1,7,5,1,8,5,1,9,5,1,10,5,1,11,5,1,12,5,0],texture_data:{front:[],back:[1,200,-100,2,400,0,1,700,-50,0,82,90]},game_object_data:[[0,[544,304]],[0,[544+5,304-32]],[0,[544-5,304-32*2]],[0,[544+5,304-32*3]],[0,[544-5,304-32*4]],[0,[544,304-32*5]],[1,[544,304-32*6]]],player_start_pos:[4*64+32,5*64-4],extra:{tile_size:64}},{tile_data:[0,0,0,14,0,0,0,1,0,14,1,0,0,2,0,4,2,1,10,2,1,14,2,0,0,3,0,3,3,1,4,3,0,10,3,0,11,3,1,14,3,0,0,4,0,2,4,1,3,4,0,4,4,0,5,4,0,9,4,0,10,4,0,11,4,0,12,4,1,14,4,0,0,5,0,1,5,1,2,5,1,3,5,1,4,5,1,5,5,1,6,5,1,7,5,1,8,5,1,9,5,1,10,5,1,11,5,1,12,5,1,13,5,1,14,5,0],texture_data:{front:[],back:[1,200,-100,2,400,0,1,700,-50,0,382,90]},game_object_data:[[0,[600,240]],[0,[600,240-32]],[2,[600,240-64]],[0,[360,240]],[0,[360,240-32]],[2,[360,240-64]],[1,[672,112]]],player_start_pos:[4*64+32,2*64-4],extra:{tile_size:64}},{tile_data:[0,0,1,6,0,1,7,0,1,8,0,1,11,0,1,0,1,0,1,1,1,2,1,1,3,1,1,8,1,0,11,1,0,0,2,0,6,2,1,7,2,1,8,2,0,11,2,0,0,3,0,5,3,1,6,3,0,7,3,0,10,3,1,11,3,0,0,4,0,4,4,1,5,4,0,6,4,0,10,4,0,11,4,0,0,5,0,1,5,1,2,5,1,3,5,1,4,5,0,5,5,0,6,5,0,7,5,1,8,5,1,9,5,1,10,5,0],texture_data:{front:[3,390,5,3,84,69],back:[1,-50,-50,2,400,-150,1,700,-50]},game_object_data:[[1,[480,304]],[0,[272-80,176]],[2,[272-80,208]],[2,[272-80,240]]],player_start_pos:[150,320-4],extra:{tile_size:64}},{tile_data:[2,0,1,3,0,1,4,0,1,5,0,1,6,0,1,9,0,1,10,0,1,11,0,1,12,0,1,15,0,1,16,0,1,17,0,1,18,0,1,20,0,1,4,1,0,9,1,0,20,1,0,4,2,0,9,2,0,11,2,1,12,2,1,15,2,1,16,2,1,17,2,1,18,2,1,20,2,0,4,3,0,9,3,0,12,3,0,18,3,0,4,4,0,9,4,0,10,4,1,11,4,1,12,4,0,15,4,1,16,4,1,17,4,1,18,4,0,20,4,1,24,5,1,0,6,1,1,6,1,2,6,1,3,6,1,4,6,1,5,6,1,6,6,1,7,6,1,8,6,1,9,6,1,10,6,1,11,6,1,12,6,1,13,6,1,14,6,1,15,6,1,16,6,1,17,6,1,18,6,1,19,6,1,20,6,1,21,6,1,22,6,1,23,6,1,24,6,0],texture_data:{front:[],back:[1,-50,-50,2,400,-150,1,700,-50]},game_object_data:[[1,[744,204]],[1,[1100,204]],[1,[1050,114]],[3,[944,114-64]],[2,[(64*18)-16,114-32]],[2,[(15*64)+24,114-16]],[2,[(15*64)+24,114-32]],[2,[(15*64)+40,114-16]],[2,[(15*64)+40,114-32]]],player_start_pos:[200,-4]},{tile_data:[11,-2,1,10,-1,1,9,0,1,13,0,1,8,1,1,12,1,1,16,1,0,18,1,0,7,2,1,11,2,1,16,2,0,18,2,0,6,3,1,10,3,1,16,3,0,17,3,0,18,3,0,5,4,1,9,4,1,0,6,0,1,6,1,2,6,1,3,6,1,4,6,1,5,6,1,6,6,1,7,6,1,8,6,1,9,6,1,10,6,1,11,6,1,12,6,1,13,6,1,14,6,1,15,6,1,16,6,1,17,6,1,18,6,1,19,6,1,20,6,1],texture_data:{front:[],back:[1,-50,-50,2,400,-150,1,700,-50]},game_object_data:[[1,[550,-232-8]],[3,[550,-232+32-8]],[3,[288+16+64,192+48]],[3,[288-16+64,192+48]],[3,[448-16+64,128+48-64]],[3,[448-48+64,128+48-64]],[1,[17*64+32,3*64-16]],[3,[20*64,4*64]]],player_start_pos:[32,6*64-8]},{tile_data:[0,0,1,25,0,1,0,1,0,25,1,0,0,2,0,25,2,0,0,3,0,5,3,0,25,3,0,0,4,0,5,4,0,10,4,0,25,4,0,0,5,0,1,5,1,2,5,1,3,5,1,4,5,1,5,5,0,6,5,1,7,5,1,8,5,1,9,5,1,10,5,0,11,5,1,12,5,1,13,5,1,14,5,1,15,5,1,16,5,1,17,5,1,21,5,1,22,5,1,23,5,0,24,5,1,25,5,0,0,6,0,25,6,0,0,7,0,1,7,1,2,7,1,3,7,1,4,7,1,5,7,1,6,7,1,7,7,1,8,7,1,9,7,1,10,7,1,11,7,1,12,7,1,13,7,1,14,7,1,15,7,1,16,7,1,17,7,1,19,7,1,20,7,1,21,7,1,22,7,1,23,7,1,24,7,1,25,7,1],texture_data:{front:[],back:[1,200,-100,2,400,0,1,700,-50]},game_object_data:[[1,[5*64+32,3*64-16-32]],[3,[5*64+32,3*64-16]],[1,[10*64+32,4*64-16-32]],[3,[10*64+32,4*64-16]],[1,[15*64+32,5*64-16-32]],[3,[15*64+32,5*64-16]],[3,[18*64+16,5*64+16]],[3,[20*64+48,5*64+16]],[2,[23*64+32-0.15,5*64-16-32]],[2,[23*64+32-0.15,5*64-16]],[1,[24*64+32,5*64-16]],[1,[24*64+16,7*64-16]],[3,[24*64+48,7*64-16]],[3,[24*64+48,7*64-16-32]],[1,[1*64+32,7*64-16]],[4,[1*64+32+64,7*64-16]]],player_start_pos:[1*64+32,5*64-4],extra:{tile_size:64}}];function get_level_data(a){return _level[a]}function get_level_count(){return _level.length}_tile_data_converter=[{texture:"img/dirt_tile.png"},{texture:"img/grass_top_tile.png"}];_texture_data_converter=["img/tree_cartoony-01.png","img/cloud1-01.png","img/cloud2-01.png","img/vine_128x64-01.png"];_game_objects_data_converter=[game_objects.Crate,game_objects.Chest,game_objects.BoomCrate,game_objects.BouncyCrate,game_objects.MetalCrate];function LevelLoader(d,c,a){this._scene=d;this._world=c;this._loader=a;this._tile_size=64;this._tiles=[];this._textures=[];this._game_objects=[];this._player_start_pos=[0,0]}LevelLoader.prototype.create=function(a){this._load_textures(a.texture_data.back);this._create_tiles(a.tile_data);this._load_textures(a.texture_data.front);this._load_game_objects(a.game_object_data);this._player_start_pos=a.player_start_pos};LevelLoader.prototype.destroy=function(){this._destroy_tiles();this._destroy_textures();this._destroy_game_objects()};LevelLoader.prototype._destroy_tiles=function(){for(var a=0;a<this._tiles.length;a++){this._tiles[a].destroy()}};LevelLoader.prototype._destroy_textures=function(){for(var a=0;a<this._textures.length;a++){this._textures[a].destroy()}};LevelLoader.prototype._destroy_game_objects=function(){for(var a=0;a<this._game_objects.length;a++){this._game_objects[a].remove()}};LevelLoader.prototype._load_textures=function(c){for(var a=0;a<c.length;a+=3){var d=new TexImage(this._loader.get(_texture_data_converter[c[a]]),this._scene.view_info,this._scene.root_node,null,true);d.transform.translate([c[a+1],c[a+2],0]);this._textures.push(d)}};LevelLoader.prototype._load_game_objects=function(f){for(var e=0;e<f.length;e++){var a=f[e][0];var d=[this._scene,this._loader,this._world];for(var h=1;h<f[e].length;h++){d.push(f[e][h])}var c=Class.create(_game_objects_data_converter[a],{initialize:function($super){$super.apply(this,d)}});var j=new c();this._game_objects.push(j)}};LevelLoader.prototype._create_tiles=function(d){for(var c=0;c<d.length;c+=3){var a=d[c]*this._tile_size;var f=(d[c+1]*this._tile_size)-0;var e=new LevelTile(this._scene,this._world,this._loader,this._scene.root_node,_tile_data_converter[d[c+2]],a,f);this._tiles.push(e)}};LevelLoader.prototype.get_player_start_pos=function(){return this._player_start_pos};function LevelTile(h,f,c,e,d,a,i){this._tile_width=64;this._tile_height=64;this._image=new TexImage(c.get(d.texture),h.view_info,e,[this._tile_width,this._tile_height],true);this._image.transform.translate([a,i,0]);this._body=this._create_body(f,a,i)}LevelTile.prototype.destroy=function(){this._image.destroy();this._body.m_world.DestroyBody(this._body);this._body=null};LevelTile.prototype._create_body=function(e,a,f){var d=new b2BoxDef();d.extents.Set(this._tile_width/2,this._tile_height/2);d.restitution=0.3;var c=new b2BodyDef();c.AddShape(d);c.position.Set(a+(this._tile_width/2),f+(this._tile_height/2));return e.CreateBody(c)};(function(){play_sound=function(d,c,e){var f=100;if(c){f=c}f=5;var a=0;if(e){a=e}soundPlayer.play(d,f,a)}})();