示例#1
0
    //-------------------------------------------------------------------------
    private void guardDialog()
    {
        // THIS FUNCTION HANDLES THE BEGINNING OF THE SCENE WHERE THE GUARD
        // IS TALKING TO THE PLAYER

        // while talking the guard is not patrolling
        Patrolling.isPatrolling = false;

        // the guard says the following ...
        string text  = "Don't move from that spot.";
        string text2 = "If you do, you will regret it. I promise you that.";

        if (!guardTextStarted_)
        {
            manager.Enable(false);
            BackgroundMusic.SetVolume(0.5f);
            guardTextStarted_ = true;
            Color red = new Color(1.0f, 0.0f, 0.0f, 1.0f);
            DialogField.Display(text, red, 0.0f, 2.0f);
            DialogField.Display(text2, red, 2.5f, 4.5f);
        }

        // switch to patrolling state
        if (time_ >= 24.7f)
        {
            GuardAnimation.Play(1.0f, 0);
            manager.Enable(true);
            BackgroundMusic.SetVolume(0.5f);
            Patrolling.isPatrolling = true;
            updateHandler_          = guardPatrolling;
        }
    }
示例#2
0
        public Trex(Texture2D spriteSheet, Vector2 position)
        {
            Position = position;
            _idleBackgroundSprite = new Sprite(spriteSheet, TREX_IDLE_BACKGROUNG_SPRITE_POS_X, TREX_IDLE_BACKGROUNG_SPRITE_POS_Y, TREX_DEFAULT_SPRITE_WIDTH, TREX_DEFAULT_SPRITE_HEIGHT);
            State = TrexState.Idle;

            _random = new Random();


            _idleSprite      = new Sprite(spriteSheet, TREX_DEFAULT_SPRITE_POS_X, TREX_DEFAULT_SPRITE_POS_Y, TREX_DEFAULT_SPRITE_WIDTH, TREX_DEFAULT_SPRITE_HEIGHT);
            _idleBlinkSprite = new Sprite(spriteSheet, TREX_DEFAULT_SPRITE_POS_X + TREX_DEFAULT_SPRITE_WIDTH, TREX_DEFAULT_SPRITE_POS_Y, TREX_DEFAULT_SPRITE_WIDTH, TREX_DEFAULT_SPRITE_HEIGHT);

            CreateBlinkAnimation();
            _blinkAnimation.Play()
        }
示例#3
0
        public void UpdateAnimation()
        {
            var inputState = GetInputState();

            if (inputState == InputState.None)
            {
                if (_oldInputState != InputState.None)
                {
                    SpriteAnimation.Stop(_characterSpriteComponent);

                    _characterSpriteSheet.CurrentFrame = _animationFrames.FirstOrDefault(i => _oldInputState.HasFlag(i.Key)).Value.First();

                    _oldInputState = InputState.None;
                }
            }
            else
            {
                if (_oldInputState != inputState)
                {
                    SpriteAnimation.Play(_characterSpriteComponent, _animationFrames.FirstOrDefault(i => inputState.HasFlag(i.Key)).Value, AnimationRepeatMode.LoopInfinite, 15);
                }
            }

            _oldInputState = inputState;
        }
        void PlayRun()
        {
            var provider = (SpriteFromSheet)playerSprite.SpriteProvider;

            provider.Sheet = runGroup;
            SpriteAnimation.Play(playerSprite, 0, provider.Sheet.Sprites.Count - 1, AnimationRepeatMode.LoopInfinite, 12);
        }
示例#5
0
        public override void Start()
        {
            var spriteComponent = Entity.Get <SpriteComponent>();
            var sheet           = ((SpriteFromSheet)spriteComponent.SpriteProvider).Sheet;

            SpriteAnimation.Play(spriteComponent, sheet.FindImageIndex("active0"), sheet.FindImageIndex("active1"), AnimationRepeatMode.LoopInfinite, 2);
        }
        public override void Start()
        {
            // Initialization of the script.
            SpriteComponent = Entity.Get <SpriteComponent>();

            SpriteAnimation.Play(SpriteComponent, 0, SpriteComponent.SpriteProvider.SpritesCount - 1, AnimationRepeatMode.PlayOnce);
        }
