Esempio n. 1
0
    void OnTriggerEnter2D(Collider2D other)
    {
        //Debug.Log(_partVisuels.Count.ToString());
        //TODO: optimize

        //OtherShip?
        if (other.CompareTag("ShipDetector"))
        {
            //Debug.Log("other ship detected");
            _otherShips.Add(other.gameObject);
            return;
        }
        //Projectile?
        Projectile otherProj = other.GetComponent <Projectile>();

        if (otherProj != null && otherProj.firedFrom != _thisShipHash)
        {
            //WE HAVE BEEN HIT!

            //find closest object to hitpoint
            float          dist = Mathf.Infinity;
            ShipData.Parts part = null;
            foreach (ShipData.Parts aPart in _partVisuels.Keys)
            {
                float tempdist = Vector2.Distance(other.transform.position, _partVisuels[aPart].transform.position);
                if (tempdist < dist)
                {
                    dist = tempdist;
                    part = aPart;
                }
            }

            Destroy(other.gameObject);

            _ship.TakeDamage(other.GetComponent <Projectile>().GetProjInfo.Damage, new ShipData.intPos2(part.Column, part.Row));
        }
        //Floating Ship Part?
        DisconectedPart otherPart = other.GetComponent <DisconectedPart>();

        if (otherPart != null)
        {
            //We Found a free Part!

            ShipData.Parts newPart = otherPart.GetPart();
            if (_partVisuels.ContainsKey(newPart) == false)
            {
                AddParts(newPart);
            }

            //TODO add funtionality to assign the position of the object; insted of randomly.

            //Destroying
            Destroy(other.gameObject);
        }
    }
Esempio n. 2
0
    public void CreateTestShip(bool isPlayer)
    {
        if (isPlayer == true && currentPlayerShip != null)
        {
            Destroy(currentPlayerShip);
        }

        GameObject currentShip = (GameObject)Instantiate(shipPrefab, Vector3.zero, Quaternion.identity);

        if (isPlayer)
        {
            currentPlayerShip = currentShip;
        }
        else
        {
            currentShip.transform.position = new Vector2(Random.Range(-100, 100), Random.Range(-100, 100));
            currentShip.transform.rotation = Quaternion.Euler(0, 0, Random.Range(0, 360));
        }

        ShipManager newShipManager = currentShip.GetComponent <ShipManager>();

        List <ShipData.Parts> newShipParts = new List <ShipData.Parts>();

        //add a shield
        ShipData.Parts shield = new ShipData.Parts(10, ShipData.Parts.partTypes.shield, 10, 100);
        shield.AssignPosition(new ShipData.intPos2(0, 0));
        newShipParts.Add(shield);

        //add an engine (south)
        ShipData.Parts engine = new ShipData.Parts(10, ShipData.Parts.partTypes.engine, 10, 100);
        engine.AssignPosition(new ShipData.intPos2(0, -1));
        newShipParts.Add(engine);

        //add a gun (north)
        ShipData.Parts weapon = new ShipData.Parts(10, ShipData.Parts.partTypes.weapon, 10, 100);
        weapon.AssignPosition(new ShipData.intPos2(0, 1));
        newShipParts.Add(weapon);

        newShipManager.SetupShip(isPlayer, newShipParts);
    }
Esempio n. 3
0
    protected void CreatePartVisuel(ShipData.Parts part)
    {
        GameObject partObj = (GameObject)Instantiate(
            GControl.instance.partPrefab,
            Vector3.zero,
            transform.rotation);

        partObj.transform.SetParent(transform);
        partObj.transform.localPosition = PartColRowToLocalSpacePosition(part.Column, part.Row);
        partObj.GetComponentInChildren <TextMesh>().text = "C: " + part.Column.ToString() + "\nR: " + part.Row.ToString();
        partObj.name = "PartObj: " + part.GetPartType.ToString() + ". C: " + part.Column.ToString() + ". R: " + part.Row.ToString();
        switch (part.GetPartType)
        {
        case (ShipData.Parts.partTypes.engine):
            partObj.GetComponentInChildren <Renderer>().material.color = Color.green;
            break;

        case (ShipData.Parts.partTypes.armour):
            partObj.GetComponentInChildren <Renderer>().material.color = Color.yellow;
            break;

        case (ShipData.Parts.partTypes.weapon):
            partObj.GetComponentInChildren <Renderer>().material.color = Color.red;
            break;

        case (ShipData.Parts.partTypes.shield):
            partObj.GetComponentInChildren <Renderer>().material.color = Color.blue;
            break;

        default:
            partObj.GetComponentInChildren <Renderer>().material.color = Color.white;
            break;
        }

        _partVisuels.Add(part, partObj);
    }
Esempio n. 4
0
 // Unity functions
 void Awake()
 {
     part = new ShipData.Parts(10, ShipData.Parts.RandomPartType(), 10, 100);
 }
Esempio n. 5
0
 protected void RemovePartVisuels(ShipData.Parts part)
 {
     Destroy(_partVisuels[part]);
     _partVisuels.Remove(part);
 }
Esempio n. 6
0
 //Parts
 public void AddParts(ShipData.Parts newParts)
 {
     _ship.AddParts(newParts);
 }