//If the player is within a certain distance of an item they //can pick it up unless they are already holding something //if they are not holding anything and pick something up //that item should disappear and appear in a display box //on the bottom right of the screen. public void InteractObject(ObjectiveObject item) { kbState = Keyboard.GetState(); if (item.Textures[0] != picture) { if (objectPickedUp == false) { //trying to get commmented out code to work //if (kbState.IsKeyDown(Keys.E) && position.Intersects(item.Position) && previousKbState.IsKeyUp(Keys.E)) if (kbState.IsKeyDown(Keys.E) && previousKbState.IsKeyUp(Keys.E)) { item.Position = new Rectangle(0, 0, 0, 0); objectPickedUp = true; item.PickedUp = true; } } else { //trying to get commented code to work //if (kbState.IsKeyDown(Keys.E) && objectPickedUp && previousKbState.IsKeyUp(Keys.E)) if (kbState.IsKeyDown(Keys.E) && previousKbState.IsKeyUp(Keys.E)) { item.Position = new Rectangle(this.X, this.Y + 100, 25, 25); objectPickedUp = false; item.PickedUp = false; } } } previousKbState = Keyboard.GetState(); }
//parameterized constructor that will set th efields to objects that are inputed into the constructor public TeaParty(ObjectiveObject vTeaKettle, ObjectiveObject vTeaCups, ObjectiveObject vPlate, List <Point> initialObjSpawn, Game1 game, ObjectiveObject rug, InsanityBar vInsanity) : base() { teaKettle = vTeaKettle; teaCups = vTeaCups; plate = vPlate; this.rug = rug; numberOfCompletions = 0; this.initialObjSpawn = initialObjSpawn; this.game = game; objSpawn = new List <Point>(); insanity = vInsanity; }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); characterHitbox = Content.Load <Texture2D>("unnamed"); //Menus and Screens mainMenu = Content.Load <Texture2D>("MainMenu"); pauseMenu = Content.Load <Texture2D>("PauseMenu"); credits = Content.Load <Texture2D>("CreditsScreen"); controls = Content.Load <Texture2D>("ControlsScreen"); endScreen = Content.Load <Texture2D>("EndScreen"); winScreen = Content.Load <Texture2D>("YouWin"); tempBackground = Content.Load <Texture2D>("BackgroundPic"); //Temp Background //tempBackground = Content.Load<Texture2D>("BackgroundPic"); tree = Content.Load <Texture2D>("Tree"); treeInsane = Content.Load <Texture2D>("TreeInsane"); treeImages = new Texture2D[2]; treeImages[0] = treeInsane; treeImages[1] = characterHitbox; //Insanity Bar insanityBar0 = Content.Load <Texture2D>("NightmareBar0"); insanityBar1 = Content.Load <Texture2D>("NightmareBar1"); insanityBar2 = Content.Load <Texture2D>("NightmareBar2"); insanityBar3 = Content.Load <Texture2D>("NightmareBar3"); insanityBar4 = Content.Load <Texture2D>("NightmareBar4"); insanityBar5 = Content.Load <Texture2D>("NightmareBar5"); insanityBarImages[0] = insanityBar0; insanityBarImages[1] = insanityBar1; insanityBarImages[2] = insanityBar2; insanityBarImages[3] = insanityBar3; insanityBarImages[4] = insanityBar4; insanityBarImages[5] = insanityBar5; insanity = new InsanityBar(insanityBar0, insanityBarImages); //loading the objective object plate into the game platePicture = Content.Load <Texture2D>("Plate"); texturesPlate = new Texture2D[1]; texturesPlate[0] = platePicture; plate = new ObjectiveObject(300, 300, texturesPlate); //loading in the objective object tea kettle into the game teaKetlePictures = Content.Load <Texture2D>("TeaKettle"); texturesTeaKettle = new Texture2D[1]; texturesTeaKettle[0] = teaKetlePictures; teaKettle = new ObjectiveObject(1500, 1000, texturesTeaKettle); //loading in the objective object tea cup into the game cupsPictures = Content.Load <Texture2D>("TeaCup"); texturesCups = new Texture2D[1]; texturesCups[0] = cupsPictures; cups = new ObjectiveObject(1700, 400, texturesCups); invisible = Content.Load <Texture2D>("blank"); textureInvisible = new Texture2D[1]; textureInvisible[0] = invisible; //Character and Enemies teddy0 = Content.Load <Texture2D>("masterSpriteSheet"); teddy1 = Content.Load <Texture2D>("TeddyDeath"); character = Content.Load <Texture2D>("Character"); masterSpriteSheet = Content.Load <Texture2D>("MasterSpriteSheet"); characterImages = new Texture2D[12]; characterImages[0] = character; characterImages[1] = characterHitbox; arial12 = Content.Load <SpriteFont>("arial12"); //sets the black background to a blank picture blackBackground = Content.Load <Texture2D>("unnamed"); //Array of bears bears = new Texture2D[3]; bears[0] = masterSpriteSheet; bears[1] = teddy1; bears[2] = characterHitbox; //Songs mainMenuSong = Content.Load <Song>("MainMenuMusic"); //start the game by playing main menu song MediaPlayer.Play(mainMenuSong); gameSong = Content.Load <Song>("maingame"); gameOverSong = Content.Load <Song>("GameOverMusic"); winSong = Content.Load <Song>("WinGame Music"); rugPicture = Content.Load <Texture2D>("rug"); rugTextures = new Texture2D[1]; rugTextures[0] = rugPicture; // TODO: use this.Content to load your game content here }
/// <summary> /// Load Map Method - Kevin /// Accepts a string to be turned into a file path. The method then reads /// the corresponding file and builds a map from it. /// </summary> /// <param name="file"></param> public void LoadMap(string file) { insanity.ResetInsanityBar(); // Reads information from the map file loadMap = new StreamReader(file); // Skips the first line. It is only needed for the level editor loadMap.ReadLine(); // Reads the map height and width mapHeight = int.Parse(loadMap.ReadLine()); mapWidth = int.Parse(loadMap.ReadLine()); // Creates a list of trees and enemies to help with drawing treeTiles = new List <GameObject>(); enemyTiles = new List <Enemy>(); boundaryTiles = new List <BorderTree>(); // Creates a list of points and a random object for spawing List <Point> initialObjSpawn = new List <Point>(); List <Point> objSpawn; Random rand = new Random(); int spawnIndex; // Resets the origin origin = new Point(0, 0); //rug = new ObjectiveObject(1700, 500, rugTextures); // Creating Game Objects from the file //Loops through each line in the file for (int i = 0; i < mapHeight; i++) { for (int j = 0; j < mapWidth; j++) { // Parses the line into an int objToPlace = int.Parse(loadMap.ReadLine()); if (objToPlace == playerColor) { // Creates a new player object player = new Player(masterSpriteSheet, 400, 240, characterImages, invisible); backgroundBox = new Rectangle(j * tileDimensions * -1, i * tileDimensions * -1, 6000, 6000); } if (objToPlace == treeColor) { // Creates a new tree MapObject and adds it to the // list of trees MapObject t = new MapObject(treeImages, j * tileDimensions, i * tileDimensions); treeTiles.Add(t); } if (objToPlace == enemyColor) { // Creates a new Enemy and adds it to the list of enemies Enemy e = new Enemy(bears, j * tileDimensions, i * tileDimensions, player, this); enemyTiles.Add(e); } if (objToPlace == boundaryColor) { // Creates a new BoarderTree object and adds it to the list // of boarder trees BorderTree b = new BorderTree(treeImages, j * tileDimensions, i * tileDimensions); boundaryTiles.Add(b); } if (objToPlace == objectiveColor) { // Creates a new spawn location for objectives and adds it to the list // of spawn points Point p = new Point(j * tileDimensions, i * tileDimensions); initialObjSpawn.Add(p); } if (objToPlace == rugColor) { // Creates a new rug rug = new ObjectiveObject(j * tileDimensions, i * tileDimensions, rugTextures); rug.Position = new Rectangle(j * tileDimensions, i * tileDimensions, 172, 82); } } } // Copys the initial list to pass to the tea party objSpawn = initialObjSpawn; // Spawns the tea kettle at a random point from the list and removes the point from the list spawnIndex = rand.Next(initialObjSpawn.Count); teaKettle = new ObjectiveObject(initialObjSpawn[spawnIndex].X, initialObjSpawn[spawnIndex].Y, texturesTeaKettle); initialObjSpawn.RemoveAt(spawnIndex); // Spawns the plate at a random point from the list and removes the point from the list spawnIndex = rand.Next(initialObjSpawn.Count); plate = new ObjectiveObject(initialObjSpawn[spawnIndex].X, initialObjSpawn[spawnIndex].Y, texturesPlate); initialObjSpawn.RemoveAt(spawnIndex); // Spawns the cup at a random point from the list and removes the point from the list spawnIndex = rand.Next(initialObjSpawn.Count); cups = new ObjectiveObject(initialObjSpawn[spawnIndex].X, initialObjSpawn[spawnIndex].Y, texturesCups); initialObjSpawn.RemoveAt(spawnIndex); // Creates a TeaParty object and passes in the objectives, spawn location list, and the game tea = new TeaParty(teaKettle, cups, plate, initialObjSpawn, this, rug, insanity); // Closes the StreamReader loadMap.Close(); // Creates a new entity manager manager = new EntityManager(this, insanity); //sets the invisible object to the same position of the player invisibleObject = new ObjectiveObject(player.HitBoxX, player.HitBoxY, textureInvisible); //sets the objective text's vector equal to the players position objectiveTextVector = new Vector2(player.Position.X, player.Position.Y - 80); //sets the rectangle of the black background of the objective text to the position of the player blackBackgroundRectangle = new Rectangle(player.Position.X - 10, player.Position.Y - 90, 300, 75); gameState = GameState.Game; }