예제 #1
0
        public override void Draw(RenderContext renderContext)
        {
            if (CanDraw)
            {
                renderContext.SpriteBatch.Draw(_texture, Position, DrawRect, Color,
                    MathHelper.ToRadians(Rotation), Vector2.Zero, Scale, Effect, Depth);

                base.Draw(renderContext);
            }
        }
예제 #2
0
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            _renderContext = new RenderContext();
            _background = new GameSprite("Background");
            _enemy = new GameSprite("Enemy");
            _hero = new Hero2D();
            _hero.Initialize();

            _enemy.Position = new Vector2(10, 10);

            base.Initialize();
        }
예제 #3
0
        public override void Update(RenderContext renderContext)
        {
            _heroSprite.Update(renderContext);

            var heroPos = _heroSprite.Position;
            if (_direction == 1 && heroPos.X >= renderContext.GraphicsDevice.Viewport.Width
                - (FrameWidth * _heroSprite.Scale.X))
            {
                _direction = -1;
                _heroSprite.Effect = SpriteEffects.FlipHorizontally;
            }

            else if (_direction == -1 && heroPos.X < 0)
            {
                _direction = 1;
                _heroSprite.Effect = SpriteEffects.None;
            }

            heroPos.X += (float)(Speed * renderContext.GameTime.ElapsedGameTime.TotalSeconds * _direction);

            _heroSprite.Position = heroPos;
        }
예제 #4
0
 public virtual void Draw(RenderContext renderContext)
 {
 }
예제 #5
0
        public virtual void Update(RenderContext renderContext)
        {
            WorldMatrix =
                Matrix.CreateTranslation(new Vector3(-PivotPoint, 0)) *
                Matrix.CreateScale(new Vector3(LocalScale, 1)) *
                Matrix.CreateRotationZ(MathHelper.ToRadians(LocalRotation)) *
                Matrix.CreateTranslation(new Vector3(LocalPosition, 0));

            if (Parent != null)
            {
                WorldMatrix = Matrix.Multiply(WorldMatrix, Matrix.CreateTranslation(new Vector3(Parent.PivotPoint, 0)));
                WorldMatrix = Matrix.Multiply(WorldMatrix, Parent.WorldMatrix);
            }
        }
예제 #6
0
 public override void Draw(RenderContext renderContext)
 {
     _heroSprite.Draw(renderContext);
 }
        public override void Update(RenderContext renderContext)
        {
            if (IsPlaying && !IsPaused)
            {
                _totalFrameTime += renderContext.GameTime.ElapsedGameTime.Milliseconds;
                if (_totalFrameTime >= FrameInterval)
                {
                    _totalFrameTime = 0;
                    if (_rowCount > 1)
                    {
                        _frameRect.Location = new Point(FrameSize.X * (CurrentFrame % _columnCount),
                            FrameSize.Y * (int)Math.Floor(CurrentFrame / _columnCount));
                    }
                    else _frameRect.Location = new Point(FrameSize.X * CurrentFrame, 0);
                    DrawRect = _frameRect;
                    ++CurrentFrame;
                    if (CurrentFrame >= NumFrames)
                    {
                        CurrentFrame = 0;
                        IsPlaying = IsLooping;
                    }
                }
            }

            base.Update(renderContext);
        }