示例#7
0
        public void Update(GameTime gameTime)
        {
            if (State == TrexState.Idle)
            {
                if (!_blinkAnimation.IsPlaying)
                {
                    CreateBlinkAnimation();
                    _blinkAnimation.Play();
                }
                _blinkAnimation.Update(gameTime);
            }
            else if (State == TrexState.Jumping || State == TrexState.Falling)
            {
                Position           = new Vector2(Position.X, Position.Y + _verticalVelocity * (float)gameTime.ElapsedGameTime.TotalSeconds);
                _verticalVelocity += GRAVITY * (float)gameTime.ElapsedGameTime.TotalSeconds;

                if (_verticalVelocity >= 0)
                {
                    State = TrexState.Falling;
                }


                if (Position.Y >= _startPosY)
                {
                    Position          = new Vector2(Position.X, _startPosY);
                    _verticalVelocity = 0;
                    State             = TrexState.Idle;
                }
            }
        }
示例#8
0
        public Dino(Texture2D spritesheet, Vector2 position, SoundEffect jumpSound)
        {
            Position = position;

            _startPosY = Position.Y;

            _idleDinoBackgroundSprite = new Sprite(spritesheet, IDLE_BACKGROUND_SPRITE_X, IDLE_BACKGROUND_SPRITE_Y, DINO_SPRITE_WIDTH, DINO_SPRITE_HEIGHT);
            State = DinoState.Idle;

            _jumpSound = jumpSound;

            _random = new Random();

            _idleSprite      = new Sprite(spritesheet, DINO_SPRITE_X, DINO_SPRITE_Y, DINO_SPRITE_WIDTH, DINO_SPRITE_HEIGHT);
            _idleBlinkSprite = new Sprite(spritesheet, DINO_SPRITE_X + DINO_SPRITE_WIDTH, DINO_SPRITE_Y, DINO_SPRITE_WIDTH, DINO_SPRITE_HEIGHT);

            _blinkAnimation = new SpriteAnimation();
            CreateBlinkAnimation();
            _blinkAnimation.Play();

            _runAnimation = new SpriteAnimation();
            _runAnimation.AddFrame(new Sprite(spritesheet, DINO_RUNNING_SPRITE_ONE_X, DINO_RUNNING_SPRITE_ONE_Y, DINO_SPRITE_WIDTH, DINO_SPRITE_HEIGHT), 0);
            _runAnimation.AddFrame(new Sprite(spritesheet, DINO_RUNNING_SPRITE_TWO_X, DINO_RUNNING_SPRITE_TWO_Y, DINO_SPRITE_WIDTH, DINO_SPRITE_HEIGHT), RUN_ANIMATION_FRAME_DURATION);
            _runAnimation.AddFrame(_runAnimation[0].Sprite, RUN_ANIMATION_FRAME_DURATION * 2);
            _runAnimation.Play();

            _duckAnimation = new SpriteAnimation();
            _duckAnimation.AddFrame(new Sprite(spritesheet, DINO_DUCKING_SPRITE_ONE_X, DINO_DUCKING_SPRITE_ONE_Y, DINO_DUCKING_SPRITE_WIDTH, DINO_SPRITE_HEIGHT), 0);
            _duckAnimation.AddFrame(new Sprite(spritesheet, DINO_DUCKING_SPRITE_ONE_X + DINO_DUCKING_SPRITE_WIDTH, DINO_DUCKING_SPRITE_ONE_Y, DINO_DUCKING_SPRITE_WIDTH, DINO_SPRITE_HEIGHT), RUN_ANIMATION_FRAME_DURATION);
            _duckAnimation.AddFrame(_duckAnimation[0].Sprite, RUN_ANIMATION_FRAME_DURATION * 2);
            _duckAnimation.Play();
        }
