コード例 #1
0
ファイル: bullet.cs プロジェクト: ahmmohs/divinity
    // Use this for initialization
    void Start()
    {
        rb = gameObject.GetComponent <Rigidbody2D> ();


        camObj = GameObject.Find("Main Camera");
        Camera = camObj.GetComponent <camera> ();

        if (player.direction == 0)
        {
            transform.localScale = new Vector2(0.0807231f, 15.29459f);
            rb.velocity          = new Vector2(0f, bulletSpeed);
        }
        if (player.direction == 1)
        {
            transform.localScale = new Vector2(0.0807231f, 15.29459f);
            rb.velocity          = new Vector2(0f, -bulletSpeed);
        }
        if (player.direction == 2)
        {
            rb.velocity = new Vector2(bulletSpeed, 0f);
        }
        if (player.direction == 3)
        {
            rb.velocity = new Vector2(-bulletSpeed, 0f);
        }
        Camera.cameraShake(.025f, .25f);
    }
コード例 #2
0
ファイル: player.cs プロジェクト: ahmmohs/divinity
    void Controller()
    {
        //movement
        if (smashing == false)
        {
            if (slashing == false)
            {
                if (Input.GetKeyDown(KeyCode.UpArrow))
                {
                    multiDir++;
                }
                if (Input.GetKey(KeyCode.UpArrow))
                {
                    direction = 0;
                    rb.AddForce(transform.up * playerSpeed);
                    movingup = true;
                }
                if (Input.GetKeyUp(KeyCode.UpArrow))
                {
                    multiDir = 0;
                    //rb.velocity = new Vector2 (0f, 0f);
                }
                if (Input.GetKeyDown(KeyCode.DownArrow))
                {
                    multiDir++;
                }
                if (Input.GetKey(KeyCode.DownArrow))
                {
                    direction = 1;
                    rb.AddForce(transform.up * -playerSpeed);
                    movingup = false;
                    moving   = true;
                }
                if (Input.GetKeyUp(KeyCode.DownArrow))
                {
                    moving   = false;
                    multiDir = 0;
                    //rb.velocity = new Vector2 (0f, 0f);
                }
                if (Input.GetKeyDown(KeyCode.RightArrow))
                {
                    multiDir++;
                }
                if (Input.GetKey(KeyCode.RightArrow))
                {
                    direction = 2;
                    rb.AddForce(transform.right * playerSpeed);
                    movingup             = false;
                    moving               = true;
                    transform.localScale = new Vector2(1f, 1f);
                }
                if (Input.GetKeyUp(KeyCode.RightArrow))
                {
                    moving   = false;
                    multiDir = 0;
                    //rb.velocity = new Vector2 (0f, 0f);
                }
                if (Input.GetKeyDown(KeyCode.LeftArrow))
                {
                    multiDir++;
                }
                if (Input.GetKey(KeyCode.LeftArrow))
                {
                    direction = 3;
                    rb.AddForce(transform.right * -playerSpeed);
                    movingup             = false;
                    moving               = true;
                    transform.localScale = new Vector2(-1f, 1f);
                }
                if (Input.GetKeyUp(KeyCode.LeftArrow))
                {
                    moving   = false;
                    multiDir = 0;
                    //rb.velocity = new Vector2 (0f, 0f);
                }


                //shooting
                if (shotsRemain > 0)
                {
                    if (Input.GetKeyDown(KeyCode.X))
                    {
                        shoottime = shootinterval;
                    }
                    if (Input.GetKey(KeyCode.X))
                    {
                        shoottime += Time.deltaTime;
                        shooting   = true;

                        /*if (firstshot == true) {
                         * if (moving == true && shooting == true) {
                         * shootwalking = true;
                         * } else if (movingup == true && shooting == true) {
                         * shootwalking = false;
                         * shooting = false;
                         * } else
                         * shootwalking = false;
                         * Vector3 spawnPos = new Vector3 (0f, 0f, 0f);
                         * if (direction == 0) {
                         * spawnPos = new Vector3 (transform.position.x, transform.position.y + .67f, transform.position.z);
                         * }
                         * if (direction == 1) {
                         * spawnPos = new Vector3 (transform.position.x, transform.position.y - .67f, transform.position.z);
                         * }
                         *
                         * if (direction == 2) {
                         * spawnPos = new Vector3 (transform.position.x + .1f, transform.position.y + .27f, 0);
                         * }
                         * if (direction == 3) {
                         * spawnPos = new Vector3 (transform.position.x - .1f, transform.position.y + .27f, 0);
                         * }
                         * GameObject.Instantiate (bullet, spawnPos, Quaternion.identity);
                         * firstshot = false;
                         * }*/

                        if (shoottime >= shootinterval)
                        {
                            if (moving == true && shooting == true)
                            {
                                shootwalking = true;
                            }
                            else if (movingup == true && shooting == true)
                            {
                                shootwalking = false;
                                shooting     = false;
                            }
                            else
                            {
                                shootwalking = false;
                            }
                            Vector3 spawnPos = new Vector3(0f, 0f, 0f);
                            if (direction == 0)
                            {
                                spawnPos = new Vector3(transform.position.x, transform.position.y + .67f, transform.position.z);
                            }
                            if (direction == 1)
                            {
                                spawnPos = new Vector3(transform.position.x, transform.position.y - .67f, transform.position.z);
                            }

                            if (direction == 2)
                            {
                                spawnPos = new Vector3(transform.position.x + .1f, transform.position.y + .27f, 0);
                            }
                            if (direction == 3)
                            {
                                spawnPos = new Vector3(transform.position.x - .1f, transform.position.y + .27f, 0);
                            }
                            audio.PlayOneShot(shootSound, .1f);
                            GameObject.Instantiate(bullet, spawnPos, Quaternion.identity);
                            player.shotsRemain--;
                            shoottime = 0f;
                        }
                    }
                }

                if (Input.GetKeyUp(KeyCode.X))
                {
                    shooting     = false;
                    shootwalking = false;
                }
            }

            if (swordtime >= swordInt)
            {
                swordCount = false;
                if (slashCount == true)
                {
                    slashTime += Time.deltaTime;
                }
                if (slashTime >= slashInt)
                {
                    slashing       = false;
                    swordtime      = 0;
                    slashTime      = 0;
                    swordCount     = true;
                    slashCount     = false;
                    meleeC.enabled = false;
                }
                if (Input.GetKeyDown(KeyCode.Z))
                {
                    slashing       = true;
                    slashCount     = true;
                    meleeC.enabled = true;
                    Camera.cameraShake(.025f, .25f);
                }
            }


            //dashing
            if (Input.GetKeyDown(KeyCode.Space))
            {
                if (dashcooldown == false)
                {
                    if (multiDir == 2)
                    {
                        rb.AddForce(transform.up * rb.velocity.y * 100);
                        rb.AddForce(transform.right * rb.velocity.x * 100);
                    }
                    else
                    {
                        rb.AddForce(transform.up * rb.velocity.y * 200);
                        rb.AddForce(transform.right * rb.velocity.x * 200);
                    }
                    dashcooldown = true;
                }
            }

            if (dashcooldown == true)
            {
                dashtime += Time.deltaTime;
                if (dashtime >= dashinterval)
                {
                    dashtime     = 0f;
                    dashcooldown = false;
                }
            }
        }
        anim.SetBool("isShooting", shooting);
        anim.SetBool("isShootwalking", shootwalking);
        anim.SetBool("isMoving", moving);
        anim.SetBool("isSmashing", smashing);
        anim.SetBool("isMovingup", movingup);
        anim.SetBool("isSlashing", slashing);
    }
