//methods respawns objects onto grid public void spawnNewDestructables() { //if there are too few point blocks on the map, add some more if (numberOfPointBlocks < 22) { int randX = randomize.Next(1, 17); int randY = randomize.Next(1, 11); if (mapPathData[randY, randX] != -1 && (randX != gridWidth && randY != gridHeight / 2)) { //checks that no blocks are drawn over existing enemy objects if (MainGameClass.playermode == MainGameClass.PLAYERMODE.SinglePlayer && MainGameClass.enemyObjects.Count != 0) { StationaryObject temporaryObject = new StationaryObject(destructableTexture, 1, 1, (int)(randX * gridDimensions.X), (int)(randY * gridDimensions.Y), StationaryObject.PILLER.CAN_DESTROY); destructables.Add(temporaryObject); mapPathData[randY, randX] = -1; numberOfPointBlocks++; MainGameClass.objects.Add(temporaryObject); } else { StationaryObject temporaryObject = new StationaryObject(destructableTexture, 1, 1, (int)(randX * gridDimensions.X), (int)(randY * gridDimensions.Y), StationaryObject.PILLER.CAN_DESTROY); destructables.Add(temporaryObject); mapPathData[randY, randX] = -1; numberOfPointBlocks++; MainGameClass.objects.Add(temporaryObject); } } } }
//setup map public void initialiseMap(Texture2D desTex, Texture2D indesTex) { //load textures destructableTexture = desTex; indestructableTexture = indesTex; //generate destructable objects on map for (int x = 0; x < gridWidth; x++) { for (int y = 0; y < gridHeight; y++) { if (x != 0 && y != 0) { if (x != gridWidth && y != gridHeight/2) { StationaryObject temporaryObject = new StationaryObject(destructableTexture, 1, 1, (int)(x * gridDimensions.X), (int)(y * gridDimensions.Y), StationaryObject.PILLER.CAN_DESTROY); //1st quadrant int randX = randomize.Next(1, 8); int randY = randomize.Next(1, 6); if (x == randX && y == randY && mapPathData[y,x]!=-1) { destructables.Add(temporaryObject); mapPathData[y, x] = -1; numberOfPointBlocks++; } if (x < randX && y == randY && mapPathData[y, x] != -1) { destructables.Add(temporaryObject); mapPathData[y, x] = -1; numberOfPointBlocks++; } //2nd quadrant randX = randomize.Next(9, 17); randY = randomize.Next(1, 6); if (x == randX && y == randY && mapPathData[y, x] != -1) { destructables.Add(temporaryObject); mapPathData[y, x] = -1; numberOfPointBlocks++; } if (x > randX && y > gridHeight && y < randY && mapPathData[y, x] != -1) { destructables.Add(temporaryObject); mapPathData[y, x] = -1; numberOfPointBlocks++; } //3rd quadrant randX = randomize.Next(9, 17); randY = randomize.Next(7, 11); if (x == randX && y == randY && mapPathData[y, x] != -1) { mapPathData[y, x] = -1; destructables.Add(temporaryObject); numberOfPointBlocks++; } if (x > randX && y == randY && mapPathData[y, x] != -1) { destructables.Add(temporaryObject); mapPathData[y, x] = -1; numberOfPointBlocks++; } //4th quadrant randX = randomize.Next(1, 8); randY = randomize.Next(7, 11); if (x == randX && y == randY && mapPathData[y, x] != -1) { destructables.Add(temporaryObject); mapPathData[y, x] = -1; numberOfPointBlocks++; } if (x < randX && y > randY && mapPathData[y, x] != -1) { destructables.Add(temporaryObject); mapPathData[y, x] = -1; numberOfPointBlocks++; } } } }//end y }//end x //generate indestructable objects int random_x; int random_y; int cntr = 0; while (cntr < 6) { random_x = randomize.Next(1, 17); random_y = randomize.Next(1, 11); if (mapPathData[random_y, random_x] != -1 && (random_x != gridWidth && random_y != gridHeight / 2)) { StationaryObject temporaryObject = new StationaryObject(indestructableTexture, 1, 1, (int)(random_x * gridDimensions.X), (int)(random_y * gridDimensions.Y), StationaryObject.PILLER.CANNOT_DESTROY); indestructables.Add(temporaryObject); mapPathData[random_y, random_x] = -1; cntr++; } } //add destructable and indestructable objects to list of game objects for (int i = 0; i < destructables.Count; i++) { MainGameClass.objects.Add(destructables.ElementAt(i)); } for (int i = 0; i < indestructables.Count; i++) { MainGameClass.objects.Add(indestructables.ElementAt(i)); } }
//setup map public void initialiseMap(Texture2D desTex, Texture2D indesTex) { //load textures destructableTexture = desTex; indestructableTexture = indesTex; //generate destructable objects on map for (int x = 0; x < gridWidth; x++) { for (int y = 0; y < gridHeight; y++) { if (x != 0 && y != 0) { if (x != gridWidth && y != gridHeight / 2) { StationaryObject temporaryObject = new StationaryObject(destructableTexture, 1, 1, (int)(x * gridDimensions.X), (int)(y * gridDimensions.Y), StationaryObject.PILLER.CAN_DESTROY); //1st quadrant int randX = randomize.Next(1, 8); int randY = randomize.Next(1, 6); if (x == randX && y == randY && mapPathData[y, x] != -1) { destructables.Add(temporaryObject); mapPathData[y, x] = -1; numberOfPointBlocks++; } if (x < randX && y == randY && mapPathData[y, x] != -1) { destructables.Add(temporaryObject); mapPathData[y, x] = -1; numberOfPointBlocks++; } //2nd quadrant randX = randomize.Next(9, 17); randY = randomize.Next(1, 6); if (x == randX && y == randY && mapPathData[y, x] != -1) { destructables.Add(temporaryObject); mapPathData[y, x] = -1; numberOfPointBlocks++; } if (x > randX && y > gridHeight && y < randY && mapPathData[y, x] != -1) { destructables.Add(temporaryObject); mapPathData[y, x] = -1; numberOfPointBlocks++; } //3rd quadrant randX = randomize.Next(9, 17); randY = randomize.Next(7, 11); if (x == randX && y == randY && mapPathData[y, x] != -1) { mapPathData[y, x] = -1; destructables.Add(temporaryObject); numberOfPointBlocks++; } if (x > randX && y == randY && mapPathData[y, x] != -1) { destructables.Add(temporaryObject); mapPathData[y, x] = -1; numberOfPointBlocks++; } //4th quadrant randX = randomize.Next(1, 8); randY = randomize.Next(7, 11); if (x == randX && y == randY && mapPathData[y, x] != -1) { destructables.Add(temporaryObject); mapPathData[y, x] = -1; numberOfPointBlocks++; } if (x < randX && y > randY && mapPathData[y, x] != -1) { destructables.Add(temporaryObject); mapPathData[y, x] = -1; numberOfPointBlocks++; } } } } //end y } //end x //generate indestructable objects int random_x; int random_y; int cntr = 0; while (cntr < 6) { random_x = randomize.Next(1, 17); random_y = randomize.Next(1, 11); if (mapPathData[random_y, random_x] != -1 && (random_x != gridWidth && random_y != gridHeight / 2)) { StationaryObject temporaryObject = new StationaryObject(indestructableTexture, 1, 1, (int)(random_x * gridDimensions.X), (int)(random_y * gridDimensions.Y), StationaryObject.PILLER.CANNOT_DESTROY); indestructables.Add(temporaryObject); mapPathData[random_y, random_x] = -1; cntr++; } } //add destructable and indestructable objects to list of game objects for (int i = 0; i < destructables.Count; i++) { MainGameClass.objects.Add(destructables.ElementAt(i)); } for (int i = 0; i < indestructables.Count; i++) { MainGameClass.objects.Add(indestructables.ElementAt(i)); } }