示例#9
0
        public TRex(Texture2D spriteSheet, Vector2 position, SoundEffect jumpSound)
        {
            Position              = position;
            _jumpSound            = jumpSound;
            _idleBackgroundSprite = new Sprite(spriteSheet, TREX_IDLE_BACKGROUND_SPRITE_POS_X, TREX_IDLE_BACKGROUND_SPRITE_POS_Y, TREX_DEFAULT_SPRITE_WIDTH, TREX_DEFAULT_SPRITE_HEIGHT);
            State            = TRexState.Idle;
            _random          = new Random();
            _idleSprite      = new Sprite(spriteSheet, TREX_DEFAULT_SPRITE_POS_X, TREX_DEFAULT_SPRITE_POS_Y, TREX_DEFAULT_SPRITE_WIDTH, TREX_DEFAULT_SPRITE_HEIGHT);
            _idleBlinkSprite = new Sprite(spriteSheet, TREX_DEFAULT_SPRITE_POS_X + TREX_DEFAULT_SPRITE_WIDTH, TREX_DEFAULT_SPRITE_POS_Y, TREX_DEFAULT_SPRITE_WIDTH, TREX_DEFAULT_SPRITE_HEIGHT);

            _blinkAnimation = new SpriteAnimation();
            CreateBlinkAnimation();
            _blinkAnimation.Play();
            _startPosY    = position.Y;
            _runAnimation = new SpriteAnimation();
            _runAnimation.AddFrame(new Sprite(spriteSheet, TREX_RUNNING_SPRITE_ONE_POS_X, TREX_RUNNING_SPRITE_ONE_POS_Y, TREX_DEFAULT_SPRITE_WIDTH, TREX_DEFAULT_SPRITE_HEIGHT), 0);
            _runAnimation.AddFrame(new Sprite(spriteSheet, TREX_RUNNING_SPRITE_ONE_POS_X + TREX_DEFAULT_SPRITE_WIDTH, TREX_RUNNING_SPRITE_ONE_POS_Y, TREX_DEFAULT_SPRITE_WIDTH, TREX_DEFAULT_SPRITE_HEIGHT), RUN_ANIMATION_FRAME_LENGTH);
            _runAnimation.AddFrame(_runAnimation[0].Sprite, RUN_ANIMATION_FRAME_LENGTH * 2);
            _runAnimation.Play();

            _duckAnimation = new SpriteAnimation();
            _duckAnimation.AddFrame(new Sprite(spriteSheet, TREX_DUCKING_SPRITE_ONE_POS_X, TREX_DUCKING_SPRITE_ONE_POS_Y, TREX_DUCKING_SPRITE_WIDTH, TREX_DEFAULT_SPRITE_HEIGHT), 0);
            _duckAnimation.AddFrame(new Sprite(spriteSheet, TREX_DUCKING_SPRITE_ONE_POS_X + TREX_DUCKING_SPRITE_WIDTH, TREX_DUCKING_SPRITE_ONE_POS_Y, TREX_DUCKING_SPRITE_WIDTH, TREX_DEFAULT_SPRITE_HEIGHT), RUN_ANIMATION_FRAME_LENGTH);
            _duckAnimation.AddFrame(_duckAnimation[0].Sprite, RUN_ANIMATION_FRAME_LENGTH * 2);
            _duckAnimation.Play();

            _deadSprite = new Sprite(spriteSheet, TREX_DEAD_SPRITE_POS_X, TREX_DEAD_SPRITE_POS_Y, TREX_DEFAULT_SPRITE_WIDTH, TREX_DEFAULT_SPRITE_HEIGHT);

            IsAlive = true;
        }
示例#10
0
        public void TestPauseResume()
        {
            var spriteComp = CreateSpriteComponent(15);

            SpriteAnimation.Play(spriteComp, 0, 10, AnimationRepeatMode.PlayOnce, 1);
            SpriteAnimation.Pause(spriteComp);
            SpriteAnimation.Draw(new GameTime(TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(2)));

            Assert.Equal(0, spriteComp.CurrentFrame);

            SpriteAnimation.Play(spriteComp, 0, 10, AnimationRepeatMode.PlayOnce, 1);
            SpriteAnimation.Draw(new GameTime(TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(2)));

            Assert.Equal(2, spriteComp.CurrentFrame);

            SpriteAnimation.Pause(spriteComp);
            SpriteAnimation.Draw(new GameTime(TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(2)));

            Assert.Equal(2, spriteComp.CurrentFrame);

            SpriteAnimation.Resume(spriteComp);
            SpriteAnimation.Draw(new GameTime(TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(2)));

            Assert.Equal(4, spriteComp.CurrentFrame);
        }
