예제 #1
0
        public override void Update(GameTime gameTime)
        {
            AnimationControllerComponent animationController = Parent.GetComponent <AnimationControllerComponent>();

            if (Keyboard.GetState().IsKeyDown(Keys.W))
            {
                up = true;
                animationController.PlayAnimation("moveUp");
            }
            else
            {
                up = false;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.D))
            {
                right = true;
                animationController.PlayAnimation("moveRight");
            }
            else
            {
                right = false;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.A))
            {
                left = true;
                animationController.PlayAnimation("moveLeft");
            }
            else
            {
                left = false;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.S))
            {
                down = true;
                animationController.PlayAnimation("moveDown");
            }
            else
            {
                down = false;
            }
        }
예제 #2
0
        public TestGameObject(World manager, GameObject parent) : base(manager, parent)
        {
            Depth = 0.91f;
            Texture2D multiTexture      = ResourceLoader.LoadTexture2D(manager.GraphicsDevice, "character", "Content/character.png");
            Animation moveDownAnimation = new Animation(manager.SpriteBatch, new AnimationFrame(multiTexture, new Rectangle(0, 0, 16, 16)));

            moveDownAnimation.AddFrame(new AnimationFrame(multiTexture, new Rectangle(16, 0, 16, 16)));
            moveDownAnimation.AddFrame(new AnimationFrame(multiTexture, new Rectangle(0, 0, 16, 16)));
            moveDownAnimation.AddFrame(new AnimationFrame(multiTexture, new Rectangle(32, 0, 16, 16)));

            Animation moveUpAnimation = new Animation(manager.SpriteBatch, new AnimationFrame(multiTexture, new Rectangle(144, 0, 16, 16)));

            moveUpAnimation.AddFrame(new AnimationFrame(multiTexture, new Rectangle(160, 0, 16, 16)));
            moveUpAnimation.AddFrame(new AnimationFrame(multiTexture, new Rectangle(144, 0, 16, 16)));
            moveUpAnimation.AddFrame(new AnimationFrame(multiTexture, new Rectangle(176, 0, 16, 16)));

            Animation moveLeftAnimation = new Animation(manager.SpriteBatch, new AnimationFrame(multiTexture, new Rectangle(48, 0, 16, 16)));

            moveLeftAnimation.AddFrame(new AnimationFrame(multiTexture, new Rectangle(48, 0, 16, 16)));
            moveLeftAnimation.AddFrame(new AnimationFrame(multiTexture, new Rectangle(64, 0, 16, 16)));
            moveLeftAnimation.AddFrame(new AnimationFrame(multiTexture, new Rectangle(48, 0, 16, 16)));
            moveLeftAnimation.AddFrame(new AnimationFrame(multiTexture, new Rectangle(80, 0, 16, 16)));

            Animation moveRightAnimation = new Animation(manager.SpriteBatch, new AnimationFrame(multiTexture, new Rectangle(96, 0, 16, 16)));

            moveRightAnimation.AddFrame(new AnimationFrame(multiTexture, new Rectangle(112, 0, 16, 16)));
            moveRightAnimation.AddFrame(new AnimationFrame(multiTexture, new Rectangle(96, 0, 16, 16)));
            moveRightAnimation.AddFrame(new AnimationFrame(multiTexture, new Rectangle(128, 0, 16, 16)));

            Animation stopDownAnimation  = new Animation(manager.SpriteBatch, new AnimationFrame(multiTexture, new Rectangle(0, 0, 16, 16)));
            Animation stopUpAnimation    = new Animation(manager.SpriteBatch, new AnimationFrame(multiTexture, new Rectangle(144, 0, 16, 16)));
            Animation stopLeftAnimation  = new Animation(manager.SpriteBatch, new AnimationFrame(multiTexture, new Rectangle(48, 0, 16, 16)));
            Animation stopRightAnimation = new Animation(manager.SpriteBatch, new AnimationFrame(multiTexture, new Rectangle(96, 0, 16, 16)));
            AnimationControllerComponent animationController = new AnimationControllerComponent(this, "moveUp", moveUpAnimation);

            animationController.AddAnimation("moveDown", moveDownAnimation);
            animationController.AddAnimation("moveLeft", moveLeftAnimation);
            animationController.AddAnimation("moveRight", moveRightAnimation);
            animationController.AddAnimation("stopDown", stopDownAnimation);
            animationController.AddAnimation("stopUp", stopUpAnimation);
            animationController.AddAnimation("stopLeft", stopLeftAnimation);
            animationController.AddAnimation("stopRight", stopRightAnimation);
            animationController.PlayAnimation("moveLeft");

            MoveScript moveSceipt = new MoveScript(this);

            MoveAnimationScript moveAnimationScript = new MoveAnimationScript(this);

            ColliderComponent collider = new ColliderComponent(this, new Vector2(0, 0), new Vector2(16, 8));

            collider.Collider.IsRigid = true;

            WeaponScript weaponScript = new WeaponScript(this);
        }
