Example #1
0
    public override void OnBeatSuccess(BasePlanet planet, BeatResult result)
    {
        if (planet != this)
        {
            return;
        }
        int resultBonus = result == BeatResult.Awesome ? 2 : 1;

        if (planetState == PlanetState.Colonized)
        {
            List <BasePlanet> destroyed = manager.GetDestroyedPlanets(teamID);
            if (destroyed.Count > 0 && manager.GetResourceType(repairCost.type) >= repairCost.amount)
            {
                int idx = UnityEngine.Random.Range(0, destroyed.Count - 1);
                destroyed[idx].Repair();
                manager.SpendResource(repairCost.type, repairCost.amount);
            }
            else
            {
                int units = baseBeatRate * resultBonus;
                Debug.LogFormat("Adding {0} units of {1}", units, PlanetUtils.GetResourceName(resourceType));
                manager.AddResource(resourceType, units);
            }
        }
        BlinkColour();
        CheckColonize(planet);
    }
Example #2
0
    public void EvaluateTap(BasePlanet tappedPlanet)
    {
        BeatEntry be;

        if (!leSong.GetBeat(currentBeatInfoIdx, out be))
        {
            return;
        }

        double delta = activeMetronome.GetRemainingTimeToTick(be.beat);

        Debug.LogFormat("DELTA: {2}, Expected beat #{0}. Current: {1}", be.beat, totalTicks, delta);

        if (delta < -kFailureThreshold || delta > activeMetronome.TimeBetweenBeats)
        {
            BeatFailed(tappedPlanet);
            return;
        }

        if (Math.Abs(delta) <= kAwesomeThreshold) // define threshold
        {
            BeatSuccess(tappedPlanet, BeatResult.Awesome);
        }
        else if (delta > kAwesomeThreshold && delta <= kGoodThreshold)
        {
            BeatSuccess(tappedPlanet, BeatResult.Good);
        }
        else
        {
            BeatSuccess(tappedPlanet, BeatResult.Meh);
        }
        lastTouchedBeat = be.beat;
    }
Example #3
0
    public override void OnBeatSuccess(BasePlanet planet, BeatResult result)
    {
        if (planet != this)
        {
            return;
        }

        int resultBonus =
            result == BeatResult.Awesome ? 3 : result == BeatResult.Good ? 2 : 1;

        if (planetState == PlanetState.Colonized && CanSpawnShip())
        {
            int units = defaultSpawnCount * resultBonus;
            Debug.LogFormat("Spawning {0} {1} units", units, shipPrefab.shipName);
            for (int i = 0; i < units; ++i)
            {
                BaseShip s = Instantiate <BaseShip>(shipPrefab);
                s.name = string.Format("{0}#{1}", s.shipName, counter++);
                s.SetHQ(hq);
                manager.SpendResourceList(shipSpawnRequirements);
                manager.RegisterShip(s);
            }
        }
        base.OnBeatSuccess(planet, result);
    }
Example #4
0
    public virtual void OnBeatFailed(BasePlanet planet)
    {
        Color colour = spRenderer.color;

        seq = DOTween.Sequence();
        seq.Append(spRenderer.DOBlendableColor(Color.red, 0.1f));
        seq.Append(spRenderer.DOColor(colour, 0.025f));
    }
Example #5
0
    public void SetTarget(BasePlanet target)
    {
        targetPlanet = target;
        shipState    = ShipState.Moving;
        Vector2 targetVector = target.transform.position - transform.position;

        targetOrientation  = -90 + Mathf.Atan2(targetVector.y, targetVector.x) * Mathf.Rad2Deg;
        transform.rotation = Quaternion.AngleAxis(targetOrientation, Vector3.forward);
    }
Example #6
0
    public void HitPlayerBase(float damage)
    {
        BasePlanet hq = System.Array.Find(followers, (planet) => planet is HQPlanet);

        if (hq)
        {
            hq.Hit(damage);
        }
    }
Example #7
0
 public void CheckColonize(BasePlanet planet)
 {
     if (planetState == PlanetState.Desert && CanColonize())
     {
         foreach (ResourceRequirement req in requirements)
         {
             manager.SpendResource(req.type, req.amount);
         }
         Colonize();
     }
 }
Example #8
0
    public override void OnBeatFailed(BasePlanet planet)
    {
        if (planet != this && planetState != PlanetState.Colonized)
        {
            return;
        }
        base.OnBeatFailed(planet);

        Debug.LogFormat("attack was countered");
        manager.HitPlayerBase(counterDamage);
    }
Example #9
0
    public override void OnBeatFailed(BasePlanet planet)
    {
        if (planet != this && planetState != PlanetState.Colonized)
        {
            return;
        }
        base.OnBeatFailed(planet);

        Debug.LogFormat("Lost {0} units of {1}", resourcePenalty, PlanetUtils.GetResourceName(resourceType));
        manager.DecreaseResource(resourceType, resourcePenalty);
    }
