public void OnSpawned()
        {
            slots.physicsObject.isEnabled = true;

            willDespawnOnSceneExit = true;
            isFiring         = false;
            isDead           = false;
            isBeingReflected = false;
            spawningActor    = null;
            spawningAttack   = null;

            framesMovedInCurrentHorizontalDirection = 0;
            framesMovedInCurrentVerticalDirection   = 0;

            remainingFramesBeforeDespawn = framesBeforeDespawn;

            remainingHorizontalFlips = horizontalFlipsAllowed;
            remainingVerticalFlips   = verticalFlipsAllowed;

            ResetToOriginalValues();

            GetComponent <Collider2D>().enabled = true;

            direction.horizontal = Direction.Horizontal.Neutral;
            direction.vertical   = Direction.Vertical.Neutral;

            StopAllCoroutines();
            StartCoroutine("SpawnCoroutine");

            ParentHelper.Parent(gameObject, ParentHelper.ParentObject.Projectiles);
        }
        protected void ProcessCollision(Collider2D col)
        {
            if ((col.tag == "Player" && willDestroyOnHit.player) || (col.tag == "Enemy" && willDestroyOnHit.enemy))
            {
                if (!isDead)
                {
                    RexActor targetActor = col.gameObject.GetComponent <RexActor>();
                    if (targetActor != null && spawningActor != null && targetActor == spawningActor)                    //Don't collide if this is the same actor that spawned it
                    {
                        return;
                    }

                    OnDeath();
                }
            }

            if (col.gameObject.tag == "Reflector")
            {
                if (!isBeingReflected && reflection.willReflectOnReflectors)
                {
                    Reflector reflector = col.GetComponent <Reflector>();
                    if (!(reflector && spawningActor && reflector.actor == spawningActor))
                    {
                        Reflect(reflector);
                        isBeingReflected = true;
                        spawningActor    = null;
                    }
                }
                else if (!reflection.willReflectOnReflectors)
                {
                    isDead = true;
                    OnDeath();
                }
            }
        }
Exemple #3
0
        private static void AddProjectileAttack()
        {
            GameObject selectedObject = Selection.activeGameObject;
            RexActor   actor          = null;

            if (selectedObject)
            {
                actor = selectedObject.GetComponent <RexActor>();
            }

            GameObject attackGameObject = null;

            if (actor != null)
            {
                Transform attackTransform = actor.transform.Find("Attacks");
                if (attackTransform)
                {
                    attackGameObject = attackTransform.gameObject;
                }
            }

            if (attackGameObject == null && actor != null)
            {
                attackGameObject                  = new GameObject();
                attackGameObject.name             = "Attacks";
                attackGameObject.transform.parent = actor.transform;
            }

            if (actor != null)
            {
                Object     prefab = Resources.Load("Templates/ProjectileAttackTemplate") as Object;
                GameObject projectileGameObject = Instantiate(prefab, SceneView.lastActiveSceneView.pivot, Quaternion.identity) as GameObject;
                projectileGameObject.name = "ProjectileAttack";
                PrefabUtility.DisconnectPrefabInstance(projectileGameObject);
                projectileGameObject.transform.parent        = attackGameObject.transform;
                Selection.activeGameObject                   = projectileGameObject;
                projectileGameObject.transform.localPosition = new Vector3(1.94f, 0.0f, 0.0f);

                Attack attack = projectileGameObject.GetComponent <Attack>();
                attack.slots.actor          = actor;
                attack.slots.audio          = actor.GetComponent <AudioSource>();
                attack.slots.boxCollider    = attack.GetComponent <BoxCollider2D>();
                attack.slots.spriteRenderer = attack.GetComponentInChildren <SpriteRenderer>();

                if (actor.tag == "Enemy")
                {
                    attack.GetComponent <ContactDamage>().willDamagePlayer  = true;
                    attack.GetComponent <ContactDamage>().willDamageEnemies = false;
                }
            }
            else
            {
                EditorUtility.DisplayDialog("Ruh-roh!", "Please select a GameObject with a RexActor component to attach this attack to first.", "Got it!");
            }
        }
Exemple #4
0
        void Awake()
        {
            gameObject.tag = "Reflector";

            Attack attack = GetComponent <Attack>();

            if (attack)
            {
                actor = attack.slots.actor;
            }
        }
