Example #1
0
    public void Refresh(PlaneCard card)
    {
        // Here, we're copying values from the card because we have to to interface with Unity.
        // However, we've arranged things so that this function gets called any time
        // the card gets modified.
        Fuselage.transform.localPosition        = Card.Fuselage.Pos;
        Fuselage.transform.localScale           = Card.Fuselage.Size.XYZ1();
        LeftWing.transform.localPosition        = new Vector2(-Card.Wing.Pos.x, Card.Wing.Pos.y);
        LeftWing.transform.localScale           = Card.Wing.Size.XYZ1();
        RightWing.transform.localPosition       = Card.Wing.Pos;
        RightWing.transform.localScale          = new Vector2(-Card.Wing.Size.x, Card.Wing.Size.y).XYZ1();
        LeftStabilizer.transform.localPosition  = new Vector2(-Card.Stabilizer.Pos.x, Card.Stabilizer.Pos.y);
        LeftStabilizer.transform.localScale     = Card.Stabilizer.Size;
        RightStabilizer.transform.localPosition = Card.Stabilizer.Pos;
        RightStabilizer.transform.localScale    = new Vector2(-Card.Stabilizer.Size.x, Card.Stabilizer.Size.y).XYZ1();

        if (Controller == null)
        {
            return;
        }
        var healthPct = ((float)Controller.HitPoints) / Controller.MaxHitPoints;
        var color     = Color.Lerp(Color.white, Color.Lerp(Color.red, Color.black, 0.2f), 1 - healthPct);

        Fuselage.color        = color;
        LeftWing.color        = color;
        RightWing.color       = color;
        LeftStabilizer.color  = color;
        RightStabilizer.color = color;
    }
Example #2
0
    public PlaneCard Refresh(PlaneCard card)
    {
        Fuselage.transform.localPosition        = Card.Fuselage.Pos;
        Fuselage.transform.localScale           = Card.Fuselage.Size.XYZ1();
        LeftWing.transform.localPosition        = new Vector2(-Card.Wing.Pos.x, Card.Wing.Pos.y);
        LeftWing.transform.localScale           = Card.Wing.Size.XYZ1();
        RightWing.transform.localPosition       = Card.Wing.Pos;
        RightWing.transform.localScale          = new Vector2(-Card.Wing.Size.x, Card.Wing.Size.y).XYZ1();
        LeftStabilizer.transform.localPosition  = new Vector2(-Card.Stabilizer.Pos.x, Card.Stabilizer.Pos.y);
        LeftStabilizer.transform.localScale     = Card.Stabilizer.Size;
        RightStabilizer.transform.localPosition = Card.Stabilizer.Pos;
        RightStabilizer.transform.localScale    = new Vector2(-Card.Stabilizer.Size.x, Card.Stabilizer.Size.y).XYZ1();

        if (Controller == null)
        {
            return(card);
        }
        var healthPct = ((float)Controller.HitPoints) / Controller.MaxHitPoints;
        var color     = Color.Lerp(Color.white, Color.Lerp(Color.red, Color.black, 0.2f), 1 - healthPct);

        Fuselage.color        = color;
        LeftWing.color        = color;
        RightWing.color       = color;
        LeftStabilizer.color  = color;
        RightStabilizer.color = color;

        return(card);
    }
Example #3
0
 public static PlaneCard PostDoc(PlaneCard existing)
 {
     if (existing.OnChanged != null)
     {
         existing.OnChanged(existing);
     }
     return(existing);
 }
Example #4
0
    public void Setup(PlaneCard card)
    {
        var viewTrf = (Transform)Instantiate(ViewPrefab, transform.position, transform.rotation);

        viewTrf.parent  = transform;
        View            = viewTrf.GetComponent <PlaneView>();
        View.Controller = this;

        UseCard(card);
    }
Example #5
0
    void StartGame()
    {
        m_sw.Stop();
        UnityEngine.Debug.Log("Config parsing ms: " + m_sw.ElapsedMilliseconds);

        // PlaneCards are loaded on first access so this call to LoadConfigs is
        // functionally unncessary, but since we're taking a framerate hit with
        // LoadLevel, might as well make it a tiny bit longer and load the cards
        // at the same time
        PlaneCard.LoadConfigs();
        UnityEngine.SceneManagement.SceneManager.LoadScene("PlaneDemo");
    }
