public static SpaceEffect FromXml(XmlResource Xml, SpaceEffect DstObject) { if (Xml == null) { throw new ArgumentNullException(nameof(Xml)); } SpaceEffect Result = DstObject; if (DstObject == null) { Result = new SpaceEffect(); } Result = SpaceObject.FromXml(Xml, Result) as SpaceEffect; XmlNode obj = Xml.Xml.LastChild; string baseName = GetXmlText(obj, "Base", string.Empty); SpaceEffect baseObject = Result; if (!string.IsNullOrEmpty(baseName)) { try { baseObject = SpaceEffect.FromXml(ResourceManager.Get <XmlResource>(baseName), null); } catch (KeyNotFoundException e) { baseObject = Result; Debug.WriteLine("XML Error: Failed to locate XML base " + baseName + ". " + e.Message); } } Result.Lifespan = GetXmlValue(obj, "Lifespan", baseObject.Lifespan); Result.MaxParticles = (int)GetXmlValue(obj, "MaxParticles", baseObject.MaxParticles); Result.MinParticles = (int)GetXmlValue(obj, "MinParticles", baseObject.MinParticles); Result.ParticleSpawnRadius = GetXmlValue(obj, "ParticleSpawnRadius", baseObject.ParticleSpawnRadius); Result.MaxParticleLife = GetXmlValue(obj, "MaxParticleLife", baseObject.MaxParticleLife); Result.MinParticleLife = GetXmlValue(obj, "MinParticleLife", baseObject.MinParticleLife); Result.MaxParticleScale = GetXmlValue(obj, "MaxParticleScale", baseObject.MaxParticleScale); Result.MinParticleScale = GetXmlValue(obj, "MinParticleScale", baseObject.MinParticleScale); Result.MaxParticleRotation = GetXmlValue(obj, "MaxParticleRotation", baseObject.MaxParticleRotation); Result.MinParticleRotation = GetXmlValue(obj, "MinParticleRotation", baseObject.MinParticleRotation); Result.MaxParticleAlpha = GetXmlValue(obj, "MaxParticleAlpha", baseObject.MaxParticleAlpha); Result.MinParticleAlpha = GetXmlValue(obj, "MinParticleAlpha", baseObject.MinParticleAlpha); Result.MaxParticleDirection = GetXmlValue(obj, "MaxParticleDirection", baseObject.MaxParticleDirection); Result.MinParticleDirection = GetXmlValue(obj, "MinParticleDirection", baseObject.MinParticleDirection); Result.MaxParticleAngle = GetXmlValue(obj, "MaxParticleAngle", baseObject.MaxParticleAngle); Result.MinParticleAngle = GetXmlValue(obj, "MinParticleAngle", baseObject.MinParticleAngle); Result.MaxParticleSpeed = GetXmlValue(obj, "MaxParticleSpeed", baseObject.MaxParticleSpeed); Result.MinParticleSpeed = GetXmlValue(obj, "MinParticleSpeed", baseObject.MinParticleSpeed); Result.ParticleFade = GetXmlBool(obj, "ParticleFade", baseObject.ParticleFade); Result.ParticleDrag = GetXmlValue(obj, "ParticleDrag", baseObject.ParticleDrag); Result.Children = GetXmlChildrenEffect(obj, "ChildEffect", baseObject.Children); return(Result); }
public override void Destroy() { if (Hardpoints != null) { foreach (SpaceShipHardpoint hp in Hardpoints) { if (hp.Active) { hp.Destroy(); } } } var o = SpaceEffect.FromXml(ResourceManager.Get <XmlResource>(@"xml\effect\base_explosion"), null); o.Location = Location; o.Velocity = Velocity; GameManager.Add(o); base.Destroy(); }
public static void Tick(double Delta) { if (Debug.Enabled) { if (!Debug.ConsoleIsOpen) { if (IsKeyPressed(KeyboardKey.KEY_SPACE)) { Paused = !Paused; } } } // =============================Camera Controls======================================== float scrollAmount = GetMouseWheelMove(); float a = (float)Math.Abs(scrollAmount) * ViewScale * 100.0f; a = 0; const float maxZoom = 4; const float minZoom = 0.1f; if (scrollAmount > 0) { ViewScale *= 1.1f; if (ViewScale > maxZoom) { ViewScale = maxZoom; } else { ViewOffset -= new Vector2(a, a); } } if (scrollAmount < 0) { ViewScale *= 0.9f; if (ViewScale < minZoom) { ViewScale = minZoom; } else { ViewOffset += new Vector2(a, a); } } if (!Debug.ConsoleIsOpen) { if (IsKeyDown(KeyboardKey.KEY_W)) { ViewOffset += Vector2.UnitY * (5f + panBoost); } if (IsKeyDown(KeyboardKey.KEY_S)) { ViewOffset += Vector2.UnitY * -(5f + panBoost); } if (IsKeyDown(KeyboardKey.KEY_A)) { ViewOffset += Vector2.UnitX * (5f + panBoost); } if (IsKeyDown(KeyboardKey.KEY_D)) { ViewOffset += Vector2.UnitX * -(5f + panBoost); } if (!IsKeyDown(KeyboardKey.KEY_W) && !IsKeyDown(KeyboardKey.KEY_S) && !IsKeyDown(KeyboardKey.KEY_A) && !IsKeyDown(KeyboardKey.KEY_D)) { panBoost *= 0.90f; } else { panBoost += 0.25f; panBoost = Math.Clamp(panBoost, 0, 10); } } if (!Paused || ((IsKeyDown(KeyboardKey.KEY_RIGHT) || IsKeyPressed(KeyboardKey.KEY_LEFT)) && !Debug.ConsoleIsOpen)) { // ==================================Collisons========================================= while (bufferObjects.Count > 0) { Instance.Objects.Add(bufferObjects.Dequeue()); } IEnumerable <SpaceObject> projectiles = Instance.Objects.Where(o => o is SpaceProjectile && o.Active ); IEnumerable <SpaceObject> ships = Instance.Objects.Where(o => o is SpaceShip && o.Active ); foreach (SpaceObject projectile in projectiles) { foreach (SpaceObject ship in ships) { if (projectile.Faction != ship.Faction && //Raylib.Raylib.Vector2Distance(projectile.Location, ship.Location) < ship.Texture.Texture.width / 2 && ship.CheckCollision(projectile.Hitbox, projectile.Location, projectile.Scale, (float)projectile.Angle) && (projectile as SpaceProjectile)?.Sender != ship ) { (ship as SpaceShip)?.Damage((double)(projectile as SpaceProjectile)?.Damage); var o = SpaceEffect.FromXml(ResourceManager.Get <XmlResource>(@"xml\effect\base_impact"), null); o.Location = projectile.Location; o.Velocity = ship.Velocity; GameManager.Add(o); projectile.Active = false; } } } // ==================================================================================== foreach (SpaceShipUnit unit in Instance.Units) { unit.Tick(Delta); } for (int i = 0; i < Instance.Objects.Count; i++) { Instance.Objects[i].Tick(Delta); } if (Instance.Objects.Count > PruneLimit) { Prune(); } } }