0

I've written Pacman in AS2, now I want to port it to AS3 using classes....

I'm looking for ADVICE on my approach to tackling this so far (feels like I'm going wrong already)...

I've made a Console Class that holds program output and a container for a stage, which contains the Maze Class (with dots and scores), then there's a Pacman Class and a Monsters Class, and a Fruits Class too.

(image output for clarity)

public class Console Extends MovieClip
    // creates a stage and consoles for development (extending MovieClip) 
    // (see image link below).

    public var gameStage:MovieClip = new MovieClip();
    // to gameStage I've added the maze and all the dots (working fine).

public class Maze Extends Console
    var maze:maze1 = new maze1(); // simplified for here
    gameStage.addChild(maze);

public class Monsters Extends Maze
    // bla bla bla

public class Fruits Extends Monsters
    // bla bla bla

public class Pacman Extends Fruits
    var pac:MsPacman = new MsPacman(); //from library
    gameStage.addChild(pac);
    //now I just add this Pacman Class to the main timeline
    //...and the ALL the others are added through inheritance.

I'm trying to give every class access to public gameStage MovieClip in the Console Class, without creating multiple instances of the Console.

So...should I be nesting each Class in a 'stack' like this, with each one extending the former, with the last one being the Pacman Class, and then just add that to the main timeline? Or am I about to head down a dark alley? I've had a look at MVC Patterns, very confusing for me.

Am I inadvertently using some other design pattern without realising it? Is it safe to continue is this direction? I'm hoping to get this done properly so I can refer back to it as a template for future projects.

Many thanks for your time.

Digi

(image output (same as above)) - as you might be able to see, I use Console for many things, including a central stage, it helps me a lot in development and I just disable it at production time.

1 Answers1

0

Why would you extend Console all the time? Is console really a general class of your game objects? Is it like Animal -> Dog & Cat? I seriously doubt that, seems to me it is just a container for all or rather your Maze class (which has no class, as I see). I actually don't see too much of a use using inheritance in your case. Maybe I would do a Collectible class (and then subclass it for the fruits and dots).

If I were you I would create a "game" class that would contain all of this. It would have an enterframe event that would update the position of all the assets (monsters, pacman) and check for collisions. No other enterframe event in other classes. I would maybe create a Maze class if it was necessary and sublcass only Sprite for Pacman, collectibles, etc...

Fygo
  • 4,555
  • 6
  • 33
  • 47
  • Okay, I've changed my code and post quite a bit in the hope of explaining myself more clearly. Thanks for your response.:) – DigiWongaDude Jan 10 '14 at 21:06
  • ...also the idea of using one enterframe is fine (I did that in AS2), except all of them move differently, at different times too, which got a bit messy so I'm planning on giving each character a setInterval instead. – DigiWongaDude Jan 10 '14 at 21:45
  • Okay, I've considered what you've suggested and it DOES make good sense! I'll make a Game Class and add all the other Class references to it on the Main Timeline, using public variables in the Game Class... right? – DigiWongaDude Jan 11 '14 at 11:29
  • I've seen the light, thanks to your advice Fygo! Not using the main timeline either. It's looking so much simpler and logical using your suggestion (all coming out of/through the Game Class). – DigiWongaDude Jan 11 '14 at 12:04