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)
    {
        attControl = animator.GetComponent <AttackControl>();
        attControl.currentlyAttacking = false;
        animator.SetBool("Attack", false);
        //attControl.doDamage.activateWeaponColider(false);
    }
Ejemplo n.º 2
0
    override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        attackControl = animator.GetComponent <AttackControl>();
        attackControl.currentlyAttacking = false;
        animator.SetBool("Attack", false);

        animator.GetComponent <PlayerControl>().canMove  = true;
        animator.GetComponent <PlayerControl>().canBlock = true;
    }
Ejemplo n.º 3
0
 public void Attack()
 {
     if (!(source as Creature).ActionAvailable)
     {
         Toaster.Instance.DoToast("You have already acted with this creature");
         return;
     }
     AttackControl.Setup(source as Creature);
     gameObject.SetActive(false);
 }
Ejemplo n.º 4
0
    public void Grid(GameObject Charactor, Animator anim) //執行格子內容
    {
        if (Control._playerPossition[Control.now_Player] == 0)
        {
            Control._playerHp[Control.now_Player] += 300;
            FloatText.Click(Charactor, 300, "+");
            FloatText.story_text("來到這個迷宮不知道多久了,還沒找到全部的裝置...",
                                 Manager._selectedName[Control.now_Player] + "  Get  props ");
            Time.timeScale = 0;
        }
        //過關道具
        else if (Control._playerPossition[Control.now_Player] % 40 == 1 ||//1
                 Control._playerPossition[Control.now_Player] % 40 == 10 ||
                 Control._playerPossition[Control.now_Player] % 40 == 20 ||
                 Control._playerPossition[Control.now_Player] % 40 == 23 ||
                 Control._playerPossition[Control.now_Player] % 40 == 28 ||
                 Control._playerPossition[Control.now_Player] % 40 == 32)
        {
            int number = -1;
            if (Control._playerPossition[Control.now_Player] % 40 == 1)
            {
                number = 0;
            }
            else if (Control._playerPossition[Control.now_Player] % 40 == 10)
            {
                number = 1;
            }
            else if (Control._playerPossition[Control.now_Player] % 40 == 20)
            {
                number = 2;
            }
            else if (Control._playerPossition[Control.now_Player] % 40 == 23)
            {
                number = 3;
            }
            else if (Control._playerPossition[Control.now_Player] % 40 == 28)
            {
                number = 4;
            }
            else
            {
                number = 5;
            }
            if (Control._props[number] == true)
            {
                FloatText.story_text("發現了鬼火獸的裝置,看著上面的編號好像已經有人拿過了...",
                                     Manager._selectedName[Control.now_Player] + " 獲得重複編號為" + (number + 1) + "的鬼火獸裝置");
            }
            else
            {
                Control._props[number] = true;
                FloatText.story_text("發現了鬼火獸的裝置,該趕快回去跟他們會合,和他們說這件事情...",
                                     Manager._selectedName[Control.now_Player] + " 得到了上面有著編號" + (number + 1) + "的鬼火獸裝置");
            }
            GameObject.Find("Canvas").GetComponent <Control>().GetProps();
        }
        //獲得武器V
        else if (Control._playerPossition[Control.now_Player] % 40 == 3 ||
                 Control._playerPossition[Control.now_Player] % 40 == 7 ||
                 Control._playerPossition[Control.now_Player] % 40 == 13 ||
                 Control._playerPossition[Control.now_Player] % 40 == 17 ||
                 Control._playerPossition[Control.now_Player] % 40 == 22 ||
                 Control._playerPossition[Control.now_Player] % 40 == 30 ||
                 Control._playerPossition[Control.now_Player] % 40 == 35 ||
                 Control._playerPossition[Control.now_Player] % 40 == 39)
        {
            AttackControl.setImage(Charactor);
            AttackCanvas.enabled = true;
            MainCanvas.enabled   = false;
            attack = true;
        }
        //怪物
        else if (Control._playerPossition[Control.now_Player] % 40 == 5 ||//5
                 Control._playerPossition[Control.now_Player] % 40 == 14 ||
                 Control._playerPossition[Control.now_Player] % 40 == 25 ||
                 Control._playerPossition[Control.now_Player] % 40 == 36)
        {
            Attack.MonsterAttack(GameObject.Find(Manager._selectedName[Control.now_Player]));
        }
        //抵擋V
        else if (Control._playerPossition[Control.now_Player] % 40 == 4 ||
                 Control._playerPossition[Control.now_Player] % 40 == 15 ||
                 Control._playerPossition[Control.now_Player] % 40 == 27 ||
                 Control._playerPossition[Control.now_Player] % 40 == 37)
        {
            FloatText.story_text("不知道這裝置能幹什麼用。好像能保護自己的樣子...",
                                 Manager._selectedName[Control.now_Player] + "  獲得防禦一次的機會");
            Control._held[Control.now_Player] = Control.Shield.Withstand;
        }
        //陷阱V
        else if (Control._playerPossition[Control.now_Player] % 40 == 8 ||
                 Control._playerPossition[Control.now_Player] % 40 == 11 ||
                 Control._playerPossition[Control.now_Player] % 40 == 18 ||
                 Control._playerPossition[Control.now_Player] % 40 == 33)
        {
            Attack._Attack(GameObject.Find("Block" + Control._playerPossition[Control.now_Player] % 40));
        }
        //死亡V
        else if (Control._playerPossition[Control.now_Player] % 40 == 9)
        {
            anim.SetBool("isDeath", true);
            GameObject.Find("Canvas").GetComponent <Control>().next.enabled = true;
            Control._playerHp[Control.now_Player] = 0;
            Control._state[Control.now_Player]    = Control.PlayerState.Death;
        }
        //監牢V
        else if (Control._playerPossition[Control.now_Player] % 40 == 19)
        {
            FloatText.story_text("被同伴發現身上有鬼火獸的傷口。被關在了監牢裡面...",
                                 Manager._selectedName[Control.now_Player] + "  暫停一回合 ");
            Control._state[Control.now_Player] = Control.PlayerState.Sleep;
        }
        //隨機移動
        else if (Control._playerPossition[Control.now_Player] % 40 == 30)
        {
            FloatText.story_text("迷宮突然變換了。走著走著不知道到了那裡...",
                                 Manager._selectedName[Control.now_Player] + "  隨機移動 ");
            Control._playerPossition[Control.now_Player] += Random.Range(1, 39);
            Charactor.transform.position = GameObject.Find("Block" + Control._playerPossition[Control.now_Player] % 40).transform.position;
            Grid(Charactor, anim);
        }
        //獲得食物v
        else
        {
            Control._playerHp[Control.now_Player] += 200;
            FloatText.Click(Charactor, 200, "+");
            FloatText.story_text("還好有找到食物,不然已經沒東西吃了...",
                                 Manager._selectedName[Control.now_Player] + " 取得了食物 ,增加了200點生命");
            Time.timeScale = 0;
        }
        int    count = 0;
        string name  = null;

        for (int i = 0; i < 6; i++) //計算過關道具是否全部都有
        {
            if (Control._props[i] == true)
            {
                count++;
            }
            if (count == 6)
            {
                FloatText.WinText(Manager._selectedName[Control.now_Player]);
                Destroy(GameObject.Find("LatticeControl").GetComponent <GridContent>());
            }
        }//計算過關道具是否全部都有↑↑↑
        count = 0;
        for (int i = 0; i < Manager._countLimit; i++) //計算是否剩一位玩家
        {
            if (Control._state[i] != Control.PlayerState.Death)
            {
                count++;
                name = Manager._selectedName[i];
            }
        }
        if (count == 1)
        {
            FloatText.WinText(name);
            Destroy(GameObject.Find("LatticeControl").GetComponent <GridContent>());
        }
        else
        {
            if (Control._playerHp[Control.now_Player] <= 0)
            {
                GameObject.Find("GameOver").GetComponent <Image>().enabled = true;
            }
        }
        //計算是否剩一位玩家↑↑↑
    }
