Example #1
0
        public void TwoBodyGravityTest()
        {
            var Ganymede = new PlanetaryBody("Ganymede");
            var gpos     = new Vector3(3, 0, 0);
            var Callisto = new PlanetaryBody("Callisto");
            var cpos     = new Vector3(5, 0, 0);

            var res = PlanetarySystem.Step(new[] { (gpos, Vector3.Zero), (cpos, Vector3.Zero) });
Example #2
0
    // Start is called before the first frame update
    void Start()
    {
        Universe uni = Universe.Instance;

        uni.AddSolarSystem();

        for (int i = 0; i < uni.Systems.Count; i++)
        {
            // Iterate through Solar systems
            SolarSystem curr_sys = uni.Systems[i];
            for (int j = 0; j < curr_sys.Bodies.Count; j++)
            {
                // Get the Body
                PlanetaryBody curr_body = curr_sys.Bodies[j];

                // Get the position
                bool    isStar  = curr_body is Star;
                Vector3 bodyPos = RandomCartesianPosition(isStar, j);

                // Create the Game Object
                GameObject bodyGO = CreateBodyGameObject(bodyPos, curr_body, isStar);

                // Create the orbit
                GameObject orbitGO = CreateOrbitPath(curr_body.Name + "Orbit", j + 1, this.gameObject);

                // Add it to our Dict
                curr_sys.BodyToObjectMap.Add(curr_sys.Bodies[j], bodyGO);
            }
        }

        ac = FindObjectOfType <AudioController>();
        if (ac == null)
        {
            Debug.LogError("No Audio Controller found!!");
        }

        foreach (VictoryCondition vic in FindObjectsOfType <VictoryCondition>())
        {
            Debug.Log("We found one!");
            victories.Add(vic);
        }

        player = FindObjectOfType <PlayerManager>();
        if (player == null)
        {
            throw new System.Exception("No player found!");
        }

        screen = FindObjectOfType <ScreenManager>();
        if (screen == null)
        {
            throw new System.Exception("No Screen found!");
        }

        UpdateColonisedPlanets();
    }
Example #3
0
    // Update is called once per frame
    void Update()
    {
        // Mouse interaction with the Universe
        Ray        mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit      = new RaycastHit();

        if (Physics.Raycast(mouseRay, out hit) && Input.GetMouseButtonDown(0))
        {
            if (currentlySelectedGO != null && currentlySelectedGO.Equals(hit.transform.gameObject))
            {
                // Double clicked
                if (currentlySelectedGO.tag.Equals("Body"))
                {
                    Debug.Log("Double Clicked on " + lastSelectedBody);
                    screen.ShowSelectionDialogue(lastSelectedBody);
                }
                else if (currentlySelectedGO.tag.Equals("Ship"))
                {
                    Debug.Log("Double Clicked on " + lastSelectedShip);
                    screen.ShowSelectionDialogue(lastSelectedShip);
                }

                ac.PlaySoundEffect(ac.SoundFX[0], false);
            }
            else
            {
                currentlySelectedGO = hit.transform.gameObject;
                if (currentlySelectedGO.tag.Equals("Body"))
                {
                    lastSelectedBody = Universe.Instance.Systems[0].GetBodyFromGameObject(currentlySelectedGO);
                    Debug.Log("Clicked on " + lastSelectedBody);
                }
                else if (currentlySelectedGO.tag.Equals("Ship"))
                {
                    lastSelectedShip = player.shipMan.GetShipFromGameObject(currentlySelectedGO);
                    Debug.Log("Clicked on " + lastSelectedShip);
                }

                ac.PlaySoundEffect(ac.SoundFX[1], false);
            }
        }


        if (victories != null)
        {
            foreach (VictoryCondition vic in victories)
            {
                if (vic.PlayerMeetsConditions(player))
                {
                    // Player has won!
                    Debug.Log("Player wins!");
                }
            }
        }
    }
Example #4
0
    // Creates a GameObject and sets its position
    private GameObject CreateBodyGameObject(Vector3 pos, PlanetaryBody body, bool isStar)
    {
        GameObject toReturn;

        if (isStar)
        {
            //Debug.Log("Creating star");
            toReturn = Instantiate(yellowStarPrefab);
        }
        else
        {
            toReturn = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        }
        toReturn.transform.position = pos;
        toReturn.name = body.Name;
        toReturn.tag  = "Body";
        toReturn.transform.SetParent(this.transform);

        return(toReturn);
    }
Example #5
0
    public void Initialize(PlanetaryBody parent, int planetNum)
    {
        base.Start();

        parentBody = parent;

        this.planetNum = planetNum;

        renderer = GetComponent<Renderer>();

        Size = localRNG.Next(MIN_SIZE, MAX_SIZE);

        homeStar = parentBody.GetComponent<SystemStar>();

        //Randomize Rotation Speed
        //rotationSpeed = localRNG.Next(MIN_ROTATION, MAX_ROTATION);

        // Set Planet Size
        transform.localScale = new Vector3(Size, Size, Size);

        // Orbit Speed is a function of distance from orbit parent (whether it be a planet or star)
        orbitSpeed = localRNG.Next(MIN_ORBIT_SPEED, MAX_ORBIT_SPEED);

        // Rotational offset
        initialRotationOffset = localRNG.Next(0, 360);

        // Randomize Location around orbit parent (for illusion of time passing)
        // Consider actually counting the amount of time the user has been away.
        transform.position = (transform.position - parentBody.transform.position).normalized*ORBIT_CONSTANT*planetNum +
                             parentBody.transform.position;
        transform.RotateAround(parentBody.transform.position, Vector3.forward, initialRotationOffset);

        System.TimeSpan dt = System.DateTime.Now - homeStar.discoveryTime;

        transform.RotateAround(parentBody.transform.position, Vector3.forward, -orbitSpeed*(float) dt.TotalSeconds);

        // Set Color
        if (planetNum <= 2)
        {
            _layeredSprite.Randomize((uint) localRNG.Next(), ref localRNG, "red");
        }
        else if (planetNum > 2 & planetNum < 4)
        {
            _layeredSprite.Randomize((uint) localRNG.Next(), ref localRNG, "green");
        }
        else
        {
            _layeredSprite.Randomize((uint) localRNG.Next(), ref localRNG, "blue");
        }

        // Draw orbit path (same color as planet)
        orbitPath = GetComponent<LineRenderer>();
        orbitPath.materials[0].color = Color.gray;

        // Draw the orbit.
        DrawOrbit();

        // Randomize Moons
        /* add moons after
        if (orbitParent.tag == SystemStar.TAG && Random.value <= MOON_CHANCE)
        {
            int numMoons = Random.Range(1, MAX_MOONS + 1);
            BuildMoons(numMoons);
        }
        */
    }