Example #10
0
    public override void OnBeatFailed(BasePlanet planet)
    {
        if (planet != this && planetState != PlanetState.Colonized)
        {
            return;
        }
        base.OnBeatFailed(planet);

        Debug.LogFormat("{0} ships took damage", shipPrefab.shipName);
        manager.DamageShipsOfType(shipPrefab.shipName, 10.0f);
    }
Example #11
0
 public void LaunchAttack(BasePlanet target, float attackBonus)
 {
     foreach (BaseShip s in ships)
     {
         if (target.TeamID == s.TeamID || s.HasTarget)
         {
             continue;
         }
         s.SetTarget(target);
         s.ApplyDamageBonus(attackBonus);
     }
 }
Example #12
0
    public override void OnBeat(bool isRelevant)
    {
        if (!manager.running || manager.Paused || paused)
        {
            return;
        }

        if (manager.TotalBeats == nextDecisionBeat)
        {
            EnemyDecision   decision = EnemyDecision.Spawn;
            List <BaseShip> ships    = manager.GetShipsForFaction(teamID);
            if (ships.Count > 0)
            {
                if (ships.Count == maxShipsToDeploy || UnityEngine.Random.value >= deployProbability)
                {
                    decision = EnemyDecision.Deploy;
                }
            }

            switch (decision)
            {
            case EnemyDecision.Spawn:
            {
                int units = UnityEngine.Random.Range(minSpawnUnits, maxSpawnUnits);
                Debug.LogFormat("Spawning {0} {1} enemy units", units, shipPrefab.shipName);
                for (int i = 0; i < units; ++i)
                {
                    BaseShip s = Instantiate <BaseShip>(shipPrefab);
                    s.name = string.Format("{0}#{1}", s.shipName, counter++);
                    s.SetHQ(hq);
                    manager.RegisterShip(s);
                }
                break;
            }

            case EnemyDecision.Deploy:
            {
                List <BasePlanet> planets = manager.GetPlanetsInFaction(TeamType.Player);
                // Force attacking only the base
                BasePlanet target = planets.Find(x => x is HQPlanet);
                if (target != null)
                {
                    manager.LaunchAttack(target, 0.0f);
                }
                break;
            }
            }

            nextDecisionBeat += Random.Range(minDecisionMult, maxDecisionMult) * UnityEngine.Random.Range(minDecisionBeats, maxDecisionBeats);
        }
        base.OnBeat(isRelevant);
    }
Example #13
0
    public override void OnBeatSuccess(BasePlanet planet, BeatResult result)
    {
        if (planet != this)
        {
            return;
        }

        float resultBonus = result == BeatResult.Awesome ? damageBonus : 1.0f;

        if (CanAttackPlanet())
        {
            manager.LaunchAttack(this, resultBonus);
        }
        base.OnBeatSuccess(planet, result);
    }
Example #14
0
    public void SetHQ(BasePlanet hq)
    {
        teamID     = hq.TeamID;
        rootPlanet = hq;
        transform.SetParent(rootPlanet.transform.parent);
        CircleCollider2D circleColl = rootPlanet.GetComponent <CircleCollider2D>();

        orbitOffset   = circleColl.offset;
        orbitDistance = circleColl.radius * (1.0f + UnityEngine.Random.Range(kRadiusMinOffset, kRadiusMaxOffset));
        degree        = UnityEngine.Random.value * 2 * Mathf.PI;
        Debug.Log("Angle: " + degree + ", degrees: " + Mathf.Rad2Deg * degree);
        Vector2 polarPos = (Vector2)rootPlanet.transform.position + new Vector2(orbitDistance * Mathf.Cos(degree), orbitDistance * Mathf.Sin(degree));

        transform.rotation = Quaternion.AngleAxis(-90 + Mathf.Rad2Deg * degree, Vector3.forward);
        transform.position = polarPos + orbitOffset;
    }
Example #15
0
    public override void OnBeatSuccess(BasePlanet planet, BeatResult result)
    {
        if (planet != this)
        {
            return;
        }
        int resultBonus = result == BeatResult.Awesome ? 2 : 1;

        if (planetState == PlanetState.Colonized)
        {
            int units = baseBeatRate * resultBonus;
            Debug.LogFormat("Adding {0} units of {1}", units, PlanetUtils.GetResourceName(resourceType));
            manager.AddResource(resourceType, units);
        }

        base.OnBeatSuccess(planet, result);
    }
 public static Planet ToPlanet(this BasePlanet basePlanet)
 {
     return(new Planet
     {
         Climate = basePlanet.Climate,
         Created = basePlanet.Created,
         Diameter = basePlanet.Diameter,
         Edited = basePlanet.Edited,
         Films = basePlanet.Films,
         Gravity = basePlanet.Gravity,
         Name = basePlanet.Name,
         OrbitalPeriod = basePlanet.OrbitalPeriod,
         Population = basePlanet.Population,
         Residents = basePlanet.Residents,
         RotationPeriod = basePlanet.RotationPeriod,
         SurfaceWater = basePlanet.SurfaceWater,
         Terrain = basePlanet.Terrain,
         Url = basePlanet.Url
     });
 }
Example #17
0
 internal double distance(BasePlanet tp)
 {
     return Math.Sqrt(Math.Pow((this.coord.X-tp.coord.X),2) + Math.Pow((this.coord.Y - tp.coord.Y), 2));
 }