Exemple #5
0
        protected bool IsActorAlreadyInList(RexActor rexActor)
        {
            bool isRexActorInList = false;

            for (int i = actorsTouched.Count - 1; i >= 0; i--)
            {
                if (actorsTouched[i].actor == rexActor)
                {
                    isRexActorInList = true;
                }
            }

            return(isRexActorInList);
        }
Exemple #6
0
        protected virtual void ProcessCollision(Collider2D col, CollisionType type = CollisionType.Enter)
        {
            if (col.tag != "Terrain")            //Ignoring terrain collisions speeds up performance here
            {
                bool willBounce = false;
                if (type == CollisionType.Enter)
                {
                    if (slots.controller)
                    {
                        BounceState bounce = slots.controller.bounceState;
                        if (bounce && slots.collider)
                        {
                            if (bounce.CanBounce(slots.collider, col))
                            {
                                willBounce = true;
                                bounce.StartBounce(slots.collider, col);
                                RexActor bouncedOnActor = col.GetComponent <RexActor>();
                                if (bouncedOnActor)
                                {
                                    bouncedOnActor.Damage(bounce.damageDealt, false);
                                    bouncedOnActor.OnBouncedOn(slots.collider);
                                }
                            }
                        }
                    }
                }

                if (!willBounce)
                {
                    ContactDamage contactDamage = col.GetComponent <ContactDamage>();
                    if (contactDamage != null)
                    {
                        if (col.GetComponent <RexActor>() && col.GetComponent <RexActor>().isDead)
                        {
                            return;
                        }

                        if (tag == "Player" && contactDamage.willDamagePlayer)
                        {
                            Damage(contactDamage.amount, true, BattleEnums.DamageType.Regular, col);
                        }
                        else if (tag == "Enemy" && contactDamage.willDamageEnemies)
                        {
                            Damage(contactDamage.amount, true, BattleEnums.DamageType.Regular, col);
                        }
                    }
                }
            }
        }
        //Uses positioning and collider data to determine if we can start a bounce from an object
        public bool CanBounce(Collider2D bouncerCol, Collider2D otherCol)
        {
            bool canBounce = false;

            if (isEnabled && controller.isEnabled && IsColliderBelow(bouncerCol, otherCol) && !controller.slots.physicsObject.IsOnSurface())
            {
                RexActor actorToBounceOn = otherCol.GetComponent <RexActor>();
                if (actorToBounceOn != null && actorToBounceOn.canBounceOn)
                {
                    canBounce = true;
                }
            }

            return(canBounce);
        }
Exemple #8
0
 protected void OnTriggerEnter2D(Collider2D col)
 {
     if (col.tag == "Player")
     {
         RexActor rexActor = col.GetComponent <RexActor>();
         if (rexActor != null)
         {
             if (!IsActorAlreadyInList(rexActor))
             {
                 ActorWithSide actorWithSide = new ActorWithSide();
                 actorWithSide.actor = rexActor;
                 actorWithSide.side  = RexObject.Side.None;
                 actorsTouched.Add(actorWithSide);
                 CheckForEnter();
             }
         }
     }
 }
        protected override void TriggerEffect(RexActor player)
        {
            if (player == null)
            {
                return;
            }

            if (equation == Equation.Increment)
            {
                //Debug.Log("Add " + amount + " to score");
                ScoreManager.Instance.IncrementScore(amount);
            }
            else
            {
                //Debug.Log("Remove " + amount + " from score");
                ScoreManager.Instance.DecrementScore(amount);
            }
        }
Exemple #10
0
 protected void OnTriggerExit2D(Collider2D col)
 {
     if (col.tag == "Player")
     {
         RexActor rexActor = col.GetComponent <RexActor>();
         if (rexActor != null)
         {
             for (int i = actorsTouched.Count - 1; i >= 0; i--)
             {
                 if (actorsTouched[i].actor == rexActor)
                 {
                     actorsTouched.RemoveAt(i);
                     return;
                 }
             }
         }
     }
 }
        protected override void TriggerEffect(RexActor player)
        {
            if (player == null)
            {
                return;
            }

            if (energyType == EnergyType.HP)
            {
                if (equation == Equation.Increment)
                {
                    player.RestoreHP(amount);
                }
                else
                {
                    player.Damage(amount);
                }
            }
            else if (energyType == EnergyType.Weapon)
            {
                if (equation == Equation.Increment)
                {
                    player.RestoreMP(amount);
                }
                else
                {
                    player.DecrementMP(amount);
                }
            }
            else if (energyType == EnergyType.Lives)
            {
                if (equation == Equation.Increment)
                {
                    LivesManager.Instance.IncrementLives(amount);
                }
                else
                {
                    LivesManager.Instance.DecrementLives(amount);
                }
            }
        }
