html绘制水管,html5 canvas-接水管小游戏_游戏教程_小游戏源码,蚂蚁社区-严谨,有原则的开源社区...

var Box = function(center , style , Gateway , angle , coordinate){

this.center = center;

this.style = style;

this.angle = angle;

this.endangle = angle;

this.Gateway = Gateway;

this.coordinate = coordinate;

}

Box.prototype = {

constructor:Box,

draw:function(){

this.setHole();

if(this.angle!==this.endangle){

canclick = false;

this.rotate();

}

var ext = [

{x:0,y:-boxWidth/2},

{x:boxWidth/2,y:0},

{x:0,y:boxWidth/2},

{x:-boxWidth/2,y:0},

]

ctx.save();

ctx.translate(this.center.x , this.center.y);

ctx.rotate(this.angle);

//画管道

switch(this.style){

case 0:break;

case 1:ctx.drawImage(document.getElementById("pipe1") , -boxWidth/2 , -boxWidth/2 , boxWidth , boxWidth);

break;

case 2:ctx.drawImage(document.getElementById("pipe2") , -boxWidth/2 , -boxWidth/2 , boxWidth , boxWidth);

break;

case 3:ctx.drawImage(document.getElementById("start") , -boxWidth/2 , -boxWidth/2 , boxWidth , boxWidth);

break;

}

ctx.restore();

},

rotate:function(){

if(Math.abs(this.endangle-this.angle)<=0.01){

canclick = true;

this.endangle = this.endangle>=2*Math.PI?0:this.endangle;

this.angle = this.endangle;

if(this.style===3){

var result = connectPipes();

if(result){

// alert('成功连通')

connectSuccess = true;

}

else {

alert("游戏失败")

window.location.reload();

}

}

}

else {

this.angle += (this.endangle-this.angle)*0.2;

}

},

setHole:function(){

if(this.style===1){

var zl = this.endangle/(0.5*Math.PI);

var initHole1 = 0 , initHole2 = 2;

this.inHole = (initHole1+zl)>=4?((initHole1+zl)-4):(initHole1+zl);

this.outHole = (initHole2+zl)>=4?((initHole2+zl)-4):(initHole2+zl);

}

else if(this.style===2){

var zl = this.endangle/(0.5*Math.PI);

var initHole1 = 1 , initHole2 = 2;

this.inHole = (initHole1+zl)>=4?((initHole1+zl)-4):(initHole1+zl);

this.outHole = (initHole2+zl)>=4?((initHole2+zl)-4):(initHole2+zl);

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值