Ejemplo n.º 1
0
    void Update()
    {
        if (Input.GetButtonDown("UseItem") && equipped != null)
        {
            if (!info.isAiming)   //enter aiming mode
            {
                info.isAiming = true;
            }
            else     //confirm item use
            {
                info.isAiming = false;
                DestroyHighlights();

                //apply ability effect
                int[,] pattern = equipped.GetComponent <Equipment>().pattern;
                Vector3 pos = info.interacter.GetComponent <BoxCollider2D>().transform.position;
                highlight = DrawHighlights.createPattern(Resources.Load("tile_attack") as GameObject, pattern, pos, info.facing);
                foreach (Transform t in highlight.transform)
                {
                    t.gameObject.AddComponent <KillAfterAnimation>();



                    //kill any enemies standing on square

                    foreach (var enemy in GlobalContainer.global.enemies.GetComponentsInChildren <Transform>())
                    {
                        if (enemy.position.Equals(t.position))
                        {
                            Destroy(enemy.gameObject);
                            info.score += 1;
                        }
                    }
                }

                //play a cool sound
                TempSoundPlayer sp = Instantiate(Resources.Load("TempSoundPlayer") as GameObject).GetComponent <TempSoundPlayer>();
                sp.playSound(info.attackSound);

                if (!equipped.GetComponent <Equipment>().activate()) //use item
                {
                    unequipEquipment();                              //if its durability is used up, destroy it
                }
            }
        }

        //Update highlights
        if (info.isAiming)   //MAKE THIS BETTER AND NOT UPDATE EVERY LOOP

        //If item uses tile highlighting
        {
            int[,] pattern = equipped.GetComponent <Equipment>().pattern;
            if (pattern != null)
            {
                DestroyHighlights();
                Vector3 pos = info.interacter.GetComponent <BoxCollider2D>().transform.position;
                highlight = DrawHighlights.createPattern(Resources.Load("tile_select2") as GameObject, pattern, pos, info.facing);
            }
        }
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        //Attack
        if (Input.GetMouseButtonDown(0) && equipped != null && equipped.GetComponent <MeleeWeapon>() != null)
        {
            MeleeWeapon w = equipped.GetComponent <MeleeWeapon>();


            w.activate();

            //if (!w.isActive) { w.activate(); }
        }

        //Unequip
        if (Input.GetMouseButtonDown(1) && equipped != null)
        {
            equipped.transform.parent = null;
            GrabableObject go = equipped.GetComponent <GrabableObject>();
            go.owner = null;
            go.reset_y_position();
            equipped.transform.localRotation = Quaternion.identity;
            equipped = null;
            anim.SetBool("isHolding", false);

            //play sound
            TempSoundPlayer sp = (Instantiate(Resources.Load("TempSoundPlayer"), transform.position, transform.rotation) as GameObject).GetComponent <TempSoundPlayer>();
            sp.setVolume(0.2f);
            sp.playSound(drop_sound);
        }
    }
Ejemplo n.º 3
0
    public void PlayerDeath()
    {
        TempSoundPlayer sp = Instantiate(Resources.Load("TempSoundPlayer") as GameObject).GetComponent <TempSoundPlayer>();

        sp.playSound(deathSound);
        Destroy(global.player);
        //SceneManager.LoadScene("Game Over");
    }
    public override void onHit()
    {
        //TODO: Hit particle effects and sounds
        if (hit_particle != null)
        {
            Instantiate(hit_particle, transform.position, transform.rotation);
        }

        if (hit_sounds.Length > 0)
        {
            TempSoundPlayer sp       = (Instantiate(Resources.Load("TempSoundPlayer"), transform.position, transform.rotation) as GameObject).GetComponent <TempSoundPlayer>();
            AudioClip       hit_clip = hit_sounds[Random.Range(0, hit_sounds.Length)];
            sp.playSound(hit_clip);
        }
    }
    public override void OnInteraction()
    {
        health -= 1;

        if (health >= 0)
        {
            TempSoundPlayer sp = Instantiate(Resources.Load("TempSoundPlayer") as GameObject).GetComponent <TempSoundPlayer>();
            sp.playSound(crate_hit);
            anim.Play("crate", 0, 0.9f - ((float)health / 2)); //change frame the crate is displaying
        }

        if (health == 0)
        {
            isCollision = false; //after crate dies, you can walk over it
        }
    }
    public override void onDeath()
    {
        //TODO: DEath particle effects and sounds
        if (kill_particle != null)
        {
            Instantiate(kill_particle, transform.position, transform.rotation);
        }

        if (kill_sounds.Length > 0)
        {
            TempSoundPlayer sp        = (Instantiate(Resources.Load("TempSoundPlayer"), transform.position, transform.rotation) as GameObject).GetComponent <TempSoundPlayer>();
            AudioClip       kill_clip = kill_sounds[Random.Range(0, kill_sounds.Length)];
            sp.playSound(kill_clip);
        }


        Destroy(this.gameObject);
    }
