Exemplo n.º 1
0
        public CorpseViewModel(Game game,
                               IActorGraphics actorGraphics,
                               Vector2 position,
                               Microsoft.Xna.Framework.Audio.SoundEffectInstance soundEffectInstance)
        {
            _actorGraphics       = actorGraphics ?? throw new ArgumentNullException(nameof(actorGraphics));
            _soundEffectInstance = soundEffectInstance;
            var shadowTexture = game.Content.Load <Texture2D>("Sprites/game-objects/simple-object-shadow");

            _rootSprite = new SpriteContainer
            {
                Position = position
            };

            var shadowSprite = new Sprite(shadowTexture)
            {
                Position = new Vector2(0, 0),
                Origin   = new Vector2(0.5f, 0.5f),
                Color    = new Color(Color.White, 0.5f)
            };

            _rootSprite.AddChild(shadowSprite);

            _actorGraphics.ShowOutlined   = false;
            _actorGraphics.ShowHitlighted = false;
            _rootSprite.AddChild(_actorGraphics.RootSprite);
        }
Exemplo n.º 2
0
        public ActorDamagedEngine(IActorGraphics actorGraphics, SpriteContainer rootSprite, Vector2 attackerPosition,
                                  IAnimationBlockerService animationBlockerService, SoundEffectInstance?soundEffectInstance)
        {
            _actorGraphics       = actorGraphics;
            _rootSprite          = rootSprite;
            _soundEffectInstance = soundEffectInstance;
            var positionDifference = attackerPosition - actorGraphics.RootSprite.Position;
            var hitDirection       = positionDifference;

            hitDirection.Normalize();
            _rootSprite.FlipX = hitDirection.X > 0;
            _startPosition    = rootSprite.Position;
            var oppositeDirection = hitDirection * -1;

            _hitPosition = (oppositeDirection * HIT_DISTANCE) + _startPosition;

            _moveBlocker = new AnimationCommonBlocker();

            animationBlockerService.AddBlocker(_moveBlocker);
        }
Exemplo n.º 3
0
        public ActorViewModel(
            IActor actor,
            GameObjectParams gameObjectParams)
        {
            Actor = actor;

            _game = gameObjectParams.Game ??
                    throw new ArgumentException($"{nameof(gameObjectParams.Game)} is not defined.",
                                                nameof(gameObjectParams));
            _sectorViewModelContext = gameObjectParams.SectorViewModelContext ??
                                      throw new ArgumentException(
                                                $"{nameof(gameObjectParams.SectorViewModelContext)} is not defined.",
                                                nameof(gameObjectParams));
            _personSoundStorage = gameObjectParams.PersonSoundStorage ??
                                  throw new ArgumentException(
                                            $"{nameof(gameObjectParams.PersonSoundStorage)} is not defined.",
                                            nameof(gameObjectParams));

            _gameObjectVisualizationContentStorage = gameObjectParams.GameObjectVisualizationContentStorage ??
                                                     throw new ArgumentException(
                                                               $"{nameof(gameObjectParams.GameObjectVisualizationContentStorage)} is not defined.",
                                                               nameof(gameObjectParams));

            _spriteBatch = gameObjectParams.SpriteBatch ??
                           throw new ArgumentException($"{nameof(gameObjectParams.SpriteBatch)} is not defined.",
                                                       nameof(gameObjectParams));

            if (gameObjectParams.PersonVisualizationContentStorage is null)
            {
                throw new ArgumentException(
                          $"{nameof(gameObjectParams.PersonVisualizationContentStorage)} is not defined.",
                          nameof(gameObjectParams));
            }

            var equipmentModule = Actor.Person.GetModuleSafe <IEquipmentModule>();

            var shadowTexture = _game.Content.Load <Texture2D>("Sprites/game-objects/simple-object-shadow");

            _rootSprite   = new SpriteContainer();
            _shadowSprite = new Sprite(shadowTexture)
            {
                Position = new Vector2(0, 0),
                Origin   = new Vector2(0.5f, 0.5f),
                Color    = new Color(Color.White, 0.5f)
            };

            _rootSprite.AddChild(_shadowSprite);

            var isHumanGraphics = Actor.Person is HumanPerson;

            if (isHumanGraphics)
            {
                if (equipmentModule is not null)
                {
                    var graphicsRoot = new HumanoidGraphics(equipmentModule,
                                                            gameObjectParams.PersonVisualizationContentStorage);

                    _rootSprite.AddChild(graphicsRoot);

                    _graphicsRoot = graphicsRoot;
                }
                else
                {
                    // There is no cases when human person hasn't equipment module.
                    // It can be empty module to show "naked" person in the future.
                    throw new InvalidOperationException("Person has no IEquipmentModule.");
                }
            }
            else
            {
                var             monsterPerson = Actor.Person as MonsterPerson;
                SpriteContainer?graphics      = null;
                switch (monsterPerson.Scheme.Sid)
                {
                case "predator":
                    graphics = new AnimalGraphics(gameObjectParams.PersonVisualizationContentStorage);
                    break;

                case "warthog":
                    graphics = new MonoGraphics("warthog", gameObjectParams.PersonVisualizationContentStorage);
                    break;

                case "predator-meat":
                    graphics = new AnimalGraphics(gameObjectParams.PersonVisualizationContentStorage);
                    break;

                case "skeleton":
                    graphics = new MonoGraphics("skeleton", gameObjectParams.PersonVisualizationContentStorage);
                    break;

                case "skeleton-equipment":
                    graphics = new MonoGraphics("skeleton-equipment",
                                                gameObjectParams.PersonVisualizationContentStorage);
                    break;

                case "gallbladder":
                    graphics = new MonoGraphics("gallbladder", gameObjectParams.PersonVisualizationContentStorage);
                    break;
                }

                _rootSprite.AddChild(graphics);

                _graphicsRoot = (IActorGraphics)graphics;
            }

            var hexSize = MapMetrics.UnitSize / 2;
            var playerActorWorldCoords = HexHelper.ConvertToWorld(((HexNode)Actor.Node).OffsetCoords);
            var newPosition            = new Vector2(
                (float)(playerActorWorldCoords[0] * hexSize * Math.Sqrt(3)),
                playerActorWorldCoords[1] * hexSize * 2 / 2
                );

            _rootSprite.Position = newPosition;

            Actor.Moved    += Actor_Moved;
            Actor.UsedProp += Actor_UsedProp;
            Actor.PropTransferPerformed        += Actor_PropTransferPerformed;
            Actor.BeginTransitionToOtherSector += Actor_BeginTransitionToOtherSector;
            if (Actor.Person.HasModule <IEquipmentModule>())
            {
                Actor.Person.GetModule <IEquipmentModule>().EquipmentChanged += PersonEquipmentModule_EquipmentChanged;
            }

            if (Actor.Person.HasModule <ISurvivalModule>())
            {
                Actor.Person.GetModule <ISurvivalModule>().Dead += PersonSurvivalModule_Dead;
            }

            _actorStateEngineList = new List <IActorStateEngine> {
                new ActorIdleEngine(_graphicsRoot.RootSprite)
            };
        }