/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here empty = Content.Load<Texture2D>("empty"); OWSpriteSheet = Content.Load<Texture2D>("OverworldTiles"); heartsSheet = Content.Load<Texture2D>("Heart Tiles"); caveMap = Content.Load<Texture2D>("Cave map"); equippedFrame = Content.Load<Texture2D>("ItemFrame"); LoZText = Content.Load<SpriteFont>("Pixel Emulator"); UW1Sheet = Content.Load<Texture2D>("UW"); currentState = Globals.gState.overworld; numT = 9; tStart = new Vector2[numT]; tSMap = new Globals.gState[numT]; tDest = new Vector2[numT]; tDMap = new Globals.gState[numT]; string tileString; string colString; string caveColString; string UW1ColString; using (StreamReader sr = new StreamReader("OWTileMap.txt")) { tileString = sr.ReadLine(); } using (StreamReader sr = new StreamReader("OWCollision.txt")) { colString = sr.ReadLine(); for(int i = 0; i<87; i++) { colString += sr.ReadLine(); } } using (StreamReader sr = new StreamReader("Cavelision.txt")) { caveColString = sr.ReadLine(); for (int i = 0; i < 45; i++) { caveColString += sr.ReadLine(); } } using (StreamReader sr = new StreamReader("UW1Collision.txt")) { UW1ColString = sr.ReadLine(); for (int i = 0; i < 87; i++) { UW1ColString += sr.ReadLine(); } } using (StreamReader sr = new StreamReader("Transitions.txt")) { for (int i = 0; i < numT; i++) { string transition = sr.ReadLine(); string[] tSplit = transition.Split('|'); string[] vtS = tSplit[0].Split(','); tStart[i].X = float.Parse(vtS[0]); tStart[i].Y = float.Parse(vtS[1]); vtS = tSplit[2].Split(','); tDest[i].X = float.Parse(vtS[0]); tDest[i].Y = float.Parse(vtS[1]); Globals.gState test; if(Enum.TryParse<Globals.gState>(tSplit[1], out test)) tSMap[i] = test; if (Enum.TryParse<Globals.gState>(tSplit[3], out test)) tDMap[i] = test; } } string[] tsSplit = tileString.Split(' '); string[] colSplit = colString.Split(' '); string[] caveSplit = caveColString.Split(' '); string[] uw1Split = UW1ColString.Split(' '); for (int j = 0; j < 88; j++) { for(int i = 0; i < 256; i++) { tileMap[i,j] = int.Parse(tsSplit[(j*256)+i], System.Globalization.NumberStyles.HexNumber); //Convert.ToInt32(tsSplit[(j*16) + i]); if(colSplit[(j*256)+i] == "X") { collisionMap[i,j] = 1; //1 = collide. } else if (colSplit[(j * 256) + i] == "T") { collisionMap[i, j] = 2; //2 = transition tile } else collisionMap[i, j] = 0; if (uw1Split[(j * 256) + i] == "X" || uw1Split[(j * 256) + i] == "0") { UWCMap1[i, j] = 1; } else if (uw1Split[(j * 256) + i] == "T") { UWCMap1[i, j] = 2; } else UWCMap1[i, j] = 0; if (i < 64 && j < 44) { if (caveSplit[(j * 64) + i] == "X") { caveCMap[i, j] = 1; //1 = collide. } else if (caveSplit[(j * 64) + i] == "T") { caveCMap[i, j] = 2; //2 = transition tile } else caveCMap[i, j] = 0; } } } Link = new player(new Vector2(7.5f, 5), 6); viewPort = new Vector2(112, 77); Link.move(viewPort); //adjusts Link's position based on which map section the camera starts in. oldState = Keyboard.GetState(); }
protected void updatePlayer(double delta) { newState = Keyboard.GetState(); Vector2 movAmount = new Vector2(0); Vector2 movCheck = new Vector2(0); bool moving = false; if (newState.IsKeyDown(Keys.W)) { movAmount = new Vector2(0, -1); movCheck.Y = -8; moving = true; } else if (newState.IsKeyDown(Keys.A)) { movAmount = new Vector2(-1, 0); movCheck.X = -8; moving = true; } else if (newState.IsKeyDown(Keys.S)) { movAmount = new Vector2(0, 1); movCheck.Y = 8; moving = true; } else if (newState.IsKeyDown(Keys.D)) { movAmount = new Vector2(1, 0); movCheck.X = 8; moving = true; } //CHECK 0.5 - if player is on a transition tile. //N.B. - Has to be at start so as to be before movement position checks are made, because collision uses offsetPos. Will also mean player finishes movement before activating animation for (int i = 0; i < numT; i++) { Vector2 lTemp = new Vector2(); lTemp.X = Convert.ToSingle(Math.Round(Link.getPos().X)); lTemp.Y = Convert.ToSingle(Math.Round(Link.getPos().Y)); if (currentState == tSMap[i]) { if (tStart[i] == lTemp) { //DO THINGS. Link.setPos(new Vector2(0)); Vector2 vTemp = new Vector2(tDest[i].X%16, tDest[i].Y%11); viewPort = tDest[i] - vTemp; currentState = tDMap[i]; Link.move(tDest[i]); mapChange = false; } } /*else if (currentState == tDMap[i]) { if (tDest[i] == lTemp) { DO OTHER THINGS. -- Maybe not. Link.setPos(new Vector2(0)); Vector2 vTemp = new Vector2(tStart[i].X % 16, tStart[i].Y % 11); viewPort = tStart[i] - vTemp; currentState = tSMap[i]; Link.move(tStart[i]); } } //*/ } if (moving && !mapChange) { Vector2 offsetPos = new Vector2(0.5f); offsetPos += Link.getPos(); //uses center of link as position instead of top left, allows for standardised collision checking movCheck += movAmount; //CHECK 1 - if player position would go off edge of map: zone transition. if (currentState == Globals.gState.overworld) //Check not needed for caves as caves are all singular zones that operate off transition tiles instead of edges. { Vector2 zoneCheck = (movCheck / new Vector2(16)) + offsetPos - viewPort; if (zoneCheck.X < 0) { offsetPos = Link.getPos(); mapChange = true; MCDir = new Vector2(-1, 0); tempSteps = 20; } else if (zoneCheck.X > 16) { mapChange = true; MCDir = new Vector2(1, 0); tempSteps = 20; } else if (zoneCheck.Y < 0) { mapChange = true; MCDir = new Vector2(0, -1); tempSteps = 20; } else if (zoneCheck.Y > 10.5) { mapChange = true; MCDir = new Vector2(0, 1); tempSteps = 20; } } else if (currentState != Globals.gState.caves) { Vector2 zoneCheck = (movCheck / new Vector2(16)) + offsetPos - viewPort; if (zoneCheck.X < 1) { offsetPos = Link.getPos(); mapChange = true; MCDir = new Vector2(-1, 0); tempSteps = 20; } else if (zoneCheck.X > 15) { mapChange = true; MCDir = new Vector2(1, 0); tempSteps = 20; } else if (zoneCheck.Y < 1) { mapChange = true; MCDir = new Vector2(0, -1); tempSteps = 20; } else if (zoneCheck.Y > 9.5) { mapChange = true; MCDir = new Vector2(0, 1); tempSteps = 20; } } //CHECK 2 - if player would start to move inside a wall switch (currentState) { case Globals.gState.overworld: if(!checkCollision(offsetPos, movCheck, collisionMap)) { Link.move(movAmount/16); } break; case Globals.gState.caves: if (!checkCollision(offsetPos, movCheck, caveCMap)) { Link.move(movAmount / 16); } break; case Globals.gState.dungeon1: if (!checkCollision(offsetPos, movCheck, UWCMap1)) { Link.move(movAmount / 16); } break; case Globals.gState.dungeon2: if (!checkCollision(offsetPos, movCheck, UWCMap2)) { Link.move(movAmount / 16); } break; } } oldState = newState; }