void OnFighterReceivedDamage(params object[] args)
    {
        FighterModel fighter = ((GameObject)args [1]).GetComponent <FighterModel> ();

        if (fighter.allegiance == FighterAlliegiance.Ally)
        {
            menuItemDictionary [fighter.gameObject].UpdateValues();
        }
    }
        /// <summary>
        /// Critério de vitória
        /// <para />O vencedor é determinado pela maior porcentagem de vitórias, sendo que só é necessário a avaliação
        /// <para />do número inteiro, não decimal.
        /// <para />O cálculo para identificar a porcentagem é: vitórias / total de lutas * 100.
        /// <para />Caso haja empate deve ser considerado o critério de desempate.
        /// <para />Critérios de desempate
        /// <para />O primeiro critério será pela quantidade de artes marciais que o lutador possuí, ou seja,
        /// <para />o lutador com maior número é o vencedor.
        /// <para /Caso a quantidade de artes marciais não seja o suficiente, o segundo critério deve ser pelo número de lutas
        /// <para />, sendo assim o lutador com o maior número de lutas é o vencedor.
        /// </summary>
        /// <param name="fighter0"></param>
        /// <param name="fighter1"></param>
        /// <returns></returns>
        private List <FighterModel> GetWinner(FighterModel fighter0, FighterModel fighter1)
        {
            if (fighter0 == null)
            {
                throw new ArgumentNullException(nameof(fighter0));
            }

            if (fighter1 == null)
            {
                throw new ArgumentNullException(nameof(fighter1));
            }

            FighterModel winner = null;
            int          wins0  = fighter0.Wins * 100 / fighter0.Fights;
            int          wins1  = fighter1.Wins * 100 / fighter1.Fights;

            if (wins0 > wins1)
            {
                winner = fighter0;
            }
            else if (wins1 > wins0)
            {
                winner = fighter1;
            }
            else
            {
                //draw
                if (fighter0.MartialArtCollectionCount > fighter1.MartialArtCollectionCount)
                {
                    winner = fighter0;
                }
                else if (fighter1.MartialArtCollectionCount > fighter0.MartialArtCollectionCount)
                {
                    winner = fighter1;
                }
                else if (fighter0.Fights > fighter1.Fights)
                {
                    winner = fighter0;
                }
                else if (fighter1.Fights > fighter0.Fights)
                {
                    winner = fighter1;
                }
                else
                {
                    Console.WriteLine("Draw.");
                }
            }

            var looser     = winner.Equals(fighter0) ? fighter1 : fighter0;
            var collection = new List <FighterModel> {
                winner, looser
            };

            return(collection);
        }
 // WINDOW BORDERS:
 public static void CheckForWindowCollisions(FighterModel fighter)
 {
     if (fighter.Bounds.Left <= 0 - (fighter.Bounds.Width / 4))
     {
         fighter.Move("collisionLeft");
     }
     else if (fighter.Bounds.Right - (fighter.Bounds.Width / 4) >= PlazaSmashGame.WindowWidth)
     {
         fighter.Move("collisionRight");
     }
 }
Exemple #4
0
        // Constructor.
        public WalkState(FighterStateContext context)
        {
            stateContext     = context;
            animator         = stateContext.fighter.GetComponentInChildren <Animator> ();
            fighterTransform = stateContext.fighter.transform;

            // Set move direction depending on FighterAllegiance.
            FighterModel fighterModel = stateContext.fighter.GetComponent <FighterModel> ();

            moveDirection = (int)fighterModel.allegiance;

            animator.SetTrigger("Walk");
        }
        // Simple factory method , not a pattern
        public FighterSixteen getFighterPlane(FighterModel model)
        {
            switch (model)
            {
            case FighterModel.AverageModel:
                return(new FighterSixteenAM());

            case FighterModel.EconomicalModel:
                return(new FighterSixteenEM());

            default:
                return(new FighterSixteen());
            }
        }
    void OnAttackDataSet(Attack attackData)
    {
        FighterModel fighterModel = (model as ProjectileModel).attackData.attackOrigin.GetComponent <FighterModel> ();

        moveDirection = (int)fighterModel.allegiance;

        if (fighterModel.allegiance == FighterAlliegiance.Ally)
        {
            gameObject.layer = LayerMask.NameToLayer("AlliedProjectile");
        }
        else
        {
            gameObject.layer = LayerMask.NameToLayer("EnemyProjectile");
        }
    }
