I've searched for an actionscript to do this, but I'm afraid it needs some modification to work in koolmoves. If anyone has some time left to try and make this work.
The basic idea is that you have a ball an a boundary box where the ball bounces in.
the actionscript looks like this :
onClipEvent (load) {
// Used to determine if object is being dragged
dragged = false;
// Give the object a random starting speed
xspeed = Math.round(Math.random()*4+2);
yspeed = Math.round(Math.random()*4+2);
// Define the boundaries based on the box
left = /boundary:_x-(/boundary:_width/2);
right = /boundary:_x+(/boundary:_width/2);
top = /boundary:_y-(/boundary:_height/2);
bottom = /boundary:_y+(/boundary:_height/2);
// Friction is percent of speed retained each frame
friction = 0.99;
// Constant which represents effect of gravity
gravity = 0.2;
}
onClipEvent (keyDown) {
// Allow the user to control the ball using keypad
if (Key.getCode() == Key.DOWN) {
yspeed++;
} else if (Key.getCode() == Key.UP) {
yspeed--;
} else if (Key.getCode() == Key.RIGHT) {
xspeed++;
} else if (Key.getCode() == Key.LEFT) {
xspeed--;
}
}
onClipEvent (mouseDown) {
// Is the user clicking on the ball? If so initiate a drag action.
if (this.hitTest(/:_xmouse, /:_ymouse, true)) {
dragged = true;
startDrag (this, false, left, top, right, bottom);
}
}
onClipEvent (mouseUp) {
// Let go of the ball
dragged = false;
stopDrag ();
}
onClipEvent (enterFrame) {
if (dragged) {
// Calculate the speed based on the position change per frame
xspeed = _x-lastx;
yspeed = _y-lasty;
lastx = _x;
lasty = _y;
} else {
// Reposition the ball based on speed, friction, and gravity
_x += Number(xspeed);
if (_x<left || _x>right) {
xspeed = -xspeed;
} else {
xspeed *= friction;
}
_y += Number(yspeed);
if (_y<top || _y>bottom) {
yspeed = -yspeed;
} else {
yspeed = (yspeed+gravity)*friction;
}
}
}
Last edited by simpelendidi; 07-11-2003 at 05:49 PM.
Originally posted by simpelendidi I've searched for an actionscript to do this, but I'm afraid it needs some modification to work in koolmoves. If anyone has some time left to try and make this work.
The basic idea is that you have a ball an a boundary box where the ball bounces in.
In order to throw the Ball... You would firts need to know in what direction the Ball was moving. You would do this by comparing _x values and _y values. This could be done with If statements.