大鱼吃小鱼游戏-mom.js
2015-11-13 11:04
666 查看
var momObj = function() { this.x ; this.y ; this.angle ; //定义角度 this.bigEye = new Image(); //鱼眼睛 //this.bigBody = new Image(); // 鱼身体 this.bigTail = new Image(); //鱼尾巴 this.momTailTimer = 0; this.momTailCount = 0; this.momEyeTimer = 0; this.momEyeCount = 0; this.momEyeInterval = 1000; this.momBodyCount = 0; } momObj.prototype.init = function() { this.x = 0; this.y = 0; this.angle = 0; this.bigEye.src ='./src/bigEye0.png'; //this.bigBody.src ='./src/bigSwim0.png'; this.bigTail.src ='./src/bigTail0.png'; } momObj.prototype.draw = function() { //lerp x,y计算鱼与鼠标距离差,目的是让鱼跟随鼠标动。 this.x = lerpDistance(mousex, this.x, 0.98); this.y = lerpDistance(mousey, this.y, 0.99); //delta angle //Math.atan2(y,x) var deltaY = mousey - this.y; var deltaX = mousex - this.x; var beta = Math.atan2(deltaY, deltaX) + Math.PI;//-PI , PI //lerp angle this.angle = lerpAngle(beta, this.angle, 0.6); //计算出鱼与鼠标角度 //tail this.momTailTimer +=17; if(this.momTailTimer > 50) { this.momTailCount = (this.momTailCount + 1) % 8; this.momTailTimer %= 50; } //mom eye this.momEyeTimer += 17; if(this.momEyeTimer > this.momEyeInterval) { this.momEyeCount = (this.momEyeCount +1) % 2; this.momEyeTimer %= this.momEyeInterval; if(this.momEyeCount == 0) { this.momEyeInterval = Math.random() * 1500 + 2000; } else { this.momEyeInterval = 200; } } ctx1.save(); ctx1.translate(this.x, this.y); ctx1.rotate(this.angle); //鱼跟随鼠标转动 var momTailCount = this.momTailCount; ctx1.drawImage(momTail[momTailCount], - momTail[momTailCount].width * 0.5 + 30 , - momTail[momTailCount].height * 0.5); var momBodyCount = this.momBodyCount; if(data.double == 2)//ora { ctx1.drawImage(momBodyBlue[momBodyCount], - momBodyBlue[momBodyCount].width * 0.5 , - momBodyBlue[momBodyCount].height * 0.5); }else { ctx1.drawImage(momBodyOra[momBodyCount], - momBodyOra[momBodyCount].width * 0.5 , - momBodyOra[momBodyCount].height * 0.5); } var momEyeCount = this.momEyeCount; ctx1.drawImage(momEye[momEyeCount], - momEye[momEyeCount].width * 0.5 , - momEye[momEyeCount].height * 0.5); //ctx1.drawImage(this.bigBody, - this.bigBody.width * 0.5 , - this.bigBody.height * 0.5); ctx1.restore(); }
相关文章推荐
- 大鱼吃小鱼游戏-baby.js
- 使用three.js画一个三角形
- javascript 根据身份证号码取得生日与性别
- cJSON学习笔记
- 大鱼吃小鱼游戏-ane.js
- javascript 判断18位身份证的正确与错误
- JSP文件上传--Smartupload组件
- 理解JavaScript的作用域链
- JavaScript中的this
- 简单js图片点击向左滚动
- js冒泡排序(Bubble Sort)
- javascript内置对象之arguments
- 大鱼吃小鱼游戏-main.js
- Javascript 操作select控件大全(新增、修改、删除、选中、清空、判断存在等)
- javascript:void(0)点击登录没反应怎么解决
- Javascript获取页面元素的位置
- JavaScript中的setInterval用法
- javascript:void(0)是什么意思及href=#与href=javascriptvoid(0)的区别
- JSP引用JS文件中文乱码问题
- js判断输入的数值大于另一个数值