using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Sprint3_actual.SpriteFactories; using Sprint3_actual.StateFiles; using Sprint3_actual.Items; using System.Collections.Generic; using System.Linq; using Sprint3_actual.BorderElements; using Sprint3_actual.XML_LevelLoading; using Sprint3_actual.SoundManagement; using System.Threading; namespace Sprint3_actual { public class Game1 : Game { public Camera2D camera; public Vector2 CameraPos; Matrix viewMatrix; public LevelTransition transition; private GraphicsDeviceManager graphics; public Texture2D PlayerTexture; private List<IController> controllerList; private ILink player; public List<XMLParser.Item> XMLItems; public int roomColumn; public int roomRow; public room[,] Rooms; public room currentRoom; public bool transitioning; public bool isLinkDead; //Gametype: 1 = normal, 2 = dungeon2, 3 = procedurally generated public ILink Player { get { return player; } set { player = value; } } public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; IsMouseVisible = true; transitioning = false; isLinkDead = false; transition = new LevelTransition(); } protected override void Initialize() { Rooms = new room[8, 8]; graphics.IsFullScreen = false; graphics.PreferredBackBufferWidth = 768; graphics.PreferredBackBufferHeight = 696; graphics.ApplyChanges(); camera = new Camera2D(new Viewport()); CameraPos = Vector2.Zero; KeyboardController k = new KeyboardController(this); controllerList = new List<IController>(); controllerList.Add(k); Window.Title = "The Legend of Sigma"; base.Initialize(); } protected override void LoadContent() { GlobalVars.spriteBatch = new SpriteBatch(GraphicsDevice); GlobalVars.font = Content.Load<SpriteFont>("LegendOfZelda"); //this font needs to be changed PlayerTexture = Content.Load<Texture2D>("NES - The Legend Of Zelda - Link"); Player = new Link(this, PlayerTexture); Texture2D NPCSpriteSheet = Content.Load<Texture2D>("NPCSprites"); BlockSpriteFactory.Instance.LoadAllTextures(Content); BorderElementsSpriteFactory.Instance.LoadAllTextures(Content); ItemSpriteFactory.Instance.LoadAllTextures(Content); NPCSpriteFactory.Instance.LoadAllTextures(Content); InventorySpriteFactory.Instance.LoadAllTextures(Content); SoundEngine.Instance.LoadSounds(Content); SoundEngine.Instance.startDungeonMusic(); Inventory.Instance.loadInventory(this, camera.Position); } protected override void Update(GameTime gameTime) { GlobalVars.gameTime = gameTime; if (!isLinkDead) { foreach (IController controller in controllerList) { controller.Update(); } GlobalVars.gameTime = gameTime; currentRoom = Rooms[roomRow, roomColumn]; if (!transitioning) { Player.Update(); Rooms[roomRow, roomColumn].update(gameTime); if (Inventory.Instance.levelCount == 1) { if (roomRow == 4 && roomColumn == 2) { if (currentRoom.NPCList.Count == 0) { currentRoom.DoorList[2].Open = true; } } if (roomRow == 3 && roomColumn == 2) { if (currentRoom.BlockList.ElementAt(0).getPos().X > camera.Position.X + 336) { currentRoom.DoorList[1].Open = true; } } if (roomRow == 1 && roomColumn == 6) { if (currentRoom.NPCList.Count == 0) { currentRoom.DoorList[2].Open = true; } } if (roomRow == 2 && roomColumn == 5) { if (currentRoom.NPCList.Count == 0) { currentRoom.DoorList[2].Open = true; } } } else if (Inventory.Instance.levelCount == 2) { if (roomRow == 6 && roomColumn == 3) { if (currentRoom.NPCList.Count == 0) { currentRoom.DoorList[1].Open = true; } } if (roomRow == 4 && roomColumn == 4) { if (currentRoom.NPCList.Count == 0) { currentRoom.DoorList[3].Open = true; } } if (roomRow == 2 && roomColumn == 4) { if (currentRoom.NPCList.Count == 0) { currentRoom.DoorList[0].Open = true; } } if (roomRow == 1 && roomColumn == 4) { if (currentRoom.NPCList.Count == 0) { currentRoom.DoorList[0].Open = true; currentRoom.DoorList[3].Open = true; } } if (roomRow == 0 && roomColumn == 4) { if (currentRoom.NPCList.Count == 0) { currentRoom.DoorList[1].Open = true; } } } else { if (currentRoom.BossRoom) { if (currentRoom.NPCList.Count == 0) { currentRoom.BossRoom = false; currentRoom.StageItemList.Add(StageItemFactory.Instance.CreateStageItem(28, currentRoom.RoomColumnOffset + 384, currentRoom.RoomRowOffset + GlobalVars.inventoryHeight + 264, this)); } } } } else { transition.updateCamera(camera, this); } Inventory.Instance.Update(camera.Position); } else { SoundEngine.Instance.stopMusic(); Thread.Sleep(3000); Exit(); } base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.DimGray); viewMatrix = camera.GetViewMatrix(); GlobalVars.spriteBatch.Begin(SpriteSortMode.Immediate, null, SamplerState.PointClamp, null, transformMatrix: viewMatrix); if (!isLinkDead) { foreach (room Room in Rooms) { if (Inventory.Instance.levelCount == 1) { if (GlobalVars.roomArray1[Room.roomY, Room.roomX] != null) Room.DrawBelowLinkObjects(); } else if (Inventory.Instance.levelCount == 2) { if (GlobalVars.roomArray2[Room.roomY, Room.roomX] != null) { Room.DrawBelowLinkObjects(); } } else { if (Room != null) { Room.DrawBelowLinkObjects(); } } if (!transitioning) { Player.Draw(); Rooms[roomRow, roomColumn].DrawAboveLinkObjects(); } Player.Draw(); Inventory.Instance.Draw(camera.Position); } } else { GraphicsDevice.Clear(Color.Black); GlobalVars.spriteBatch.DrawString(GlobalVars.font, "GAME OVER", new Vector2(CameraPos.X + 300, CameraPos.Y + 300), Color.White); } GlobalVars.spriteBatch.End(); base.Draw(gameTime); } } }