Esempio n. 1
0
        public Player(XmasHell game)
        {
            _game             = game;
            _currentDirection = Vector2.Zero;

            _idleAnimationTimer = new CountdownTimer(5);
            _idleAnimationTimer.Stop();
            _idleAnimationTimer.Completed += (sender, args) =>
            {
                Console.WriteLine("PLAY IDLE");
                CurrentAnimator.Play("Idle");
            };

            var playerHitboxTexture = Assets.GetTexture2D("Graphics/Sprites/Player/hitbox");

            var animatorConfig = new Config
            {
                MetadataEnabled = false,
                EventsEnabled   = false,
                PoolingEnabled  = true,
                TagsEnabled     = false,
                VarsEnabled     = false,
                SoundsEnabled   = false
            };

            var factory = new DefaultProviderFactory <ISprite, SoundEffect>(animatorConfig, true);

            var loader = new SpriterContentLoader(_game.Content, "Graphics/Sprites/Player/player");

            loader.Fill(factory);

            Stack <SpriteDrawInfo> drawInfoPool = new Stack <SpriteDrawInfo>();

            foreach (var entity in loader.Spriter.Entities)
            {
                var animator = new CustomSpriterAnimator(_game, entity, factory, drawInfoPool);
                _animators.Add(animator);
            }

            CurrentAnimator = _animators.First();
            var spriteSize = new Vector2(60, 82);

            CurrentAnimator.Position = new Vector2(spriteSize.X / 2f, spriteSize.Y / 2f);
            CurrentAnimator.Play("Idle");

            CurrentAnimator.AnimationFinished += AnimationFinished;

            _hitboxSprite = new Sprite(playerHitboxTexture)
            {
                //Scale = new Vector2(
                //    (GameConfig.PlayerHitboxRadius * 2f) / playerHitboxTexture.Width,
                //    (GameConfig.PlayerHitboxRadius * 2f) / playerHitboxTexture.Height
                //)
            };
            _hitbox = new CollisionCircle(this, Vector2.Zero, GameConfig.PlayerHitboxRadius);

            // Don't forget to set the player position delegate to the MoverManager
            _game.GameManager.MoverManager.SetPlayerPositionDelegate(Position);
        }
Esempio n. 2
0
        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            float deltaTime = gameTime.ElapsedGameTime.Ticks / (float)TimeSpan.TicksPerMillisecond;

            stats.OnUpdate(deltaTime);
            Vector2 scale = animator.Scale;

            if (WasPressed(Keys.Enter))
            {
                SwitchEntity();
            }
            if (WasPressed(Keys.Space))
            {
                animator.Play(animator.GetNextAnimation());
            }
            if (WasPressed(Keys.O))
            {
                animator.ChangeAnimationSpeed(-0.2f, 5.0f);
            }
            if (WasPressed(Keys.P))
            {
                animator.ChangeAnimationSpeed(0.2f, 5.0f);
            }
            if (WasPressed(Keys.R))
            {
                animator.Speed = -animator.Speed;
            }
            if (WasPressed(Keys.X))
            {
                animator.Play(animator.Name);
            }
            if (WasPressed(Keys.T))
            {
                animator.Transition(animator.GetNextAnimation(), 1000.0f);
            }
            if (WasPressed(Keys.C))
            {
                animator.PushNextCharacterMap();
            }
            if (WasPressed(Keys.V))
            {
                animator.PopCharacterMap();
            }
            if (WasPressed(Keys.J))
            {
                animator.Color = animator.Color == Color.White ? Color.Red : Color.White;
            }

            if (WasPressed(Keys.W))
            {
                animator.Position += new Vector2(0, -10);
            }
            if (WasPressed(Keys.S))
            {
                animator.Position += new Vector2(0, 10);
            }
            if (WasPressed(Keys.A))
            {
                animator.Position += new Vector2(-10, 0);
            }
            if (WasPressed(Keys.D))
            {
                animator.Position += new Vector2(10, 0);
            }
            if (WasPressed(Keys.Q))
            {
                animator.Rotation -= 15 * (float)Math.PI / 180;
            }
            if (WasPressed(Keys.E))
            {
                animator.Rotation += 15 * (float)Math.PI / 180;
            }
            if (WasPressed(Keys.N))
            {
                animator.Scale -= new Vector2(Math.Sign(scale.X) * 0.2f, Math.Sign(scale.Y) * 0.2f);
            }
            if (WasPressed(Keys.M))
            {
                animator.Scale += new Vector2(Math.Sign(scale.X) * 0.2f, Math.Sign(scale.Y) * 0.2f);
            }
            if (WasPressed(Keys.F))
            {
                animator.Scale *= new Vector2(-1, 1);
            }
            if (WasPressed(Keys.G))
            {
                animator.Scale *= new Vector2(1, -1);
            }

            if (WasPressed(Keys.OemTilde))
            {
                (animator as MonoGameDebugAnimator).DrawSpriteOutlines = !(animator as MonoGameDebugAnimator).DrawSpriteOutlines;
            }
            if (WasPressed(Keys.OemMinus))
            {
                graphics.SynchronizeWithVerticalRetrace = !graphics.SynchronizeWithVerticalRetrace;
                graphics.ApplyChanges();
            }

            oldState = Keyboard.GetState();

            animator.Update(deltaTime);

            elapsedTime += deltaTime;
            if (elapsedTime >= 100)
            {
                elapsedTime -= 100;
                string entity = animator.Entity.Name;
                animatorInfo = string.Format("{0} : {1}", entity, animator.Name);
                metadata     = string.Format("Variables:\n{0}\nTags:\n", animator.GetVarValues(), animator.GetTagValues());
            }
        }
