Oh yes that looks like a very neat solution Dan!!

>From your code, it looks like your checkCollisions method is within the Ball
class - is that correct?

And hence would the addBounceObject method also be in the Ball class?

So the Game object would call the checkCollisions for each ball (there may
be more than one ball in this game)

i.e

for (var i:Number = arrBallObjects.length; i >=0; i--) {


        var vBall_Object = arrBallObjects[i];

        if (vBall_Object.return_If_Moving() == true) {

                                vBall_Object.checkCollisions ();

        }

}

Does this sound right?

How would you go about the above using the CollisionController.as you
previously suggested?

Thanks for your help on this one

Paul

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Holth,
Daniel C.
Sent: 13 December 2006 14:43
To: Flashcoders mailing list
Subject: RE: [Flashcoders] AS2 OOP Class Structure for simple pong type game


That would be one way.  Although it is rather limiting.  I'm assuming that
the ball will bounce whenever it hits an object.

Perhaps create an array of bounceObjects[];

function addBounceObject(obj:Object):Number{
        return bounceObjects.push(obj);
}

Then you could create your hit tracker.

function checkCollisions(){
        var len:Number = bounceObjects.length;
        // Loop through and check all objects hitting the ball
        for(var i:Number = 0; i < len; i++){
                // Check each object hit ball
                if(this.hitTest(bounceObjects[i])){

                        this.bounce(); // Bounce the ball
                        bounceObject[i].onHitByBall();
                }
        }
}

Have your onEnterFrame functions run checkCollisions every time.  That way
you check for hits against the paddle, bricks etc. 


The bounceObject[i].onHitByBall() would execute a function in that objects
code that would say what to do when it was hit by a ball.  In the instance
of a paddele do nothing, a brick - destory it! 


-Dan

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Paul
Steven
Sent: Wednesday, December 13, 2006 8:26 AM
To: 'Flashcoders mailing list'
Subject: RE: [Flashcoders] AS2 OOP Class Structure for simple pong type
game


Thanks for the reply Dan

Not quite sure how the Ball references the Paddle or alternatively the
CollisionController references the ball and paddle.

My Game class creates the Ball and Paddle as follows:

mcPaddle = new Paddle(mcReference, "paddle_mc", 50, 100, 289);

var vBall_Object = new Ball(mcReference, "ball_mc", 100, 160, 240);
arrBallObjects.push(vBall_Object);

If I wanted to give the Ball a reference to the paddle, would I do something
like this? (see last parameter)

var vBall_Object = new Ball(mcReference, "ball_mc", 100, 160, 240,
mcPaddle);

Thanks

Paul


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Holth,
Daniel C.
Sent: 13 December 2006 14:14
To: Flashcoders mailing list
Subject: RE: [Flashcoders] AS2 OOP Class Structure for simple pong type game


I would make the ball responsible for checking if it collides with the
paddle because the ball's behavior/state will change - not the paddle's, nor
does the state of the 'game' really change.

An alternative would be to create a CollissionControler.as that does all
your hit testing for you.  This may become useful when you add the bricks or
other objects that need to check for collisions.

-Dan

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Paul
Steven
Sent: Wednesday, December 13, 2006 8:02 AM
To: 'Flashcoders mailing list'
Subject: [Flashcoders] AS2 OOP Class Structure for simple pong type game


I am creating a simple pong / breakout / arkanoid game in AS2 and not sure
how best to deal with the classes.

So far I have a Game.as class, a Paddle.as class and a Ball.as class.

I need to detect when the ball (or balls) collide with the Paddle.

My question is, which class should check for this collision?

Should the Game class do this or should I pass a reference to the Paddle
into the Ball class so the Ball is able to check this collision itself?

If it is the Game class, then I guess it is a case of giving both the Paddle
and Ball classes a method to return their current position and then letting
the Game class compare these positions to determine if a collision has
occurred?

If the Ball class needs to have a reference to the Paddle passed to it, I am
not sure how this is done. So I would appreciate any advice on this.

I appreciate there are probably a lot of different solutions to this, but I
am trying to get off on the right footing with this OOP programming.

Many thanks

Paul

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

This e-mail and its attachments are intended only for the use of the
addressee(s) and may contain privileged, confidential or proprietary
information. If you are not the intended recipient, or the employee or agent
responsible for delivering the message to the intended recipient, you are
hereby notified that any dissemination, distribution, displaying, copying,
or use of this information is strictly prohibited. If you have received this
communication in error, please inform the sender immediately and delete and
destroy any record of this message. Thank you.
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

This e-mail and its attachments are intended only for the use of the
addressee(s) and may contain privileged, confidential or proprietary
information. If you are not the intended recipient, or the employee or agent
responsible for delivering the message to the intended recipient, you are
hereby notified that any dissemination, distribution, displaying, copying,
or use of this information is strictly prohibited. If you have received this
communication in error, please inform the sender immediately and delete and
destroy any record of this message. Thank you.
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to