public StaticObjectViewModel(Game game, IStaticObject staticObject, SpriteBatch spriteBatch) { _game = game; StaticObject = staticObject; _spriteBatch = spriteBatch; var graphics = new StaticObjectGraphics(game, staticObject); var worldCoords = HexHelper.ConvertToWorld(((HexNode)StaticObject.Node).OffsetCoords); var hexSize = MapMetrics.UnitSize / 2; var staticObjectPosition = new Vector2( (int)Math.Round(worldCoords[0] * hexSize * Math.Sqrt(3), MidpointRounding.ToEven), (int)Math.Round(worldCoords[1] * hexSize * 2 / 2, MidpointRounding.ToEven) ); _rootSprite = new SpriteContainer { Position = staticObjectPosition }; var shadowTexture = _game.Content.Load <Texture2D>("Sprites/game-objects/simple-object-shadow"); _rootSprite.AddChild(new Sprite(shadowTexture) { Position = new Vector2(0, 0), Origin = new Vector2(0.5f, 0.5f), Color = new Color(Color.White, 0.5f) }); _rootSprite.AddChild(graphics); }
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); }
public StaticObjectViewModel(Game game, IStaticObject staticObject, SpriteBatch spriteBatch, bool createHighlighted = false) { _game = game; StaticObject = staticObject; _spriteBatch = spriteBatch; var graphics = new StaticObjectGraphics(game, staticObject); var worldCoords = HexHelper.ConvertToWorld(((HexNode)StaticObject.Node).OffsetCoords); var hexSize = MapMetrics.UnitSize / 2; var staticObjectPosition = new Vector2( (int)Math.Round(worldCoords[0] * hexSize * Math.Sqrt(HIGHLIGHT_DURATION_SECONDS), MidpointRounding.ToEven), (int)Math.Round(worldCoords[1] * hexSize * 2 / 2, MidpointRounding.ToEven) ); _rootSprite = new SpriteContainer { Position = staticObjectPosition }; var hasNoShadow = StaticObject.Purpose == PropContainerPurpose.Puddle || StaticObject.Purpose == PropContainerPurpose.Pit; if (!hasNoShadow) { var shadowTexture = _game.Content.Load <Texture2D>("Sprites/game-objects/simple-object-shadow"); _rootSprite.AddChild(new Sprite(shadowTexture) { Position = new Vector2(0, 0), Origin = new Vector2(0.5f, 0.5f), Color = new Color(Color.White, 0.5f) }); } _rootSprite.AddChild(graphics); if (createHighlighted) { _highlightCounter = HIGHLIGHT_DURATION_SECONDS; } }
private static SpriteContainer CreateSpriteHierarchy(IEnumerable <AnimalPart> parts) { var bodySprite = parts.Single(x => x.Type == AnimalPartType.Body).Texture; var headSprite = parts.Single(x => x.Type == AnimalPartType.Head).Texture; var tailSprite = parts.Single(x => x.Type == AnimalPartType.Tail).Texture; var legCloseFrontSprite = parts.Single(x => x.Type == AnimalPartType.LegCloseFront).Texture; var legCloseHindSprite = parts.Single(x => x.Type == AnimalPartType.LegCloseHind).Texture; var legFarFrontSprite = parts.Single(x => x.Type == AnimalPartType.LegFarFront).Texture; var legFarHindSprite = parts.Single(x => x.Type == AnimalPartType.LegFarHind).Texture; var container = new SpriteContainer(); container.AddChild(new Sprite(legFarFrontSprite) { Position = new Vector2(0, -12), Origin = new Vector2(0.5f, 0.5f) }); container.AddChild(new Sprite(legFarHindSprite) { Position = new Vector2(0, -12), Origin = new Vector2(0.5f, 0.5f) }); container.AddChild(new Sprite(bodySprite) { Position = new Vector2(0, -12), Origin = new Vector2(0.5f, 0.5f) }); container.AddChild(new Sprite(headSprite) { Position = new Vector2(-0, -12), Origin = new Vector2(0.5f, 0.5f) }); container.AddChild(new Sprite(tailSprite) { Position = new Vector2(0, -12), Origin = new Vector2(0.5f, 0.5f) }); container.AddChild(new Sprite(legCloseFrontSprite) { Position = new Vector2(0, -12), Origin = new Vector2(0.5f, 0.5f) }); container.AddChild(new Sprite(legCloseHindSprite) { Position = new Vector2(0, -12), Origin = new Vector2(0.5f, 0.5f) }); return(container); }
private static SpriteContainer CreateSpriteHierarchy(Texture2D texture2D, Vector2 spritePosition) { var container = new SpriteContainer(); container.AddChild(new Sprite(texture2D) { Position = spritePosition, Origin = new Vector2(0.5f, 0.5f) }); return(container); }
private void UpdateSpriteMatrix(GameTime gameTime) { _updateCounter -= gameTime.ElapsedGameTime.TotalSeconds; if (_updateCounter > 0) { return; } _updateCounter = MAP_UPDATE_DELAY_SECONDS; if (_player.MainPerson is null) { throw new InvalidOperationException(); } var fowData = _player.MainPerson.GetModule <IFowData>(); var visibleFowNodeData = fowData.GetSectorFowData(_sector); if (visibleFowNodeData is null) { throw new InvalidOperationException(); } var materializedNodes = visibleFowNodeData.Nodes.ToArray(); Parallel.ForEach(materializedNodes, fowNode => { var node = (HexNode)fowNode.Node; Color nodeColor; if (_uiState.HoverViewModel != null && node == _uiState.HoverViewModel.Item) { nodeColor = Color.CornflowerBlue; } else { nodeColor = Color.White; } if (fowNode.State != SectorMapNodeFowState.Observing) { nodeColor = Color.Lerp(nodeColor, new Color(0, 0, 0, 0), 0.5f); } if (!_hexSprites.TryGetValue(node.OffsetCoords, out var currentHexSprite)) { var worldCoords = HexHelper.ConvertToWorld(node.OffsetCoords); var hexSize = MapMetrics.UnitSize / 2; var hexTextureIndex = node.GetHashCode() % 4; var hexTextureIndexX = hexTextureIndex / 2; var hexTextureIndexY = hexTextureIndex % 2; // Remember. Hex width is less that size (radius). // It equals R*Sqrt(3)/2. So sprite width is R*Sqrt(3)/2*2 or R*Sqrt(3). It's about 28 pixels. // You should make sprite 28*16. var hexSprite = new Sprite(_hexSprite) { SourceRectangle = new Rectangle(hexTextureIndexX * 28, hexTextureIndexY * 16, 28, 16) }; var hexSpriteContainer = new SpriteContainer { Position = new Vector2( (float)(worldCoords[0] * hexSize * Math.Sqrt(3)), worldCoords[1] * hexSize * 2 / 2 ) }; hexSpriteContainer.AddChild(hexSprite); if (_sector.Map.Transitions.TryGetValue(fowNode.Node, out var transition)) { if (transition.SectorNode.Biome.LocationScheme.Sid == "dungeon" || transition.SectorNode.Biome.LocationScheme.Sid == "elder-temple") { var transitionMarkerSprite = new Sprite(_hexMarkerTextures) { SourceRectangle = new Rectangle(28, 0, 28, 16) }; hexSpriteContainer.AddChild(transitionMarkerSprite); } else { var transitionMarkerSprite = new Sprite(_hexMarkerTextures) { SourceRectangle = new Rectangle(0, 0, 28, 16) }; hexSpriteContainer.AddChild(transitionMarkerSprite); } } _hexSprites.AddOrUpdate(node.OffsetCoords, hexSpriteContainer, (offsetCoords, sprite) => { return(sprite); }); currentHexSprite = hexSpriteContainer; } currentHexSprite.Color = nodeColor; }); }
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) }; }