Exemplo n.º 1
0
    public void PlayerTestSimplePasses()
    {
        //Initialize player controller object
        Player_control pctrl = new Player_control();

        //Create vector to mime inputs
        Vector2 inputs   = new Vector2(0.0f, 0.0f);
        Vector2 movement = new Vector2(0.0f, 0.0f);

        //Testing for the movement vector calculator for all possible inputs
        for (int i = 0; i < 2; i++)
        {
            for (int j = 0; j < 2; j++)
            {
                inputs   = new Vector2(-1.0f + i, -1.0f + j);
                movement = pctrl.movement_calculator(inputs.x, inputs.y);
                inputs.Normalize();
                Assert.AreEqual(movement.x, inputs.x);
                Assert.AreEqual(movement.y, inputs.y);
            }
        }
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        //Get the rb2d for the player
        rb2d     = GetComponent <Rigidbody2D>();
        animator = GetComponent <Animator>();

        //Get the raw input for the input axis
        float moveHorizontal = Input.GetAxisRaw("Horizontal");
        float moveVertical   = Input.GetAxisRaw("Vertical");



        wu = false;
        wd = false;
        wl = false;
        wr = false;


        if (moveHorizontal == 1.0)
        {
            wr = true;
        }
        if (moveHorizontal == -1.0)
        {
            wl = true;
        }
        if (moveVertical == 1.0)
        {
            wu = true;
        }
        if (moveVertical == -1.0)
        {
            wd = true;
        }


        //Get the movement vectore based on input from the player controller
        movement = pctrl.movement_calculator(moveHorizontal, moveVertical);


        //Move the player based on the player's speed/ movement vector, and time between frames.
        rb2d.MovePosition(rb2d.position + movement * speed * Time.fixedDeltaTime);

        // Shooting up
        if (Input.GetKey(KeyCode.UpArrow) || test_key_up)
        {
            au = true;
            WeaponFire weapon = GetComponent <WeaponFire>();
            weapon.set_dmg(damage);
            weapon.set_fire_rate(fire_rate);
            weapon.set_range(range);
            weapon.set_shot_speed(shot_speed);


            if (weapon != null)
            {
                // false because the player is not an enemy
                weapon.AttackUp();
            }
        }
        else
        {
            au = false;
        }

        // Shooting down
        if (Input.GetKey(KeyCode.DownArrow) || test_key_down)
        {
            ad = true;
            WeaponFire weapon = GetComponent <WeaponFire>();
            weapon.set_dmg(damage);
            weapon.set_fire_rate(fire_rate);
            weapon.set_range(range);
            weapon.set_shot_speed(shot_speed);

            if (weapon != null)
            {
                // false because the player is not an enemy
                weapon.AttackDown();
            }
        }
        else
        {
            ad = false;
        }

        // Shooting right
        if (Input.GetKey(KeyCode.RightArrow) || test_key_right)
        {
            ar = true;
            WeaponFire weapon = GetComponent <WeaponFire>();
            weapon.set_dmg(damage);
            weapon.set_fire_rate(fire_rate);
            weapon.set_range(range);
            weapon.set_shot_speed(shot_speed);

            if (weapon != null)
            {
                // false because the player is not an enemy
                weapon.AttackRight();
            }
        }
        else
        {
            ar = false;
        }

        // Shooting left
        if (Input.GetKey(KeyCode.LeftArrow) || test_key_left)
        {
            al = true;
            WeaponFire weapon = GetComponent <WeaponFire>();
            weapon.set_dmg(damage);
            weapon.set_fire_rate(fire_rate);
            weapon.set_range(range);
            weapon.set_shot_speed(shot_speed);

            if (weapon != null)
            {
                // false because the player is not an enemy
                weapon.AttackLeft();
            }
        }
        else
        {
            al = false;
        }

        //Animation controller logic
        //If attacking
        if (au || al || ar || ad)
        {
            //Set the animation bool based on attacking direction

            animator.SetBool("au", au);
            animator.SetBool("al", al);
            animator.SetBool("ar", ar);
            animator.SetBool("ad", ad);

            //move flags are set to false so we play attack and not move animations if attacking
            animator.SetBool("wl", false);
            animator.SetBool("wr", false);
            animator.SetBool("wu", false);
            animator.SetBool("wd", false);
        }
        //else -- not attacking
        else
        {
            animator.SetBool("au", au);
            animator.SetBool("al", al);
            animator.SetBool("ar", ar);
            animator.SetBool("ad", ad);
            animator.SetBool("wl", wl);
            animator.SetBool("wr", wr);
            animator.SetBool("wu", wu);
            animator.SetBool("wd", wd);
        }
    }