Exemple #12
0
 public override void NotifyOfCollisionWithPhysicsObject(Collider2D col, Side side, CollisionType type)
 {
     if (col.tag == "Player")
     {
         RexActor rexActor = col.GetComponent <RexActor>();
         if (rexActor != null)
         {
             if (!IsActorAlreadyInList(rexActor))
             {
                 if (side == actorSide)
                 {
                     ActorWithSide actorWithSide = new ActorWithSide();
                     actorWithSide.actor = rexActor;
                     actorWithSide.side  = side;
                     actorsTouched.Add(actorWithSide);
                     CheckForEnter();
                 }
             }
         }
     }
 }
Exemple #13
0
 protected void CheckForEnter()
 {
     if (!hasOpened)
     {
         for (int i = actorsTouched.Count - 1; i >= 0; i--)
         {
             RexActor rexActor = actorsTouched[i].actor;
             if (rexActor != null)
             {
                 if (actorSide == actorsTouched[i].side)
                 {
                     if ((rexActor.slots.input && (rexActor.slots.input.verticalAxis == (int)pressDirectionVertical && rexActor.slots.input.horizontalAxis == (int)pressDirectionHorizontal)) || willOpenOnTouch)
                     {
                         hasOpened = true;
                         Open();
                     }
                 }
             }
         }
     }
 }
        public void Fire(Vector2 _startingPosition, Direction.Horizontal _horizontal, Direction.Vertical _vertical, RexActor _spawningActor, RexPool _parentSpawnPool = null)
        {
            if (!willDestroyWhenSceneChanges)
            {
                DontDestroyOnLoad(gameObject);
            }

            isFiring         = true;
            isBeingReflected = false;
            movementSpeed    = originalMovementSpeed;
            spawningActor    = _spawningActor;

            if (sounds.fireSound)
            {
                GetComponent <AudioSource>().PlayOneShot(sounds.fireSound);
            }

            if (_parentSpawnPool != null)
            {
                parentSpawnPool = _parentSpawnPool;
            }

            SetPosition(_startingPosition);
            SetHorizontalDirection(_horizontal);
            SetVerticalDirection((Direction.Vertical)((int)startingVerticalDirection * (int)_vertical * PhysicsManager.Instance.gravityScale));

            firingDirection = _horizontal;

            slots.physicsObject.properties.acceleration = Vector2.zero;

            float startingXSpeed = (acceleration == 0.0f) ? movementSpeed.x * (int)direction.horizontal : 0.0f;

            slots.physicsObject.SetVelocityX(startingXSpeed);
            slots.physicsObject.SetAccelerationCapX(movementSpeed.x * (int)direction.horizontal);

            float startingYSpeed = (acceleration == 0.0f) ? movementSpeed.y * (int)direction.vertical : 0.0f;

            slots.physicsObject.SetVelocityY(startingYSpeed);
            slots.physicsObject.SetAccelerationCapY(movementSpeed.y * (int)direction.vertical);
        }
Exemple #15
0
        protected void ProcessCollision(Collider2D col, RexObject.CollisionType collisionType)
        {
            float    waveTop = GetComponent <BoxCollider2D>().bounds.max.y;
            RexActor actor   = col.gameObject.GetComponent <RexActor>();

            if (actor != null)
            {
                if (collisionType == RexObject.CollisionType.Enter)
                {
                    actor.NotifyOfWaterlineContact(collisionType);
                    GenerateEnterSplash(new Vector2(col.gameObject.transform.position.x, waveTop), col.gameObject.transform);
                }
                else if (collisionType == RexObject.CollisionType.Exit)
                {
                    actor.NotifyOfWaterlineContact(collisionType);
                    if (actor.waterProperties.waterBodiesTouched <= 0)
                    {
                        GenerateExitSplash(new Vector2(col.gameObject.transform.position.x, waveTop), col.gameObject.transform);
                    }
                }
            }
        }
Exemple #16
0
 protected virtual void TriggerEffect(RexActor player)
 {
 }
