Ejemplo n.º 1
0
        // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
        //override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
        //
        //}

        // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
        //override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
        //
        //}

        // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
        override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            WormObject worm = animator.gameObject.GetComponent <WormObject>();

            worm.Jump();
            animator.SetBool("isJumping", true);
        }
Ejemplo n.º 2
0
 public void SpawnWorms()
 {
     for (int t = 0; t < Teams.Count; t++)
     {
         Team  team = Teams[t];
         Color col  = Color.grey;
         if (t < DefTeamColors.Length)
         {
             col = DefTeamColors[t];
         }
         team.TeamColor = col;
         foreach (var name in team.WormNames)
         {
             int safe = 100;
             while (true)
             {
                 WormObject worm = SpawnWorm(name, col);
                 if (worm)
                 {
                     team.Worms.Add(worm);
                     worm.Crosshair.gameObject.SetActive(false);
                     worm.TeamIndex = t;
                     break;
                 }
                 safe--;
                 if (safe == 0)
                 {
                     Debug.LogError("Failed to spawn a worm");
                     break;
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
 public void HurtWorm(WormObject worm, int damage)
 {
     if (worm == PlayerManager.CurrentWorm && State == GameState.Movement)
     {
         State = GameState.Observing;
     }
 }
Ejemplo n.º 4
0
        // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
        //override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
        //
        //}

        // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
        //override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
        //
        //}

        // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
        override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            //Debug.Log("Finishing single action");
            WormObject worm = animator.gameObject.GetComponent <WormObject>();

            worm.State = WormState.Idle;
        }
Ejemplo n.º 5
0
 public void DeleteWorm(WormObject worm)
 {
     if (worm == PlayerManager.CurrentWorm && State == GameState.Movement)
     {
         State = GameState.Observing;
     }
     Teams[worm.TeamIndex].Worms.Remove(worm);
 }
Ejemplo n.º 6
0
 public bool KillNextWorm()
 {
     if (WormsToDie.Count > 0)
     {
         WormObject worm = WormsToDie[0];
         worm.SetToDie();
         return(true);
     }
     return(false);
 }
Ejemplo n.º 7
0
        public IEnumerator RetreatWorm(float time, WormObject worm)
        {
            yield return(new WaitForSeconds(time));

            if (worm)
            {
                worm.Horizontal = 0;
                worm.Vertical   = 0;
            }
            State = GameState.Observing;
        }
Ejemplo n.º 8
0
        public bool KillWorm(WormObject worm)
        {
            if (WormsToDie.Contains(worm))
            {
                WormsToDie.Remove(worm);
                DeleteWorm(worm);

                State = GameState.Damage;
                return(true);
            }
            return(false);
        }
Ejemplo n.º 9
0
 protected override bool OnCollideWithObject(RectObject other, ref Vector2 vel)
 {
     if (other is WormObject && vel.magnitude > KnockOutVelocity)
     {
         //Debug.LogFormat("Hit a worm, vel {0}", vel);
         WormObject worm = (WormObject)other;
         vel *= 0.8f;
         //Debug.Break();
         worm.AddForce(vel);
         worm.SetFalling();
         return(false);
     }
     return(base.OnCollideWithObject(other, ref vel));
 }
Ejemplo n.º 10
0
        public void NextTurn(WormObject lastWorm)
        {
            if (lastWorm)
            {
                SetWormCrosshair(lastWorm, false);
            }
            for (int i = 0; i < DebrisContainer.transform.childCount; i++)
            {
                Destroy(DebrisContainer.transform.GetChild(i).gameObject, GRandom.GetFloat(0, 1.0f));
            }
            CycleTeams();
            WormObject worm = Teams[CurrentTeam].GetNextWorm();

            ActivateWorm(worm);
        }
Ejemplo n.º 11
0
        public WormObject SpawnWorm(string name, Color col)
        {
            WormObject wormDef = WormPrefab.GetComponent <WormObject>();
            int        w       = wormDef.Width;
            int        h       = wormDef.Height;

            int random_x = GRandom.GetInt(0, Width - w);
            int start_y  = Height;

            //Debug.LogFormat("Trying to spawn worm at {0}", random_x);

            while (start_y > 1)
            {
                start_y--;
                Node n     = MapGrid[random_x, start_y];
                Node floor = MapGrid[random_x, start_y - 1];
                if (wormSpawned[random_x, start_y])
                {
                    continue;
                }
                if (!floor.Solid || n.Solid)
                {
                    continue;
                }
                Vector2Int pos  = new Vector2Int(n.Position.x, n.Position.y);
                WormObject worm = SpawnWormAt(pos, w, h);
                if (worm)
                {
                    //Debug.LogFormat("Spawned at node {0}", MapGrid[pos.x, pos.y]);
                    worm.name   = name;
                    worm.Health = WormHealth;
                    RadiusAction(pos, MinWormSpawnRange, wormSpawned, null, (x) => x = true);
                    GameObject wormInfoObj = Instantiate(WormInfoPrefab, WormCanvas.transform);
                    WormInfo   wormInfo    = wormInfoObj.GetComponent <WormInfo>();
                    if (wormInfo)
                    {
                        wormInfo.Target = worm.transform;
                        wormInfo.SetName(name);
                        wormInfo.SetColor(col);
                    }
                    worm.WormInfo = wormInfo;
                    return(worm);
                }
            }
            return(null);
        }
Ejemplo n.º 12
0
        public HashSet <RectObject> Explode(Vector2Int pos, int radius, int forceRadius, float maxForce, int debrisChance = 16)
        {
            HashSet <RectObject> hitObjects = new HashSet <RectObject>();

            System.Action <Node> act = (x) =>
            {
                if (x.Solid == true && GRandom.GetInt(1, 100) <= debrisChance)
                {
                    Color  col  = MapSprite.texture.GetPixel(x.Position.x, x.Position.y);
                    string name = "Debris_" + debrisCount;
                    //RectObject debris = SpawnDebris(x.Position, col, Vector2.zero, name, GRandom.GetFloat(2.0f, 4.0f));
                    RectObject debris = SpawnDebris(x.Position, col, Vector2.zero, name, 0, false, true);
                    hitObjects.Add(debris);
                }
                x.Solid = false;

                if (x.Object)
                {
                    if (!hitObjects.Contains(x.Object))
                    {
                        hitObjects.Add(x.Object);
                    }
                }
            };
            RadiusAction(pos, radius, MapGrid, act, null, NoColor);
            foreach (var hitObject in hitObjects)
            {
                Vector2 objectCenter = hitObject.GetCenter();
                float   dist         = Vector2.Distance(pos, objectCenter);
                float   dist_b       = dist / radius;
                float   force        = Mathf.Lerp(maxForce, 0, dist_b);
                Vector2 vel          = new Vector2(objectCenter.x - pos.x, objectCenter.y - pos.y).normalized;
                hitObject.AddForce(vel * force);
                if (hitObject is WormObject)
                {
                    WormObject worm   = (WormObject)hitObject;
                    int        damage = (int)(force / DamageFactor);
                    worm.GetHurt(damage, DamageType.Explosion);
                }
            }
            mapChanged = true;
            return(hitObjects);
        }
Ejemplo n.º 13
0
 public void ActivateWorm(WormObject worm)
 {
     CurrentWorm = worm;
     playerShot  = false;
 }
Ejemplo n.º 14
0
 private void SetWormCrosshair(WormObject worm, bool activate)
 {
     worm.Crosshair.gameObject.SetActive(activate);
 }
Ejemplo n.º 15
0
 public void ActivateWorm(WormObject worm)
 {
     PlayerManager.ActivateWorm(worm);
     CameraManager.CenterOnWorm(worm);
     SetWormCrosshair(worm, true);
 }
Ejemplo n.º 16
0
 public void CenterOnWorm(WormObject worm)
 {
     Target = worm.transform.position;
 }