示例#11
0
        public TRex(Texture2D spritesheet, Vector2 position, SoundEffect jumpSound)
        {
            this.Position   = position;
            this._JumpSound = jumpSound;
            _IdleBackGround = new Sprite(spritesheet, _IdleBAckGround_posX, _IdleBAckGround_posY, TrexWidth, TrexHeiht);
            State           = TrexState.idle;
            _random         = new Random();

            _IdleSprit       = new Sprite(spritesheet, Trexpos, TrexYpos, TrexWidth, TrexHeiht);
            _IdleBlinkSprite = new Sprite(spritesheet, Trexpos + TrexWidth, TrexYpos, TrexWidth, TrexHeiht);
            _BlinkAnimation  = new SpriteAnimation();

            CreateBlinkAnimation();
            _BlinkAnimation.Play();

            _startposy = Position.Y;


            _runAnimation = new SpriteAnimation();

            _runAnimation.AddFrame(new Sprite(spritesheet, Trexpos + TrexWidth * 2, TrexYpos, TrexWidth, TrexHeiht), 0);
            _runAnimation.AddFrame(new Sprite(spritesheet, Trexpos + TrexWidth * 3, TrexYpos, TrexWidth, TrexHeiht), Run_Length);
            _runAnimation.AddFrame(_runAnimation[0].Sprite, Run_Length * 2);

            _runAnimation.Play();
            _runAnimation.ShouldLoop = true;

            _DuckingAnimation = new SpriteAnimation();
            _DuckingAnimation.AddFrame(new Sprite(spritesheet, Trex_Ducking_X, TrexYpos, TREX_DUCKING_WITDH, TrexHeiht), 0);
            _DuckingAnimation.AddFrame(new Sprite(spritesheet, Trex_Ducking_X + TREX_DUCKING_WITDH, TrexYpos, TREX_DUCKING_WITDH, TrexHeiht), Run_Length);
            _DuckingAnimation.AddFrame(_DuckingAnimation[0].Sprite, Run_Length * 2);

            _DuckingAnimation.Play();
        }
示例#12
0
 public void Explode()
 {
     IsAlive = false;
     enemySpriteComponent.SpriteProvider = new SpriteFromSheet {
         Sheet = spriteSheet
     };
     SpriteAnimation.Play(enemySpriteComponent, spriteSheet.FindImageIndex("blowup0"), spriteSheet.FindImageIndex("blowup7"), AnimationRepeatMode.LoopInfinite, enemyBlowupFps);
     enemyAge = enemyTimeToLive - 0.3f;
 }
示例#13
0
 public void Explode()
 {
     IsAlive = false;
     enemySpriteComponent.SpriteProvider = new SpriteFromSheet {
         Sheet = enemyExplosionSprite
     };
     SpriteAnimation.Play(enemySpriteComponent, 0, enemySpriteComponent.SpriteProvider.SpritesCount - 1, AnimationRepeatMode.LoopInfinite, enemyBlowupFps);
     enemyAge = enemyTimeToLive - 0.3f;
 }
示例#14
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            // sets the virtual resolution
            areaSize = new Vector2(GraphicsDevice.Presenter.BackBuffer.Width, GraphicsDevice.Presenter.BackBuffer.Height);

            // Creates the camera
            CameraComponent.UseCustomProjectionMatrix = true;
            CameraComponent.ProjectionMatrix          = Matrix.OrthoRH(areaSize.X, areaSize.Y, -2, 2);

            // Load assets
            groundSprites = Content.Load <SpriteSheet>("GroundSprite");
            ballSprite1   = Content.Load <SpriteSheet>("BallSprite1");
            ballSprite2   = Content.Load <SpriteSheet>("BallSprite2");
            ball          = new Entity {
                new SpriteComponent {
                    SpriteProvider = new SpriteFromSheet {
                        Sheet = Content.Load <SpriteSheet>("BallSprite1")
                    }
                }
            };

            // create fore/background entities
            foreground = new Entity();
            background = new Entity();
            foreground.Add(new SpriteComponent {
                SpriteProvider = new SpriteFromSheet {
                    Sheet = groundSprites, CurrentFrame = 1
                }
            });
            background.Add(new SpriteComponent {
                SpriteProvider = new SpriteFromSheet {
                    Sheet = groundSprites, CurrentFrame = 0
                }
            });

            Scene.Entities.Add(ball);
            Scene.Entities.Add(foreground);
            Scene.Entities.Add(background);

            spriteComponent    = ball.Get <SpriteComponent>();
            transformComponent = ball.Get <TransformComponent>();

            var decorationScalings = new Vector3(areaSize.X, areaSize.Y, 1);

            background.Get <TransformComponent>().Scale    = decorationScalings;
            foreground.Get <TransformComponent>().Scale    = decorationScalings / 2;
            background.Get <TransformComponent>().Position = new Vector3(0, 0, -1);
            foreground.Get <TransformComponent>().Position = new Vector3(0, 0, 1);

            SpriteAnimation.Play(spriteComponent, 0, spriteComponent.SpriteProvider.SpritesCount - 1, AnimationRepeatMode.LoopInfinite, 30);
        }
