Ejemplo n.º 1
0
        public static void Hit(Fighter a, Fighter b)
        {
            FighterState  aframe = a.moves[a.currentState].GetFrame(), bframe = b.moves[b.currentState].GetFrame();
            List <HitBox> aattack = aframe.GetHitbox(HitBox.Type.Attack), battack = bframe.GetHitbox(HitBox.Type.Attack);
            List <HitBox> adef = aframe.GetHitbox(HitBox.Type.Body), bdef = bframe.GetHitbox(HitBox.Type.Body);

            foreach (HitBox h in aattack)
            {
                foreach (HitBox d in bdef)
                {
                    HitBox attack = new HitBox(h, a.transform);
                    HitBox def    = new HitBox(d, b.transform);
                    if (attack.Hit(def))
                    {
                        b.Hit(0);
                    }
                }
            }

            foreach (HitBox h in battack)
            {
                foreach (HitBox d in adef)
                {
                    HitBox attack = new HitBox(h, b.transform);
                    HitBox def    = new HitBox(d, a.transform);
                    if (attack.Hit(def))
                    {
                        a.Hit(0);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public void CopyFrom(FighterState fs)
 {
     foreach (HitBox hb in fs.hitboxes)
     {
         hitboxes.Add(new HitBox(hb));
     }
     sprite = fs.sprite;
     time   = fs.time;
 }
Ejemplo n.º 3
0
        public HitBox GetAttackHitbox()
        {
            FighterState state = GetFrame();

            foreach (HitBox h in state.hitboxes)
            {
                if (h._type == HitBox.Type.Attack)
                {
                    return(h);
                }
            }
            return(null);
        }
Ejemplo n.º 4
0
        public static void Hit(FighterController a, FighterController b)
        {
            FighterState  aframe = a.fighter.GetFrame(), bframe = b.fighter.GetFrame();
            List <HitBox> aattack = aframe.GetHitbox(HitBox.Type.Attack), battack = bframe.GetHitbox(HitBox.Type.Attack);
            List <HitBox> adef = aframe.GetHitbox(HitBox.Type.Body), bdef = bframe.GetHitbox(HitBox.Type.Body);

            if (!aframe.Computed)
            {
                foreach (HitBox h in aattack)
                {
                    foreach (HitBox d in bdef)
                    {
                        HitBox attack = new HitBox(h, a.transform);
                        HitBox def    = new HitBox(d, b.transform);
                        if (attack.Hit(def))
                        {
                            b.Hit(0, new HitBox(h), a);
                        }
                    }
                }
                if (aattack.Count > 0)
                {
                    b.Block();
                }
            }

            if (!bframe.Computed)
            {
                foreach (HitBox h in battack)
                {
                    foreach (HitBox d in adef)
                    {
                        HitBox attack = new HitBox(h, b.transform);
                        HitBox def    = new HitBox(d, a.transform);
                        if (attack.Hit(def))
                        {
                            a.Hit(0, new HitBox(h), b);
                        }
                    }
                }
                if (battack.Count > 0)
                {
                    a.Block();
                }
            }


            aframe.Consume();
            bframe.Consume();
        }
Ejemplo n.º 5
0
        public static void DrawState(FighterState state, float h)
        {
            Rect rect = EditorGUILayout.GetControlRect();

            if (state != null && state.sprite != null)
            {
                rect.width  = state.sprite.rect.width * scale;
                rect.height = h * scale;
            }
            GUILayout.Space(h * scale);
            if (state != null && state.sprite != null)
            {
                GUI.DrawTextureWithTexCoords(rect, state.sprite.texture, GetSpriteRect(state.sprite));
            }
        }
Ejemplo n.º 6
0
        public void UpdateObject(float deltaTime)
        {
            FighterState state = GetFrame();

            if (state != lastState)
            {
                if (state.wwiseEvent && controller != null)
                {
                    AkSoundEngine.PostEvent(state.wwiseEventName, controller);
                }
                //Launch Events
                foreach (Event e in state.events)
                {
                    if (FightEvent != null)
                    {
                        Debug.Log("Invoking");
                        FightEvent.Invoke(e);
                    }
                }
            }

            lastState   = state;
            parryTimer += deltaTime;
            guard      -= guardDecrease * deltaTime;
            stun       -= stunDecrease * deltaTime;
            if (guard < 0)
            {
                guard = 0.0f;
            }
            if (stun < 0)
            {
                stun = 0.0f;
            }
            if (bFallen)
            {
                fallTimer += deltaTime;
                if (fallTimer >= fallTime)
                {
                    SetMove(GetUp);
                    bFallen = false;
                }
            }
        }
Ejemplo n.º 7
0
 void DrawFrame(FighterState state)
 {
     state.sprite = (Sprite)EditorGUILayout.ObjectField("Sprite:", state.sprite, typeof(Sprite), false);
     state.time   = EditorGUILayout.Slider(state.time, 0, 10);
     if (GUILayout.Button("Add Hitbox"))
     {
         state.hitboxes.Add(new HitBox(HitBox.Type.Attack, Vector2.zero, Vector2.one));
     }
     for (int i = state.hitboxes.Count - 1; i >= 0; i--)
     {
         HitBox h = state.hitboxes[i];
         EditorGUILayout.Separator();
         h._Type     = (HitBox.Type)EditorGUILayout.Popup((int)h._type, System.Enum.GetNames(typeof(HitBox.Type)));
         h._position = EditorGUILayout.Vector2Field("Pos:", h._position);
         h._size     = EditorGUILayout.Vector2Field("Size:", h._size);
         if (GUILayout.Button("Remove"))
         {
             state.hitboxes.Remove(h);
         }
     }
 }
Ejemplo n.º 8
0
 public FighterStateEditor(FighterState f)
 {
     state = f;
 }
Ejemplo n.º 9
0
        void OnGUI()
        {
            GUILayout.BeginHorizontal();

            if (GUILayout.Button("Convert"))
            {
                FighterConverter.Convert(fighter);
            }

            GUILayout.Label("Fighter Editor", EditorStyles.boldLabel);

            fighter = (FighterObject)EditorGUILayout.ObjectField(fighter, typeof(FighterObject), true);
            if (GUILayout.Button("Edit MoveSet"))
            {
                MoveSetEditor.Init(fighter);
            }
            GUILayout.EndHorizontal();
            if (!fighter)
            {
                return;
            }

            windowPos = EditorGUILayout.BeginScrollView(windowPos);
            GUILayout.BeginVertical(GUILayout.MaxWidth(800));
            GUILayout.BeginVertical("Box");

            GUILayout.BeginHorizontal();
            fighter.jumpStrength = EditorGUILayout.FloatField("Jump Strength", fighter.jumpStrength);
            fighter.speed        = EditorGUILayout.FloatField("Speed", fighter.speed);
            fighter.fallTime     = EditorGUILayout.FloatField("Fall Time", fighter.fallTime);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            fighter.lifeMax          = EditorGUILayout.FloatField("Life", fighter.lifeMax);
            fighter.guardMax         = EditorGUILayout.FloatField("Guard", fighter.guardMax);
            fighter.stunMax          = EditorGUILayout.FloatField("Stun", fighter.stunMax);
            fighter.parryTime        = EditorGUILayout.FloatField("Parry Time", fighter.parryTime);
            fighter.parryPerfectTime = EditorGUILayout.FloatField("Perfect Parry Time", fighter.parryPerfectTime);
            GUILayout.EndHorizontal();

            //Fighter Properties
            GUILayout.BeginHorizontal();
            fighter.Stand  = EditorGUILayout.Popup("Stand", fighter.Stand, fighter.moves.ConvertAll <string>(MoveToName).ToArray());
            fighter.Crouch = EditorGUILayout.Popup("Crouch", fighter.Crouch, fighter.moves.ConvertAll <string>(MoveToName).ToArray());
            fighter.Walk   = EditorGUILayout.Popup("Walk", fighter.Walk, fighter.moves.ConvertAll <string>(MoveToName).ToArray());
            fighter.Hit    = EditorGUILayout.Popup("Hit", fighter.Hit, fighter.moves.ConvertAll <string>(MoveToName).ToArray());
            fighter.Block  = EditorGUILayout.Popup("Block", fighter.Block, fighter.moves.ConvertAll <string>(MoveToName).ToArray());
            fighter.Taunt  = EditorGUILayout.Popup("Taunt", fighter.Taunt, fighter.moves.ConvertAll <string>(MoveToName).ToArray());
            fighter.Fall   = EditorGUILayout.Popup("Fall", fighter.Fall, fighter.moves.ConvertAll <string>(MoveToName).ToArray());
            fighter.GetUp  = EditorGUILayout.Popup("Get Up", fighter.GetUp, fighter.moves.ConvertAll <string>(MoveToName).ToArray());
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            fighter.JumpStart    = EditorGUILayout.Popup("Jump Start", fighter.JumpStart, fighter.moves.ConvertAll <string>(MoveToName).ToArray());
            fighter.JumpFall     = EditorGUILayout.Popup("Jump Fall", fighter.JumpFall, fighter.moves.ConvertAll <string>(MoveToName).ToArray());
            fighter.JumpRecovery = EditorGUILayout.Popup("Jump Recovery", fighter.JumpRecovery, fighter.moves.ConvertAll <string>(MoveToName).ToArray());
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();

            GUILayout.BeginHorizontal();
            int newMove = EditorGUILayout.Popup(selectedMove, fighter.moves.ConvertAll <string>(MoveToName).ToArray());

            if (selectedMove != newMove)
            {
                selectedMove = newMove;
                states.Clear();
                foreach (FighterState f in fighter.moves[selectedMove].frames)
                {
                    states.Add(new FighterStateEditor(f));
                }
            }
            if (selectedMove >= 0)
            {
                fighter.moves[selectedMove].name = GUILayout.TextField(fighter.moves[selectedMove].name);
            }
            if (GUILayout.Button("New Move"))
            {
                fighter.moves.Add(new Move());
                selectedMove = fighter.moves.Count - 1;
            }
            if (GUILayout.Button("Delete"))
            {
                fighter.moves.RemoveAt(selectedMove);
                if (selectedMove >= fighter.moves.Count)
                {
                    selectedMove = fighter.moves.Count - 1;
                }
            }
            GUILayout.EndHorizontal();
            if (selectedMove >= 0)
            {
                Move selMove = fighter.moves[selectedMove];
                selMove.attack = EditorGUILayout.Toggle("Is Attack?", selMove.attack);
                fighter.moves[selectedMove].velocity = EditorGUILayout.Vector2Field("Move Velocity", fighter.moves[selectedMove].velocity);
                selMove.defaultNext = EditorGUILayout.Popup("Default next:", selMove.defaultNext, fighter.GetMoveList());
                //Draw Preview
                FighterStateEditor.DrawState(fighter.moves[selectedMove].GetFrame((Time.time * fighter.moves[selectedMove].time_modifier)), fighter.moves[selectedMove].GetMaxHeight());
                fighter.moves[selectedMove].time_modifier = EditorGUILayout.Slider(fighter.moves[selectedMove].time_modifier, 0.0f, 5.0f);
                if (GUILayout.Button("Add State"))
                {
                    FighterState        s  = new FighterState();
                    List <FighterState> st = fighter.moves[selectedMove].frames;
                    if (st.Count > 0)
                    {
                        s.CopyFrom(st[st.Count - 1]);
                    }
                    fighter.moves[selectedMove].frames.Add(s);
                    states.Add(new FighterStateEditor(s));
                }

                statesScroll = EditorGUILayout.BeginScrollView(statesScroll);

                GUILayout.BeginHorizontal();
                for (int i = 0; i < states.Count; i++)
                {
                    GUILayout.BeginVertical("Box", GUILayout.MaxWidth(250));
                    GUILayout.BeginHorizontal();
                    if (i > 0 && GUILayout.Button("<"))
                    {
                        states.Insert(i - 1, states[i]);
                        states.RemoveAt(i + 1);
                    }
                    if (GUILayout.Button("Remove"))
                    {
                        fighter.moves[selectedMove].frames.RemoveAt(i);
                        states.RemoveAt(i);
                        i--;
                    }
                    if (i < states.Count - 1 && GUILayout.Button(">"))
                    {
                        Debug.Log("insert");
                        states.Insert(i + 2, states[i]);
                        states.RemoveAt(i);
                    }
                    GUILayout.EndHorizontal();
                    states[i].OnGUI();
                    GUILayout.EndVertical();
                }
                GUILayout.EndHorizontal();

                EditorGUILayout.EndScrollView();
            }
            GUILayout.EndVertical();
            EditorGUILayout.EndScrollView();
            EditorUtility.SetDirty(fighter);
        }