Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.06 KB | None | 0 0
  1. function GAME(mn){
  2.  
  3. // $(document).ready(function(mn,nm){
  4.  
  5. var user = []; // игрок
  6. var img = []; // картинки
  7. var map = []; // карта
  8. var obj = []; // объекты
  9. var _us = []; // иконка игрока
  10.  
  11. $.ajax({
  12. type: "GET",
  13. url: "/_instalscript/engine/map/server.php",
  14. data: ({mn : mn}),
  15. dataType: "json",
  16. success: function(gm){
  17. img['map'] = gm['map']['img']; // Карта
  18. img['user'] = gm['ui']['img']; // Игрок
  19. map = gm['map']; // ширина карты
  20. // map['height'] = gm['map']['height']; // высота карты
  21. user['x'] = gm['ui']['x']; // игрок по Х
  22. user['y'] = gm['ui']['y']; // игрок по У
  23. user['vin'] = gm['ui']['vin']; // игрок по У
  24. obj = gm['obj']; // Дополнительные объекты
  25. }
  26. ,async:false
  27. });
  28. $('#map').attr('width', map['w']+'px');
  29. $('#map').attr('height', map['h']+'px');
  30. var example = document.getElementById("map"),
  31. ctx = example.getContext('2d'),
  32. _map = new Image();
  33. _map.src = img['map']; // Карта (картинка)
  34. _map.onload = function(){
  35. _user = new Image();
  36. _user.src = img['user']; // иконка игрока
  37. _us['w'] = _user.width; // ширина иконки игрока
  38. _us['h'] = _user.height; // высота иконки игрока
  39. user['sx'] = 0;
  40. user['sy'] = 0;
  41. map['sx'] = map['w'];
  42. map['sy'] = map['h'];
  43. ///////////////// Координата по X ////////////////
  44. if(user['x'] - (map['w']/2) <= 0){
  45. map['sx'] = 0;
  46. user['sx'] = user['x'];
  47. }
  48. else{
  49.  
  50. map['sx'] = user['x'] - map['w'] / 2; // Смещение карты = Положение игрока - половина прогруженной карты
  51. user['sx'] = map['w'] / 2 - _us['w'] / 2; // мещение игрока = половина прогруженной карты - половина иконки игрока
  52.  
  53. if(map['sx'] > map['width'] - map['w']){
  54. map['sx'] = map['width'] - map['w'];
  55. user['sx'] = user['x'] - map['sx'] - _us['w'];
  56. }
  57.  
  58. }
  59. ///////////////// Координата по Y ////////////////
  60. if(user['y'] - map['h']/2 <= 0){
  61. map['sy'] = 0;
  62. user['sy'] = -user['y'];
  63. }
  64. else{
  65. map['sy'] = user['y'] - map['h']/2;
  66. user['sy'] = -(map['h']/2);
  67.  
  68. if(map['sy'] > map['height'] - map['h']){
  69. map['sy'] = map['height'] - map['h'];
  70. user['sy'] = user['y'] - map['sy'] - _us['h'];
  71. user['sy'] = - user['sy'];
  72. }
  73. }
  74. ctx.drawImage(_map, map['sx'], map['sy'], map['w'], map['h'], 0, 0, map['w'], map['h']); // Фон
  75.  
  76. $('#attack-mutant').html("");
  77. $('#place-obj-map').html("");
  78.  
  79. // Объекты
  80. $.each(obj,function(i,val){
  81. img['obj'] = new Image();
  82. img['obj'].src = obj[i]['img'];
  83. obj_x = obj[i]['x'] - map['sx'];
  84. obj_y = obj[i]['y'] - map['sy'];
  85. obj_src = obj[i]['src'];
  86. obj_type = obj[i]['type'];
  87. obj_name = obj[i]['name'];
  88. obj_id = obj[i]['id'];
  89.  
  90. var obj_add = $('#m-obj-map').html();
  91.  
  92. if(obj_x >= 0 && obj_x < map['w'] && obj_y >= 0 && obj_y < map['h']){
  93.  
  94.  
  95. if(obj_type == 'place'){
  96. var text = "<a class = 'lnk-map-place' id = 'place-"+obj_id+"' href = '/is/map/place/" + obj_id + "/'>"+ obj_name + "</a><br>";
  97. $('#place-obj-map').html(text + $('#place-obj-map').html());
  98. }
  99.  
  100. if(obj_type == 'mutant'){
  101.  
  102. // var text = "<a class = '' id = 'mutant-"+obj_id+"' href = '/is/map/attack/" + obj_id + "/'><img src = '"+ obj_src + "'></a>";
  103. var text = "<div class = 'mutant-list'><a id = 'mutant-"+obj_id+"' href = '/is/map/attack/" + obj_id + "/'>"+ obj_name + "</a> <span class = 'mutant-xy' mid = '"+obj_id+"' >[x:"+obj[i]['x']+" y:"+obj[i]['y']+"]</span></div>";
  104. $('#attack-mutant').html(text + $('#attack-mutant').html());
  105. }
  106. }
  107. ctx.drawImage(img['obj'],obj_x,obj_y);
  108. });
  109. if(user['vin']<5){
  110. document.getElementById('top').removeAttribute("onclick");
  111. document.getElementById('lft').removeAttribute("onclick");
  112. document.getElementById('rht').removeAttribute("onclick");
  113. document.getElementById('bot').removeAttribute("onclick");
  114. $('#u-position').html("<a class = 'perehod'><span style = 'color:DarkOrange'><center>У вас не достаточно энергии!</center></span></a>");
  115. }else{
  116. $('#u-position').html("x:" + user['x'] + " y:" + user['y']);
  117. }
  118. ctx.drawImage(_user,user['sx'], -user['sy']);
  119. }
  120. // });
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement