Exemple #1
0
        /// <summary>
        /// Drop first item in inventory back into the world
        /// </summary>
        /// <param name="world"></param>
        public void DropItem(World world)
        {
            PointF dropLocation = GetLocationInFrontOfPlayer();
            // Check if item can be dropped on target from dropLocation
            bool isLand = world.getTerraintile(dropLocation).IsWalkable;
            bool hasSolidEntitiesOnTarget = world.checkCollision(this, dropLocation);
            List<Entity> entitiesOnTerrainTile = world.getEntitiesOnTerrainTile(location);
            List<Entity> entitiesOnTargetTerrainTile = world.getEntitiesOnTerrainTile(dropLocation);
            bool hasWaterlilyOnTarget = entitiesOnTargetTerrainTile.Exists(e => e.getSpriteID() == (int) SPRITES.waterlily);

            // If no item exists in inventory or
            //      there is a solid target on dropLocation or
            //      targettile is not land, return
            if (!Inventory.Any() || hasSolidEntitiesOnTarget ||
                (!isLand && !hasWaterlilyOnTarget))
                return;
            // If item is key, lock door
            if (Inventory[0].Entity is Key)
            {
                // If player is standing in a door, cancel action
                if (entitiesOnTerrainTile.Exists(e => e is Door))
                    return;
                world.LockDoor((Key)Inventory[0].Entity);
            }

            // Set droplocation on item
            Inventory[0].Entity.setLocation(dropLocation);
            // Push item in world objects list
            world.getEntities().Add(Inventory[0].Entity);
            // Remove item from inventory
            Inventory.RemoveAt(0);
        }
Exemple #2
0
 /// <summary>
 /// Pickup first item on given tile
 /// </summary>
 /// <param name="w"></param>
 public void PickupItems(World w)
 {
     if (Inventory.Count >= 10) return;
     // Get a list with nonSolid entities on terrain tile and filter for bananas or keys
     List<Entity> EntitiesOnTile =
         w.getEntitiesOnTerrainTile(getLocation(), true)
             .Where(e => e.getType() == ENTITIES.fruit || e.getType() == ENTITIES.key)
             .ToList();
     // If there's nothing in the list of entities, return;
     if (EntitiesOnTile.Count == 0) return;
     // Add first item of list to inventory
     Inventory.Add(new Item(EntitiesOnTile[0]));
     // If key is picked up, unlock door
     if (EntitiesOnTile[0] is Key)
         w.UnlockDoor((Key)EntitiesOnTile[0]);
     // Remove item from world
     w.getEntities().Remove(EntitiesOnTile[0]);
 }