Compiling for different targets is causing weird tilemap bug

19 views
Skip to first unread message

Devyn Mapes

unread,
Nov 10, 2014, 10:55:07 AM11/10/14
to haxef...@googlegroups.com
Everything's been working great until earlier this morning when I compiled my program to test it out natively on Windows and OS X using C++. Up until this point I've just been building and running for neko.

When I compile the game for neko, everything works great. My game runs without issues, however, there is a random bug that prevents me from walking from my second room into my first room. I can walk from my first room to my second room though. Here is the output of running neko.

Now, here is the output when compiling for Windows / Mac.

As you can see, there are extra lines in the tilemap that have been generated with a value of 0. I cannot for the life of me figure out why. At first I thought it was an issue with the data I've sent into the timely. So, I setup a debug procedure to see exactly what string was being passed in.

I have the image above scaled so you can read the text output. At the moment, I have it set to generate the string that the first room is using and output that to a FlxText object. Either way, as you can see, there is no line of 0's at the right end of the string. 

Due to this, I cannot for the life of me figure out why this weird bug is happening. Any help you guys could provide would be greatly appreciated. Below is all relevant code from my program.


private function generateWorld():Void
{
/***********************************
* !!!WORLD GENERATION: IMPORTANT!!!
* Read carefully. It's complex.
***********************************/

// STEP 1: Generate an array of worlds
worlds = new Array<World>();

for (row in 0...maxNumOfWorlds)
{
// generate random world size
worldSize = FlxRandom.intRanged(0, 2);
if (row == 0)
{
worlds[row] = new World("entrance", worldSize);
currentNumOfWorlds += 1;
} // end if

else 
{
worlds[row] = new World(("world" + Std.string(currentNumOfWorlds)), worldSize);
currentNumOfWorlds += 1;
} // end if
} // end for

// STEP 2: Create tilemaps for each world
gameMaps = new Array<FlxTilemap>();
entityMaps = new Array<FlxTilemap>();
waterMaps = new Array<FlxTilemap>();

for (row in 0...maxNumOfWorlds)
{
gameMaps[row] = new FlxTilemap();
entityMaps[row] = new FlxTilemap();
waterMaps[row] = new FlxTilemap();
} // end for

// STEP 3: Populate those tilemaps with
// data stored in each world.

// NOTE: Also positions tilemaps in the 
// game world.

currentMaxHeight = 0; // max height of the game map

for (row in 0...maxNumOfWorlds)
{
// add data from world into tilemap
tempMap = worlds[row].generateMap();
mapString = worlds[row].convertMapToString(tempMap);
gameMaps[row].loadMap(mapString, "assets/images/brick_tiles.png", tileSize, tileSize, 0, 0, 0, 1);

// add data  from world's entity map into tilemap
mapString = worlds[row].convertMapToString(worlds[row].getEntityMap());
entityMaps[row].loadMap(mapString, "assets/images/entities.png", tileSize, tileSize, 0, 0, 0, 100);

// add data from the world's water map into tilemap
mapString = worlds[row].convertMapToString(worlds[row].getLiquidsMap());
waterMaps[row].loadMap(mapString, "assets/images/water.png", tileSize, tileSize, 0, 0, 0, 100);

// if we're dealing with a room that isn't
// the starting room
if (row > 0)
{
// adjust it's X position so that it is not on top of another world
gameMaps[row].x = (gameMaps[(row - 1)].widthInTiles) * tileSize;
entityMaps[row].x = (entityMaps[(row - 1)].widthInTiles) * tileSize;
waterMaps[row].x = (waterMaps[(row - 1)].widthInTiles) * tileSize;

// adjust it's Y position so that it's doors line up properly
if (gameMaps[row].heightInTiles > gameMaps[(row - 1)].heightInTiles)
{
gameMaps[row].y = 0 - ((gameMaps[row].heightInTiles -
                                                         gameMaps[(row - 1)].heightInTiles - 3) * tileSize);
entityMaps[row].y = 0 - ((entityMaps[row].heightInTiles -
                                                       entityMaps[(row - 1)].heightInTiles - 3) * tileSize);
waterMaps[row].y = 0 - ((waterMaps[row].heightInTiles -
                                                        waterMaps[(row - 1)].heightInTiles - 3) * tileSize);
} // end if
} // end if

// if current map height is greater than current max height
// current max height = current map height
if ((-1 * gameMaps[row].y) > currentMaxHeight)
{
currentMaxHeight = (-1 * (gameMaps[row].y));
} // end if

// add the newly generated tilemaps to groups
group_GameMaps.add(gameMaps[row]);
group_Entities.add(entityMaps[row]);
//group_WaterMaps.add(waterMaps[row]);
} // end for

// adjust world height so that it is drawn within the world bounds
for (row in 0...maxNumOfWorlds)
{
gameMaps[row].y += currentMaxHeight;
entityMaps[row].y += currentMaxHeight;
waterMaps[row].y += currentMaxHeight;
} // end for
} // end GenerateWorld


public function generateMap():Array<Array<Int>>
  {
    var tempMap:Array<Array<Int>>;

    // set the max size X and Y
    // to the size of the world
    var sizeX:Int = Std.int(size.x);
    var sizeY:Int = Std.int(size.y);


    // fill the map with empty space
    tempMap = [for (row in 0...sizeY) [for (col in 0...sizeX) 0]];
    

    // rule 1: map must have boundaries on all sides
    // therefore: fill top and bottom of room with 1's

    var row:Int = 0;
    while (row < sizeY)
    {
      for (col in 0...sizeX)
      {
        if (row == 0)
        {
          tempMap[row][col] = 3;
        }
        if (row > 0)
        {
          tempMap[row][col] = 2;
        }
      } // end for

      if (row == (sizeY - 1))
      {
        row++;
      }

      if (row > 0)
      {
        row++;
      } // end for

      if (row == 0)
      {
        row = sizeY - 1;
      } // end if
    } // end while

    // fill left and right side of room with 1's
    var col:Int = 0;
    while (col < sizeX)
    {
      for (row in 0...sizeY)
      {
        if (col == 0)
        {
          tempMap[row][col] = 5;
        }
        if (col > 0)
        {
          tempMap[row][col] = 4;
        }
      } // end for

      if (col == (sizeX - 1))
      {
        col++;
      }
      if (col > 0)
      {
        col++;
      } // end if

      if (col == 0)
      {
        col = sizeX - 1;
      } // end if
    } // end while

    // set the corners equal to 1
    tempMap[0][0] = 1;
    tempMap[0][(sizeX - 1)] = 1;
    tempMap[(sizeY - 1)][0] = 1;
    tempMap[(sizeY - 1)][(sizeX - 1)] = 1;

    col = row = 0;

    if (worldName != "entrance")
    {
      tempMap = generatePlatforms(tempMap);
    } // end if

    tempMap = generateDoors(tempMap);
    map = tempMap;

    return tempMap;
  } // end generateMap


public function convertMapToString(map:Array<Array<Int>>):String
  {
    var mapString:String = "";
    var sizeX:Int = Std.int(size.x);
    var sizeY:Int = Std.int(size.y);
    
    for (row in 0...sizeY)
    {
      for (col in 0...sizeX)
      {
        mapString += Std.string(map[row][col]) + ",";
      } // end for

      if (row < (sizeY-1))
      {
        mapString += "\n";
      } // end if
    } // end for
    
    return mapString;
  } // end convertMapToString



Reply all
Reply to author
Forward
0 new messages