果实运动的速度越来越快,求解,已初始化
果实运动的速度越来越快,求解,已初始化
果实运动的速度越来越快,求解,已初始化
2016-01-27
var fruitObj = function() { this.x = []; this.y = []; this.l = []; this.alive = []; this.speed = []; this.orange = new Image(); this.blue = new Image(); this.fruitType = []; } fruitObj.prototype.num = 30; fruitObj.prototype.init = function() { for (var i = 0; i <= this.num; i++) { this.alive[i] = false; this.x[i] = 0; this.y[i] = 0; this.l[i] = 0; this.fruitType[i] = ''; this.speed[i] = Math.random() * 0.0003 + 0.00001; //[ 0.00001 , 0.00051) this.born(i); } this.orange.src = './src/fruit.png'; this.blue.src = './src/blue.png'; } fruitObj.prototype.draw = function() { for (var i = 0; i < this.num; i++) { if( this.alive[i]){ if( this.fruitType[i] == 'blue' ){ var pic = this.blue; }else{ var pic = this.orange; } if( this.l[i] <= 14){ this.l[i] += this.speed[i] * deltaTime; }else{ this.y[i] -= this.speed[i] * deltaTime; } ctx2.drawImage( pic , this.x[i] - this.l[i] , this.y[i] - this.l[i] , this.l[i] , this.l[i] ) if( this.y[i] < 10 ){ this.alive[i] = false; } } }; } fruitObj.prototype.born = function(i) { var aneId = Math.floor(Math.random() * ane.num); this.x[i] = ane.x[aneId]; this.y[i] = canH - ane.len[aneId]; this.l[i] = 0; this.alive[i] = true; var ran = Math.random(); if( ran < 0.3 ){ this.fruitType[i] = 'blue' }else{ this.fruitType[i] = 'orange'; } } fruitObj.prototype.fruitManger = function() { var num = 0; for (var i = 0; i < fruit.num; i++) { if(fruit.alive[i]){ num++; } } if( num < 15 ){ fruit.rebornFruit(); return; } } fruitObj.prototype.rebornFruit = function() { for (var i = 0; i < fruit.num; i++) { if(!fruit.alive[i]){ fruit.born(i); return; } }; };
是啊,而且在出生的时候,也给this.l[i]=0了
var fruitObj = function() {
this.x = [];
this.y = [];
this.l = [];
this.alive = [];
this.speed = [];
this.orange = new Image();
this.blue = new Image();
this.fruitType = [];
}
fruitObj.prototype.num = 30;
fruitObj.prototype.init = function() {
for (var i = 0; i <= this.num; i++) {
this.alive[i] = false;
this.x[i] = 0;
this.y[i] = 0;
this.l[i] = 0;
this.fruitType[i] = '';
this.speed[i] = Math.random() * 0.0003 + 0.00001; //[ 0.00001 , 0.00051)
this.born(i);
}
this.orange.src = './src/fruit.png';
this.blue.src = './src/blue.png';
}
fruitObj.prototype.draw = function() {
for (var i = 0; i < this.num; i++) {
if( this.alive[i]){
if( this.fruitType[i] == 'blue' ){
var pic = this.blue;
}else{
var pic = this.orange;
}
if( this.l[i] <= 14){
this.l[i] += this.speed[i] * deltaTime;
}else{
this.y[i] -= this.speed[i] * deltaTime;
}
ctx2.drawImage( pic , this.x[i] - this.l[i] , this.y[i] - this.l[i] , this.l[i] , this.l[i] )
if( this.y[i] < 10 ){
this.alive[i] = false;
}
}
};
}
fruitObj.prototype.born = function(i) {
var aneId = Math.floor(Math.random() * ane.num);
this.x[i] = ane.x[aneId];
this.y[i] = canH - ane.len[aneId];
this.l[i] = 0;
this.alive[i] = true;
var ran = Math.random();
if( ran < 0.3 ){
this.fruitType[i] = 'blue'
}else{
this.fruitType[i] = 'orange';
}
}
fruitObj.prototype.fruitManger = function() {
var num = 0;
for (var i = 0; i < fruit.num; i++) {
if(fruit.alive[i]){
num++;
}
}
if( num < 15 ){
fruit.rebornFruit();
return;
}
}
fruitObj.prototype.rebornFruit = function() {
for (var i = 0; i < fruit.num; i++) {
if(!fruit.alive[i]){
fruit.born(i);
return;
}
};
};
举报