How to use globalMap method in ng-mocks

Best JavaScript code snippet using ng-mocks

map-cluster.js

Source:map-cluster.js Github

copy

Full Screen

1var wyz_map_loaded = false;2var wyz_dom_loaded = false;3document.addEventListener('DOMContentLoaded', function() {4 wyz_dom_loaded = true;5 wyz_init_load_map();6}, false);7function wyz_init_load_map() {8 if(wyz_map_loaded)return;9 if (typeof google === 'object' && typeof google.maps === 'object' && wyz_dom_loaded ) {10 wyz_map_loaded = true;11 wyz_load_map();12 }13}14function wyz_load_map(){15 var latLng;16 var map;17 var markerSpiderfier;18 var searching = false;19 var geoEnabled = false;20 var myLat = 0;21 var myLon = 0;22 var myTrueLat = 0;23 var myTrueLon = 0;24 var radVal = 0;25 var fRadVal = 0;26 var offset = 1;27 var append = '';28 var appendTop = '';29 var appendBottom = '';30 var locationFirstRun = true;31 var mapFirstLoad = true;32 var pageFirstLoad = true;33 var sidebarWidth =0;34 var mapCntr = 0;35 var markers = [];36 var infowindow;37 var bounds;38 var content;39 var gpsLen = globalMap.GPSLocations.length;40 var lastIndex = 0;41 var searchMarker = globalMap.myLocationMarker;42 var spiderfyMarker = globalMap.spiderfyMarker;43 var markerAnchorX;44 var markerAnchorY;45 var markerWidthX;46 var markerWidthY;47 var myoverlay;48 var myPosition;49 var page = 0;50 var path = wyz_plg_ref + "templates-and-shortcodes\/images\/";51 var clusterStyles = [{52 textColor: 'grey',53 url: path + "mrkr-clstr-sml.png",54 height: 50,55 width: 5056 }, {57 textColor: 'grey',58 url: path + "mrkr-clstr-mdm.png",59 height: 50,60 width: 5061 }, {62 textColor: 'grey',63 url: path + "mrkr-clstr-lrg.png",64 height: 50,65 width: 5066 }];67 var markerCluster;68 var spiderConfig = {69 keepSpiderfied: true,70 event: 'mouseover',71 };72 function initMap() {73 if(searching && jQuery.isEmptyObject(globalMap.GPSLocations)){74 toastr.info( globalMap.translations.noBusinessesFound );75 }76 // Hide Business list under map77 if (!globalMap.defCoor || globalMap.defCoor.latitude === '' || undefined === globalMap.defCoor.latitude){78 latLng = new google.maps.LatLng(0, 0);79 globalMap.defCoor = new Object;80 globalMap.defCoor.latitude = 0;81 globalMap.defCoor.longitude = 0;82 globalMap.defCoor.zoom = 11;83 }84 else latLng = new google.maps.LatLng(parseFloat(globalMap.defCoor.latitude), parseFloat(globalMap.defCoor.longitude));85 var scrollwheel = 'on' == mapScrollZoom ? true : false;86 var options = {87 zoom: parseInt(globalMap.defCoor.zoom),88 scrollwheel : scrollwheel,89 center: latLng,90 mapTypeId: google.maps.MapTypeId.ROADMAP,91 };92 map = new google.maps.Map(document.getElementById('home-map'), options);93 markerSpiderfier = new OverlappingMarkerSpiderfier(map, spiderConfig);94 if ( '' != globalMap.mapSkin ) {95 map.setOptions({styles: globalMap.mapSkin});96 }97 myoverlay = new google.maps.OverlayView();98 myoverlay.draw = function () {99 this.getPanes().markerLayer.id='markerLayer';100 };101 myoverlay.setMap(map);102 mapCntr = 0;103 markers = [];104 infowindow = new google.maps.InfoWindow();105 bounds = new google.maps.LatLngBounds();106 107 gpsLen = globalMap.GPSLocations.length;108 lastIndex = 0;109 markerCluster = new MarkerClusterer(map, markers, { maxZoom: 12, averageCenter: true, styles: clusterStyles });110 if (!geoEnabled || !searching) {111 }112 }113 var slided = false;114 var hasMapSidebar = jQuery('#slidable-map-sidebar').length;115 function updateMap(){116 var marker;117 gpsLen = globalMap.GPSLocations.length;118 for (var ii = lastIndex; ii<gpsLen; ii++){119 if(undefined!=globalMap.GPSLocations[ii]&&''!=globalMap.GPSLocations[ii].latitude&&''!=globalMap.GPSLocations[ii].longitude && ! isNaN(parseFloat(globalMap.GPSLocations[ii].latitude)) && !isNaN(parseFloat(globalMap.GPSLocations[ii].longitude) ) ){120 var latlng = new google.maps.LatLng(parseFloat(globalMap.GPSLocations[ii].latitude), parseFloat(globalMap.GPSLocations[ii].longitude));121 content = '<div id="content">'+122 '<div style="display:none;">' + globalMap.businessNames[ii] + '</div>' +123 '<div id="siteNotice">'+124 '</div>'+125 '<div id="mapBodyContent">'+126 ('' != globalMap.businessLogoes[ii] ? globalMap.businessLogoes[ii] : '<img class="business-logo-marker wp-post-image" src="'+globalMap.defLogo+'"/>' )127 +128 '<h4>'+globalMap.businessNames[ii]+'</h4>'+ 129 ( null != globalMap.afterBusinessNames[ii] ? ( '<div>' + globalMap.afterBusinessNames[ii] + '</div>' ) : '' ) +130 '<a href="'+globalMap.businessPermalinks[ii]+'"' + ( 2 == globalMap.templateType ? '' : ' class="wyz-button" style="background-color:' + globalMap.businessCategoriesColors[ii] + ';"' ) + '>'+globalMap.translations.viewDetails+'</a>'+ 131 '</div>'+132 '</div>';133 if ('' !== globalMap.markersWithIcons[ii]) {134 marker = new google.maps.Marker({135 position: latlng,136 counter: ii,137 icon: {138 url: globalMap.markersWithIcons[ii],139 size: new google.maps.Size(markerWidthX,markerWidthY),140 origin: new google.maps.Point(0, 0),141 anchor: new google.maps.Point(markerAnchorX, markerAnchorY),142 },143 info: content,144 shadow: globalMap.myLocationMarker,145 optimized: false,146 category: parseInt(globalMap.businessCategories[ii]),147 busName: globalMap.businessNames[ii],148 busId: globalMap.businessIds[ii],149 busPermalink:globalMap.businessPermalinks[ii],150 favorite:globalMap.favorites[ii],151 galleryLoaded: false,152 gallery: [],153 });154 var circle2 = new google.maps.Circle({155 map: map,156 radius: parseInt(globalMap.range_radius[ii]),157 fillColor: globalMap.radFillColor,158 strokeColor: globalMap.radStrokeColor,159 strokeWeight: 1160 });161 circle2.bindTo('center', marker , 'position');162 } else{163 marker = new google.maps.Marker({164 busName: globalMap.businessNames[ii],165 counter: ii,166 info: content,167 busId: globalMap.businessIds[ii],168 busPermalink:globalMap.businessPermalinks[ii],169 position: latlng,170 galleryLoaded: false,171 favorite:globalMap.favorites[ii],172 gallery: [],173 });174 var circle2 = new google.maps.Circle({175 map: map,176 radius: parseInt(globalMap.range_radius[ii]),177 fillColor: globalMap.radFillColor,178 strokeColor: globalMap.radStrokeColor,179 strokeWeight: 1180 });181 circle2.bindTo('center', marker , 'position');182 }183 if(2 != globalMap.templateType ){184 marker.setAnimation(google.maps.Animation.DROP);185 }186 if(searching || 'on' == mapAutoZoom) {187 bounds.extend(marker.position);188 map.fitBounds(bounds);189 }190 191 var galleryContainer = jQuery('.page-map-right-content .map-info-gallery');192 google.maps.event.addListener(marker, 'click', function() {193 jQuery('.map-container').trigger('wyz_marker_click', [this.busId] );194 if ( globalMap.templateType == 1){195 infowindow.setContent(this.info);196 infowindow.open(map, this);197 }198 199 this.setAnimation(google.maps.Animation.oo);200 jQuery('.map-company-info .company-logo').attr( 'href',this.busPermalink );201 jQuery('.map-company-info #map-company-info-name>a').attr( 'href',this.busPermalink ).html(this.busName);202 jQuery('.page-map-right-content #rate-bus').attr('href',this.busPermalink +'#'+globalMap.tabs['rating'] );203 jQuery('.map-company-info #map-company-info-slogan').html('');204 jQuery('.page-map-right-content .map-company-info .company-logo img').attr('src','');205 jQuery('.map-company-info #map-company-info-rating').html('');206 if(jQuery('.map-company-info #map-company-info-name .verified-icon').length)207 jQuery('.map-company-info #map-company-info-name .verified-icon').remove();208 if(globalMap.favEnabled){209 var favBus = jQuery('.page-map-right-content .fav-bus');210 favBus.data("busid",this.busId );211 if ( this.favorite){212 favBus.find('i').removeClass('fa-heart-o');213 favBus.find('i').addClass('fa-heart');214 favBus.data('fav',1 );215 } else {216 favBus.find('i').removeClass('fa-heart');217 favBus.find('i').addClass('fa-heart-o');218 favBus.data('fav',0 );219 }220 }221 if(hasMapSidebar && !slided){222 jQuery('#slidable-map-sidebar').animate({right:'0'}, {queue: false, duration: 500});223 if(jQuery('.map-container .location-search-float').length){224 jQuery('.map-container .location-search-float').css({'margin-top': '0'});225 }226 slided = true;227 }228 galleryContainer.html('');229 if(!this.galleryLoaded){230 var This = this;231 232 jQuery('.page-map-right-content .search-wrapper #map-sidebar-loading').addClass('loading-spinner');233 jQuery('.page-map-right-content .search-wrapper').css('background-image','');234 jQuery.ajax({235 type: "POST",236 url: ajaxurl,237 data: "action=business_map_sidebar_data&nonce=" + ajaxnonce + "&bus_id=" + this.busId ,238 success: function(result) {239 result = JSON.parse(result);240 This.galleryLoaded = true;241 This.gallery = result;242 jQuery('.map-container').trigger('business_map_sidebar_data_loaded', [result] );243 jQuery('.map-company-info #map-company-info-slogan').html(result.slogan);244 jQuery('.map-company-info #map-company-info-name>a').before(result.verified);245 jQuery('.page-map-right-content .map-company-info .company-logo img').attr('src',result.logo);246 jQuery('.page-map-right-content .search-wrapper #map-sidebar-loading').removeClass('loading-spinner');247 for(var i=0;i<result.gallery.length;i++){248 galleryContainer.append( '<li><img src="'+result.gallery.thumb[i]+'" alt=""></li>' );249 }250 if ( result.gallery.length > 0)251 jQuery('.page-map-right-content .map-info-gallery li:last-child').append('<a class="gal-link" href="'+This.busPermalink+'#'+globalMap.tabs['photo']+'">'+globalMap.translations.viewAll+'</a>');252 jQuery('.map-company-info #map-company-info-desc').html(result.slogan );253 jQuery('.map-company-info #map-company-info-rating').html(result.ratings );254 jQuery('.page-map-right-content .search-wrapper').css('background-image','url('+result.banner_image+')');255 jQuery('.map-info-links').append(result.share);256 if ( result.canBooking) {257 jQuery('.page-map-right-content #book-bus').attr('href',This.busPermalink +'#'+globalMap.tabs['booking'] );258 jQuery('.page-map-right-content #book-bus').parent().css('display','block');259 jQuery('.page-map-right-content .map-info-links li').each(function(){260 jQuery(this).removeClass('three-way-width');261 });262 } else {263 jQuery('.page-map-right-content #book-bus').attr('href','');264 jQuery('.page-map-right-content #book-bus').parent().css('display','none');265 jQuery('.page-map-right-content .map-info-links li').each(function(){266 jQuery(this).addClass('three-way-width');267 });268 }269 jQuery('.page-map-right-content .map-info-gallery li .gal-link').css('line-height',jQuery('.page-map-right-content .map-info-gallery').width()/4+'px');270 }271 });272 } else {273 jQuery('.page-map-right-content .search-wrapper #map-sidebar-loading').removeClass('loading-spinner');274 for(var i=0;i<this.gallery.gallery.length;i++){275 galleryContainer.append( '<li><img src="'+this.gallery.gallery.thumb[i]+'" alt=""></li>' );276 }277 jQuery('.page-map-right-content .map-company-info .company-logo img').attr('src',this.gallery.logo);278 jQuery('.map-company-info #map-company-info-slogan').html(this.gallery.slogan);279 jQuery('.map-company-info #map-company-info-name>a').before(this.gallery.verified);280 if(this.gallery.gallery.length)281 jQuery('.page-map-right-content .map-info-gallery li:last-child').append('<a class="gal-link" href="'+this.busPermalink+'#'+globalMap.tabs['photo']+'">'+globalMap.translations.viewAll+'</a>');282 jQuery('.map-company-info #map-company-info-desc').html(this.gallery.slogan );283 jQuery('.map-company-info #map-company-info-rating').html(this.gallery.ratings );284 jQuery('.page-map-right-content .search-wrapper').css('background-image','url('+this.gallery.banner_image+')');285 jQuery('.map-info-links').append(this.gallery.share);286 if ( this.gallery.canBooking) {287 jQuery('.page-map-right-content #book-bus').attr('href',this.busPermalink +'#'+globalMap.tabs['booking'] );288 jQuery('.page-map-right-content #book-bus').parent().css('display','block');289 jQuery('.page-map-right-content .map-info-links li').each(function(){290 jQuery(this).css('width','25%');291 });292 } else {293 jQuery('.page-map-right-content #book-bus').attr('href','');294 jQuery('.page-map-right-content #book-bus').parent().css('display','none');295 jQuery('.page-map-right-content .map-info-links li').each(function(){296 jQuery(this).css('width','33%');297 });298 }299 jQuery('.page-map-right-content .map-info-gallery li .gal-link').css('line-height',jQuery('.page-map-right-content .map-info-gallery').width()/4+'px');300 }301 });302 303 markers.push(marker);304 markerSpiderfier.addMarker(marker);305 if( 0 >= radVal && ( searching || 'on' == mapAutoZoom )&& marker != undefined ) {306 bounds.extend(marker.position);307 map.fitBounds(bounds);308 }309 }310 311 mapCntr++;312 }313 if( pageFirstLoad && globalMap.onLoadLocReq &&globalMap.geolocation && navigator.geolocation && 1>globalMap.defRad) {314 jQuery('#map-mask').fadeIn('"slow"');315 var la,lo;316 navigator.geolocation.getCurrentPosition(function(position) {317 wyzSaveLocationCookies(position);318 la = position.coords.latitude;319 lo = position.coords.longitude;320 jQuery('#map-mask').fadeOut('"fast"');321 marker = new google.maps.Marker({322 position: { lat: parseFloat(la), lng: parseFloat(lo) },323 icon: {324 url: searchMarker,325 size: new google.maps.Size(40,55),//WyzMapSize1326 origin: new google.maps.Point(0, 0),327 anchor: new google.maps.Point(20, 55),//WyzMapAnchor1328 },329 map: map330 });331 if(2 != globalMap.templateType )332 marker.setAnimation(google.maps.Animation.DROP);333 markers.push(marker);334 markerSpiderfier.addMarker(marker);335 map.setCenter({lat:la, lng:lo});336 }, function(error) {337 wyzLocationCookiesError(error);338 handleLocationError(1);339 jQuery('#map-mask').fadeOut('fast');340 });341 } else {342 if (globalMap.geolocation && pageFirstLoad && globalMap.onLoadLocReq && 1>globalMap.defRad){343 handleLocationError(3);344 }345 }346 pageFirstLoad=false;347 if ((geoEnabled||'dropdown' != globalMap.filterType) && (searching || (globalMap.defRad>0 && globalMap.onLoadLocReq)) && (0!=myLat||0!=myLon)) {348 //setup radius multiplier in miles or km349 var radMult = ('km'==globalMap.radiusUnit ? 1000 : 1609.34);350 // Add circle overlay and bind to marker351 var circleParams = {352 map: map,353 radius: radVal * radMult,354 fillColor: '#42c2ff',355 strokeColor: '#00aeff',356 strokeWeight: 1357 };358 if( '' == searchMarker) {359 circleParams.center = { lat: parseFloat(myLat), lng: parseFloat(myLon) };360 var circle = new google.maps.Circle(circleParams);361 bounds.extend(circleParams.center);362 } else {363 marker = new google.maps.Marker({364 position: { lat: parseFloat(myLat), lng: parseFloat(myLon) },365 icon: {366 url: searchMarker,367 size: new google.maps.Size(40,55),368 origin: new google.maps.Point(0, 0),369 anchor: new google.maps.Point(20, 55),370 },371 map: map372 });373 if(2 != globalMap.templateType )374 marker.setAnimation(google.maps.Animation.DROP);375 var circle = new google.maps.Circle(circleParams);376 circle.bindTo('center', marker, 'position');377 bounds.extend(marker.position);378 }379 map.fitBounds(bounds);380 var sz = 0;381 sz = (radVal<20? 11 : ( radVal<50 ? 10 : ( radVal<80?9:(radVal < 101 ? 8 : (radVal < 201 ? 7 : (radVal < 401 ? 6 : radVal < 501 ? 5 : 0))))));382 if (0 !== sz)383 map.setZoom(sz);384 } /*else {385 var sz = map.getZoom();386 if(!isNaN(sz)){387 if(sz>3)388 sz--;389 map.setZoom(sz);390 }391 }*/392 393 markerSpiderfier = new OverlappingMarkerSpiderfier(map, spiderConfig);394 // all markers set and added to map, update marker cluster395 markerCluster = new MarkerClusterer(map, markers, { maxZoom: 12, averageCenter: true, styles: clusterStyles });396 397 markerCluster.setMaxZoom(15);398 lastIndex = gpsLen;399 }400 function paginateBusinessList(){401 append = appendTop = appendBottom = '';402 if('' != globalMap.businessList){403 if(globalMap.hasBefore || globalMap.hasAfter){404 if(globalMap.hasBefore)405 append += '<li class="prev-page float-left">' + 406 '<button class="wyz-primary-color wyz-prim-color btn-square list-paginate" data-offset="-1"><i class="fa fa-angle-left"> </i> ' + globalMap.translations.prev + '</button></li>';407 if(globalMap.hasAfter){408 append += '<li class="next-page float-right">'+409 '<button class="wyz-primary-color wyz-prim-color btn-square list-paginate" data-offset="1">' + globalMap.translations.nxt + ' <i class="fa fa-angle-right"></i></button></li>';410 }411 if('' != append){412 appendTop = '<div class="blog-pagination fix" style="margin-bottom:20px;margin-top:0;"><ul>' + append + '</ul></div>';413 appendBottom = '<div class="blog-pagination fix" style="margin-bottom:30px;"><ul>' + append + '</ul></div>';414 }415 }416 }417 }418 // Display Businesses list under the map419 function updateBusinessList(){420 if('' != globalMap.businessList){421 paginateBusinessList();422 if(globalMap.ess_grid_shortcode == '') {423 jQuery('#business-list').html(appendTop + '<div class="bus-list-container">' + globalMap.businessList + '</div>' + appendBottom );424 jQuery(document).trigger('wyzMapListFetch', [globalMap.businessList, appendBottom, 1]);425 }426 else {427 jQuery('#business-list').html(appendTop + '<div class="bus-list-container">' + globalMap.ess_grid_shortcode + '</div>' + appendBottom);428 jQuery(document).trigger('wyzMapListFetch', [globalMap.ess_grid_shortcode, appendBottom, 2]);429 }430 setTimeout(function(){ jQuery('#business-list').show(); jQuery('#business-list').resize();}, 100);431 }432 }433 var active;434 function mapSearch() {435 if ('dropdown' != globalMap.filterType){436 var tmpMapLocSearch = jQuery('#wyz-loc-filter-txt').val();437 if ( '' == tmpMapLocSearch){438 jQuery("#loc-filter-lat").val('');439 jQuery("#loc-filter-lon").val('');440 jQuery("#wyz-loc-filter").val('');441 }442 }443 geoEnabled = ( globalMap.geolocation && navigator.geolocation && 0 < radVal && 500>= radVal )?true:false;444 if ( geoEnabled && (isNaN(radVal) || 0 > radVal || 500 < radVal) )445 toastr.warning( globalMap.translations.notValidRad);446 else {447 if(mapFirstLoad&&globalMap.defRad>0 && !isNaN(globalMap.defRad)){448 radVal = globalMap.defRad;449 }450 var catId = jQuery("#wyz-cat-filter").val();451 if ( mapFirstLoad && undefined != globalMap.defCat && null != globalMap.defCat )452 catId = globalMap.defCat;453 var busName = jQuery("#map-names").val();454 jQuery('#map-mask').fadeIn('"slow"');455 jQuery('#map-loading').fadeIn('"fast"');456 457 var locData = jQuery("#wyz-loc-filter").val();458 if ( mapFirstLoad && undefined != globalMap.defLoc && null != globalMap.defLoc )459 locData = globalMap.defLoc;460 var locId = '';461 if ( 'dropdown' == globalMap.filterType ) {462 if( -1 != locData && '' != locData){463 locData = JSON.parse(locData);464 myLat = locData.lat;465 myLon = locData.lon;466 searchMarker = globalMap.locLocationMarker;467 }else if(geoEnabled){468 myLat = myTrueLat;469 myLon = myTrueLon;470 }else{471 searchMarker = globalMap.myLocationMarker;472 }473 474 locId = locData.id;475 if( undefined == locId )476 locId = '';477 } else {478 if ( '' != jQuery("#loc-filter-lat").val()){479 myLat = jQuery("#loc-filter-lat").val();480 myLon = jQuery("#loc-filter-lon").val();481 locId = '';482 if ( radVal<1)radVal=500;483 } else if(radVal>0) {484 myLat = myTrueLat;485 myLon = myTrueLon;486 }487 searchMarker = globalMap.myLocationMarker;488 }489 page = 0;490 if(jQuery.active>0&&undefined!=active)491 active.abort();492 if(hasMapSidebar && slided){493 if( jQuery('html').attr('dir') == 'rtl')494 jQuery('#slidable-map-sidebar').animate({right:sidebarWidth}, {queue: false, duration: 500});495 else496 jQuery('#slidable-map-sidebar').animate({right:-sidebarWidth}, {queue: false, duration: 500});497 slided = false;498 if(jQuery('.map-container .location-search-float').length){499 jQuery('.map-container .location-search-float').css({'margin-top':'-90px'});500 }501 }502 fRadVal = radVal;503 if (-1 == catId && '' === busName && "" == locId && 'text' != globalMap.filterType )504 ajax_map_search('', '', '', geoEnabled);505 else506 ajax_map_search(catId, busName, locId, geoEnabled);507 if(mapFirstLoad)508 mapFirstLoad = false;509 else510 searching = true;511 }512 }513 var input_interval;514 function intialize() {515 infowindow = new google.maps.InfoWindow();516 bounds = new google.maps.LatLngBounds();517 input_interval = setTimeout(input_autocomplete, 500);518 }519 function input_autocomplete() {520 if (!(typeof google.maps.places === 'object') )521 return;522 clearInterval(input_interval);523 input = document.getElementById('wyz-loc-filter-txt');524 autocomplete = new google.maps.places.Autocomplete(input);525 google.maps.event.addListener(autocomplete, 'place_changed', function () {526 var place = autocomplete.getPlace();527 document.getElementById('loc-filter-txt').value = place.name;528 document.getElementById('loc-filter-lat').value = place.geometry.location.lat();529 document.getElementById('loc-filter-lon').value = place.geometry.location.lng();530 });531 }532 if('text'==globalMap.filterType){533 google.maps.event.addDomListener(window, 'load', intialize);534 }535 function checkUpdateSlider() {536 if(globalMap.hasNearMe && globalMap.nearMeContent && jQuery('#near-me-businesses').length){537 jQuery('#near-me-businesses').html(globalMap.nearMeContent);538 jQuery('#near-me-businesses .recently-added-area').show();539 jQuery(document).trigger('wyz_rec_added_slider');540 }541 }542 function ajax_map_search(catId, busName, locId, geoEnabled) {543 active = jQuery.ajax({544 type: "POST",545 url: ajaxurl,546 data: "action=global_map_search&nonce=" + ajaxnonce + "&page_id=" + globalMap.pageId + "&page=" + page + "&bus-name=" + busName + "&loc-id=" + locId + "&is-listing=" + globalMap.isListingPage+"&has-listings="+globalMap.hasLists + "&is-grid=" + globalMap.isGrid + "&cat-id=" + catId + ( ( geoEnabled || 'text' == globalMap.filterType ) ? "&rad=" + fRadVal + "&lat=" + myLat + "&lon=" + myLon : '') + '&posts-per-page=' +(globalMap.isListingPage ? globalMap.postsPerPage : '-1'),547 success: function(result) {548 result = JSON.parse(result);549 console.log(result.hasAfter);550 if(0==page){551 resetGlobalData(result);552 checkUpdateSlider();553 initMap();554 jQuery('#map-mask').fadeOut('fast');555 }556 else557 updateGlobalData(result);558 if(0==parseInt(result.postsCount)){559 searching=false;560 jQuery('#map-loading').fadeOut('fast');561 return;562 }563 564 updateMap();565 if(globalMap.isListingPage && globalMap.hasLists && 0==page){566 updateBusinessList();567 }568 569 page+=parseInt(result.postsCount);570 ajax_map_search(catId, busName, locId, geoEnabled);571 }572 });573 }574 function resetGlobalData(result){575 var tempMark = globalMap.myLocationMarker;576 var tempLocMark = globalMap.locLocationMarker;577 var tempGeolocation = globalMap.geolocation;578 var defCoor = globalMap.defCoor;579 var defLogo = globalMap.defLogo;580 var radUnit = globalMap.radiusUnit;581 var grid = globalMap.isGrid;582 var translations = globalMap.translations;583 var tmpFilterType = globalMap.filterType;584 var tmpTemplateType = globalMap.templateType;585 var tmpTabs = globalMap.tabs;586 var tmpFavEn = globalMap.favEnabled;587 var tmpSkin = globalMap.mapSkin;588 var onLoadLocReq = globalMap.onLoadLocReq;589 var defRad = globalMap.defRad;590 var radFillColor = globalMap.radFillColor;591 var radStrokeColor = globalMap.radStrokeColor;592 var tmpPageId = globalMap.pageId;593 var tmpHasLists = globalMap.hasLists;594 var range_radius= result.range_radius;595 globalMap = null;596 google.maps.event.trigger(map, 'resize');597 globalMap = result;598 globalMap.radFillColor = radFillColor;599 globalMap.radStrokeColor = radStrokeColor;600 globalMap.myLocationMarker = tempMark;601 globalMap.locLocationMarker = tempLocMark;602 globalMap.geolocation = tempGeolocation;603 globalMap.defCoor = defCoor;604 globalMap.defLogo = defLogo;605 globalMap.radiusUnit = radUnit;606 globalMap.isGrid = grid;607 globalMap.businessList = result.businessList;608 globalMap.isListingPage = result.isListingPage;609 globalMap.postsPerPage = result.postsPerPage;610 globalMap.businessIds = result.businessIds;611 globalMap.hasAfter = result.hasAfter;612 globalMap.hasBefore = result.hasBefore;613 globalMap.filterType = tmpFilterType;614 globalMap.templateType = tmpTemplateType;615 globalMap.translations = translations;616 globalMap.tabs = tmpTabs;617 globalMap.mapSkin = tmpSkin;618 globalMap.onLoadLocReq = onLoadLocReq;619 globalMap.defRad = defRad;620 globalMap.favEnabled = tmpFavEn;621 globalMap.pageId = tmpPageId;622 globalMap.range_radius=range_radius;623 globalMap.hasLists = tmpHasLists;624 }625 function updateGlobalData(result){626 for(var i=0;i<result.postsCount;i++){627 globalMap.GPSLocations.push(result.GPSLocations[i]);628 globalMap.markersWithIcons.push(result.markersWithIcons[i]);629 globalMap.businessNames.push(result.businessNames[i]);630 globalMap.businessLogoes.push(result.businessLogoes[i]);631 globalMap.businessPermalinks.push(result.businessPermalinks[i]);632 globalMap.businessCategories.push(result.businessCategories[i]);633 globalMap.businessCategoriesColors.push(result.businessCategoriesColors[i]);634 globalMap.range_radius.push(result.range_radius[i]);635 636 }637 globalMap.postsCount = result.postsCount;638 639 }640 function ajax_business_list(ofst){641 if(ofst != 1 && ofst != -1)642 return;643 if((ofst == -1 && offset == 0) || (ofst == 1 && ! globalMap.hasAfter))644 return;645 if(ofst == 1)646 offset++;647 else648 offset--;649 jQuery.ajax({650 type: "POST",651 url: ajaxurl,652 data: "action=business_listing_paginate&nonce=" + ajaxnonce + "&business_ids=" + JSON.stringify(globalMap.businessIds) + "&is-grid=" + globalMap.isGrid + "&offset=" + offset + '&posts-per-page=' + globalMap.postsPerPage,653 success: function(result) {654 result = JSON.parse(result);655 if(null != result){656 globalMap.businessList = result.businessList;657 globalMap.hasBefore = result.hasBefore;658 globalMap.hasAfter = result.hasAfter;659 globalMap.ess_grid_shortcode = result.ess_grid_shortcode;660 updateBusinessList();661 }662 }663 });664 }665 function handleLocationError(browserHasGeolocation) {666 switch (browserHasGeolocation) {667 case 1:668 toastr.error(globalMap.translations.geoFail);669 break;670 case 2:671 break;672 case 3:673 toastr.warning(globalMap.translations.geoBrowserFail);674 }675 }676 jQuery(document).ready(function() {677 sidebarWidth = jQuery(window).width();678 if( jQuery('html').attr('dir') == 'rtl')679 jQuery('#slidable-map-sidebar').css({'right':sidebarWidth*2});680 else681 jQuery('#slidable-map-sidebar').css({'right':-sidebarWidth*2});682 jQuery(".map-share-btn").live({683 click: function (e) {684 e.preventDefault();685 jQuery(this).parent().nextAll(".business-post-share-cont").first().toggle();686 }687 });688 jQuery('.search-wrapper .close-button').click(function(event){689 event.preventDefault();690 if(slided){691 if( jQuery('html').attr('dir') == 'rtl')692 jQuery('#slidable-map-sidebar').animate({right:sidebarWidth}, {queue: false, duration: 500});693 else694 jQuery('#slidable-map-sidebar').animate({right:-sidebarWidth}, {queue: false, duration: 500});695 if(jQuery('.map-container .location-search-float').length){696 jQuery('.map-container .location-search-float').css({'margin-top': '-90px'});697 }698 slided = false;699 }700 });701 globalMap.templateType = parseInt(globalMap.templateType);702 switch ( globalMap.templateType ) {703 case 1:704 markerAnchorX = 20;705 markerAnchorY = 55;706 markerWidthX = 40;707 markerWidthY = 55;708 break;709 case 2:710 markerAnchorX = 0;711 markerAnchorY = 60;712 markerWidthX = 60;713 markerWidthY = 60;714 break;715 }716 if( typeof WyzMapAnchorX !== 'undefined' ){717 markerAnchorX = WyzMapAnchorX;718 markerAnchorY = WyzMapAnchorY;719 }720 if( typeof WyzMapWidthX !== 'undefined' ){721 markerWidthX = WyzMapWidthX;722 markerWidthY = WyzMapWidthY;723 }724 var useDimmer = 1 == wyz_template_type;725 //pretty select box726 jQuery('#wyz-cat-filter').selectator({727 labels: {728 search: globalMap.translations.searchText729 },730 useDimmer: useDimmer731 });732 jQuery('#wyz-loc-filter').selectator({733 labels: {734 search: globalMap.translations.searchText735 },736 useDimmer: useDimmer737 });738 //add km or miles to the map radius slider739 if(globalMap.radiusUnit=='mile')740 jQuery('.location-search .input-range p span').addClass('distance-miles');741 else742 jQuery('.location-search .input-range p span').addClass('distance-km');743 var range = jQuery('#loc-radius');744 var radius = jQuery('#loc-radius').attr('value')745 jQuery('#loc-radius').siblings('p').find('span').html( radius );746 var rtl = jQuery('html[dir="rtl"]').length ? 'right' : 'left';747 range.rangeslider({748 polyfill: false,749 direction: rtl,750 fillClass: 'range_fill',751 handleClass: 'range_handle',752 onSlideEnd: function(pos, value) {753 if (locationFirstRun) {754 locationFirstRun = false;755 //geolocation activation756 if (globalMap.geolocation && navigator.geolocation) {757 jQuery('#map-mask').fadeIn('"slow"') ;758 navigator.geolocation.getCurrentPosition(function(position) {759 wyzSaveLocationCookies(position);760 jQuery('#map-mask').fadeOut('"fast"') ;761 myTrueLat = position.coords.latitude;762 myTrueLon = position.coords.longitude;763 }, function(error) {764 jQuery('#map-mask').fadeOut('"fast"') ;765 wyzLocationCookiesError(error)766 handleLocationError(1);767 });768 } else {769 if (globalMap.geolocation)770 handleLocationError(3);771 else772 handleLocationError(2);773 }774 } 775 }776 });777 jQuery('#map-company-info-name-a, .map-company-info .company-logo, .map-info-links #rate-bus').click(function(e){778 window.location.href = jQuery(this).attr("href");779 });780 jQuery('.fav-bus').click(favoriteBus);781 if ( 2 == globalMap.templateType){782 jQuery('.range_handle').append('<span></span>');783 784 var radiusLength = jQuery('.range_handle span');785 range.on('input', function() {786 radiusLength.html( jQuery(this).val() + ' ' + globalMap.radiusUnit );787 radVal = jQuery(this).val();788 });789 var locRadius = jQuery('input[type="range"]').attr('value');790 var radiusLength = jQuery('.range_handle span');791 radiusLength.html( locRadius + ' ' + globalMap.radiusUnit );792 } else{793 range.on('input', function() {794 jQuery(this).siblings('p').find('span').html( jQuery(this).val() );795 radVal = jQuery(this).val();796 });797 }798 jQuery('#map-names').keypress(function(e) {799 if(e.which == 13) {800 jQuery('#map-search-submit').trigger('click');801 }802 });803 jQuery('#map-search-submit').on('click', mapSearch);804 google.maps.event.addDomListener(window, 'load', function(){805 initMap();806 if(globalMap.hasSlider){807 navigator.geolocation.getCurrentPosition(function(position){808 wyzSaveLocationCookies(position);809 resume_work();810 }, function(error){811 wyzLocationCookiesError(error);812 resume_work();813 });814 } else {815 resume_work();816 }817 function resume_work(){818 mapSearch();819 if( globalMap.onLoadLocReq &&globalMap.geolocation && navigator.geolocation && 0<globalMap.defRad) {820 jQuery('#loc-radius').trigger('input');821 navigator.geolocation.getCurrentPosition(function(position) {822 wyzSaveLocationCookies(position);823 myTrueLat = position.coords.latitude;824 myTrueLon = position.coords.longitude;825 mapSearch();826 }, function(error) {827 wyzLocationCookiesError(error);828 handleLocationError(1);829 });830 }831 }832 });833 jQuery(".list-paginate").live('click',function(){834 jQuery(".list-paginate").prop('disabled', true).css('background-color','#68819b'); 835 ajax_business_list(parseInt(jQuery(this).data('offset')));836 });837 });838 function favoriteBus(event){839 event.preventDefault();840 var bus_id = jQuery(this).data('busid');841 if( '' == bus_id || undefined == bus_id ) return;842 var isFav = jQuery(this).data('fav');843 jQuery(this).parent().addClass('fade-loading');844 jQuery(this).unbind('favoriteBus');845 var favType = isFav == 1 ? 'unfav' : 'fav';846 var target = jQuery(this);847 jQuery.ajax({848 type: "POST",849 url: ajaxurl,850 data: "action=business_favorite&nonce=" + ajaxnonce + "&business_id=" + bus_id + "&fav_type=" + favType,851 success: function(result) {852 target.parent().removeClass('fade-loading');853 var i;854 for(i=0;i<globalMap.length;i++){855 if(globalMap.businessIds == bus_id)856 break;857 }858 if(favType=='fav'){859 if(i<globalMap.length)860 globalMap.favorites[i]=true;861 target.find('i').removeClass('fa-heart-o');862 target.find('i').addClass('fa-heart');863 target.data('fav',1 );864 } else {865 if(i<globalMap.length)866 globalMap.favorites[i]=false;867 target.find('i').removeClass('fa-heart');868 target.find('i').addClass('fa-heart-o');869 target.data('fav',0 );870 }871 }872 });873 }...

Full Screen

Full Screen

game.js

Source:game.js Github

copy

Full Screen

1/*2 * Warped Demo Code3 * @copyright 2017 Ansimuz4 * Get more free assets and code like these at: www.pixelgameart.org5 * Visit my store for premium content at https://ansimuz.itch.io/6 * */7var game;8var player;9var background;10var middleground;11var gameWidth = 240;12var gameHeight = 176;13var globalMap;14var shootingFlag;15var nextShot;16var projectiles;17var enemies;18var items;19var isDuck;20var hurtFlag;21window.onload = function () {22 game = new Phaser.Game(gameWidth, gameHeight, Phaser.AUTO, "");23 game.state.add('Boot', boot);24 game.state.add('Preload', preload);25 game.state.add('TitleScreen', titleScreen);26 game.state.add('PlayGame', playGame);27 //28 game.state.start("Boot");29}30var boot = function (game) {31};32boot.prototype = {33 preload: function () {34 this.game.load.image('loading', 'assets/sprites/loading.png');35 },36 create: function () {37 game.scale.pageAlignHorizontally = true;38 game.scale.pageAlignVertically = true;39 game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;40 game.renderer.renderSession.roundPixels = true; // no blurring41 this.game.state.start('Preload');42 }43}44var preload = function (game) {45};46preload.prototype = {47 preload: function () {48 var loadingBar = this.add.sprite(game.width / 2, game.height / 2, 'loading');49 loadingBar.anchor.setTo(0.5);50 game.load.setPreloadSprite(loadingBar);51 // load title screen52 game.load.image('title', 'assets/sprites/title-screen.png');53 game.load.image('enter', 'assets/sprites/press-enter-text.png');54 game.load.image('credits', 'assets/sprites/credits-text.png');55 game.load.image('instructions', 'assets/sprites/instructions.png');56 // environment57 game.load.image('background', 'assets/environment/background.png');58 game.load.image('middleground', 'assets/environment/middleground.png');59 //tileset60 game.load.image('tileset', 'assets/environment/tilesets.png');61 game.load.image('walls', 'assets/environment/walls.png');62 game.load.tilemap('map', 'assets/maps/map.json', null, Phaser.Tilemap.TILED_JSON);63 // atlas sprites64 game.load.atlasJSONArray('atlas', 'assets/atlas/atlas.png', 'assets/atlas/atlas.json');65 game.load.atlasJSONArray('atlas-props', 'assets/atlas/atlas-props.png', 'assets/atlas/atlas-props.json');66 //67 game.load.audio('music', ['assets/sound/platformer_level04_loop.ogg']);68 },69 create: function () {70 this.game.state.start('TitleScreen');71 }72}73var titleScreen = function (game) {74};75titleScreen.prototype = {76 create: function () {77 background = game.add.tileSprite(0, 0, gameWidth, gameHeight, 'background');78 middleground = game.add.tileSprite(0, 0, gameWidth, gameHeight, 'middleground');79 this.title = game.add.image(gameWidth / 2, 80, 'title');80 this.title.anchor.setTo(0.5);81 var credits = game.add.image(gameWidth / 2, game.height - 12, 'credits');82 credits.anchor.setTo(0.5);83 this.pressEnter = game.add.image(game.width / 2, game.height - 45, 'enter');84 this.pressEnter.anchor.setTo(0.5);85 var startKey = game.input.keyboard.addKey(Phaser.Keyboard.ENTER);86 startKey.onDown.add(this.startGame, this);87 game.time.events.loop(700, this.blinkText, this);88 this.state = 1;89 },90 blinkText: function () {91 if (this.pressEnter.alpha) {92 this.pressEnter.alpha = 0;93 } else {94 this.pressEnter.alpha = 1;95 }96 },97 update: function () {98 middleground.tilePosition.y -= .2;99 },100 startGame: function () {101 if (this.state == 1) {102 this.state = 2;103 this.title2 = game.add.image(game.width / 2, 40, 'instructions');104 this.title2.anchor.setTo(0.5, 0);105 this.title.destroy();106 } else {107 this.game.state.start('PlayGame');108 }109 }110}111var playGame = function (game) {112};113playGame.prototype = {114 create: function () {115 this.createBackgrounds();116 this.createTilemap();117 this.populate();118 //119 this.createPlayer(4, 7);120 this.decorWorld();121 //122 this.bindKeys();123 //124 game.camera.follow(player, Phaser.Camera.FOLLOW_PLATFORMER);125 // music126 this.music = game.add.audio('music');127 this.music.loop = true;128 this.music.play();129 },130 createBackgrounds: function () {131 background = game.add.tileSprite(0, 0, gameWidth, gameHeight, 'background');132 middleground = game.add.tileSprite(0, 0, gameWidth, gameHeight, 'middleground');133 background.fixedToCamera = true;134 middleground.fixedToCamera = true;135 },136 createTilemap: function () {137 // tile138 globalMap = game.add.tilemap('map');139 globalMap.addTilesetImage('tileset');140 globalMap.addTilesetImage('walls');141 this.layer2 = globalMap.createLayer('Tile Layer 2');142 this.layer2.resizeWorld();143 this.layer = globalMap.createLayer('Tile Layer 1');144 this.layer.resizeWorld();145 // collision146 globalMap.setCollisionBetween(27, 31);147 globalMap.setCollision(33);148 globalMap.setCollisionBetween(182, 185);149 globalMap.setCollisionBetween(182, 185);150 globalMap.setCollision(81);151 globalMap.setCollision(83);152 globalMap.setCollision(85);153 globalMap.setCollision(87);154 globalMap.setCollision(89);155 globalMap.setCollision(114);156 globalMap.setCollision(116);157 globalMap.setCollision(93);158 globalMap.setCollision(170);159 globalMap.setCollisionBetween(172, 173);160 globalMap.setCollision(175);161 globalMap.setCollision(177);162 globalMap.setCollisionBetween(179, 180);163 globalMap.setCollision(166);164 globalMap.setCollision(214);165 globalMap.setCollision(215);166 globalMap.setCollision(238);167 globalMap.setCollision(239);168 globalMap.setCollisionBetween(254, 257);169 globalMap.setCollision(76);170 globalMap.setCollision(100);171 globalMap.setCollision(78);172 globalMap.setCollision(102);173 globalMap.setCollision(248);174 globalMap.setCollision(249);175 globalMap.setCollision(251);176 globalMap.setCollision(252);177 globalMap.setCollision(259);178 globalMap.setCollision(260);179 globalMap.setCollision(119);180 globalMap.setCollision(206);181 globalMap.setCollision(230);182 globalMap.setCollision(209);183 globalMap.setCollision(233);184 // one way185 this.setOneWayCollision(38);186 this.setOneWayCollision(42);187 this.setOneWayCollision(187);188 this.setOneWayCollision(188);189 },190 setOneWayCollision: function (tileIndex) {191 var x, y, tile;192 for (x = 0; x < globalMap.width; x++) {193 for (y = 1; y < globalMap.height; y++) {194 tile = globalMap.getTile(x, y);195 if (tile !== null) {196 if (tile.index == tileIndex) {197 tile.setCollision(false, false, true, false);198 }199 }200 }201 }202 },203 decorWorld: function () {204 this.addProp(0, 6, 'gate-01');205 this.addProp(6, 8, 'plant-big');206 this.addProp(19, 20, 'plant-small');207 this.addProp(13, 19, 'plant-big');208 this.addProp(6, 8, 'plant-big');209 this.addProp(21, 20, 'stone');210 this.addProp(54, 8, 'stone-head');211 this.addProp(52, 1, 'stalactite');212 this.addProp(22, 14, 'stalactite');213 },214 addProp: function (x, y, item) {215 game.add.image(x * 16, y * 16, 'atlas-props', item);216 },217 populate: function () {218 // groups219 projectiles = game.add.group();220 projectiles.enableBody = true;221 //222 enemies = game.add.group();223 enemies.enableBody = true;224 //225 items = game.add.group();226 items.enableBody = true;227 // place enemies228 this.addCrab(56, 6);229 this.addCrab(12, 18);230 this.addJumper(30, 5);231 this.addJumper(48, 5);232 this.addOctopus(52, 17);233 this.addOctopus(23, 17);234 //place items235 this.addItem(30, 3);236 this.addItem(60, 18);237 this.addItem(59, 4);238 this.addItem(4, 17);239 },240 addJumper: function (x, y) {241 var temp = new Jumper(game, x, y);242 game.add.existing(temp);243 enemies.add(temp);244 },245 addOctopus: function (x, y) {246 var temp = new Octopus(game, x, y);247 game.add.existing(temp);248 enemies.add(temp);249 },250 addCrab: function (x, y) {251 var temp = new Crab(game, x, y);252 game.add.existing(temp);253 enemies.add(temp);254 },255 addItem: function (x, y) {256 var temp = new Item(game, x, y);257 game.add.existing(temp);258 items.add(temp);259 },260 createPlayer: function (x, y) {261 x *= 16;262 y *= 16;263 player = game.add.sprite(x, y, 'atlas', 'player-idle-1');264 player.anchor.setTo(0.5);265 game.physics.arcade.enable(player);266 player.body.gravity.y = 500;267 player.body.setSize(11, 40, 35, 24);268 //animations269 var s = 10;270 player.animations.add('idle', Phaser.Animation.generateFrameNames('player-idle-', 1, 4, '', 0), s - 4, true);271 player.animations.add('run', Phaser.Animation.generateFrameNames('player-run-', 1, 10, '', 0), s, true);272 player.animations.add('run-shot', Phaser.Animation.generateFrameNames('player-run-shot-', 1, 10, '', 0), s, true);273 player.animations.add('duck', ['player-duck'], s, true);274 player.animations.add('jump', Phaser.Animation.generateFrameNames('player-jump-', 1, 6, '', 0), s, true);275 player.animations.add('fall', Phaser.Animation.generateFrameNames('player-jump-', 3, 6, '', 0), s, true);276 player.animations.add('shooting', Phaser.Animation.generateFrameNames('player-stand-', 1, 3, '', 0), s + 5, true);277 player.animations.add('hurt', Phaser.Animation.generateFrameNames('player-hurt-', 1, 2, '', 0), 4, false);278 //default animation279 player.animations.play('idle');280 },281 bindKeys: function () {282 this.wasd = {283 jump: game.input.keyboard.addKey(Phaser.Keyboard.C),284 attack: game.input.keyboard.addKey(Phaser.Keyboard.X),285 //jump: game.input.keyboard.addKey(Phaser.Keyboard.Q), // dvorak286 //attack: game.input.keyboard.addKey(Phaser.Keyboard.J), // dvorak287 left: game.input.keyboard.addKey(Phaser.Keyboard.LEFT),288 right: game.input.keyboard.addKey(Phaser.Keyboard.RIGHT),289 down: game.input.keyboard.addKey(Phaser.Keyboard.DOWN)290 }291 game.input.keyboard.addKeyCapture(292 [Phaser.Keyboard.LEFT,293 Phaser.Keyboard.RIGHT,294 Phaser.Keyboard.DOWN295 ]296 );297 },298 update: function () {299 game.physics.arcade.collide(player, this.layer);300 game.physics.arcade.collide(enemies, this.layer);301 game.physics.arcade.collide(projectiles, this.layer, this.hitWall, null, this);302 //303 game.physics.arcade.overlap(enemies, projectiles, this.shotImpact, null, this);304 game.physics.arcade.overlap(player, enemies, this.hurtPlayer, null, this);305 game.physics.arcade.overlap(player, items, this.pickItem, null, this);306 this.movePlayer();307 this.playerAnimations();308 this.parallaxBackground();309 this.hurtFlagManager();310 // this.debugGame();311 },312 pickItem: function (p, i) {313 i.kill();314 },315 hurtPlayer: function (p, enemy) {316 if (hurtFlag) {317 return;318 }319 hurtFlag = true;320 p.animations.play('hurt');321 p.body.velocity.y = -150;322 p.body.velocity.x = (p.scale.x == 1) ? -100 : 100;323 },324 hurtFlagManager: function () {325 // reset hurt when touching ground326 if (hurtFlag && player.body.onFloor()) {327 hurtFlag = false;328 }329 },330 hitWall: function (shot, wall) {331 shot.kill();332 var impact = new ShotImpact(game, shot.x, shot.y);333 game.add.existing(impact);334 },335 shotImpact: function (enemy, shot) {336 var impact = new ShotImpact(game, shot.x, shot.y);337 game.add.existing(impact);338 shot.kill();339 // enemy.kill();340 enemy.health--;341 },342 parallaxBackground: function () {343 middleground.tilePosition.x = this.layer.x * -0.5;344 },345 movePlayer: function () {346 var speed = 100;347 if (this.wasd.left.isDown) {348 player.body.velocity.x = -speed;349 player.scale.x = -1;350 } else if (this.wasd.right.isDown) {351 player.body.velocity.x = speed;352 player.scale.x = 1;353 } else {354 player.body.velocity.x = 0;355 }356 //jump357 if (this.wasd.jump.isDown && player.body.onFloor()) {358 player.body.velocity.y = -200;359 }360 // shooting361 if (this.wasd.attack.isDown) {362 shootingFlag = true;363 this.shoot();364 } else if (this.wasd.attack.onUp) {365 shootingFlag = false;366 }367 },368 playerAnimations: function () {369 if (hurtFlag) {370 return;371 }372 if (player.body.onFloor()) {373 if (player.body.velocity.x != 0) {374 if (shootingFlag) {375 player.animations.play('run-shot');376 } else {377 player.animations.play('run');378 }379 } else {380 if (this.wasd.down.isDown) {381 player.animations.play('duck');382 isDuck = true;383 } else {384 isDuck = false;385 if (shootingFlag) {386 player.animations.play('shooting');387 } else {388 player.animations.play('idle');389 }390 }391 }392 } else {393 if (player.body.velocity.y > 0) {394 player.animations.play('fall');395 } else if (player.body.velocity.y < 0) {396 player.animations.play('jump');397 }398 }399 },400 shoot: function () {401 if (nextShot > game.time.now) {402 return;403 }404 nextShot = game.time.now + 200; // wait at least half second405 var shot = new Shot(game, player.x, player.y, player.scale.x);406 game.add.existing(shot);407 projectiles.add(shot);408 },409 debugGame: function () {410 //game.debug.spriteInfo(this.player, 30, 30);411 //game.debug.body(player);412 enemies.forEachAlive(this.renderGroup, this);413 items.forEachAlive(this.renderGroup, this);414 },415 renderGroup: function (member) {416 game.debug.body(member);417 },418}419// shot420Shot = function (game, x, y, dir) {421 y = (isDuck) ? y + 8 : y - 5;422 x += (dir == 1) ? 11 : -20;423 Phaser.Sprite.call(this, game, x, y, 'atlas', 'shot-1');424 this.animations.add('shot', Phaser.Animation.generateFrameNames('shot-', 1, 2, '', 0), 10, true);425 this.animations.play('shot');426 game.physics.arcade.enable(this);427 this.body.velocity.x = 220 * dir;428 this.checkWorldBounds = true;429}430Shot.prototype = Object.create(Phaser.Sprite.prototype);431Shot.prototype.constructor = Shot;432Shot.prototype.update = function () {433 if (!this.inWorld) {434 this.destroy();435 }436}437// Crab438Crab = function (game, x, y) {439 x *= 16;440 y *= 16;441 this.health = 5;442 Phaser.Sprite.call(this, game, x, y, 'atlas', 'crab-idle-1');443 this.animations.add('idle', Phaser.Animation.generateFrameNames('crab-idle-', 1, 4, '', 0), 10, true);444 this.animations.add('walk', Phaser.Animation.generateFrameNames('crab-walk-', 1, 4, '', 0), 10, true);445 this.animations.play('idle');446 this.anchor.setTo(0.5);447 game.physics.arcade.enable(this);448 this.body.setSize(16, 25, 16, 7);449 this.body.gravity.y = 500;450 this.body.velocity.x = 60 * game.rnd.pick([1, 0]);451 ;452 this.body.bounce.x = 1;453}454Crab.prototype = Object.create(Phaser.Sprite.prototype);455Crab.prototype.constructor = Crab;456Crab.prototype.update = function () {457 if (this.body.velocity.x < 0) {458 this.scale.x = 1;459 } else {460 this.scale.x = -1;461 }462 if (this.body.velocity.x != 0) {463 this.animations.play('walk');464 } else {465 this.animations.play('idle');466 }467 if (this.health <= 0) {468 var death = new EnemyDeath(game, this.x, this.y);469 game.add.existing(death);470 this.destroy();471 }472}473// Jumper474Jumper = function (game, x, y) {475 x *= 16;476 y *= 16;477 this.health = 5;478 Phaser.Sprite.call(this, game, x, y, 'atlas', 'jumper-idle-1');479 this.animations.add('idle', Phaser.Animation.generateFrameNames('jumper-idle-', 1, 4, '', 0), 7, true);480 this.animations.add('jump', ['jumper-jump'], 10, true);481 this.animations.play('idle');482 this.anchor.setTo(0.5);483 game.physics.arcade.enable(this);484 this.body.setSize(16, 25, 16, 8);485 this.body.gravity.y = 500;486 this.body.bounce.x = 1;487 game.time.events.loop(2000, this.jumperJump, this);488 this.dir = -1;489}490Jumper.prototype = Object.create(Phaser.Sprite.prototype);491Jumper.prototype.constructor = Jumper;492Jumper.prototype.update = function () {493 if (this.body.onFloor()) {494 this.body.velocity.x = 0;495 this.animations.play('idle');496 } else {497 this.body.velocity.x = this.dir * 60;498 this.animations.play('jump');499 }500 if (this.health <= 0) {501 var death = new EnemyDeath(game, this.x, this.y);502 game.add.existing(death);503 this.destroy();504 }505}506Jumper.prototype.jumperJump = function () {507 if (!this.alive) {508 return;509 }510 this.dir *= -1;511 this.body.velocity.y = -200;512}513// octopus514Octopus = function (game, x, y) {515 x *= 16;516 y *= 16;517 this.health = 5;518 Phaser.Sprite.call(this, game, x, y, 'atlas', 'octopus-1');519 game.physics.arcade.enable(this);520 this.anchor.setTo(0.5);521 this.body.setSize(14, 22, 8, 6);522 this.animations.add('fly', Phaser.Animation.generateFrameNames('octopus-', 1, 4, '', 0), 15, true);523 this.animations.play('fly');524 var VTween = game.add.tween(this).to({525 y: y + 50526 }, 1000, Phaser.Easing.Linear.None, true, 0, -1);527 VTween.yoyo(true);528};529Octopus.prototype = Object.create(Phaser.Sprite.prototype);530Octopus.prototype.constructor = Octopus;531Octopus.prototype.update = function () {532 if (this.x > player.x) {533 this.scale.x = 1;534 } else {535 this.scale.x = -1;536 }537 if (this.health <= 0) {538 var death = new EnemyDeath(game, this.x, this.y);539 game.add.existing(death);540 this.destroy();541 }542};543// enemy death544EnemyDeath = function (game, x, y) {545 Phaser.Sprite.call(this, game, x, y, 'atlas', 'enemy-death-1');546 this.anchor.setTo(0.5);547 var anim = this.animations.add('death', Phaser.Animation.generateFrameNames('enemy-death-', 1, 5, '', 0), 18, false);548 this.animations.play('death');549 anim.onComplete.add(function () {550 this.kill();551 }, this);552};553EnemyDeath.prototype = Object.create(Phaser.Sprite.prototype);554EnemyDeath.prototype.constructor = EnemyDeath;555// shot impact556ShotImpact = function (game, x, y) {557 Phaser.Sprite.call(this, game, x, y, 'atlas', 'impact-1');558 this.anchor.setTo(0.5);559 var anim = this.animations.add('impact', Phaser.Animation.generateFrameNames('impact-', 1, 5, '', 0), 18, false);560 this.animations.play('impact');561 anim.onComplete.add(function () {562 this.kill();563 }, this);564};565ShotImpact.prototype = Object.create(Phaser.Sprite.prototype);566ShotImpact.prototype.constructor = ShotImpact;567// item568Item = function (game, x, y) {569 x *= 16;570 y *= 16;571 Phaser.Sprite.call(this, game, x, y, 'atlas', 'power-up-1');572 this.anchor.setTo(0.5);573 this.animations.add('item', Phaser.Animation.generateFrameNames('power-up-', 1, 7, '', 0), 20, true);574 this.animations.play('item');575};576Item.prototype = Object.create(Phaser.Sprite.prototype);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { globalMap } from 'ng-mocks';2import { globalMock } from 'ng-mocks';3import { globalMockMethod } from 'ng-mocks';4import { globalMockOf } from 'ng-mocks';5import { globalMockProvider } from 'ng-mocks';6import { globalSpy } from 'ng-mocks';7import { globalSpyMethod } from 'ng-mocks';8import { globalSpyOn } from 'ng-mocks';9import { globalSpyOnProperty } from 'ng-mocks';10import { globalSpyProperty } from 'ng-mocks';11import { globalStub } from 'ng-mocks';12import { globalStubMethod } from 'ng-mocks';13import { globalStubProperty } from 'ng-mocks';14import { globalStubPropertyGetter } from 'ng-mocks';15import { globalStubPropertySetter } from 'ng-mocks';16import { globalStubProvider } from 'ng-mocks';17import { globalTransform } from 'ng-mocks';18import { globalTransformMethod } from 'ng-mocks';19import { globalTransformProperty } from 'ng-mocks';20import { globalTransformProvider } from 'ng-mocks';21import {

Full Screen

Using AI Code Generation

copy

Full Screen

1import { globalMap } from 'ng-mocks';2import { globalMock } from 'ng-mocks';3import { globalMockMethod } from 'ng-mocks';4import { globalMockProperty } from 'ng-mocks';5import { globalSpy } from 'ng-mocks';6import { globalSpyProperty } from 'ng-mocks';7import { globalSpyPropertyGet } from 'ng-mocks';8import { globalSpyPropertySet } from 'ng-mocks';9import { globalSpyReturn } from 'ng-mocks';10import { globalSpyThrow } from 'ng-mocks';11import { globalSpyValue } from 'ng-mocks';12import { globalStub } from 'ng-mocks';13import { globalStubProperty } from 'ng-mocks';14import { globalStubPropertyGet } from 'ng-mocks';15import { globalStubPropertySet } from 'ng-mocks';16import { globalStubReturn } from 'ng-mocks';17import { globalStubThrow } from 'ng-mocks';18import { globalStubValue } from 'ng-mocks';19import { globalUnmock } from 'ng-mocks';20import { globalUnspy } from 'ng-mocks';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { globalMap } from 'ng-mocks';2import { globalMock } from 'ng-mocks';3import { globalMockMethod } from 'ng-mocks';4import { globalMockMethodReturn } from 'ng-mocks';5import { globalMockMethodResolve } from 'ng-mocks';6import { globalMockMethodReject } from 'ng-mocks';7import { globalMockMethodReset } from 'ng-mocks';8import { globalMockMethodCall } from 'ng-mocks';9import { globalMockMethodCalls } from 'ng-mocks';10import { globalMockMethodCallReset } from 'ng-mocks';11import { globalMockMethodCallCount } from 'ng-mocks';12import { globalMockMethodCallArgs } from 'ng-mocks';13import { globalMockMethodCallArg } from 'ng-mocks';14import { globalMockMethodCallArgAt } from 'ng-mocks';15import { globalMockMethodCallArgWith } from 'ng-mocks';16import { globalMockMethodCallArgWithAt } from 'ng-mocks';17import { globalMockMethodCallWith } from 'ng-mocks';18import { globalMockMethodCallWithAt } from 'ng-mocks';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { globalMap } from 'ng-mocks';2import { MyComponent } from './my.component';3describe('MyComponent', () => {4 it('should work', () => {5 const component = globalMap.get(MyComponent);6 });7});8import { Component } from '@angular/core';9@Component({10})11export class MyComponent {12 public doSomething() {13 }14}15import { TestBed } from '@angular/core/testing';16import { MyComponent } from './my.component';17describe('MyComponent', () => {18 it('should work', () => {19 TestBed.configureTestingModule({20 });21 const component = TestBed.get(MyComponent);22 });23});24import { TestBed } from '@angular/core/testing';25import { MyComponent } from './my.component';26describe('MyComponent', () => {27 it('should work', () => {28 TestBed.configureTestingModule({29 });30 const component = TestBed.get(MyComponent);31 });32});33import { TestBed } from '@angular/core/testing';34import { MyComponent } from './my.component';35describe('MyComponent', () => {36 it('should work', () => {37 TestBed.configureTestingModule({38 });39 const component = TestBed.get(MyComponent);40 });41});42import { TestBed } from '@angular/core/testing';43import { MyComponent } from './my.component';44describe('MyComponent', () => {45 it('should work', () => {46 TestBed.configureTestingModule({47 });48 const component = TestBed.get(MyComponent);49 });50});51import { TestBed } from '@angular/core/testing';52import { MyComponent } from './my.component';53describe('MyComponent', () => {54 it('should work', () => {55 TestBed.configureTestingModule({56 });

Full Screen

Using AI Code Generation

copy

Full Screen

1const globalMap = require('ng-mocks').globalMap;2const map = globalMap.get('myModule');3const service = map.get('myService');4const methods = Object.getOwnPropertyNames(service.__proto__);5const firstMethod = methods[0];6service[firstMethod]();7const secondMethod = methods[1];8service[secondMethod]();9const thirdMethod = methods[2];10service[thirdMethod]();11const fourthMethod = methods[3];12service[fourthMethod]();13const fifthMethod = methods[4];14service[fifthMethod]();15const sixthMethod = methods[5];16service[sixthMethod]();17const seventhMethod = methods[6];18service[seventhMethod]();19const eighthMethod = methods[7];20service[eighthMethod]();21const ninthMethod = methods[8];22service[ninthMethod]();23const tenthMethod = methods[9];24service[tenthMethod]();25const eleventhMethod = methods[10];26service[eleventhMethod]();

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run ng-mocks automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful