慕粉1728572880
//分值计算
var dataObj = function ()
{
this.fruitNum = 0;
this.double = 1;
this.score = 0;
this.gameOver = false;
this.alpha = 0;
}
dataObj.prototype.draw = function()
{
var w = can1.width;
var h = can1.height;
ctx1.save();
ctx1.shadoBlur = 10;
ctx1.shadowColor = "white";
ctx1.fillStyle = "white";
ctx1.fillText("分数 " + this.score, w * 0.5, h - 20);
if(this.gameOver)
{
this.alpha += deltaTime * 0.0005;
if(this.alpha > 1)
this.alpha = 1;
ctx1.fillStyle = "rgba(255,255,255," + this.alpha +")";
ctx1.fillText("游戏结束", w * 0.5, h * 0.5);
}
ctx1.restore();
}
dataObj.prototype.addScore = function()
{
this.score += this.fruitNum * 10 * this.double;
this.fruitNum = 0;
this.double = 1;
}
了缺3282150
我觉得这个就像是Photoshop一样,用两个canvas相当于两层,后面一层绘制背景,海草,前面一层绘制大鱼,小鱼,果实,这样静态的事物在后面,动态的事物在前面,相互分开有利于开发,层次分明,相互不会干扰
银白色暴风雪
ChristineN
频繁创建和析构对象,造成效率降低。“池”这个数据结构的作用之一就是为了消除这方面的效率瓶颈。
qq_不懂_18
在baby.js代码中判断时将判断语句this.babyBodyTimer改成大于三百就没有那么快了
慕标1555283
也可以动态添加按钮
追风逐日
主要看那些类方法,注意规律,理清各个方法之间的联系就好,多看几遍没事
JSAL
for(var i=0; i<this.num; i++){
if(this.alive[i]){
//draw
this.r[i] += deltaTime*0.04;
if(this.r[i]>50){
this.alive[i] = false;
continue;
}
var alpha = 1 - this.r[i]/50;
ctx1.beginPath();
ctx1.arc(this.x[i], this.y[i], this.r[i], 0, Math.PI*2);
ctx1.closePath();
ctx1.strokeStyle = "rgba(255, 255, 255,"+ alpha +")";
ctx1.stroke();
}
}
年年青瑜
综合评分下面有,资料下载,点击 绿色 “下载”就可以了。
飞翔123
//判断大鱼和果实的距离
function momFruitsCollision(){
if(!data.gameOver){
for (var i=0;i< fruit.num;i++){
if(fruit.alive[i]){
//
var l =calLength2(fruit.x[i],fruit.y[i],mom.x,mom.y);
if(l < 500){
fruit.dead(i);
//
data.fruitNum ++;
mom.momBodyCount ++;
if(mom.momBodyCount > 7){
mom.momBodyCount = 7;
}
if(fruit.fruitType[i] == "blue"){
data.double =2;
}
wave.born(fruit.x[i],fruit.y[i]);
}
}
}
}
}
//mom baby collision
function momBabyCollision(){
if(!data.gameOver){
if(data.fruitNum > 0){
var l = calLength2(mom.x,mom.y,baby.x,baby.y);
if(l < 500){
baby.babyBodyCount = 0;
// data => 0
// data.reset();
mom.momBodyCount = 0;
//score update
data.addScore();
//draw halo
halo.born(baby.x,baby.y);
}
}
}
}
王不留形
...嗯,有个图片的路径少了一个"." 是我逗比了
大家不要再浪费时间了
纳格兰
不清楚。。。但感觉不是代码的问题而是电脑的问题。。。