コード例 #3
0
    void OnTriggerEnter2D(Collider2D col)
    {
        if (col.gameObject.tag == "bullet")
        {
            audio.PlayOneShot(impactClip, .6f);
            Vector2 bulSpeed;
            enemyHealth -= enemy.bulDmg;
            bulSpeed     = col.GetComponent <Rigidbody2D>().velocity;


            rb.velocity = bulSpeed / 5;
            Destroy(col.gameObject);
        }

        if (col.gameObject.name == "melee")
        {
            audio.PlayOneShot(impactClip, .6f);

            if (player.direction == 0)
            {
                rb.velocity = (transform.up * 4);
            }
            if (player.direction == 1)
            {
                rb.velocity = (transform.up * -4);
            }
            if (player.direction == 2)
            {
                rb.velocity = (transform.right * 4);
            }
            if (player.direction == 3)
            {
                rb.velocity = (transform.right * -4);
            }

            enemyHealth -= enemy.sDmg;
            if (enemyHealth < 0)
            {
                killedBysword = true;
            }
        }



        if (col.gameObject.name == "player" || col.gameObject.name == "fColl")
        {
            pb2.GetComponent <Rigidbody2D>().velocity = new Vector2((rb.velocity.x * 10), (rb.velocity.y * 10));
            if (tutorial.isTutorial == false)
            {
                Camera.cameraShake(.04f, .15f);
                player.flashing = true;
            }

            if (pb2.velocity.x > maxSpeed.x)
            {
                pb2.GetComponent <Rigidbody2D>().velocity = new Vector2((maxSpeed.x), (pb2.velocity.y));
            }
            if (pb2.velocity.y > maxSpeed.y)
            {
                pb2.GetComponent <Rigidbody2D>().velocity = new Vector2((pb2.velocity.x), (maxSpeed.y));
            }
            //checking if the player gets too much velocity on the knockback
            if (pb2.velocity.x < -maxSpeed.x)
            {
                pb2.GetComponent <Rigidbody2D>().velocity = new Vector2((-maxSpeed.x), (pb2.velocity.y));
            }
            if (pb2.velocity.y < -maxSpeed.y)
            {
                pb2.GetComponent <Rigidbody2D>().velocity = new Vector2((pb2.velocity.x), (-maxSpeed.y));
            }

            if (tutorial.isTutorial == false)
            {
                player.playerHealth = player.playerHealth - enemy.enemyDmg;
            }
        }
    }