PDA

View Full Version : Organising a Large Game Project



Dan0
April 11th, 2009, 07:19 PM
Hey,
I really want to start work on a game idea I have using PaperVision.

The largest/most complex thing in Flash I have ever made is probably my last project which is an interactive school map for my A Level http://dan0.net/temp/dt/intermap.htm . Check it out, its a little laggy in the browser but it is designed to run in the flash projector from the desktop.

I used around 10 .as files and dumped all my graphics in 1 .fla as sprites and stuff.
This is ok (...ish) as I had a large 'main' file and a massive 'main3d' file which (324 lines which is big for me :S lol).

Im planning on making it a big, 3D adventure style game with lots of elements and AI things. But how do I organise my code? If I continue like this, I'm going to have a few mahasssive files and lots of small ones.

How to the 'pros' organise their stuff? All the time I see source codes for small experiments which are great, but I have never seen any layout overviews of what files they used and what kinds of things they put in them. I also have no idea how complex environments, where objects need to update to add/remove elements without having to check the position of the player every frame. I feel a little out of my depth because I have no experience in doing larger projects, even though I would say I'm quite-very competent at flash.

Thanks for reading all this and giving my (and others in a similar position) any advice!
Dan

:)

P.S. later this year I'm going to start doing a blog with some tutorials on my various asspects of my Interactive Map.. think its worth it?

waseem
April 11th, 2009, 08:03 PM
I've never created anything that large so I'm totally guessing here. I think you would have one main swf with several other swfs that contain the various game elements loaded into it. I think you would also have to utilize AS classes and object oriented programing.

Dan0
April 11th, 2009, 08:24 PM
Oh yeh sorry, I am talking about doing everything in ActionScript 3 with classes and OOP involved.

But do the professionals have, for example, one main class importing lots of other classes, or referencing new classes etc? Flex.. or the Flash IDE (that I am using now)? How do people handle vectors and images when using Flex? I just don't have a feeling for where to start... Any links of advice would be great.
Thanks,
Dan

justkevin
April 12th, 2009, 01:06 AM
I'm not a professional, but I am working on a fairly complicated game. While there are some parts of the structure I'm not 100% happy with, overall the architecture is working for this project.

I have a single "Application" mxml class which is what loads first. The application holds references to objects exist outside the game, such as preferences, game loader, etc.

When a new game is started, a GameWindow mxml class is added. This lays out the game interface and creates an instance of the "Game" class. The game is initialized from XML, which can either be the new game defaults, or a saved game.

Some of the major classes:

Game: Loads maps, handles the main game loop, among other things

Map: A collection of MapNodes that represents the physical game world. The nodes allow for broad-phase collision detection and local area updates-- only the entities within X nodes of the player are updated, allowing for very large maps without slow down (the game is set in space, so the maps are effectively infinite in size, but practically the action is restricted to a finite, but still very large area).

Entity: Any game "thing"-- the player, enemies, planets, treasure, wormhole etc. Various subclasses provide specialized functionality.

Component: Complex entities like NPCs and the player have a collection of components that define their functionality. E.g., an engine component, weapon components, etc.

AI: NPCs have an AIState and AIThinker property. The AIState holds various AI related properties, the AIThinker decides what the NPCs state is, e.g., INTERCEPT, ATTACK, VEER, RETURN HOME, etc.

Factories: Create entities from defaults defined in XML. (I tried to define almost everything that's a variable in XML, which is very convenient for testing. I put all the XML in a database which is served up at runtime. So, for example, I can test a change in an enemy's armaments without rebuilding the swf)

Triggers/Actions: Trigger/Action pairs are how I'm handling help/missions/achievements. A trigger is designed to detect a special game state (e.g., "Player has item X" or "There are 0 enemies near orbit 3 on map 8") and fire one or more actions (e.g. "Open a help window" or "Add a new trigger").

Several things I would do differently if I were rewriting the same project from scratch:
All of my custom MXML components are in one folder. I initially expected to only have a couple, but ended up with several dozen. I'd organize them better.
Entities have too many subclasses. Some of these would have been handled better using composition.
I tried to make the components for NPCs and the player use the same classes. They ended up being more different than alike.

I'm interested to hear how other people structure their large game projects.

.ral:cr
April 12th, 2009, 01:35 AM
P.S. later this year I'm going to start doing a blog with some tutorials on my various asspects of my Interactive Map.. think its worth it?
i don't know if worths, but what i know is that your map is moving very slowly on my macbook, almost not usable and don't seems to me to be so complex.
for your game, maybe will be useful this package: http://lab.polygonal.de/ds/

Dan0
April 12th, 2009, 11:39 AM
Well that's great, thanks justkevin! I look forward to having a play on your game now haha.

In response to .ral:cr, for me creating that map took a lot of work because of small details in PV3D like including boarders on the material texture etc. Yeah it works crap if you have a PPC mac but I get 20fps on my Intel Mac in firefox.. oh yeah also Safari sucks at rendering flash if your using it.. Thanks for the link though it looks really informative oowww source code ^,^ lol