Be a Supporter!
TheWanderingFox
TheWanderingFox
  • Member since: Jan. 1, 2010
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Help with map arrays May. 24th, 2012 @ 08:41 AM Reply

Hey guys, I'm currently working on a game where when 3 characters are saved and sent to the exit it changes to a new map, the only issue is when the level is complete the numbers in the array change but the images do not.
I realise this is a case of using removeChild [row] [col] but I'm not too sure how to begin with the code. I know it's a case of removing certain event listeners and again setting up the map, but as I say I'm not entirely sure how to start with the code
Here is the code for the map array and it's set up:

var origMap:Array = [
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 5, 2, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 1],
[1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1],
[1, 5, 1, 0, 1, 4, 0, 0, 0, 2, 0, 1, 0, 1, 0, 1],
[1, 0, 1, 0, 1, 2, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1],
[1, 5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1],
[1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1],
[1, 0, 1, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1],
[1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
]

var twoMap:Array = [
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 5, 2, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 1],
[1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1],
[1, 0, 1, 0, 1, 4, 0, 0, 0, 2, 0, 1, 0, 1, 0, 1],
[1, 5, 1, 0, 1, 2, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1],
[1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1],
[1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1],
[1, 5, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1],
[1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1],
[1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
]

var AllMaps:Array = [origMap, twoMap]
var map:Array; // used in the game play..
var displayMap:Array;

function newLevel(){
currentLevel += 1;
trace (currentLevel);
setUpGame();
DoOver();

}

//

function setUpGame(){
displayMap = new Array(); // (re) initialise the display map
map = new Array();
copyArray(map, AllMaps[currentLevel]) // (re) populate the map array with original data
for (var row = 0; row < MAP_HEIGHT; row++){
displayMap[row] = new Array();
for (var col = 0; col < MAP_WIDTH; col++){
var tile:Tile = new Tile();
displayMap[row][col] = tile;
tile.x = TILE_WIDTH / 2 + (col) * TILE_WIDTH;
tile.y = TILE_WIDTH / 2 + (row + 1) * TILE_WIDTH;
tile.visible = false;
addChild(tile);
tile.gotoAndStop(1);
switch (map[row][col]){

function copyArray(copy:Array, original:Array){
/* copies the contents of original array into copy. Both arrays assumed to be 2D */
for (var row = 0; row < original.length; row++){
copy[row] = new Array()
for (var col = 0; col < original[row].length; col++){
copy[row][col] = original[row][col]

Sorry for the crappy code!
Hope someone can help,
thank you!

Wolfos
Wolfos
  • Member since: Jan. 19, 2008
  • Offline.
Forum Stats
Member
Level 25
Game Developer
Response to Help with map arrays May. 24th, 2012 @ 09:20 AM Reply

Learn to fucking read.
http://www.newgrounds.com/bbs/forum/2

Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to Help with map arrays May. 24th, 2012 @ 09:23 AM Reply

Also, if you're going to post code, please use the code tags; it makes it much easier to read.