00:00
00:00
Newgrounds Background Image Theme

privateC2004 just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Help with map arrays

620 Views | 2 Replies
New Topic Respond to this Topic

Help with map arrays 2012-05-24 08:41:10


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!

Response to Help with map arrays 2012-05-24 09:20:14


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

Response to Help with map arrays 2012-05-24 09:23:10


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