示例#15
0
        public void Update(GameTime gameTime)
        {
            if (State == TrexState.Idle)
            {
                if (!_blinkAnimation.IsPlaying)
                {
                    CreateBlinkAnimation();
                    _blinkAnimation.Play();
                }

                _blinkAnimation.Update(gameTime);
            }
            else if (State == TrexState.Jumping || State == TrexState.Falling)
            {
                Position           = new Vector2(Position.X, Position.Y + _verticalVelocity * (float)gameTime.ElapsedGameTime.TotalSeconds + _dropVelocity * (float)gameTime.ElapsedGameTime.TotalSeconds);
                _verticalVelocity += GRAVITY * (float)gameTime.ElapsedGameTime.TotalSeconds;

                if (_verticalVelocity >= 0)
                {
                    State = TrexState.Falling;
                }

                if (Position.Y >= _startPosY)
                {
                    Position          = new Vector2(Position.X, _startPosY);
                    _verticalVelocity = 0;
                    State             = TrexState.Running;

                    OnJumpComplete();
                }
            }
            else if (State == TrexState.Running)
            {
                _runAnimation.Update(gameTime);
            }
            else if (State == TrexState.Ducking)
            {
                _duckAnimation.Update(gameTime);
            }

            if (State != TrexState.Idle)
            {
                Speed += ACCELERATION_PPS_PER_SECOND * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }

            if (Speed > MAX_SPEED)
            {
                Speed = MAX_SPEED;
            }

            _dropVelocity = 0;
        }
示例#16
0
    /// <summary>
    /// Reset the active animation and start playing a new one.
    /// </summary>
    /// <param name="animationName">The name of the animation to play.</param>
    public void Play(string animationName)
    {
        SpriteAnimation animationToPlay = GetAnimation(animationName);

        if (animationToPlay != null)
        {
            activeAnimation = animationToPlay;
            activeAnimation.Play();
        }
        else
        {
            Debug.LogError("Object " + gameObject.name + " does not contain a SpriteAnimation script with the animation name \"" + animationName + "\".");
        }
    }
示例#17
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            // sets the virtual resolution
            areaSize = new Vector2(GraphicsDevice.BackBuffer.Width, GraphicsDevice.BackBuffer.Height);

            // Creates the camera
            CameraComponent.UseCustomProjectionMatrix = true;
            CameraComponent.ProjectionMatrix          = SpriteBatch.CalculateDefaultProjection(new Vector3(areaSize, 200));

            // Load assets
            groundSprites = Asset.Load <SpriteGroup>("GroundSprite");
            ballSprite1   = Asset.Load <Texture>("Sphere1");
            ballSprite2   = Asset.Load <Texture>("Sphere2");
            ball          = Asset.Load <Entity>("Ball");

            // create fore/background entities
            foreground = new Entity();
            background = new Entity();
            foreground.Add(new SpriteComponent {
                SpriteProvider = new SpriteFromSpriteGroup {
                    SpriteGroup = groundSprites
                }, CurrentFrame = 1
            });
            background.Add(new SpriteComponent {
                SpriteProvider = new SpriteFromSpriteGroup {
                    SpriteGroup = groundSprites
                }, CurrentFrame = 0
            });

            Scene.AddChild(ball);
            Scene.AddChild(foreground);
            Scene.AddChild(background);

            spriteComponent  = ball.Get(SpriteComponent.Key);
            transfoComponent = ball.Get(TransformComponent.Key);

            transfoComponent.Position.X = areaSize.X / 2;
            transfoComponent.Position.Y = areaSize.Y / 2;

            var decorationScalings = new Vector3(areaSize.X, areaSize.Y, 1);

            background.Get(TransformComponent.Key).Scale    = decorationScalings;
            foreground.Get(TransformComponent.Key).Scale    = decorationScalings;
            background.Get(TransformComponent.Key).Position = new Vector3(0, 0, -1);
            foreground.Get(TransformComponent.Key).Position = new Vector3(0, areaSize.Y, 1);

            SpriteAnimation.Play(spriteComponent, 0, spriteComponent.SpriteProvider.SpritesCount - 1, AnimationRepeatMode.LoopInfinite, 30);
        }
