width = ball._width/2-1;
vx = vy = 0;
grav = 2;
damp = 0.98;
k = 0.1;
left = 0;
right = 500;
top = 150;
bottom = 350;
bounce = -0.6;
out = false;
ball.onPress = function() {
out = true;
this.startDrag(true,left+width,0,right-width,bottom);
};
ball.onRelease = onReleaseOutside = function() {
out = false;
this.stopDrag();
};
MovieClip.prototype.drawline = function(x, y) {
x1 = x-_root.width;
x2 = x+_root.width;
with (this._parent) {
clear();
beginFill(0x123456);
lineStyle(1);
moveTo(left, top);
curveTo(x1, top, x1, y);
lineTo(x2, y);
curveTo(x2, top, right, top);
lineTo(right, 350);
lineTo(left, 350);
lineTo(left, top);
endFill();
}
};
MovieClip.prototype.drawline_0 = function() {
with (this._parent) {
clear();
beginFill(0x123456);
lineStyle(1);
moveTo(left, top);
lineTo(right, top);
lineTo(right, 350);
lineTo(left, 350);
lineTo(left, top);
}
};
function angle(x1, y1) {
var dx = ball._x-x1;
var dy = ball._y-y1;
var a = Math.atan2(dy, dx);
var distance = Math.sqrt(dx*dx+dy*dy);
var ax = (distance/Math.cos(a)-dx)*k;
var ay = dy*k*-1;
vx = vx+ax;
vy = vy+ay;
}
_root.createEmptyMovieClip("line", 0);
_root.createEmptyMovieClip("line1", 2000);
_root.onEnterFrame = function() {
if (!out) {
vy += grav;
vy *= damp;
vx *= damp;
ball._y += vy;
ball._x += vx;
}
if (ball._y>top && ball._x>left && ball._y<right) {
if (!out) {
angle(left, top);
angle(right, top);
}
line.drawline(ball._x, ball._y);
} else {
line1.drawline_0();
}
if (ball._x>right) {
ball._x = right;
vx = vx*bounce;
}
if (ball._x<left) {
ball._x = left;
vx = vx*bounce;
}
};
Flash 动画:
vx = vy = 0;
grav = 2;
damp = 0.98;
k = 0.1;
left = 0;
right = 500;
top = 150;
bottom = 350;
bounce = -0.6;
out = false;
ball.onPress = function() {
out = true;
this.startDrag(true,left+width,0,right-width,bottom);
};
ball.onRelease = onReleaseOutside = function() {
out = false;
this.stopDrag();
};
MovieClip.prototype.drawline = function(x, y) {
x1 = x-_root.width;
x2 = x+_root.width;
with (this._parent) {
clear();
beginFill(0x123456);
lineStyle(1);
moveTo(left, top);
curveTo(x1, top, x1, y);
lineTo(x2, y);
curveTo(x2, top, right, top);
lineTo(right, 350);
lineTo(left, 350);
lineTo(left, top);
endFill();
}
};
MovieClip.prototype.drawline_0 = function() {
with (this._parent) {
clear();
beginFill(0x123456);
lineStyle(1);
moveTo(left, top);
lineTo(right, top);
lineTo(right, 350);
lineTo(left, 350);
lineTo(left, top);
}
};
function angle(x1, y1) {
var dx = ball._x-x1;
var dy = ball._y-y1;
var a = Math.atan2(dy, dx);
var distance = Math.sqrt(dx*dx+dy*dy);
var ax = (distance/Math.cos(a)-dx)*k;
var ay = dy*k*-1;
vx = vx+ax;
vy = vy+ay;
}
_root.createEmptyMovieClip("line", 0);
_root.createEmptyMovieClip("line1", 2000);
_root.onEnterFrame = function() {
if (!out) {
vy += grav;
vy *= damp;
vx *= damp;
ball._y += vy;
ball._x += vx;
}
if (ball._y>top && ball._x>left && ball._y<right) {
if (!out) {
angle(left, top);
angle(right, top);
}
line.drawline(ball._x, ball._y);
} else {
line1.drawline_0();
}
if (ball._x>right) {
ball._x = right;
vx = vx*bounce;
}
if (ball._x<left) {
ball._x = left;
vx = vx*bounce;
}
};
Flash 动画:
回复Comments
作者:
{commentrecontent}