Ejemplo n.º 5
0
 private void OnDrawGizmos()
 {
     Gizmos.color = new Color(255f, 0f, 0f, 0.5f);
     Gizmos.DrawWireSphere(transform.position, interactiveDistance);
     attackControl = GetComponent <AttackControl>();
 }
Ejemplo n.º 6
0
 public void OnClicked()
 {
     CreatureMoveControl.Cancel();
     AttackControl.Cancel();
     // need to add single tile target effect control
 }
Ejemplo n.º 7
0
        public override void OnLoad()
        {
            Paint += OnPaint;

            dd = new SKDrawDebug(HipsterEngine);

            HipsterEngine.Physics.Initialize(-1000, -1000, 1000, 1000, 0, 0f, true);
            HipsterEngine.Physics.GetWorld().SetDebugDraw(dd);

            MousePosition = new Vec2(0, 0);


            HipsterEngine.Surface.Canvas.Camera.SetScale(0.5f);

            HipsterEngine.Surface.Canvas.Camera.Y = Height / 2;
            HipsterEngine.Surface.Canvas.Camera.X = -Width / 2;

            HipsterEngine.Particles.AddParticleSystem(new ParticlesControllerFire(HipsterEngine));


            var        isMove     = false;
            var        mouse      = new Vec2();
            var        listMouses = new List <Vec2>();
            MouseJoint joint      = null;
            Body       body       = null;

            MouseDown += (o, e) =>
            {
                isMove = true;

                if (e.Button == MouseButton.Right)
                {
                    HipsterEngine.Physics.FactoryBody
                    .CreateRigidVertex()
                    .CreateBox(0.2f, 0.2f, 50, 50, 0.2f)
                    .CreateBodyDef(e.X, e.Y, 0, true, false)
                    .Build(1f);
                }
            };
            MouseMove += (o, e) =>
            {
                MousePosition = new Vec2(e.X, e.Y);

                var ps = (ParticlesControllerFire)HipsterEngine.Particles.GetSystem(typeof(ParticlesControllerFire));
                ps.AddBlood(MousePosition.X - HipsterEngine.Surface.Canvas.Camera.X, MousePosition.Y + HipsterEngine.Surface.Canvas.Camera.Y, new Vec2(), 5);

                if (isMove)
                {
                    mouse = new Vec2(e.X / PhysicsController.metric, e.Y / PhysicsController.metric);

                    if (listMouses.Count >= 10)
                    {
                        listMouses.RemoveAt(0);
                    }
                    listMouses.Add(mouse);

                    body = HipsterEngine.Physics.GetRayBody(e.X, e.Y);

                    if (body != null && joint == null)
                    {
                        joint = HipsterEngine.Physics.AddJointMouse(body, mouse);
                    }

                    joint?.SetTarget(mouse);
                }
            };
            MouseUp += (o, e) =>
            {
                if (joint != null)
                {
                    HipsterEngine.Physics.GetWorld().DestroyJoint(joint);
                    joint = null;
                    body  = null;
                }

                isMove = false;
                listMouses.Clear();
            };

            Trees = new List <Tree>();


            InitializeBall();

            //   Robots = new List<IRobot>();
            //   var robot = new Robot(HipsterEngine, Earth);
            //   robot.Initialize(new TwoWheels(), new Box2(), new Gun1())
            //       .Build(Width / 2+200, 120, 90, 20);

            //   var robot1 = new Robot(HipsterEngine, Earth);
            //   robot1.Initialize(new TwoWheels(), new Box2(), new Gun1())
            //       .Build(Width / 2-200, 120, 90, 20);
            //   Robots.Add(robot);
            //   Robots.Add(robot1);

            aControl = new AttackControl(HipsterEngine, 70);
            mControl = new MoveControl(HipsterEngine);
            mControl.Tracker.Move += (sender, vec2) =>
            {
                ValueX = vec2.X;
                //       Robots.First().Transmission.Move(-ValueX / 10);

                if (ValueX > 0)
                {
                    //         ((Gun1) Robots.First().Arms).SetAngleRad(90);
                }
                else if (ValueX < 0)
                {
                    //         ((Gun1) Robots.First().Arms).SetAngleRad(-90);
                }
                else if (ValueX == 0)
                {
                    //     ((Gun1) Robots.First().Arms).SetAngleRad(180);
                }
            };
            aControl.Click += (sender, args) =>
            {
                //       Robots.First().Arms.Attack();
            };

            Timer       = new TimeWatch();
            Timer.Tick += tick => { ((Gun1)Robots.First().Arms).SetAngleRad(tick); };
        }
    /*
     * For now, just a weighted average of the controls of different behaviour.
     * If blended horizontalMovement < 0.5, round to 0. (majority of behaviour said NO to
     * movement)
     * If > 0.5, round to 1.
     *
     * Later some behaviour might only be here for shooting. In that case, we will ignore them.
     */
    private Control BlendControllerBehaviours()
    {
        // The blended values. They are float that will be later rounded to int.
        Vector2 blendedMovement        = new Vector2();
        Vector2 blendedOrientation     = new Vector2();
        float   blendedFire            = 0f;
        float   blendedNextWeapon      = 0f;
        Vector2 blendedAttackDirection = new Vector2();
        float   weightMvtSum           = 0f;
        float   weightAtkSum           = 0f;

        foreach (WeightedBehaviour wb in controllerComponents)
        {
            // Important here! Just get the control once in case it trigger side effects
            // or state machine transitions...
            Control behaviourControl = wb.behaviour.GetControls();

            // ---------------------------------------------------------
            // 1. BLEND MOVEMENT
            // ---------------------------------------------------------

            if (behaviourControl.movementControl != null)
            {
                blendedMovement    += behaviourControl.movementControl.movement * wb.weight;
                blendedOrientation += behaviourControl.movementControl.orientation * wb.weight;
                weightMvtSum       += wb.weight;
            }

            // ---------------------------------------------------------
            // 2. BLEND ATTACK
            // ---------------------------------------------------------
            if (behaviourControl.attackControl != null)
            {
                blendedNextWeapon      += behaviourControl.attackControl.selectNextWeapon * wb.weight;
                blendedAttackDirection += behaviourControl.attackControl.direction * wb.weight;

                if (behaviourControl.attackControl.shouldFire)
                {
                    blendedFire += wb.weight;
                }

                weightAtkSum += wb.weight;
            }
        }

        // put back the values between 0 and 1.
        if (weightMvtSum != 0)
        {
            blendedMovement    /= weightMvtSum;
            blendedOrientation /= weightMvtSum;
        }

        if (weightAtkSum != 0)
        {
            blendedFire            /= weightAtkSum;
            blendedNextWeapon      /= weightAtkSum;
            blendedAttackDirection /= weightAtkSum;
        }
        // Then, assign to Control
        // TODO Value can be either -1, 0 or 1...
        Control control = new Control();

        MovementControl movementControl = new MovementControl();

        movementControl.movement = new Vector2((int)Math.Round(blendedMovement.x, MidpointRounding.AwayFromZero),
                                               (int)Math.Round(blendedMovement.y, MidpointRounding.AwayFromZero));
        movementControl.orientation = new Vector2((int)Math.Round(blendedOrientation.x, MidpointRounding.AwayFromZero),
                                                  (int)Math.Round(blendedOrientation.y, MidpointRounding.AwayFromZero));

        AttackControl attackControl = new AttackControl();

        attackControl.shouldFire       = blendedFire >= 0.5;
        attackControl.selectNextWeapon = (int)Math.Round(blendedNextWeapon, MidpointRounding.AwayFromZero);
        attackControl.direction        = blendedAttackDirection.normalized;


        control.movementControl = movementControl;
        control.attackControl   = attackControl;
        return(control);
    }
Ejemplo n.º 9
0
 // Start is called before the first frame update
 void Start()
 {
     attackControl = GameObject.FindObjectOfType <AttackControl>();
 }