Esempio n. 3
0
        public override void Update(float deltaTime)
        {
            stats.OnUpdate(deltaTime);
            Vector2 scale = currentAnimator.Scale;

            if (IsPressed(Keys.Enter))
            {
                SwitchEntity();
            }
            if (IsPressed(Keys.Space))
            {
                currentAnimator.Play(GetNextAnimation());
            }
            if (IsPressed(Keys.P))
            {
                ChangeAnimationSpeed(DeltaSpeed);
            }
            if (IsPressed(Keys.O))
            {
                ChangeAnimationSpeed(-DeltaSpeed);
            }
            if (IsPressed(Keys.R))
            {
                currentAnimator.Speed = -currentAnimator.Speed;
            }
            if (IsPressed(Keys.X))
            {
                currentAnimator.Play(currentAnimator.Name);
            }
            if (IsPressed(Keys.T))
            {
                currentAnimator.Transition(GetNextAnimation(), 1000.0f);
            }
            if (IsPressed(Keys.C))
            {
                PushCharacterMap();
            }
            if (IsPressed(Keys.V))
            {
                currentAnimator.SpriteProvider.PopCharMap();
            }
            if (IsPressed(Keys.J))
            {
                currentAnimator.Color = currentAnimator.Color == Color.White ? Color.Red : Color.White;
            }

            if (IsPressed(Keys.W))
            {
                currentAnimator.Position += new Vector2(0, -10);
            }
            if (IsPressed(Keys.S))
            {
                currentAnimator.Position += new Vector2(0, 10);
            }
            if (IsPressed(Keys.A))
            {
                currentAnimator.Position += new Vector2(-10, 0);
            }
            if (IsPressed(Keys.D))
            {
                currentAnimator.Position += new Vector2(10, 0);
            }
            if (IsPressed(Keys.Q))
            {
                currentAnimator.Rotation -= 15 * (float)Math.PI / 180;
            }
            if (IsPressed(Keys.E))
            {
                currentAnimator.Rotation += 15 * (float)Math.PI / 180;
            }
            if (IsPressed(Keys.N))
            {
                currentAnimator.Scale -= new Vector2(Math.Sign(scale.X) * 0.2f, Math.Sign(scale.Y) * 0.2f);
            }
            if (IsPressed(Keys.M))
            {
                currentAnimator.Scale += new Vector2(Math.Sign(scale.X) * 0.2f, Math.Sign(scale.Y) * 0.2f);
            }
            if (IsPressed(Keys.F))
            {
                currentAnimator.Scale *= new Vector2(-1, 1);
            }
            if (IsPressed(Keys.G))
            {
                currentAnimator.Scale *= new Vector2(1, -1);
            }

            oldState = Keyboard.GetState();

            currentAnimator.Update(deltaTime);

            string entity = currentAnimator.Entity.Name;

            status   = string.Format("{0} : {1}", entity, currentAnimator.Name);
            metadata = "Variables:\n" + GetVarValues() + "\nTags:\n" + GetTagValues();
        }