Example #1
0
        public Creature()
        {
            CurrentHP = 150;
            MaxHP = 150;
            ID = lastID++;
            Access = Constants.ACCESS_NORMAL;
            CharType = 1;
            CurrentDirection = Direction.SOUTH;
            CurrentHealthStatus = HealthStatus.HEALTHY;
            Name = "None";
            OutfitUpper = 0x88;
            OutfitMiddle = 0x88;
            OutfitLower = 0x35;
            LogedIn = false;
            CurrentWalkSettings = new WalkSettings();
            Corpse = 437; //TODO: Move away from hard coding
            Invisible = false;
            Polymorph = 0;
            AddType(Constants.TYPE_BLOCKING | Constants.TYPE_BLOCKS_AUTO_WALK
                | Constants.TYPE_BLOCKS_MONSTERS);
            CurrentFightMode = FightMode.NORMAL;
            CurrentFightStance = FightStance.CHASE;
            AddType(Constants.TYPE_CREATURE);

            LastWalk = new Elapser(0);
        }
Example #2
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <remarks>Every initial values come from <see cref="Constants.Player"/>.</remarks>
 internal Player() : base(
         0,
         Constants.Player.INITIAL_X,
         Constants.Player.INITIAL_Y,
         Constants.Player.SPRITE_WIDTH,
         Constants.Player.SPRITE_HEIGHT,
         Constants.Player.MAXIMAL_LIFE_POINTS,
         Constants.Player.HIT_LIFE_POINT_COST,
         Constants.Player.INITIAL_SPEED,
         Constants.Player.RECOVERY_TIME,
         nameof(Filename.Player),
         nameof(Filename.PlayerRecovery),
         Direction.Right)
 {
     NewScreenEntrance      = null;
     Inventory              = new Inventory();
     SwordHitSprite         = null;
     _hitElapser            = null;
     _currentWeaponHitDelay = Constants.Player.SWORD_HIT_DELAY;
     _movementTimeManager   = new Elapser(this, ElapserUse.PlayerMovement);
     _renderShield          = DefaultRender.BasicImage(this, nameof(Filename.PlayerShield));
     _renderRecoveryShield  = DefaultRender.AnimatedBasicImage(this,
                                                               nameof(Filename.PlayerRecoveryShield), ElapserUse.LifeSpriteRecovery, Constants.RECOVERY_BLINK_DELAY);
     _renderSword         = DefaultRender.BasicImage(this, nameof(Filename.PlayerSword));
     _renderRecoverySword = DefaultRender.AnimatedBasicImage(this,
                                                             nameof(Filename.PlayerRecoverySword), ElapserUse.LifeSpriteRecovery, Constants.RECOVERY_BLINK_DELAY);
 }
Example #3
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="point">Starting <see cref="Point"/>.</param>
 /// <param name="direction"><see cref="Direction"/></param>
 /// <param name="thrownBy"><see cref="LifeSprite"/> who throws the arrow.</param>
 internal ActionnedArrow(Point point, Direction direction, LifeSprite thrownBy)
     : base(0, point.X, point.Y, Constants.Arrow.WIDTH, Constants.Arrow.HEIGHT,
            RenderType.Image, nameof(Filename.Arrow), nameof(Direction))
 {
     Direction  = direction;
     _elapser   = new Elapser(this, ElapserUse.ArrowMovement);
     _hitOrAway = false;
     _thrownBy  = thrownBy;
 }
Example #4
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="id"><see cref="Sprite.Id"/></param>
 /// <param name="x"><see cref="Sprite.X"/></param>
 /// <param name="y"><see cref="Sprite.Y"/></param>
 /// <param name="width"><see cref="Sprite.Width"/></param>
 /// <param name="height"><see cref="Sprite.Height"/></param>
 /// <param name="maximalLifePoints"><see cref="DamageableSprite.CurrentLifePoints"/></param>
 /// <param name="hitLifePointCost"><see cref="LifeSprite.HitLifePointCost"/></param>
 /// <param name="speed"><see cref="LifeSprite.Speed"/></param>
 /// <param name="recoveryTime"><see cref="LifeSprite._recoveryTime"/></param>
 /// <param name="renderFilename"><see cref="Sprite._render"/></param>
 /// <param name="renderRecoveryFilename"><see cref="LifeSprite._renderRecovery"/></param>
 /// <param name="defaultDirection">Initial <see cref="LifeSprite.Direction"/>.</param>
 /// <param name="lootItemType"><see cref="LootItemType"/></param>
 /// <param name="lootQuantity"><see cref="LootQuantity"/></param>
 internal Enemy(int id, double x, double y, double width, double height, double maximalLifePoints, double hitLifePointCost,
                double speed, double recoveryTime, string renderFilename, string renderRecoveryFilename,
                Enums.Direction defaultDirection, Enums.ItemType?lootItemType, int lootQuantity)
     : base(id, x, y, width, height, maximalLifePoints, hitLifePointCost, speed, recoveryTime, renderFilename,
            renderRecoveryFilename, defaultDirection)
 {
     _movementTimeManager = new Elapser(this, Enums.ElapserUse.EnemyMovement);
     LootItemType         = lootItemType;
     LootQuantity         = lootQuantity;
 }
