Beispiel #1
0
 public bool containsItem(InventoryItem [,] i, InventoryItem it)
 {
     foreach(InventoryItem itt in i)
     {
         if(it.Equals(itt))
         {
             return true;
         }
     }
     return false;
 }
Beispiel #2
0
        public bool addItemToPlatform(InventoryItem i)
        {
            Type t = i.GetType();

            if (t.IsAssignableFrom(itemType) || itemType.IsAssignableFrom(t))
            {
                setItemOnPlatform(true);
                return true;
            }
            return false;
        }
Beispiel #3
0
 public override bool combineItems(InventoryItem i)
 {
     if(i is BatteryGooI && i.getState())
     {
         batteries = true;
         itemTipGood = "I am bright as the sun";
         itemTipBad = "I am bright as the sun";
         //goodGraphic = Textures.textures["LitLantern"];
         //badGraphic = Textures.textures["LitLantern"];
         return true;
     }
     return false;
 }
Beispiel #4
0
 public void addInventoryItem(InventoryItem ii)
 {
     for (int x = 0; x < items.GetLength(0); x++)
     {
         for (int y = 0; y < items.GetLength(1); y++)
         {
            if (items[x,y] == null)
            {
                 items[x,y] = ii;
                 return;
            }
         }
     }
 }
Beispiel #5
0
        public bool setStoredItem(InventoryItem i)
        {
            if(i == null)
            {
                storedItem = i;
                return true;
            }

            if(storedItem == null)
            {
                storedItem = i;
                storedItem.setX(this.x + 34);
                storedItem.setY(this.y + 34);
                return true;
            }
            return false;
        }
Beispiel #6
0
 public void addInventoryItem(InventoryItem ii)
 {
     int xpos = 3;
     int ypos = 3;
     for (int x = 0; x < items.GetLength(0); x++)
     {
         for (int y = 0; y < items.GetLength(1); y++)
         {
            if (items[x,y] == null)
            {
                 items[x,y] = ii;
                //Set position relative to the inventory
                 items[x, y].setX(xpos);
                 items[x, y].setY(ypos);
                 items[x, y].setState(engine.getWorldState());
                // items[x, y].setHitBox(new Rectangle(xpos + xx, ypos + yy, 32, 32));
                 return;
            }
            xpos += 36;
         }
         ypos += 36;
         xpos = 3;
     }
 }
Beispiel #7
0
 public void setSelectedItem(InventoryItem i, bool b)
 {
     if(b)
     {
         selectedItem = i;
     }
     if(i.isSelected() && !b)
     {
         selectedItem = null;
     }
     i.setSelected(b);
 }
Beispiel #8
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);
            }
        }
Beispiel #9
0
        public void setInventoryItems(InventoryItem[,] inv)
        {
            if(inv == null)
            {
                return;
            }
            for (int x = 0; x < items.GetLength(0); x++)
            {
                for (int y = 0; y < items.GetLength(1); y++)
                {

                        if(items[x,y]!= null && !containsItem(inv,items[x,y]))
                        {
                            //Remove batteries from lamp if necessary
                            if(items[x,y] is LampI)
                            {
                                ((LampI)items[x, y]).setBatteries(false);
                            }

                            setSelectedItem(items[x,y], false);
                            //engine.addItemToCurrentLevel(items[x,y].getItem());
                        }

                        /*
                        if(inv[x,y] == null)
                        {
                            engine.addItemToCurrentLevel(items[x, y].getItem());
                        }
                        else if()
                        */
                    setInventoryItem(inv[x, y],x,y);
                }
            }
        }
Beispiel #10
0
 public void setInventoryItem(InventoryItem ii, int x, int y)
 {
     if (ii == null)
     {
         items[x, y] = null;
         return;
     }
     ii.setX(itemRectangles[x, y].X);
     ii.setY(itemRectangles[x, y].Y);
     items[x, y] = ii;
 }
Beispiel #11
0
 public void returnItemToSlot(InventoryItem i)
 {
     for (int x = 0; x < items.GetLength(0); x++)
     {
         for (int y = 0; y < items.GetLength(1); y++)
         {
             if (i.Equals(items[x, y]))
             {
                 i.setX(itemRectangles[x, y].X);
                 i.setY(itemRectangles[x, y].Y);
                 return;
             }
         }
     }
 }
Beispiel #12
0
        /*
        public bool addItemFromBox(InventoryItem i)
        {
            for (int x = 0; x < items.GetLength(0); x++)
            {
                for (int y = 0; y < items.GetLength(1); y++)
                {
                    Vector2 itemCenter = i.getCenter();
                    itemCenter.X -= this.x;
                    itemCenter.Y -= this.y;

                    if (itemRectangles[x, y].Contains(itemCenter) && (items[x, y] == null || (items[x, y] != null && !items[x, y].Equals(i))))
                    {
                        if (items[x, y] == null)
                        {
                            items[x, y] = i;
                            i.setX(itemRectangles[x, y].X);
                            i.setY(itemRectangles[x, y].Y);
                            return true;
                        }
                        else
                        {
                        }

                    }
                }
            }
            return false;

        }*/
        public void removeItem(InventoryItem i)
        {
            for (int x = 0; x < items.GetLength(0); x++)
            {
                for (int y = 0; y < items.GetLength(1); y++)
                {
                    if(i.Equals(items[x,y]))
                    {
                        items[x, y] = null;
                        return;
                    }
                }
            }
        }
Beispiel #13
0
 //return false if items were not combined
 public virtual bool combineItems(InventoryItem i)
 {
     return false;
 }
Beispiel #14
0
 public virtual void makeInventoryItem()
 {
     inventoryItem = new InventoryItem(state);
 }