예제 #1
0
파일: Enemy.cs 프로젝트: raimis001/brsd2015
    public static void create(string type, SpawnData data)
    {
        if (ShipData.enemyShips.ContainsKey(type))
        {
            Vector3  pos   = new Vector3(Mathf.Sin(data.angle), Mathf.Cos(data.angle), 0) * data.distance;
            HexaShip enemy = HexaShip.createShip(ShipData.enemyShips[type].ship, pos);
            enemy.speed = data.speed;
            enemy.type  = "enemy";

            return;
        }

        GameObject prefab = Resources.Load(type) as GameObject;

        if (prefab == null)
        {
            return;
        }

        float delay = 0f;

        for (int i = 0; i < data.count; i++)
        {
            float   angle = data.angle + (Random.Range(-10f, 10f) * Mathf.Deg2Rad);
            Vector3 pos   = new Vector3(Mathf.Sin(angle), Mathf.Cos(angle), 0) * data.distance;
            Enemy   enemy = (Instantiate(prefab, pos, Quaternion.identity) as GameObject).GetComponent <Enemy>();
            enemy.delay = delay;
            enemy.data  = data;

            delay += data.delay;
        }
    }
예제 #2
0
    public static DeviceData createDevice(int id, Transform parent)
    {
        DeviceData data = ShipData.devices[id];

        if (data.id == 0)
        {
            return(new DeviceData(data));
        }
        GameObject prefab = Resources.Load("devices/" + data.prefab) as GameObject;

        if (prefab == null)
        {
            return(null);
        }

        data            = new DeviceData(data);
        data.gameObject = HexaShip.Instantiate(prefab, parent.position, Quaternion.identity) as GameObject;
        data.gameObject.transform.parent = parent;
        data.gameObject.tag = parent.gameObject.tag;

        Device device = data.gameObject.GetComponent <Device>();

        if (device != null)
        {
            device.data = data;
        }

        return(data);
    }
예제 #3
0
    public static HexaShip createShip(Dictionary <TilePoint, DeviceData> data, Vector3 position)
    {
        HexaShip ship = (Instantiate(Resources.Load("Ship"), position, Quaternion.identity) as GameObject).GetComponent <HexaShip>();

        ship.shipData = data;

        return(ship);
    }
예제 #4
0
    public ShipData()
    {
        JSONNode json;

        if (!initMainData)
        {
            initMainData = true;
            Sprite[] sprites;
            sprites = Resources.LoadAll <Sprite>("textures/devices");
            for (int i = 0; i < sprites.Length; i++)
            {
                if (sprites[i].name.IndexOf("mainShip") > -1)
                {
                    string s = sprites[i].name.Remove(0, 8);
                    tiles.Add(int.Parse(s), sprites[i]);
                }
                if (sprites[i].name.IndexOf("pirateShip") > -1)
                {
                    string s = sprites[i].name.Remove(0, 10);
                    tilesPirate.Add(int.Parse(s), sprites[i]);
                }
            }
            tileResource = Resources.Load("Tile") as GameObject;

            json = JSONNode.Parse(Resources.Load <TextAsset>("Data/Devices").text)["devices"];
            for (int i = 0; i < json.Count; i++)
            {
                int id = int.Parse(json.AsObject.keyAt(i));
                devices.Add(id, new DeviceData(id, json[i]));
            }

            json = JSONNode.Parse(Resources.Load <TextAsset>("Data/MainShip").text);
            for (int i = 0; i < json["ship"].Count; i++)
            {
                ship.Add(new TilePoint(json["ship"][i]["x"].AsInt, json["ship"][i]["y"].AsInt), new DeviceData(json["ship"][i]["device"]["id"].AsInt, json["ship"][i]["device"]));
            }

            json = JSONNode.Parse(Resources.Load <TextAsset>("Data/Enemies").text)["enemies"];
            for (int i = 0; i < json.Count; i++)
            {
                enemyShips.Add(json.AsObject.keyAt(i), new EnemyData(json[i]));
            }
        }


        levels = new Dictionary <int, LevelData>();
        json   = JSONNode.Parse(Resources.Load <TextAsset>("Data/EnemyWaves").text)["levels"];
        for (int i = 0; i < json.Count; i++)
        {
            int id = int.Parse(json.AsObject.keyAt(i));
            levels.Add(id, new LevelData(json[i]));
        }
        levelCount = levels.Count;

        json           = JSONNode.Parse(Resources.Load <TextAsset>("Data/MainShip").text);
        knowledge      = json["properties"]["knowledge"].AsInt;
        scraps         = json["properties"]["scraps"].AsInt;
        scrapInventory = json["properties"]["scrapInventory"].AsInt;
        metals         = json["properties"]["metals"].AsInt;
        metalPrice     = json["properties"]["metalPrice"].AsInt;

        Gui.UpdateScraps();
        Gui.UpdateMetals();
        Gui.UpdateKnowledge();

        mainShip = HexaShip.createShip(ship, Vector3.zero);

        loadLevel(1);
    }