nappyhead
02-28-2005, 07:36 PM
I've been trying to develop a shuffleboard game and I'm at the point where I'm trying to figure out how to get the pucks to collide and bounce off of each other.
This is the code I have placed into each Movie Clip (puck):
Set Variables on Frame 1:
this._x=35;
this._y=210;
rightedge=524;
leftedge=26;
topedge=190;
bottomedge=291;
drag=.98;
bounce=.9;
Frame 2:
// Check if you're NOT draggin
if(!dragging){
// Initialize Movement
_x = _x+xspeed;
// Collide with Right Edge and Go Back
if (_x+_width/2>rightedge) {
_x = rightedge-_width/2;
xspeed = -xspeed*bounce;
}
// Collide with Left Edge and Go Back
if (_x-_width/2<leftedge) {
_x = leftedge+_width/2;
xspeed = -xspeed*bounce;
}
// Collide with Bottom Edge and Go Back
_y = _y+yspeed;
if (_y+_height/2>bottomedge) {
_y = bottomedge-_height/2;
yspeed = -yspeed*bounce;
}
// Collide with Top Edge and Go Back
if (_y-_height/2<topedge) {
_y = topedge+_height/2;
yspeed = -yspeed*bounce;
}
yspeed = yspeed*drag;
xspeed = xspeed*drag;
} else {
xspeed=_x-oldx;
yspeed=_y-oldy;
oldx=_x;
oldy=_y;
}
Frame 3:
gotoAndPlay(2);
As you can see, you have the ability to drag a puck and roll it across the table, but the two pucks are still unable to collide.
I realize there's a lot to making these pucks collide and I would greatly appreciate it if someone would be able to give me some kind of idea of how to make this happen.
This is the code I have placed into each Movie Clip (puck):
Set Variables on Frame 1:
this._x=35;
this._y=210;
rightedge=524;
leftedge=26;
topedge=190;
bottomedge=291;
drag=.98;
bounce=.9;
Frame 2:
// Check if you're NOT draggin
if(!dragging){
// Initialize Movement
_x = _x+xspeed;
// Collide with Right Edge and Go Back
if (_x+_width/2>rightedge) {
_x = rightedge-_width/2;
xspeed = -xspeed*bounce;
}
// Collide with Left Edge and Go Back
if (_x-_width/2<leftedge) {
_x = leftedge+_width/2;
xspeed = -xspeed*bounce;
}
// Collide with Bottom Edge and Go Back
_y = _y+yspeed;
if (_y+_height/2>bottomedge) {
_y = bottomedge-_height/2;
yspeed = -yspeed*bounce;
}
// Collide with Top Edge and Go Back
if (_y-_height/2<topedge) {
_y = topedge+_height/2;
yspeed = -yspeed*bounce;
}
yspeed = yspeed*drag;
xspeed = xspeed*drag;
} else {
xspeed=_x-oldx;
yspeed=_y-oldy;
oldx=_x;
oldy=_y;
}
Frame 3:
gotoAndPlay(2);
As you can see, you have the ability to drag a puck and roll it across the table, but the two pucks are still unable to collide.
I realize there's a lot to making these pucks collide and I would greatly appreciate it if someone would be able to give me some kind of idea of how to make this happen.