On Jun 23, 2004, at 1:55 PM, Frank C wrote:
On 23-Jun-04, at 2:19 PM, Paul Kaiser wrote:
I have various objects that are subclasses of Object3D. For example:
Shot
Skeleton
TrashCan
I'd like for every one of these objects to have a unique identifier
(integer) within the game.
My thought was to have an array "objArray as Object3D" and that I can
members of this array can reference the various instances of Object3D
subclasses.
i.e. objArray indices:
0 - 8 reference player shots (a maximum of 9 available at any given
time)
9 - 59 reference skeletons (50 max)
60 - 70 reference trashcans (10 max)
This would probably be much easier to manage as 3 separate arrays -
especially if you decide to change some of your max values later on.
Personally I would never put such low limits on these types of things
until the gameplay has been thoroughly tested and tweaked. Even then,
settings like these are often more useful if they are made variable at
runtime, so you don't get stuck in a change-compile-test-quit-repeat
cycle.
The array is built during my GameInit phase, which is dependent upon
several variables having to do with difficulty level and settings i the
level data. While building the array, I keep track of the lowest index
for an object type and the highest index.
Can I declare the array to be of type "Object3D" and have it
reference various subclasses of Object3D?
Technically that will work, but you may find yourself doing a lot of
type casting to get at your subclass data, and that can be expensive
if it happens for a lot of objects every frame.
Hmm... okay, this could be an issue.
You might want to consider building a common interface for all the
world object classes to avoid typcasting, and/or creating an Object3D
subclass that is the super of all your other classes, or a totally new
base class that contains an Object3D as a property.
Ah, I see what you're saying. I appreciate the pointer -- I haven't had
to work with classes in this way much, or have probably used subclasses
inefficiently in the past.
FYI, the reason I'm taking this approach is that I have a "mapArray"
which is a 2D representation of the location of various game objects.
Instead of using collision detection per se, my objects know where they
are at and are about to go in the mapArray. (especially important for
knowing when they have hit a wall.)
When an object moves to a spot, it can check and see what the integer
value is at that spot in mapArray -- 0 is impassable, 1 is passable, 2
represents the player. All other indices 3 thru top end of the array
would refer to other game objects.
If objects 3 thru 9 happen to be shots from the player's gun, the
object that hit there can run it's "TakeDamage" method, etc.
So forth and so on for other object types.
The ideas was that when an object moves to a new location, it
immediately has a reference to whatever else might be at that location
on the map, and can act accordingly. Just by knowing the number is
between 3 thru 9, we automagically know it is a player shot and that we
do certain things.
Hope this makes sense.
Off to think about it some more.
Paul
Frank.
_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
|