/// <summary> /// Damages a section of ship. /// </summary> /// <param name="section">section</param> /// <param name="amount">amount</param> public void Damage(Point gridLocation, int amount) { var damageScale = 1f; var upgrades = _topology.Upgrades .Select(x => x.GetType()) .ToArray(); if (upgrades.Contains(typeof(HullReinforcement))) { damageScale -= 0.1f; } this.Update(() => { var section = _topology.SectionAt(gridLocation); if (section == null) { return; } section.Damage((int)(amount * damageScale)); if (section.Health == 0) { _topology.SectionAt(gridLocation)?.Module?.OnDestruction(this, GetNodeForSection(gridLocation)); _topology.Remove(gridLocation); SoundEffects.Get("ChunkyExplosion")?.Play(); //PerformPartsAnalysis(); } }); }
public void Render(RenderContext context) { context.GraphicsDevice.DepthStencilState = DepthStencilState.Default; var camera = CameraManager.ActiveCamera; if (_shipTopology.SectionAt(GridLocation) != null) { _shipRenderer.Render(context, Transform.WorldTransform, _shipTopology.SectionAt(GridLocation)); //_floorModel.SetDiffuseColour(Color.Gray); } else { //_floorModel.SetDiffuseColour(Color.DarkSlateBlue); } _floorModel.Draw(Offset * Transform.WorldTransform, camera.View, camera.Projection); }
//private (Point point, BuildNode buildNode) GetSelectedGridPoint() //{ //} public void Tick(TickContext context) { var mouse = Mouse.GetState(); var screenPos = new Vector2( mouse.X / (float)GraphicsDevice.Viewport.Width, 1.0f - (mouse.Y / (float)GraphicsDevice.Viewport.Height) ) * 2 - new Vector2(1, 1); //Console.WriteLine($"screen {screenPos}"); //Console.WriteLine(screenPos); //Console.WriteLine(worldDirectionVector); var ray = Camera.CreateRay(screenPos); var res = RayCollider.RayCast(ray, (byte)HitLayers.BuildTile); // Console.WriteLine($"Location: {res.location}"); var buildNode = res.entity?.Get <BuildNode>(); if (buildNode != null) { //Console.WriteLine($"{buildNode.GridLocation}"); } this.Update(() => HoverNode = buildNode); if (PlacingSection != null) { if (KeyControls.HasBeenPressed(Keys.R)) { PlacingSection.Rotate(1); } if (MouseControls.RightClicked) { CancelPlacing(); } else if (buildNode != null && MouseControls.LeftClicked) { var gridLocation = buildNode.GridLocation; if (_shipTopology.SectionAt(gridLocation) == null && _shipTopology.LegalSectionCheck(PlacingSection, gridLocation)) { this.Update(() => { _shipTopology.SetSection(gridLocation, PlacingSection); _productionLine.Remove(PlacingSection); PlacingSection = null; SoundEffects.Get("Hammer")?.Play(); }); } else { SoundEffects.Get("Click")?.Play(); } } } }
public void Tick(TickContext context) { if (!Active) { return; } // Get location of node. var location = GlobalLocation; // Get every obstacle within 5 units of the node. foreach (var entity in FlightSpaces.ObstacleSpace.GetNearby(location, 5f)) { var pos = entity.Get <Transform>().Location; var radius = entity.Get <IObstacle>()?.Radius ?? 1f; var distance = (location - pos).Length(); if (distance < 1f + radius) { if (entity.Has <IShipCollider>()) { entity.Get <IShipCollider>().OnHit(this, _ship, GridLocation, location, _shipTopology.SectionAt(GridLocation)); } } } foreach (var entity in FlightSpaces.ShipSpace.GetNearby(location, 5f)) { var otherNode = entity.Get <FlightNode>(); if (!otherNode.Active || otherNode.ShipGuid == ShipGuid) { continue; } var pos = otherNode.GlobalLocation; var distance = (location - pos).Length(); if (distance < 2f) { if (entity.Has <IShipCollider>()) { entity.Get <IShipCollider>().OnHit(this, _ship, GridLocation, location, _shipTopology.SectionAt(GridLocation)); } } } }