Esempio n. 1
0
            public Spit(Player target, Vector2 position)
            {
                Size    = new Size(64, 32);
                random  = new Random();
                texture = Game.Instance.Content.Load <Texture2D>("spit");

                body = BodyFactory.CreateRectangle(Game.Instance.World,
                                                   ConvertUnits.ToSimUnits(texture.Height),
                                                   ConvertUnits.ToSimUnits(texture.Width), 1f, this);

                body.Friction      = 0f;
                body.BodyType      = BodyType.Dynamic;
                body.Restitution   = 0f;
                body.LinearDamping = 5f;
                body.Mass          = 1f;
                Position           = new Vector2(position.X, position.Y + Size.Height);

                aliveTime = 1250;

                body.OnCollision += new OnCollisionEventHandler(body_OnCollision);

                targetinComponent = new TargetingComponent <Player>(this);
                targetinComponent.ChangeTarget(target);

                direction = new Vector2(targetinComponent.VelocityToTarget.X * 25, 0);
            }
Esempio n. 2
0
        protected virtual void GetTarget()
        {
            GameplayState gameplayState = Game.Instance.GameStateManager.States
                                          .FirstOrDefault(s => s is GameplayState)
                                          as GameplayState;

            Player nearest = gameplayState.Players.FindNearest <Player>(Position) as Player;

            if (nearest != null)
            {
                targetComponent.ChangeTarget(nearest);
            }

            brain.PopState();
        }
Esempio n. 3
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            animator.Location = Position + new Vector2(0, 256 * animator.Scale / 2);
            animator.Update(gameTime);

            // Haetaan lähin monsteri.
            Monster nearest = Game.Instance.GameObjects.FindNearest <Monster>(Position) as Monster;

            if (nearest != null)
            {
                targetingComponent.ChangeTarget(nearest);
            }

            // Jos monsteri on jo kuollut ja se on vieläkin targettina, clearitaan target.
            if (!Game.Instance.ContainsGameObject(nearest))
            {
                nearest = null;
                targetingComponent.ClearTarget();
            }

            animator.FlipX = Velocity.X < 0;
        }
Esempio n. 4
0
            public Spit(Player target, Vector2 position)
            {
                Size = new Size(64, 32);
                random = new Random();
                texture = Game.Instance.Content.Load<Texture2D>("spit");

                body = BodyFactory.CreateRectangle(Game.Instance.World,
                     ConvertUnits.ToSimUnits(texture.Height),
                     ConvertUnits.ToSimUnits(texture.Width), 1f, this);

                body.Friction = 0f;
                body.BodyType = BodyType.Dynamic;
                body.Restitution = 0f;
                body.LinearDamping = 5f;
                body.Mass = 1f;
                Position = new Vector2(position.X, position.Y + Size.Height);

                aliveTime = 1250;

                body.OnCollision += new OnCollisionEventHandler(body_OnCollision);

                targetinComponent = new TargetingComponent<Player>(this);
                targetinComponent.ChangeTarget(target);

                direction = new Vector2(targetinComponent.VelocityToTarget.X * 25, 0);
            }