Click here to Skip to main content
15,887,249 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear CodeProject,

I have been working on my game for the past couple of days, and for some odd reason the following code won't work:

C#
// -- Write the world bytes.
for (int i = ChunkSize; i > 0; i--)
{
    for (int j = ChunkSize; j > 0; j--)
    {
        // -- Block.
        char Block;
        if (ChunkY > 0 || (ChunkY == 0 && j > World.ChunkSize / 2))
        {
            Block = (char)BlockID.BLOCK_GRASS;
        }
        else
            Block = (char)BlockID.BLOCK_AIR;

        // -- Add Return.
        _ReturnString = _ReturnString + Block.ToString();
    }
}


Well, in fact, it works. But the only thing that doesn't work is this part:

C#
(ChunkY == 0 && j > World.ChunkSize / 2))



Also keep in mind that I am writing the world from the end to the beginning, the reason why is because I read it out afterwards and it's backwards if I don't also write it backwards.

If you do not understand my problem: Basically, I am creating a flatgrass, but if the chunkY coordinate is 0 it should fill the grass all the way to the middle instead of the whole chunk. And it's basically only doing it for the whole chunk thing.
Posted
Updated 23-Dec-12 1:59am
v2
Comments
Shahin Khorshidnia 23-Dec-12 8:44am    
So what is your C# problem? You may correct the algorithm firstly.
Yvar Birx 23-Dec-12 9:21am    
My problem is as I said this: "(ChunkY == 0 && j > World.ChunkSize / 2))". There is no algorithm as this is flat grass.
Daniele Rota Nodari 27-Dec-12 7:15am    
You are looping j from ChunkSize to 1 and comparing it with World.ChunkSize / 2.
Are ChunkSize and World.ChunkSize in some way related?
What are current values for ChunkSize, ChunkY, World.ChunkSize?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900