[CS3] Drag to fire Balls.
Basically Im trying to recreate this game called shuffle found on the shockwave site. http://www.shockwave.com/gamelanding/shuffle.jsp
Ive taken a fantastic bit of code from http://www.krazydad.com/bestiary/ called "Superball" which gives a basic ball environment simular to the one in the game. I have edited it a little but am struggling to convert it now.
At the moment you "toss" the balls around the screen but I need to edit this into a drag back and release to select the power and direction, like the above game.
Code:
MovieClip.prototype.pressBall = function()
{
this.isDragging = true;
this.vx = this.vy = 0;
this.lmx = _root._xmouse;
this.lmy = _root._ymouse;
this.startDrag(false);
}
MovieClip.prototype.releaseBall = function()
{
this.isDragging = false;
this.stopDrag();
}
MovieClip.prototype.moveBall = function()
{
// compute forces on ball
if (!this.isDragging) {
this.vx *= dampK; // damping due to air resistance
this.vy *= dampK;
this.vy += gravK; // gravity
// bounce off floor and ceiling
if (this._y+ballRadius + this.vy >= SH ||
(this._y-ballRadius) + this.vy < 0)
{
this.vy *= -dampCollision;
}
// bounce off right and left walls
if ((this._x-ballRadius) + this.vx <= 0 ||
this._x+ballRadius + this.vx >= SW)
{
this.vx *= -dampCollision;
}
this._x += this.vx;
this._y += this.vy;
}
else {
// Set vx,vy to correspond to mouse movement, enabling user to 'toss' ball
this.vx *= dampK;
this.vy *= dampK;
this.vx = _root._xmouse - this.lmx;
this.vy = _root._ymouse - this.lmy;
this.lmx = _root._xmouse;
this.lmy = _root._ymouse;
}
}
I think this is the relevent peice of code. Any ideas from anyone?