void HomeViewModel_OnDownloadRequestCompleted(object sender, System.Net.DownloadStringCompletedEventArgs e) { IsBusy = false; try { if (e.Error == null) { NearestSpaceObject = JsonConvert.DeserializeObject<SpaceObject>(e.Result); IsError = false; Message = String.Empty; } else { IsError = true; Message = "We've failed to load your request"; } } catch (Exception ex) { IsError = true; Message = "We've failed to load your request"; } }
public void DrawOrbit(SpaceObject spaceObject) { GameObject orbit = new GameObject(spaceObject.Name + "_OrbitPath"); orbit.transform.SetParent(spaceObject.Orbit.OrbitCentre.UnityObject.transform); var orbitPath = orbit.AddComponent<LineRenderer>(); orbitPath.SetWidth(0.5f, 0.5f); orbitPath.material.shader = Shader.Find("Standard"); orbitPath.receiveShadows = false; orbitPath.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; orbitPath.material.SetColor("_TintColor", new Color(0.5f, 0.5f, 0.5f)); orbitPath.useWorldSpace = false; int segmentCount = Mathf.CeilToInt(spaceObject.Orbit.Period) * EarthYearInSeconds; if (segmentCount < 50) { segmentCount = 50; } if (segmentCount > 200) { segmentCount = 200; } orbitPath.SetVertexCount(segmentCount + 1); var step = spaceObject.Orbit.Period / segmentCount; for (int i = 0; i < (segmentCount + 1); i++) { var newPositionRadial = OrbitMechanics.CalculatePosition(step * i, spaceObject.Orbit); orbitPath.SetPosition(i, newPositionRadial.ToCartesian() * AUToWorldUnits + spaceObject.Orbit.OrbitCentre.UnityObject.transform.position); } foreach (SpaceObject orbitingObject in spaceObject.OrbitingObjects) { DrawOrbit(orbitingObject); } }
public SpaceObjectComponent(SpaceObject obj) { Object = obj; if (obj.TextureId != null) { //Texture = ServiceLocator.Instance.GetService<ContentManager>().Load<Texture2D>(obj.TextureId); } }
private void TransformPlanetsPosition(SpaceObject spaceObject) { var newPosition = spaceObject.CurrentPosition.ToCartesian() * AUToWorldUnits; Vector3 shift = new Vector3(0, 0, 0); if (spaceObject.Orbit != null) { shift = spaceObject.Orbit.OrbitCentre.UnityObject.transform.position; } spaceObject.UnityObject.transform.Translate(newPosition - spaceObject.UnityObject.transform.position + shift); foreach (SpaceObject orbitingObject in spaceObject.OrbitingObjects) { TransformPlanetsPosition(orbitingObject); } }
public static void SetPositionAtTime(float time, SpaceObject spaceObject) { if (spaceObject.Orbit != null) { spaceObject.CurrentPosition = CalculatePosition(time, spaceObject.Orbit); } else { spaceObject.CurrentPosition = new SphericalCoordinates(0, 0, 0); } foreach (SpaceObject orbitingObject in spaceObject.OrbitingObjects) { SetPositionAtTime(time, orbitingObject); } }
private void BuildSystemGameOjects(SpaceObject spaceObject, GameObject parentGameObject) { GameObject gameObject = GameObject.CreatePrimitive(PrimitiveType.Sphere); var planetMesh = gameObject.GetComponent<MeshRenderer>(); planetMesh.material.shader = Shader.Find("Particles/Additive"); planetMesh.material.SetColor("_TintColor", Color.blue); gameObject.name = spaceObject.Name; spaceObject.UnityObject = gameObject; var sizeScale = spaceObject.Size * EarthSizeToWorldUnits; gameObject.transform.SetParent(parentGameObject.transform); gameObject.transform.localScale = new Vector3(sizeScale, sizeScale, sizeScale); gameObject.transform.localPosition = spaceObject.CurrentPosition.ToCartesian() * AUToWorldUnits; foreach (SpaceObject orbitingObject in spaceObject.OrbitingObjects) { BuildSystemGameOjects(orbitingObject, gameObject); } }
private void GenerateTestSystem() { Star = new Star() { Mass = 1, Size = 1, Rotation = 30, System = this, Name = "Sol" }; var earth = new Planet() { Mass = 1, Size = 1, Rotation = 24, Name = "Earth", Orbit = new Orbit() { MeanDistance = 1, Period = 1, Eccentricity = 0.0167086f, Inclination = 7.155f, PeriapsisArgument= 114.207f, OrbitCentre = Star } }; var moon = new Moon() { Mass = 0.0123f, Size = 0.273f, Rotation = 27, Name = "Moon", Orbit = new Orbit() { MeanDistance = 0.00257f * 40, Period = 0.0739f, Eccentricity = 0.0549f, Inclination = 5.145f, OrbitCentre = earth } }; earth.OrbitingObjects.Add(moon); Star.OrbitingObjects.Add(earth); var jupiter = new Planet() { Mass = 317.8f, Size = 11.209f, Rotation = 9.925f, Name = "Jupiter", Orbit = new Orbit() { MeanDistance = 5.20260f, Period = 11.8618f, Eccentricity = 0.048498f, Inclination = 6.09f, PeriapsisArgument = 273.867f, OrbitCentre = Star } }; var ganymede = new Planet() { Mass = 0.025f, Size = 0.413f, Rotation = 9.925f, Name = "Ganymede", Orbit = new Orbit() { MeanDistance = 0.00715f * 120, Period = 0.0195f, Eccentricity = 0.0013f, Inclination = 2.214f, OrbitCentre = jupiter } }; var calisto = new Planet() { Mass = 0.018f, Size = 0.378f, Rotation = 9.925f, Name = "Calisto", Orbit = new Orbit() { MeanDistance = 0.0125f * 80, Period = 0.04569f, Eccentricity = 0.0074f, Inclination = 2.017f, OrbitCentre = jupiter } }; var io = new Planet() { Mass = 0.015f, Size = 0.286f, Rotation = 9.925f, Name = "Io", Orbit = new Orbit() { MeanDistance = 0.002819f * 250, Period = 0.00484f, Eccentricity = 0.0041f, Inclination = 2.213f, OrbitCentre = jupiter } }; Star.OrbitingObjects.Add(jupiter); jupiter.OrbitingObjects.Add(ganymede); jupiter.OrbitingObjects.Add(calisto); jupiter.OrbitingObjects.Add(io); var saturn = new Planet() { Mass = 95.159f, Size = 9.4492f, Rotation = 10.55f, Name = "Saturn", Orbit = new Orbit() { MeanDistance = 9.554909f, Period = 29.4571f, Eccentricity = 0.05555f, Inclination = 5.51f, PeriapsisArgument = 339.392f, OrbitCentre = Star } }; var titan = new Planet() { Mass = 0.0225f, Size = 0.404f, Rotation = 10.55f, Name = "Titan", Orbit = new Orbit() { MeanDistance = 0.00816f * 80, Period = 0.043f, Eccentricity = 0.0288f, Inclination = 8.348f, OrbitCentre = saturn } }; Star.OrbitingObjects.Add(saturn); saturn.OrbitingObjects.Add(titan); var uranus = new Planet() { Mass = 14.536f, Size = 4.007f, Rotation = 17.1f, Name = "Uranus", Orbit = new Orbit() { MeanDistance = 19.2184f, Period = 84.0205f, Eccentricity = 0.046381f, Inclination = 6.48f, PeriapsisArgument = 96.998f, OrbitCentre = Star } }; Star.OrbitingObjects.Add(uranus); var neptune = new Planet() { Mass = 17.147f, Size = 3.883f, Rotation = 16.02f, Name = "Neptune", Orbit = new Orbit() { MeanDistance = 30.110387f, Period = 164.8f, Eccentricity = 0.009456f, Inclination = 6.43f, PeriapsisArgument = 276.336f, OrbitCentre = Star } }; Star.OrbitingObjects.Add(neptune); var venus = new Planet() { Mass = 0.815f, Size = 0.9499f, Rotation = -5832.6f, Name = "Venus", Orbit = new Orbit() { MeanDistance = 0.723f, Period = 0.615f, Eccentricity = 0.006772f, Inclination = 3.86f, PeriapsisArgument = 54.884f, OrbitCentre = Star } }; Star.OrbitingObjects.Add(venus); var mars = new Planet() { Mass = 0.107f, Size = 0.533f, Rotation = 24.2f, Name = "Mars", Orbit = new Orbit() { MeanDistance = 1.523f, Period = 1.88f, Eccentricity = 0.0934f, Inclination = 5.65f, PeriapsisArgument = 286.502f, OrbitCentre = Star } }; Star.OrbitingObjects.Add(mars); var mercury = new Planet() { Mass = 0.055f, Size = 0.3829f, Rotation = 1407.5f, Name = "Mercury", Orbit = new Orbit() { MeanDistance = 0.387f, Period = 0.240f, Eccentricity = 0.205f, Inclination = 3.38f, PeriapsisArgument = 29.124f, OrbitCentre = Star } }; Star.OrbitingObjects.Add(mercury); //var mercury = new Planet() { Mass = f, Size = f, Rotation = f, Name = "Mercury", Orbit = new Orbit() { MeanDistance = f * 40, Period = f, Eccentricity = f, Inclination = f, PeriapsisArgument = f, OrbitCentre = Star } }; // var mercury = new Planet() { Mass = f, Size = f, Rotation = f, Name = "Mercury", Orbit = new Orbit() { MeanDistance = f * 40, Period = f, Eccentricity = f, Inclination = f, PeriapsisArgument = f, OrbitCentre = Star } }; // var mercury = new Planet() { Mass = f, Size = f, Rotation = f, Name = "Mercury", Orbit = new Orbit() { MeanDistance = f * 40, Period = f, Eccentricity = f, Inclination = f, PeriapsisArgument = f, OrbitCentre = Star } }; // var mercury = new Planet() { Mass = f, Size = f, Rotation = f, Name = "Mercury", Orbit = new Orbit() { MeanDistance = f * 40, Period = f, Eccentricity = f, Inclination = f, PeriapsisArgument = f, OrbitCentre = Star } }; // var mercury = new Planet() { Mass = f, Size = f, Rotation = f, Name = "Mercury", Orbit = new Orbit() { MeanDistance = f * 40, Period = f, Eccentricity = f, Inclination = f, PeriapsisArgument = f, OrbitCentre = Star } }; }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); SpaceObject obj = null; if (PhoneApplicationService.Current.State["CurrentSpaceObject"] != null) { obj = PhoneApplicationService.Current.State["CurrentSpaceObject"] as SpaceObject; } else { obj = new SpaceObject() { id_object = 1 }; } vm.InitCamera(viewfinderBrush, obj); if (NavigationContext.QueryString.TryGetValue("action", out action)) { if (action == "delete") NavigationService.RemoveBackEntry(); } }
// All space objects have health public SwordsmanAttackingState(SpaceObject _enemyObject, GameObject _currentGameObject, float _nextEnemyRange) { enemyObject = _enemyObject; currentGameObject = _currentGameObject; nextEnemyRange = _nextEnemyRange; // Begin attack approach isAttacking = true; //since queries cost so much, save some time and do one here. //offSet = DelegateAttackPosition(currentGameObject, enemyObject); }
public void DeleteObject(SpaceObject spaceObject) { this.SpaceObjects[Array.IndexOf(this.SpaceObjects, spaceObject)] = null; }
public void RotateObject(SpaceObject spaceObject, double angle) { ObjectAnimated?.Invoke(this, new AnimationEventArgs(this.CaptureGameState(spaceObject), angle)); spaceObject.Rotate(angle); }
// Use this for initialization void Start() { planets = new List <Planet>(); objects = new List <SpaceObject>(); ships = new List <Spaceship>(); // Znajdz wszystkie planety aktualnie w grze // ...i ustaw poczatkowe szybkosci planet var ps = GameObject.FindObjectsOfType <Planet>(); print("Planets: " + ps.Length); foreach (var p in ps) { planets.Add(p); // Znajdz 'rodzica' if (p.parent || p.children.Count < 1) { continue; } List <Planet> stack = new List <Planet>(); foreach (var c in p.children) { stack.Add(c); } print("Liczba dzieci: " + stack.Count); while (stack.Count > 0) { Planet child = stack[0]; stack.RemoveAt(0); Vector3 dir = child.transform.position - p.transform.position; Vector3 f = p.GetForceAt(child.transform.position); Matrix4x4 m = Matrix4x4.TRS(new Vector3(), Quaternion.Euler(0, 90, 0), new Vector3(1, 1, 1)); SpaceObject so = child.GetComponent <SpaceObject>(); float v = Mathf.Sqrt(f.magnitude * dir.magnitude / p.mass) * 20; print("Spd: " + v); so.spd += m.MultiplyPoint3x4(dir.normalized) * v + child.parent.GetComponent <SpaceObject>().spd; foreach (var c in child.children) { stack.Add(c); } } } // Znajdz wszystkie obiekty aktualnie w grze var os = GameObject.FindObjectsOfType <SpaceObject>(); print("Objects: " + os.Length); foreach (var o in os) { o.universe = this; objects.Add(o); } // Ustaw poczatkowa szybkosc graczy var ss = GameObject.FindObjectsOfType <Spaceship>(); print("Players: " + ss.Length); foreach (var s in ss) { Planet closest = GetClosest(s.transform.position); Vector3 dir = s.transform.position - closest.transform.position; Vector3 f = closest.GetForceAt(s.transform.position); Matrix4x4 m = Matrix4x4.TRS(new Vector3(), Quaternion.Euler(0, 90, 0), new Vector3(1, 1, 1)); SpaceObject so = s.GetComponent <SpaceObject>(); float v = Mathf.Sqrt(f.magnitude * dir.magnitude / closest.mass); so.spd += m.MultiplyPoint3x4(dir.normalized) * v + closest.GetComponent <SpaceObject>().spd; so.transform.LookAt(closest.transform.position); ships.Add(s); } if (asteroids > 0 && asteroid) { //print("Tworzenie asteroid..."); CreateAsteridField(asteroids, fieldradius, asteroid); } }
public virtual void SOCollided(SpaceObject collidedObject) { Selfdestruct (DamageSource.Unknown); }
public override void Collide(SpaceObject collider) { collider.TakeDamage(20, this); isdead = true; }
//Used when the user clicks in the painting area while using the insert tool. // This will create a new object when the user left-clicks, and delete the object // it is currently on when it is right clicked. private void painting_clicked_insert(MouseEventArgs e) { DrawPoint mouse = pb_Level.PointToClient(MousePosition); // Remove the object under the cursor. if (e.Button == MouseButtons.Right) { foreach (SpaceObject obj in currentlySelectedRoom.Objects.Reverse<SpaceObject>()) { XnaRectangle bb = obj.getBBRelativeToWorld(); /*texture = Image.FromFile(currdir + "\\" + obj.TextureName + ".png"); if (mouse.X > obj.Position.X && mouse.X < (obj.Position.X + texture.Width) && mouse.Y > obj.Position.Y && mouse.Y < (obj.Position.Y + texture.Height))*/ if (bb.Contains(Conversion.PointToPoint(mouse))) { currentlySelectedRoom.Objects.Remove(obj); if (obj == currentlySelectedObject) { currentlySelectedObject = null; } break; } } } // Add an object. if (e.Button == MouseButtons.Left) { if (rb_Doors.Checked) { makeDoor(mouse); } else { object textureName = lb_TextureList.SelectedItem; if (textureName != null) { texture = Image.FromFile(currdir + "\\" + textureDir + textureName.ToString()); MakeSpaceObject(textureDir + textureName.ToString(), texture, mouse); } } } }
/// <summary> /// Internal method used by SpaceObject.LocationID. It shouldn't be used from anywhere else. /// </summary> internal void AddSpaceObject(SpaceObject spaceObject) { _spaceObjects.Add(spaceObject.ID, spaceObject); SpaceObjectAdded?.Invoke(this, spaceObject); }
public void Update(SpaceObject space) { _cacheService.Update(space); SetCache(GenerateKey(space.Id.ToString()), space); }
/// <summary> /// Двигает отдельный космический объект /// </summary> /// <param name="obj">Объект</param> /// <param name="time">Время галактики</param> public static void Process(SpaceObject obj, double time) { obj.Move(time); }
/// <summary> /// Internal method used by SpaceObject.LocationID. It shouldn't be used from anywhere else. /// </summary> public void RemoveSpaceObject(SpaceObject spaceObject) { _spaceObjects.Remove(spaceObject.ID); SpaceObjectRemoved?.Invoke(this, spaceObject); }
public void AddSpaceObject(SpaceObject spaceObject) { if (spaceObject.GetFaction() == "Player") { m_PlayerShips.Add(spaceObject); if (spaceObject.GetSize() == "Small") { m_PlayerSmallShips.Add(spaceObject); if (spaceObject.GetClass() == "Interceptor") { m_PlayerInterceptors.Add(spaceObject); } else if (spaceObject.GetClass() == "HeavyAssault") { m_PlayerHeavyAssault.Add(spaceObject); } else if (spaceObject.GetClass() == "Lancer") { m_PlayerLancer.Add(spaceObject); } else if (spaceObject.GetClass() == "Support") { m_PlayerSupport.Add(spaceObject); } else if (spaceObject.GetClass() == "Bomber") { m_PlayerBomber.Add(spaceObject); } else { Debug.LogError("invalid class : " + spaceObject.GetClass() + " for space object : " + spaceObject.gameObject.name); } } else if (spaceObject.GetSize() == "Large") { m_PlayerLargeShips.Add(spaceObject); if (spaceObject.GetClass() == "AssaultFregate") { m_PlayerAssaultFregate.Add(spaceObject); } else if (spaceObject.GetClass() == "ArtilleryFregate") { m_PlayerArtilleryFregate.Add(spaceObject); } else if (spaceObject.GetClass() == "SupportFregate") { m_PlayerSupportFregate.Add(spaceObject); } else if (spaceObject.GetClass() == "AntiFighterFregate") { m_PlayerAntiFighterFregate.Add(spaceObject); } else { Debug.LogError("invalid class : " + spaceObject.GetClass() + " for space object : " + spaceObject.gameObject.name); } } else { Debug.LogError("invalid size : " + spaceObject.GetSize() + " for space object : " + spaceObject.gameObject.name); } } else if (spaceObject.GetFaction() == "Enemy") { m_EnemyShips.Add(spaceObject); if (spaceObject.GetSize() == "Small") { m_EnemySmallShips.Add(spaceObject); if (spaceObject.GetClass() == "Interceptor") { m_EnemyInterceptors.Add(spaceObject); } else if (spaceObject.GetClass() == "HeavyAssault") { m_EnemyHeavyAssault.Add(spaceObject); } else if (spaceObject.GetClass() == "Lancer") { m_EnemyLancer.Add(spaceObject); } else if (spaceObject.GetClass() == "Support") { m_EnemySupport.Add(spaceObject); } else if (spaceObject.GetClass() == "Bomber") { m_EnemyBomber.Add(spaceObject); } else { Debug.LogError("invalid class : " + spaceObject.GetClass() + " for space object : " + spaceObject.gameObject.name); } } else if (spaceObject.GetSize() == "Large") { m_EnemyLargeShips.Add(spaceObject); m_EnemyLargeShips.Add(spaceObject); if (spaceObject.GetClass() == "AssaultFregate") { m_EnemyAssaultFregate.Add(spaceObject); } else if (spaceObject.GetClass() == "ArtilleryFregate") { m_EnemyArtilleryFregate.Add(spaceObject); } else if (spaceObject.GetClass() == "SupportFregate") { m_EnemySupportFregate.Add(spaceObject); } else if (spaceObject.GetClass() == "AntiFighterFregate") { m_EnemyAntiFighterFregate.Add(spaceObject); } else { Debug.LogError("invalid class : " + spaceObject.GetClass() + " for space object : " + spaceObject.gameObject.name); } } else { Debug.LogError("invalid size : " + spaceObject.GetSize() + " for space object : " + spaceObject.gameObject.name); } } else { Debug.LogError("invalid faction : " + spaceObject.GetFaction() + " for space object : " + spaceObject.gameObject.name); } }
/// <summary> /// This method is designed to set the worker to various tasks. More to be done soon. /// </summary> private void SetWorkerTask(SpaceObject o, Worker unitWorker, Ray ray, RaycastHit hit, int unitsCount, int i ) { RaycastHit checkBuildingHit; if (Physics.Raycast(ray, out checkBuildingHit)) { if (checkBuildingHit.transform.GetComponent<ChristmasTree>() != null) { unitWorker.SetTask(checkBuildingHit.transform.gameObject); } else if (checkBuildingHit.transform.GetComponent<Warehouse>() != null) { unitWorker.SetTask(checkBuildingHit.transform.gameObject); } else { unitWorker.SetTask(ray.GetPoint(hit.distance), unitsCount, i); } } }
private void SetSwordsmanTask(SpaceObject o, Swordsman unitSwordsman, Ray ray, RaycastHit hit, int unitsCount, int i) { RaycastHit checkObjectHit; if (Physics.Raycast(ray, out checkObjectHit)) { SpaceObject so = checkObjectHit.transform.GetComponent<SpaceObject>(); if (so != null) { if (so.Transponder == TransponderType.Enemy) { unitSwordsman.SetTask(so.gameObject); } } else { unitSwordsman.SetTask(ray.GetPoint(hit.distance), unitsCount, i); } } }
public void AttackingMelee() { if (!isAttacking) { return; } var animator = currentGameObject.GetComponent<Animator>(); var navAgent = currentGameObject.GetComponent<NavMeshAgent>(); var swordsman = currentGameObject.GetComponent<Swordsman>(); if(enemyObject != null) { //Debug.Log("hit1"); goToTarget = enemyObject.transform.position - offSet; if (attackRecharge < attackSpeed) { attackRecharge += Time.deltaTime; animator.SetBool("Crouch", false); // Rotate to face enemy. Vector3 projectedToDefaultPlane = Vector3.ProjectOnPlane((enemyObject.transform.position - currentGameObject.transform.position), Vector3.up).normalized; Quaternion rotation = Quaternion.LookRotation(projectedToDefaultPlane); navAgent.updateRotation = false; currentGameObject.transform.rotation = Quaternion.Slerp(currentGameObject.transform.rotation, rotation, Time.deltaTime * 2); //if (Vector3.Distance(goToTarget, currentGameObject.transform.position) < 3f) //{ // navAgent.updatePosition = false; // currentGameObject.transform.position = Vector3.Lerp(currentGameObject.transform.position, goToTarget, Time.deltaTime); //} //else if(!navAgent.updatePosition) //{ // //Debug.Log("Lerp update position." + goToTarget); // goToTarget = navAgent.nextPosition; // currentGameObject.transform.position = Vector3.Lerp(currentGameObject.transform.position, goToTarget, Time.deltaTime * 5); // // update the position if we are close enough to the target. // if (Vector3.Distance(goToTarget, currentGameObject.transform.position) < .5f) // { // //Debug.Log("Nav update position."); // navAgent.updatePosition = true; // } //} } else if (Vector3.Distance(goToTarget, currentGameObject.transform.position) < 3f) { attackRecharge = 0; navAgent.stoppingDistance = 2f; animator.SetBool("Crouch", true); navAgent.updateRotation = true; enemyObject.TakeHealth(2); // needs to return to normal spot before updating the position. if(enemyObject.Health <= 0) { //Debug.Log("Lerp back to nav mesh Position: " + navAgent.nextPosition); goToTarget = navAgent.nextPosition; } } } else { //if (!navAgent.updatePosition) //{ // //Debug.Log("Lerp update position." + goToTarget); // goToTarget = navAgent.nextPosition; // currentGameObject.transform.position = Vector3.Lerp(currentGameObject.transform.position, goToTarget, Time.deltaTime * 5); // // update the position if we are close enough to the target. // if (Vector3.Distance(goToTarget, currentGameObject.transform.position) < .5f) // { // //Debug.Log("Nav update position."); // navAgent.updatePosition = true; // } //} } if(enemyObject == null) { // Set isAttacking to false if enemy is out of range. // That is the end of this script in that case. var nearestEnemy = RTSUnitQueryCollection.FindNearestIdentifiedType<SpaceObject>(currentGameObject, TransponderType.Enemy, 100); //make sure the agent will update position before moving to a new thing. This also includes decide whether to attack or not. //if (navAgent.updatePosition) //{ if (nearestEnemy != null) { enemyObject = nearestEnemy; //offSet = DelegateAttackPosition(currentGameObject, enemyObject); } else { isAttacking = false; } //} } //approach the designated target. if (isAttacking) { swordsman.SetTask(goToTarget, 1, 0, MillitarTask.Attack); } else { // Set this to its default state. navAgent.updateRotation = true; navAgent.updatePosition = true; animator.SetBool("Crouch", false); swordsman.SetTask(goToTarget, 1, 0); goToTarget = currentGameObject.transform.position; } }
public SpaceObject GetOrAdd(string id, SpaceObject document) { return(base.GetOrAdd(GenerateKey(id), document)); }
/// <summary> /// This is the default movement state. Used for testing, other units will inherit this behavior. /// </summary> private void SetSimpleTask(SpaceObject o, Ray ray, RaycastHit hit, int unitsCount, int i ) { var scm = o.transform.GetComponent<SimpleCharacterMove>(); if (scm != null) { if (Physics.Raycast(ray, out hit, float.PositiveInfinity, 1 << 8)) { //Debug.Log ("Move with SCM!"); //scm.Move (ray2.GetPoint (hit2.distance)); //move with SCM + AI scm.Move(ray.GetPoint(hit.distance), unitsCount, i); } } }
/// <summary> /// Predict the Location of a SpaceObject in number of turns /// </summary> /// <param name="obj"></param> /// <param name="turns"></param> /// <returns></returns> public Location PredictLocation(SpaceObject obj, int turns) { return(calculator.PredictLocationByMovement(obj, turns)); }
public static void Main() { //TODO: legge inn tall på måner Star sun = new Star("Sun", "Yellow", 1390000, 0, 0, (27 * 24)); sun.position[0] = 0; sun.position[1] = 0; List <SpaceObject> solarSystem = new List <SpaceObject> { //new Star("Sun", "Yellow", 1390000, 0, 0, (27 * 24)), sun, new Planet("Mercury", "Darkgrey", 2439, 57910, 88 * 24, 1416, 47, null), new Planet("Venus", "Beige", 6051, 108200, 225 * 24, 243, 35, null), new Planet("Earth", "Blue", 6371, 149600, 365 * 24, 24, 30, new List <Moon>() { new Moon("Moon", "White", 3475 / 2, 384400 / 1000, 30 * 24, 27 * 24, 1, null) }), new Planet("Mars", "Red", 3389, 227940, 687 * 24, 25, 24, new List <Moon>() { new Moon("Phobos", "Grey", 22 / 2, 9378 / 1000, 8, (int)(0.3 * 24), 2), new Moon("Deimos", "Off-white", 23 / 2, 9376 / 1000, 30, (int)(1.2 * 24), 1) }), new Planet("Jupiter", "Beige Red", 69911, 778330, 4333, 10, 13, new List <Moon>() { new Moon("Metris", "Grey", 22, 127969 / 1000, (int)(0.29 * 24), 0, 32), new Moon("Callisto", "Grey", 2400, 01883000 / 1000, (int)(16.7 * 24), (int)(16.7 * 24), 8), }), new Planet("Saturn", "Eggshell", 58232, 1429400, 10760, 11, 10, new List <Moon>() { new Moon("Pan", "Grey", 9655, 133583 / 1000, (int)(0.57 * 24), 0, 17) }), new Planet("Uranus", "Pale blue", 25362, 2870990, 30685, 17, 7, new List <Moon>() { new Moon("Ophelia", "Grey", 16, 53760 / 1000, (int)(0.376 * 24), 0, 10) }), new Planet("Neptune", "Blue", 24622, 4504300, 60190, 16, 5, new List <Moon>() { new Moon("Naiad", "Grey", 29, 48000 / 1000, (int)(0.29 * 24), 0, 12) }), new DwarfPlanet("Pluto", "Steel Red", 1188, 5913520, 90550, 6387 * 24, 4743, null), new AsteroidBelt("The asteroid belt", "Grey Rock", 69420), new Asteroid("243 Ida", "Grey", 16, 4280, 1767, 5, 420, null) }; Console.Write("Please enter time: "); String string_time = Console.ReadLine(); Console.Write("Please enter planet name: "); String planet_name = Console.ReadLine(); int time = convert_time(string_time); bool found = false; SpaceObject space_object = sun; foreach (SpaceObject obj in solarSystem) { if (obj.name == planet_name) { space_object = obj; found = true; } } if (!found) { Console.WriteLine(space_object.toString()); space_object.updatePosition(time, solarSystem[0]); Console.WriteLine(String.Format("x: {0}, y: {1}", space_object.position[0], space_object.position[1])); } Console.ReadLine(); }
private void OnMissileHit(SpaceObject spaceObject) { m_MissilesFired--; spaceObject.OnReset -= OnMissileHit; }
public BaseObject(SpaceObject parent) { SpaceObject = parent; GUID = parent.GUID; }
private void OnSpaceObjectDeactivated(SpaceObject spaceObject) { Despawn(spaceObject); }
public void AddObject(SpaceObject o) { objects.Add(o); }
public SystemMapScene(SpaceObject spaceObject) { CurrentSpaceObject = spaceObject; }
public void AddObject(SpaceObject spaceObject) { this.SpaceObjects[this.OffsetCoordinatesToIndex(spaceObject.ObjectCoordinates)] = spaceObject; }
protected override void UpdateDestructableObject() { input = Controls.Get().players[playerNum]; Vector2 move = new Vector2(); //find which direction to move this Player move.y += input.forward; move.y -= input.backward; move.x -= input.straifL; move.x += input.straifR; move.Normalize(); //find out how much to more this Player in the direction move *= accelerationPerSec * level.secsPerUpdate; //move this Player relative to its current angle if (input.relativeMovement) { ModifyVelocityRelative(move); } //move this Player relative to the screen else { ModifyVelocityAbsolute(move); } //turn this Player left or right if (input.turns) { angularVelocity += turnSpeed * input.turnL; angularVelocity -= turnSpeed * input.turnR; } //point this Player in a direction on the screen else { double toTurn = new Vector2(input.turnL - input.turnR, input.turnUp - input.turnDown).GetAngle(); if (!double.IsNaN(toTurn)) { angle = (float)toTurn; } } if (shootTimer > 0) { shootTimer--; } else if (input.shoot) { //reset shootTimer shootTimer = shootTimeSecs * level.updatesPerSec; //create a new lazerShot infront of this Player SpaceObject shot = level.CreateObject("LazerShotPF", new Vector2(0, 2).Rotate(angle) + position, angle); shot.velocity = velocity; shot.MoveForward(shotSpeed); shot.color = color; shot.team = team; level.score += SHOT_POINTS; } //update Items held by this Player and check to see if any were dropped for (int i = 0; i < theItems.Length; i++) { if (theItems[i] != null) { theItems[i].Holding(input.items(i)); if (input.pickupDrop && input.items(i)) { theItems[i].Drop(); } } } }
public int GetDistance(SpaceObject firstObject, SpaceObject secondObject) { return(this.CombatMap.GetDistance(firstObject.ObjectCoordinates, secondObject.ObjectCoordinates)); }
public override void SOCollided(SpaceObject collidedObject) { }
public bool CanMoveObjectTo(SpaceObject spaceObject, Hex.OffsetCoordinates destination) { return(this.PerformBFS(spaceObject.ObjectCoordinates, spaceObject.ActionsLeft).Keys.Contains(destination)); }
public override void TakeDamage(float damage, SpaceObject source) { isdead = true; }
/// <summary> /// Angles are at unit 1, multiply accordingly. /// </summary> /// <param name="self"></param> /// <param name="enemy"></param> /// <returns>A round Robin if there is 1 or more attackers already attacking.</returns> public static Vector3 DelegateAttackPosition(GameObject self, SpaceObject enemy) { Swordsman[] nearbyAttackers = RTSUnitQueryCollection.FindAndOrganizeAttackVectorForSwordsman(enemy, TransponderType.Friendly); //defalt case Vector3 attackAngle = Vector3.ProjectOnPlane((enemy.transform.position - self.transform.position), Vector3.up).normalized; if(nearbyAttackers.Length == 0) { //attack at the closest angle. return attackAngle; } else if(nearbyAttackers.Length >= 0) { // move clock wise by 1/8 * 360 Quaternion rotationOfAttack = Quaternion.Euler(0, nearbyAttackers.Length / 8 * 360, 0); return rotationOfAttack * attackAngle; } // shouldn't get here. return enemy.transform.position; }
void OnPlayerCollision(SpaceObject so) { var dmg = so.Size.magnitude; Player.HP -= dmg; _camEffects.HITIntensity = Mathf.Clamp(dmg,0,4); if (Player.HP <= 0) { GameOver(); } }
public void ComputeAttackRange(SpaceObject objectSelected) { m_AttackRangeTiles.Clear(); m_AttackRangeTiles = ActionManager.Instance.GetWeaponSelected().ComputeAttackRange(objectSelected); ComputeTargetInRange(); }
public PageViewModel(SpaceObject SO) { CurrentName = SO.CurrentName; Velocity = SO.Velocity; Size = SO.Size; }
public void InitCamera(VideoBrush currentVideoBrush,SpaceObject currentSpaceObject) { this.CurrentSpaceObject = currentSpaceObject; this.CurrentSpaceObject.OnChannelCreationCompleted += CurrentSpaceObject_OnChannelCreationCompleted; this.Camera = new PhotoCamera(CameraType.Primary); this.Camera.Initialized += Camera_Initialized; this.Camera.CaptureCompleted += Camera_CaptureCompleted; this.Camera.CaptureImageAvailable += Camera_CaptureImageAvailable; //Set the VideoBrush source to the camera. currentVideoBrush.SetSource(Camera); //create channel this.CurrentSpaceObject.CreateChannel(); }
private static void CheckColumn(SpaceObject cell, int i, int j) { var unstableList = new List <Coordinate>(); var asteroidsColumnList = new List <Coordinate>(); asteroidsColumnList.Add(cell.GridPosition); var unstableIsAdded = false; while (j < Map.GetLength(1) - 1 && Map[i, j + 1] != null && Map[i, j + 1].TypeOfObject == cell.TypeOfObject) { j++; asteroidsColumnList.Add(Map[i, j].GridPosition); } if (asteroidsColumnList.Count < 3) { return; } var listToDestroy = new List <Coordinate>(); foreach (var coordinate in asteroidsColumnList) { listToDestroy.Add(coordinate); } if (asteroidsColumnList.Count >= 5) { var coord = asteroidsColumnList.ElementAt(asteroidsColumnList.Count / 2); Map[coord.X, coord.Y].DestroyAsteroid(); listToDestroy.Remove(coord); unstableList.Add(coord); unstableIsAdded = true; } var bufRowList = new List <Coordinate>(); foreach (var asteroid in asteroidsColumnList) { j = asteroid.Y; i = asteroid.X; while (i < Map.GetLength(0) - 1 && Map[i + 1, j] != null && Map[i + 1, j].TypeOfObject == cell.TypeOfObject) { i++; bufRowList.Add(Map[i, j].GridPosition); } i = asteroid.X; while (i > 0 && Map[i - 1, j] != null && Map[i - 1, j].TypeOfObject == cell.TypeOfObject) { i--; bufRowList.Add(Map[i, j].GridPosition); } if (bufRowList.Count >= 5) { var coord = bufRowList.ElementAt(asteroidsColumnList.Count / 2); Map[coord.X, coord.Y].DestroyAsteroid(); listToDestroy.Remove(coord); unstableList.Add(coord); unstableIsAdded = true; } if (bufRowList.Count >= 2) { foreach (var coordinate in bufRowList) { listToDestroy.Add(coordinate); } if (!unstableIsAdded) { Map[asteroid.X, asteroid.Y].DestroyAsteroid(); listToDestroy.Remove(asteroid); unstableList.Add(asteroid); unstableIsAdded = true; } } bufRowList.Clear(); } HandleUnstableAsteroids(listToDestroy); foreach (var coordinate in listToDestroy .Where(x => Map[x.X, x.Y] != null && Map[x.X, x.Y].IsAsteroid())) { Map[coordinate.X, coordinate.Y].DestroyAsteroid(); } foreach (var coord in unstableList) { Game.SpaceObjectCreate(coord.X, coord.Y, SpaceObject.CharsToObjectTypes .First(x => x.Value == cell.TypeOfObject).Key, 0, true); } }
public void InitCurrentSpaceObject(SpaceObject obj) { CurrentSpaceObject = obj; }
void OnPlayerCollision(SpaceObject so) { HPBar.SetHP(_player.HP / _player.HP_MAX); }
public void CreateEvent(SpaceObject spaceObject,string access_token=null) { CreateEvent(spaceObject.id_object,access_token); }
//Switches the current room to the room toSwitchTo. This involves repainting the paint screen, //changing the title of the editor, making sure our currentlySelectedObject is null so we don't get //null pointers, and update the room being edited. private void switchRooms(Room toSwitchTo) { currentlySelectedObject = null; menu_door.Enabled = false; currentlySelectedRoom = toSwitchTo; updateTitle(); pb_Level.Refresh(); }
public void setTarget(SpaceObject newTarget) { this.target = newTarget; }
public Tuple <double, double> pos(SpaceObject planet, double tid, int skala) { var temp = planet.getPosition(tid); return(temp); }
public void AddObject(SpaceObject source) { SpaceCraft creature = null; switch (source) { case SpaceObject.None: break; case SpaceObject.LightShip: creature = new LightShip(this, _initialX, _initialY, _active, _shipSpeed, _counter, _hitpoints, _lifes); break; case SpaceObject.HeavyShip: creature = new HeavyShip(this, _initialX, _initialY, _active, _shipSpeed, _counter, _hitpoints, _lifes); break; case SpaceObject.EnemyShip: creature = AddEnemy(); break; case SpaceObject.ShotLeft: creature = AddShot(_leftShift); break; case SpaceObject.ShotRight: creature = AddShot(_rightShift); break; case SpaceObject.ShotEnemy: creature = AddEnemyShot(_shotEnemyShift); break; default: break; } if (_amountOfObjects >= _gameObjects.Length - 1) { Array.Resize(ref _gameObjects, _gameObjects.Length * 2); } for (int i = 0; i <= _amountOfObjects; i++) { if (_gameObjects[i] is null) { _gameObjects[i] = creature; ++_amountOfObjects; break; } if (!_gameObjects[i].Active) { _gameObjects[i] = creature; break; } } }
void Start() { rb = GetComponent <Rigidbody>(); spaceObject = GetComponent <SpaceObject>(); boxCollider = GetComponent <BoxCollider>(); }
public override void SOCollided(SpaceObject collidedObject) { if (this == gm.playerShip) { DamageShip (maxHP * 0.1f, DamageSource.Enviroment, true); } else if (collidedObject == gm.playerShip) { Selfdestruct (DamageSource.Player); } }
public string CollideWith(SpaceObject other) => this.EnsureThreadSafe(ref doubleDispatchObject) .Via(nameof(CollideWith), other, () => default(string) ?? throw new NotImplementedException());
//Draws an arbitrary space object to the drawing pane. // Note: Won't work for doors. private void drawSpaceObject(SpaceObject obj, PaintEventArgs e) { Image img = Image.FromFile(currdir + "\\" + obj.TextureName + ".png"); //In order to do rotations and scaling in windows forms, we need to determine where // the upper right, upper left, and lower left corners map to. We determine these, and // tell the graphics to draw the image. //Find the new point for the upper-left corner DrawPoint upper_left = Conversion.Vector2ToDrawPoint(obj.mapPointOnImage(0, 0)); //Find the new point for the upper-right corner float x_ur = obj.getOriginalWidth(); float y_ur = 0; DrawPoint upper_right = Conversion.Vector2ToDrawPoint( obj.mapPointOnImage(x_ur, y_ur)); //Find the new point for the lower-left corner float x_ll = 0; float y_ll = obj.getOriginalHeight(); DrawPoint lower_left = Conversion.Vector2ToDrawPoint(obj.mapPointOnImage(x_ll, y_ll)); //Define the point mapping. DrawPoint[] destmapping = {upper_left, upper_right, lower_left}; DrawRect srcrect = new DrawRect(0,0,img.Width / obj.NumberOfFrames,img.Height); //Draw the image with the specified position and scaling. e.Graphics.DrawImage(img, destmapping, srcrect, GraphicsUnit.Pixel); }
protected void CreateEvent(SpaceObject obj) { App.CurrentUser.CreateEvent(obj, SettingHelper.GetKeyValue<SocialAccount>("SocialAccount").access_token); }
//End of the callbacks, beginning of the helper fuctions //Used when the user clicks in the painting area while using the select tool. // This will select the object who's center is closest to the mouse. private void painting_clicked_select(MouseEventArgs e) { XnaPoint mousePosition = Conversion.PointToPoint(pb_Level.PointToClient(MousePosition)); currentlySelectedObject = null; //Find all possible objects that we might be selecting. List<SpaceObject> candidates = new List<SpaceObject>(); foreach (SpaceObject obj in currentlySelectedRoom.Objects) { if (obj.getBBRelativeToWorld().Contains(mousePosition)) { candidates.Add(obj); } } //If the room is the currently selected room, the player is not null, and the click is close enough // to the player's location, add the player to the list of possible candidates. if(currentState == State.EDITING_WORLD && currentlySelectedRoom == world.CurrentRoom && world.player != null && world.player.getBBRelativeToWorld().Contains(mousePosition)) { candidates.Add(world.player); } //Find the object whose center is closest to the current mouse position. If there is no // possible selection, then the currentlySelectedObject continues to be null. foreach (SpaceObject cand in candidates) { if (currentlySelectedObject == null || dist(mousePosition, cand.getCenterPoint()) < dist(mousePosition, currentlySelectedObject.getCenterPoint())) { currentlySelectedObject = cand; refreshResizeObjectBox(); } } //If the currently selected item is a door, enable the door menu item. Otherwise, disable it. if (currentlySelectedObject != null && currentlySelectedObject is Door) { menu_door.Enabled = true; } else { menu_door.Enabled = false; } // Set fields in Object Properties panel if (currentlySelectedObject != null) { tb_Damage.Enabled = false; // Only true if this is a hazard (below) tb_Rotation.Enabled = true; b_ApplyProperties.Enabled = true; b_Front.Enabled = true; tb_SLevel.Enabled = false; tb_Rotation.Text = (currentlySelectedObject.Rotation * 180.0f / MathHelper.Pi).ToString(); if (currentlySelectedObject is HazardStatic) { tb_Damage.Text = ((HazardStatic)currentlySelectedObject).Damage.ToString(); tb_Damage.Enabled = true; } else if (currentlySelectedObject is HazardDynamic) { // Other tb_Damage.Text = ((HazardDynamic)currentlySelectedObject).Damage.ToString(); tb_Damage.Enabled = true; } else if (currentlySelectedObject is Survivor || currentlySelectedObject is VanishWall) { tb_SLevel.Enabled = true; } SetScriptingFields(); } else { // Clear all the properties fields tb_Damage.Text = ""; tb_Rotation.Text = ""; tb_SLevel.Text = ""; b_ApplyProperties.Enabled = false; b_Front.Enabled = false; tb_Damage.Enabled = false; tb_Rotation.Enabled = false; tb_SLevel.Enabled = false; tb_Script.Text = ""; tb_Script.Enabled = false; cbox_Scripted.Checked = false; cbox_Scripted.Enabled = false; } }
public void Init(SpaceObject thisSO, GameObject sM) { thisServerObject = new SpaceObject(thisSO); spaceManager = sM; }