view Earth_x/ball.js @ 9:182428b3aee8

vacuum_ver6
author <e085737>
date Sat, 04 Dec 2010 22:08:22 +0900
parents fccccbcc94be
children
line wrap: on
line source

function update(ctx){
    for(num in balls){
        var data = balls[num];
	data.collision(data);
	data.update(data);
	drawBall(ctx, currentAngle, data.x, data.y, data.z, data.scale, ctx.obj.Earth);
    }
}

function Ball(x,y,z){
    this.x=x;
    this.y=y;
    this.z=z;
    this.scale = 0.005; // 大きさ
    this.dx=0.2;        // 初速度
    this.dy=0;
    this.update=ballupdate;
    this.collision = ballcollision;
    return this;
}

ballupdate = function Bupdate(ball){
    if(ball.dx > a){
        ball.dx -= a;
    }else if(ball.dx < -a){
	ball.dx += a;
    }else{
	ball.dx = 0;
    }
    ball.x += ball.dx;
    ball.dy -= g;
    ball.y += ball.dy;
}

ballcollision = function Bcollision(ball){
    if(ball.y <= -1){
	ball.y = -1;
	ball.dy = -ball.dy * e;
    }
    if(ball.x <= -2.7){
	ball.x = -2.7;
	ball.dx = -ball.dx * e;
    }
    if(ball.x >= 2.7){
	ball.x = 2.7;
	ball.dx = -ball.dx * e;
    }
}