public LevelObjectPrefab(XElement element) { ChildObjects = new List <ChildObject>(); LevelTriggerElements = new List <XElement>(); OverrideProperties = new List <LevelObjectPrefab>(); OverrideCommonness = new Dictionary <string, float>(); SerializableProperties = SerializableProperty.DeserializeProperties(this, element); if (element != null) { Config = element; Name = element.Name.ToString(); LoadElements(element, -1); InitProjSpecific(element); } //use the maximum width of the sprite as the minimum surface width if no value is given if (element != null && !element.Attributes("minsurfacewidth").Any()) { if (Sprites.Any()) { MinSurfaceWidth = Sprites[0].size.X * MaxSize; } if (DeformableSprite != null) { MinSurfaceWidth = Math.Max(MinSurfaceWidth, DeformableSprite.Size.X * MaxSize); } } }
private void LookAt() { if (Sprites != null && Sprites.Any(c => c is CrazyBug)) { var enemies = Sprites.Where(c => c is CrazyBug).Select(c => (CrazyBug)c).ToList(); if (enemies.Count > 0) { var distance = enemies[0].Position - Position; _rotation = (float)Math.Atan2(distance.Y, distance.X) + MathHelper.ToRadians(90); } } }
public void Update(GameTime gameTime) { if (!_running) { return; } if (_sprites == null && Sprites.Any()) { _sprites = Sprites.Values.ToList(); } _accumulator += gameTime.ElapsedGameTime.TotalMilliseconds; if (CurrentIndex == 0 && _accumulator < StartDelay) { return; } if (_accumulator > TimeBetweenSprites) { ++CurrentIndex; _accumulator = 0; } if (CurrentIndex == SpriteCount) { if (Repeat) { CurrentIndex = 0; if (ReverseAtEnd) { _sprites.Reverse(); } } else { Stop(); } } }
public LevelObjectPrefab(XElement element, string identifier = null) { ChildObjects = new List <ChildObject>(); LevelTriggerElements = new List <XElement>(); OverrideProperties = new List <LevelObjectPrefab>(); OverrideCommonness = new Dictionary <string, float>(); Identifier = null; SerializableProperties = SerializableProperty.DeserializeProperties(this, element); if (element != null) { Config = element; Identifier = element.GetAttributeString("identifier", null) ?? identifier; if (string.IsNullOrEmpty(Identifier)) { #if DEBUG DebugConsole.ThrowError($"Level object prefab \"{element.Name}\" has no identifier! Using the name as the identifier instead..."); #else DebugConsole.AddWarning($"Level object prefab \"{element.Name}\" has no identifier! Using the name as the identifier instead..."); #endif Identifier = element.Name.ToString(); } LoadElements(element, -1); InitProjSpecific(element); } //use the maximum width of the sprite as the minimum surface width if no value is given if (element != null && !element.Attributes("minsurfacewidth").Any()) { if (Sprites.Any()) { MinSurfaceWidth = Sprites[0].size.X * MaxSize; } if (DeformableSprite != null) { MinSurfaceWidth = Math.Max(MinSurfaceWidth, DeformableSprite.Size.X * MaxSize); } } }
public bool HasSprite(Func <Sprite, bool> evaluator) { return(Sprites.Any(x => evaluator(x))); }