First of all Hello to you all as I am new to the community.
I need some help with flash, bear in mind I am a flash noob.
Basically I am trying to create a greek building made of roof being on top of 4-5 columns standing on top of a fixed position floor, but when you remove one of the pillars the roof will collapse and blow up or something like that
I have found on the web a free script with drag and drop/collision/gravity and i have modified as much as I could and now Im stuck with the objects within the file being circles and the collision works for circles and I need it to be squares/rectangles so it can be replaced with a column later on. I already replaced the circle with a square but the collision still detects it as a circle.
I belive everything within the function collisionDetect() { } is responsible for the detection of the circle shape, have no idea how to modify it though
ActionScript Code:
balls = new Array();
for (var i = 0; i < 5; i++) {
myBall = attachMovie("ball", "ball" + i, i);
balls.push(myBall);
myBall.vx = 0;
myBall.vy = 0;
myBall._x = Math.random() * Stage.width;
myBall._y = Math.random() * Stage.height;
myBall.onEnterFrame = ballMove;
myBall.onPress = ballPress;
myBall.onRelease = myBall.onReleaseOutside = function () {
stopDrag();
this.onEnterFrame = ballMove;
};
}
ballRadius = ball0._width / 2;
leftWall = 0 + ballRadius;
rightWall = Stage.width - ballRadius;
topWall = 0 + ballRadius;
bottomWall = Stage.height - ballRadius;
ballLength = balls.length;
onEnterFrame = function () {
collisionDetect();
getEnvironment();
};
function getEnvironment() {
yGravity = 1;
friction = 1;
frictionShow = Math.abs(Math.round(friction * 100) - 100) + " Friction";
bounce = 0;
bounceShow = Math.abs(Math.round(bounce * 100) - 100) + " Bounce";
}
function ballMove() {
this.vy += yGravity;
this.vx += xGravity;
this.vy *= friction;
this.vx *= friction;
this._x += this.vx;
this._y += this.vy;
if (this._x < leftWall) {
this._x = leftWall;
this.vx *= -bounce;
this.vy *= bounce;
}
if (this._x > rightWall) {
this._x = rightWall;
this.vx *= -bounce;
this.vy *= bounce;
}
if (this._y > bottomWall) {
this._y = bottomWall;
this.vy *= -bounce;
this.vx *= bounce;
}
if (this._y < topWall) {
this._y = topWall;
this.vy *= -bounce;
this.vx *= bounce;
}
}
function ballPress() {
delete this.onEnterFrame;
this.onEnterFrame = function() {
startDrag(this);
this.vx = this._x - this.oldx;
this.vy = this._y - this.oldy;
this.oldx = this._x;
this.oldy = this._y;
};
}
function collisionDetect() {
for (var i = 0; i < ballLength - 1; i++) {
tempBall1 = balls[i];
for (var j = i + 1; j < ballLength; j++) {
tempBall2 = balls[j];
var dx = tempBall1._x - tempBall2._x;
var dy = tempBall1._y - tempBall2._y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < ballRadius * 2) {
var angle = Math.atan2(dy, dx);
var cos = Math.cos(angle);
var sin = Math.sin(angle);
tempBall1._x = tempBall2._x + cos * (ballRadius * 2);
tempBall1._y = tempBall2._y + sin * (ballRadius * 2);
tempBall2._x = tempBall1._x - cos * (ballRadius * 2);
tempBall2._y = tempBall1._y - sin * (ballRadius * 2);
var vx2 = cos * tempBall1.vx + sin * tempBall1.vy;
var vy1 = cos * tempBall1.vy - sin * tempBall1.vx;
var vx1 = cos * tempBall2.vx + sin * tempBall2.vy;
var vy2 = cos * tempBall2.vy - sin * tempBall2.vx;
tempBall1.vx = cos * vx1 - sin * vy1;
tempBall1.vy = cos * vy1 + sin * vx1;
tempBall2.vx = cos * vx2 - sin * vy2;
tempBall2.vy = cos * vy2 + sin * vx2;
}
}
}
}
Ive pasted the code and attached the file for your needs.
Any help would be greatly appreciated.