コード例 #1
0
ファイル: Sprite.cs プロジェクト: robinsodergren/Archive
        public void Update(GameTime gameTime)
        {
            if (IsDucking)
            {
                CurrentAnimation = DuckAnimation;
            }
            else
            {
                ApplyPhysics(gameTime);

                if (IsOnGround())
                {
                    if (IsMoving()) CurrentAnimation = MoveAnimation;
                    else CurrentAnimation = IdleAnimation;
                }
                else
                {
                    if (!IsFallingAfterJump()) CurrentAnimation = JumpAnimation;
                    else CurrentAnimation = FallAnimation;
                }
            }

            CurrentAnimation.Update(gameTime);
        }
コード例 #2
0
ファイル: Game1.cs プロジェクト: robinsodergren/Archive
        /// <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);

            Texture2D playerTexture = Content.Load<Texture2D>("Images/AstroBoyRunV2");

            SpriteAnimation playerStillAnimation = new SpriteAnimation(new Rectangle(0, 0, 30, 40), new TimeSpan[] {
                TimeSpan.FromMilliseconds(2000),
                TimeSpan.FromMilliseconds(100),
                TimeSpan.FromMilliseconds(100),
                TimeSpan.FromMilliseconds(100)});

            SpriteAnimation playerMoveAnimation = new SpriteAnimation(new Rectangle(4 * 30, 0, 30, 40), new TimeSpan[] {
                TimeSpan.FromMilliseconds(80),
                TimeSpan.FromMilliseconds(80),
                TimeSpan.FromMilliseconds(80),
                TimeSpan.FromMilliseconds(80),
                TimeSpan.FromMilliseconds(80),
                TimeSpan.FromMilliseconds(80),
                TimeSpan.FromMilliseconds(80),
                TimeSpan.FromMilliseconds(80),
                TimeSpan.FromMilliseconds(80),
                TimeSpan.FromMilliseconds(80)});

            // TODO: use this.Content to load your game content here
            _player = new Sprite(playerTexture);

            _player.Position = new Vector2(0, 400);
            _player.Velocity = new Vector2(0, 0);

            _player.IdleAnimation = playerStillAnimation;
            _player.MoveAnimation = playerMoveAnimation;
        }
コード例 #3
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            _backgroundTexture = Content.Load<Texture2D>("Images/Layer0_0");

            Texture2D playerTexture = Content.Load<Texture2D>("Images/AstroBoyRunV2");

            SpriteAnimation playerIdleAnimation = new SpriteAnimation(new Rectangle(0, 0, 30, 40), new TimeSpan[] {
                TimeSpan.FromMilliseconds(2000),
                TimeSpan.FromMilliseconds(100),
                TimeSpan.FromMilliseconds(100),
                TimeSpan.FromMilliseconds(100)});

            SpriteAnimation playerMoveAnimation = new SpriteAnimation(new Rectangle(4 * 30, 0, 30, 40), new TimeSpan[] {
                TimeSpan.FromMilliseconds(80),
                TimeSpan.FromMilliseconds(80),
                TimeSpan.FromMilliseconds(80),
                TimeSpan.FromMilliseconds(80),
                TimeSpan.FromMilliseconds(80),
                TimeSpan.FromMilliseconds(80),
                TimeSpan.FromMilliseconds(80),
                TimeSpan.FromMilliseconds(80),
                TimeSpan.FromMilliseconds(80),
                TimeSpan.FromMilliseconds(80)});

            SpriteAnimation playerJumpAnmation = new SpriteAnimation(new Rectangle(240 + 30, 48, 30, 48), new TimeSpan[] {
                TimeSpan.FromMilliseconds(60),
                TimeSpan.FromMilliseconds(1000)});

            SpriteAnimation playerFallAnmation = new SpriteAnimation(new Rectangle(240 + 30*3, 48, 30, 48), new TimeSpan[] {
                TimeSpan.FromMilliseconds(1000)});

            SpriteAnimation playerDuckAnimation = new SpriteAnimation(new Rectangle(240, 56, 30, 40), new TimeSpan[] {
                TimeSpan.FromMilliseconds(1000)});

            // TODO: use this.Content to load your game content here
            _player = new Sprite(playerTexture);

            _player.Position = new Vector2(0, 320);
            _player.Velocity = new Vector2(0, 0);

            _player.IdleAnimation = playerIdleAnimation;
            _player.MoveAnimation = playerMoveAnimation;
            _player.JumpAnimation = playerJumpAnmation;
            _player.FallAnimation = playerFallAnmation;
            _player.DuckAnimation = playerDuckAnimation;

            _level.Load(_level.CurrentLevel);
        }