void Update() { if (origin) { Vector3 directVect = (origin.position + 2.5f * Time.deltaTime * (Vector3)GameState.asteroid.GetComponent <Rigidbody2D> ().velocity - transform.position).normalized; float angle = Mathf.Atan2(directVect.y, directVect.x) * Mathf.Rad2Deg; transform.eulerAngles = Vector3.forward * (angle + 90); transform.position = Vector3.SmoothDamp(transform.position, origin.position + 2.5f * Time.deltaTime * (Vector3)GameState.asteroid.GetComponent <Rigidbody2D> ().velocity, ref vel, smoothing); if ((transform.position - origin.position).magnitude < 0.5f) { smoothing = 0.05f; /* * if (GameState.player.transform.childCount > 0) { * print ("SHOOP"); * animationChild = GameState.player.transform.GetChild (0); * childRelativePos = animationChild.localPosition; * animationChild.SetParent (transform); * animationChild.localPosition = childRelativePos; * animationChild.GetComponent<Collider2D> ().enabled = false; * } */ if ((transform.position - origin.position).magnitude < 0.2f) { /* * if (animationChild) { * animationChild.SetParent (GameState.player.transform); * animationChild.GetComponent<Collider2D> ().enabled = true; * animationChild.localPosition = childRelativePos; * }*/ // print ("Destination Reached"); GameState.player.GetComponent <SpriteRenderer> ().enabled = true; if (GameState.player.GetComponent <PlayerCollision> ().holding) { GameState.player.GetComponent <PlayerCollision> ().heldObject.SetActive(true); } AsteroidInfo aI = destination.GetComponent <AsteroidInfo>(); if (aI != null) { aI.TriggerPulse(); } Destroy(gameObject); } } } }
private AsteroidInfo GetBestStation() { AsteroidInfo bestDetection = new AsteroidInfo(new Point(), new Point(), 0, 0); foreach (AsteroidInfo asteroid in Asteroids) { GetStationDetection(asteroid); if (asteroid.Detections > bestDetection.Detections) { bestDetection = asteroid; } } return(bestDetection); }
/// <summary> /// Checks for collisions between the ship and an asteroid /// </summary> /// <returns><c>true</c>, if the ship and asteroid collide <c>false</c> otherwise.</returns> bool ShipAstCollisionCheck(GameObject asteroid) { // get the asteroid info script from the asteroid astInfo = asteroid.GetComponent <AsteroidInfo> (); // check for overlapping // get the distance between centers (squared) float distance = (astInfo.Center - sInfo.Center).sqrMagnitude; // if a squared + b squared > c squared, they are colliding if (distance < (astInfo.Radius * astInfo.Radius) + (sInfo.Radius * sInfo.Radius)) { return(true); // they collide } else { return(false); } }
/// <summary> /// Check for collisions between the bullet and an asteroid /// </summary> /// <returns><c>true</c>, if collision was bulleted, <c>false</c> otherwise.</returns> /// <param name="asteroid">Asteroid.</param> bool BulletCollision(GameObject asteroid) { if (asteroid != null) // fixes an error on restart { // get the asteroid info script from the asteroid astInfo = asteroid.GetComponent <AsteroidInfo> (); // loop through the bullets to check for collisions foreach (GameObject bul in bullets) { // get the distance between the point and center float distance = (astInfo.Center - bul.transform.position).sqrMagnitude; // get the square radius float radSquared = astInfo.Radius * astInfo.Radius; // used to distinguish between big or small asteroids if (radSquared > 1.5f) { // collides if (distance < radSquared) { bullets.Remove(bul); Destroy(bul); return(true); // bullet is inside the radius hence colliding } } else // radii smaller than 1 cause issues { if (distance < radSquared + 1.5f) { bullets.Remove(bul); Destroy(bul); return(true); // bullet is inside the radius hence colliding } } } } return(false); // not colliding }
// public void SetSelf(Transform inT) // { // self = inT; // } public void CreateAsteroids() { AsteroidInfo dictionaryInfo = new AsteroidInfo(); // Spawns asteroid at a certain distance from the beacon as per grouping specs. Vector3 rndLocation = new Vector3(Random.Range(-grouping, grouping), Random.Range(-grouping, grouping), Random.Range(-grouping, grouping)) + transform.position; GameObject asteroid = GameObject.Instantiate(Resources.Load("Asteroids/asteroid"), rndLocation, Quaternion.identity) as GameObject; asteroid.transform.localScale = new Vector3(Random.Range(500, 3000), Random.Range(500, 3000), Random.Range(500, 3000)); asteroid.rigidbody.isKinematic = false; asteroid.name = "|Asteroid|" + ID.ToString() + "_0"; asteroid.GetComponent<AsteroidBehavior>().beacon = this; dictionaryInfo.gameObject = asteroid; dictionaryInfo.meshCol = asteroid.GetComponent<MeshCollider>(); dictionaryInfo.boxCol = asteroid.GetComponent<BoxCollider>(); dictionaryInfo.renderer = asteroid.GetComponent<Renderer>(); asteroidList.Add(asteroid.name, dictionaryInfo); for (int asteroidsSpawned = 1; asteroidsSpawned < asteroidsAtBeacon; ++asteroidsSpawned) { rndLocation = new Vector3(Random.Range(-grouping, grouping), Random.Range(-grouping, grouping), Random.Range(-grouping, grouping)) + transform.position; asteroid = GameObject.Instantiate(asteroid, rndLocation, Quaternion.identity) as GameObject; asteroid.transform.localScale = new Vector3(Random.Range(500, 3000), Random.Range(500, 3000), Random.Range(500, 3000)); asteroid.rigidbody.isKinematic = false; asteroid.name = "|Asteroid|" + ID.ToString() + "_" + asteroidsSpawned; asteroid.GetComponent<AsteroidBehavior>().beacon = this; dictionaryInfo = new AsteroidInfo(); dictionaryInfo.gameObject = asteroid; dictionaryInfo.meshCol = asteroid.GetComponent<MeshCollider>(); dictionaryInfo.boxCol = asteroid.GetComponent<BoxCollider>(); dictionaryInfo.renderer = asteroid.GetComponent<Renderer>(); asteroidList.Add(asteroid.name, dictionaryInfo); // Put beacon in AsteroidFields list for Beacons. } DisableAsteroids(); }
private void ReadXmlAsteroid(XmlReader reader) { XmlSerializer serializer = new XmlSerializer(typeof(AsteroidInfo)); asteroidInfo = (AsteroidInfo)serializer.Deserialize(reader); }
void EnableAsteroid(AsteroidInfo inInfo) { inInfo.renderer.enabled = true; inInfo.boxCol.enabled = true; inInfo.meshCol.enabled = true; }
void DisableAsteroid(AsteroidInfo inInfo) { inInfo.renderer.enabled = false; inInfo.boxCol.enabled = false; inInfo.meshCol.enabled = false; }
public IEnumerator SyncAsteroidsCo(Vector3[] scales, Vector3[] positions, Vector3[] rotations) { AsteroidInfo dictionaryInfo = new AsteroidInfo(); asteroidsAtBeacon = positions.Length; for (int asteroidsSpawned = 0; asteroidsSpawned < asteroidsAtBeacon; ++asteroidsSpawned) { GameObject asteroid = GameObject.Instantiate(Resources.Load("Asteroids/asteroid"), positions[asteroidsSpawned], Quaternion.Euler(rotations[asteroidsSpawned])) as GameObject; asteroid.transform.localScale = scales[asteroidsSpawned]; asteroid.rigidbody.isKinematic = false; asteroid.name = "|Asteroid|" + ID.ToString() + "_" + asteroidsSpawned; dictionaryInfo = new AsteroidInfo(); dictionaryInfo.gameObject = asteroid; dictionaryInfo.meshCol = asteroid.GetComponent<MeshCollider>(); dictionaryInfo.boxCol = asteroid.GetComponent<BoxCollider>(); dictionaryInfo.renderer = asteroid.GetComponent<Renderer>(); asteroidList.Add(asteroid.name, dictionaryInfo); yield return null; // Put beacon in AsteroidFields list for Beacons. } DisableAsteroids(); }
private void SwapToMapIcons() { foreach (GameObject asteroid in theAsteroids) { AsteroidInfo aI = asteroid.GetComponent <AsteroidInfo>(); SpriteRenderer sR = asteroid.GetComponent <SpriteRenderer>(); asteroid.GetComponent <SpriteRenderer>().sprite = aI.SensorMapIcon; sR.color = Color.white; if (GameState.asteroid.gameObject == asteroid.gameObject) { sR.sprite = PLAYERICO; //Debug.Log("MEMES ARE A HEALTHY DOSAGE OF MEDICINE REQUIRED TO DO THE THING YOU NEED TO LIVE YOUR LIVER"); } else { if (aI.hasSensors) { sR.sprite = aI.SensorMapIcon; } else { sR.sprite = aI.NonSenseMapIcon; } } // highlight them if they are in current path PathMaker pm = GameObject.FindGameObjectWithTag("GameController").GetComponent <PathMaker> (); //if (pm.path.ContainsValue (asteroid.transform)) { // asteroid.GetComponent<SpriteRenderer> ().color = new Color (sR.color.r + pm.highlightAmount, // sR.color.g + pm.highlightAmount, sR.color.b + pm.highlightAmount, 1); //} // draw plant icons if (aI.greenPlantCount > 0) { GameObject plantIcon = Instantiate(greenPlantIcon, new Vector3(0, 0, 0), Quaternion.identity) as GameObject; plantIcon.transform.parent = asteroid.gameObject.transform; plantIcon.transform.localPosition = new Vector3(0, plantIconOffset, 0); } if (aI.bluePlantCount > 0) { GameObject plantIcon = Instantiate(bluePlantIcon, new Vector3(0, 0, 0), Quaternion.identity) as GameObject; plantIcon.transform.parent = asteroid.gameObject.transform; plantIcon.transform.localPosition = new Vector3(0, -plantIconOffset, 0); } if (aI.yellowPlantCount > 0) { GameObject plantIcon = Instantiate(yellowPlantIcon, new Vector3(0, 0, 0), Quaternion.identity) as GameObject; plantIcon.transform.parent = asteroid.gameObject.transform; plantIcon.transform.localPosition = new Vector3(plantIconOffset, 0, 0); } if (aI.redPlantCount > 0) { GameObject plantIcon = Instantiate(redPlantIcon, new Vector3(0, 0, 0), Quaternion.identity) as GameObject; plantIcon.transform.parent = asteroid.gameObject.transform; plantIcon.transform.localPosition = new Vector3(-plantIconOffset, 0, 0); } } //also swap to mapIcons for ScapCloudCores foreach (GameObject cloud in theScrapClouds) { cloud.GetComponent <SpriteRenderer>().sprite = cloud.GetComponent <AsteroidInfo>().SensorMapIcon; } }
public void OnEnable() { info = GetComponent <AsteroidInfo>(); }
private void Start() { asteroid = gameObject.AddComponent <AsteroidInfo>(); asteroid.asteroidName = asteroidName; asteroid.chargeGauge = chargeGauge; }
void AsteroidsDeserialize() { if (iniWicoCraftSave == null) { return; } string sAsteroidSave; /* * if (AsteroidSaveFile == null) * sAsteroidSave = Storage; * else */ // sAsteroidSave = AsteroidSaveFile.GetPublicText(); sAsteroidSave = iniWicoCraftSave.GetSection(sAsteroidSection); // sAsteroidSave = iniMiner.GetSection(sAsteroidSection); if (sAsteroidSave.Length < 1) { // Echo("Saved information not available"); return; } if (sAsteroidSave == sLastAsteroidLoad) { return; // no changes in saved info. } asteroidsInfo.Clear(); double x1, y1, z1; sLastAsteroidLoad = sAsteroidSave; string[] atheStorage = sAsteroidSave.Split('\n'); int iLine = 0; int iCount = -1; if (atheStorage.Length < 2) { return; // nothing to parse } // Echo(atheStorage[iLine]); iCount = Convert.ToInt32(atheStorage[iLine++]); // Echo("total="+iCount); for (int j = 0; j < iCount; j++) { // Echo("#="+j); long eId; // Echo(atheStorage[iLine]); eId = Convert.ToInt64(atheStorage[iLine++]); BoundingBoxD box; // Echo(atheStorage[iLine]); ParseVector3d(atheStorage[iLine++], out x1, out y1, out z1); box.Min = new Vector3D(x1, y1, z1); // Echo(atheStorage[iLine]); ParseVector3d(atheStorage[iLine++], out x1, out y1, out z1); box.Max = new Vector3D(x1, y1, z1); AsteroidInfo ast = new AsteroidInfo(); ast.EntityId = eId; ast.BoundingBox = box; asteroidsInfo.Add(ast); // Echo("----"); } // Echo("EOL"); }
private void ReadJsonAsteroid(JToken token) { asteroidInfo = token.ToObject <AsteroidInfo>(); }
public override string Solve(string input, bool part2) { /*input = ".#..##.###...#######\r\n" + * "##.############..##.\r\n" + * ".#.######.########.#\r\n" + * ".###.#######.####.#.\r\n" + * "#####.##.#.##.###.##\r\n" + * "..#####..#.#########\r\n" + * "####################\r\n" + * "#.####....###.#.#.##\r\n" + * "##.#################\r\n" + * "#####.##.###..####..\r\n" + * "..######..##.#######\r\n" + * "####.##.####...##..#\r\n" + * ".#####..#.######.###\r\n" + * "##...#.##########...\r\n" + * "#.##########.#######\r\n" + * ".####.#.###.###.#.##\r\n" + * "....##.##.###..#####\r\n" + * ".#.#.###########.###\r\n" + * "#.#.#.#####.####.###\r\n" + * "###.##.####.##.#..##";*/ /*input = ".#....#####...#..\r\n" + * "##...##.#####..##\r\n" + * "##...#...#.#####.\r\n" + * "..#.....#...###..\r\n" + * "..#.#.....#....##";*/ map = input.Split(new string[] { "\n" }, StringSplitOptions.None); for (int y = 0; y < map.Length; y++) { string line = map[y].Replace("\r", ""); for (int x = 0; x < line.Length; x++) { if (line[x] == '#') { Asteroids.Add(new AsteroidInfo(new Point(x, y), new Point(), 0, 0)); } } } StationInfo = GetBestStation(); if (part2) { GetStationDetection(StationInfo); Dictionary <Point, List <AsteroidInfo> > AsteroidGroups = new Dictionary <Point, List <AsteroidInfo> >(); //Gruppieren foreach (AsteroidInfo asteroid in Asteroids) { if (!AsteroidGroups.ContainsKey(asteroid.Direction)) { AsteroidGroups.Add(asteroid.Direction, new List <AsteroidInfo>()); } AsteroidGroups[asteroid.Direction].Add(asteroid); } //Gruppen Sortieren var groups = AsteroidGroups.OrderBy(x => GetAsteroidAngle(x)); var orderedGroups = new Dictionary <Point, List <AsteroidInfo> >(); foreach (var asteroidGroup in groups) { var group = asteroidGroup.Value.OrderBy(x => x.Distance).ToList(); asteroidGroup.Value.Clear(); //Gruppeninhalt sortieren foreach (AsteroidInfo asteroid in group) { asteroidGroup.Value.Add(asteroid); } orderedGroups.Add(asteroidGroup.Key, asteroidGroup.Value); } Asteroids.Clear(); int pos = 0; while (orderedGroups.Count != 0) { if (pos >= orderedGroups.Count) { pos = 0; } Point currKey = orderedGroups.ElementAt(pos).Key; Asteroids.Add(orderedGroups[currKey][0]); orderedGroups[currKey].RemoveAt(0); if (orderedGroups[currKey].Count == 0) { orderedGroups.Remove(currKey); pos--; } pos++; } Console.SetCursorPosition(0, 1); Console.Write(input.Replace(".", " ")); for (int i = 0; i < Asteroids.Count; i++) { Console.SetCursorPosition(Asteroids[i].Position.X, Asteroids[i].Position.Y + 1); Console.Write(i == 0 ? 'X' : ' '); Console.SetCursorPosition(0, 0); Console.WriteLine("".PadLeft(Console.BufferWidth)); Console.SetCursorPosition(0, 0); Console.Write(string.Format("i = {0} Asteroid: {1}", i, Asteroids[i].ToString())); Thread.Sleep(50); } Console.Clear(); Point location = Asteroids[200].Position; return($"Vaporizing Asteroid#200 @{location.X}|{location.Y} CHECK: {location.X * 100 + location.Y}"); } return($"Maximale Asteroiden gefunden: {StationInfo.Detections} @{StationInfo.Position.X}|{StationInfo.Position.Y}"); }