Example #5
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="id"><see cref="Sprite.Id"/></param>
 /// <param name="x"><see cref="Sprite.X"/></param>
 /// <param name="y"><see cref="Sprite.Y"/></param>
 /// <param name="width"><see cref="Sprite.Width"/></param>
 /// <param name="height"><see cref="Sprite.Height"/></param>
 /// <param name="itemType"><see cref="ItemType"/></param>
 /// <param name="quantity"><see cref="Quantity"/></param>
 /// <param name="timeBeforeDisapear"><see cref="_timeManager"/> lifetime, in milliseconds.</param>
 internal PickableItem(int id, double x, double y, double width, double height,
                       ItemType?itemType, int quantity, double?timeBeforeDisapear)
     : base(id, x, y, width, height, RenderType.Image, new[] { itemType.HasValue?itemType.Value.ToString() : nameof(Filename.Coin) })
 {
     ItemType = itemType;
     Quantity = quantity;
     if (timeBeforeDisapear.HasValue)
     {
         _timeManager = new Elapser(this, ElapserUse.PickableItemLifetime, timeBeforeDisapear.Value);
     }
 }
Example #6
0
 /// <inheritdoc />
 internal override void BehaviorAtNewFrame()
 {
     if (Engine.Default.IsTriggered(this))
     {
         _triggerTimeManager = new Elapser(this, Enums.ElapserUse.FloorTriggerManagement, _actionDuration);
     }
     else if (_triggerTimeManager?.Elapsed == true)
     {
         _triggerTimeManager = null;
     }
 }
Example #7
0
 /// <inheritdoc />
 internal override void BehaviorAtNewFrame()
 {
     // Explosion beginning.
     if (_explodingTimeManager == null && _pendingTimeManager.Elapsed)
     {
         _explodingTimeManager = new Elapser(this, Enums.ElapserUse.BonbExploding, Constants.Bomb.TIME_WHILE_EXPLODING);
         ExplosionSprite       = new BombExplosion(this);
     }
     else if (IsDone)
     {
         ExplosionSprite = null;
     }
 }
Example #8
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="id"><see cref="Sprite.Id"/></param>
 /// <param name="x"><see cref="Sprite.X"/></param>
 /// <param name="y"><see cref="Sprite.Y"/></param>
 /// <param name="width"><see cref="Sprite.Width"/></param>
 /// <param name="height"><see cref="Sprite.Height"/></param>
 /// <param name="maximalLifePoints"><see cref="MaximalLifePoints"/></param>
 /// <param name="hitLifePointCost"><see cref="HitLifePointCost"/></param>
 /// <param name="speed"><see cref="_originalSpeed"/></param>
 /// <param name="recoveryTime"><see cref="_recoveryTime"/></param>
 /// <param name="renderFilename">File name for <see cref="Sprite._render"/>.</param>
 /// <param name="renderRecoveryFilename">File name for <see cref="_renderRecovery"/>.</param>
 /// <param name="defaultDirection">Default <see cref="Direction"/>.</param>
 protected LifeSprite(int id, double x, double y, double width, double height, double maximalLifePoints, double hitLifePointCost,
                      double speed, double recoveryTime, string renderFilename, string renderRecoveryFilename, Direction defaultDirection)
     : base(id, x, y, width, height, maximalLifePoints, RenderType.Image, new[] { renderFilename, nameof(Direction) })
 {
     Direction              = defaultDirection;
     MaximalLifePoints      = maximalLifePoints;
     HitLifePointCost       = hitLifePointCost;
     _originalSpeed         = speed;
     _recoveryManager       = null;
     _recoveryTime          = recoveryTime;
     ExplosionLifePointCost = Constants.Bomb.EXPLOSION_LIFE_POINT_COST;
     ArrowLifePointCost     = Constants.Arrow.LIFE_POINT_COST;
     _renderRecovery        = DefaultRender.AnimatedBasicImage(this, renderRecoveryFilename, ElapserUse.LifeSpriteRecovery, Constants.RECOVERY_BLINK_DELAY);
 }
Example #9
0
        // Manages the main weapon hit.
        private void ManageHit()
        {
            if (Engine.Default.KeyPress.PressHit && _hitElapser == null)
            {
                _hitElapser = new Elapser(this, ElapserUse.PlayerSwordManagement, _currentWeaponHitDelay);
                // Sprite coordinates are not important here, as we compute them below.
                SwordHitSprite = new SwordHit(Id, 0, 0, 0, 0);
            }
            else if (_hitElapser?.Elapsed == true)
            {
                _hitElapser = null;
            }
            if (_hitElapser == null)
            {
                SwordHitSprite = null;
            }

            SwordHitSprite?.AdjustToPlayer();
        }
