PDA

View Full Version : Need help with coding concept for game


chancebanning
06-17-2008, 03:20 AM
Hey,

I'm hoping you guys could help me out with a concept for a certain aspect of a game I'd like to make. I don't want anyone to lay the code out for me, just an idea of what I should be reading into.

The game will be a platformer, but set at somewhat of an isometric view so the player can move up and down to some extent. There will be a number of rooms (movieclips) that the player can move throughout, and I plan on having them all on the stage at the same time but with their visibility toggled depending on what room the player is currently in. Either that or each room will be on a separate keyframe within the main timeline.

Here is what I'd like help with though...
For example, one room will have a number of rocks on the ground. I want the player to be able to pick up a rock and carry it around, and be able to drop it in any of the other rooms where it will remain unless moved again.

The challenge is that I want to be able to add any number of rocks/objects to any of the rooms, and not have to add a big chunk of code each time I do so.. ideally I'd like to just drag a "rock" movieclip onto the stage, add maybe one simple line of code somewhere that declares it's presence, and have the game know where to take it from there.

I'm not too sure what to be reading into here though, as this is new territory for me. I've heard of assigning objects to classes, adding them to arrays,.. I'm starting to get lost. If anyone can just point me in the right direction here, maybe go over an example or two, I'd really appreciate it.

Thanks!

sconer
06-17-2008, 03:45 AM
It all depends on how much time and effort you are willing to put into this game. If you really want to make it professional and glitch free, then look into tile games. Otherwise, arrays will suit most of your needs. Basically, an array will hold an object whose properties are identified by a number (index). For example:

var myArray:Array = ['Hello', 123, some_mc];
trace(myArray);
trace(myArray[1]);

trace(myArray) will return the entire list of objects: Hello, 123, _level10.some_mc.
trace(myArray[1]) will return the object in index 1: 123. You might say, why would it return 123 if index 1 is clearly 'Hello,' this because the first element in an array starts at 0.

chancebanning
06-17-2008, 04:30 AM
Thanks for the reply,

When you say tile-based, do you mean the character is restricted to a grid, and can only move in increments of so many points? If so, I'm definitely going for a very natural feel with this game. The player will be able to walk in all directions, including diagonally. Movement will be restricted by obstacles and walls, which will be defined using a shapeFlag hit test.

Arrays are actually one thing I have looked into. I'm current planning on using them to control groups of objects based on which "room" they are in. Here's an idea of how I'm doing that..

Each bunch of objects for a room starts out on a separate layer, but all on the same keyframe on the same level. Each object - likely using code placed directly on the object movieclips - has it's instance name loaded into an array for it's room, such as room1Array, room2Array, etc..

Say I want to toggle the visibility for all objects in a room. I do this by running a FOR loop, which loops once for each object in the array. Each time it loops, it specifies the next movieclip name in the array, and sets that movieclip's visibility to true or false, whichever. I also plan on using this method to move a roomful of objects, and whatever else. Not sure if this is the best way of doing things, but only way I can think of for the way I have to set things up.

What I'm trying to figure out now is how to set things up so I can apply a bunch of properties to a number of movieclips, and have my player be able to interact with them all in the same fashion. I'm trying to think of how this would be done with arrays, but I have a lot on my mind right now so it isn't coming easily.