Exemplo n.º 1
0
        /// <summary>
        /// Attempt to position the given item at the given index. If the space is occupied already it will fail.
        /// </summary>
        /// <param name="item">The item to be positioned.</param>
        /// <param name="x">The x index of the tile to position at.</param>
        /// <param name="y">The y index of the tile to position at.</param>
        /// <returns>True if successfully positioned, false if the space was occupied.</returns>
        public bool AttemptToPositionAt(GridItem item, int x, int y)
        {
            if (!InBounds(x, y) || this.tiles[x][y].HasInhabitant)
            {
                return(false); // Space occupied
            }

            this.tiles[x][y].AddInhabitant(item);
            item.SetInitialScreenPosition(x * Tile.TILE_SIZE, y * Tile.TILE_SIZE, Tile.TILE_SIZE, Tile.TILE_SIZE);

            // Add the item to the simulation and set up appropriate event handlers
            if (item.GetType() == typeof(Organism))
            {
                var organism = (Organism)item;
                organism.DeathOccurred += OrganismDeathHandler;
                Organisms.Add(organism);
            }
            else if (item.GetType() == typeof(Food))
            {
                var food = (Food)item;
                food.DeathOccurred += FoodEatenHandler;
                Foods.Add(food);
            }



            return(true); // Successfully positioned
        }
