public void AddAnimation(Animation animation)
 {
     if (CurrentAnimation == null)
     {
         CurrentAnimation = animation;
     }
     Animations[animation.Name] = animation;
 }
 public void AddOrientedAnimation(Animation leftAnimation, Animation rightAnimation)
 {
     AddOrientedAnimation(new OrientedAnimation(leftAnimation, rightAnimation));
 }
 public void AddOrientedAnimation(Animation animation)
 {
     AddOrientedAnimation(new OrientedAnimation(animation));
 }
 public OrientedAnimation(Animation leftAnimation)
 {
     LeftAnimation = leftAnimation;
     RightAnimation = null;
     CurrentOrientation = Orientation.Left;
     Name = leftAnimation.Name;
 }
 public OrientedAnimation(Animation leftAnimation, Animation rightAnimation)
 {
     RightAnimation = rightAnimation;
     LeftAnimation = leftAnimation;
     CurrentOrientation = Orientation.Left;
     Name = leftAnimation.Name + "," + rightAnimation.Name;
 }
Example #6
0
        public Person(string _tag, Vector3 position,
            ComponentManager componentManager,
            ContentManager content,
            GraphicsDevice graphics,
            string spritesheet)
            : base(componentManager, "person", componentManager.RootComponent, Matrix.CreateTranslation(position),  new Vector3(0.5f, 1.0f, 0.5f),
            new Vector3(0.0f, -0.3f, 0.0f),  1.0f, 1.0f, 0.999f, 0.999f)
        {
            OrientWithVelocity = true;
            Texture2D sprites = content.Load<Texture2D>(spritesheet);
            tag = _tag;
            Tags.Add(tag);
            string name = "person";
            OrientWithVelocity = true;
            this.team = null;
            Score = 0.0f;
            AnimationState = new Dictionary<string,string>();
            IsSleeping = false;

            List<Point> offsets = new List<Point>();
            offsets.Add(new Point(0, 0));

            Point offset = offsets[RandomHelper.random.Next(0, offsets.Count)];

            List<Point> rightFrames = new List<Point>();
            rightFrames.Add(new Point(1 + offset.X, 0 + offset.Y));
            rightFrames.Add(new Point(2 + offset.X, 0 + offset.Y));
            rightFrames.Add(new Point(3 + offset.X, 0 + offset.Y));
            rightFrames.Add(new Point(4 + offset.X, 0 + offset.Y));

            Animation walkRight = new Animation(graphics, sprites, name + "_walk_right", 32, 32, rightFrames, true, Color.White, 10.0f, 0.8f, 1, true);

            List<Point> leftFrames = new List<Point>();
            leftFrames.Add(new Point(1 + offset.X, 0 + offset.Y));
            leftFrames.Add(new Point(2 + offset.X, 0 + offset.Y));
            leftFrames.Add(new Point(3 + offset.X, 0 + offset.Y));
            leftFrames.Add(new Point(4 + offset.X, 0 + offset.Y));

            Animation walkLeft = new Animation(graphics, sprites, name + "_walk_left", 32, 32, leftFrames, true, Color.White, 10.0f, 0.8f, 1, false);

            List<Point> rightFramesIdle = new List<Point>();
            rightFramesIdle.Add(new Point(0 + offset.X, 0 + offset.Y));

            Animation idleRight = new Animation(graphics, sprites, name + "_idle_right", 32, 32, rightFramesIdle, true, Color.White, 2.0f, 0.8f, 1, true);

            List<Point> leftFramesIdle = new List<Point>();
            leftFramesIdle.Add(new Point(0 + offset.X, 0 + offset.Y));

            Animation idleLeft = new Animation(graphics, sprites, name + "_idle_left", 32, 32, leftFramesIdle, true, Color.White, 2.0f, 0.8f, 1, false);

            walkLeft.Play();
            walkRight.Play();
            idleLeft.Play();
            idleRight.Play();

            Matrix spriteMatrix = Matrix.Identity;
            image = new OrientableBillboardSpriteComponent(componentManager, "idlesprite", this, spriteMatrix, sprites);
            OrientedAnimation idle = new OrientedAnimation(idleLeft, idleRight);
            image.AddOrientedAnimation(idle);
            AnimationState["idle"] = idle.Name;
            OrientedAnimation walk = new OrientedAnimation(walkLeft, walkRight);
            image.AddOrientedAnimation(walk);
            AnimationState["walk"] = walk.Name;

            Matrix shadowTransform = Matrix.CreateRotationX((float)Math.PI * 0.5f);
            //shadowTransform.Translation = new Vector3(0.0f, -0.31f, 0.0f);
            shadow = new ShadowComponent(componentManager, "shadow", this, shadowTransform, content.Load<Texture2D>("shadowcircle"));
            shadow.OrientsToCamera = false;
            List<Point> shP = new List<Point>();
            shP.Add(new Point(0, 0));
            Animation shadowAnimation = new Animation(graphics, content.Load<Texture2D>("shadowcircle"), "sh", 32, 32, shP, false, Color.White, 1, 0.7f, 0.7f, false);
            shadow.AddAnimation(shadowAnimation);
            shadowAnimation.Play();
            shadow.SetCurrentAnimation("sh");

            Matrix teamTransform = Matrix.CreateRotationX((float)Math.PI * 0.5f);
            //shadowTransform.Translation = new Vector3(0.0f, -0.31f, 0.0f);
            ShadowComponent team = new ShadowComponent(componentManager, "team", this, shadowTransform, content.Load<Texture2D>("circle"));
            team.OrientsToCamera = false;
            List<Point> circleP = new List<Point>();
            circleP.Add(new Point(0, 0));
            Animation circleAnimation = new Animation(graphics, content.Load<Texture2D>("circle"), "teamcircle", 32, 32, shP, false, Color.Red, 1, 0.9f, 0.9f, false);
            team.AddAnimation(circleAnimation);
            circleAnimation.Play();
            team.SetCurrentAnimation("teamcircle");
            teamCircle = team;

            Tags.Add("Walker");

            velocityController = new VelocityController(this);
            velocityController.IsTracking = true;
        }