Exemple #7
0
        public void Update(GameFightSynchronizeMessage message)
        {
            foreach (GameFightFighterInformations infos in message.fighters)
            {
                foreach (FighterModel fighter in Defenders)
                {
                    if (fighter.ContextualId == infos.contextualId)
                    {
                        fighter.Team   = (TeamEnum)infos.teamId;
                        fighter.Alive  = infos.alive;
                        fighter.CellId = infos.disposition.cellId;
                        if (fighter.Team == TeamEnum.TEAM_CHALLENGER && !Challengers.Contains(fighter))
                        {
                            Challengers.Add(fighter);
                            Defenders.Remove(fighter);
                        }
                        return;
                    }
                }
                foreach (FighterModel fighter in Challengers)
                {
                    if (fighter.ContextualId == infos.contextualId)
                    {
                        fighter.Team   = (TeamEnum)infos.teamId;
                        fighter.Alive  = infos.alive;
                        fighter.CellId = infos.disposition.cellId;

                        if (fighter.Team == TeamEnum.TEAM_CHALLENGER && !Defenders.Contains(fighter))
                        {
                            Defenders.Add(fighter);
                        }
                        Challengers.Remove(fighter);
                        return;
                    }
                }
                FighterModel ft = new FighterModel(infos.contextualId, infos.disposition.cellId, (TeamEnum)infos.teamId, this);
                if (ft.Team == TeamEnum.TEAM_DEFENDER)
                {
                    Defenders.Add(ft);
                }
                else if (ft.Team == TeamEnum.TEAM_CHALLENGER)
                {
                    Challengers.Add(ft);
                }
            }
        }
        // PIXEL PERFECT:
        private static bool IsThereCollision(
            FighterModel thisFighter,
            Color[] thisColorData,
            FighterModel otherFighter,
            Color[] otherColorData)
        {
            bool isThereCollision = false;

            // UNCOMMENT IF YOU DONT HAVE A GAMING RIG :D
            // if (thisFighter.Bounds.Contains(otherFighter.Bounds))
            // {
            // AND COMMENT THIS LINE:
            if (thisFighter.HitBounds.Intersects(otherFighter.HitBounds))
            {
                int top    = Math.Max(thisFighter.HitBounds.Top, otherFighter.HitBounds.Top);
                int bottom = Math.Min(thisFighter.HitBounds.Bottom, otherFighter.HitBounds.Bottom);
                int left   = Math.Max(thisFighter.HitBounds.Left, otherFighter.HitBounds.Left);
                int right  = Math.Min(thisFighter.HitBounds.Right, otherFighter.HitBounds.Right);

                for (int y = top; y < bottom; y++)
                {
                    if (isThereCollision)
                    {
                        break;
                    }

                    for (int x = left; x < right; x++)
                    {
                        Color firstPixel = thisColorData[(x - thisFighter.HitBounds.Left) +
                                                         (thisFighter.HitBounds.Width * (y - thisFighter.HitBounds.Top))];

                        Color secondPixel = otherColorData[(x - otherFighter.HitBounds.Left) +
                                                           (otherFighter.HitBounds.Width * (y - otherFighter.HitBounds.Top))];

                        if (firstPixel.A != 0 && secondPixel.A != 0)
                        {
                            isThereCollision = true;
                            break;
                        }
                    }
                }
            }

            // }
            return(isThereCollision);
        }
        public static void Initialize()
        {
            FightSoundPlayed = false;

            DeadFighter = false;

            rng = new Random();

            BgModel = new BackgroundModel(PickRandomBackground());

            FirstFighter  = new FighterModel("Clark");
            SecondFighter = new FighterModel("Yuri");

            FirstFighterHealth  = new HealthView(new Vector2(20, 20));
            SecondFighterHealth = new HealthView(new Vector2(PlazaSmashGame.WindowWidth - 100, 20));

            BgView = new BackgroundView(BgModel.Name);

            FirstFighterActions = new Dictionary <string, ViewObject>();
            FirstFighterActions.Add("Stand", new StandView(FirstFighter.Name));
            FirstFighterActions.Add("Move", new MoveView(FirstFighter.Name));
            FirstFighterActions.Add("ReversedMove", new ReversedMoveView(FirstFighter.Name));
            FirstFighterActions.Add("Punch", new PunchView(FirstFighter.Name));
            FirstFighterActions.Add("Kick", new KickView(FirstFighter.Name));
            FirstFighterActions.Add("Block", new BlockView(FirstFighter.Name)); // IMPLEMENT
            FirstFighterActions.Add("Hit", new HitView(FirstFighter.Name));
            FirstFighterActions.Add("Die", new DieView(FirstFighter.Name));

            SecondFighterActions = new Dictionary <string, ViewObject>();
            SecondFighterActions.Add("Stand", new StandView(SecondFighter.Name));
            SecondFighterActions.Add("Move", new MoveView(SecondFighter.Name));
            SecondFighterActions.Add("ReversedMove", new ReversedMoveView(SecondFighter.Name));
            SecondFighterActions.Add("Punch", new PunchView(SecondFighter.Name));
            SecondFighterActions.Add("Kick", new KickView(SecondFighter.Name));
            SecondFighterActions.Add("Block", new BlockView(SecondFighter.Name)); // IMPLEMENT
            SecondFighterActions.Add("Hit", new HitView(SecondFighter.Name));
            SecondFighterActions.Add("Die", new DieView(SecondFighter.Name));
        }
        public static void DrawFighter(Dictionary <string, ViewObject> actions, FighterModel thisFighter, FighterModel otherFighter)
        {
            bool fighterIsIdle = true;

            foreach (var action in actions)
            {
                if (action.Value.ToBeDrawn)
                {
                    if (!action.Value.Drawn)
                    {
                        fighterIsIdle = false;

                        if (action.Key == "Hit")
                        {
                            thisFighter.GotHit(otherFighter.Damage);
                            thisFighter.HasBeenHit = false;
                        }

                        action.Value.Draw(thisFighter.Bounds);
                        break;
                    }
                    else
                    {
                        if (action.Key == "Die")
                        {
                            PlazaSmashGame.SM.ChangeState();
                        }

                        action.Value.ToBeDrawn = false;
                    }
                }
            }

            if (fighterIsIdle)
            {
                actions["Stand"].Draw(thisFighter.Bounds);
            }
        }
        public static void CheckForAttackCollision(
            FighterModel thisFighter,
            Dictionary <string, ViewObject> thisFighterActions,
            FighterModel otherFighter,
            Dictionary <string, ViewObject> otherFighterActions)
        {
            // NEEDED FOR GetData()
            ViewObject otherFighterCurrentAction = GetFighterCurrentAction(otherFighterActions);

            if (thisFighterActions["Punch"].ToBeDrawn)
            {
                if (IsThereCollision(
                        thisFighter,
                        thisFighterActions["Punch"].GetColorData(),
                        otherFighter,
                        otherFighterCurrentAction.GetColorData()))
                {
                    if (!otherFighter.IsBlocking)
                    {
                        BattlegroundController.ResetViews(otherFighterActions);

                        if (thisFighter.Name == "Clark")
                        {
                            AudioController.PlaySound(AudioController.ClarkPunchInstance);
                        }
                        else if (thisFighter.Name == "Yuri")
                        {
                            AudioController.PlaySound(AudioController.YuriPunchInstance);
                        }

                        otherFighterActions["Hit"].ToBeDrawn = true;
                        otherFighterActions["Hit"].Drawn     = false;
                    }
                    else
                    {
                        // ADD BLOCKING FUNCTIONALITY HERE
                        // AudioController.PlaySound(AudioController.BlockSoundInstance);
                    }

                    otherFighter.HasBeenHit = true;
                }
            }
            else if (thisFighterActions["Kick"].ToBeDrawn)
            {
                if (IsThereCollision(
                        thisFighter,
                        thisFighterActions["Kick"].GetColorData(),
                        otherFighter,
                        otherFighterCurrentAction.GetColorData()))
                {
                    if (!otherFighter.IsBlocking)
                    {
                        if (thisFighter.Name == "Clark")
                        {
                            AudioController.PlaySound(AudioController.ClarkKickInstance);
                        }
                        else if (thisFighter.Name == "Yuri")
                        {
                            AudioController.PlaySound(AudioController.YuriKickInstance);
                        }

                        BattlegroundController.ResetViews(otherFighterActions);

                        otherFighterActions["Hit"].ToBeDrawn = true;
                        otherFighterActions["Hit"].Drawn     = false;
                    }
                    else
                    {
                        // ADD BLOCKING FUNCTIONALITY HERE
                        // AudioController.PlaySound(AudioController.BlockSoundInstance);
                    }

                    otherFighter.HasBeenHit = true;
                }
            }
        }
