Exemplo n.º 1
0
        /// <summary>
        /// Adds a group to the list.
        /// </summary>
        /// <param name="group"><see cref="Group">Group</see> to add to the list.</param>
        /// <param name="assignHandle">Specifies if a handle needs to be generated for the group parameter.</param>
        /// <returns>
        /// If a group already exists with the same name as the instance that is being added the method returns the existing group,
        /// if not it will return the new group.<br />
        /// The methods will automatically add the grouped entities to the document, if they have not been added previously.
        /// </returns>
        internal override Group Add(Group group, bool assignHandle)
        {
            if (list.Count >= MaxCapacity)
            {
                throw new OverflowException(string.Format("Table overflow. The maximum number of elements the table {0} can have is {1}", CodeName, MaxCapacity));
            }
            if (group == null)
            {
                throw new ArgumentNullException(nameof(group));
            }

            // if no name has been given to the group a generic name will be created
            if (group.IsUnnamed && string.IsNullOrEmpty(group.Name))
            {
                group.SetName("*A" + Owner.GroupNamesIndex++, false);
            }

            Group add;

            if (list.TryGetValue(group.Name, out add))
            {
                return(add);
            }

            if (assignHandle || string.IsNullOrEmpty(group.Handle))
            {
                Owner.NumHandles = group.AsignHandle(Owner.NumHandles);
            }

            list.Add(group.Name, group);
            references.Add(group.Name, new List <DxfObject>());
            foreach (EntityObject entity in group.Entities)
            {
                if (entity.Owner != null)
                {
                    // the group and its entities must belong to the same document
                    if (!ReferenceEquals(entity.Owner.Owner.Owner.Owner, Owner))
                    {
                        throw new ArgumentException("The group and their entities must belong to the same document. Clone them instead.");
                    }
                }
                else
                {
                    // only entities not owned by anyone need to be added
                    Owner.AddEntity(entity);
                }
                references[group.Name].Add(entity);
            }

            group.Owner = this;

            group.NameChanged   += Item_NameChanged;
            group.EntityAdded   += Group_EntityAdded;
            group.EntityRemoved += Group_EntityRemoved;

            Owner.AddedObjects.Add(group.Handle, group);

            return(group);
        }
Exemplo n.º 2
0
        public override void Update(GameTime gameTime)
        {
            if (KeyboardUtil.KeyPressed(Keys.H) && Vector2.Distance(this.XandY, Game1.Player.XandY) <= Game1.TileSize * 4)
            {
                Owner.AddEntity(new ItemDrop(Item.Sosda, this.X + (Game1.TileSize / 2), this.Y + (Game1.TileSize / 2)));
            }
            if (KeyboardUtil.KeyPressed(Keys.X) && Vector2.Distance(this.XandY, Game1.Player.XandY) <= Game1.TileSize * 4)
            {
                Owner.AddEntity(new ItemDrop(Item.Sword, this.X + (Game1.TileSize / 2), this.Y + (Game1.TileSize / 2)));
            }
            if (KeyboardUtil.KeyPressed(Keys.P) && Vector2.Distance(this.XandY, Game1.Player.XandY) <= Game1.TileSize * 4)
            {
                Owner.AddEntity(new ItemDrop(Item.doritos, this.X + (Game1.TileSize / 2), this.Y + (Game1.TileSize / 2)));
            }

            base.Update(gameTime);
        }
Exemplo n.º 3
0
        public void Damage(int amount)
        {
            Health -= amount;
            DamageIdiot idiot = new DamageIdiot(amount);

            idiot.X = X;
            idiot.Y = Y - (Game1.TileSize * 2);
            Owner.AddEntity(idiot);
            if (Health <= 0)
            {
                Owner.RemoveEntity(this);
                Game1.PlaySound("enemy_death");
            }
            else
            {
                Game1.PlaySound("enemy_hit");
            }
        }
Exemplo n.º 4
0
        void Group_EntityAdded(Group sender, GroupEntityChangeEventArgs e)
        {
            if (e.Item.Owner != null)
            {
                // the group and its entities must belong to the same document
                if (!ReferenceEquals(e.Item.Owner.Owner.Owner.Owner, Owner))
                {
                    throw new ArgumentException("The group and the entity must belong to the same document. Clone it instead.");
                }
            }
            else
            {
                // only entities not owned by anyone will be added
                Owner.AddEntity(e.Item);
            }

            references[sender.Name].Add(e.Item);
        }
Exemplo n.º 5
0
        public override void Update(GameTime gameTime)
        {
            if (!Game1.Host)
            {
                return;
            }

            if (!Owner.IsTilePassable(Utility.GetTilePos(X, Y)))
            {
                Owner.AddEntity(new Explosion(X, Y - (Game1.TileSize / 2)));
                Owner.RemoveEntity(this);
                return;
            }

            foreach (var i in Owner.GetEntitiesInside(this.GetCollisionBox(), "NPC"))
            {
                if (i is Enemy)
                {
                    int dmg = Game1.Random.Next(5, 16);
                    (i as Enemy).Damage(dmg);
                    Owner.RemoveEntity(this);
                    return;
                }
                else if (i is Stupidmadoka)
                {
                    Owner.AddEntity(new Explosion(i.X, i.Y - (Game1.TileSize / 2)));
                    Owner.AddEntity(new ItemDrop(Item.Groomba, i.X, i.Y));
                    Owner.RemoveEntity(i);
                    Owner.RemoveEntity(this);
                    Game1.PlaySound("madoka_death", 0.2f);
                    return;
                }
            }

            foreach (var i in Owner.GetEntitiesInside(this.GetCollisionBox(), "Solid"))
            {
                if (i is Treeeeeeee)
                {
                    Owner.AddEntity(new Explosion(i.X + (Game1.TileSize / 2), i.Y + (Game1.TileSize / 2)));
                    Owner.AddEntity(new ItemDrop(Item.Log, i.X + (Game1.TileSize / 2), i.Y + (Game1.TileSize / 2)));
                    Owner.RemoveEntity(i);
                    Owner.RemoveEntity(this);
                    return;
                }
            }

            if (Owner.RectCollidesWith(this.GetCollisionBox(), "Solid"))
            {
                Owner.RemoveEntity(this);
                return;
            }

            this.Lifetime -= gameTime.ElapsedGameTime.Milliseconds;
            if (this.Lifetime <= 0)
            {
                Owner.RemoveEntity(this);
                return;
            }
            this.X += (float)Math.Round(this.Speed * Math.Cos(this.Angle));
            this.Y += (float)Math.Round(this.Speed * Math.Sin(this.Angle));
        }