Exemple #17
0
        private void ProcessCollision(Collider2D col)
        {
            RexObject rexObject = col.GetComponent <RexObject>();

            if (rexObject != null)
            {
                RexActor actor = col.GetComponent <RexActor>();
                if (actor != null && actor.isDead)
                {
                    return;
                }

                if (rexObject.willDespawnOnSceneExit || isBottomlessPit)
                {
                    float buffer        = 0.5f * GlobalValues.tileSize;
                    float warningBuffer = 0.15f * GlobalValues.tileSize;
                    if (edge == Edge.Right)
                    {
                        if (rexObject.transform.position.x > transform.position.x + buffer)
                        {
                            rexObject.Clear();
                        }
                        else if (rexObject.transform.position.x > transform.position.x + warningBuffer)
                        {
                            rexObject.OnSceneBoundaryCollisionInsideBuffer();
                        }
                    }
                    else if (edge == Edge.Left)
                    {
                        if (rexObject.transform.position.x < transform.position.x - buffer)
                        {
                            rexObject.Clear();
                        }
                        else if (rexObject.transform.position.x < transform.position.x - warningBuffer)
                        {
                            rexObject.OnSceneBoundaryCollisionInsideBuffer();
                        }
                    }
                    else if (edge == Edge.Top)
                    {
                        if (rexObject.transform.position.y > transform.position.y + buffer)
                        {
                            rexObject.Clear();
                        }
                        else if (rexObject.transform.position.y > transform.position.y + warningBuffer)
                        {
                            rexObject.OnSceneBoundaryCollisionInsideBuffer();
                        }
                    }
                    else if (edge == Edge.Bottom)
                    {
                        if (rexObject.transform.position.y < transform.position.y - buffer)
                        {
                            rexObject.Clear();
                        }
                        else if (rexObject.transform.position.y < transform.position.y - warningBuffer)
                        {
                            rexObject.OnSceneBoundaryCollisionInsideBuffer();
                        }
                    }
                }
            }
        }
 void OnDestroy()
 {
     camera      = null;
     focusObject = null;
 }
 public void SetFocusObject(RexActor _focusObject)
 {
     focusObject = _focusObject;
 }
Exemple #20
0
        private static void FillRexActorSlots()
        {
            GameObject selectedObject = Selection.activeGameObject;
            RexActor   actor          = null;

            if (selectedObject)
            {
                actor = selectedObject.GetComponent <RexActor>();
            }

            if (actor != null)
            {
                actor.slots.physicsObject  = actor.GetComponent <RexPhysics>();
                actor.slots.anim           = actor.GetComponent <Animator>();
                actor.slots.controller     = actor.GetComponentInChildren <RexController>();
                actor.slots.input          = actor.GetComponent <RexInput>();
                actor.slots.jitter         = actor.GetComponent <Jitter>();
                actor.slots.spriteHolder   = actor.transform.Find("SpriteHolder");
                actor.slots.spriteRenderer = actor.transform.Find("SpriteHolder").GetComponentInChildren <SpriteRenderer>();

                if (actor.damagedProperties.spritesToFlash == null)
                {
                    actor.damagedProperties.spritesToFlash = new List <SpriteRenderer>();
                }

                actor.damagedProperties.spritesToFlash.Add(actor.slots.spriteRenderer);
                actor.slots.collider = actor.GetComponent <BoxCollider2D>();

                RexPhysics physicsObject = actor.GetComponent <RexPhysics>();
                if (physicsObject != null)
                {
                    physicsObject.rexObject = actor;
                }

                RexController controller = actor.slots.controller;
                if (controller)
                {
                    controller.slots.actor = actor;
                    actor.waterProperties.landController = controller;
                }

                Energy[] energy = actor.GetComponentsInChildren <Energy>();
                if (energy.Length > 0)
                {
                    for (int i = 0; i < energy.Length; i++)
                    {
                        if (energy[i].gameObject.name == "HP")
                        {
                            actor.hp = energy[i];
                        }
                        else if (energy[i].gameObject.name == "MP")
                        {
                            actor.mp = energy[i];
                        }
                    }

                    if (actor.hp == null)
                    {
                        actor.hp = energy[0];
                    }
                }

                Attack[] attacks = actor.GetComponentsInChildren <Attack>();
                for (int i = 0; i < attacks.Length; i++)
                {
                    attacks[i].slots.actor = actor;
                }

                EditorUtility.DisplayDialog("Yeah!", "The RexActor was successfully slotted!", "Yay!");
            }
            else
            {
                EditorUtility.DisplayDialog("Ruh-roh!", "Please select a GameObject with a RexActor component first.", "Got it!");
            }
        }