Exemplo n.º 2
0
 // Pre push
 public override void PrePush(GridItem byItem, Direction inDirection)
 {
     base.PrePush(byItem, inDirection);
     if (data.isWinProp && byItem.GetType() == typeof(GridCharacter))
     {
         GridCharacter c = (GridCharacter)byItem;
         GameManager.instance.WinStage(c.playerIndex);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// This updates the context menu based on the current property grid
        /// state before it is displayed.
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void ctxPropGrid_Opening(object sender, CancelEventArgs e)
        {
            GridItem item      = base.SelectedGridItem;
            Type     type      = item.GetType();
            object   component = type.GetProperty("Instance",
                                                  BindingFlags.NonPublic | BindingFlags.Public |
                                                  BindingFlags.Instance).GetValue(item, BindingFlags.GetProperty,
                                                                                  null, null, null);

            miReset.Enabled = (item.PropertyDescriptor != null &&
                               item.PropertyDescriptor.CanResetValue(component));
            miShowDescription.Checked = this.HelpVisible;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a queue of locations to check whether the items intersect
        /// </summary>
        /// <param name="xApprox">Reference the approximate x value the character is currently in</param>
        /// <param name="yApprox">Reference the approximate y value the character is currently in</param>
        /// <param name="xcheck">The x value to check either a fixed value (-1 or 1) or i from a for loop</param>
        /// <param name="ycheck">The y value to check either a fixed value (-1 or 1) or i from a for loop</param>
        /// <returns>A queue of items in that direction that need checking for intersection</returns>
        private static Queue <GridItem> QueuingLocationsToCheck(ref int xApprox, ref int yApprox, int xcheck, int ycheck)
        {
            Queue <GridItem> queue = new Queue <GridItem>(3);
            //If xCheck is 0 then it should be replaced by i, otherwise yCheck should shouldnt
            bool xCheckIsi = xcheck == 0;

            for (int i = -1; i <= 1; i++)
            {
                //If xcheck is the variable value (i.e. the direction you want to check for multiple items, e.g. if you're checking up you want to check for up,
                //up-left, up-right etc so xcheck changes, same with down). Otherwise ycheck is the variable (when moving left or right)
                switch (xCheckIsi)
                {
                case true:
                    xcheck = i;
                    break;

                case false:
                    ycheck = i;
                    break;
                }

                //If outside the _gridManager then stop looking
                if (xApprox + xcheck < 0 || yApprox + ycheck < 0 || xApprox + xcheck > (Constants.GRID_TILES_XY - 1) ||
                    yApprox + ycheck > (Constants.GRID_TILES_XY - 1))
                {
                    continue;
                }
                //Check for right-above, right and right-below, and if they are non-walkable or they are a closed exit
                GridItem item = _gridManager.GridItems[yApprox + ycheck, xApprox + xcheck];
                if (item.GetType() == typeof(NonWalkable) || (item.GetType() == typeof(Exitable) && !(item as Exitable).CanExit))
                {
                    //Then add to the queue
                    queue.Enqueue(_gridManager.GridItems[yApprox + ycheck, xApprox + xcheck]);
                }
            }

            return(queue);
        }
 private static object GetBindableObject(/*PropertyGrid propertyGrid,*/ GridItem gridItem)
 {
     if (gridItem != null)
     {
         if (gridItem.Value?.GetType().GetCustomAttributes(false).OfType <BindingSurrogateAttribute>().Any() ?? false)
         {
             return(gridItem.Value);
         }
         if (gridItem.Parent?.Value != null)
         {
             return(gridItem.Parent.Value);
         }
     }
     return((gridItem.GetType().GetProperty("OwnerGrid")?.GetValue(gridItem) as PropertyGrid)?.SelectedObject);
 }
Exemplo n.º 6
0
        private TimbreBase[] findTimbre(GridItem item)
        {
            List <TimbreBase> il = new List <TimbreBase>();

            if (item == null)
            {
                return(il.ToArray());
            }

            var instance = item.GetType().GetProperty("Instance").GetValue(item, null);

            if (instance.GetType() == typeof(object[]))
            {
                var objs = instance as object[];
                foreach (var o in objs)
                {
                    var inst = o as TimbreBase;
                    if (inst != null)
                    {
                        il.Add(inst);
                    }
                }
            }
            {
                var inst = instance as TimbreBase;
                if (inst != null)
                {
                    il.Add(inst);
                }
            }
            {
                var array = instance as Array;
                if (array != null && array.GetValue(0) is TimbreBase)
                {
                    il.Add((TimbreBase)array.GetValue(0));
                }
            }
            if (il.Count != 0)
            {
                return(il.ToArray());
            }

            return(findTimbre(item.Parent));
        }
Exemplo n.º 7
0
        private List <object> ListGridItemValues(GridItem gridItem)
        {
            List <object> list = new List <object>();

            try
            {
                FieldInfo field = gridItem.GetType().GetField("objs", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                if (field != null)
                {
                    object[] objs = (object[])field.GetValue(gridItem);
                    for (int i = 0; i < objs.Length; i++)
                    {
                        object obj = objs[i];
                        EntityCustomTypeDescriptor entityCustomTypeDescriptor = obj as EntityCustomTypeDescriptor;
                        if (entityCustomTypeDescriptor != null)
                        {
                            obj = entityCustomTypeDescriptor.Entity;
                        }
                        list.Add(obj);
                    }
                }
            }
            catch { }

            if (list.Count == 0)
            {
                EntityPropertyDescriptor entityPropertyDescriptor = gridItem.PropertyDescriptor as EntityPropertyDescriptor;
                if (entityPropertyDescriptor != null)
                {
                    list.Add(entityPropertyDescriptor.Entity);
                }
            }

            if (list.Count == 0)
            {
                object value = gridItem.Parent.Value;
                if (!(value is System.Collections.ICollection))
                {
                    list.Add(gridItem.Parent.Value);
                }
            }
            return(list);
        }
Exemplo n.º 8
0
    // Be stunned
    public override void PrePush(GridItem byItem, Direction inDirection)
    {
        base.PrePush(byItem, inDirection);
        if (byItem.GetType() == typeof(GridCharacter) && byItem != this)
        {
            if (characterState != GridCharacterState.Stunned && _stunElapsed >= stunTime + stunInvulnerable)
            {
                _stunElapsed = 0f;
                MusicManager.PlaySFX(stunClip);
                _curDizzy = InstantiateEffect(dizzyEffect, tile.transform.position, dizzyEffectOffset, inDirection, false);
                _curDizzy.SetParent(transform);

                // Hit
                if (onHit != null)
                {
                    onHit(this, (GridCharacter)byItem);
                }

                // Set state
                SetState(GridCharacterState.Stunned);
            }
        }
    }