Skip to main content
February 15, 2011
Answered

collisiondetection

  • February 15, 2011
  • 3 replies
  • 1322 views

having problems...

if one can't communicate between mc's external classes how can you create stuff?

I have  a timer inside each instance form a bomber_mc via a external class:

this timer places  bom_mc's on the stage from the location of bomber_mc (there are several). But I want to do a do a collisiondetection test with each bom and yet another kanon_mc....

can you give me a hint in the right direction?

This topic has been closed for replies.
Correct answer moccamaximum

this could to the trick to pass functions between classes. but can I make several statements like this in the document class?

in shooter.as (main doc class):

package {

         import flash.display.MovieClip;

          ...etc.

         public class shooter extends MovieClip {

              ... etc.

          }

         public class test_super extends bomber_class {

               super.super_test();

          }

}

and in the bomber_class:

package {

         import flash.display.MovieClip;

          ...etc.

         public class bomber extends MovieClip {

              public function super_test():void {

               }

          }


You have to be careful which ghosts you want to evoke, how deep in the rabbit-hole you really want to go ;-)

By calling super in every class you create you kind of sabotage the whole encapsulating principle that lies at the center of OOP, also: not every Problem in Programming can be satisfiable solved with inheritance, often an Interface is way better to handle and does the job better.

You have, in my opinion two options here:

1.creating a game that works in a reasonable time or

2.to learn OOP and use the game more as a kind of experimental field. If you want to do the latter a good start and maybe the only Design Pattern every programmer should heard  of is the MVC (Model-View-Controller) Concept. (google it)

If you want to do the first (creating the game is your first priority) you might want to abandon all your classes and subclasses and just put everything in one main.as, from what I see the complexity of your game will not need more (no offence intended here), and have a look at the Tweening concept, I guess you use a lot of Enterframe events to drive your objects( like bomber.x +=5, canonshot.y -=3 and so forth).

Flash has its own Tween classes, but there are some open source implementations that are even better, faster and easier to understand (http://www.greensock.com/), you won`t need any timers any more that have to communicate with your objects, because tweens have their timers built in, that are much more flexible than the one Flash offers off-shelf.

Anyway: at this point you will have to make a decision, since I don`t think you can have both.

Good luck!

3 replies

February 16, 2011

yes, but how do I attach a timer to each bomber? It's those timers that will initiate dropping the bomb.

I already have a timer that puts bombers on the stage. each bomber should drop bombs (at an interval).

I miss those days when had multimedia-authoring-tools like mTropolis where objects could send/broadcast messages to start events.

Inspiring
February 16, 2011

I`m trying to figure out what you want to achieve: You have some classes like a Bomber.as, Canon.as and inside the classes Timers that trigger an automatic firing/bombing, and the user can maybe steer the airplane with the keyboard and gets points for destroying the canons, and must try to avoid being shot?

February 16, 2011

see some rough swifs :

with bom and timer inside bomber

http://www.7tim.be/flash/shooter_tib.swf

with one timer, and just putting bomb on stage from the main doc. class

http://www.7tim.be/flash/shooter_tob.swf

the bombers at the top are placed on the stage with a timer and put into an array

the bullets from the kanon are also put on the stage (by pressing spacebar) and put in an array

each movieclip has its own class-file. There I do the movements.

kanon at  bottom is controled by arrow keys, and shooting with spacebar.

you want to see some code?

kglad
Community Expert
Community Expert
February 15, 2011

use a controller class to instantiate your bombers and store their references in an array.  you can loop through your array performing hittests.

February 15, 2011

One approach is to make an array of all the items you want to doe a colision test on and at the appropate moment loop thorugh the array testing all items against your target clip.  Then throw an appropiate event with actions accordingly.

Hope that helps...