This project is read-only.

Adding New Cells

Aug 19, 2011 at 8:14 PM

I'm trying to a new cell to my TD game, but I'm not sure where to add the code.  This cell is similar to the obstruction, but Creeps are allowed to pass through it. (The user is unable to place towers on top of the cell).

First, I added the new cell name to the 'Coding4Fun.ScriptTD.Common\SpecialCellType.cs'.  Then in the 'Coding4Fun.ScriptTD.Engine(Windows Phone)\Logic\Cell.cs' I added the code below.  When I tried to deploy the game,  'Coding4Fun.ScriptTD.Common\Grid.cs' threw an argument exception.  It highlighted the code: SpecialCells.Add(cell.Id, cell);

        public bool IsLandCreepPath
            get { return CellType == SpecialCellType.CreepPath || Tower != null; }

Aug 20, 2011 at 11:56 AM

I made some changes in the latest revision that will help with this, but in the XML spec, the Buildable attribute indicates if a tower can be built on it. So you can mark a cell as None, and then make Buildable="false".

All of the changes are in revision 69610:

So if you want to apply those changes to your source, check the diffs for each file to see what has changed. Basically I removed the exception when building if you had a special cell without a name, and then I added a check inside Grid.cs, in the ApplyMap method to apply the Buildable and CellType attribute to the normal cell if it has no name, or treat it as a special cell if it does.

Now you can specify an obstruction where a creep can pass through using:

<Cell Type="None" Buildable="False" X="whatever" Y="whatever" />
I hope this helps. :)