Ejemplo n.º 1
0
    void Awake()
    {
        instance = this;

        deathScreen.gameObject.SetActive(false);

        List <Transform> walls = generateMapBounds();

        HumanTankController = Instantiate(humanTankContPrefab, tankRoot, false);
        HumanTankController.Init(
            new Vector3(300, -800, 0),
            0,
            PlayerManager.Instance.TankSchematic);

        Dictionary <string, object> data = DataPasser.Instance.RetrieveData();
        TankSchematic enemyTankSchem     = ((EnemyInfo)data["Opponent"]).TankSchem;

        AITankController = Instantiate(aiTankContPrefab, tankRoot, false);
        AITankController.Init(
            new Vector3(300, 800, 0),
            180f,
            enemyTankSchem,
            HumanTankController.SelfTank,
            walls);

        MainCamera.GetComponent <ObjectFollower>().SetObjToFollow(HumanTankController.SelfTank.gameObject);

        DisableMovement = false;
    }
Ejemplo n.º 2
0
    public virtual void Init(Vector2 startPos, float startRot, TankSchematic tankSchematic)
    {
        if (SelfTank != null)
        {
            Destroy(SelfTank.gameObject);
        }

        SelfTank = Instantiate(tankPrefab, this.transform, false);
        SelfTank.transform.position = startPos;
        SelfTank.Body.rotation      = startRot;

        SelfTank.Init(tankSchematic);
    }
Ejemplo n.º 3
0
    //protected void FixedUpdate() {
    //    // TODO: for testing only. Remove once done.
    //    //rotationTest();
    //    //velocityTest();
    //    //reachPosTest();
    //    //futurePredicTest();
    //}

    public void Init(Vector2 startPos, float startRot, TankSchematic tankSchematic, Tank targetTank, List <Transform> walls)
    {
        base.Init(startPos, startRot, tankSchematic);

        TargetTank = targetTank;
        Map        = new Map(CombatHandler.Instance.MapWidth, CombatHandler.Instance.MapHeight, CombatHandler.Instance.TileDim, walls);

        // TODO: for now, just manually fill up goals list.
        goals.Add(new AttackGoal(this));
        goals.Add(new ManeuverGoal(this));
        goals.Add(new DodgeGoal(this));
        curGoal = null;
    }
Ejemplo n.º 4
0
    private void loadEnemyInfo()
    {
        TextAsset jsonText = Resources.Load("EnemyConf") as TextAsset;

        JObject root = JObject.Parse(jsonText.text);

        foreach (var info in root)
        {
            string  name = info.Key;
            JObject jObj = (JObject)info.Value;

            TankSchematic schem = JSONUtility.LoadTankSchematic(jObj.Value <JObject>("Tank"));

            enemyInfoDict.Add(name, new EnemyInfo(name, schem));
        }
    }
Ejemplo n.º 5
0
    public void Init(TankSchematic tankSchematic)
    {
        tankGOConstructor.Init(tankSchematic);

        Hull = new HullPart(tankSchematic.HullSchematic, this);

        int count      = 0;
        int validCount = 0;

        foreach (WeaponPartSchematic weaponSchematic in tankSchematic.WeaponSchematics)
        {
            if (weaponSchematic != null)
            {
                RectTransform rect = tankGOConstructor.weaponGOs[validCount].GetComponent <RectTransform>();
                Vector2       dir  = tankSchematic.HullSchematic.OrigWeaponDirs[count];

                Vector2 weaponFireOffset = dir.normalized * rect.sizeDelta.y;

                // Then create weapon representation and add to hull
                WeaponPart part = new WeaponPart(weaponSchematic, weaponFireOffset, this);
                Hull.AddWeaponAtIdx(part, count);

                validCount += 1;
            }
            count += 1;
        }

        boxCollider.size = tankSchematic.HullSchematic.Size;

        float totalWeight = calculateTotalWeight() / 10f;

        this.body.mass = totalWeight;

        this.body.angularDrag = Hull.Schematic.AngularDrag;

        MaxArmour = calculateTotalArmour();

        ResetState();

        DisableMovement = false;

        initialized = true;
    }