Example #18
0
        public MainWindow()
        {
            InitializeComponent();
            this.Background = Brushes.Black;
            //canvas.Background = Brushes.Black;
            Painter painter = new Painter(canvas);
            manager = new ManagerPlanet(painter);
            Vector startCord = new Vector(canvas.Width / 2, canvas.Height / 2);
            planet = new BasePlanet(startCord);
            //manager.AddPlanet(planet);
            //manager.AddPlanet(new BasePlanet(new Coord(150, 980), new Coord(3050, 0), Brushes.Red, 2, 7));
            //manager.AddPlanet(new BasePlanet(new Coord(700, 400), new Coord(0, 1500), Brushes.Blue, 1, 5));
            //manager.AddPlanet(new BasePlanet(new Coord(1000, 400), new Coord(0, 0), Brushes.Gold, 100000, 25));
            //manager.AddPlanet(new BasePlanet(new Coord(850, 500), new Coord(-50, 30), Brushes.SteelBlue, 100, 10));
            //manager.AddPlanet(new BasePlanet(new Coord(50, 800), new Coord(100, 40), Brushes.White, 1, 4));
            //manager.AddPlanet(new BasePlanet(new Coord(350, 100), new Coord(-30, 300), Brushes.Silver, 3, 1));

            //manager.AddPlanet(new BasePlanet(new Coord(600, 600), new Coord(100, 100), Brushes.Red, 10, 10));
            //manager.AddPlanet(new BasePlanet(new Coord(1200, 600), new Coord(200, -100), Brushes.Yellow, 10, 10));
            //manager.AddPlanet(new BasePlanet(new Coord(900, 300), new Coord(310, 0), Brushes.Violet, 300, 10));
            //manager.AddPlanet(new BasePlanet(new Coord(900, 900), new Coord(410, 0), Brushes.MintCream, 10, 10));
            //manager.AddPlanet(new BasePlanet(new Coord(900, 600), new Coord(300, 0), Brushes.MintCream, 300, 10));
            //manager.AddPlanet(new BasePlanet(new Coord(150, 980), new Coord(500, 0), Brushes.Red, 2, 7));
            //manager.AddPlanet(new BasePlanet(new Coord(400, 400), new Coord(300, 0), Brushes.Blue, 1, 5));
            //manager.AddPlanet(new BasePlanet(new Coord(1000, 400), new Coord(0, 0), Brushes.Gold, 100000, 25));
            //manager.AddPlanet(new BasePlanet(new Coord(850, 500), new Coord(900, 0), Brushes.SteelBlue, 100, 10));
            Random rand = new Random();
            rand.Next();
            for (int i = 0; i < 100; i++)
            {
                manager.AddPlanet(new BasePlanet(new Vector(rand.Next(0, 700), rand.Next(0, 400)), new Vector(rand.Next(2000, 5000), rand.Next(2000, 5000)), Brushes.Red, rand.Next(10, 10), 3));
            }
            manager.AddPlanet(new BasePlanet(new Vector(350, 200), new Vector(0, 0), Brushes.Yellow, -1000, 10));
            manager.AddPlanet(new BasePlanet(new Vector(450, 200), new Vector(0, 0), Brushes.Yellow, 10000, 10));

            //manager.AddPlanet(new BasePlanet(new Coord(600, 600), new Coord(0, 3500), Brushes.Red, 10, 10));
            //manager.AddPlanet(new BasePlanet(new Coord(1200, 600), new Coord(0, -3500), Brushes.Yellow, 10, 10));
            //manager.AddPlanet(new BasePlanet(new Coord(900, 300), new Coord(-3500, 0), Brushes.Violet, 10, 10));
            //manager.AddPlanet(new BasePlanet(new Coord(900, 900), new Coord(3500, 0), Brushes.MintCream, 10, 10));
            //manager.AddPlanet(new BasePlanet(new Coord(900, 600), new Coord(0, 0), Brushes.Blue, 3000, 15));
            manager.UpdatePlanets();
            manager.DisplayPlanets();
        }
Example #19
0
 public virtual void OnBeatSuccess(BasePlanet planet, BeatResult result)
 {
     BlinkColour();
     CheckColonize(planet);
 }
Example #20
0
 public BasePlanet(BasePlanet planet1, BasePlanet planet2)
     : this(planet1.coord,planet1._speed+planet2._speed,Brushes.Blue,planet1.weight+planet2.weight,(planet2.radius+planet1.radius)*0.8)
 {
     _strength = planet1._strength + planet2._strength;
 }
Example #21
0
 public void AddPlanet(BasePlanet planet)
 {
     planets.Add(planet);
     ellipses.Add(planet.ellipse);
 }
Example #22
0
            public void merger(BasePlanet planet)
            {
                double m1 = planet.weight;
                double m2 = weight;

                radius = Math.Sqrt(Math.Pow(planet.radius, 2) + Math.Pow(radius, 2));
                weight += planet.weight;
                _speed = (m1 * planet._speed + m2 * _speed) / (m1 + m2);
            }