Exemple #12
0
        private static void DetermineInput(Keys[] fighterKeys, Keys[] currentPressedKeys, FighterModel fighter, Dictionary <string, ViewObject> actions)
        {
            if (actions["Hit"].Drawn)
            {
                if (!BlockInput)
                {
                    foreach (Keys pressedKey in currentPressedKeys)
                    {
                        if (pressedKey == fighterKeys[0])
                        {
                            BattlegroundController.ResetViews(actions);

                            fighter.Move("left");

                            actions["Move"].ToBeDrawn = true;
                            actions["Move"].Drawn     = false;

                            for (int i = 0; i < currentPressedKeys.Length; i++)
                            {
                                if (currentPressedKeys[i] == fighterKeys[1] || currentPressedKeys[i] == fighterKeys[2] ||
                                    currentPressedKeys[i] == fighterKeys[2])
                                {
                                    currentPressedKeys[i] = Keys.None;
                                }
                            }
                        }
                        else if (pressedKey == fighterKeys[1])
                        {
                            BattlegroundController.ResetViews(actions);

                            fighter.Move("right");

                            actions["ReversedMove"].ToBeDrawn = true;
                            actions["ReversedMove"].Drawn     = false;

                            for (int i = 0; i < currentPressedKeys.Length; i++)
                            {
                                if (currentPressedKeys[i] == fighterKeys[0] || currentPressedKeys[i] == fighterKeys[2] ||
                                    currentPressedKeys[i] == fighterKeys[3])
                                {
                                    currentPressedKeys[i] = Keys.None;
                                }
                            }
                        }
                        else if (pressedKey == fighterKeys[2] && !PreviousKeyboardState.IsKeyDown(fighterKeys[2]))
                        {
                            fighter.Punch();

                            // TO REDUCE INPUT DELAY:
                            actions["Move"].Drawn         = true;
                            actions["ReversedMove"].Drawn = true;

                            actions["Punch"].ToBeDrawn = true;
                            actions["Punch"].Drawn     = false;

                            for (int i = 0; i < currentPressedKeys.Length; i++)
                            {
                                if (currentPressedKeys[i] == fighterKeys[0] || currentPressedKeys[i] == fighterKeys[1] ||
                                    currentPressedKeys[i] == fighterKeys[3])
                                {
                                    currentPressedKeys[i] = Keys.None;
                                }
                            }
                        }
                        else if (pressedKey == fighterKeys[3] && !PreviousKeyboardState.IsKeyDown(fighterKeys[3]))
                        {
                            fighter.Kick();

                            actions["Move"].Drawn         = true;
                            actions["ReversedMove"].Drawn = true;

                            actions["Kick"].ToBeDrawn = true;
                            actions["Kick"].Drawn     = false;

                            for (int i = 0; i < currentPressedKeys.Length; i++)
                            {
                                if (currentPressedKeys[i] == fighterKeys[0] || currentPressedKeys[i] == fighterKeys[1] ||
                                    currentPressedKeys[i] == fighterKeys[2])
                                {
                                    currentPressedKeys[i] = Keys.None;
                                }
                            }
                        }

                        // ADD BLOCKING FUNCTIONALITY HERE
                    }
                }
            }
        }
