Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 03-18-2009, 09:41 PM   #1
aaron_da_killa
Registered User
 
Join Date: Feb 2009
Location: Sydney, Australia
Posts: 33
Send a message via MSN to aaron_da_killa
Unhappy [AS3] Platform Game Advice

Hey.

I'm trying to make a platform game but I need some advice about how it should be structured.

For example, should the document class of the game be the youngest child so to speak and or should all the other classes be children of the document class?

At the moment, I have three classes, a Document Class, a Player Class which handles things like player movement, jumping, scrolling and a platform class which at the moment handles collison detection and collison reaction (making the player stand ontop of the platform, making the player stop when hitting the side of the platform).

It seems that no matter what way I arrange the classes, I get problems.

Could somebody give me a general overview of how a non tile based platform game should be arranged.

If anybody has any more questions about the way I've structured my game, please let me know.

Thanks in advanced
aaron_da_killa is offline   Reply With Quote
Old 03-19-2009, 09:35 AM   #2
bluemagica
Senior Member
 
Join Date: Feb 2008
Posts: 387
Default

the document class is in reality neither an exact parent or a child, but by its use, it can act as both! A parent child relationship occurs when one class "inherits" properties from another class, but it is hardly ever needed to inherit from the document class!

Anyway, the structure of the game can be made in any way, where your goal is to keep the classes independent of each other as much as possible! So you can do something like,

Document class - handles preloader, menu, and every element that is outside the core gameplay!

Game class - this class will handle the actual gameplay, for example, "player" and "bullet" are two separate classes inside game class, so its the job of game class to check for collision between them. Game class can look inside itself, but a class, like player class here, shouldn't look outside itself!

--Sub classes-
player - player movements, key press, AI . (I generally use player for both player and NPC)
object - defines properties of objects like solid platform, spring, traps,....
weapons - self explanatory
enemy - ""

interactions between the objects of subclass should be handled by their parent, the game class!
bluemagica is offline   Reply With Quote
Old 03-19-2009, 10:31 AM   #3
aaron_da_killa
Registered User
 
Join Date: Feb 2009
Location: Sydney, Australia
Posts: 33
Send a message via MSN to aaron_da_killa
Default

Yay, a reply, thanks Bluemagica.

That's an interesting approach that I haven't considerd before with this Game Class idea. I would have to make all movieclips on the stage accesible from Game Class, how would I do this? Maybe add them to the stage from Game Class?
aaron_da_killa is offline   Reply With Quote
Old 03-19-2009, 11:05 AM   #4
bluemagica
Senior Member
 
Join Date: Feb 2008
Posts: 387
Default

