Ejemplo n.º 1
0
 void attack()
 {
     if (!w1.anima.IsPlaying("sword"))
     {
         w1.attack();
     }
 }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        float   horizontal = Input.GetAxis("Horizontal");
        float   vertical   = Input.GetAxis("Vertical");
        Vector2 move       = new Vector2(horizontal, vertical);

        if (move != Vector2.zero)
        {
            faceDir = move.normalized;
        }
        Vector2 position = transform.position;

        position = position + move * speed * Time.deltaTime;
        rigidBody2d.MovePosition(position);
        bool h = Input.GetKeyDown("h");

        if (h)
        {
            changeManaPoint();
            if (targetEnermy == null || (targetEnermy.transform.position - transform.position).magnitude > 10)
            {
                GameObject  go    = GameObject.Find("/Enermy");
                Transform[] trans = go.GetComponentsInChildren <Transform>();
                if (trans != null && trans.Length > 0)
                {
                    setTargetEnermy();
                }
            }
            Debug.Log("when press h:" + targetEnermy);
            currentWeapon.attack(gameObject, targetEnermy, faceDir);
        }
        bool k = Input.GetKeyDown("k");

        if (k)
        {
            /*GameObject pfb = Resources.Load("prefabs/1") as GameObject;
             * GameObject prefabInstance = Instantiate(pfb);
             * prefabInstance.transform.parent = transform;
             * prefabInstance.AddComponent<weapon>();*/

            currentWeaponIndex = currentWeaponIndex + 1;
            if (currentWeaponIndex >= weapons.Length - 1)
            {
                currentWeaponIndex = 0;
            }
            currentWeapon = weapons[currentWeaponIndex].GetComponent <weapon>();
            transform.Find("/UsedWeapon").GetComponentInChildren <Image>().sprite = currentWeapon.getSprite();
        }
    }
Ejemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        Vector2 move = new Vector2(randomX, randomY);

        if (move != Vector2.zero)
        {
            faceDir = move.normalized;
        }
        if (time <= 0)
        {
            time    = 2;
            randomX = Random.Range(-1f, 1f);
            randomY = Random.Range(-1f, 1f);
            currentWeapon.attack(gameObject, leadingRole, this.faceDir);
        }
        Vector2 position = transform.position;

        position = position + move * speed * Time.deltaTime;
        rigidBody2d.MovePosition(position);

        time -= Time.deltaTime;
    }
Ejemplo n.º 4
0
        public static int combat(int enemyMaxHealth, ref weapon enemyWeapon, int playerMaxHealth, ref int playerHealth, ref weapon playerWeapon)
        {
            bool run         = false;
            int  enemyHealth = enemyMaxHealth;

            while (enemyHealth > 0 && run != true && playerHealth > 0)
            {// your turn
                Console.Clear();
                Console.WriteLine("Your health: {0}\nEnemy Health: {1}\nCurrent Weapon: {2}", playerHealth, enemyHealth, playerWeapon.name);
                bool skip = false;
                while (!skip)   // if you need to exit out of one of the menus
                {
                    skip = true;
                    int selection = choice(new string[] { "Attack", "Use Item or Switch Weapon", "Run" });
                    switch (selection)
                    {
                    case 1:
                        int damage = playerWeapon.attack();
                        enemyHealth -= damage;
                        Print("you attack for " + Convert.ToString(damage) + " damage");
                        break;

                    case 2:
                        int item = useItem();
                        if (item == 0 || item == inventory.Count + 1)     // either nothing was entered or back was selected
                        {
                            skip = false;
                        }
                        else if (inventory[item - 1] is potion)
                        {
                            playerHealth = Math.Min(playerHealth + ((potion)inventory[item - 1]).healingEffect, playerMaxHealth);     // heal the player to at most their max health
                        }
                        else
                        {
                            playerWeapon = (weapon)inventory[item - 1];
                        }
                        break;

                    case 3:
                        run = new Random().Next(0, 1) == 1;
                        if (run)
                        {
                            Console.WriteLine("You successfully ran");
                        }
                        else
                        {
                            Console.WriteLine("You couldn't escape");
                        }
                        break;

                    default:
                        Console.WriteLine("You Flinched!");
                        break;
                    }
                }
                if (enemyHealth <= 0)
                {
                    // enemy turn
                    int enemyDamage = enemyWeapon.attack();
                    playerHealth -= enemyDamage;
                    Print("the enemy hit you for " + Convert.ToString(enemyDamage) + " and you are now on " + Convert.ToString(playerHealth) + " HP");
                    Console.Clear();
                }
            }
            if (playerHealth == 0)
            {
                Print("you have been defeated, your health is 0");
                Thread.Sleep(1000);
            }
            else
            {
                Print("your foe has been defeated");
            }
            Thread.Sleep(1000);
            Console.Clear();
            return(-1);
        }