-
Notifications
You must be signed in to change notification settings - Fork 1
/
__game-scripts.js
3 lines (3 loc) · 10.7 KB
/
__game-scripts.js
1
2
3
var PlayerAnimationHandler=pc.createScript("playerAnimationHandler");PlayerAnimationHandler.attributes.add("blendTime",{type:"number",default:.2}),PlayerAnimationHandler.prototype.initialize=function(){var i=this.app;i.keyboard.on(pc.EVENT_KEYDOWN,this.keyChange,this),i.keyboard.on(pc.EVENT_KEYUP,this.keyChange,this),this.direction="Idle",this.setDirection("Idle")},PlayerAnimationHandler.prototype.checkButtons=function(){var i=this.app,e=i.keyboard.isPressed(pc.KEY_W),t=i.keyboard.isPressed(pc.KEY_A),n=i.keyboard.isPressed(pc.KEY_S),r=i.keyboard.isPressed(pc.KEY_D);if(n&&!e)return console.log("SES!!!"),void(t&&!r?this.direction="Run Forward Right":r&&!t?(console.log("DDDD!!!"),this.direction="Run Forward Left"):this.direction="Run Forward");e||n?(console.log("burasi mi"),this.direction=t&&!r?"Run Forward Left":r&&!t?"Run Forward Right":"Run Forward"):this.direction=t&&!r?"Run Left":r&&!t?"Run Right":"Idle"},PlayerAnimationHandler.prototype.keyChange=function(i){var e=this.direction;this.checkButtons(),e!==this.direction&&this.setDirection(this.direction)},PlayerAnimationHandler.prototype.setDirection=function(i){this.direction=i,this.entity.animation.play(i,this.blendTime)};var PlayerMovement=pc.createScript("playerMovement");PlayerMovement.attributes.add("speed",{type:"number",default:.09}),PlayerMovement.prototype.initialize=function(){var e=this.app.root.findByName("Camera");this.cameraScript=e.script.cameraMovement},PlayerMovement.prototype.update=function(e){var t=this.app,r=this.entity.forward,i=this.entity.right,a=!1,s=0,p=0;if(t.keyboard.isPressed(pc.KEY_W)&&(s+=r.x,p+=r.z),t.keyboard.isPressed(pc.KEY_S)&&(s+=r.x,p+=r.z,a=!0),t.keyboard.isPressed(pc.KEY_A)&&(a?(s+=i.x,p+=i.z):(s-=i.x,p-=i.z)),t.keyboard.isPressed(pc.KEY_D)&&(a?(s-=i.x,p-=i.z):(s+=i.x,p+=i.z)),t.keyboard.isPressed(pc.KEY_SPACE)&&this.entity.rigidbody.applyImpulse(0,50,0),0!==s||0!==p){var o,d=new pc.Vec3(s*e,0,p*e);d.normalize().scale(this.speed),d.add(this.entity.getPosition()),o=a?this.cameraScript.eulers.x:this.cameraScript.eulers.x+180;var c=new pc.Vec3(0,o,0);this.entity.rigidbody.teleport(d,c)}};var CameraMovement=pc.createScript("cameraMovement");CameraMovement.attributes.add("mouseSpeed",{type:"number",default:1.4,description:"Mouse Sensitivity"}),CameraMovement.prototype.initialize=function(){this.eulers=new pc.Vec3,this.touchCoords=new pc.Vec2;var e=this.app;e.mouse.on("mousemove",this.onMouseMove,this),e.mouse.on("mousedown",(function(){e.mouse.enablePointerLock()}),this),this.rayEnd=e.root.findByName("RaycastEndPoint")},CameraMovement.prototype.postUpdate=function(e){var t=this.entity.parent,o=this.eulers.x+180,s=this.eulers.y,i=new pc.Vec3(-s,o,0);t.setEulerAngles(i),this.entity.setPosition(this.getWorldPoint()),this.entity.lookAt(t.getPosition())},CameraMovement.prototype.onMouseMove=function(e){pc.Mouse.isPointerLocked()&&(this.eulers.x-=this.mouseSpeed*e.dx/60%360,this.eulers.y+=this.mouseSpeed*e.dy/60%360,this.eulers.x<0&&(this.eulers.x+=360),this.eulers.y<0&&(this.eulers.y+=360))},CameraMovement.prototype.getWorldPoint=function(){var e=this.entity.parent.getPosition(),t=this.rayEnd.getPosition(),o=this.app.systems.rigidbody.raycastFirst(e,t);return o?o.point:t};"undefined"!=typeof document&&(
/*! FPSMeter 0.3.1 - 9th May 2013 | https://github.com/Darsain/fpsmeter */
function(t,e){function s(t,e){for(var n in e)try{t.style[n]=e[n]}catch(t){}return t}function H(t){return null==t?String(t):"object"==typeof t||"function"==typeof t?Object.prototype.toString.call(t).match(/\s([a-z]+)/i)[1].toLowerCase()||"object":typeof t}function R(t,e){if("array"!==H(e))return-1;if(e.indexOf)return e.indexOf(t);for(var n=0,o=e.length;n<o;n++)if(e[n]===t)return n;return-1}function I(){var t,e=arguments;for(t in e[1])if(e[1].hasOwnProperty(t))switch(H(e[1][t])){case"object":e[0][t]=I({},e[0][t],e[1][t]);break;case"array":e[0][t]=e[1][t].slice(0);break;default:e[0][t]=e[1][t]}return 2<e.length?I.apply(null,[e[0]].concat(Array.prototype.slice.call(e,2))):e[0]}function N(t){return 1===(t=Math.round(255*t).toString(16)).length?"0"+t:t}function S(t,e,n,o){t.addEventListener?t[o?"removeEventListener":"addEventListener"](e,n,!1):t.attachEvent&&t[o?"detachEvent":"attachEvent"]("on"+e,n)}function D(t,e){function g(t,e,n,o){return h[0|t][Math.round(Math.min((e-n)/(o-n)*M,M))]}function r(){F.legend.fps!==q&&(F.legend.fps=q,F.legend[c]=q?"FPS":"ms"),b=q?v.fps:v.duration,F.count[c]=999<b?"999+":b.toFixed(99<b?0:O.decimals)}function m(){for(l=n(),P<l-O.threshold&&(v.fps-=v.fps/Math.max(1,60*O.smoothing/O.interval),v.duration=1e3/v.fps),w=O.history;w--;)T[w]=0===w?v.fps:T[w-1],j[w]=0===w?v.duration:j[w-1];if(r(),O.heat){if(z.length)for(w=z.length;w--;)z[w].el.style[o[z[w].name].heatOn]=q?g(o[z[w].name].heatmap,v.fps,0,O.maxFps):g(o[z[w].name].heatmap,v.duration,O.threshold,0);if(F.graph&&o.column.heatOn)for(w=C.length;w--;)C[w].style[o.column.heatOn]=q?g(o.column.heatmap,T[w],0,O.maxFps):g(o.column.heatmap,j[w],O.threshold,0)}if(F.graph)for(y=0;y<O.history;y++)C[y].style.height=(q?T[y]?Math.round(x/O.maxFps*Math.min(T[y],O.maxFps)):0:j[y]?Math.round(x/O.threshold*Math.min(j[y],O.threshold)):0)+"px"}function k(){20>O.interval?(p=i(k),m()):(p=setTimeout(k,O.interval),f=i(m))}function G(t){(t=t||window.event).preventDefault?(t.preventDefault(),t.stopPropagation()):(t.returnValue=!1,t.cancelBubble=!0),v.toggle()}function U(){O.toggleOn&&S(F.container,O.toggleOn,G,1),t.removeChild(F.container)}function V(){if(F.container&&U(),o=D.theme[O.theme],!(h=o.compiledHeatmaps||[]).length&&o.heatmaps.length){for(y=0;y<o.heatmaps.length;y++)for(h[y]=[],w=0;w<=M;w++){var e,n=h[y],a=w;e=.33/M*w;var i=o.heatmaps[y].saturation,l=o.heatmaps[y].lightness,p=void 0,c=void 0,u=void 0,d=u=void 0,f=p=c=void 0;f=void 0;0===(u=.5>=l?l*(1+i):l+i-l*i)?e="#000":(c=(u-(d=2*l-u))/u,f=(e*=6)-(p=Math.floor(e)),f*=u*c,0===p||6===p?(p=u,c=d+f,u=d):1===p?(p=u-f,c=u,u=d):2===p?(p=d,c=u,u=d+f):3===p?(p=d,c=u-f):4===p?(p=d+f,c=d):(p=u,c=d,u-=f),e="#"+N(p)+N(c)+N(u)),n[a]=e}o.compiledHeatmaps=h}for(var b in F.container=s(document.createElement("div"),o.container),F.count=F.container.appendChild(s(document.createElement("div"),o.count)),F.legend=F.container.appendChild(s(document.createElement("div"),o.legend)),F.graph=O.graph?F.container.appendChild(s(document.createElement("div"),o.graph)):0,z.length=0,F)F[b]&&o[b].heatOn&&z.push({name:b,el:F[b]});if(C.length=0,F.graph)for(F.graph.style.width=O.history*o.column.width+(O.history-1)*o.column.spacing+"px",w=0;w<O.history;w++)C[w]=F.graph.appendChild(s(document.createElement("div"),o.column)),C[w].style.position="absolute",C[w].style.bottom=0,C[w].style.right=w*o.column.width+w*o.column.spacing+"px",C[w].style.width=o.column.width+"px",C[w].style.height="0px";s(F.container,O),r(),t.appendChild(F.container),F.graph&&(x=F.graph.clientHeight),O.toggleOn&&("click"===O.toggleOn&&(F.container.style.cursor="pointer"),S(F.container,O.toggleOn,G))}"object"===H(t)&&undefined===t.nodeType&&(e=t,t=document.body),t||(t=document.body);var o,h,l,p,f,x,b,w,y,v=this,O=I({},D.defaults,e||{}),F={},C=[],M=100,z=[],E=O.threshold,A=0,P=n()-E,T=[],j=[],q="fps"===O.show;v.options=O,v.fps=0,v.duration=0,v.isPaused=0,v.tickStart=function(){A=n()},v.tick=function(){l=n(),E+=(l-P-E)/O.smoothing,v.fps=1e3/E,v.duration=A<P?E:l-A,P=l},v.pause=function(){return p&&(v.isPaused=1,clearTimeout(p),a(p),a(f),p=f=0),v},v.resume=function(){return p||(v.isPaused=0,k()),v},v.set=function(t,e){return O[t]=e,q="fps"===O.show,-1!==R(t,u)&&V(),-1!==R(t,d)&&s(F.container,O),v},v.showDuration=function(){return v.set("show","ms"),v},v.showFps=function(){return v.set("show","fps"),v},v.toggle=function(){return v.set("show",q?"ms":"fps"),v},v.hide=function(){return v.pause(),F.container.style.display="none",v},v.show=function(){return v.resume(),F.container.style.display="block",v},v.destroy=function(){v.pause(),U(),v.tick=v.tickStart=function(){}},V(),k()}var n,o=t.performance;n=o&&(o.now||o.webkitNow)?o[o.now?"now":"webkitNow"].bind(o):function(){return+new Date};for(var a=t.cancelAnimationFrame||t.cancelRequestAnimationFrame,i=t.requestAnimationFrame,h=0,l=0,p=(o=["moz","webkit","o"]).length;l<p&&!a;++l)i=(a=t[o[l]+"CancelAnimationFrame"]||t[o[l]+"CancelRequestAnimationFrame"])&&t[o[l]+"RequestAnimationFrame"];a||(i=function(e){var o=n(),a=Math.max(0,16-(o-h));return h=o+a,t.setTimeout((function(){e(o+a)}),a)},a=function(t){clearTimeout(t)});var c="string"===H(document.createElement("div").textContent)?"textContent":"innerText";D.extend=I,window.FPSMeter=D,D.defaults={interval:100,smoothing:10,show:"fps",toggleOn:"click",decimals:1,maxFps:60,threshold:100,position:"absolute",zIndex:10,left:"5px",top:"5px",right:"auto",bottom:"auto",margin:"0 0 0 0",theme:"dark",heat:0,graph:0,history:20};var u=["toggleOn","theme","heat","graph","history"],d="position zIndex left top right bottom margin".split(" ")}(window),function(t,e){e.theme={};var n=e.theme.base={heatmaps:[],container:{heatOn:null,heatmap:null,padding:"5px",minWidth:"95px",height:"30px",lineHeight:"30px",textAlign:"right",textShadow:"none"},count:{heatOn:null,heatmap:null,position:"absolute",top:0,right:0,padding:"5px 10px",height:"30px",fontSize:"24px",fontFamily:"Consolas, Andale Mono, monospace",zIndex:2},legend:{heatOn:null,heatmap:null,position:"absolute",top:0,left:0,padding:"5px 10px",height:"30px",fontSize:"12px",lineHeight:"32px",fontFamily:"sans-serif",textAlign:"left",zIndex:2},graph:{heatOn:null,heatmap:null,position:"relative",boxSizing:"padding-box",MozBoxSizing:"padding-box",height:"100%",zIndex:1},column:{width:4,spacing:1,heatOn:null,heatmap:null}};e.theme.dark=e.extend({},n,{heatmaps:[{saturation:.8,lightness:.8}],container:{background:"#222",color:"#fff",border:"1px solid #1a1a1a",textShadow:"1px 1px 0 #222"},count:{heatOn:"color"},column:{background:"#3f3f3f"}}),e.theme.light=e.extend({},n,{heatmaps:[{saturation:.5,lightness:.5}],container:{color:"#666",background:"#fff",textShadow:"1px 1px 0 rgba(255,255,255,.5), -1px -1px 0 rgba(255,255,255,.5)",boxShadow:"0 0 0 1px rgba(0,0,0,.1)"},count:{heatOn:"color"},column:{background:"#eaeaea"}}),e.theme.colorful=e.extend({},n,{heatmaps:[{saturation:.5,lightness:.6}],container:{heatOn:"backgroundColor",background:"#888",color:"#fff",textShadow:"1px 1px 0 rgba(0,0,0,.2)",boxShadow:"0 0 0 1px rgba(0,0,0,.1)"},column:{background:"#777",backgroundColor:"rgba(0,0,0,.2)"}}),e.theme.transparent=e.extend({},n,{heatmaps:[{saturation:.8,lightness:.5}],container:{padding:0,color:"#fff",textShadow:"1px 1px 0 rgba(0,0,0,.5)"},count:{padding:"0 5px",height:"40px",lineHeight:"40px"},legend:{padding:"0 5px",height:"40px",lineHeight:"42px"},graph:{height:"40px"},column:{width:5,background:"#999",heatOn:"backgroundColor",opacity:.5}})}(window,FPSMeter));var Fps=pc.createScript("fps");Fps.prototype.initialize=function(){this.fps=new FPSMeter({heat:!0,graph:!0})},Fps.prototype.update=function(t){this.fps.tick()};