Exemple #13
0
    // TODO: clean up. encapsulate.
    private GameObject SpawnFighter(FighterData fighterData, FighterAlliegiance allegiance)
    {
        GameObject newFighter;

        // Instantiate prefab with appropriate behavior. (Melee Fighter Controller/Ranged Fighter Controller)
        if (fighterData.fighterClass == Class.Archer)
        {
            newFighter = Instantiate(archerFighterPrefab);
        }
        else if (fighterData.fighterClass == Class.Mage)
        {
            newFighter = Instantiate(mageFighterPrefab);
        }
        else
        {
            newFighter = Instantiate(meleeFighterPrefab);
        }

        FighterModel fighterModel = newFighter.GetComponent <FighterModel>();

        fighterModel.fighterData = fighterData;
        fighterModel.allegiance  = allegiance;

        // Set currentHP back to max value.
        fighterModel.fighterData.HP = fighterModel.fighterData.maxHP;

        // TEMP. Increase/Decrease box collider height to offset sprite positions.

        float randomOffset = Mathf.Round((UnityEngine.Random.Range(0.5f, 1.7f)) * 100f) / 100f;          // Random float round off to 2 decimal place.


        BoxCollider2D collider = newFighter.GetComponent <BoxCollider2D> ();

        collider.size = new Vector2(collider.size.x, randomOffset);

        Vector3 tempPosition = newFighter.transform.position;

        tempPosition.z = randomOffset * 10f;
        newFighter.transform.position = tempPosition;

//		Debug.Log ("RANDOM OFFSET: " + randomOffset.ToString ());

        if (allegiance == FighterAlliegiance.Ally)
        {
            allies.Add(newFighter);
        }
        else
        {
            enemies.Add(newFighter);

            // Set layer of object (rigidBody) and child (trigger collider) to "EnemyUnits".
            newFighter.layer = LayerMask.NameToLayer("EnemyUnits");
            newFighter.transform.GetChild(0).gameObject.layer = LayerMask.NameToLayer("EnemyUnits");

            // Set enemy sprites to face the opposite direction.
            Vector3 tempScale = newFighter.transform.localScale;
            tempScale.x *= -1;
            newFighter.transform.localScale = tempScale;
        }

//		newFighter.GetComponent <FighterController> ().SetFighterSkin ();
        newFighter.SetActive(true);

        return(newFighter);
    }
        /// <summary>
        /// A final é disputada pelos vencedores das semifinais.
        /// </summary>
        /// <param name="fighter0"></param>
        /// <param name="fighter1"></param>
        /// <returns></returns>
        public List <FighterModel> Final(FighterModel fighter0, FighterModel fighter1)
        {
            var collection = GetWinner(fighter0, fighter1);

            return(collection);
        }
        /// <summary>
        /// A disputa de terceiro e quarto é realizada pelos lutadores perdedores das semifinais.
        /// </summary>
        /// <param name="fighter0"></param>
        /// <param name="fighter1"></param>
        /// <returns></returns>
        public List <FighterModel> ThirdPlace(FighterModel fighter0, FighterModel fighter1)
        {
            var collection = GetWinner(fighter0, fighter1);

            return(collection);
        }