Ejemplo n.º 1
0
 public override void OnDead()
 {
     if (_canDrop)
     {
         // TODO: tehokkaampi drop
         for (int i = 0; i < 10; i++)
         {
             DropScript.Drop(ResourceManager.Instance.GetCorpseDrops(), transform);
         }
     }
 }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        // Detects if the character is moving right. If it is, flips it
        // horizontally.
        bool flip = Input.GetKeyDown(KeyCode.RightArrow);

        if (flip)
        {
            dir_right = true;
            foreach (SpriteRenderer childsr in sr)
            {
                childsr.flipX = true;
            }
            ani.SetBool("left", false);
            ani.SetBool("right", true);
        }

        // Detects if the character is moving left. If it is, unflips it
        // horizontally.
        bool unflip = Input.GetKeyDown(KeyCode.LeftArrow);

        if (unflip)
        {
            dir_right = false;
            foreach (SpriteRenderer childsr in sr)
            {
                childsr.flipX = false;
            }
            ani.SetBool("left", true);
            ani.SetBool("right", false);
        }

        // moving horizontally
        float inputX = Input.GetAxis("Horizontal");

        if (!inputX.Equals(0))
        {
            rb.velocity = new Vector2(speed.x * inputX, rb.velocity.y);
        }
        //else {
        //    ani.SetBool("left", false);
        //    ani.SetBool("right", false);
        //}

        // jumping
        if (Input.GetKeyDown(KeyCode.UpArrow) && isGrounded())
        {
            rb.AddForce(Vector2.up * jumpForce * (float)1.88,
                        ForceMode2D.Impulse);
        }

        // dropping a stack of books (usually used for holding buttons)
        bool drop = Input.GetKeyDown("space");

        if (drop)
        {
            DropScript drop2 = GetComponent <DropScript>();
            if (drop2 != null)
            {
                drop2.Drop();
            }
        }

        // shooting a book at an enemy (attacking)
        bool shoot = Input.GetKeyDown(KeyCode.RightShift);

        if (shoot)
        {
            WeaponScript weapon = GetComponent <WeaponScript>();
            if (weapon != null)
            {
                weapon.Attack(false);
            }
        }
    }