Guest User

Untitled

a guest
Jul 22nd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. ;
  2. (function(){
  3.  
  4. var playerName;
  5.  
  6. var skirmish = new networld.Engine({
  7. node: '#skirmish-viewport',
  8. images: {
  9. 'sprites': '/images/sprites.png',
  10. 'crosshairs': '/images/crosshair.png',
  11. 'guns-m4a1': '/images/m4a1.png'
  12. },
  13. loadCursor: function(){
  14. return new networld.Sprite({
  15. x: this.mouse.x,
  16. y: this.mouse.y,
  17. image: {
  18. file: this.images.get('crosshairs'),
  19. crop: {
  20. x: 0,
  21. y: 0,
  22. width:35,
  23. height:36
  24. }
  25. },
  26. width:35,
  27. height:36,
  28. angle:0,
  29. container:this.$node
  30. });
  31. },
  32. loadPlayer: function(){
  33.  
  34. playerName = prompt("Choose a name");
  35.  
  36. this.socket.send({name:playerName,x:0,y:0,angle:0});
  37.  
  38. var sprite = new PlayerSprite({
  39. x:0,
  40. y:0,
  41. angle:0,
  42. width:35,
  43. height:31,
  44. image: {
  45. file: this.images.get('sprites'),
  46. crop: {
  47. x: 0,
  48. y: 38*2,
  49. width: 35,
  50. height: 31
  51. }
  52. },
  53. container:this.$node
  54. });
  55.  
  56. sprite.addGun('m4a1', this.images.get('guns-m4a1'));
  57.  
  58. return sprite;
  59. },
  60. loop: function(){
  61.  
  62. if(this.keys['87']){ //w
  63. this.player.moveUp();
  64. }
  65. if(this.keys['83']){ //s
  66. this.player.moveDown();
  67. }
  68. if(this.keys['65']){ //a
  69. this.player.moveLeft();
  70. }
  71. if(this.keys['68']){ //d
  72. this.player.moveRight();
  73. }
  74. var center = {x: (this.player.x + this.player.width/2), y: (this.player.y + this.player.height/2)};
  75. var dX = this.mouse.x - center.x;
  76. var dY = this.mouse.y - center.y;
  77.  
  78. var radians = Math.atan2(dX, dY);
  79. var angle = (-1 * radians * 180 / Math.PI) + 90;
  80.  
  81. this.player.angle = angle;
  82. this.player.update();
  83.  
  84. for(var name in this.netPlayers){
  85. this.netPlayers[name].update();
  86. }
  87. },
  88. sync: function(){
  89. this.socket.send({name:playerName, x:this.player.x, y:this.player.y, angle:this.player.angle});
  90. },
  91. receiveData: function(data){
  92. for(var name in data){
  93. if(name != playerName){
  94. if(typeof this.netPlayers[name] == 'undefined'){
  95. this.netPlayers[name] = new PlayerSprite({
  96. x:data[name].x,
  97. y:data[name].y,
  98. angle:data[name].angle,
  99. width:35,
  100. height:31,
  101. image: {
  102. file: this.images.get('sprites'),
  103. crop: {
  104. x: 0,
  105. y: 38*2,
  106. width: 35,
  107. height: 31
  108. }
  109. },
  110. container:this.$node
  111. });
  112. this.netPlayers[name].addGun("m4a1", this.images.get('guns-m4a1'));
  113. }else{
  114. this.netPlayers[name].x = data[name].x;
  115. this.netPlayers[name].y = data[name].y;
  116. this.netPlayers[name].angle = data[name].angle;
  117. }
  118. }
  119. }
  120. }
  121. });
  122.  
  123.  
  124. var PlayerSprite = networld.Sprite.extend({
  125. addGun: function(name, image){
  126. switch(name){
  127. case 'm4a1':
  128. default:
  129. this.addLayer({
  130. name: 'gun',
  131. image: image,
  132. width: 42,
  133. height: 42,
  134. cropX: 0,
  135. cropY: 0,
  136. offsetY: -3
  137. });
  138. break;
  139. }
  140. }
  141. });
  142.  
  143. })();
Add Comment
Please, Sign In to add comment