public override void OnInspectorGUI() { // Get the place of the next available position in the script field = (AsteroidField)target; base.OnInspectorGUI (); if (GUILayout.Button ("Load asteroids from resources")) { Object[] objects = Resources.LoadAll ("Asteroids", typeof(GameObject)); GameObject[] asteroids = new GameObject[objects.Length]; for (int i = 0; i < objects.Length; i++) { asteroids[i] = (GameObject)objects[i]; } field.prefabs = asteroids; } addRigid = EditorGUILayout.Toggle ("Add RigidBody", addRigid); addCollider = EditorGUILayout.Toggle ("Add BoxCollider", addCollider); addAsteroid = EditorGUILayout.Toggle ("Add Asteroid script", addAsteroid); addDamagable = EditorGUILayout.Toggle ("Add DamagableObject", addDamagable); addMaterial = EditorGUILayout.Toggle ("Assign same material to asteroid", addMaterial); if (GUILayout.Button ("Generate")) { GenerateAsteroids (addRigid, addCollider, addAsteroid, addDamagable, addMaterial); } }
public override void OnInspectorGUI() { // Get the place of the next available position in the script field = (AsteroidField)target; base.OnInspectorGUI(); if (GUILayout.Button("Load asteroids from resources")) { Object[] objects = Resources.LoadAll("Asteroids", typeof(GameObject)); GameObject[] asteroids = new GameObject[objects.Length]; for (int i = 0; i < objects.Length; i++) { asteroids[i] = (GameObject)objects[i]; } field.prefabs = asteroids; } addRigid = EditorGUILayout.Toggle("Add RigidBody", addRigid); addCollider = EditorGUILayout.Toggle("Add BoxCollider", addCollider); addAsteroid = EditorGUILayout.Toggle("Add Asteroid script", addAsteroid); addDamagable = EditorGUILayout.Toggle("Add DamagableObject", addDamagable); addMaterial = EditorGUILayout.Toggle("Assign same material to asteroid", addMaterial); if (GUILayout.Button("Generate")) { GenerateAsteroids(addRigid, addCollider, addAsteroid, addDamagable, addMaterial); } }
static IEnumerable <(Point point, int visible)> AnalyzeLocations(AsteroidField asteroidField) { foreach (var asteroid in asteroidField.Asteroids) { yield return(asteroid, asteroidField.CountVisibleFrom(asteroid)); } }
protected override object SolvePart1() { var map = Input.Select((line, y) => line.Select((chr, x) => (X: x, Y: y, IsAsteroid: chr == '#')).ToArray()).ToArray(); var mapWidth = map[0].Length; var mapHeight = map.Length; var asteroidField = new AsteroidField { Asteroids = map.SelectMany(s => s) .Where(s => s.IsAsteroid) .Select(s => new Asteroid { Sector = new Sector { X = s.X, Y = s.Y } }) .ToList() }; var station = asteroidField.Asteroids.Aggregate((a1, a2) => a1.VisibleAsteroids(asteroidField.Asteroids, mapWidth, mapHeight).Count > a2.VisibleAsteroids(asteroidField.Asteroids, mapWidth, mapHeight).Count ? a1 : a2); return(station.VisibleAsteroids(asteroidField.Asteroids, mapWidth, mapHeight).Count); }
public void GeneratePoints(Map.Area area, List <Vector2> areaPoints) { // Make at least one point be a station or a planet Map.Area.POIData data = new Map.Area.POIData(); Vector2 pos = areaPoints[Random.Range(0, areaPoints.Count)]; Station station = (Station)PickRandom(stations.Cast <PointOfInterest>().ToArray()); data.pointOfInterest = station; data.position = pos; area.pointsOfInterest.Add(data); areaPoints.Remove(pos); // Set others randomly foreach (Vector2 v in areaPoints) { Map.Area.POIData d = new Map.Area.POIData(); AsteroidField field = (AsteroidField)PickRandom(asteroidFields.Cast <PointOfInterest>().ToArray()); d.pointOfInterest = field; d.position = v; area.pointsOfInterest.Add(d); } }
public void Puzzle1_FindBestLocation() { var field = new AsteroidField(Input.Day10Parse(Input.Day10)); var bestLocation = field.OrderByDescending(x => x.VisibleNeighbors).First(); bestLocation.VisibleNeighbors.Should().Be(329); }
public GameObject InitializeAsteroidField(AsteroidField asteroidField) { var asteroidFieldGO = Instantiate(_asteroidFieldPrefab, new Vector3(0, 0, 0), Quaternion.identity); asteroidFieldGO.name = asteroidField.Name; asteroidFieldGO.AddComponent <AsteroidFieldWatcher>().AsteroidField = asteroidField; return(asteroidFieldGO); }
public void Examples_FindBestLocation(string data, int expectedX, int expectedY, int expectedNeighbors) { var field = new AsteroidField(Input.Day10Parse(data)); var bestLocation = field.OrderByDescending(x => x.VisibleNeighbors).First(); bestLocation.Location.Should().Be((expectedX, expectedY)); bestLocation.VisibleNeighbors.Should().Be(expectedNeighbors); }
public void AsteroidField_ParsesAsteroidsCorrectly(string data, int x, int y) { var expectedCount = data.Count(x => x == '#'); var field = new AsteroidField(Input.Day10Parse(data)); field.Should().HaveCount(expectedCount); field.Asteroids.TryGetValue((x, y), out _).Should().BeTrue(); }
public AsteroidFieldComponent(AsteroidField field, GameObject parent) : base(parent) { Field = field; //var shapes = new List<CompoundSurShape.TransformedShape>(); Dictionary <string, int> indexes = new Dictionary <string, int>(); foreach (var asteroid in Field.Cube) { var mdl = asteroid.Drawable as ModelFile; var path = Path.ChangeExtension(mdl.Path, "sur"); if (File.Exists(path)) { int idx; if (!indexes.TryGetValue(path, out idx)) { if (shape == null) { shape = new SurCollider(path); idx = 0; indexes.Add(path, 0); } else { idx = shape.LoadSur(path); indexes.Add(path, idx); } } shape.AddPart(0, asteroid.RotationMatrix * Matrix4.CreateTranslation(asteroid.Position * field.CubeSize), null, idx); } else { FLLog.Error("Sur", "Hitbox not found " + path); } } float rdist = 0f; if (field.Zone.Shape is ZoneSphere) { rdist = ((ZoneSphere)field.Zone.Shape).Radius; } else if (field.Zone.Shape is ZoneEllipsoid) { var s = ((ZoneEllipsoid)field.Zone.Shape).Size; rdist = Math.Max(Math.Max(s.X, s.Y), s.Z); } else if (field.Zone.Shape is ZoneBox) { var s = ((ZoneEllipsoid)field.Zone.Shape).Size; rdist = Math.Max(Math.Max(s.X, s.Y), s.Z); } rdist += COLLIDE_DISTANCE; activateDist = rdist * rdist; }
public void AsteroidFieldTest() { var value = new AsteroidField(null, Vector3 <HugeNumber> .Zero, childOrbit: OrbitalParameters.GetCircular(new HugeNumber(1, 1000), Vector3 <HugeNumber> .Zero)); var json = JsonSerializer.Serialize(value); Console.WriteLine(); Console.WriteLine(json); var deserialized = JsonSerializer.Deserialize <AsteroidField>(json); Assert.AreEqual(value, deserialized); Assert.AreEqual(json, JsonSerializer.Serialize(deserialized)); }
public void Test2() { var map = @".#..#,.....,#####,....#,...##"; var field = new AsteroidField(map.Split(',')); var(cell, c) = field.GetMaxVisibilityCell(); console.WriteLine($"{cell.X} {cell.Y} => {c}"); Assert.Equal(3, cell.X); Assert.Equal(4, cell.Y); Assert.Equal(8, c); }
public MainGame(GameStateManager manager, SpriteFont font, Camera camera, Ship ship, Gameboard plane, AsteroidField asteroids, SoundEffect laser, SoundEffect hit) { _bulletList = new List <Projectile>(); _manager = manager; _font = font; _camera = camera; _ship = ship; _plane = plane; _asteroids = asteroids; _laser = laser; _hit = hit; _collide = true; _reloadTime = TimeSpan.FromSeconds(3); _shootTime = TimeSpan.FromMilliseconds(150); }
public void Test1(string map, int fromx, int fromy, int expectedCount) { //System.Diagnostics.Debugger.Launch(); var field = new AsteroidField(map.Split(',')); //field.Log=console.WriteLine; var c = field.CountUnblockedAsteroid(field.GetCell(null, fromx, fromy)); if (c != expectedCount) { field.Log = console.WriteLine; field.CountUnblockedAsteroid(field.GetCell(null, fromx, fromy)); } Assert.Equal(expectedCount, c); }
public AsteroidFieldComponent(AsteroidField field, GameObject parent) : base(parent) { Field = field; var shapes = new List <CompoundSurShape.TransformedShape>(); foreach (var asteroid in Field.Cube) { var mdl = asteroid.Drawable as ModelFile; var path = Path.ChangeExtension(mdl.Path, "sur"); if (File.Exists(path)) { SurFile sur = parent.Resources.GetSur(path); foreach (var s in sur.GetShape(0)) { shapes.Add(new CompoundSurShape.TransformedShape(s, new Matrix3(asteroid.RotationMatrix), asteroid.Position * Field.CubeSize)); } } else { FLLog.Error("Sur", "Hitbox not found " + path); } } float rdist = 0f; if (field.Zone.Shape is ZoneSphere) { rdist = ((ZoneSphere)field.Zone.Shape).Radius; } else if (field.Zone.Shape is ZoneEllipsoid) { var s = ((ZoneEllipsoid)field.Zone.Shape).Size; rdist = Math.Max(Math.Max(s.X, s.Y), s.Z); } else if (field.Zone.Shape is ZoneBox) { var s = ((ZoneEllipsoid)field.Zone.Shape).Size; rdist = Math.Max(Math.Max(s.X, s.Y), s.Z); } rdist += COLLIDE_DISTANCE; activateDist = rdist * rdist; shape = new CompoundSurShape(shapes); }
public void SpawnEnemies(GameObject astro, GameObject quad) { AsteroidField field = quad.GetComponent <AsteroidField>(); // In the future I want to randomize their local position and have posse's of bandits //int num = Random.Range(1, 3); Vector3 Pos = new Vector3((astro.transform.localScale.x + 2), (astro.transform.localScale.y + 2), astro.transform.localScale.z + 2); for (int i = 0; i < 1; i++) { GameObject temp = Instantiate(bandito); temp.transform.parent = astro.transform; temp.transform.localPosition = Pos; temp.transform.SetParent(quad.transform); field.enemies.Add(temp); temp.SetActive(false); } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); EGL.Space(); AsteroidField field = (AsteroidField)target; field.AsteroidGameObject = (GameObject)EGL.ObjectField(new GUIContent("Asteroid Game Object", "The game object that represents the spawned asteroids"), field.AsteroidGameObject, typeof(GameObject), false); field.InnerRadius = EGL.FloatField(new GUIContent("Inner Radius", "The inner radius of the field"), field.InnerRadius); field.OuterRadius = EGL.Slider("Outer Radius", field.OuterRadius, field.InnerRadius, 10000 + field.InnerRadius); EGL.Space(); scaleUsesRange = EGL.Toggle(new GUIContent("Scale uses range?", "Whether the asteroids spawned should pick a scale from a specified range."), scaleUsesRange); if (scaleUsesRange) { field.AsteroidLowerScale = EGL.Slider("Lower range", field.AsteroidLowerScale, 0, 20); field.AsteroidUpperScale = EGL.Slider("Upper range", field.AsteroidUpperScale, field.AsteroidLowerScale, field.AsteroidLowerScale + 20); } else { field.AsteroidScale = EGL.Slider("Scale", field.AsteroidScale, 0, 20); } using (new EditorGUI.DisabledScope(field.AsteroidGameObject == null)) { if (GUILayout.Button("Generate Field")) { field.GenerateField(scaleUsesRange); } } if (GUILayout.Button("Clear Field")) { field.ClearField(); } }
protected override object SolvePart2() { var map = Input.Select((line, y) => line.Select((chr, x) => (X: x, Y: y, IsAsteroid: chr == '#')).ToArray()).ToArray(); var mapWidth = map[0].Length; var mapHeight = map.Length; var asteroidField = new AsteroidField { Asteroids = map.SelectMany(s => s) .Where(s => s.IsAsteroid) .Select(s => new Asteroid { Sector = new Sector { X = s.X, Y = s.Y } }) .ToList() }; var station = asteroidField.Asteroids.Aggregate((a1, a2) => a1.VisibleAsteroids(asteroidField.Asteroids, mapWidth, mapHeight).Count > a2.VisibleAsteroids(asteroidField.Asteroids, mapWidth, mapHeight).Count ? a1 : a2); var queues = asteroidField.Asteroids .Where(a => a != station) .Select(a => (a.Sector, Angle: station.AngleTo(a), Distance: station.DistanceTo(a))) .ToLookup(a => a.Angle) .OrderByDescending(a => a.Key) .Select(a => new Queue <(Sector Sector, double Angle, double Distance)>(a.OrderBy(b => b.Distance))) .ToList(); return(queues.Repeat() .SelectMany(NextInQueue) .Skip(199) .Take(1) .Select(a => a.Sector.X * 100 + a.Sector.Y) .Single()); }
protected override string Solve(IEnumerable <string> inputs) { var field = new AsteroidField(inputs); var visibleFromRock = new List <(Vector2 Coordinates, int VisibleRocks)>(field.Asteroids.Count); var slopes = new HashSet <Vector2>(field.Asteroids.Count); foreach (var rock in field.Asteroids) { foreach (var pair in field.Asteroids.MakePairs(rock)) { var slope = Slope(pair); slopes.Add(slope); } visibleFromRock.Add((rock, slopes.Count)); slopes.Clear(); } var(Coordinates, VisibleRocks) = visibleFromRock.OrderByDescending(x => x.VisibleRocks).First(); AssertExpectedResult("<14, 17>,260", $"{Coordinates},{VisibleRocks}"); return($"{Coordinates} visible to {VisibleRocks:N0} other rocks"); }
public override void OnInspectorGUI() { field = (AsteroidField)target; EGL.LabelField("Settings", EditorStyles.boldLabel); field.hideFlags = (HideFlags)EGL.EnumPopup("Hide Flags", field.hideFlags); field.desiredAsteroids = EGL.IntField("Desired Asteroids", field.desiredAsteroids); EGL.Space(); EGL.LabelField("GameObject", EditorStyles.boldLabel); ShowGameObjectInformation(); EGL.Space(); EGL.LabelField("Radius", EditorStyles.boldLabel); ShowRadiusInfromation(); EGL.Space(); EGL.LabelField("Scale", EditorStyles.boldLabel); ShowScaleInformation(); EGL.Space(); ShowButtons(); }
public void Initialize() { //MainMenu _buttonList = new List <Button>(); //Options _buttonOptionsList = new List <Button>(); //MainGame _camera = new Camera(); _camera.Position = new Vector3(0, 100, 0); _camera.Target = Vector3.Zero; _camera.UpVector = Vector3.UnitZ; _camera.FieldOfView = MathHelper.PiOver2; _camera.NearClipPlane = 0.1f; _camera.FarClipPlane = 10000f; _camera.AspectRatio = Graphics.GraphicsDevice.DisplayMode.AspectRatio; _plane = new Gameboard(); _plane.Position = Vector3.Zero; _asteroidField = new AsteroidField(50, Content); _asteroidField.Initialize(); _ship = new Ship(); _ship.Position = new Vector3(95, 20, 0); }
public override IEnumerable <IModObject> Load(Mod mod) { foreach (var rec in DataFile.Records) { StellarObject sobj; string temp, type; int index = -1; rec.TryFindFieldValue("Physical Type", out type, ref index, Mod.Errors, 0, true); if (type == "Star" || type == "Destroyed Star") { var star = new Star(); sobj = star; rec.TryFindFieldValue(new string[] { "Size", "Star Size" }, out temp, ref index, Mod.Errors, 0, true); if (temp == null) { Mod.Errors.Add(new DataParsingException("Could not find Size field for star.", Mod.CurrentFileName, rec)); continue; } StellarSize size; if (Enum.TryParse <StellarSize>(temp, out size)) { star.StellarSize = size; } else { Mod.Errors.Add(new DataParsingException("Invalid star size. Must be Tiny, Small, Medium, Large, or Huge.", Mod.CurrentFileName, rec)); } rec.TryFindFieldValue(new string[] { "Age", "Star Age" }, out temp, ref index, Mod.Errors, 0, true); if (temp == null) { Mod.Errors.Add(new DataParsingException("Could not find Age field for star.", Mod.CurrentFileName, rec)); continue; } star.Age = temp; rec.TryFindFieldValue(new string[] { "Color", "Star Color" }, out temp, ref index, Mod.Errors, 0, true); if (temp == null) { Mod.Errors.Add(new DataParsingException("Could not find Color field for star.", Mod.CurrentFileName, rec)); continue; } star.Color = temp; rec.TryFindFieldValue(new string[] { "Luminosity", "Star Luminosity" }, out temp, ref index, Mod.Errors, 0, true); if (temp == null) { Mod.Errors.Add(new DataParsingException("Could not find Luminosity field for star.", Mod.CurrentFileName, rec)); continue; } star.Brightness = temp; if (type == "Destroyed Star") { star.IsDestroyed = true; } } else if (type == "Planet") { var planet = new Planet(); sobj = planet; rec.TryFindFieldValue(new string[] { "Size", "Planet Size" }, out temp, ref index, Mod.Errors, 0, true); if (temp == null) { Mod.Errors.Add(new DataParsingException("Could not find Size field for planet.", Mod.CurrentFileName, rec)); continue; } StellarSize ss; StellarObjectSize sos = Mod.Current.StellarObjectSizes.Where(s => s.StellarObjectType == "Planet" && s.Name == temp).FirstOrDefault(); if (sos == null) { if (!Enum.TryParse <StellarSize>(temp, out ss)) { Mod.Errors.Add(new DataParsingException("Invalid planet size. Must be Tiny, Small, Medium, Large, or Huge, or a planet size entry from PlanetSize.txt.", Mod.CurrentFileName, rec)); } } else { ss = sos.StellarSize; } planet.StellarSize = ss; planet.Size = sos; rec.TryFindFieldValue(new string[] { "Physical Type", "Planet Physical Type" }, out temp, ref index, Mod.Errors, 1, true); // skip the original Physical Type field which just says it's a planet if (temp == null) { Mod.Errors.Add(new DataParsingException("Could not find Physical Type field for planet.", Mod.CurrentFileName, rec)); continue; } planet.Surface = temp; rec.TryFindFieldValue(new string[] { "Atmosphere", "Planet Atmosphere" }, out temp, ref index, Mod.Errors, 0, true); if (temp == null) { Mod.Errors.Add(new DataParsingException("Could not find Atmosphere field for planet.", Mod.CurrentFileName, rec)); continue; } planet.Atmosphere = temp; } else if (type == "Asteroids") { var ast = new AsteroidField(); sobj = ast; rec.TryFindFieldValue(new string[] { "Size", "Planet Size" }, out temp, ref index, Mod.Errors, 0, true); if (temp == null) { Mod.Errors.Add(new DataParsingException("Could not find Size field for asteroids.", Mod.CurrentFileName, rec)); continue; } StellarSize ss; StellarObjectSize sos = Mod.Current.StellarObjectSizes.Where(s => s.StellarObjectType == "Planet" && s.Name == temp).FirstOrDefault(); if (sos == null) { if (!Enum.TryParse <StellarSize>(temp, out ss)) { Mod.Errors.Add(new DataParsingException("Invalid asteroid field size. Must be Tiny, Small, Medium, Large, or Huge, or an asteroids size entry from PlanetSize.txt.", Mod.CurrentFileName, rec)); } } else { ss = sos.StellarSize; } ast.StellarSize = ss; ast.Size = sos; rec.TryFindFieldValue(new string[] { "Physical Type", "Planet Physical Type" }, out temp, ref index, Mod.Errors, 1, true); // skip the original Physical Type field which just says it's asteroids if (temp == null) { Mod.Errors.Add(new DataParsingException("Could not find Physical Type field for asteroids.", Mod.CurrentFileName, rec)); continue; } ast.Surface = temp; rec.TryFindFieldValue(new string[] { "Atmosphere", "Planet Atmosphere" }, out temp, ref index, Mod.Errors, 0, true); if (temp == null) { Mod.Errors.Add(new DataParsingException("Could not find Atmosphere field for asteroids.", Mod.CurrentFileName, rec)); continue; } ast.Atmosphere = temp; rec.TryFindFieldValue(new string[] { "Combat Tile" }, out temp, ref index, Mod.Errors, 0, true); if (temp == null) { Mod.Errors.Add(new DataParsingException("Could not find Combat Tile field for asteroids.", Mod.CurrentFileName, rec)); continue; } ast.CombatTile = temp; } else if (type == "Storm") { var storm = new Storm(); sobj = storm; rec.TryFindFieldValue(new string[] { "Size", "Storm Size" }, out temp, ref index, Mod.Errors, 0, true); if (temp == null) { Mod.Errors.Add(new DataParsingException("Could not find Size field for storm.", Mod.CurrentFileName, rec)); continue; } StellarSize size; if (Enum.TryParse <StellarSize>(temp, out size)) { storm.StellarSize = size; } else { Mod.Errors.Add(new DataParsingException("Invalid storm size. Must be Tiny, Small, Medium, Large, or Huge.", Mod.CurrentFileName, rec)); } rec.TryFindFieldValue(new string[] { "Combat Tile" }, out temp, ref index, Mod.Errors, 0, true); if (temp == null) { Mod.Errors.Add(new DataParsingException("Could not find Combat Tile field for storm.", Mod.CurrentFileName, rec)); continue; } storm.CombatTile = temp; } else if (type == "Warp Point") { var wp = new WarpPoint(); sobj = wp; rec.TryFindFieldValue(new string[] { "Size", "Warp Point Size" }, out temp, ref index, Mod.Errors, 0, true); if (temp == null) { Mod.Errors.Add(new DataParsingException("Could not find Size field for warp point.", Mod.CurrentFileName, rec)); continue; } StellarSize size; if (Enum.TryParse <StellarSize>(temp, out size)) { wp.StellarSize = size; } else { Mod.Errors.Add(new DataParsingException("Invalid warp point size. Must be Tiny, Small, Medium, Large, or Huge.", Mod.CurrentFileName, rec)); } rec.TryFindFieldValue(new string[] { "One-Way", "Warp Point One-Way" }, out temp, ref index, Mod.Errors, 0, true); if (temp == null) { Mod.Errors.Add(new DataParsingException("Could not find One-Way field for warp point.", Mod.CurrentFileName, rec)); continue; } bool oneway; if (bool.TryParse(temp, out oneway)) { wp.IsOneWay = oneway; } else { Mod.Errors.Add(new DataParsingException("Invalid value " + temp + " for warp point One-Way field. Must be true or false.", Mod.CurrentFileName, rec)); } rec.TryFindFieldValue("Unusual", out temp, ref index, Mod.Errors, 0, true); if (temp == null) { Mod.Errors.Add(new DataParsingException("Could not find Unusual field for warp point.", Mod.CurrentFileName, rec)); continue; } bool unusual; if (bool.TryParse(temp, out unusual)) { wp.IsUnusual = unusual; } else { Mod.Errors.Add(new DataParsingException("Invalid value " + temp + " for warp point Unusual field. Must be true or false.", Mod.CurrentFileName, rec)); } } else { Mod.Errors.Add(new DataParsingException("Invalid stellar object type: " + type + ".", Mod.CurrentFileName, rec)); continue; } rec.TryFindFieldValue("Picture", out temp, ref index, null, 0, true); // ignore error for now, might use Picture Num if (temp == null) { rec.TryFindFieldValue("Picture Num", out temp, ref index, Mod.Errors, 0, true); if (temp == null) { Mod.Errors.Add(new DataParsingException("Could not find Picture field or Picture Num field.", Mod.CurrentFileName, rec)); continue; } int pnum; if (!int.TryParse(temp, out pnum)) { Mod.Errors.Add(new DataParsingException("Picture Num field was not an integer.", Mod.CurrentFileName, rec)); continue; } sobj.PictureName = "p" + (pnum + 1).ToString("0000"); // to match SE4 } else { sobj.PictureName = temp; } rec.TryFindFieldValue("Description", out temp, ref index, Mod.Errors, 0, true); sobj.TemplateParameters = rec.Parameters; sobj.Description = temp; sobj.ModID = rec.Get <string>("ID", sobj); mod.StellarObjectTemplates.Add(sobj); yield return(sobj); } }
void LoadGameData() { string json = File.ReadAllText(@"../game_data.json"); var json_parser = JObject.Parse(json); foreach (Station station in LoadType <Station>(json_parser, 1)) { var station_pos = new Vector3((float)station.position[0], 0f, world_height - (float)station.position[1]); var tilt_x = Random.Range(-80, -100); var tilt_y = Random.Range(0, 360); var station_game_object = Instantiate(station_model, station_pos, Quaternion.Euler(new Vector3(tilt_x, tilt_y, 0f))); station_game_object.name = station.name; station_objects.Add(station_game_object); // load billboard var raw_station_name = station_game_object.name.Split(' ')[0]; foreach (GameObject obj in billboards) { var raw_name = obj.name.Split(' ')[0]; if (raw_name == raw_station_name) { var offset = station_game_object.transform.position + new Vector3(8, 10, 0); var new_billboard = Instantiate(obj, offset, Quaternion.identity); var offset2 = station_game_object.transform.position + new Vector3(-8, 10, 0); var new_billboard_2 = Instantiate(obj, offset2, Quaternion.identity); } } } //load black market stations foreach (Station station in LoadType <Station>(json_parser, 2)) { var station_pos = new Vector3((float)station.position[0], 0f, world_height - (float)station.position[1]); var station_game_object = Instantiate(black_market_station_model, station_pos, Quaternion.identity); station_game_object.name = station.name; station_objects.Add(station_game_object); } // load secure station foreach (Station station in LoadType <Station>(json_parser, 3)) { var station_pos = new Vector3((float)station.position[0], 15f, world_height - (float)station.position[1]); var station_game_object = Instantiate(secure_station_model, station_pos, Quaternion.Euler(new Vector3(0f, 100f, 0f))); station_game_object.name = station.name; station_objects.Add(station_game_object); } // Load asteroid fields cuprite_field = LoadType <AsteroidField>(json_parser, 5)[0]; var cuprite_field_pos = new Vector3((float)cuprite_field.position[0], 0f, world_height - (float)cuprite_field.position[1]); var cuprite_field_game_object = Instantiate(cuprite_field_model, cuprite_field_pos, Quaternion.identity); cuprite_field_game_object.name = cuprite_field.name; goethite_field = LoadType <AsteroidField>(json_parser, 4)[0]; var goethite_field_pos = new Vector3((float)goethite_field.position[0], 0f, world_height - (float)goethite_field.position[1]); var goethite_field_game_object = Instantiate(goethite_field_model, goethite_field_pos, Quaternion.identity); goethite_field_game_object.name = goethite_field.name; gold_field = LoadType <AsteroidField>(json_parser, 6)[0]; var gold_field_pos = new Vector3((float)gold_field.position[0], 0f, world_height - (float)gold_field.position[1]); var gold_field_game_object = Instantiate(gold_field_model, gold_field_pos, Quaternion.identity); gold_field_game_object.name = gold_field.name; // Load ships foreach (Ship ship in LoadType <Ship>(json_parser, 0)) { ships.Add(ship); var ship_pos = new Vector3((float)ship.position[0], 0f, world_height - (float)ship.position[1]); var ship_game_object = Instantiate(ship_model, ship_pos, Quaternion.identity); //ship_game_object.name = ship.team_name; ship.gameObject = ship_game_object; ship_objects.Add(ship_game_object); ship_game_object.GetComponent <ShipController>().UpdateFromLog(ship); } }
// Use this for initialization void Start() { afScript = (AsteroidField)((GameObject)GameObject.Find("AsteroidField")).GetComponent("AsteroidField"); InvokeRepeating("generateAsteroid", 1.0f, genRate); }
public void StartNewFlight() { AsteroidField.StartNewFlight(); ShipController.StartNewFlight(); }
public void Update(float deltaTime) { ShipController.Update(deltaTime); AsteroidField.Update(deltaTime); }
private void Awake() { Instance = GetComponent <AsteroidField>(); }
public void Initialize(AsteroidField parentField) { ParentField = parentField; Asteroids = new List <Transform>(); }
public void setAsteroidField(AsteroidField af) { afScript = af; }
public AsteroidFieldRenderer(AsteroidField field, SystemRenderer sys) { this.field = field; this.sys = sys; //Set up renderDistSq float rdist = 0f; if (field.Zone.Shape is ZoneSphere) { rdist = ((ZoneSphere)field.Zone.Shape).Radius; } else if (field.Zone.Shape is ZoneEllipsoid) { var s = ((ZoneEllipsoid)field.Zone.Shape).Size; rdist = Math.Max(Math.Max(s.X, s.Y), s.Z); } else if (field.Zone.Shape is ZoneBox) { var s = ((ZoneEllipsoid)field.Zone.Shape).Size; rdist = Math.Max(Math.Max(s.X, s.Y), s.Z); } if (field.BillboardCount != -1) { billboardCube = new AsteroidBillboard[field.BillboardCount]; for (int i = 0; i < field.BillboardCount; i++) { billboardCube[i].Spawn(this); } calculatedBillboards = new AsteroidBillboard[field.BillboardCount]; } rdist += field.FillDist; renderDistSq = rdist * rdist; cubes = new CalculatedCube[4000]; _asteroidsCalculation = CalculateAsteroidsTask; if (field.Cube.Count > 0) { CreateBufferObject(); } //Set up band if (field.Band == null) { return; } if (bandShader == null) { bandShader = Shaders.AsteroidBand.Get(); _bsTexture = bandShader.Shader.GetLocation("Texture"); _bsCameraPosition = bandShader.Shader.GetLocation("CameraPosition"); _bsColorShift = bandShader.Shader.GetLocation("ColorShift"); _bsTextureAspect = bandShader.Shader.GetLocation("TextureAspect"); } Vector3 sz; if (field.Zone.Shape is ZoneSphere) { sz = new Vector3(((ZoneSphere)field.Zone.Shape).Radius); } else if (field.Zone.Shape is ZoneEllipsoid) { sz = ((ZoneEllipsoid)field.Zone.Shape).Size; } else { return; } sz.X -= field.Band.OffsetDistance; sz.Z -= field.Band.OffsetDistance; lightingRadius = Math.Max(sz.X, sz.Z); renderBand = true; bandTransform = ( Matrix4x4.CreateScale(sz.X, field.Band.Height / 2, sz.Z) * field.Zone.RotationMatrix * Matrix4x4.CreateTranslation(field.Zone.Position) ); bandCylinder = sys.ResourceManager.GetOpenCylinder(SIDES); }
static void ShowFieldRadi(AsteroidField field, GizmoType type) { //Gizmos.DrawWireSphere(field.transform.position, field.outerRadius); //Gizmos.DrawWireSphere(field.transform.position, field.innerRadius); }
protected override string Solve2(IEnumerable <string> inputs) { var field = new AsteroidField(inputs); var visibleFromRock = new SortedDictionary <double, SortedDictionary <float, (Vector2, Vector2)> >(); var rock = field.Asteroids.Where(x => x.X == 14 && x.Y == 17).Single(); foreach (var pair in field.Asteroids.MakePairs(rock)) { var length = Lengths(pair); var distance = Distance(pair); var quadrant = length.ToQuadrant(); double degrees; if (quadrant == Quadrant.Boundary) { degrees = (length.X == 0) ? (length.Y < 0 ? 0 : 180) : (length.X < 0 ? 270 : 90); } else { double toa = Math.Abs(length.Y) / (double)Math.Abs(length.X); var angle = Math.Atan(toa); degrees = RadianToDegree(angle); switch (quadrant) { case Quadrant.TopRight: degrees = 90 - degrees; break; case Quadrant.TopLeft: degrees = 270 + degrees; break; case Quadrant.BottomLeft: degrees = 270 - degrees; break; case Quadrant.BottomRight: degrees = 180 - degrees; break; default: throw new NotSupportedException($"{quadrant.ToString()} is not supported to calculate angle."); } } if (!visibleFromRock.ContainsKey(degrees)) { visibleFromRock.Add(degrees, new SortedDictionary <float, (Vector2, Vector2)>()); } visibleFromRock[degrees].Add(distance, (pair.Other, length)); } var key = visibleFromRock.Keys.ElementAt(199); return($"the 200th rock to be blasted is {visibleFromRock[key].First().Value.Item1}"); }
public AsteroidFieldRenderer(AsteroidField field, SystemRenderer sys) { this.field = field; this.sys = sys; //Set up renderDistSq float rdist = 0f; if (field.Zone.Shape is ZoneSphere) { rdist = ((ZoneSphere)field.Zone.Shape).Radius; } else if (field.Zone.Shape is ZoneEllipsoid) { var s = ((ZoneEllipsoid)field.Zone.Shape).Size; rdist = Math.Max(Math.Max(s.X, s.Y), s.Z); } else if (field.Zone.Shape is ZoneBox) { var s = ((ZoneEllipsoid)field.Zone.Shape).Size; rdist = Math.Max(Math.Max(s.X, s.Y), s.Z); } if (field.BillboardCount != -1) { astbillboards = new AsteroidBillboard[field.BillboardCount]; } rdist += field.FillDist; renderDistSq = rdist * rdist; cubes = new CalculatedCube[1000]; _asteroidsCalculation = CalculateAsteroids; if (field.Cube.Count > 0) { CreateBufferObject(); } //Set up band if (field.Band == null) { return; } if (bandShader == null) { bandShader = ShaderCache.Get("AsteroidBand.vs", "AsteroidBand.frag"); _bsTexture = bandShader.Shader.GetLocation("Texture"); _bsCameraPosition = bandShader.Shader.GetLocation("CameraPosition"); _bsColorShift = bandShader.Shader.GetLocation("ColorShift"); _bsTextureAspect = bandShader.Shader.GetLocation("TextureAspect"); } Vector3 sz; if (field.Zone.Shape is ZoneSphere) { sz = new Vector3(((ZoneSphere)field.Zone.Shape).Radius); } else if (field.Zone.Shape is ZoneEllipsoid) { sz = ((ZoneEllipsoid)field.Zone.Shape).Size; } else { return; } sz.Xz -= new Vector2(field.Band.OffsetDistance); lightingRadius = Math.Max(sz.X, sz.Z); renderBand = true; bandTransform = ( Matrix4.CreateScale(sz.X, field.Band.Height / 2, sz.Z) * field.Zone.RotationMatrix * Matrix4.CreateTranslation(field.Zone.Position) ); bandCylinder = new OpenCylinder(SIDES); bandNormal = bandTransform; bandNormal.Invert(); bandNormal.Transpose(); }
public override void Initialize() { float aspectRatio = game.GraphicsDevice.Viewport.AspectRatio; #region Load Models //Load Models Vector3 initPlayerPosition = new Vector3(0, 0, 0); player = new Player(game, initPlayerPosition, 5f); moon = new Planet(game, new Vector3(0, 0, 9000), 300f, "moon"); game.Components.Add(player); game.Components.Add(moon); #endregion #region Load Cameras //Load Cameras thirdPersonCam = new _3rdPersonCam(game, (player.getPosition()), player, Vector3.Up, aspectRatio); flyByCam = new StaticCam(game, player, Vector3.Up, aspectRatio); firstPersonCam = new FirstPersonCam(game, player.getPosition(), Vector3.Up, aspectRatio); availableCameras = new Queue<Camera>(); availableCameras.Enqueue(thirdPersonCam); availableCameras.Enqueue(flyByCam); currentCam = availableCameras.Dequeue(); #endregion #region setup game objects cameras and draw order asteroidField = new AsteroidField(game, currentCam); game.Components.Add(asteroidField); player.setCamera(currentCam); player.DrawOrder = 3; moon.setCamera(currentCam); moon.DrawOrder = 3; skybox = new Skybox(game, currentCam, "Space"); skybox.DrawOrder = 1; game.Components.Add(skybox); #endregion #region initialize controls input = new Control(game, player, thirdPersonCam, false); game.Components.Add(input); #endregion collisonDetector = new Collision(game); game.Components.Add(collisonDetector); #region Audio //game.getMusicPlayer().playRandomTrack(); #endregion optionsHaveChanged(); }
private AsteroidField InitializeField() { field = new AsteroidField(Game, camera, 100.0f,hud); field.DrawOrder = 1; Game.Components.Add(field); return field; }