大鱼吃小鱼游戏-ane.js

// 定义海葵对象类
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();
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值