yep exactly, you add all the things in the actual gameplay, from within the game class, and you initiate the game class from the document class! there can be another class (which isn't exactly a OOP way), a global class, which makes communicating between classes easier...like telling the "score" from the game class to document or scene_manager class so that it can be shown at the end of game, or player preferences, etc!
bluemagica is offline   Reply With Quote
Old 03-19-2009, 10:41 PM   #5
aaron_da_killa
Registered User
 
Join Date: Feb 2009
Location: Sydney, Australia
Posts: 33
Send a message via MSN to aaron_da_killa
Default

Alrghty, thanks again buddy.

So, if this GameEngine class isn't linked to the DocumentClass which is as the name suggests the document class of this game, then how would I do I call movieclip instances on the stage via their instance name in GameEngine or its children?

I uploaded an image of my current class structure.

Edit:

Alrighty, here is one for ya. I have a movieclip with the instance name player on the stage. That movieclip is linked to the PlayerCode class by using the following linkage properties:

Class: PlayerCode
BaseClass: flash.display.MovieClip

I can use the keyword "player" to refer to that movieclip instance in the Class PlayerCode but I can't use it elsewhere, not even in DocumentClass which is the projects document class! Not even in DocumentClass! Why is that?Alrghty, thanks again buddy.

So, if this GameEngine class isn't linked to the DocumentClass which is as the name suggests the document class of this game, then how would I do I call movieclip instances on the stage via their instance name in GameEngine or its children?

I uploaded an image of my current class structure.
aaron_da_killa is offline   Reply With Quote
Old 03-20-2009, 03:54 AM   #6
bluemagica
Senior Member
 
Join Date: Feb 2008
Posts: 387
Default

lol, i don't think you have completely understood yet! In the structure, everything dosent have a need to have a parent or "extend" a class, an "include" will be better!
Take my advice, and use StarUML (freeware), its a great software to plan your class structure, and with an extra plugin, it can generate as3 code for your class structure....


back to your question, class name and instance name are not the same and every object instance, exits within its parent scope, so if you create a player from gameEngine, DocumentClass on the outside, and bulletClass on the inside can't see it directly...they will both need to use a reference!for documentClass, say you did something like

var game:gameEngine = new gameEngine("level1","player1",5); //lvl,name,lives
game.init();

and in gameEngine you did something like

public var player:Player = new Player();
player.x = player.y = stage.stageWidth/2;

From documentClass you can access player by:- game.player
similarly, for bullet:- MovieClip(parent).player


theres another tiny trick:
var player:Player = new Player();
player.name = P1;

then you can use
var player = game.getChildByName(P1);
bluemagica is offline   Reply With Quote
Old 03-20-2009, 10:57 PM   #7
aaron_da_killa
Registered User
 
Join Date: Feb 2009
Location: Sydney, Australia
Posts: 33
Send a message via MSN to aaron_da_killa
Default

Thanks again Bluemagica.

Just two questions and then I'm going to see if I can fix this problem.

Quote:
Originally Posted by bluemagica View Post
everything dosent have a need to have a parent or "extend" a class, an "include" will be better!
Right, so just like I say "import flash.display.object", I can say "import DocumentClass" and that means that in whatever class I import that to, I can access all of DocumentClass' functions/methods, variables and movieclips that belong too it say?

Question 2, I'm a little bit confused about what you mean classes on the inside and classes on the outside, could you explain that a bit for me when/if you have a free moment.
aaron_da_killa is offline   Reply With Quote
Old 03-21-2009, 04:30 AM   #8
bluemagica
Senior Member
 
Join Date: Feb 2008
Posts: 387
Default

1) with include, you can access only "public" stuff, say class A looks like:
Code:
package script
{
  import flash.display.*;
  class A extends Sprite //A is inheriting from sprite class
  {
   
    public var age:Number = 9; //public variable

    public function A() //public function + constructor
   { 
      show_name();
    }
    private function show_name() //private function
    {
       trace("PLAYER1");
    }
  }
}
So in call B you can do:
Code:
package script //simply means the as file is in "script" folder
{
  import script.A;

  public class B
  {
      public function B()
      {
        trace(A.age); //9
        A.age = 10;  // modifying the public variable temporarily
        trace(A.age); //10
        A.show_name() //error, can't access private
        var abc = new A(); //show_name() called
      }
  }
}
This code is just to show you the use of public and private, but there an be few errors since i wrote this without testing!



2) inside and outside simply means their visibility, you are creating the player class, within the gameEngine class, so its inside the gameEngine, means for any instance of player, gameEngine will be its parent! Similarly, documentClass lies outside gameEngine!
bluemagica is offline   Reply With Quote
Old 03-21-2009, 01:30 PM   #9
aaron_da_killa
Registered User
 
Join Date: Feb 2009
Location: Sydney, Australia
Posts: 33
Send a message via MSN to aaron_da_killa
Unhappy

Argh!

Alrighty, about your answer to question one.

I am trying to access a variable exactly as you accessed the variable age from class A except I get this error:

1119: Access of possibly undefined property gravity through a reference with static type Class.

Now, what I am doing is exactly what you have done in that example except for three things:

1) My fla and *.as files are placed in the same location so my package doesn't have a name. Meaning the equivalent of my import statement on your example looks like this: import A; (I doubt its this because I get no errors saying could not find specified class)

2) Class B in the example doesn't extend anything, however the equivalent of Class B in my set up extends movieclip

3) Class B belongs to a movieclip in the library with an instance placed on the stage, hence the need for #2.

So which one of these things is causing that error? Other than those 3 things, both your example and my setup are the exact same!
aaron_da_killa is offline   Reply With Quote
Old 03-21-2009, 04:21 PM   #10
bluemagica
Senior Member
 
Join Date: Feb 2008
Posts: 387
Default

try
var a = new A();
trace(a.gravity);
bluemagica is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[AS2] Platform game problem renegadegd Gaming and Game Development 2 12-20-2008 11:59 PM
Flash AS2 Platform game help sakit Gaming and Game Development 0 04-14-2008 03:45 PM
Platform game - not working as intended! bloodstyle Gaming and Game Development 0 03-21-2008 07:09 PM
Platform jumper - type game the_r Gaming and Game Development 5 10-08-2007 04:59 PM
help with my platform game killkenny64 Gaming and Game Development 1 10-13-2006 10:35 AM


All times are GMT. The time now is 01:26 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.