html5 塔防小游戏,HTML5塔防小游戏源代码
/**
*
* Author:
*oldj
*链接已屏蔽
*
* File: td-obj-monster.js
* @save-up: [td.js, ../td.html]
*
* Create Date: 2010-11-20 12:34:41
* Last Update: 2010-11-22 15:01:45
*
*/
// _TD.a.push begin
_TD.a.push(function (TD) {
// monster 瀵硅薄鐨勫睘鎬с€佹柟娉曘€傛敞鎰忓睘鎬т腑涓嶈鏈夋暟缁勩€佸璞$瓑
// 寮曠敤灞炴€э紝鍚﹀垯澶氫釜瀹炰緥鐨勭浉鍏冲睘鎬т細鍙戠敓鍐茬獊
var monster_obj = {
_init: function (cfg) {
cfg = cfg || {};
this.idx = cfg.idx || 1;
this.difficulty = cfg.difficulty || 1.0;
var attr = TD.getDefaultMonsterAttributes(this.idx);
this.speed = Math.floor(
(attr.speed + this.difficulty - 1) * (Math.random() * 0.5 + 0.75));
if (this.speed < 1) this.speed = 1;
if (this.speed > cfg.max_speed) this.speed = cfg.max_speed;
this.life = this.life0 = Math.floor(attr.life * this.difficulty * (Math.random() + 0.5));
if (this.life < 1) this.life = this.life0 = 1;
this.shield = Math.floor(attr.shield + Math.sqrt(this.difficulty) - 1);
if (this.shield < 0) this.shield = 0;
this.damage = Math.floor((attr.damage || 1) * (0.5 + Math.random()));
if (this.damage < 1) this.damage = 1;
this.money = attr.money || Math.floor(Math.sqrt((this.speed + this.life) * (this.shield + 1) * this.damage));
if (this.money < 1) this.money = 1;
this.color = attr.color || TD.lang.rndRGB();
this.r = this.damage;
if (this.r < 4) this.r = 4;
if (this.r > TD.grid_size / 2 - 4) this.r = TD.grid_size / 2 - 4;
this.render = attr.render;
this.grid = null; // 褰撳墠鏍煎瓙
this.map = null;
this.next_grid = null;
this.way = [];
this.toward = 2; // 榛樿闈㈡湞涓嬫柟
this._dx = 0;
this._dy = 0;
},
caculatePos: function () {
if (!this.map) return;
},
beHit: function (building, damage) {
if (!this.is_valid) return;
damage -= this.shield;
if (damage <= 0) damage = 1;
this.life -= damage;
TD.score += Math.min(
Math.floor(Math.sqrt(damage)), 1
);
if (this.life < 0) {
this.beKilled(building);
}
},
beKilled: function (building) {
if (!this.is_valid) return;
this.life = 0;
this.is_valid = false;
TD.money += this.money;
building.killed ++;
},
arrive: function () {
this.grid = this.next_grid;
this.next_grid = null;
this.checkFinish();
},
findWay: function () {
var _this = this;
var fw = new TD.FindWay(
this.map.grid_x, this.map.grid_y,
this.grid.mx, this.grid.my,
this.map.exit.mx, this.map.exit.my,
function (x, y) {
return _this.map.checkPassable(x, y);
}
);
this.way = fw.way;
delete fw;
},
/**
* 妫€鏌ユ槸鍚﹀凡鍒拌揪缁堢偣
*/
checkFinish: function () {
if (this.grid && this.map && this.grid == this.map.exit) {
TD.life -= this.damage;
TD.wave_damage += this.damage;
if (TD.life <= 0) {
TD.life = 0;
TD.stage.gameover();
} else {
this.pause();
this.del();
}
}
},
beAddToGrid: function (grid) {
this.grid = grid;
this.map = grid.map
this.cx = grid.cx;
this.cy = grid.cy;
this.grid.scene.addElement(this);
},
/**
* 鍙栧緱鏈濆悜
* 鍗充笅涓€涓牸瀛愬湪褰撳墠鏍煎瓙鐨勫摢杈? * 0锛氫笂锛?锛氬彸锛?锛氫笅锛?锛氬乏
*/
getToward: function () {
if (!this.grid || !this.next_grid) return;
if (this.grid.my < this.next_grid.my) {
this.toward = 0;
} else if (this.grid.mx < this.next_grid.mx) {
this.toward = 1;
} else if (this.grid.my > this.next_grid.my) {
this.toward = 2;
} else if (this.grid.mx > this.next_grid.mx) {
this.toward = 3;
}
},
getNextGrid: function () {
if (this.way.length == 0 ||
Math.random() < 0.1 // 鏈?1/10 鐨勬鐜囪嚜鍔ㄩ噸鏂板璺?) {
this.findWay();
}
var next_grid = this.way.shift();
if (next_grid && !this.map.checkPassable(next_grid[0], next_grid[1])) {
this.findWay();
next_grid = this.way.shift();
}
if (!next_grid) {
return;
}
this.next_grid = this.map.getGrid(next_grid[0], next_grid[1]);
this.getToward();
},
step: function () {
if (!this.is_valid || this.is_paused || !this.grid) return;
if (!this.next_grid) {
this.getNextGrid();
}
if (this.cx == this.next_grid.cx && this.cy == this.next_grid.cy) {
this.arrive();
} else {
// 绉诲姩鍒?next grid
var dpx = this.next_grid.cx - this.cx,
dpy = this.next_grid.cy - this.cy,
sx = dpx < 0 ? -1 : 1,
sy = dpy < 0 ? -1 : 1,
speed = this.speed * TD.global_speed;
if (Math.abs(dpx) < speed && Math.abs(dpy) < speed) {
this.cx = this.next_grid.cx;
this.cy = this.next_grid.cy;
this._dx = speed - Math.abs(dpx);
this._dy = speed - Math.abs(dpy);
} else {
this.cx += dpx == 0 ? 0 : sx * (speed + this._dx);
this.cy += dpy == 0 ? 0 : sy * (speed + this._dy);
this._dx = 0;
this._dy = 0;
}
}
},
onClick: function () {
}
};
/**
* @param cfg 閰嶇疆瀵硅薄
* 鑷冲皯闇€瑕佸寘鍚互涓嬮」锛? * {
* life: 鎬墿鐨勭敓鍛藉€? * shield: 鎬墿鐨勯槻寰″€? * speed: 鎬墿鐨勯€熷害
* }
*/
TD.Monster = function (id, cfg) {
//cfg.on_events = ["enter", "out", "click"];
//monster 鏆傛椂涓嶇洃鍚簨浠?var monster = new TD.Element(id, cfg);
TD.lang.mix(monster, monster_obj);
monster._init(cfg);
return monster;
}
}); // _TD.a.push end
更多源码 | 好库简介 | 网站地图 | 帮助中心 | 版权说明
Copyright© 2009-2012 OKBASE.NET All Rights Reserved 好库网 版权所有
html5 塔防小游戏,HTML5塔防小游戏源代码相关推荐
- html塔防游戏,HTML5 版塔防游戏
HTML5 版塔防游戏来自老杰的博客,本人很喜欢这款游戏.就转载到苏岳宁博客里,希望更多的朋友看到试玩这款TD游戏吧!下面是游戏进行时的截图: 下文来自老杰的博客: ---------------- ...
- XMUOJ·小H的塔防游戏2
小H的塔防游戏2 题目描述 小H在你的帮助下成功通过了塔防游戏1. 现在来到了第二关,有一个n*n的地图,地图中'X'代表障碍物,'.'代表空地. 小H需要在空地上建防御塔,规定任意两个防御塔不能位于 ...
- 微信小程序做塔防类游戏
开发一款塔防游戏需要以下步骤: 设计游戏规则和关卡设计,包括塔防类型.敌人类型.塔类型.升级系统等. 使用微信开发者工具创建新的小程序项目. 使用小程序框架(WXML.WXSS和JavaScript) ...
- python小游戏毕设 塔防小游戏设计与实现 (源码)
文章目录 0 项目简介 1 游戏介绍 2 实现效果 3 Pygame介绍 4 原理和实现 4.1 环境配置 4.2 游戏界面说明 4.3 游戏主逻辑 4.4 游戏开始界面 4.5 游戏选择界面 4.6 ...
- 【毕业设计】 python小游戏毕设 - 塔防小游戏设计与实现
文章目录 0 前言 1 课题背景 2 实现效果 3 Pygame介绍 4 原理和实现 4.1 环境配置 4.2 游戏界面说明 4.3 游戏主逻辑 4.4 游戏开始界面 4.5 游戏选择界面 4.6 实 ...
- 【HMS Core案例分享】华为分析 X 江湖游戏 | 揭秘塔防游戏的增长秘籍
江湖游戏是一家集网络游戏发行.运营和服务于一体的公司,于2018年成立,是国内新兴的游戏发行商之一.江湖游戏凭借着3D欧美卡通塔防巨作<塔塔帝国>,以及诙谐幽默的<泡面三国>, ...
- 开发者已将您从测试计划中移除_深度合作,Ohayoo定制模式为开发者提供更全面的支持|塔防|游戏|休闲游戏|ohayoo|塔防游戏...
Ohayoo和成都这个城市的缘分由来已久.据统计,在过去一年多时间里,Ohayoo为成都地区超过50家开发者提供了产品调优上的建议,与超过20家开发者建立了实质性的合作关系,并储备了待上线产品10余款 ...
- unity塔防游戏怪物转向_一款塔防+第一人称射击的混合类游戏
HELLO-大家好,这里是小白的每日一游推荐时间.世上的游戏千千万,有许多好玩的游戏由于缺乏宣传,所以不被广大玩家所熟知.在这里小白每天会为大家推荐一款评价很高但是不太出名的游戏- <幽闭圣地 ...
- 河内塔php,基于HTML5的WebGL设计汉诺塔3D游戏
在这里我们将构造一个基于HT for Web的HTML5+JavaScript来实现汉诺塔游戏. 知道了汉诺塔的规则和算法,现在就开始创建元素.用HT for Web(http://www.hight ...
- 手机游戏缺少index_264.html,html5手机端大家来找茬微信小游戏代码
特效描述:html5 手机端大家来找茬 微信小游戏代码.html5手机端大家来找茬微信小游戏代码 代码结构 1. HTML代码 重新开始 剩余时间: 30 s 分数: 0 点 击 开 始 游 戏 护眼 ...
最新文章
- 微信小程序点击图片实现长按预览、保存、识别带参数二维码、转发等功能
- Android性能优化之APK优化,内容太过真实
- Apache Shiro Architecture--官方文档
- 轻量级3d模型查看器_耐能取得两项软件著作权,自研轻量级3D人脸识别算法领先业界...
- 对于Eclipse的正确用法
- 读《可复制的领导力》
- 华为荣耀v20是android10,荣耀V20和荣耀V10买哪个好
- 此次边路调整系统推荐射手走哪路_王者荣耀地图重大对称改动,终于能射手对射手,上单对上单了...
- 美国影视演员协会选择了Windows Azure
- linux下怎么创建root,Linux用root账号创建一个新的登录账号的方法
- 爆火的Java面试题-kafka源码解析与实战豆瓣
- 提出问题之后,对于回答问题内容的仔细确认!!!(一个字一个字确认!!)
- mount: RPC: Unable to receive; errno = Connection refused 的解决方法
- 软件测试之 app性能测试的指标
- MAC下Charles的破解版
- caffe安装+Ubuntu16.04+三显卡gpu加速
- 2018年 - 年终总结
- 自媒体行业的发展和前景
- 传统深度模型的uncertainty----Monte Carlo dropout
- 旺店通·企业奇门和用友BIP接口打通对接实战