Frame 1
stop();
Frame 2
go = false;
createEmptyMovieClip("terrain", 1);
terrain.lineStyle(10, 2228309, 100);
imdrawing = false;
onMouseDown = function () {
if (!go) {
if (imdrawing == false) {
terrain.moveTo(_xmouse, _ymouse);
imdrawing = true;
}
if (imdrawing == true) {
onEnterFrame = function () {
terrain.lineTo(_xmouse, _ymouse);
};
}
}
};
onMouseUp = function () {
onEnterFrame = function () {
imdrawing = false;
};
};
stop();
Instance of Symbol 14 MovieClip "exit" in Frame 2
onClipEvent (load) {
drag = false;
}
onClipEvent (enterFrame) {
if (drag == true) {
this._x = _root._xmouse;
this._y = _root._ymouse;
}
}
onClipEvent (keyDown) {
if (getCode() == "<Key.UP>") {
trace("The up arrow key was pressed");
}
}
Instance of Symbol 23 MovieClip "ball" in Frame 2
onClipEvent (load) {
yspeed = -1;
xspeed = -1;
gravity = 0.7;
radius = 5;
friction = 0.9;
precision = 360;
bounces = 0;
}
onClipEvent (enterFrame) {
if (_root.go == true) {
if (_root.exit.hitTest(_x, _y, true)) {
xspeed = 0;
yspeed = 0;
} else {
collisions = 0;
sum_x = 0;
sum_y = 0;
yspeed = yspeed + gravity;
x = 1;
while (x < precision) {
spot_x = _x + (radius * Math.sin((x * 360) / precision));
spot_y = _y - (radius * Math.cos((x * 360) / precision));
if (_root.terrain.hitTest(spot_x, spot_y, true)) {
collisions++;
sum_x = sum_x + spot_x;
sum_y = sum_y + spot_y;
}
x++;
}
if (collisions > 0) {
_root.last_hit._x = old_x;
_root.last_hit._y = old_y;
bounces++;
_root.collisions.text = "Bounces: " + bounces;
ball_dir = Math.atan(yspeed / (xspeed * -1)) / (Math.PI/180);
if ((xspeed * -1) < 0) {
ball_dir = ball_dir + 180;
}
if (((xspeed * -1) >= 0) && (yspeed < 0)) {
ball_dir = ball_dir + 360;
}
spot_x = sum_x / collisions;
spot_y = sum_y / collisions;
x_cat = spot_x - _x;
y_cat = spot_y - _y;
ball_coll = Math.atan(y_cat / x_cat) / (Math.PI/180);
if (x_cat < 0) {
ball_coll = ball_coll + 180;
}
if ((x_cat >= 0) && (y_cat < 0)) {
ball_coll = ball_coll + 360;
}
ground_rotation = ball_coll - 90;
if (ground_rotation < 0) {
ground_rotation = ground_rotation + 180;
}
bounce_angle = (180 - ball_dir) - (2 * ground_rotation);
if (bounce_angle < 0) {
bounce_angle = bounce_angle + 360;
}
speed = Math.sqrt((yspeed * yspeed) + (xspeed * xspeed));
xspeed = (speed * Math.cos((bounce_angle * Math.PI) / 180)) * friction;
yspeed = ((speed * Math.sin((bounce_angle * Math.PI) / 180)) * -1) * friction;
_x = old_x;
_y = old_y;
} else {
old_x = _x;
old_y = _y;
}
_y = (_y + yspeed);
_x = (_x + xspeed);
}
}
}
on (keyPress "<Space>") {
go = false;
}
Frame 3
stop();
Symbol 7 Button
on (press) {
gotoAndPlay (2);
}
Symbol 11 Button
on (press) {
drag = true;
}
on (release) {
drag = false;
}
Symbol 29 Button
on (release) {
go = true;
}
Symbol 32 Button
on (release) {
_root.ball._x = 11.4;
_root.ball._y = 9.2;
_root.ball.xspeed = 0;
_root.ball.yspeed = 0;
_root.go = false;
_root.terrain.clear();
_root.terrain.lineStyle(10, 2228309, 100);
}
Symbol 35 Button
on (release) {
terrain.lineStyle(10, 16713993, 100);
}
Symbol 37 Button
on (release) {
terrain.lineStyle(10, 191560, 100);
}
Symbol 39 Button
on (release) {
terrain.lineStyle(10, 2228309, 100);
}
Symbol 41 Button
on (release) {
terrain.lineStyle(25, 0, 1);
}
Symbol 43 Button
on (release) {
_root.ball._x = 11.4;
_root.ball._y = 9.2;
_root.ball.xspeed = 0;
_root.ball.yspeed = 0;
_root.go = false;
_root.terrain.lineStyle(10, 2228309, 100);
}
Symbol 45 Button
on (release) {
terrain.lineStyle(5, 0, 100);
}
Symbol 47 Button
on (press) {
go = false;
}
Symbol 49 Button
on (press) {
gotoAndPlay (3);
}
Symbol 50 Button
on (press) {
gotoAndPlay (2);
}