|
2#
楼主 |
发表于 2018-5-18 15:34:35
|
只看该作者
- // 构造器
- return function(urlObj, callback) {
- this.callback = callback;
- if (!TankWar.mySite) { // 如果没有启动预加载,直接进入回调
- this.progressBar(100);
- return;
- }
- this.urlList = obj2array(urlObj);
- this.total = this.urlList.length;
- this.succeedcount = 0;
- this.errorcount = 0;
- this.init();
- }
- })();
- PreLoad.prototype = {
- loadImg: function(url) {
- var img = new Image(), that = this;
- img.onload = function() {
- that.complete(url, '图片');
- }
- img.onerror = function() {
- that.error(url);
- }
- img.src = url;
- },
- loadMap: function(url) {
- var that = this;
- $.getJSON(url, function(map) {
- TankWar.maps.push(map);
- that.complete(url, '地图');
- });
- },
- complete: function(url, type) {
- this.progressBar(Math.round(++this.succeedcount*100/this.total), url, type);
- },
- error: function(url) {
- throw new Error('load '+ url +' failed.');
- },
- progressBar: function(percent, url, type) {
- if (url && type) {
- $('#percent span').text(percent);
- $('#loading span').text(type + ': ' + url.substr(url.lastIndexOf('/') + 1, url.length));
- }
- $('#bar').stop().animate({left: 550 - 550*percent/100}, 200);
- if (percent === 100) this.over();
- },
- over: function() {
- var that = this;
- setTimeout(function() {
- that.callback();
- }, 500);
- },
- init: function() {
- $('#percent, #loading').show();
- for (var i = 0; i < this.total; i++) {
- if (/\.json$/.test(this.urlList))
- this.loadMap(this.urlList);
- else
- this.loadImg(this.urlList);
- }
- }
- };
- 5.util.js 接口、接口检查、继承等的实现。
- 6.tank.namespace.js & tank.config.js 命名空间及常用参数。
- Javascript代码
- var config = {};
- config.my_site = ''; // 如果将此游戏放在您网站上,请配置网址如:config.my_site = 'http://www.mysite.com/tank',将会自动启用预加载技术,以获得更好的游戏体验
- config.develop_model = 'product'; // develop|test|product 如果是product,将不进行接口检查,以提高游戏速度
- config.enemy_number_of_level = [{r:5,b:3,y:2,g:1},{r:10,b:5,y:3,g:2},{r:15,b:5,y:5,g:5}]; // 每一关的敌方坦克数量,目前有三关
- config.default_scene = 'lawn'; // 默认场景
- // 游戏参数
- config.player1_lives = 4;
- config.player1_speed = 2;
- config.player1_move_keys = { 37: 'left', 38: 'up', 39: 'right', 40: 'down'};
- config.player1_fire_key = 32;
- config.player2_lives = 4;
- config.player2_speed = 2;
- config.player2_move_keys = { 65: 'left', 87: 'up', 68: 'right', 83: 'down'};
- config.player2_fire_key = 71;
- config.enemy_red_speed = 1;
- config.enemy_blue_speed = 1.5;
- config.enemy_yellow_speed = 2;
- config.enemy_green_speed = 2.5;
- config.bullet_speed = 10;
- 7.1-3.json 地图
- Javascript代码
- [{
- "type": "b", // b为敌方坦克出生地,你可以添加/减少b的个数,调节敌方坦克数量
- "y": 10,
- "x": 9
- }, {
- "type": "b",
- "y": 9,
- "x": 332
- }, {
- "type": "b",
- "y": 9,
- "x": 653
- },
- {
- "type": "h", // 子弹打不破的石头
- "y": 172,
- "x": 10
- },
- {
- "type": "l", // 草地
- "y": 212,
- "x": 43
- }, {
- "type": "e", // 子弹两次可以打破的砖头
- "y": 212,
- "x": 79
- }]
复制代码
|
|