diff --git a/docs/assets/index-c7e87ed6.js b/docs/assets/index-c7e87ed6.js index 531aea1..eaaebc5 100644 --- a/docs/assets/index-c7e87ed6.js +++ b/docs/assets/index-c7e87ed6.js @@ -13200,4 +13200,4 @@ Blob_Info_Q174=vec4(0,0,0,0); #endif float Out_Q255;Remap_Range_B255(0.0,1.0,0.0,1.0,X_Q248,Out_Q255);float X_Q236;float Y_Q236;float Z_Q236;To_XYZ_B228(Nrm_World_Q182,X_Q236,Y_Q236,Z_Q236);vec4 Color_At_T_Q247=mix(Linear_Q251,Linear_Q252,Out_Q255);float Minus_F_Q237=-Z_Q236;float R_Q249;float G_Q249;float B_Q249;float A_Q249;R_Q249=Color_At_T_Q247.r; G_Q249=Color_At_T_Q247.g; B_Q249=Color_At_T_Q247.b; A_Q249=Color_At_T_Q247.a;float ClampF_Q238=clamp(0.0,Minus_F_Q237,1.0);float Result_Q243;Conditional_Float_B243(_Decal_Front_Only_,ClampF_Q238,1.0,Result_Q243);vec4 Vec4_Q239=vec4(Result_Q243,Radial_Gradient_Q280,G_Q249,B_Q249);vec3 Position=Pos_World_Q162;vec3 Normal=Nrm_World_Q182;vec2 UV=XY_Q235;vec3 Tangent=Tangent_World_N_Q177;vec3 Binormal=Difference_Q211;vec4 Color=Out_Color_Q184;vec4 Extra1=Vec4_Q239;vec4 Extra2=Blob_Info_Q173;vec4 Extra3=Blob_Info_Q174;gl_Position=viewProjection*vec4(Position,1);vPosition=Position;vNormal=Normal;vUV=UV;vTangent=Tangent;vBinormal=Binormal;vColor=Color;vExtra1=Extra1;vExtra2=Extra2;vExtra3=Extra3;}`;B.ShaderStore.ShadersStore[C]=w;var X={name:C,shader:w}},"../../../dev/gui/src/3D/vector3WithInfo.ts":(Fe,m,U)=>{U.r(m),U.d(m,{Vector3WithInfo:()=>w});var B=U("../../../../node_modules/tslib/tslib.es6.mjs"),C=U("babylonjs/Misc/perfCounter"),w=function(X){(0,B.__extends)(te,X);function te(I,T){T===void 0&&(T=0);var v=X.call(this,I.x,I.y,I.z)||this;return v.buttonIndex=T,v}return te}(C.Vector3)},"../../../dev/gui/src/index.ts":(Fe,m,U)=>{U.r(m),U.d(m,{AbstractButton3D:()=>C.AbstractButton3D,AdvancedDynamicTexture:()=>B.AdvancedDynamicTexture,AdvancedDynamicTextureInstrumentation:()=>B.AdvancedDynamicTextureInstrumentation,BaseGradient:()=>B.BaseGradient,BaseSlider:()=>B.BaseSlider,Button:()=>B.Button,Button3D:()=>C.Button3D,Checkbox:()=>B.Checkbox,CheckboxGroup:()=>B.CheckboxGroup,ColorPicker:()=>B.ColorPicker,Container:()=>B.Container,Container3D:()=>C.Container3D,Control:()=>B.Control,Control3D:()=>C.Control3D,CornerHandle:()=>C.CornerHandle,CylinderPanel:()=>C.CylinderPanel,DisplayGrid:()=>B.DisplayGrid,Ellipse:()=>B.Ellipse,FluentBackplateMaterial:()=>C.FluentBackplateMaterial,FluentButtonMaterial:()=>C.FluentButtonMaterial,FluentMaterial:()=>C.FluentMaterial,FluentMaterialDefines:()=>C.FluentMaterialDefines,FocusableButton:()=>B.FocusableButton,GUI3DManager:()=>C.GUI3DManager,GizmoHandle:()=>C.GizmoHandle,Grid:()=>B.Grid,HandMenu:()=>C.HandMenu,HandleMaterial:()=>C.HandleMaterial,HandleState:()=>C.HandleState,HolographicBackplate:()=>C.HolographicBackplate,HolographicButton:()=>C.HolographicButton,HolographicSlate:()=>C.HolographicSlate,Image:()=>B.Image,ImageBasedSlider:()=>B.ImageBasedSlider,ImageScrollBar:()=>B.ImageScrollBar,InputPassword:()=>B.InputPassword,InputText:()=>B.InputText,InputTextArea:()=>B.InputTextArea,KeyPropertySet:()=>B.KeyPropertySet,Line:()=>B.Line,LinearGradient:()=>B.LinearGradient,MRDLBackplateMaterial:()=>C.MRDLBackplateMaterial,MRDLSliderBarMaterial:()=>C.MRDLSliderBarMaterial,MRDLSliderThumbMaterial:()=>C.MRDLSliderThumbMaterial,MathTools:()=>B.MathTools,Matrix2D:()=>B.Matrix2D,Measure:()=>B.Measure,MeshButton3D:()=>C.MeshButton3D,MultiLine:()=>B.MultiLine,MultiLinePoint:()=>B.MultiLinePoint,NearMenu:()=>C.NearMenu,PlanePanel:()=>C.PlanePanel,RadialGradient:()=>B.RadialGradient,RadioButton:()=>B.RadioButton,RadioGroup:()=>B.RadioGroup,Rectangle:()=>B.Rectangle,ScatterPanel:()=>C.ScatterPanel,ScrollBar:()=>B.ScrollBar,ScrollViewer:()=>B.ScrollViewer,SelectionPanel:()=>B.SelectionPanel,SelectorGroup:()=>B.SelectorGroup,SideHandle:()=>C.SideHandle,SlateGizmo:()=>C.SlateGizmo,Slider:()=>B.Slider,Slider3D:()=>C.Slider3D,SliderGroup:()=>B.SliderGroup,SpherePanel:()=>C.SpherePanel,StackPanel:()=>B.StackPanel,StackPanel3D:()=>C.StackPanel3D,Style:()=>B.Style,TextBlock:()=>B.TextBlock,TextWrapper:()=>B.TextWrapper,TextWrapping:()=>B.TextWrapping,ToggleButton:()=>B.ToggleButton,TouchButton3D:()=>C.TouchButton3D,TouchHolographicButton:()=>C.TouchHolographicButton,TouchHolographicButtonV3:()=>C.TouchHolographicButtonV3,TouchHolographicMenu:()=>C.TouchHolographicMenu,TouchMeshButton3D:()=>C.TouchMeshButton3D,ValueAndUnit:()=>B.ValueAndUnit,Vector2WithInfo:()=>B.Vector2WithInfo,Vector3WithInfo:()=>C.Vector3WithInfo,VirtualKeyboard:()=>B.VirtualKeyboard,VolumeBasedPanel:()=>C.VolumeBasedPanel,XmlLoader:()=>B.XmlLoader,name:()=>B.name});var B=U("../../../dev/gui/src/2D/index.ts"),C=U("../../../dev/gui/src/3D/index.ts")},"../../../lts/gui/src/legacy/legacy.ts":(Fe,m,U)=>{U.r(m),U.d(m,{AbstractButton3D:()=>B.AbstractButton3D,AdvancedDynamicTexture:()=>B.AdvancedDynamicTexture,AdvancedDynamicTextureInstrumentation:()=>B.AdvancedDynamicTextureInstrumentation,BaseGradient:()=>B.BaseGradient,BaseSlider:()=>B.BaseSlider,Button:()=>B.Button,Button3D:()=>B.Button3D,Checkbox:()=>B.Checkbox,CheckboxGroup:()=>B.CheckboxGroup,ColorPicker:()=>B.ColorPicker,Container:()=>B.Container,Container3D:()=>B.Container3D,Control:()=>B.Control,Control3D:()=>B.Control3D,CornerHandle:()=>B.CornerHandle,CylinderPanel:()=>B.CylinderPanel,DisplayGrid:()=>B.DisplayGrid,Ellipse:()=>B.Ellipse,FluentBackplateMaterial:()=>B.FluentBackplateMaterial,FluentButtonMaterial:()=>B.FluentButtonMaterial,FluentMaterial:()=>B.FluentMaterial,FluentMaterialDefines:()=>B.FluentMaterialDefines,FocusableButton:()=>B.FocusableButton,GUI3DManager:()=>B.GUI3DManager,GizmoHandle:()=>B.GizmoHandle,Grid:()=>B.Grid,HandMenu:()=>B.HandMenu,HandleMaterial:()=>B.HandleMaterial,HandleState:()=>B.HandleState,HolographicBackplate:()=>B.HolographicBackplate,HolographicButton:()=>B.HolographicButton,HolographicSlate:()=>B.HolographicSlate,Image:()=>B.Image,ImageBasedSlider:()=>B.ImageBasedSlider,ImageScrollBar:()=>B.ImageScrollBar,InputPassword:()=>B.InputPassword,InputText:()=>B.InputText,InputTextArea:()=>B.InputTextArea,KeyPropertySet:()=>B.KeyPropertySet,Line:()=>B.Line,LinearGradient:()=>B.LinearGradient,MRDLBackplateMaterial:()=>B.MRDLBackplateMaterial,MRDLSliderBarMaterial:()=>B.MRDLSliderBarMaterial,MRDLSliderThumbMaterial:()=>B.MRDLSliderThumbMaterial,MathTools:()=>B.MathTools,Matrix2D:()=>B.Matrix2D,Measure:()=>B.Measure,MeshButton3D:()=>B.MeshButton3D,MultiLine:()=>B.MultiLine,MultiLinePoint:()=>B.MultiLinePoint,NearMenu:()=>B.NearMenu,PlanePanel:()=>B.PlanePanel,RadialGradient:()=>B.RadialGradient,RadioButton:()=>B.RadioButton,RadioGroup:()=>B.RadioGroup,Rectangle:()=>B.Rectangle,ScatterPanel:()=>B.ScatterPanel,ScrollBar:()=>B.ScrollBar,ScrollViewer:()=>B.ScrollViewer,SelectionPanel:()=>B.SelectionPanel,SelectorGroup:()=>B.SelectorGroup,SideHandle:()=>B.SideHandle,SlateGizmo:()=>B.SlateGizmo,Slider:()=>B.Slider,Slider3D:()=>B.Slider3D,SliderGroup:()=>B.SliderGroup,SpherePanel:()=>B.SpherePanel,StackPanel:()=>B.StackPanel,StackPanel3D:()=>B.StackPanel3D,Style:()=>B.Style,TextBlock:()=>B.TextBlock,TextWrapper:()=>B.TextWrapper,TextWrapping:()=>B.TextWrapping,ToggleButton:()=>B.ToggleButton,TouchButton3D:()=>B.TouchButton3D,TouchHolographicButton:()=>B.TouchHolographicButton,TouchHolographicButtonV3:()=>B.TouchHolographicButtonV3,TouchHolographicMenu:()=>B.TouchHolographicMenu,TouchMeshButton3D:()=>B.TouchMeshButton3D,ValueAndUnit:()=>B.ValueAndUnit,Vector2WithInfo:()=>B.Vector2WithInfo,Vector3WithInfo:()=>B.Vector3WithInfo,VirtualKeyboard:()=>B.VirtualKeyboard,VolumeBasedPanel:()=>B.VolumeBasedPanel,XmlLoader:()=>B.XmlLoader,name:()=>B.name});var B=U("../../../dev/gui/src/index.ts"),C=typeof U.g<"u"?U.g:typeof window<"u"?window:void 0;typeof C<"u"&&(C.BABYLON=C.BABYLON||{},C.BABYLON.GUI||(C.BABYLON.GUI=B))},"babylonjs/Misc/perfCounter":Fe=>{Fe.exports=ie},"../../../../node_modules/tslib/tslib.es6.mjs":(Fe,m,U)=>{U.r(m),U.d(m,{__addDisposableResource:()=>Wt,__assign:()=>w,__asyncDelegator:()=>Oe,__asyncGenerator:()=>$,__asyncValues:()=>z,__await:()=>ne,__awaiter:()=>A,__classPrivateFieldGet:()=>Pi,__classPrivateFieldIn:()=>je,__classPrivateFieldSet:()=>Pe,__createBinding:()=>W,__decorate:()=>te,__disposeResources:()=>wt,__esDecorate:()=>T,__exportStar:()=>K,__extends:()=>C,__generator:()=>R,__importDefault:()=>pi,__importStar:()=>Hi,__makeTemplateObject:()=>Vt,__metadata:()=>P,__param:()=>I,__propKey:()=>f,__read:()=>Q,__rest:()=>X,__runInitializers:()=>v,__setFunctionName:()=>S,__spread:()=>G,__spreadArray:()=>ce,__spreadArrays:()=>g,__values:()=>q,default:()=>pa});var B=function(Z,Re){return B=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(D,Le){D.__proto__=Le}||function(D,Le){for(var Ze in Le)Object.prototype.hasOwnProperty.call(Le,Ze)&&(D[Ze]=Le[Ze])},B(Z,Re)};function C(Z,Re){if(typeof Re!="function"&&Re!==null)throw new TypeError("Class extends value "+String(Re)+" is not a constructor or null");B(Z,Re);function D(){this.constructor=Z}Z.prototype=Re===null?Object.create(Re):(D.prototype=Re.prototype,new D)}var w=function(){return w=Object.assign||function(Re){for(var D,Le=1,Ze=arguments.length;Le=0;St--)(At=Z[St])&&(Je=(Ze<3?At(Je):Ze>3?At(Re,D,Je):At(Re,D))||Je);return Ze>3&&Je&&Object.defineProperty(Re,D,Je),Je}function I(Z,Re){return function(D,Le){Re(D,Le,Z)}}function T(Z,Re,D,Le,Ze,Je){function At(xi){if(xi!==void 0&&typeof xi!="function")throw new TypeError("Function expected");return xi}for(var St=Le.kind,ji=St==="getter"?"get":St==="setter"?"set":"value",Zt=!Re&&Z?Le.static?Z:Z.prototype:null,ue=Re||(Zt?Object.getOwnPropertyDescriptor(Zt,Le.name):{}),tr,ti=!1,or=D.length-1;or>=0;or--){var sn={};for(var Yr in Le)sn[Yr]=Yr==="access"?{}:Le[Yr];for(var Yr in Le.access)sn.access[Yr]=Le.access[Yr];sn.addInitializer=function(xi){if(ti)throw new TypeError("Cannot add initializers after decoration has completed");Je.push(At(xi||null))};var gr=(0,D[or])(St==="accessor"?{get:ue.get,set:ue.set}:ue[ji],sn);if(St==="accessor"){if(gr===void 0)continue;if(gr===null||typeof gr!="object")throw new TypeError("Object expected");(tr=At(gr.get))&&(ue.get=tr),(tr=At(gr.set))&&(ue.set=tr),(tr=At(gr.init))&&Ze.unshift(tr)}else(tr=At(gr))&&(St==="field"?Ze.unshift(tr):ue[ji]=tr)}Zt&&Object.defineProperty(Zt,Le.name,ue),ti=!0}function v(Z,Re,D){for(var Le=arguments.length>2,Ze=0;Ze0&&Je[Je.length-1])&&(Zt[0]===6||Zt[0]===2)){D=0;continue}if(Zt[0]===3&&(!Je||Zt[1]>Je[0]&&Zt[1]=Z.length&&(Z=void 0),{value:Z&&Z[Le++],done:!Z}}};throw new TypeError(Re?"Object is not iterable.":"Symbol.iterator is not defined.")}function Q(Z,Re){var D=typeof Symbol=="function"&&Z[Symbol.iterator];if(!D)return Z;var Le=D.call(Z),Ze,Je=[],At;try{for(;(Re===void 0||Re-- >0)&&!(Ze=Le.next()).done;)Je.push(Ze.value)}catch(St){At={error:St}}finally{try{Ze&&!Ze.done&&(D=Le.return)&&D.call(Le)}finally{if(At)throw At.error}}return Je}function G(){for(var Z=[],Re=0;Re1||St(ti,or)})})}function St(ti,or){try{ji(Le[ti](or))}catch(sn){tr(Je[0][3],sn)}}function ji(ti){ti.value instanceof ne?Promise.resolve(ti.value.v).then(Zt,ue):tr(Je[0][2],ti)}function Zt(ti){St("next",ti)}function ue(ti){St("throw",ti)}function tr(ti,or){ti(or),Je.shift(),Je.length&&St(Je[0][0],Je[0][1])}}function Oe(Z){var Re,D;return Re={},Le("next"),Le("throw",function(Ze){throw Ze}),Le("return"),Re[Symbol.iterator]=function(){return this},Re;function Le(Ze,Je){Re[Ze]=Z[Ze]?function(At){return(D=!D)?{value:ne(Z[Ze](At)),done:!1}:Je?Je(At):At}:Je}}function z(Z){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var Re=Z[Symbol.asyncIterator],D;return Re?Re.call(Z):(Z=typeof q=="function"?q(Z):Z[Symbol.iterator](),D={},Le("next"),Le("throw"),Le("return"),D[Symbol.asyncIterator]=function(){return this},D);function Le(Je){D[Je]=Z[Je]&&function(At){return new Promise(function(St,ji){At=Z[Je](At),Ze(St,ji,At.done,At.value)})}}function Ze(Je,At,St,ji){Promise.resolve(ji).then(function(Zt){Je({value:Zt,done:St})},At)}}function Vt(Z,Re){return Object.defineProperty?Object.defineProperty(Z,"raw",{value:Re}):Z.raw=Re,Z}var Kt=Object.create?function(Z,Re){Object.defineProperty(Z,"default",{enumerable:!0,value:Re})}:function(Z,Re){Z.default=Re};function Hi(Z){if(Z&&Z.__esModule)return Z;var Re={};if(Z!=null)for(var D in Z)D!=="default"&&Object.prototype.hasOwnProperty.call(Z,D)&&W(Re,Z,D);return Kt(Re,Z),Re}function pi(Z){return Z&&Z.__esModule?Z:{default:Z}}function Pi(Z,Re,D,Le){if(D==="a"&&!Le)throw new TypeError("Private accessor was defined without a getter");if(typeof Re=="function"?Z!==Re||!Le:!Re.has(Z))throw new TypeError("Cannot read private member from an object whose class did not declare it");return D==="m"?Le:D==="a"?Le.call(Z):Le?Le.value:Re.get(Z)}function Pe(Z,Re,D,Le,Ze){if(Le==="m")throw new TypeError("Private method is not writable");if(Le==="a"&&!Ze)throw new TypeError("Private accessor was defined without a setter");if(typeof Re=="function"?Z!==Re||!Ze:!Re.has(Z))throw new TypeError("Cannot write private member to an object whose class did not declare it");return Le==="a"?Ze.call(Z,D):Ze?Ze.value=D:Re.set(Z,D),D}function je(Z,Re){if(Re===null||typeof Re!="object"&&typeof Re!="function")throw new TypeError("Cannot use 'in' operator on non-object");return typeof Z=="function"?Re===Z:Z.has(Re)}function Wt(Z,Re,D){if(Re!=null){if(typeof Re!="object"&&typeof Re!="function")throw new TypeError("Object expected.");var Le;if(D){if(!Symbol.asyncDispose)throw new TypeError("Symbol.asyncDispose is not defined.");Le=Re[Symbol.asyncDispose]}if(Le===void 0){if(!Symbol.dispose)throw new TypeError("Symbol.dispose is not defined.");Le=Re[Symbol.dispose]}if(typeof Le!="function")throw new TypeError("Object not disposable.");Z.stack.push({value:Re,dispose:Le,async:D})}else D&&Z.stack.push({async:!0});return Re}var kt=typeof SuppressedError=="function"?SuppressedError:function(Z,Re,D){var Le=new Error(D);return Le.name="SuppressedError",Le.error=Z,Le.suppressed=Re,Le};function wt(Z){function Re(Le){Z.error=Z.hasError?new kt(Le,Z.error,"An error was suppressed during disposal."):Le,Z.hasError=!0}function D(){for(;Z.stack.length;){var Le=Z.stack.pop();try{var Ze=Le.dispose&&Le.dispose.call(Le.value);if(Le.async)return Promise.resolve(Ze).then(D,function(Je){return Re(Je),D()})}catch(Je){Re(Je)}}if(Z.hasError)throw Z.error}return D()}const pa={__extends:C,__assign:w,__rest:X,__decorate:te,__param:I,__metadata:P,__awaiter:A,__generator:R,__createBinding:W,__exportStar:K,__values:q,__read:Q,__spread:G,__spreadArrays:g,__spreadArray:ce,__await:ne,__asyncGenerator:$,__asyncDelegator:Oe,__asyncValues:z,__makeTemplateObject:Vt,__importStar:Hi,__importDefault:pi,__classPrivateFieldGet:Pi,__classPrivateFieldSet:Pe,__classPrivateFieldIn:je,__addDisposableResource:Wt,__disposeResources:wt}}},Ft={};function He(Fe){var m=Ft[Fe];if(m!==void 0)return m.exports;var U=Ft[Fe]={exports:{}};return Qt[Fe](U,U.exports,He),U.exports}He.n=Fe=>{var m=Fe&&Fe.__esModule?()=>Fe.default:()=>Fe;return He.d(m,{a:m}),m},He.d=(Fe,m)=>{for(var U in m)He.o(m,U)&&!He.o(Fe,U)&&Object.defineProperty(Fe,U,{enumerable:!0,get:m[U]})},He.g=function(){if(typeof globalThis=="object")return globalThis;try{return this||new Function("return this")()}catch{if(typeof window=="object")return window}}(),He.o=(Fe,m)=>Object.prototype.hasOwnProperty.call(Fe,m),He.r=Fe=>{typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(Fe,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(Fe,"__esModule",{value:!0})};var ei={};return(()=>{/*!**********************!*\ !*** ./src/index.ts ***! - \**********************/He.r(ei),He.d(ei,{default:()=>m,gui:()=>Fe});var Fe=He("../../../lts/gui/src/legacy/legacy.ts");const m=Fe})(),ei=ei.default,ei})())})(cC);var Ul=cC.exports;class sC{constructor(yt,ie,Qt,Ft,He=!1,ei=null){this.name=yt,this.startPosition=ie,this.scene=Qt,this.shadowGenerator=Ft,this.isGunControlled=He,this.canvas=ei,this.tankMaterial=new Ke.StandardMaterial("tankMaterial",this.scene),this.tankMaterial.diffuseTexture=new Ke.Texture("https://sapienzainteractivegraphicscourse.github.io/final-project-tank-wars//tank.jpg"),this.wheelMaterial=new Ke.StandardMaterial("wheelMaterial",this.scene),this.wheelMaterial.diffuseTexture=new Ke.Texture("https://sapienzainteractivegraphicscourse.github.io/final-project-tank-wars/wheel.png"),this.tankSpeed=.08,this.maxTankSpeed=8,this.rotationSpeed=.02,this.maxRotationSpeed=1,this.breakForce=2,this.gunRotationSpeed=.01,this.steeringAngle=0,this.maxSteeringAngle=Math.PI/4,this.lastBulletTime=0,this.shootGap=100,this.tank=null,this.wheels=[],this.constraints=[],this.advancedTexture=Ul.AdvancedDynamicTexture.CreateFullscreenUI("UI"),this.createTank()}createTank(){this.tank=Ke.MeshBuilder.CreateBox(this.name,{width:3,height:1,depth:3},this.scene),this.tank.position=this.startPosition,this.tank.previousPosition=this.tank.position.clone(),this.tank.material=this.tankMaterial,this.tank.direction=1,this.tank.health=100,this.shadowGenerator.addShadowCaster(this.tank);const yt=Ke.MeshBuilder.CreateBox("leftSideStick",{width:.2,height:1,depth:.2},this.scene);yt.position=new Ke.Vector3(-1.5,.5,0),yt.material=this.tankMaterial,yt.parent=this.tank,this.shadowGenerator.addShadowCaster(yt);const ie=Ke.MeshBuilder.CreateBox("rightSideStick",{width:.2,height:1,depth:.2},this.scene);ie.position=new Ke.Vector3(1.5,.5,0),ie.material=this.tankMaterial,ie.parent=this.tank,this.shadowGenerator.addShadowCaster(ie);const Qt=Ke.MeshBuilder.CreateSphere("turret1",{diameter:1.5},this.scene);Qt.position=new Ke.Vector3(0,.3,0),Qt.material=this.tankMaterial,Qt.parent=this.tank,this.shadowGenerator.addShadowCaster(Qt);const Ft=Ke.MeshBuilder.CreateSphere("turret2",{diameter:.8},this.scene);Ft.position=new Ke.Vector3(0,.6,0),Ft.material=this.tankMaterial,Ft.parent=Qt,this.shadowGenerator.addShadowCaster(Ft);const He=Ke.MeshBuilder.CreateCylinder("gun",{height:3,diameter:.42},this.scene);He.position=new Ke.Vector3(0,-.2,1.2),He.rotation=new Ke.Vector3(Math.PI/2,0,0),He.material=this.tankMaterial,He.parent=Ft,this.shadowGenerator.addShadowCaster(He);const ei=[];ei[0]=new Ke.Vector4(0,0,1,1),ei[1]=new Ke.Vector4(0,.5,0,.5),ei[2]=new Ke.Vector4(0,0,1,1),this.wheels[0]=Ke.MeshBuilder.CreateCylinder("wheel0",{height:.5,diameter:1.2,faceUV:ei},this.scene),this.wheels[0].rotation.z=Math.PI/2,this.wheels[0].position=new Ke.Vector3(-1.8,0,1.3),this.wheels[0].material=this.wheelMaterial,this.shadowGenerator.addShadowCaster(this.wheels[0]),this.wheels[1]=Ke.MeshBuilder.CreateCylinder("wheel1",{height:.5,diameter:1.2,faceUV:ei},this.scene),this.wheels[1].rotation.z=Math.PI/2,this.wheels[1].position=new Ke.Vector3(1.8,0,1.3),this.wheels[1].material=this.wheelMaterial,this.shadowGenerator.addShadowCaster(this.wheels[1]),this.wheels[2]=Ke.MeshBuilder.CreateCylinder("wheel2",{height:.5,diameter:1.2,faceUV:ei},this.scene),this.wheels[2].rotation.z=Math.PI/2,this.wheels[2].position=new Ke.Vector3(-1.8,0,-1.3),this.wheels[2].material=this.wheelMaterial,this.shadowGenerator.addShadowCaster(this.wheels[2]),this.wheels[3]=Ke.MeshBuilder.CreateCylinder("wheel3",{height:.5,diameter:1.2,faceUV:ei},this.scene),this.wheels[3].rotation.z=Math.PI/2,this.wheels[3].position=new Ke.Vector3(1.8,0,-1.3),this.wheels[3].material=this.wheelMaterial,this.shadowGenerator.addShadowCaster(this.wheels[3]);const Fe=new Ke.Mesh("wheelsContainer",this.scene);if(Fe.addChild(this.wheels[0]),Fe.addChild(this.wheels[1]),Fe.addChild(this.wheels[2]),Fe.addChild(this.wheels[3]),Fe.parent=this.tank,this.tank.aggregate=new Ke.PhysicsAggregate(this.tank,Ke.PhysicsShapeType.BOX,{mass:20},this.scene),this.tank.physicsBody=this.tank.aggregate.body,this.tank.physicsBody.setLinearDamping(.5),this.tank.physicsBody.setAngularDamping(1),this.isGunControlled){var m=this;let U;this.canvas.addEventListener("pointermove",function(B){let C=m.scene.pick(m.scene.pointerX,m.scene.pointerY);if(C.hit){let w=new Ke.Vector3(C.pickedPoint.x,C.pickedPoint.y,C.pickedPoint.z);U||(U=w);let X=0,te=.01;const I=()=>{X+=te,U=Ke.Vector3.Lerp(U,w,X),m.rotateGun(U),X<1?requestAnimationFrame(I):U=w};requestAnimationFrame(I)}})}if(this.name!=="player"){const C=new Ul.Rectangle;C.width="100px",C.height="10px",C.color="black",C.thickness=1,C.background="black",C.verticalAlignment=Ul.Rectangle.VERTICAL_ALIGNMENT_CENTER,C.horizontalAlignment=Ul.Rectangle.HORIZONTAL_ALIGNMENT_CENTER,C.isPointerBlocker=!1,this.advancedTexture.addControl(C);const w=new Ul.Rectangle;w.width="0px",w.height="10px",w.color="red",w.thickness=1,w.background="red",w.verticalAlignment=Ul.Rectangle.VERTICAL_ALIGNMENT_CENTER,w.horizontalAlignment=Ul.Rectangle.HORIZONTAL_ALIGNMENT_LEFT,w.isPointerBlocker=!1,this.advancedTexture.addControl(w),this.healthBar=w,C.linkWithMesh(this.tank),C.linkOffsetY=-30,w.linkWithMesh(this.tank),w.linkOffsetY=-30}}transformForce(yt,ie){if(!(this.tank.health<=0)){var Qt=new Ke.Matrix;return yt.rotationQuaternion.toRotationMatrix(Qt),Ke.Vector3.TransformNormal(ie,Qt)}}updateHealthBar(){if(this.tank.health>=0&&this.name!=="player"){const yt=this.tank.health/100,ie=100,Qt=ie*yt;this.healthBar.width=`${Qt}px`;const He=ie/2-Qt/2;this.healthBar.linkOffsetX=`-${He}px`}}rotateGun(yt){if(this.tank.health<=0)return;let ie=new Ke.Vector3(0,0,1),Qt=this.tank.rotationQuaternion.toEulerAngles().y;ie=Ke.Vector3.TransformNormal(ie,Ke.Matrix.RotationAxis(Ke.Axis.Y,Qt));let Ft=yt.subtract(this.tank.getAbsolutePosition());Ft.y=0,Ft.normalize();let He=Math.acos(Ke.Vector3.Dot(ie,Ft));Ke.Vector3.Cross(ie,Ft).y<0&&(He*=-1),He<-1.2&&(He=-1.2),He>1.2&&(He=1.2),this.tank.getChildTransformNodes()[2].rotation.y=He}rotateTank(yt){if(this.tank.health<=0)return;let ie=new Ke.Vector3(0,0,1),Qt=this.tank.rotationQuaternion.toEulerAngles().y;ie=Ke.Vector3.TransformNormal(ie,Ke.Matrix.RotationAxis(Ke.Axis.Y,Qt));let Ft=yt.subtract(this.tank.getAbsolutePosition());Ft.y=0,Ft.normalize();let He=Math.acos(Ke.Vector3.Dot(ie,Ft));this.tank.physicsBody.setAngularVelocity(new Ke.Vector3(0,He,0),this.tank.getAbsolutePosition())}rotate(yt,ie,Qt){if(this.tank.health<=0)return;let Ft=new Ke.Vector3(0,0,0);yt.physicsBody.getAngularVelocityToRef(Ft),!(Ft.length()>this.maxRotationSpeed)&&yt.physicsBody.setAngularVelocity(this.transformForce(yt,ie.scale(Qt)).add(Ft),yt.getAbsolutePosition())}translate(yt,ie,Qt){if(this.tank.health<=0)return;let Ft=new Ke.Vector3(0,0,0);yt.physicsBody.getLinearVelocityToRef(Ft),!(Ft.length()>this.maxTankSpeed)&&yt.physicsBody.setLinearVelocity(this.transformForce(yt,ie.scale(Qt)).add(Ft),yt.getAbsolutePosition())}applyBreak(yt,ie){if(this.tank.health<=0)return;let Qt=new Ke.Vector3(0,0,0);yt.physicsBody.getLinearVelocityToRef(Qt),Qt.scaleInPlace(-1),Qt.normalize(),Qt.scaleInPlace(ie),yt.physicsBody.applyImpulse(Qt,yt.getAbsolutePosition())}createBullet(){if(this.tank.health<=0)return;let yt=Ke.MeshBuilder.CreateCylinder("bullet",{diameter:.2,height:.8},this.scene);yt.material=new Ke.StandardMaterial("bulletMaterial",this.scene),yt.material.diffuseColor=new Ke.Color3(1,.95,.5),this.shadowGenerator.addShadowCaster(yt);let ie=this.tank.getChildTransformNodes()[2].getChildTransformNodes()[0].getChildTransformNodes()[0],Qt=ie.absoluteRotationQuaternion;yt.rotationQuaternion=Qt.clone();let Ft=ie.getDirection(new Ke.Vector3(0,2,0)).scale(1);yt.position=ie.getAbsolutePosition().add(Ft),yt.aggregate=new Ke.PhysicsAggregate(yt,Ke.PhysicsShapeType.CYLINDER,{mass:1},this.scene),yt.physicsBody=yt.aggregate.body;let He=yt.getDirection(new Ke.Vector3(0,1,0));yt.physicsBody.applyImpulse(He.scale(100),yt.getAbsolutePosition());let ei=He.scale(-20);this.tank.physicsBody.applyImpulse(ei,this.tank.getAbsolutePosition()),setTimeout(()=>{if(this.tank&&this.tank.health>0){let m=He.scale(18);this.tank.physicsBody.applyImpulse(m,this.tank.getAbsolutePosition())}},100),yt.physicsBody.setCollisionCallbackEnabled(!0),yt.physicsBody.getCollisionObservable().add(m=>{yt.physicsBody.setCollisionCallbackEnabled(!1),yt.physicsBody.setLinearVelocity(new Ke.Vector3(0,0,0),yt.getAbsolutePosition()),yt.physicsBody.setAngularVelocity(new Ke.Vector3(0,0,0),yt.getAbsolutePosition()),yt.dispose(),(m.collidedAgainst.transformNode.name==="enemy"||m.collidedAgainst.transformNode.name==="player")&&(m.collidedAgainst.transformNode.health-=10)})}update(yt,ie,Qt,Ft,He,ei){if(this.tank.health<=0)return;let Fe=new Ke.Vector3(0,0,0),m=new Ke.Vector3(0,0,0);if(this.tank.physicsBody.getLinearVelocityToRef(Fe),this.tank.physicsBody.getAngularVelocityToRef(m),Fe.length()<.01&&this.tank.physicsBody.setLinearVelocity(new Ke.Vector3(0,0,0),this.tank.getAbsolutePosition()),m.length()<.01&&this.tank.physicsBody.setAngularVelocity(new Ke.Vector3(0,0,0),this.tank.getAbsolutePosition()),yt&&(this.tank.direction=1,this.translate(this.tank,new Ke.Vector3(0,0,1),this.tankSpeed)),ie&&(this.tank.direction=-1,this.translate(this.tank,new Ke.Vector3(0,0,-1),this.tankSpeed)),Ft&&(this.rotate(this.tank,new Ke.Vector3(0,this.tank.direction,0),this.rotationSpeed),this.steeringAngle=Math.min(this.steeringAngle+this.rotationSpeed,this.maxSteeringAngle),this.wheels[0].rotation.y=this.steeringAngle,this.wheels[1].rotation.y=this.steeringAngle,this.wheels[2].rotation.y=this.steeringAngle*.2,this.wheels[3].rotation.y=this.steeringAngle*.2),Qt&&(this.rotate(this.tank,new Ke.Vector3(0,-this.tank.direction,0),this.rotationSpeed),this.steeringAngle=Math.max(this.steeringAngle-this.rotationSpeed,-this.maxSteeringAngle),this.wheels[0].rotation.y=this.steeringAngle,this.wheels[1].rotation.y=this.steeringAngle,this.wheels[2].rotation.y=this.steeringAngle*.2,this.wheels[3].rotation.y=this.steeringAngle*.2),!Qt&&!Ft&&(this.steeringAngle>0?this.steeringAngle=Math.max(this.steeringAngle-this.rotationSpeed,0):this.steeringAngle<0&&(this.steeringAngle=Math.min(this.steeringAngle+this.rotationSpeed,0)),this.wheels[0].rotation.y=this.steeringAngle,this.wheels[1].rotation.y=this.steeringAngle,this.wheels[2].rotation.y=this.steeringAngle*.2,this.wheels[3].rotation.y=this.steeringAngle*.2),He&&this.applyBreak(this.tank,this.breakForce),ei){let C=new Date().getTime();C-this.lastBulletTime>this.shootGap&&(this.lastBulletTime=C,this.createBullet())}let B=Ke.Vector3.Distance(this.tank.position,this.tank.previousPosition)/(this.wheels[0].getBoundingInfo().boundingBox.extendSize.z*Math.PI*2);for(let C of this.wheels)C.rotation.x+=B*this.tank.direction*10;this.tank.previousPosition=this.tank.position.clone(),this.updateHealthBar()}}class BA{constructor(){this._loadingDiv=document.getElementById("loadingScreen"),this._loadingDivProgress=document.getElementById("loadingProgress")}displayLoadingUI(){this._loadingDiv.style.display="initial",this._loadingDivProgress.style.width="0px"}hideLoadingUI(){this._loadingDiv.style.display="none";let yt=document.getElementById("healthBar"),ie=document.getElementById("countScore");yt.style.display="block",ie.style.display="block"}loadingUIVisible(){return this._loadingDiv.style.display=="initial"}updateProgress(yt){this._loadingDivProgress.style.width=yt+"%"}}function FA(){const _n=document.getElementById("renderCanvas");_n.style.display="block";const yt=new Ke.Engine(_n,!0);yt.loadingScreen=new BA;let ie=0,Qt=setInterval(()=>{ie+=Math.random()*.1+.1,yt.loadingScreen.updateProgress(ie*100),ie>=1&&(clearInterval(Qt),yt.loadingScreen.hideLoadingUI())},1e3);(async function(){const He=new Ke.Scene(yt);He.clearColor=new Ke.Color3(1,1,1);const ei=new Ke.ArcRotateCamera("camera",0,0,0,new Ke.Vector3(0,0,0),He);ei.setPosition(new Ke.Vector3(0,35,-25)),ei.target=new Ke.Vector3(0,0,18);const Fe=new Ke.DirectionalLight("dir01",new Ke.Vector3(-2,-2,1),He);Fe.position=new Ke.Vector3(80,120,100);const m=new Ke.HemisphericLight("ambientLight",new Ke.Vector3(0,1,0),He);m.intensity=.5,He.fogMode=Ke.Scene.FOGMODE_EXP,He.fogDensity=.01,He.fogColor=new Ke.Color3(.1,.1,.15);const U=new Ke.ShadowGenerator(1024,Fe);U.useBlurExponentialShadowMap=!0,new Ke.Sound("Music","https://sapienzainteractivegraphicscourse.github.io/final-project-tank-wars/background.mp3",He,null,{loop:!0,autoplay:!0});var B=new Ke.ImageProcessingPostProcess("processing",1,ei);B.vignetteWeight=3,B.vignetteColor=new Ke.Color4(0,0,0,0),B.vignetteEnabled=!0;const C=await DA(),w=new Ke.HavokPlugin(!0,C);He.enablePhysics(new Ke.Vector3(0,-9.8,0),w);const X=new Ke.StandardMaterial("floor",He);X.diffuseTexture=new Ke.Texture("https://sapienzainteractivegraphicscourse.github.io/final-project-tank-wars/wood.jpg");const te=Ke.MeshBuilder.CreateTiledGround("ground",{xmin:-150,zmin:-70,xmax:150,zmax:120,subdivisions:{h:40,w:80}},He);te.receiveShadows=!0,te.material=X,te.aggregate=new Ke.PhysicsAggregate(te,Ke.PhysicsShapeType.BOX,{mass:0},He),He.obstacles=new NA(He,U),He.playerTank=new sC("player",new Ke.Vector3(0,2,10),He,U,!0,_n),He.enemies=[];var I=!1,T=!1,v=!1,f=!1,S=!1,P=!1;window.addEventListener("keydown",function(q){switch(q.keyCode){case 87:I=!0;break;case 83:T=!0;break;case 65:v=!0;break;case 68:f=!0;break;case 32:S=!0;break;case 70:P=!0;break}}),window.addEventListener("keyup",function(q){switch(q.keyCode){case 87:I=!1;break;case 83:T=!1;break;case 65:v=!1;break;case 68:f=!1;break;case 32:S=!1;break;case 70:P=!1;break}}),window.addEventListener("pointerdown",function(q){P=!0}),window.addEventListener("pointerup",function(q){P=!1});function A(q,Q){return Math.random()*(Q-q)+q}function R(){let q=A(-25,25),Q=A(42,47),G=new sC("enemy",new Ke.Vector3(q,2,Q),He,U,!1);G.shootGap=Math.random()*200+200;let g=He.enemies.length;He.enemies.push({enemyTank:G,enemyMoveForward:!0,enemyMoveBackward:!1,enemyRotateLeft:!0,enemyRotateRight:!1,enemyPressBreak:!1,enemyIsShoot:!1,updateIntervel:setInterval(()=>{let ce=Math.random();ce<.25?(He.enemies[g].enemyMoveForward=!0,He.enemies[g].enemyMoveBackward=!1,He.enemies[g].enemyRotateLeft=Math.random()<.2,He.enemies[g].enemyRotateRight=!1,He.enemies[g].enemyPressBreak=!1):ce<.5?(He.enemies[g].enemyMoveForward=!0,He.enemies[g].enemyMoveBackward=!1,He.enemies[g].enemyRotateLeft=!1,He.enemies[g].enemyRotateRight=Math.random()<.2,He.enemies[g].enemyPressBreak=!1):ce<.75?(He.enemies[g].enemyMoveForward=!1,He.enemies[g].enemyMoveBackward=!0,He.enemies[g].enemyRotateLeft=Math.random()<.2,He.enemies[g].enemyRotateRight=!1,He.enemies[g].enemyPressBreak=!1):(He.enemies[g].enemyMoveForward=!1,He.enemies[g].enemyMoveBackward=!0,He.enemies[g].enemyRotateLeft=!1,He.enemies[g].enemyRotateRight=Math.random()<.2,He.enemies[g].enemyPressBreak=!1)},5e3)})}R();let W=1,K=0;return He.registerBeforeRender(function(){He.playerTank.update(I,T,v,f,S,P);for(let Q=0;Q=0&&(q.style.width=He.playerTank.tank.health+"%"),He.playerTank.tank.health<=0&&(yt.stopRenderLoop(),setTimeout(()=>{let Q=document.getElementById("healthBar");Q.style.display="none";let G=document.getElementById("countScore");G.style.display="none";let g=document.getElementById("gameOverScreen");g.style.display="block";let ce=document.getElementById("message");ce.innerHTML="You Lose! Final Score:"+K},2e3))}),He})().then(He=>{yt.runRenderLoop(function(){He.render()}),window.addEventListener("resize",function(){yt.resize()})})}let LA=document.getElementById("startBtn");LA.addEventListener("click",()=>{let _n=document.getElementById("main");_n.style.display="none";let yt=document.getElementById("loadingScreen");yt.style.display="block",FA()}); + \**********************/He.r(ei),He.d(ei,{default:()=>m,gui:()=>Fe});var Fe=He("../../../lts/gui/src/legacy/legacy.ts");const m=Fe})(),ei=ei.default,ei})())})(cC);var Ul=cC.exports;class sC{constructor(yt,ie,Qt,Ft,He=!1,ei=null){this.name=yt,this.startPosition=ie,this.scene=Qt,this.shadowGenerator=Ft,this.isGunControlled=He,this.canvas=ei,this.tankMaterial=new Ke.StandardMaterial("tankMaterial",this.scene),this.tankMaterial.diffuseTexture=new Ke.Texture("https://sapienzainteractivegraphicscourse.github.io/final-project-tank-wars/tank.jpg"),this.wheelMaterial=new Ke.StandardMaterial("wheelMaterial",this.scene),this.wheelMaterial.diffuseTexture=new Ke.Texture("https://sapienzainteractivegraphicscourse.github.io/final-project-tank-wars/wheel.png"),this.tankSpeed=.08,this.maxTankSpeed=8,this.rotationSpeed=.02,this.maxRotationSpeed=1,this.breakForce=2,this.gunRotationSpeed=.01,this.steeringAngle=0,this.maxSteeringAngle=Math.PI/4,this.lastBulletTime=0,this.shootGap=100,this.tank=null,this.wheels=[],this.constraints=[],this.advancedTexture=Ul.AdvancedDynamicTexture.CreateFullscreenUI("UI"),this.createTank()}createTank(){this.tank=Ke.MeshBuilder.CreateBox(this.name,{width:3,height:1,depth:3},this.scene),this.tank.position=this.startPosition,this.tank.previousPosition=this.tank.position.clone(),this.tank.material=this.tankMaterial,this.tank.direction=1,this.tank.health=100,this.shadowGenerator.addShadowCaster(this.tank);const yt=Ke.MeshBuilder.CreateBox("leftSideStick",{width:.2,height:1,depth:.2},this.scene);yt.position=new Ke.Vector3(-1.5,.5,0),yt.material=this.tankMaterial,yt.parent=this.tank,this.shadowGenerator.addShadowCaster(yt);const ie=Ke.MeshBuilder.CreateBox("rightSideStick",{width:.2,height:1,depth:.2},this.scene);ie.position=new Ke.Vector3(1.5,.5,0),ie.material=this.tankMaterial,ie.parent=this.tank,this.shadowGenerator.addShadowCaster(ie);const Qt=Ke.MeshBuilder.CreateSphere("turret1",{diameter:1.5},this.scene);Qt.position=new Ke.Vector3(0,.3,0),Qt.material=this.tankMaterial,Qt.parent=this.tank,this.shadowGenerator.addShadowCaster(Qt);const Ft=Ke.MeshBuilder.CreateSphere("turret2",{diameter:.8},this.scene);Ft.position=new Ke.Vector3(0,.6,0),Ft.material=this.tankMaterial,Ft.parent=Qt,this.shadowGenerator.addShadowCaster(Ft);const He=Ke.MeshBuilder.CreateCylinder("gun",{height:3,diameter:.42},this.scene);He.position=new Ke.Vector3(0,-.2,1.2),He.rotation=new Ke.Vector3(Math.PI/2,0,0),He.material=this.tankMaterial,He.parent=Ft,this.shadowGenerator.addShadowCaster(He);const ei=[];ei[0]=new Ke.Vector4(0,0,1,1),ei[1]=new Ke.Vector4(0,.5,0,.5),ei[2]=new Ke.Vector4(0,0,1,1),this.wheels[0]=Ke.MeshBuilder.CreateCylinder("wheel0",{height:.5,diameter:1.2,faceUV:ei},this.scene),this.wheels[0].rotation.z=Math.PI/2,this.wheels[0].position=new Ke.Vector3(-1.8,0,1.3),this.wheels[0].material=this.wheelMaterial,this.shadowGenerator.addShadowCaster(this.wheels[0]),this.wheels[1]=Ke.MeshBuilder.CreateCylinder("wheel1",{height:.5,diameter:1.2,faceUV:ei},this.scene),this.wheels[1].rotation.z=Math.PI/2,this.wheels[1].position=new Ke.Vector3(1.8,0,1.3),this.wheels[1].material=this.wheelMaterial,this.shadowGenerator.addShadowCaster(this.wheels[1]),this.wheels[2]=Ke.MeshBuilder.CreateCylinder("wheel2",{height:.5,diameter:1.2,faceUV:ei},this.scene),this.wheels[2].rotation.z=Math.PI/2,this.wheels[2].position=new Ke.Vector3(-1.8,0,-1.3),this.wheels[2].material=this.wheelMaterial,this.shadowGenerator.addShadowCaster(this.wheels[2]),this.wheels[3]=Ke.MeshBuilder.CreateCylinder("wheel3",{height:.5,diameter:1.2,faceUV:ei},this.scene),this.wheels[3].rotation.z=Math.PI/2,this.wheels[3].position=new Ke.Vector3(1.8,0,-1.3),this.wheels[3].material=this.wheelMaterial,this.shadowGenerator.addShadowCaster(this.wheels[3]);const Fe=new Ke.Mesh("wheelsContainer",this.scene);if(Fe.addChild(this.wheels[0]),Fe.addChild(this.wheels[1]),Fe.addChild(this.wheels[2]),Fe.addChild(this.wheels[3]),Fe.parent=this.tank,this.tank.aggregate=new Ke.PhysicsAggregate(this.tank,Ke.PhysicsShapeType.BOX,{mass:20},this.scene),this.tank.physicsBody=this.tank.aggregate.body,this.tank.physicsBody.setLinearDamping(.5),this.tank.physicsBody.setAngularDamping(1),this.isGunControlled){var m=this;let U;this.canvas.addEventListener("pointermove",function(B){let C=m.scene.pick(m.scene.pointerX,m.scene.pointerY);if(C.hit){let w=new Ke.Vector3(C.pickedPoint.x,C.pickedPoint.y,C.pickedPoint.z);U||(U=w);let X=0,te=.01;const I=()=>{X+=te,U=Ke.Vector3.Lerp(U,w,X),m.rotateGun(U),X<1?requestAnimationFrame(I):U=w};requestAnimationFrame(I)}})}if(this.name!=="player"){const C=new Ul.Rectangle;C.width="100px",C.height="10px",C.color="black",C.thickness=1,C.background="black",C.verticalAlignment=Ul.Rectangle.VERTICAL_ALIGNMENT_CENTER,C.horizontalAlignment=Ul.Rectangle.HORIZONTAL_ALIGNMENT_CENTER,C.isPointerBlocker=!1,this.advancedTexture.addControl(C);const w=new Ul.Rectangle;w.width="0px",w.height="10px",w.color="red",w.thickness=1,w.background="red",w.verticalAlignment=Ul.Rectangle.VERTICAL_ALIGNMENT_CENTER,w.horizontalAlignment=Ul.Rectangle.HORIZONTAL_ALIGNMENT_LEFT,w.isPointerBlocker=!1,this.advancedTexture.addControl(w),this.healthBar=w,C.linkWithMesh(this.tank),C.linkOffsetY=-30,w.linkWithMesh(this.tank),w.linkOffsetY=-30}}transformForce(yt,ie){if(!(this.tank.health<=0)){var Qt=new Ke.Matrix;return yt.rotationQuaternion.toRotationMatrix(Qt),Ke.Vector3.TransformNormal(ie,Qt)}}updateHealthBar(){if(this.tank.health>=0&&this.name!=="player"){const yt=this.tank.health/100,ie=100,Qt=ie*yt;this.healthBar.width=`${Qt}px`;const He=ie/2-Qt/2;this.healthBar.linkOffsetX=`-${He}px`}}rotateGun(yt){if(this.tank.health<=0)return;let ie=new Ke.Vector3(0,0,1),Qt=this.tank.rotationQuaternion.toEulerAngles().y;ie=Ke.Vector3.TransformNormal(ie,Ke.Matrix.RotationAxis(Ke.Axis.Y,Qt));let Ft=yt.subtract(this.tank.getAbsolutePosition());Ft.y=0,Ft.normalize();let He=Math.acos(Ke.Vector3.Dot(ie,Ft));Ke.Vector3.Cross(ie,Ft).y<0&&(He*=-1),He<-1.2&&(He=-1.2),He>1.2&&(He=1.2),this.tank.getChildTransformNodes()[2].rotation.y=He}rotateTank(yt){if(this.tank.health<=0)return;let ie=new Ke.Vector3(0,0,1),Qt=this.tank.rotationQuaternion.toEulerAngles().y;ie=Ke.Vector3.TransformNormal(ie,Ke.Matrix.RotationAxis(Ke.Axis.Y,Qt));let Ft=yt.subtract(this.tank.getAbsolutePosition());Ft.y=0,Ft.normalize();let He=Math.acos(Ke.Vector3.Dot(ie,Ft));this.tank.physicsBody.setAngularVelocity(new Ke.Vector3(0,He,0),this.tank.getAbsolutePosition())}rotate(yt,ie,Qt){if(this.tank.health<=0)return;let Ft=new Ke.Vector3(0,0,0);yt.physicsBody.getAngularVelocityToRef(Ft),!(Ft.length()>this.maxRotationSpeed)&&yt.physicsBody.setAngularVelocity(this.transformForce(yt,ie.scale(Qt)).add(Ft),yt.getAbsolutePosition())}translate(yt,ie,Qt){if(this.tank.health<=0)return;let Ft=new Ke.Vector3(0,0,0);yt.physicsBody.getLinearVelocityToRef(Ft),!(Ft.length()>this.maxTankSpeed)&&yt.physicsBody.setLinearVelocity(this.transformForce(yt,ie.scale(Qt)).add(Ft),yt.getAbsolutePosition())}applyBreak(yt,ie){if(this.tank.health<=0)return;let Qt=new Ke.Vector3(0,0,0);yt.physicsBody.getLinearVelocityToRef(Qt),Qt.scaleInPlace(-1),Qt.normalize(),Qt.scaleInPlace(ie),yt.physicsBody.applyImpulse(Qt,yt.getAbsolutePosition())}createBullet(){if(this.tank.health<=0)return;let yt=Ke.MeshBuilder.CreateCylinder("bullet",{diameter:.2,height:.8},this.scene);yt.material=new Ke.StandardMaterial("bulletMaterial",this.scene),yt.material.diffuseColor=new Ke.Color3(1,.95,.5),this.shadowGenerator.addShadowCaster(yt);let ie=this.tank.getChildTransformNodes()[2].getChildTransformNodes()[0].getChildTransformNodes()[0],Qt=ie.absoluteRotationQuaternion;yt.rotationQuaternion=Qt.clone();let Ft=ie.getDirection(new Ke.Vector3(0,2,0)).scale(1);yt.position=ie.getAbsolutePosition().add(Ft),yt.aggregate=new Ke.PhysicsAggregate(yt,Ke.PhysicsShapeType.CYLINDER,{mass:1},this.scene),yt.physicsBody=yt.aggregate.body;let He=yt.getDirection(new Ke.Vector3(0,1,0));yt.physicsBody.applyImpulse(He.scale(100),yt.getAbsolutePosition());let ei=He.scale(-20);this.tank.physicsBody.applyImpulse(ei,this.tank.getAbsolutePosition()),setTimeout(()=>{if(this.tank&&this.tank.health>0){let m=He.scale(18);this.tank.physicsBody.applyImpulse(m,this.tank.getAbsolutePosition())}},100),yt.physicsBody.setCollisionCallbackEnabled(!0),yt.physicsBody.getCollisionObservable().add(m=>{yt.physicsBody.setCollisionCallbackEnabled(!1),yt.physicsBody.setLinearVelocity(new Ke.Vector3(0,0,0),yt.getAbsolutePosition()),yt.physicsBody.setAngularVelocity(new Ke.Vector3(0,0,0),yt.getAbsolutePosition()),yt.dispose(),(m.collidedAgainst.transformNode.name==="enemy"||m.collidedAgainst.transformNode.name==="player")&&(m.collidedAgainst.transformNode.health-=10)})}update(yt,ie,Qt,Ft,He,ei){if(this.tank.health<=0)return;let Fe=new Ke.Vector3(0,0,0),m=new Ke.Vector3(0,0,0);if(this.tank.physicsBody.getLinearVelocityToRef(Fe),this.tank.physicsBody.getAngularVelocityToRef(m),Fe.length()<.01&&this.tank.physicsBody.setLinearVelocity(new Ke.Vector3(0,0,0),this.tank.getAbsolutePosition()),m.length()<.01&&this.tank.physicsBody.setAngularVelocity(new Ke.Vector3(0,0,0),this.tank.getAbsolutePosition()),yt&&(this.tank.direction=1,this.translate(this.tank,new Ke.Vector3(0,0,1),this.tankSpeed)),ie&&(this.tank.direction=-1,this.translate(this.tank,new Ke.Vector3(0,0,-1),this.tankSpeed)),Ft&&(this.rotate(this.tank,new Ke.Vector3(0,this.tank.direction,0),this.rotationSpeed),this.steeringAngle=Math.min(this.steeringAngle+this.rotationSpeed,this.maxSteeringAngle),this.wheels[0].rotation.y=this.steeringAngle,this.wheels[1].rotation.y=this.steeringAngle,this.wheels[2].rotation.y=this.steeringAngle*.2,this.wheels[3].rotation.y=this.steeringAngle*.2),Qt&&(this.rotate(this.tank,new Ke.Vector3(0,-this.tank.direction,0),this.rotationSpeed),this.steeringAngle=Math.max(this.steeringAngle-this.rotationSpeed,-this.maxSteeringAngle),this.wheels[0].rotation.y=this.steeringAngle,this.wheels[1].rotation.y=this.steeringAngle,this.wheels[2].rotation.y=this.steeringAngle*.2,this.wheels[3].rotation.y=this.steeringAngle*.2),!Qt&&!Ft&&(this.steeringAngle>0?this.steeringAngle=Math.max(this.steeringAngle-this.rotationSpeed,0):this.steeringAngle<0&&(this.steeringAngle=Math.min(this.steeringAngle+this.rotationSpeed,0)),this.wheels[0].rotation.y=this.steeringAngle,this.wheels[1].rotation.y=this.steeringAngle,this.wheels[2].rotation.y=this.steeringAngle*.2,this.wheels[3].rotation.y=this.steeringAngle*.2),He&&this.applyBreak(this.tank,this.breakForce),ei){let C=new Date().getTime();C-this.lastBulletTime>this.shootGap&&(this.lastBulletTime=C,this.createBullet())}let B=Ke.Vector3.Distance(this.tank.position,this.tank.previousPosition)/(this.wheels[0].getBoundingInfo().boundingBox.extendSize.z*Math.PI*2);for(let C of this.wheels)C.rotation.x+=B*this.tank.direction*10;this.tank.previousPosition=this.tank.position.clone(),this.updateHealthBar()}}class BA{constructor(){this._loadingDiv=document.getElementById("loadingScreen"),this._loadingDivProgress=document.getElementById("loadingProgress")}displayLoadingUI(){this._loadingDiv.style.display="initial",this._loadingDivProgress.style.width="0px"}hideLoadingUI(){this._loadingDiv.style.display="none";let yt=document.getElementById("healthBar"),ie=document.getElementById("countScore");yt.style.display="block",ie.style.display="block"}loadingUIVisible(){return this._loadingDiv.style.display=="initial"}updateProgress(yt){this._loadingDivProgress.style.width=yt+"%"}}function FA(){const _n=document.getElementById("renderCanvas");_n.style.display="block";const yt=new Ke.Engine(_n,!0);yt.loadingScreen=new BA;let ie=0,Qt=setInterval(()=>{ie+=Math.random()*.1+.1,yt.loadingScreen.updateProgress(ie*100),ie>=1&&(clearInterval(Qt),yt.loadingScreen.hideLoadingUI())},1e3);(async function(){const He=new Ke.Scene(yt);He.clearColor=new Ke.Color3(1,1,1);const ei=new Ke.ArcRotateCamera("camera",0,0,0,new Ke.Vector3(0,0,0),He);ei.setPosition(new Ke.Vector3(0,35,-25)),ei.target=new Ke.Vector3(0,0,18);const Fe=new Ke.DirectionalLight("dir01",new Ke.Vector3(-2,-2,1),He);Fe.position=new Ke.Vector3(80,120,100);const m=new Ke.HemisphericLight("ambientLight",new Ke.Vector3(0,1,0),He);m.intensity=.5,He.fogMode=Ke.Scene.FOGMODE_EXP,He.fogDensity=.01,He.fogColor=new Ke.Color3(.1,.1,.15);const U=new Ke.ShadowGenerator(1024,Fe);U.useBlurExponentialShadowMap=!0,new Ke.Sound("Music","https://sapienzainteractivegraphicscourse.github.io/final-project-tank-wars/background.mp3",He,null,{loop:!0,autoplay:!0});var B=new Ke.ImageProcessingPostProcess("processing",1,ei);B.vignetteWeight=3,B.vignetteColor=new Ke.Color4(0,0,0,0),B.vignetteEnabled=!0;const C=await DA(),w=new Ke.HavokPlugin(!0,C);He.enablePhysics(new Ke.Vector3(0,-9.8,0),w);const X=new Ke.StandardMaterial("floor",He);X.diffuseTexture=new Ke.Texture("https://sapienzainteractivegraphicscourse.github.io/final-project-tank-wars/wood.jpg");const te=Ke.MeshBuilder.CreateTiledGround("ground",{xmin:-150,zmin:-70,xmax:150,zmax:120,subdivisions:{h:40,w:80}},He);te.receiveShadows=!0,te.material=X,te.aggregate=new Ke.PhysicsAggregate(te,Ke.PhysicsShapeType.BOX,{mass:0},He),He.obstacles=new NA(He,U),He.playerTank=new sC("player",new Ke.Vector3(0,2,10),He,U,!0,_n),He.enemies=[];var I=!1,T=!1,v=!1,f=!1,S=!1,P=!1;window.addEventListener("keydown",function(q){switch(q.keyCode){case 87:I=!0;break;case 83:T=!0;break;case 65:v=!0;break;case 68:f=!0;break;case 32:S=!0;break;case 70:P=!0;break}}),window.addEventListener("keyup",function(q){switch(q.keyCode){case 87:I=!1;break;case 83:T=!1;break;case 65:v=!1;break;case 68:f=!1;break;case 32:S=!1;break;case 70:P=!1;break}}),window.addEventListener("pointerdown",function(q){P=!0}),window.addEventListener("pointerup",function(q){P=!1});function A(q,Q){return Math.random()*(Q-q)+q}function R(){let q=A(-25,25),Q=A(42,47),G=new sC("enemy",new Ke.Vector3(q,2,Q),He,U,!1);G.shootGap=Math.random()*200+200;let g=He.enemies.length;He.enemies.push({enemyTank:G,enemyMoveForward:!0,enemyMoveBackward:!1,enemyRotateLeft:!0,enemyRotateRight:!1,enemyPressBreak:!1,enemyIsShoot:!1,updateIntervel:setInterval(()=>{let ce=Math.random();ce<.25?(He.enemies[g].enemyMoveForward=!0,He.enemies[g].enemyMoveBackward=!1,He.enemies[g].enemyRotateLeft=Math.random()<.2,He.enemies[g].enemyRotateRight=!1,He.enemies[g].enemyPressBreak=!1):ce<.5?(He.enemies[g].enemyMoveForward=!0,He.enemies[g].enemyMoveBackward=!1,He.enemies[g].enemyRotateLeft=!1,He.enemies[g].enemyRotateRight=Math.random()<.2,He.enemies[g].enemyPressBreak=!1):ce<.75?(He.enemies[g].enemyMoveForward=!1,He.enemies[g].enemyMoveBackward=!0,He.enemies[g].enemyRotateLeft=Math.random()<.2,He.enemies[g].enemyRotateRight=!1,He.enemies[g].enemyPressBreak=!1):(He.enemies[g].enemyMoveForward=!1,He.enemies[g].enemyMoveBackward=!0,He.enemies[g].enemyRotateLeft=!1,He.enemies[g].enemyRotateRight=Math.random()<.2,He.enemies[g].enemyPressBreak=!1)},5e3)})}R();let W=1,K=0;return He.registerBeforeRender(function(){He.playerTank.update(I,T,v,f,S,P);for(let Q=0;Q=0&&(q.style.width=He.playerTank.tank.health+"%"),He.playerTank.tank.health<=0&&(yt.stopRenderLoop(),setTimeout(()=>{let Q=document.getElementById("healthBar");Q.style.display="none";let G=document.getElementById("countScore");G.style.display="none";let g=document.getElementById("gameOverScreen");g.style.display="block";let ce=document.getElementById("message");ce.innerHTML="You Lose! Final Score:"+K},2e3))}),He})().then(He=>{yt.runRenderLoop(function(){He.render()}),window.addEventListener("resize",function(){yt.resize()})})}let LA=document.getElementById("startBtn");LA.addEventListener("click",()=>{let _n=document.getElementById("main");_n.style.display="none";let yt=document.getElementById("loadingScreen");yt.style.display="block",FA()});