Example #1
0
        public virtual void onHit(Vector2 knockback)
        {
            var xKnockback           = _playerComponent.CurrentStateHorizontalKnockback();
            var yKnockback           = _playerComponent.CurrentStateVerticalKnockback();
            var screenShakeMagnitude = _playerComponent.CurrentStateScreenShakeMagnitude();

            var diff = Math.Sign((entity.position - _playerComponent.entity.position).X);

            knockback.X = diff;

            _knockbackTick     = new Vector2(0.05f, yKnockback);
            _knockbackVelocity = new Vector2(knockback.X * 2, -1000);

            if (Math.Abs(xKnockback) > 0.01)
            {
                _knockbackTick     = new Vector2(xKnockback, yKnockback);
                _knockbackVelocity = new Vector2(diff * 60, -1000);
            }

            if (Math.Abs(yKnockback) < 0.001)
            {
                platformerObject.velocity.Y = platformerObject.collisionState.below ? -100 : -130;
            }

            if (screenShakeMagnitude > 0.0f)
            {
                (entity.scene as SceneMap)?.startScreenShake(screenShakeMagnitude, 100);
            }

            AudioManager.hit.Play(0.5f);

            Core.getGlobalManager <ScoreManager>().GetComboPoints(_playerComponent.CurrentDamageScale());
        }
        public override void render(Graphics graphics, Camera camera)
        {
            // Icon
            var iconTexture = _iconsSubtextures[_playerComponent.CurrentWeapon];

            graphics.batcher.draw(iconTexture, entity.position + _iconPosition, Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.0f);

            var hudPosition = entity.position + _hpBounds.Location.ToVector2();

            graphics.batcher.draw(_hpBackTexture, hudPosition);
            graphics.batcher.draw(_hpFillTexture,
                                  new Rectangle((int)hudPosition.X + _hpFillOffset, (int)hudPosition.Y, (int)(_hpBounds.Width * hpFillWidth()),
                                                _hpBounds.Height));

            // Damage scale
            var damageScalePosition = entity.position + _damageScalePosition;
            var damageScale         = $"{_playerComponent.CurrentDamageScale() * 100}";

            for (var i = 0; i < damageScale.Length; i++)
            {
                var pos   = damageScalePosition + 6 * i * Vector2.UnitX;
                var drect = new Rectangle((int)pos.X, (int)pos.Y, 6, 6);
                var srect = new Rectangle(int.Parse(damageScale[i].ToString()) * 6, 0, 6, 6);
                graphics.batcher.draw(_numbersTexture, drect, srect, Color.White);
            }
            graphics.batcher.draw(_numbersTexture,
                                  new Rectangle((int)damageScalePosition.X + damageScale.Length * 6, (int)damageScalePosition.Y, 6, 6),
                                  new Rectangle(60, 0, 6, 6), Color.White);

            // Score
            var          scorePosition = entity.position + new Vector2(20, 55);
            const string score         = "Score: ";
            var          scoreNum      = $"{_scoreManager.Score}";

            graphics.batcher.drawString(GameMain.smallBitmapFont, score, scorePosition, Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 1.0f);
            var pScorePosition = scorePosition + GameMain.smallBitmapFont.measureString(score).X *Vector2.UnitX;

            graphics.batcher.drawString(GameMain.smallBitmapFont, scoreNum, pScorePosition, Color.White, 0.0f, Vector2.Zero, _scoreManager.ScaleMultiplier, SpriteEffects.None, 1.0f);

            // Instructions
            if (_systemManager.getSwitch("guide1"))
            {
                graphics.batcher.draw(_guide1Texture, entity.position, Color.White);
            }
            if (_systemManager.getSwitch("guide2"))
            {
                graphics.batcher.draw(_guide2Texture, entity.position, Color.White);
            }

            // Go
            if (_goAlpha > 0.0f)
            {
                var pos   = entity.position + _goPosition;
                var drect = new Rectangle((int)(pos.X + _goExtraPosition), (int)pos.Y, 72, _goTexture.Height);
                var srect = new Rectangle(72 * _goIndex, 0, 72, 20);
                graphics.batcher.draw(_goTexture, drect, srect, Color.White * _goAlpha);
            }
        }