예제 #3
0
        public TestGameObject(GraphicsDevice graphicsDevice)
        {
            multiTexture = ResourceLoader.LoadTexture2D(graphicsDevice, "character", "Content/character.png");
            AnimationComponent moveDownAnimation = new AnimationComponent(this, new AnimationFrame(multiTexture, new Rectangle(0, 0, 16, 16)));

            moveDownAnimation.AddFrame(new AnimationFrame(multiTexture, new Rectangle(16, 0, 16, 16)));
            moveDownAnimation.AddFrame(new AnimationFrame(multiTexture, new Rectangle(0, 0, 16, 16)));
            moveDownAnimation.AddFrame(new AnimationFrame(multiTexture, new Rectangle(32, 0, 16, 16)));

            AnimationComponent moveUpAnimation = new AnimationComponent(this, new AnimationFrame(multiTexture, new Rectangle(144, 0, 16, 16)));

            moveUpAnimation.AddFrame(new AnimationFrame(multiTexture, new Rectangle(160, 0, 16, 16)));
            moveUpAnimation.AddFrame(new AnimationFrame(multiTexture, new Rectangle(144, 0, 16, 16)));
            moveUpAnimation.AddFrame(new AnimationFrame(multiTexture, new Rectangle(176, 0, 16, 16)));

            AnimationComponent moveLeftAnimation = new AnimationComponent(this, new AnimationFrame(multiTexture, new Rectangle(48, 0, 16, 16)));

            moveLeftAnimation.AddFrame(new AnimationFrame(multiTexture, new Rectangle(48, 0, 16, 16)));
            moveLeftAnimation.AddFrame(new AnimationFrame(multiTexture, new Rectangle(64, 0, 16, 16)));
            moveLeftAnimation.AddFrame(new AnimationFrame(multiTexture, new Rectangle(48, 0, 16, 16)));
            moveLeftAnimation.AddFrame(new AnimationFrame(multiTexture, new Rectangle(80, 0, 16, 16)));

            AnimationComponent moveRightAnimation = new AnimationComponent(this, new AnimationFrame(multiTexture, new Rectangle(96, 0, 16, 16)));

            moveRightAnimation.AddFrame(new AnimationFrame(multiTexture, new Rectangle(112, 0, 16, 16)));
            moveRightAnimation.AddFrame(new AnimationFrame(multiTexture, new Rectangle(96, 0, 16, 16)));
            moveRightAnimation.AddFrame(new AnimationFrame(multiTexture, new Rectangle(128, 0, 16, 16)));

            AnimationComponent stopDownAnimation  = new AnimationComponent(this, new AnimationFrame(multiTexture, new Rectangle(0, 0, 16, 16)));
            AnimationComponent stopUpAnimation    = new AnimationComponent(this, new AnimationFrame(multiTexture, new Rectangle(144, 0, 16, 16)));
            AnimationComponent stopLeftAnimation  = new AnimationComponent(this, new AnimationFrame(multiTexture, new Rectangle(48, 0, 16, 16)));
            AnimationComponent stopRightAnimation = new AnimationComponent(this, new AnimationFrame(multiTexture, new Rectangle(96, 0, 16, 16)));

            animationController = new AnimationControllerComponent(this, "moveUp", moveUpAnimation);
            animationController.AddAnimation("moveDown", moveDownAnimation);
            animationController.AddAnimation("moveLeft", moveLeftAnimation);
            animationController.AddAnimation("moveRight", moveRightAnimation);

            animationController.AddAnimation("stopDown", stopDownAnimation);
            animationController.AddAnimation("stopUp", stopUpAnimation);
            animationController.AddAnimation("stopLeft", stopLeftAnimation);
            animationController.AddAnimation("stopRight", stopRightAnimation);

            animationController.PlayAnimation("moveLeft");

            TransformComponent transform = new TransformComponent(new Vector2(100, 1), new Vector2(1, 1), 0);

            AddComponent(transform);
            AddComponent(animationController);
        }