Ejemplo n.º 6
0
    public void Init(TankSchematic tankSchematic)
    {
        HullPrefabInfo hullPrefabInfo = PartPrefabManager.Instance.GetHullPrefabInfoViaName(tankSchematic.HullSchematic.Name);

        LeftWheelGO  = Instantiate(hullPrefabInfo.WheelPrefab, this.transform, false);
        RightWheelGO = Instantiate(hullPrefabInfo.WheelPrefab, this.transform, false);

        LeftWheelGO.transform.localPosition  = new Vector3(-hullPrefabInfo.WheelXOffset, 0);
        RightWheelGO.transform.localPosition = new Vector3(hullPrefabInfo.WheelXOffset, 0);

        HullGO = Instantiate(hullPrefabInfo.HullPrefab, this.transform, false);

        Transform weaponRoot = HullGO.transform.Find("Turret");

        JetRoot = HullGO.transform.Find("Jets");

        weaponGOs = new List <GameObject>();
        int count = 0;

        foreach (WeaponPartSchematic weaponSchematic in tankSchematic.WeaponSchematics)
        {
            if (weaponSchematic != null)
            {
                // First initialize GO
                GameObject instance = Instantiate(PartPrefabManager.Instance.GetPrefabViaName(weaponSchematic.Name), weaponRoot, false);

                RectTransform rect = instance.GetComponent <RectTransform>();
                rect.pivot = new Vector2(0.5f, 0);
                rect.transform.localPosition = tankSchematic.HullSchematic.OrigWeaponPos[count];

                Vector2 dir   = tankSchematic.HullSchematic.OrigWeaponDirs[count];
                float   angle = Vector2.Angle(new Vector2(0, 1), dir);
                rect.transform.Rotate(new Vector3(0, 0, angle));

                weaponGOs.Add(instance);
            }
            count += 1;
        }

        initialized = true;
    }
Ejemplo n.º 7
0
    private void initEquippedPartsViaPlayerSchematic()
    {
        EquippedParts = new List <PartSlot>();

        TankSchematic playerSchematic = PlayerManager.Instance.TankSchematic;

        List <PartSchematic> schematics = new List <PartSchematic> {
            playerSchematic.HullSchematic,
        };

        schematics.AddRange(playerSchematic.WeaponSchematics);

        for (int i = 0; i < schematics.Count; ++i)
        {
            PartSchematic schematic = schematics[i];

            PartSchematic.PartType pType = (schematic != null) ? schematic.PType : PartSchematic.PartType.Weapon;

            EquippedParts.Add(new PartSlot(schematic, pType, i));
        }
    }
Ejemplo n.º 8
0
    private void updateTankDisplayToCurrent()
    {
        TankSchematic tankSchem = partSlotsToTankSchematic();

        tankHighlighter.UpdateTankDisplay(tankSchem);
    }
Ejemplo n.º 9
0
 private void loadPlayerTankSchematic(JObject root)
 {
     TankSchematic = JSONUtility.LoadTankSchematic(root.Value <JObject>("Tank"));
 }
Ejemplo n.º 10
0
 public void UpdateTankSchematic(TankSchematic schematic)
 {
     TankSchematic = schematic;
 }
Ejemplo n.º 11
0
    public override void Init(Vector2 startPos, float startRot, TankSchematic tankSchematic)
    {
        base.Init(startPos, startRot, tankSchematic);

        SelfTank.gameObject.layer = 9; // Player layer
    }
Ejemplo n.º 12
0
 public void UpdateTankDisplay(TankSchematic schematic)
 {
     tankGOConstructor.Clear();
     tankGOConstructor.Init(schematic);
 }
Ejemplo n.º 13
0
 public EnemyInfo(string name, TankSchematic tankSchem)
 {
     Name      = name;
     TankSchem = tankSchem;
 }