Esempio n. 1
0
        public void Take(PlatformerCharacter bearer)
        {
            this.bearer       = bearer;
            last_bearer       = bearer;
            collide.isTrigger = true;

            sprite_render.sortingLayerID = bearer.GetComponent <SpriteRenderer>().sortingLayerID;
            transform.localScale         = start_size * carry_size;

            if (OnTake != null)
            {
                OnTake.Invoke(bearer.gameObject);
            }

            UpdateCarryItem();
        }
Esempio n. 2
0
        public bool CanTake(GameObject taker)
        {
            PlatformerCharacter player       = taker.GetComponent <PlatformerCharacter>();
            CarryItem           current_item = player.GetHoldingItem();

            if (current_item != null && item_type == current_item.item_type)
            {
                return(false);
            }

            if (take_timer >= -0.01f)
            {
                //Avoid taking back an item you just threw
                return(!throwing || last_bearer != taker);
            }

            return(false);
        }
Esempio n. 3
0
        public static PlatformerCharacter GetNearest(Vector3 pos, float range = 999f, bool alive_only = true)
        {
            PlatformerCharacter nearest = null;
            float min_dist = range;

            foreach (PlatformerCharacter character in character_list.Values)
            {
                if (!alive_only || character.IsAlive())
                {
                    float dist = (pos - character.transform.position).magnitude;
                    if (dist < min_dist)
                    {
                        min_dist = dist;
                        nearest  = character;
                    }
                }
            }
            return(nearest);
        }
Esempio n. 4
0
        public void Drop()
        {
            last_bearer       = this.bearer;
            this.bearer       = null;
            collide.isTrigger = throwing ? false : trigger_at_start;
            take_timer        = -0.01f;

            if (last_bearer && !throwing)
            {
                //Reset straight floor position
                transform.position   = new Vector3(last_bearer.transform.position.x, last_bearer.transform.position.y, initial_pos.z);
                transform.localScale = start_size;
                transform.rotation   = start_rot;
                flipX = 1f;
            }

            if (OnDrop != null)
            {
                OnDrop.Invoke(last_bearer.gameObject);
            }
        }
Esempio n. 5
0
        private void UpdatePosition()
        {
            target_pos = transform.position;
            float target_angle = 0f;

            target_rotation = Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, target_angle);

            if (bearer)
            {
                PlatformerCharacter player = bearer.GetComponent <PlatformerCharacter>();
                Vector3             motion = player.GetMove();
                if (bearer.GetComponent <PlatformerCharacter>())
                {
                    if (motion.magnitude > 0.1f)
                    {
                        last_motion = motion;
                    }
                }

                //Update position of the item
                flipX = player.GetSide();
                GameObject hand = bearer.hold_hand;
                target_pos = hand.transform.position + hand.transform.up * carry_offset.y + hand.transform.right * carry_offset.x * flipX;
                Vector3 rot_vector_forw = Quaternion.Euler(0f, 0f, carry_angle_deg * flipX) * hand.transform.forward;
                Vector3 rot_vector_up   = Quaternion.Euler(0f, 0f, carry_angle_deg * flipX) * hand.transform.up;
                target_rotation = Quaternion.LookRotation(rot_vector_forw, rot_vector_up);
            }

            //Move the object
            transform.position = target_pos;
            transform.rotation = target_rotation;

            //Flip
            transform.localScale = bearer || throwing ? start_size * carry_size : start_size;
            transform.localScale = new Vector3(Mathf.Abs(transform.localScale.x) * flipX, transform.localScale.y, transform.localScale.z);
        }
Esempio n. 6
0
 public static PlatformerCharacter[] GetAll()
 {
     PlatformerCharacter[] list = new PlatformerCharacter[character_list.Count];
     character_list.Values.CopyTo(list, 0);
     return(list);
 }