Example #10
0
        /// <summary>
        /// Checks if the instance has been hit.
        /// </summary>
        /// <returns><c>True</c> if has been hit; <c>False</c> otherwise.</returns>
        internal virtual bool CheckIfHasBeenHit()
        {
            // currently recovering ?
            if (_recoveryManager?.Elapsed == true)
            {
                _recoveryManager = null;
            }

            if (_recoveryManager == null)
            {
                double cumuledLifePoints = Engine.Default.CurrentScreen.HitByAnActionnedItem(this);

                cumuledLifePoints += ComputeLifePointCostFromEnemies();

                if (cumuledLifePoints.Greater(0))
                {
                    CurrentLifePoints -= cumuledLifePoints;
                    _recoveryManager   = _recoveryTime > 0 ? new Elapser(this, ElapserUse.LifeSpriteRecovery, _recoveryTime) : null;
                    return(true);
                }
            }

            return(false);
        }
Example #11
0
        /// <inheritdoc />
        public Brush GetRenderBrush()
        {
            if (!string.IsNullOrWhiteSpace(_hexColor))
            {
                if (_brushByStatus.Keys.Count == 0)
                {
                    _brushByStatus.Add(new KeyValuePair <int, Enums.Direction>(), (SolidColorBrush)(new BrushConverter().ConvertFrom(_hexColor)));
                }

                return(_brushByStatus.Values.First());
            }

            int currentIndex = -1;

            if (_animationElapser.HasValue)
            {
                Elapser elapser = Elapser.Instances.First(x => x.Owner == _owner && x.UseId == _animationElapser);
                if (elapser != null)
                {
                    currentIndex = elapser.GetStepIndex(_elapserNextStep, _topIndex);
                }
            }

            Enums.Direction currentDirection = _owner?.GetDirection() ?? Constants.DEFAULT_SPRITE_DIRECTION;
            KeyValuePair <int, Enums.Direction> statusKey = new KeyValuePair <int, Enums.Direction>(currentIndex, currentDirection);

            if (!_brushByStatus.ContainsKey(statusKey))
            {
                BitmapImage bitmapImage = new BitmapImage();

                string actualImageName = currentIndex >= 0 ? string.Concat(_imageName, currentIndex) : _imageName;
                string resourcePath    = Tools.GetImagePath(Engine.ResourcesPath, actualImageName);

                using (FileStream stream = new FileStream(resourcePath, FileMode.Open, FileAccess.Read))
                {
                    stream.Position = 0;
                    bitmapImage.BeginInit();
                    bitmapImage.StreamSource = stream;
                    bitmapImage.CacheOption  = BitmapCacheOption.OnLoad;
                    bitmapImage.EndInit();
                }

                double angle = 0;
                bool   flip  = false;
                switch (currentDirection)
                {
                case Enums.Direction.Bottom:
                    angle = 90;
                    break;

                case Enums.Direction.BottomLeft:
                    angle = 45;
                    flip  = true;
                    break;

                case Enums.Direction.BottomRight:
                    angle = 45;
                    break;

                case Enums.Direction.Left:
                    flip = true;
                    break;

                case Enums.Direction.Right:
                    break;

                case Enums.Direction.Top:
                    angle = -90;
                    break;

                case Enums.Direction.TopLeft:
                    angle = -45;
                    flip  = true;
                    break;

                case Enums.Direction.TopRight:
                    angle = -45;
                    break;
                }

                ImageBrush brush = new ImageBrush
                {
                    ImageSource       = bitmapImage,
                    Stretch           = Stretch.UniformToFill,
                    RelativeTransform = new TransformGroup
                    {
                        Children = new TransformCollection
                        {
                            new RotateTransform
                            {
                                CenterX = 0.5,
                                CenterY = 0.5,
                                Angle   = angle
                            }, new ScaleTransform
                            {
                                CenterX = 0.5,
                                CenterY = 0.5,
                                ScaleX  = flip ? -1 : 1
                            }
                        }
                    }
                };

                if (_mosaicDisplay)
                {
                    brush.TileMode      = TileMode.Tile;
                    brush.Stretch       = Stretch.None;
                    brush.ViewportUnits = BrushMappingMode.RelativeToBoundingBox;
                    brush.Viewport      = new System.Windows.Rect(0, 0,
                                                                  1 / (_owner.Width / brush.ImageSource.Width),
                                                                  1 / (_owner.Height / brush.ImageSource.Height));
                }

                _brushByStatus.Add(statusKey, brush);
            }

            return(_brushByStatus[statusKey]);
        }
Example #12
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="point">Drop coordinates.</param>
 internal ActionnedBomb(Point point)
     : base(0, point.X, point.Y, Constants.Bomb.WIDTH, Constants.Bomb.HEIGHT, Enums.RenderType.Image, nameof(Enums.Filename.Bomb))
 {
     _pendingTimeManager = new Elapser(this, Enums.ElapserUse.BonbPending, Constants.Bomb.TIME_WHILE_PENDING);
     ExplosionSprite     = null;
 }