示例#18
0
 public Star(Texture2D spriteSheet, Trex trex, Vector2 position) : base(trex, position)
 {
     _animation = SpriteAnimation.CreateSimpeAnimation(
         spriteSheet,
         new Point(INITIAL_FRAME_TEXTURE_COORDS_X, INITIAL_FRAME_TEXTURE_COORDS_Y),
         SPRITE_WIDTH,
         SPRITE_HEIGHT,
         new Point(0, SPRITE_HEIGHT),
         3,
         ANIMATION_FRAME_LENGTH
         );
     _animation.ShouldLoop = true;
     _animation.Play();
 }
示例#19
0
        private void CreateAnimation(Texture2D spriteSheet)
        {
            Sprite spriteA = new Sprite(spriteSheet, DINO_TEXTURE_COORDS_X, DINO_TEXTURE_COORDS_Y, DINO_WIDTH, DINO_HEIGHT);
            Sprite spriteB = new Sprite(spriteSheet, DINO_TEXTURE_COORDS_X + DINO_WIDTH, DINO_TEXTURE_COORDS_Y, DINO_WIDTH, DINO_HEIGHT);

            _animation = new SpriteAnimation();

            _animation.AddFrame(spriteA, 0);
            _animation.AddFrame(spriteB, FRAME_LENGTH);
            _animation.AddFrame(spriteA, FRAME_LENGTH * 2);

            _animation.ShouldLoop = true;
            _animation.Play();
        }
示例#20
0
        public FlyingDino(Trex trex, Vector2 position, Texture2D spriteSheet) : base(trex, position)
        {
            Sprite spriteA = new Sprite(spriteSheet, TEXTURE_COORDS_X, TEXTURE_COORDS_Y, SPRITE_WIDTH, SPRITE_HEIGHT);
            Sprite spriteB = new Sprite(spriteSheet, TEXTURE_COORDS_X + SPRITE_WIDTH, TEXTURE_COORDS_Y, SPRITE_WIDTH, SPRITE_HEIGHT);

            _trex = trex;

            _animation = new SpriteAnimation();
            _animation.AddFrame(spriteA, 0);
            _animation.AddFrame(spriteB, ANIMATION_FRAME_LENGTH);
            _animation.AddFrame(spriteA, ANIMATION_FRAME_LENGTH * 2);
            _animation.ShouldLoop = true;
            _animation.Play();
        }
示例#21
0
 static int Play(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         SpriteAnimation obj = (SpriteAnimation)ToLua.CheckObject(L, 1, typeof(SpriteAnimation));
         obj.Play();
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
示例#22
0
        private void Reset()
        {
            IsAlive = true;
            Entity.Transform.Position.Y = enemyInitPositionY;

            var random = enemyRandomLocal;

            // Appearance position
            Entity.Transform.Position.X = (((float)(random.NextDouble())) * gameWidthX) - gameWidthHalfX;
            // Waiting time
            enemyAge = enemyTimeToWait - (((float)(random.NextDouble())));

            enemySpriteComponent.SpriteProvider = new SpriteFromSheet {
                Sheet = enemyNormalSprite
            };
            SpriteAnimation.Play(enemySpriteComponent, 0, enemySpriteComponent.SpriteProvider.SpritesCount - 1, AnimationRepeatMode.LoopInfinite, enemyActiveFps);
        }
示例#23
0
    // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        if (_animation == null)
        {
            _animation = animator.GetComponent <SpriteAnimation>();
        }

        _animation.StopAll();
        _animation.Play(Clip.name);
        _animation.CalculateData();
        _startTime = Time.time;
        if (_state == null)
        {
            _state = _animation[Clip.name];
        }

        _length = _animation[Clip.name].length * (_state.wrapMode == WrapMode.PingPong ? 2 : 1);
        _isLoop = _state.wrapMode == WrapMode.Loop || _state.wrapMode == WrapMode.PingPong;
    }
