1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| function init()
{
top = 0;
left = 0;
bottom = 280;
right = Stage.width;
vpx = 3;
vpy = -4;
}
vx = 0;
vy = 0;
gravity = 0.5;
bounce = -0.7;
debut = getTimer();
Mouse.hide();
init();
onEnterFrame = function ()
{
temps.text = Math.round(getTimer() - debut) / 1000;
point._x = point._x + vpx;
point._y = point._y + vpy;
if (point._x + point._width / 2 > right)
{
point._x = right - point._width / 2;
vpx = vpx * -1;
}
else
{
if (point._x - point._width / 2 < left)
{
point._x = left + point._width / 2;
vpx = vpx * -1;
}
}
if (point._y + point._height / 2 > bottom)
{
delete onEnterFrame;
gotoAndStop("perdu");
}
else
{
if (point._y - point._height / 2 < top)
{
point._y = top + point._height / 2;
vpy = vpy * -1;
}
else
{
if (0 != (0 != point._y + point._height / 2 > pad._y & 0 != point._x > pad._x - pad._width / 2) & 0 != point._x < pad._x + pad._width / 2)
{
point._y = pad._y - point._height / 2;
vpy = vpy * -1.05;
vpx = (point._x - pad._x) / 4;
vpy = vpy * 1.05;
}
}
}
line._rotation = (Stage.width / 2 - _xmouse) * 0.22;
pad._x = _xmouse;
vy = vy + gravity;
ball._x = ball._x + vx;
ball._y = ball._y + vy;
if (ball._y > 540)
{
delete onEnterFrame;
gotoAndStop("perdu");
}
bounds = line.getBounds(this);
if (ball._x > bounds.xMin && ball._x < bounds.xMax)
{
angle = line._rotation * 3.14159265359 / 180;
cosine = Math.cos(angle);
sine = Math.sin(angle);
x = ball._x - line._x;
y = ball._y - line._y;
y1 = cosine * y - sine * x;
if (y1 > (0 - ball._height) / 2)
{
x1 = cosine * x + sine * y;
vx1 = cosine * vx + sine * vy;
vy1 = cosine * vy - sine * vx;
y1 = (0 - ball._height) / 2;
vy1 = vy1 * bounce;
x = cosine * x1 - sine * y1;
y = cosine * y1 + sine * x1;
vx = cosine * vx1 - sine * vy1;
vy = cosine * vy1 + sine * vx1;
ball._x = line._x + x;
ball._y = line._y + y;
}
}
}
; |
Partager