Пример #1
0
    /*** Script Methods ***/
    // Use this for initialization
    void Start()
    {
        /*** Init. Game System ***/

        // Default camera zoom
        Camera.main.orthographicSize = Globals.MinCameraSize + (Globals.MaxCameraSize - Globals.MinCameraSize) / 2.0f;

        // Instantiate all game-level objects
        SManager = gameObject.AddComponent(typeof(SpriteManager)) as SpriteManager;
        ProjManager = gameObject.AddComponent(typeof(ProjectileManager)) as ProjectileManager;
        ShipManager = gameObject.AddComponent(typeof(ShipsManager)) as ShipsManager;
        SceneManager = gameObject.AddComponent(typeof(SceneryManager)) as SceneryManager;
        ResManager = gameObject.AddComponent(typeof(ResourceManager)) as ResourceManager;
        BuildingManager = gameObject.AddComponent(typeof(BuildingManager)) as BuildingManager;
        AManager = gameObject.AddComponent(typeof(AudioManager)) as AudioManager;
        SongManager = gameObject.AddComponent(typeof(AudioSystem)) as AudioSystem;
        OverlayView = gameObject.AddComponent(typeof(GameOverlay)) as GameOverlay;
        ContextMenuView = gameObject.AddComponent(typeof(GameContextMenu)) as GameContextMenu;

        /*** Background System ***/

        // Allocate the background sprites
        BackgroundSprites = new Sprite[BackgroundLayerCount];
        for(int i = 0; i < BackgroundLayerCount; i++)
        {
            // Alloc and retain
            Sprite Background = new Sprite("Textures/BGLayer" + i);
            BackgroundSprites[i] = Background;

            // Make the sprite geometry as big as the max camera, and center it on the camera
            BackgroundSprites[i].SetGeometrySize(new Vector2(Globals.MaxCameraSize, Globals.MaxCameraSize) * 2.5f * Camera.main.aspect);
            BackgroundSprites[i].SetPosition(-BackgroundSprites[i].GetGeometrySize() / 2.0f);
            BackgroundSprites[i].SetDepth(Globals.BackgroundDepth - i); // Each layet is closer to the camera

            // Register sprite
            SManager.AddSprite(Background);
        }

        /*** Add Scene Elements & Load Enemey Spawn List ***/

        // Load the level gen. (note that we finish loading in the "OnLevelWasLoaded" because
        // of a Unity3D-specific design issue
        LevelLoaded = false;
        LevelGen = new LevelManager(TargetLevel);

        /*** TESTING: Add temp ships ***/

        // Create a few ships destroyers bottom right
        for(int i = 0; i < 6; i++)
        {
            int x = UnityEngine.Random.Range(-500, 500);
            int y = UnityEngine.Random.Range(-500, 500);

            BaseShip Friendly = null;
            if(i == 0)
                Friendly = new CarrierShip();
            else if(i == 1)
                Friendly = new DestroyerShip();
            else
                Friendly = new FighterShip();
            Friendly.SetPos(new Vector2(x, y));
            ShipManager.ShipsList.Add(Friendly);
        }
    }
Пример #2
0
    public override void Update(float dt)
    {
        base.Update(dt);

        if(m_ShipLine.Count <= 0)
            return;

        if(m_ShipPool.Count >= m_ShipCapacity)
            m_CurrShipTime = 0.001f;
        else
            m_CurrShipTime -= dt;

        if(m_CurrShipTime <= 0.0f)
        {
            m_CurrShipTime = m_BuildCoolDown;

            if(m_ShipLine.Count > 0 && m_ShipPool.Count < m_ShipCapacity)
            {
                ShipQItem qItem = m_ShipLine.Dequeue();

                BaseShip newShip = null;
                if(qItem.ConfigName.EndsWith("carrierconfig.txt", StringComparison.OrdinalIgnoreCase))
                    newShip = new CarrierShip();
                else if(qItem.ConfigName.EndsWith("destroyerconfig.txt", StringComparison.OrdinalIgnoreCase))
                    newShip = new DestroyerShip();
                else if(qItem.ConfigName.EndsWith("fighterconfig.txt", StringComparison.OrdinalIgnoreCase))
                    newShip = new FighterShip();
                else if(qItem.ConfigName.EndsWith("minerconfig.txt", StringComparison.OrdinalIgnoreCase))
                    newShip = new MinerShip(this);
                else
                    Debug.LogError("No matching ship type found: " + qItem.ConfigName);

                newShip.SetPos(Position + qItem.Offset);
                Globals.WorldView.ShipManager.ShipsList.Add(newShip);
                m_ShipPool.Add(newShip);
            }
        }
    }