// 定义海葵对象类
var aneObj = function()
{
//ane start point, control point , end point(sin) 二次贝塞尔曲线
this.rootx = []; //海葵x位置
this.headx = [];
this.heady = [];
this.amp = [];
this.alpha = 0;
}
// 定义海葵原型对象数量
aneObj.prototype.num = 50;
// 海葵初始化,随机产生海葵x位置和长度
aneObj.prototype.init = function()
{
for (var i = 0; i < this.num; i++)
{
this.rootx[i] = i *16 + Math.random() *20; //[0,1)
this.headx[i] = this.rootx[i];
this.heady[i] = canHeight - 250 + Math.random() * 50;
this.amp[i] = Math.random() * 50 + 100;
//console.log("a");
}
}
// 画海葵
aneObj.prototype.draw = function()
{
this.alpha += deltaTime * 0.0003; //deltaTime 为啥不起作用???
var l = Math.sin(this.alpha);
ctx2.save();
ctx2.globalAlpha = 0.6;//海葵的透明度
ctx2.lineCap = "round";//海葵线头形状
ctx2.strokeStyle = "#3b154a";//海葵的颜色
ctx2.lineWidth = 20; //海葵的粗细
for(var i = 0; i<this.num; i++)
{
//beginPath, moveTo, lineTo, lineWidth, lineCap, strokeStyle, stroke
ctx2.beginPath();
ctx2.moveTo(this.rootx[i], canHeight);
this.headx[i] = this.rootx[i] + l * this.amp[i];
ctx2.quadraticCurveTo(this.rootx[i], canHeight - 150, this.headx[i] , this.heady[i]); //二次贝塞尔曲线
ctx2.stroke();
}
ctx2.restore();
}
大鱼吃小鱼游戏-ane.js
最新推荐文章于 2024-05-18 17:28:50 发布