Exemplo n.º 1
0
 private void Update()
 {
     if (Input.GetMouseButtonUp(0))
     {
         if (pressedObject != null)
         {
             Vector2 forceTarget = (Vector2)pressedObject.transform.position;
             Vector2 forceOrigin = Camera.main.ScreenToWorldPoint(Input.mousePosition);
             float   mass        = pressedObject.GetComponent <Rigidbody2D>().mass;
             pressedObject.GetComponent <Rigidbody2D>().AddForce((forceTarget - forceOrigin) * mass * 40);
             pressedObject = null;
             SetSimulationPaused(false);
         }
     }
     if (Input.GetMouseButtonDown(0))
     {
         if (pressedObject == null)
         {
             Ray          ray        = Camera.main.ScreenPointToRay(Input.mousePosition);
             RaycastHit2D raycastHit = Physics2D.Raycast(ray.origin, ray.direction);
             if (raycastHit.collider != null)
             {
                 SpaceObject spaceObject = raycastHit.collider.GetComponent <SpaceObject>();
                 if (spaceObject != null)
                 {
                     pressedObject = spaceObject;
                     SetSimulationPaused(true);
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
    protected bool ValidTargetSize(SpaceObject target)
    {
        //Debug.Log (target.name);
        string objectType = target.GetObjectType();

        if (objectType == "Decor")
        {
            return(false);
        }
        else if (objectType == "Ship")
        {
            if (m_TargetSize == "Small")
            {
                return(true);
            }
            else if (m_TargetSize == "Medium" && target.GetComponent <Ship>().GetSize() != "Small")
            {
                return(true);
            }
            else if (m_TargetSize == "Large" && target.GetComponent <Ship>().GetSize() == "Large")
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        else
        {
            return(false);
        }
    }
 public void UpdateSpaceObject(SpaceObject spaceObject)
 {
     Mass.text      = spaceObject.Mass.ToString();
     XVelocity.text = spaceObject.GetComponent <SpaceObject>().CurrentVelocity.x.ToString();
     YVelocity.text = spaceObject.GetComponent <SpaceObject>().CurrentVelocity.y.ToString();
     ZVelocity.text = spaceObject.GetComponent <SpaceObject>().CurrentVelocity.z.ToString();
     XPosition.text = spaceObject.transform.position.x.ToString();
     YPosition.text = spaceObject.transform.position.y.ToString();
     ZPosition.text = spaceObject.transform.position.z.ToString();
 }
 public void ViewObject(SpaceObject spaceObject)
 {
     ObjectPanel.SetActive(true);
     CoordinatesObject = Instantiate(CoordinatesPrefab, spaceObject.transform.position, Quaternion.identity, spaceObject.transform);
     Mass.text         = spaceObject.Mass.ToString();
     XVelocity.text    = spaceObject.GetComponent <SpaceObject>().CurrentVelocity.x.ToString();
     YVelocity.text    = spaceObject.GetComponent <SpaceObject>().CurrentVelocity.y.ToString();
     ZVelocity.text    = spaceObject.GetComponent <SpaceObject>().CurrentVelocity.z.ToString();
     XPosition.text    = spaceObject.transform.position.x.ToString();
     YPosition.text    = spaceObject.transform.position.y.ToString();
     ZPosition.text    = spaceObject.transform.position.z.ToString();
 }
    public void Handle()
    {
        float angle = 360 / (float)m_SpawnAmount;

        for (int i = 0; i < m_SpawnAmount; i++)
        {
            Vector3     pushDirection = GetPushDirection(i, angle);
            SpaceObject asteroid      = SpawnAsteroidAtPosition(transform.localPosition + pushDirection);
            asteroid.GetComponent <AsteroidManager>().SetSmall();
            asteroid.GetComponent <IEngine>().
            Push(pushDirection * m_PushForce, Random.Range(0, 25));
        }
    }
Exemplo n.º 6
0
 public virtual void CheckDeath(SpaceObject victim)
 {
     if (victim.Health <= 0)
     {
         ScoreKeeper score = victim.GetComponent <ScoreKeeper>();
         if (score != null)
         {
             HUDController.instance.AddScore(score.GetScore());
         }
         if (victim.GetComponent <Player>() != null)
         {
             MainMenuController.instance.GameOver();
         }
         DestroyObject(victim.gameObject);
     }
 }
 public void CheckColour(SpaceObject spaceObject)
 {
     if (randomiseColour)
     {
         spaceObject.GetComponent <SpriteRenderer>().color = RandomColour();
     }
 }
Exemplo n.º 8
0
 public bool ValidTargetFaction(SpaceObject target)
 {
     if (m_TargetFaction == "Other" && target.GetComponent <SpaceObject> ().GetObjectType() == "Decor")
     {
         return(true);
     }
     if ((m_TargetFaction == "Same" && target.GetComponent <SpaceObject> ().GetFaction() == m_SpaceObject.GetFaction()) ||
         (m_TargetFaction == "Other" && target.GetComponent <SpaceObject> ().GetFaction() != m_SpaceObject.GetFaction()) ||
         (m_TargetFaction == "Self" && target.gameObject == m_SpaceObject))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 9
0
    public void SpawnMarker(SpaceObject spaceObject)
    {
        GameObject markerPrefab   = Resources.Load <GameObject>("Prefab/HUD/Marker");
        GameObject markerInstance = Instantiate(markerPrefab, spaceObject.transform.position, Quaternion.identity) as GameObject;

        markerInstance.GetComponent <Marker>().SetSpaceObject(spaceObject);
        markerInstance.GetComponent <Image>().sprite = spaceObject.GetComponent <Ship>().GetHUDMarker();
        markerInstance.transform.SetParent(GameObject.Find("HUD/Markers/IdentificationMarkers").transform);
    }
Exemplo n.º 10
0
    void setInitialValues(SpaceObject blast)
    {
        blast.damage = blastDamage;
        Vector2 dir   = new Vector2(player.transform.position.x, player.transform.position.y) - new Vector2(transform.position.x, transform.position.y);
        Vector2 force = dir.normalized * blastSpeed;

        force = CalculateShot(force);

        blast.GetComponent <Rigidbody2D>().velocity = force;
    }
Exemplo n.º 11
0
 private void Handle()
 {
     for (int i = 0; i < m_SpawnAmount; i++)
     {
         SpaceObject energyBall = ObjectPool.Get(m_SpawnOnDestroy);
         energyBall.transform.position = transform.position;
         Vector2 randomDir = Random.onUnitSphere;
         energyBall.GetComponent <IEngine>()?.Push(randomDir * m_PushForce, 0);
     }
 }
Exemplo n.º 12
0
 override public void setInitialValues(SpaceObject spaceObject)
 {
     spaceObject.AdjustSize(scale);
     spaceObject.AdjustSpeed(minSpeed, maxSpeed);
     spaceObject.AdjustMass(scale);
     if (overrideSprite != null)
     {
         SpriteRenderer spriteRenderer = spaceObject.GetComponent <SpriteRenderer>();
         spriteRenderer.sprite = overrideSprite;
     }
 }
Exemplo n.º 13
0
        private void UnPauseObj(SpaceObject obj)
        {
            if (obj.GetComponent <SpaceObject>().IsPaused)
            {
                obj.objRigidbody.simulated = true;

                pausedObjectsInUniverse.Remove(obj);
                activeObjectsInUniverse.Add(obj);

                obj.IsPaused = false;
            }
        }
 virtual public void setInitialValues(SpaceObject spaceObject)
 {
     if (randomiseTransparency)
     {
         SpriteRenderer spriteRenderer = spaceObject.GetComponent <SpriteRenderer>();
         Color          newColor       = spriteRenderer.color;
         float          newAlpha       = Random.Range(.4f, 1f);
         newColor.a           = newColor.a * newAlpha;
         spriteRenderer.color = newColor;
     }
     if (randomiseScale)
     {
         float newScale = Random.Range(.5f, 1f);
         spaceObject.AdjustSize(newScale);
     }
     if (overrideSprite != null)
     {
         SpriteRenderer spriteRenderer = spaceObject.GetComponent <SpriteRenderer>();
         spriteRenderer.sprite = overrideSprite;
     }
 }
Exemplo n.º 15
0
        private void UnGhostObj()
        {
            if (!ghostObject)
            {
                return;
            }
            else if (ghostObject == selectedObj)
            {
                ghostObject.GetComponent <SpriteRenderer>().color = Color.yellow;
            }
            else
            {
                ghostObject.GetComponent <SpriteRenderer>().color = Color.white;
            }

            if (Managers.GameState.Instance.IsState(Managers.GameState.EnumGameState.RUNNING))
            {
                UnPauseObj(ghostObject);
            }

            ghostObject = null;
        }
Exemplo n.º 16
0
    public void DamageMe(SpaceObject victim, float damage)
    {
        Debug.Log("damage to " + victim.gameObject.name + damage);
        victim.Health -= damage;
        Debug.Log(victim.gameObject.name + " health is " + victim.Health);
        CheckDeath(victim);

        //set player hp in hud
        if (victim.GetComponent <Player>() != null)
        {
            HUDController.instance.UpdatePlayerHP(victim.Health);
        }
    }
    void BuildActiveList()
    {
        int currentActive  = activeSpaceObjects.Count;
        int activeRequired = targetActiveCount - currentActive;

        for (int i = 0; i < pool.Length; i++)
        {
            if (activeRequired > 0)
            {
                SpaceObject spaceObject = pool[i];
                if (!spaceObject.gameObject.activeInHierarchy)
                {
                    Vector3 newPos = playerController.getRandomPosition(!(firstBuild && !avoidCentreDuringGeneration));
                    spaceObject.GetComponent <Transform>().position = newPos;
                    CheckColour(spaceObject);
                    CheckRotation(spaceObject);
                    spaceObject.gameObject.SetActive(true);
                    spaceObject.startMoving();
                    activeSpaceObjects.Add(spaceObject);
                    activeRequired--;
                }
            }
            else
            {
                break;
            }
        }

        GameObject[] debugVisible = GameObject.FindGameObjectsWithTag("VisibleInDebugMode");
        if (!playerController.debugMode)
        {
            foreach (GameObject debugObject in debugVisible)
            {
                if (debugObject.GetComponent <SpriteRenderer>() != null)
                {
                    debugObject.GetComponent <SpriteRenderer>().enabled = false;
                }
            }
        }
        else
        {
            foreach (GameObject debugObject in debugVisible)
            {
                if (debugObject.GetComponent <SpriteRenderer>() != null)
                {
                    debugObject.GetComponent <SpriteRenderer>().enabled = true;
                }
            }
        }
        firstBuild = false;
    }
Exemplo n.º 18
0
 public void ChangeTarget(SpaceObject target)
 {
     if (m_TargetsInRange.Contains(target))
     {
         Debug.Log("Valid target");
         m_TargetNumber = 0;
         m_SpaceObjectTargeted.GetTargetMarker().IsTargeted(false);
         m_SpaceObjectTargeted = target.GetComponent <SpaceObject>();
         m_SpaceObjectTargeted.GetTargetMarker().IsTargeted(true);
         SetWeaponTargeted(-1);
         ActionManager.Instance.GetWeaponSelected().PrepareEffect(m_SpaceObjectTargeted);
         ActionManager.Instance.GetWeaponSelected().GetWeaponAttackDisplayer().DisplayAttack(true);
         HUD.Instance.DisplayValidationButton(true);
     }
 }
Exemplo n.º 19
0
    void OnTriggerEnter(Collider other)
    {
        SpaceObject obj = other.GetComponent <SpaceObject>();

        if (obj != null && _parent != null)
        {
            // if enemy strikes enemy or asteroid => do nothing
            if (_parent.GetComponent <Enemy>() != null && (obj.GetComponent <Asteroid>() != null || obj.GetComponent <Enemy>() != null))
            {
                return;
            }
            obj.DamageMe(obj, _parent.DamageLevel);
            Destroy(gameObject);
        }
    }
 private void CheckRotation(SpaceObject spaceObject)
 {
     if (randomiseRotation)
     {
         transform.rotation = Random.rotation;
         Vector3 euler = transform.eulerAngles;
         euler.z = Random.Range(0.0f, 360.0f);
         transform.eulerAngles = euler;
     }
     if (resetRotation)
     {
         transform.rotation = Quaternion.identity;
         spaceObject.GetComponent <Rigidbody2D>().angularVelocity = 0;
     }
 }
Exemplo n.º 21
0
        private void GhostObj(SpaceObject obj)
        {
            if (!obj)
            {
                return;
            }
            else if (ghostObject)
            {
                UnGhostObj();
            }

            ghostObject = obj;
            ghostObject.GetComponent <SpriteRenderer>().color = Color.blue;

            PauseObj(ghostObject);
        }
Exemplo n.º 22
0
    public void Return(SpaceObject spaceObject)
    {
        if (spaceObject == null)
        {
            return;
        }

        PoolIdentifier poolIdentifier = spaceObject.GetComponent <PoolIdentifier>();

        if (poolIdentifier == null)
        {
            return;
        }

        int poolKey = poolIdentifier.PoolKey;

        m_Pool[poolKey].Enqueue(spaceObject);
    }
Exemplo n.º 23
0
        private bool SetSelectedObject(SpaceObject target)
        {
            bool success = false;

            if (selectedObj)
            {
                selectedObj.GetComponent <SpriteRenderer>().color = Color.white;
            }

            if (target)
            {
                target.GetComponent <SpriteRenderer>().color = Color.yellow;
                SelectedObj = target;

                success = true;
            }
            else
            {
                SelectedObj = null;
            }

            return(success);
        }
 private void CheckMouseInput()
 {
     if (Input.GetMouseButtonDown(0))
     {
         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if (Physics.Raycast(ray, out RaycastHit Hit))
         {
             SpaceObject Object = Hit.transform.GetComponent <SpaceObject>();
             if (Object)
             {
                 Debug.Log(VisiblePlanet);
                 if (VisiblePlanet)
                 {
                     TogglePlanetVisibility();
                     DelayedTogglePlanetVisibility();
                 }
                 UIManager.Instance.ViewObject(Object);
                 Object.GetComponent <Renderer>().material.SetInt("_isSelected", 1);
                 VisiblePlanet = Object.gameObject;
             }
         }
     }
 }
Exemplo n.º 25
0
        public override bool Shoot()
        {
            if (!CanShoot())
            {
                return(false);
            }

            SpaceObject so = parent.so;

            ammo -= 1.0f;
            so.ApplyForce(parent.transform.forward * recoil);

            GameObject  bgo = (GameObject)Instantiate(projectile, parent.transform.position, parent.transform.rotation);
            SpaceObject bso = bgo.GetComponent <SpaceObject>();

            bso.spd      = so.spd - parent.transform.forward * so.spd.magnitude * 0.1f;
            bso.universe = so.universe;
            bso.GetComponent <Projectile>().parent = parent;
            so.universe.AddObject(bso);

            delaycounter = delay;

            return(true);
        }