示例#24
0
        public void Update(GameTime gametime)
        {
            if (State == TrexState.idle)
            {
                if (!_BlinkAnimation.IsPlaying)
                {
                    CreateBlinkAnimation();
                    _BlinkAnimation.Play();
                }
                _BlinkAnimation.Update(gametime);
            }

            else if (State == TrexState.jumping || State == TrexState.falling)
            {
                Position   = new Vector2(Position.X, Position.Y + _Verveloc * (float)gametime.ElapsedGameTime.TotalSeconds + _DropVelo * (float)gametime.ElapsedGameTime.TotalSeconds);
                _Verveloc += GRAVITY * (float)gametime.ElapsedGameTime.TotalSeconds;

                if (_Verveloc >= 0)
                {
                    State = TrexState.falling;
                }

                if (Position.Y >= _startposy)
                {
                    Position  = new Vector2(Position.X, Position.Y);
                    _Verveloc = 0;
                    State     = TrexState.runnig;
                }
            }

            else if (State == TrexState.runnig)
            {
                _runAnimation.Update(gametime);
            }

            else if (State == TrexState.ducking)
            {
                _DuckingAnimation.Update(gametime);
            }

            _DropVelo = 0;
        }
示例#25
0
        public void TestStop()
        {
            var spriteComp = CreateSpriteComponent(20);

            SpriteAnimation.Play(spriteComp, 0, 1, AnimationRepeatMode.PlayOnce, 1);
            SpriteAnimation.Draw(new GameTime(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1)));

            Assert.Equal(1, spriteComp.CurrentFrame); // check that is it correctly updated by default

            SpriteAnimation.Stop(spriteComp);
            SpriteAnimation.Draw(new GameTime(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1)));

            Assert.Equal(1, spriteComp.CurrentFrame); // check that current frame does not increase any more

            SpriteAnimation.Play(spriteComp, 2, 3, AnimationRepeatMode.PlayOnce, 1);
            SpriteAnimation.Draw(new GameTime(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(0)));

            Assert.Equal(2, spriteComp.CurrentFrame); // check that frame is correctly set to first animation frame

            SpriteAnimation.Play(spriteComp, 2, 3, AnimationRepeatMode.PlayOnce, 1);
            SpriteAnimation.Queue(spriteComp, 5, 6, AnimationRepeatMode.PlayOnce, 1);

            SpriteAnimation.Draw(new GameTime(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(0)));

            Assert.Equal(2, spriteComp.CurrentFrame); // check that is it correctly updated by default

            SpriteAnimation.Stop(spriteComp);
            SpriteAnimation.Draw(new GameTime(TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(2)));

            Assert.Equal(2, spriteComp.CurrentFrame); // check that queue is correctly reset

            SpriteAnimation.Play(spriteComp, 2, 3, AnimationRepeatMode.PlayOnce, 1);
            SpriteAnimation.Draw(new GameTime(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(3)));

            Assert.Equal(3, spriteComp.CurrentFrame); // check that queue is correctly reset

            SpriteAnimation.Stop(spriteComp);
            SpriteAnimation.Queue(spriteComp, 5, 6, AnimationRepeatMode.PlayOnce, 1);
            SpriteAnimation.Draw(new GameTime(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(0)));

            Assert.Equal(5, spriteComp.CurrentFrame); // check that indices are correctly reseted during stop
        }
