public ConstructionMenu(Vector2 renderPosition, ContentManager Content, inventory playerInvIn, MapLoader currMapIn, Player currPlayerIn) { location = renderPosition; List<Tuple<resource.resourceTypes, int>> spikeResources = new List<Tuple<resource.resourceTypes, int>>(); spikeResources.Add(new Tuple<resource.resourceTypes, int>(resource.resourceTypes.Wood, 1)); items.Add(new constructionItem(resource.resourceTypes.Spike, spikeResources, true, false, true)); List<Tuple<resource.resourceTypes, int>> spikePitResources = new List<Tuple<resource.resourceTypes, int>>(); spikePitResources.Add(new Tuple<resource.resourceTypes, int>(resource.resourceTypes.Spike, 5)); items.Add(new constructionItem(resource.resourceTypes.SpikePit, spikePitResources, false, true)); List<Tuple<resource.resourceTypes, int>> treeResources = new List<Tuple<resource.resourceTypes, int>>(); treeResources.Add(new Tuple<resource.resourceTypes, int>(resource.resourceTypes.Acorn, 1)); items.Add(new constructionItem(resource.resourceTypes.Tree, treeResources, false, true)); background = Content.Load<Texture2D>("InventoryBackground"); itemSlot = Content.Load<Texture2D>("inventorySquare"); selectedItemSlot = Content.Load<Texture2D>("selectedInventorySquare"); inventoryDialog = Content.Load<Texture2D>("inventoryDialogBox"); Spike = Content.Load<Texture2D>("woodenStake"); SpikePit = Content.Load<Texture2D>("spikepitTile"); Tree = Content.Load<Texture2D>("treeIcon"); font = Content.Load<SpriteFont>("SpriteFont1"); playerInv = playerInvIn; currMap = currMapIn; currPlayer = currPlayerIn; }
public ConstructionMenu(Vector2 renderPosition, ContentManager Content, inventory playerInvIn, MapLoader currMapIn, Player currPlayerIn) { location = renderPosition; List <Tuple <resource.resourceTypes, int> > spikeResources = new List <Tuple <resource.resourceTypes, int> >(); spikeResources.Add(new Tuple <resource.resourceTypes, int>(resource.resourceTypes.Wood, 1)); items.Add(new constructionItem(resource.resourceTypes.Spike, spikeResources, true, false, true)); List <Tuple <resource.resourceTypes, int> > spikePitResources = new List <Tuple <resource.resourceTypes, int> >(); spikePitResources.Add(new Tuple <resource.resourceTypes, int>(resource.resourceTypes.Spike, 5)); items.Add(new constructionItem(resource.resourceTypes.SpikePit, spikePitResources, false, true)); List <Tuple <resource.resourceTypes, int> > treeResources = new List <Tuple <resource.resourceTypes, int> >(); treeResources.Add(new Tuple <resource.resourceTypes, int>(resource.resourceTypes.Acorn, 1)); items.Add(new constructionItem(resource.resourceTypes.Tree, treeResources, false, true)); background = Content.Load <Texture2D>("InventoryBackground"); itemSlot = Content.Load <Texture2D>("inventorySquare"); selectedItemSlot = Content.Load <Texture2D>("selectedInventorySquare"); inventoryDialog = Content.Load <Texture2D>("inventoryDialogBox"); Spike = Content.Load <Texture2D>("woodenStake"); SpikePit = Content.Load <Texture2D>("spikepitTile"); Tree = Content.Load <Texture2D>("treeIcon"); font = Content.Load <SpriteFont>("SpriteFont1"); playerInv = playerInvIn; currMap = currMapIn; currPlayer = currPlayerIn; }
/// <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); worldMap.loadContent(Content, graphics.PreferredBackBufferHeight, graphics.PreferredBackBufferWidth); worldMap.loadMap("content/worldMap.txt"); currentMap = worldMap; currentPlayer = new Player(Content); zombies.Add(new Zombie(Content, new Vector2(450, 450))); font = Content.Load<SpriteFont>("SpriteFont1"); soundOhNo = Content.Load<SoundEffect>("ohNo"); soundOhNoInstance = soundOhNo.CreateInstance(); conMenu = new ConstructionMenu(new Vector2(0, 0), Content, currentPlayer.getInventory(), currentMap, currentPlayer); //inv.addToInventory(resource.resourceTypes.Hatchet, 1); // TODO: use this.Content to load your game content here }
bool willCollide(Vector2 positionToMoveTo, Texture2D movingObject) { Vector2 currentViewport = currentMap.getViewport(); //Vector2 moveToRelativeToScreen = new Vector2(positionToMoveTo.X - currentViewport.X, positionToMoveTo.Y - currentViewport.Y); Matrix movingObjectMatrix = Matrix.CreateTranslation(positionToMoveTo.X, positionToMoveTo.Y, 0); Color[,] movingObjectColours = Helpers.TextureTo2DArray(movingObject); //check for consumable objects foreach (ConsumableMapObject obj in currentMap.getNonEnterableObjects()) { Vector2 objPositionRelativeToScreen = new Vector2(obj.getLocation().X - currentViewport.X, obj.getLocation().Y - currentViewport.Y); Matrix objectMatrix = Matrix.CreateTranslation(objPositionRelativeToScreen.X, objPositionRelativeToScreen.Y, 0); Color[,] nonEnterableObjectColours = Helpers.TextureTo2DArray(obj.getTexture()); Vector2 collisionPoint = Helpers.TexturesCollide(nonEnterableObjectColours, objectMatrix, movingObjectColours, movingObjectMatrix); if (collisionPoint.X != -1) { collidingObject = obj; currentPlayer.setAdjacantObject(obj); return true; } } //check for enterable objects. foreach (EnterableMapObject obj in currentMap.getEnterableObjects()) { Vector2 objPositionRelativeToScreen = new Vector2(obj.getLocation().X - currentViewport.X, obj.getLocation().Y - currentViewport.Y); Matrix objectMatrix = Matrix.CreateTranslation(objPositionRelativeToScreen.X, objPositionRelativeToScreen.Y, 0); Color[,] nonEnterableObjectColours = Helpers.TextureTo2DArray(obj.getTexture()); Vector2 collisionPoint = Helpers.TexturesCollide(nonEnterableObjectColours, objectMatrix, movingObjectColours, movingObjectMatrix); if (collisionPoint.X != -1) { Vector2 actualObjectPosition = new Vector2((positionToMoveTo.X + currentViewport.X), positionToMoveTo.Y + currentViewport.Y); if (obj.canEnterFromPosition(actualObjectPosition)) { worldMapPos = new Vector2((obj.getLocation().X + obj.getTexture().Width / 2) - currentViewport.X, obj.getLocation().Y - currentViewport.Y + obj.getTexture().Height); currentPlayer.setPosition(new Vector2(0, 0)); currentMap = obj.getMap(); } return true; } } if (currentMap.moveWillExitMap(positionToMoveTo, movingObject)) { return true; } Color[,] exitColours = Helpers.TextureTo2DArray(currentMap.getExitTexture()); Matrix exitMatrix = Matrix.CreateTranslation(currentMap.getExitPos().X, currentMap.getExitPos().Y, 0); Vector2 exitCollisionPoint = Helpers.TexturesCollide(exitColours, exitMatrix, movingObjectColours, movingObjectMatrix); if (exitCollisionPoint.X != -1) { currentPlayer.setPosition(worldMapPos); currentMap = worldMap; return true; } //check for leaving the map if (positionToMoveTo.X < 0 || positionToMoveTo.Y < 0 || positionToMoveTo.X > (graphics.PreferredBackBufferWidth - currentPlayer.getTexture().Width) || positionToMoveTo.Y > (graphics.PreferredBackBufferHeight - currentPlayer.getTexture().Height)) { return true; } collidingObject = null; currentPlayer.setAdjacantObject(null); return false; }
bool willCollide(Vector2 positionToMoveTo, Texture2D movingObject) { Vector2 currentViewport = currentMap.getViewport(); //Vector2 moveToRelativeToScreen = new Vector2(positionToMoveTo.X - currentViewport.X, positionToMoveTo.Y - currentViewport.Y); Matrix movingObjectMatrix = Matrix.CreateTranslation(positionToMoveTo.X, positionToMoveTo.Y, 0); Color[,] movingObjectColours = Helpers.TextureTo2DArray(movingObject); //check for consumable objects foreach (ConsumableMapObject obj in currentMap.getNonEnterableObjects()) { Vector2 objPositionRelativeToScreen = new Vector2(obj.getLocation().X - currentViewport.X, obj.getLocation().Y - currentViewport.Y); Matrix objectMatrix = Matrix.CreateTranslation(objPositionRelativeToScreen.X, objPositionRelativeToScreen.Y, 0); Color[,] nonEnterableObjectColours = Helpers.TextureTo2DArray(obj.getTexture()); Vector2 collisionPoint = Helpers.TexturesCollide(nonEnterableObjectColours, objectMatrix, movingObjectColours, movingObjectMatrix); if (collisionPoint.X != -1) { collidingObject = obj; currentPlayer.setAdjacantObject(obj); return(true); } } //check for enterable objects. foreach (EnterableMapObject obj in currentMap.getEnterableObjects()) { Vector2 objPositionRelativeToScreen = new Vector2(obj.getLocation().X - currentViewport.X, obj.getLocation().Y - currentViewport.Y); Matrix objectMatrix = Matrix.CreateTranslation(objPositionRelativeToScreen.X, objPositionRelativeToScreen.Y, 0); Color[,] nonEnterableObjectColours = Helpers.TextureTo2DArray(obj.getTexture()); Vector2 collisionPoint = Helpers.TexturesCollide(nonEnterableObjectColours, objectMatrix, movingObjectColours, movingObjectMatrix); if (collisionPoint.X != -1) { Vector2 actualObjectPosition = new Vector2((positionToMoveTo.X + currentViewport.X), positionToMoveTo.Y + currentViewport.Y); if (obj.canEnterFromPosition(actualObjectPosition)) { worldMapPos = new Vector2((obj.getLocation().X + obj.getTexture().Width / 2) - currentViewport.X, obj.getLocation().Y - currentViewport.Y + obj.getTexture().Height); currentPlayer.setPosition(new Vector2(0, 0)); currentMap = obj.getMap(); } return(true); } } if (currentMap.moveWillExitMap(positionToMoveTo, movingObject)) { return(true); } Color[,] exitColours = Helpers.TextureTo2DArray(currentMap.getExitTexture()); Matrix exitMatrix = Matrix.CreateTranslation(currentMap.getExitPos().X, currentMap.getExitPos().Y, 0); Vector2 exitCollisionPoint = Helpers.TexturesCollide(exitColours, exitMatrix, movingObjectColours, movingObjectMatrix); if (exitCollisionPoint.X != -1) { currentPlayer.setPosition(worldMapPos); currentMap = worldMap; return(true); } //check for leaving the map if (positionToMoveTo.X < 0 || positionToMoveTo.Y < 0 || positionToMoveTo.X > (graphics.PreferredBackBufferWidth - currentPlayer.getTexture().Width) || positionToMoveTo.Y > (graphics.PreferredBackBufferHeight - currentPlayer.getTexture().Height)) { return(true); } collidingObject = null; currentPlayer.setAdjacantObject(null); return(false); }