Exemplo n.º 6
0
        public override void Update(GameTime gameTime)
        {
            if (this != Game1.Player)
            {
                return;
            }

            if (KeyboardUtil.KeyPressed(Keys.L))
            {
                weapon = new Gunderwear();
            }

            if (KeyboardUtil.KeyPressed(Keys.H))
            {
                health--;
            }
            if (health < 0)
            {
                health++;
            }

            if (siegeOfMadoka)
            {
                somSpawnTime += gameTime.ElapsedGameTime.Milliseconds;
                if (somSpawnTime >= 1750)
                {
                    var rsm = new Reallystupidmadoka();
                    Owner.AddEntity(rsm);
                    somSpawnTime = 0;
                }
                float shortestDist = Game1.TileSize * 16;
                foreach (var i in Owner.Entities.Values)
                {
                    if (i is Reallystupidmadoka)
                    {
                        float dist = Vector2.Distance(i.XandY, this.XandY);
                        if (dist < shortestDist)
                        {
                            shortestDist = dist;
                        }
                    }
                }
                Music.Volume(Math.Max(0, (1 - (shortestDist / (Game1.TileSize * 14))) * 0.3f));
            }

            if (KeyboardUtil.KeyPressed(Keys.F2))
            {
                var tilePos = Utility.GetTilePos(X, Y);
                Owner.AddEntity(new Stupidmadoka(tilePos.X, tilePos.Y));
            }
            if (KeyboardUtil.KeyPressed(Keys.F3))
            {
                var tilePos = Utility.GetTilePos(X, Y);
                Owner.AddEntity(new Enemy(tilePos.X, tilePos.Y));
            }
            if (KeyboardUtil.KeyPressed(Keys.F4))
            {
                siegeOfMadoka = !siegeOfMadoka;
            }

            int speed = 3;

            if (KeyboardUtil.IsKeyDown(Keys.LeftShift))
            {
                speed = 24;
            }

            Vector2 move = new Vector2(0, 0);

            if (KeyboardUtil.IsKeyDown(Keys.W))
            {
                move.Y -= 1;
            }
            if (KeyboardUtil.IsKeyDown(Keys.S))
            {
                move.Y += 1;
            }
            if (KeyboardUtil.IsKeyDown(Keys.A))
            {
                move.X -= 1;
            }
            if (KeyboardUtil.IsKeyDown(Keys.D))
            {
                move.X += 1;
            }
            if (KeyboardUtil.KeyPressed(Keys.Y))
            {
                Buffs.AddBuff(BuffType.Speed, 1000, 2);
            }
            if (Game1.Player.Inventory[1] == Item.Sword2 && (weapon is Gunderwear))
            {
                weapon = new Crossbow();
            }
            if (Game1.Player.Inventory[1] == Item.Sword && !(weapon is Gunderwear))
            {
                weapon = new Gunderwear();
            }
            if (move.X > 0)
            {
                this.facing = 0;
            }
            if (move.X < 0)
            {
                this.facing = 1;
            }

            if (weapon != null)
            {
                weapon.Update(gameTime);
            }

            move *= (speed * speedMult);
            if (move.X != 0 && move.Y != 0)
            {
                move.X /= (float)Math.Sqrt(2);
                move.Y /= (float)Math.Sqrt(2);
            }

            if (move.X != 0 || move.Y != 0)
            {
                if (this.frameCount == 0)
                {
                    this.frameCount = 32;
                }
                else
                {
                    this.frameCount += 3;
                }
            }
            else
            {
                this.frameCount = 0;
            }
            this.frame = (int)Math.Floor(frameCount / 32.0) % 4;

            if (speed == 24)
            {
                Owner.AddEntity(new FakePlayer(this.X, this.Y, this.facing, this.frame));
            }

            string[] collisions = new string[] { "Solid", "NPC" };
            var      cbox       = GetCollisionBox();

            if (move.X != 0 && move.Y != 0)
            {
                float prevX = this.X;
                float prevY = this.Y;
                if (!Owner.RectCollidesWith(new Rectangle(cbox.X + (int)move.X, cbox.Y, cbox.Width, cbox.Height), collisions))
                {
                    this.X += move.X;
                }
                if (!Owner.RectCollidesWith(new Rectangle(cbox.X, cbox.Y + (int)move.Y, cbox.Width, cbox.Height), collisions))
                {
                    this.Y += move.Y;
                }
                if (Owner.RectCollidesWith(GetCollisionBox(), collisions))
                {
                    this.X = prevX;
                    this.Y = prevY;
                }
            }
            else
            {
                float prevX = this.X;
                float prevY = this.Y;
                this.X += move.X;
                this.Y += move.Y;
                if (Owner.RectCollidesWith(GetCollisionBox(), collisions))
                {
                    this.X = prevX;
                    this.Y = prevY;
                }
            }
        }