Dan, I was thinking using the tile solution would reduce the amount of
checks as instead of looping through all the brick objects and checking for
a collision using hitTest, I would simply call a function passing in the
balls current position and if this was a tile (brick) that hadn't been
destroyed, it would destroy the brick

So the bricks would be represented by a multidimensional array like so

0,0,0,0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0,0,0,0
1,1,1,1,1,1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1,1,1,1,1,1,1
0,0,0,0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0,0,0,0

And the method would use the balls x and y position to calculate the tile
row and column

var numTileColumn:Number = passedX / numTileWidth;
var numTileRow:Number = passedY / numTileHeight;

if (map[numTileColumn][numTileRow] == 1) {

        // Destroy Brick

}

Hopefully this makes sense. I have just written this code off the top of my
head so haven't implemented it in the game yet






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


>From a computational standpoint, you end up running the same amount of
processses.  Are you either haveing the ball constantly checking "Where am
I? Am I over a brick?"  or you have the ball checking "Am i hitting
something?" every onEnterFrame.

Pete's suggested having checks when it reaches a vertical threshold, but
again, you just change the the ball from asking "Am I hitting something?" to
"am I over the threshold?"  every onEnterFrame, and then add additional
computation to figure out what its hitting.

I like Mike's solution of breaking out of the loop after a collision is
detected becuase then you don't perform unnessary computations (assuming the
ball can only be hitting one thing at a time).

-Dan

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


Rather than testing every brick for a collision all the time, I was thinking
of using a tile based approach to display the bricks. Therefore rather than
each brick checking for a collision with the ball, it is a case of checking
what tile (brick) the ball currently occupies if any and if that brick has
not yet been destroyed then destroy it...

Hence a multidimensional array would be used to represent the bricks on the
screen.

Haven't implemented this yet but it sounds ok in my head:)


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Pete Miller
Sent: 13 December 2006 16:17
To: Flashcoders mailing list
Subject: RE: [Flashcoders] AS2 OOP Class Structure for simple pong type game

I don't program games (so add that factor as a consideration), it was
just my first thought that if I were doing this, I wouldn't want to test
every object for a collision all the time.  If there is a latency issue
such as you describe, a homebrewed Event class might eliminate it.

P.

>> -----Original Message-----
>> From: [EMAIL PROTECTED] [mailto:flashcoders-
>> [EMAIL PROTECTED] On Behalf Of slangeberg
>> Sent: Wednesday, December 13, 2006 11:13 AM
>> To: Flashcoders mailing list
>> Subject: Re: [Flashcoders] AS2 OOP Class Structure for simple pong
type
>> game
>>

>> Have you actually implemented an event system like this in games? It
>> seems
>> like a good idea, but for some reason I always thought this approach
>> would
>> introduce unnecessary latency, but now I'm not sure why!
>>

>> -Scott
>>

>> On 12/13/06, Pete Miller <[EMAIL PROTECTED]> wrote:
>> >
>> > Another possible strategy is for the ball to fire off an event
every
>> > time it crosses certain vertical location thresholds.  The target
>> > objects could then listen for the event which matches their
vertical
>> > location to test for a collision.
>> >
>> > For example, when the ball descends to the row containing the
paddle,
>> it
>> > fires that event, and the paddle, receiving it, tests for
collision.
>> > When the ball ascends to the first row of bricks, those bricks each
>> test
>> > for collsion.  This might be a performance improvement over testing
>> > every object in the system all the time.
>> >
>> > P.
>> >
>> > >> -----Original Message-----
>> > >> From: [EMAIL PROTECTED]
[mailto:flashcoders-
>> > >> [EMAIL PROTECTED] On Behalf Of Holth, Daniel C.
>> > >> Sent: Wednesday, December 13, 2006 9:43 AM
>> > >> 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
>> >
>>

>>

>>

>> --
>>

>> : : ) Scott
>> _______________________________________________
>> 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

_______________________________________________
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