Ejemplo n.º 7
0
    private void OnTriggerEnter2D(Collider2D other)   //EQUIP OBJECT
    {
        if (other.gameObject.GetComponent <Equipment>() != null)
        {
            if (equipped != null)
            {
                Destroy(equipped);
            }                                           //remove previous item if there is

            Transform equipment = other.gameObject.transform;

            equipment.SetParent(transform);
            equipment.localPosition = Vector3.zero;
            equipment.gameObject.SetActive(false);
            equipped = equipment.gameObject;

            //play a sound
            TempSoundPlayer sp = Instantiate(Resources.Load("TempSoundPlayer") as GameObject).GetComponent <TempSoundPlayer>();
            sp.playSound(info.pickupSound);
        }
    }
Ejemplo n.º 8
0
    private void OnTriggerStay(Collider other)
    {
        if (Input.GetKeyDown(KeyCode.E) && other.GetComponent <GrabableObject>() != null && equipped == null)
        {
            equipped = other.gameObject;
            equipped.transform.parent = grabPoint.transform;
            GrabableObject go = other.gameObject.GetComponent <GrabableObject>();
            equipped.transform.localPosition = go.position_offset;
            equipped.transform.localRotation = go.rotation_offset;
            go.owner = this.gameObject;
            //equipped.GetComponent<CapsuleCollider>().enabled = false;
            if (go.two_hand_hold)
            {
                anim.SetBool("isHolding", true);
            }

            //play sound
            TempSoundPlayer sp = (Instantiate(Resources.Load("TempSoundPlayer"), transform.position, transform.rotation) as GameObject).GetComponent <TempSoundPlayer>();
            sp.setVolume(0.2f);
            sp.playSound(pickup_sound);
        }
    }
Ejemplo n.º 9
0
    public override void onDeath()
    {
        intact_state.SetActive(false);
        broken_state.SetActive(true);

        //TODO: DEath particle effects and sounds
        if (kill_particle != null)
        {
            Instantiate(kill_particle, transform.position, transform.rotation);
        }

        if (kill_sounds.Length > 0)
        {
            TempSoundPlayer sp        = (Instantiate(Resources.Load("TempSoundPlayer"), transform.position, transform.rotation) as GameObject).GetComponent <TempSoundPlayer>();
            AudioClip       kill_clip = kill_sounds[Random.Range(0, kill_sounds.Length)];
            sp.playSound(kill_clip);
        }

        //Drop some items
        if (drop_table.Count > 0)
        {
            int ind = Random.Range(0, drop_table.Count - 1);
            Instantiate(drop_table[ind], transform.position, Quaternion.identity);
        }

        if (disable_collision_on_death)
        {
            GetComponent <Collider>().enabled = false;
        }

        GameObject gh = Instantiate(Container.self.ghost, transform);

        gh.GetComponent <Enemy>().player = Container.self.player;

        isBroken = true;
    }
    void Update()
    {
        //Move player by grid

        info.gameObject.transform.position = Vector2.MoveTowards(info.gameObject.transform.position, movePoint, move_speed);

        //Get player input
        if (Vector2.Distance(info.gameObject.transform.position, movePoint) <= moveThreshold)
        {
            //assume keyboard
            int x = 0; int y = 0;
            if (Input.GetButtonDown("Up"))
            {
                y = 1; info.facing = new Vector2(0, 1);
            }
            else if (Input.GetButtonDown("Down"))
            {
                y = -1; info.facing = new Vector2(0, -1);
            }
            else if (Input.GetButtonDown("Left"))
            {
                x = -1; info.facing = new Vector2(-1, 0);
            }
            else if (Input.GetButtonDown("Right"))
            {
                x = 1; info.facing = new Vector2(1, 0);
            }

            dir = new Vector3(x, y, 0);
            //Determine if move is valid

            Vector3      pos = info.interacter.GetComponent <BoxCollider2D>().transform.position;
            RaycastHit2D hit = Physics2D.Raycast(pos, dir, 1, 1 << LayerMask.NameToLayer("COLLIDER"));

            //Handle collisions with a raycast
            if (hit && hit.collider.gameObject.GetComponent <InteractionHandler>() && hit.collider.gameObject.GetComponent <InteractionHandler>().isCollision)
            {
                info.interacter.GetComponent <PlayerInteracter>().TriggerInteract(hit.collider);
            }
            else if (!info.isAiming)
            {
                if ((int)dir.magnitude != 0)
                {
                    global.playerMoved = true;

                    //play a sound
                    TempSoundPlayer sp = Instantiate(Resources.Load("TempSoundPlayer") as GameObject).GetComponent <TempSoundPlayer>();
                    sp.playSound(info.moveSound);
                }

                movePoint += dir;
            }

            //flip playser sprite based on input
            info.sr.flipX = info.facing.x < 0;
            if (global.tiles[-(int)(movePoint.y + .5f)][(int)(movePoint.x - 1.5f)] == 0)
            {
                //PLayer dies
                info.PlayerDeath();
                //Destroy(transform.parent.gameObject);
            }
        }
    }