示例#26
0
        public Trex(Texture2D spriteSheet, Vector2 position, SoundEffect jumpSound)
        {
            Position = position;
            _idleTrexBackgroundSprite = new Sprite(spriteSheet, TREX_IDLE_BACKGROUND_SPRITE_POSS_X, TREX_IDLE_BACKGROUND_SPRITE_POSS_Y, TREX_DEFAULT_SPRITE_WIDTH, TREX_DEFAULT_SPRITE_HEIGHT);
            State = TrexState.Idle;

            _jumpSound = jumpSound;

            _random = new Random();


            _idleSprite      = new Sprite(spriteSheet, TREX_DEFAULT_SPRITE_POS_X, TREX_DEFAULT_SPRITE_POS_Y, TREX_DEFAULT_SPRITE_WIDTH, TREX_DEFAULT_SPRITE_HEIGHT);
            _idleBlinkSprite = new Sprite(spriteSheet, TREX_DEFAULT_SPRITE_POS_X + TREX_DEFAULT_SPRITE_WIDTH, TREX_DEFAULT_SPRITE_POS_Y, TREX_DEFAULT_SPRITE_WIDTH, TREX_DEFAULT_SPRITE_HEIGHT);
            _blinkAnimation  = new SpriteAnimation();
            CreateBlinkAnimation();
            _blinkAnimation.Play();


            _startPosY = position.Y;
        }
示例#27
0
    /// <summary>
    /// Reset the active animation and start playing a new one.
    /// </summary>
    /// <param name="animationName">The name of the animation to play.</param>
    /// <param name="startingFrame">The frame to start playing the animation from.</param>
    public void Play(string animationName, int startingFrame)
    {
        SpriteAnimation animationToPlay = GetAnimation(animationName);

        if (animationToPlay != null)
        {
            if (startingFrame < animationToPlay.sprites.Length)
            {
                activeAnimation = animationToPlay;
                activeAnimation.Play(startingFrame);
            }
            else
            {
                Debug.LogError("\"" + animationToPlay.animationName + "\" animation does not have " + startingFrame + " frames. Cannot play animation from this point.");
            }
        }
        else
        {
            Debug.LogError("Object " + gameObject.name + " does not contain a SpriteAnimation script with the animation name \"" + animationName + "\".");
        }
    }
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        SpriteAnimation animation = target as SpriteAnimation;

        if (animation.IsPlaying)
        {
            if (GUILayout.Button("Stop"))
            {
                animation.Stop();
            }
        }
        else
        {
            if (GUILayout.Button("Play"))
            {
                animation.Play();
            }
        }
    }
    // Use this for initialization
    void Start()
    {
        //Get component reference
        spriteAnimation = GetComponent<SpriteAnimation>();
        spriteRenderer = GetComponent<SpriteRenderer>();

        //set gameobject position randomly.
        transform.position = new Vector3(
            Random.Range(0, Screen.width),
            Random.Range(0, Screen.height * 0.7f ),
            0);

        //set gameobject depth randomly.
        spriteRenderer.depth = Random.Range(0, 512);

        //Get all clips in SpriteAnimation Component, and random select one to play.
        List<string> tmp = new List<string>();

        SpriteAnimationClip[] clips = SpriteAnimationUtility.GetAnimationClips( spriteAnimation );

        foreach( SpriteAnimationClip clip in clips)
        {
            tmp.Add( clip.name);
        }

        int idx = Random.Range(0, tmp.Count);
        string name = tmp[ idx ];
        spriteAnimation.Play( name );
        SpriteAnimationState state = spriteAnimation[ name ];
        state.wrapMode = WrapMode.Loop;

        //set move step randomly.
        stepX = Random.Range(50, 250);
        stepY = Random.Range(50, 250);

        //Hold a Transform reference
        _transform = transform;
    }
示例#30
0
        void PlayRun()
        {
            var sheet = ((SpriteFromSheet)playerSprite.SpriteProvider).Sheet;

            SpriteAnimation.Play(playerSprite, sheet.FindImageIndex("run0"), sheet.FindImageIndex("run4"), AnimationRepeatMode.LoopInfinite, 12);
        }
示例#31
0
        void PlayIdle()
        {
            var sheet = ((SpriteFromSheet)playerSprite.SpriteProvider).Sheet;

            SpriteAnimation.Play(playerSprite, sheet.FindImageIndex("idle0"), sheet.FindImageIndex("idle4"), AnimationRepeatMode.LoopInfinite, 7);
        }