Example #6
0
    public void UseCard(PlaneCard card)
    {
        // here we take a reference to the card; the card object will get
        // updated automatically for us if the config hotloads, so we don't
        // have to have special hotloading logic in this class
        Card = card;

        // do this after assigning to Card b/c MaxHitPoints depends on Card
        HitPoints = MaxHitPoints;
        m_lastFiredTimes.Clear();

        // display the view; this has to be after HitPoints is assigned
        // or the view will show the wrong thing
        View.Card = card;
    }
Example #7
0
    public void UseCard(PlaneCard card)
    {
        if (tag == "Player")
        {
            MaxHitPoints = card.HitPoints * 2;
        }
        else
        {
            MaxHitPoints = card.HitPoints;
        }
        HitPoints = MaxHitPoints;
        m_lastFiredTimes.Clear();

        Card      = card;
        View.Card = card;
    }
Example #8
0
    void Update()
    {
        if (player == null)
        {
            player = FindObjectOfType <PlayerController>();
        }

        if (player == null)
        {
            return;
        }

        // clean out destroyed enemies
        for (int i = 0; i < enemies.Count; i++)
        {
            if (enemies[i] == null)
            {
                enemies.RemoveAt(i);
                i--;
            }
        }

        if (enemies.Count < numEnemies)
        {
            // pick a card, any card (except the card the player currently has)
            PlaneCard chosenCard = null;
            while (chosenCard == null || chosenCard == player.Controller.Card)
            {
                var cardNames  = new List <string>(PlaneCard.Cards.Keys);
                var chosenName = cardNames[(int)(Random.value * PlaneCard.Cards.Count)];
                chosenCard = PlaneCard.Cards[chosenName];
            }

            // pick a location near the player
            var spawnPos      = player.transform.position + (Vector3)Random.insideUnitCircle.normalized * spawnDistanceFromPlayer;
            var spawnRotation = Quaternion.AngleAxis(Random.value * 360, Vector3.forward);

            // set up the ai
            var enemyObj   = Instantiate(EnemyPrefab, spawnPos, spawnRotation);
            var controller = enemyObj.GetComponent <AIController>();
            controller.Setup(chosenCard);

            enemies.Add(controller);
        }
    }
    ////////////////////////////////////////////

    public void Setup(PlaneCard card)
    {
        var viewTrf = Instantiate(ViewPrefab, transform.position, transform.rotation);

        viewTrf.parent  = transform;
        View            = viewTrf.GetComponent <PlaneView>();
        View.Controller = this;

        // here we take a reference to the card; the card object will get
        // updated automatically for us if the config hotloads, so we don't
        // have to have special hotloading logic in this class
        Card = card;

        // do this after assigning to Card b/c MaxHitPoints depends on Card
        HitPoints = MaxHitPoints;
        lastFiredTimes.Clear();

        // display the view; this has to be after HitPoints is assigned
        // or the view will show the wrong thing
        View.Card = card;
    }
Example #10
0
        public void Initialize()
        {
            PlaneManager gamePreferences = Services.Get <PlaneManager>();

            int current = gamePreferences.GetCurrentPlaneId();

            Dictionary <string, PlayerPrefabItemList> prefabData = gamePreferences.GetPrefabData();

            foreach (var entry in prefabData)
            {
                var items = entry.Value.playerPrefabItems;
                for (int i = 0; i < items.Count; ++i)
                {
                    PlaneCard card = GameObject.Instantiate <PlaneCard>(m_cardPrefab);
                    card.transform.SetParent(m_grid.transform, false);
                    card.Initialize(entry.Value.Bundle, entry.Key, items[i].iconFile, items[i].id, current == items[i].id);
                    card.ClickedEvent += HandleCardClicked;
                }
            }

            m_justInitialized = true;
        }
Example #11
0
 public void Setup(PlaneCard card)
 {
     Controller.Setup(card);
 }
Example #12
0
 // We have a few places in the code which need to be notified when their
 // PlaneCard is modified.  These are places where we had no choice but to
 // copy some of the values from the PlaneCard into some other object, and
 // therefore need to re-copy the values when the PlaneCard gets hotloaded.
 //
 // To see those use cases, look for usage of OnChanged in PlaneView.cs.
 // See hotloading.md for more information on hotloading in general.
 public static PlaneCard PostDoc(PlaneCard existing)
 {
     existing.OnChanged?.Invoke(existing);
     return(existing);
 }