/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { base.Initialize(); //spawn a player and a wall here for testing purposes pausemessagething = new GameObject(); pausemessagething.Location = new Rectangle(170, 100, 500, 200); pausemessagething.Image = ImageBank.pausemessage; player = new Player(); textBox = new InputWindow(player); //set up winscreen winscreenpopup = new GameObject(); winscreenpopup.Location = new Rectangle(170,100,500,400); winscreenpopup.Image = ImageBank.winscreen; //set up lose screen loosescreenpopup = new GameObject(); loosescreenpopup.Location = new Rectangle(170, 100, 500, 400); loosescreenpopup.Image = ImageBank.looseScreen; //set up reset and continue buttons resetButton = new GameObject(); resetButton.Location = new Rectangle(370,380,80,35); continueButton = new GameObject(); continueButton.Location = new Rectangle(resetButton.Location.Right+0, 380, 80, 40); //load list of levels // levels.Add("testLevel"); // /* levels.Add("levelOne"); levels.Add("levelTwo"); levels.Add("levelThree"); levels.Add("levelFour"); levels.Add("levelFive"); levels.Add("levelSix"); levels.Add("levelSeven");//*/ levels.Add("bossLevel"); //create new map map = new Map(player); map.Load(levels[0]); //load background, set it in place background = new GameObject(); background.Location = new Rectangle(0, 0, 800, 600); background.Image = ImageBank.background; }
//read a file and populated the grid with objects public void Load(string level) { BinaryReader reader; //Get testmap data file try { reader = new BinaryReader(File.Open(level+".dat", FileMode.Open)); } catch (Exception e) { throw e; } //write number of rows, then columns then the string int r = reader.ReadInt32(); row = r; int c = reader.ReadInt32(); col = c; length = r * 50; width = c * 50; string s = reader.ReadString(); char[] chars = s.ToCharArray(); grid = new GameObject[r, c]; //populate matrix of GameObjects for (int i = 0; i < r; i++){//loop through all rows and cols for (int j = 0; j < c; j++){ char m = chars[(i * c + j)]; if (m == 'a') { //'a' is a blank space grid[i, j] = null; } else if ((int)m == (int)'a'+1) { //'a' is a blank space grid[i, j] = new Wall(); grid[i, j].Location = new Rectangle(j * 50, i * 50, 50, 50); grid[i, j].Image = ImageBank.platforms[0]; } else if((int)m < ((int)'a'+50)){ //otherwise just place a wall for now grid[i, j] = new Platform(); grid[i, j].Location = new Rectangle(j * 50, i * 50, 50, 50); grid[i, j].Image = ImageBank.platforms[(int)m-((int)'a' + 1)]; } else if (m == (char)((int)'a'+50)) { //'a'+50 should be the basic enemy grid[i, j] = null; //treat as blank space //then add a new minion on spot to Que of Movables WalkingMinion mini = new WalkingMinion(p, j * 50, i * 50-30); mini.Map = this; //give enemy reference to this map object //mini.Location = new Rectangle(j * 50, i * 50, 50, 50); movables.Add((Movable)mini); } else if (m == (char)((int)'a' + 51)) { //'a'+51 should be the shooting enemy grid[i, j] = null; //treat as blank space //then add a new minion on spot to Que of Movables ShootingMinion e2= new ShootingMinion(p, j * 50, i * 50 - 30); e2.Map = this; //give enemy reference to this map object //mini.Location = new Rectangle(j * 50, i * 50, 50, 50); movables.Add((Movable)e2); } else if (m == (char)((int)'a' + 52)) { //'a'+52 should be the lamp enemy grid[i, j] = null; //treat as blank space //then add a new minion on spot to Que of Movables LampMinion e2 = new LampMinion(p, j * 50, i * 50 - 0); e2.Map = this; //give enemy reference to this map object //mini.Location = new Rectangle(j * 50, i * 50, 50, 50); movables.Add((Movable)e2); } else if (m == (char)((int)'a' + 53)) { //'a'+53 should be the BOSS grid[i, j] = null; //treat as blank space //then add a new minion on spot to Que of Movables Boss b = new Boss(p, j * 50, i * 50 - 0); b.Map = this; //give enemy reference to this map object //mini.Location = new Rectangle(j * 50, i * 50, 50, 50); movables.Add((Movable)b); } else if (m == (char)((int)'a' + 150)) { //'a'+150 Player spawn grid[i, j] = null; //treat as blank space playerSpawn = new Point(j*50,i*50); } else if (m == (char)((int)'a' + 151)) { //'a'+151 Player goal grid[i, j] = new Goal(); //treat as blank space grid[i,j].Location= new Rectangle(j * 50, i * 50,50,50); goal = (Goal)grid[i, j]; } else if (m == (char)((int)'a' + 153)) { //'a'+153 Tutorial "keys" image grid[i, j] = new GameObject(); //treat as blank space grid[i, j].Location = new Rectangle(j * 50, i * 50, 300, 150); grid[i, j].Image = ImageBank.keys; } else { //otherwise just place a wall for now grid[i, j] = new Platform(); grid[i, j].Location = new Rectangle(j * 50, i * 50, 50, 50); } } } reader.Close(); resetList = new List<Movable>(Movables); Reset(); }