Beispiel #1
0
    //Keep track of how long energy has been in this block's system.
    //Animate said energy accordingly, and attempt to send it to another block upon reaching an interval specified in Battle_Manager
    public void UpdateEnergy()
    {
        //Only update energy if there is energy to update.
        if (HasEnergy == true)
        {
            EnergyPossessionTimer += Time.deltaTime;
            //If this block just obtained energy, position the energy sprite based on this block's Enter and ExitDirection
            if (HadEnergy == false)
            {
                //Call ModifyEnergy on the first frame when energy enters this block.
                ModifyEnergy();
                PossessedEnergy.GetComponent <SpriteRenderer>().enabled = true;
            }
            //Move energy through first half of block.
            else if (EnergyPossessionTimer < Battle_Manager.energyTravelSpeed / 2f)
            {
                if (EnterDirectionA != ExitDirection)
                {
                    MoveEnergyFirstHalf(EnterDirectionA);
                }
                else if (EnterDirectionB != ExitDirection)
                {
                    MoveEnergyFirstHalf(EnterDirectionB);
                }
            }
            //If the energy has just completed half of its movmeent through this block, update its initial position to the center of this block.
            else if (prevPossessionTimer < Battle_Manager.energyTravelSpeed / 2f && EnergyPossessionTimer >= Battle_Manager.energyTravelSpeed)
            {
                PossessedEnergy.transform.position = transform.position;
            }
            //Move energy through second half of block.
            else if (EnergyPossessionTimer >= Battle_Manager.energyTravelSpeed / 2f && EnergyPossessionTimer < Battle_Manager.energyTravelSpeed)
            {
                MoveEnergySecondHalf();
            }
            //If the energy has completed its movement, send it to the next block.
            else if (EnergyPossessionTimer >= Battle_Manager.energyTravelSpeed)
            {
                FindSendTarget();
                EnergyPossessionTimer = 0f;
            }
        }
        else
        {
            EnergyPossessionTimer = 0f;
        }


        HadEnergy           = HasEnergy;
        prevPossessionTimer = EnergyPossessionTimer;
    }
Beispiel #2
0
 //Transfer energy from this block to another that has been found and approved by AttemptSend
 public void AttemptSend(Node_Block targetBlock)
 {
     //Debug.Log("Target block exists, really attempting send...");
     if (!targetBlock.HasEnergy)
     {
         if (targetBlock.EnterDirectionA == (Directions)(((int)ExitDirection + 2) % 4)) //Results in opposite direction from ExitDirection.
         {
             if (!targetBlock.IsSource && !targetBlock.IsReceiver)                      //Sources and receivers don't have dynamic ExitDirections.
             {
                 targetBlock.ExitDirection = targetBlock.EnterDirectionB;
             }
             targetBlock.HasEnergy       = true;
             targetBlock.PossessedEnergy = PossessedEnergy;
             PossessedEnergy.EnteredNewBlock();
             PossessedEnergy = null;
             HasEnergy       = false;
         }
         else if (targetBlock.EnterDirectionB == (Directions)(((int)ExitDirection + 2) % 4) && !targetBlock.IsSource && !targetBlock.IsReceiver) //Sources and receivers don't have a second EnterDirection.
         {
             targetBlock.ExitDirection   = targetBlock.EnterDirectionA;
             targetBlock.HasEnergy       = true;
             targetBlock.PossessedEnergy = PossessedEnergy;
             PossessedEnergy.EnteredNewBlock();
             PossessedEnergy = null;
             HasEnergy       = false;
         }
         else
         {
             //Send fails if targetBlock doesn't have the corresponding EnterDirection.
             DeleteEnergy();
         }
     }
     else
     {
         //Send fails if targetBlock already has energy.
         DeleteEnergy();
     }
 }