Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function GAME(mn){
- // $(document).ready(function(mn,nm){
- var user = []; // игрок
- var img = []; // картинки
- var map = []; // карта
- var obj = []; // объекты
- var _us = []; // иконка игрока
- $.ajax({
- type: "GET",
- url: "/_instalscript/engine/map/server.php",
- data: ({mn : mn}),
- dataType: "json",
- success: function(gm){
- img['map'] = gm['map']['img']; // Карта
- img['user'] = gm['ui']['img']; // Игрок
- map = gm['map']; // ширина карты
- // map['height'] = gm['map']['height']; // высота карты
- user['x'] = gm['ui']['x']; // игрок по Х
- user['y'] = gm['ui']['y']; // игрок по У
- user['vin'] = gm['ui']['vin']; // игрок по У
- obj = gm['obj']; // Дополнительные объекты
- }
- ,async:false
- });
- $('#map').attr('width', map['w']+'px');
- $('#map').attr('height', map['h']+'px');
- var example = document.getElementById("map"),
- ctx = example.getContext('2d'),
- _map = new Image();
- _map.src = img['map']; // Карта (картинка)
- _map.onload = function(){
- _user = new Image();
- _user.src = img['user']; // иконка игрока
- _us['w'] = _user.width; // ширина иконки игрока
- _us['h'] = _user.height; // высота иконки игрока
- user['sx'] = 0;
- user['sy'] = 0;
- map['sx'] = map['w'];
- map['sy'] = map['h'];
- ///////////////// Координата по X ////////////////
- if(user['x'] - (map['w']/2) <= 0){
- map['sx'] = 0;
- user['sx'] = user['x'];
- }
- else{
- map['sx'] = user['x'] - map['w'] / 2; // Смещение карты = Положение игрока - половина прогруженной карты
- user['sx'] = map['w'] / 2 - _us['w'] / 2; // мещение игрока = половина прогруженной карты - половина иконки игрока
- if(map['sx'] > map['width'] - map['w']){
- map['sx'] = map['width'] - map['w'];
- user['sx'] = user['x'] - map['sx'] - _us['w'];
- }
- }
- ///////////////// Координата по Y ////////////////
- if(user['y'] - map['h']/2 <= 0){
- map['sy'] = 0;
- user['sy'] = -user['y'];
- }
- else{
- map['sy'] = user['y'] - map['h']/2;
- user['sy'] = -(map['h']/2);
- if(map['sy'] > map['height'] - map['h']){
- map['sy'] = map['height'] - map['h'];
- user['sy'] = user['y'] - map['sy'] - _us['h'];
- user['sy'] = - user['sy'];
- }
- }
- ctx.drawImage(_map, map['sx'], map['sy'], map['w'], map['h'], 0, 0, map['w'], map['h']); // Фон
- $('#attack-mutant').html("");
- $('#place-obj-map').html("");
- // Объекты
- $.each(obj,function(i,val){
- img['obj'] = new Image();
- img['obj'].src = obj[i]['img'];
- obj_x = obj[i]['x'] - map['sx'];
- obj_y = obj[i]['y'] - map['sy'];
- obj_src = obj[i]['src'];
- obj_type = obj[i]['type'];
- obj_name = obj[i]['name'];
- obj_id = obj[i]['id'];
- var obj_add = $('#m-obj-map').html();
- if(obj_x >= 0 && obj_x < map['w'] && obj_y >= 0 && obj_y < map['h']){
- if(obj_type == 'place'){
- var text = "<a class = 'lnk-map-place' id = 'place-"+obj_id+"' href = '/is/map/place/" + obj_id + "/'>"+ obj_name + "</a><br>";
- $('#place-obj-map').html(text + $('#place-obj-map').html());
- }
- if(obj_type == 'mutant'){
- // var text = "<a class = '' id = 'mutant-"+obj_id+"' href = '/is/map/attack/" + obj_id + "/'><img src = '"+ obj_src + "'></a>";
- 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>";
- $('#attack-mutant').html(text + $('#attack-mutant').html());
- }
- }
- ctx.drawImage(img['obj'],obj_x,obj_y);
- });
- if(user['vin']<5){
- document.getElementById('top').removeAttribute("onclick");
- document.getElementById('lft').removeAttribute("onclick");
- document.getElementById('rht').removeAttribute("onclick");
- document.getElementById('bot').removeAttribute("onclick");
- $('#u-position').html("<a class = 'perehod'><span style = 'color:DarkOrange'><center>У вас не достаточно энергии!</center></span></a>");
- }else{
- $('#u-position').html("x:" + user['x'] + " y:" + user['y']);
- }
- ctx.drawImage(_user,user['sx'], -user['sy']);
- }
- // });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement