Ejemplo n.º 1
0
        public override void Update(Actor actor)
        {
            GamePadState padState = GamePad.GetState(PlayerIndex.One);

            if (padState.ThumbSticks.Left.Length() > 0)
                actor.Direction += padState.ThumbSticks.Left * new Vector2(1, -1) * this.Weight; // Y needs to be inverted so character moves upwards
        }
Ejemplo n.º 2
0
 public override void Update(Actor actor)
 {
     actor.Direction += this.direction * this.Weight;
 }
Ejemplo n.º 3
0
 public virtual void Update(Actor actor)
 {
 }
Ejemplo n.º 4
0
        public override void Update(Actor actor)
        {
            Vector2 targetDirection = target.Position - actor.Position;
            targetDirection.Normalize(); // unit vector - http://www.fundza.com/vectors/normalize/

            actor.Direction += targetDirection * this.Weight;
        }
Ejemplo n.º 5
0
 public BehavoirSeek(float weight, Actor target)
     : base(weight)
 {
     this.target = target;
 }
Ejemplo n.º 6
0
        public override void Update(Actor actor)
        {
            if (tick == 0) // when time is up, find new direction
                this.direction = Actor.GetRandomDirection();

            tick++;
            tick %= this.changeInterval; // tick goes from 0 to changeInterval

            actor.Direction += this.direction * this.Weight;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            font = Content.Load<Microsoft.Xna.Framework.Graphics.SpriteFont>("Tahoma");

            fpsCounter = new FPSCounter(this, spriteBatch, font);

            // dummy blocks
            Texture2D block1 = Content.Load<Texture2D>("1_block");
            Actor blok1 = new Actor(Color.White, block1, false);
            blok1.Speed = 5f;
            blok1.Position = Actor.GetRandomPosition(ScreenWidth, ScreenHeight);
            blok1.BehaviorList.Add(new BehaviorConstant(0.1f, new Vector2(1f, 0)));
            //blok1.BehaviorList.Add(new BehaviorGamePad(1));
            //blok1.BehaviorList.Add(new BehaviorWander(0.05f, 60));

            Texture2D arrowTexture = Content.Load<Texture2D>("arrow");

            // set up leader actor
            Actor leader = new Actor(new Color(64, 255, 64), arrowTexture);
            leader.Speed = 4;
            leader.DrawDepth = 0f;
            leader.IsPlayer = true;
            leader.Direction = Actor.GetRandomDirection();
            leader.Position = Actor.GetRandomPosition(ScreenWidth, ScreenHeight);
            //leader.BehaviorList.Add(new BehaviorConstant(0.1f, new Vector2(1f, 0)));
            leader.BehaviorList.Add(new BehaviorGamePad(0.5f));
            leader.BehaviorList.Add(new BehaviorWander(0.05f, 60)); // if framerate is 60 FPS, then change direction once every second

            // set up a 10 drone actors
            BehavoirSeek seek = new BehavoirSeek(0.05f, leader);

            for (int i = 0; i < 10000; i++)
            {
                Actor drone = new Actor(Color.White, arrowTexture);
                drone.Color = Actor.GetRandomColor();
                drone.Speed = Actor.GetRandomSpeed(0.7d, 3.5d);
                drone.Direction = Actor.GetRandomDirection();
                drone.Position = Actor.GetRandomPosition(ScreenWidth, ScreenHeight);
                drone.BehaviorList.Add(seek);
                drone.BehaviorList.Add(new BehaviorWander(0.03f, 15));
            }
        }