Ejemplo n.º 1
0
        //Called when an item is dragged and released
        public void setNewIndex(InventoryItem i)
        {
            Vector2 itemCenter = i.getCenter();

            for (int x = 0; x < items.GetLength(0); x++)
            {
                for (int y = 0; y < items.GetLength(1); y++)
                {
                    //int itemX = (int)(itemCenter.X + 0.5);
                    //int itemY = (int)(itemCenter.Y + 0.5);
                    //Blame merle. He'll fix this later.
                    if (itemRectangles[x, y].Contains(itemCenter) && (items[x, y] == null || (items[x, y] != null && !items[x, y].Equals(i))))
                    {
                        if (items[x, y] == null)
                        {
                            removeItem(i);
                            items[x, y] = i;
                            i.setX(itemRectangles[x, y].X);
                            i.setY(itemRectangles[x, y].Y);
                        }
                        else
                        {
                            if (items[x, y].combineItems(i))
                            {
                                removeItem(i);
                            }
                            else
                            {
                                returnItemToSlot(i);
                            }
                        }

                        return;
                    }
                }
            }

            if (itemCenter.X > 0 && itemCenter.X < inventoryGraphic.Width && itemCenter.Y > 0 && itemCenter.Y < inventoryGraphic.Height)
            {
                returnItemToSlot(i);
            }
            else
            {
                Player    p    = (Player)(Game1.creatures[0]);
                Rectangle rect = p.getHitBox();
                foreach (Platform plat in Game1.platforms)
                {
                    if (p.getX() == plat.getX() && p.getY() == plat.getY())
                    {
                        bool added = plat.addItemToPlatform(i);
                        if (added)
                        {
                            removeItem(i);
                            return;
                        }
                    }
                }
                returnItemToSlot(i);
            }
        }
Ejemplo n.º 2
0
        protected override void Draw(GameTime gameTime)
        {
            Random rnd = new Random();
            Matrix camMatrix;

            if (time < 0)
            {
                camMatrix = Matrix.CreateTranslation(-player.getX() + width / 2, -player.getY() + height / 2, 0);
            }
            else
            {
                time--;
                int xMod;
                int yMod;
                //int xMod = (int)(100 * Math.Sin((time)));
                //int yMod = (int)(100 * Math.Cos((time)));
                xMod      = (int)(rnd.Next(1, 9) * Math.Sin(time));
                yMod      = (int)(rnd.Next(1, 8) * Math.Sin(time));
                camMatrix = Matrix.CreateTranslation(-player.getX() + width / 2 + xMod, -player.getY() + yMod + height / 2, 0);
            }
            spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, camMatrix);

            drawMap(spriteBatch);

            foreach (Item i in items)
            {
                spriteBatch.Draw(i.getGraphic(), new Vector2(i.getX(), i.getY()), i.getImageBoundingRectangle(), Color.White);
            }

            foreach (Creature c in creatures)
            {
                spriteBatch.Draw(c.getGraphic(), new Vector2(c.getX(), c.getY()), c.getImageBoundingRectangle(), Color.White);
            }
            if (Keyboard.GetState().IsKeyDown(Keys.I))
            {
                inventory.drawInventory(spriteBatch);
            }
            spriteBatch.End();

            base.Draw(gameTime);
        }
Ejemplo n.º 3
0
        public int navigateOutOfLight(int currentTileX, int currentTileY)
        {
            int yTiles = Game1.wallArray.GetLength(0);
            int xTiles = Game1.wallArray.GetLength(1);

            bool[,] visited = new bool[yTiles, xTiles];
            Queue <TileNode> q = new Queue <TileNode>();

            TileNode start = new TileNode(currentTileX, currentTileY);

            Player p = getPlayer();
            bool   playerIsObstacle = Game1.darkTileArray[p.getY() / 32, p.getX() / 32] != 0;

            //TileNode end = new TileNode(desiredTileX, desiredTileY);

            if (Game1.darkTileArray[currentTileY, currentTileX] == 0)
            {
                return(-1);
            }

            //navigate out of the light


            q.Enqueue(start);
            visited[start.Y, start.X] = true;

            while (q.Count != 0)
            {
                TileNode next = q.Dequeue();
                if (Game1.darkTileArray[next.Y, next.X] != 0)
                {
                    if (next.X + 1 < xTiles && !visited[next.Y, next.X + 1] && !Game1.wallArray[next.Y, next.X + 1] && !tileIsOccupied(next.X + 1, next.Y, playerIsObstacle))
                    {
                        TileNode temp = new TileNode(next.X + 1, next.Y, next);
                        visited[next.Y, next.X + 1] = true;
                        q.Enqueue(temp);
                    }
                    if (next.X - 1 >= 0 && !visited[next.Y, next.X - 1] && !Game1.wallArray[next.Y, next.X - 1] && !tileIsOccupied(next.X - 1, next.Y, playerIsObstacle))
                    {
                        TileNode temp = new TileNode(next.X - 1, next.Y, next);
                        visited[next.Y, next.X - 1] = true;
                        q.Enqueue(temp);
                    }
                    if (next.Y + 1 < yTiles && !visited[next.Y + 1, next.X] && !Game1.wallArray[next.Y + 1, next.X] && !tileIsOccupied(next.X, next.Y + 1, playerIsObstacle))
                    {
                        TileNode temp = new TileNode(next.X, next.Y + 1, next);
                        visited[next.Y + 1, next.X] = true;
                        q.Enqueue(temp);
                    }
                    if (next.Y - 1 >= 0 && !visited[next.Y - 1, next.X] && !Game1.wallArray[next.Y - 1, next.X] && !tileIsOccupied(next.X, next.Y - 1, playerIsObstacle))
                    {
                        TileNode temp = new TileNode(next.X, next.Y - 1, next);
                        visited[next.Y - 1, next.X] = true;
                        q.Enqueue(temp);
                    }
                }
                else
                {
                    while (!next.Parent.Equals(start))
                    {
                        next = (TileNode)next.Parent;
                    }
                    if (next.X < start.X)
                    {
                        return(0);
                    }
                    if (next.X > start.X)
                    {
                        return(2);
                    }
                    if (next.Y < start.Y)
                    {
                        return(1);
                    }
                    if (next.Y > start.Y)
                    {
                        return(3);
                    }
                }
            }
            return(-1);
        }