level editor design issues - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Design (/forum-5.html)
+--- Thread: level editor design issues (/thread-5739.html)
level editor design issues - GryphonClaw - Mar 22, 2005 11:23 AM
as some of you might be aware (irc://irc.freenode.net/#iDevGames people)
I'm working on a game called CocoaRunner (name change is in order i know)
which is a "clone" of the ever popular Lode Runner game.
Right now, I have a design issue
First I have a Tile class, which is the super class of all my tiles in the game, the levelClass has an array of tiles which tells each tile to draw
what my problem is, is this:
when i have a selected tile, i have a pointer to a generic tile
I can't just set the tile clicked at clickpoint.x and clickpoint.y to be equal to the selected tile, i have to create a new instance, otherwise when i change the selected tile, all the tiles in the edited level get changed to because those are just pointers to the same tile instance, my main problem is i don't know how to figure out what class to make the new tile instances.
I'm using Objective-C classes, OpenGL and the Cocoa Event system, it's all working great so far, but this problem has got me stumped
any and all help is appreciated
Please tell me if you need more info
level editor design issues - iefan - Mar 22, 2005 11:34 AM
Well, I'm not totally clear on what you are doing, but let's see if this helps you...
Alloc a blank, basic, or empty title to each location in your level.
When you change a title, release the blank title object and alloc a new one of the proper type to that location in the array. Make sure you changing the clickpoint coordinates to the proper location in your array.
To save some memory initially, you can have them all point to the same empty title, just retain it for each location and then release when you put a 'real' tile in it's place.
level editor design issues - GryphonClaw - Mar 22, 2005 11:44 AM
well, i figured i'd do that but the problem is, how do i figure out which tile to alloc? i could do a big giant switch statement to select the correct class, but I know there must be a better way...
level editor design issues - codemattic - Mar 22, 2005 02:23 PM
Im a fan of OOP - but in this instance you may want to consider creating a variable that encapsulates all the different tile types into one piece of data. You could use a C "union" variable to hold the specific tile data - and then allocate all your tiles once and be done with it.
level editor design issues - codemattic - Mar 22, 2005 02:34 PM
something like this (typed in Firefox - so may not compile as-is)
level editor design issues - GryphonClaw - Mar 22, 2005 03:07 PM
thanks for the help but... i don't think that is the solution for this problem..
i've already got all the tiles setup to be classes (sub class of tile, which provides all generic functions needed for a tile and the sub classes add specifics)
level editor design issues - flipflop - Mar 22, 2005 04:33 PM
Couldn't you do a simple 2 dimensional array of tile objects? For example, if you have a screen size that fits 128 x 128 tiles:
You can use the power of polymorphism to handle the drawing of the tile by overriding the appropriate methods. So when you want to draw you could do something like the following:
Since each subclass of Tile overrides the draw() method the proper image will be drawn.
If you are reading a file for your levels you will still need to define some kind of mapping between the file and the tile types. For example, "0" in the file may map to an EmptyTile object while a "2" may map to a LadderTile object. I'm not sure there is an easy way around this unless you serialize your objects into a file...
Not sure if that helps you or not.
level editor design issues - GryphonClaw - Mar 23, 2005 06:23 PM
Thanks for all the help
i got it to work
thanks to object introspection i can alloc the correct class by doing
Tile* newTile = [[[SelectedTile class] alloc] init];
and it creates the new class of the type that i want