Esempio n. 1
0
 public PlayerInput(ADLBaseAgent player, float horizontalAxis, bool isFireButtonDown, bool isJumpButtonDown, bool isJumpButtonUp)
 {
     this.horizontalAxis   = horizontalAxis;
     this.isFireButtonDown = isFireButtonDown;
     this.isJumpButtonDown = isJumpButtonDown;
     this.isJumpButtonUp   = isJumpButtonUp;
 }
Esempio n. 2
0
 public virtual bool DecreaseLifePoint(ADLBaseAgent agent)
 {
     if (!this.isInvulnerable && (agent.isAttacker && this.isDefender))
     {
         this.lifePoint -= agent.attack;
         return(agent.attack > 0);
     }
     return(false);
 }
Esempio n. 3
0
    protected override void Perform(ADLAgent agent)
    {
        //Find SubAgentScript by name
        string spawnAgentName = this.getAgentName();
        string spawnDirection = this.getSpawnDirection();

        ADLScript subAgentScript = agent.agentScript.subAgentScripts.Find(
            script => script.agentName.Equals(spawnAgentName));

        //Instantiate new Agent Object and Assign SubAgentScript to it
        GameObject     projectile     = GameObject.Instantiate(agent.agentPrefab) as GameObject;
        SpriteRenderer spriteRenderer = projectile.GetComponent <SpriteRenderer>();

        spriteRenderer.color = Color.red;

        ADLAgent subAgent = projectile.GetComponent <ADLAgent>();

        subAgent.isInitStateExecuted         = false;
        subAgent.agentScript                 = subAgentScript;
        subAgent.agentScript.subAgentScripts = agent.agentScript.subAgentScripts;

        Vector2 colliderSize = projectile.GetComponent <BoxCollider2D>().size;

        projectile.transform.localPosition = agent.transform.localPosition;

        if (spawnDirection.Equals("TowardPlayer"))
        {
            try {
                ADLBaseAgent player = ADLBaseAgent.FindAgent("Player", agent.transform.parent);
                if (player.transform.localPosition.x > agent.transform.localPosition.x)
                {
                    SetProjectilePositionAndDirection(subAgent, ADLBaseAgent.Direction.Normal);
                }
                else
                {
                    SetProjectilePositionAndDirection(subAgent, ADLBaseAgent.Direction.Inverse);
                }
            } catch (Exception e) when(e is NullReferenceException || e is MissingReferenceException)
            {
                Debug.LogError("Player Not Found: " + e.Message);
                SetProjectilePositionAndDirection(subAgent, agent.horizonDirection);
            }
        }
        else
        {
            SetProjectilePositionAndDirection(subAgent, agent.horizonDirection);
        }
        projectile.transform.localScale = new Vector3(this.getWidth() / colliderSize.x, this.getHeight() / colliderSize.y);

        subAgent.Start();
    }
Esempio n. 4
0
    public override object PerformFunction()
    {
        ADLBaseAgent targetAgent = this.GetAgent();
        ADLBaseAgent self        = ADLAgent.currentUpdatingAgent;

        if (self.collisionList.Contains(targetAgent))
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
Esempio n. 5
0
 public void Flip(ADLBaseAgent agent)
 {
     if (this.isFlipper && agent.isFlippable)
     {
         if (agent.prevVelocity.x > 0.01 || agent.prevVelocity.x < -0.01)
         {
             Debug.Log("Flip X");
             agent.horizonDirection = GetOppositeDirection(agent.horizonDirection);
         }
         if (agent.prevVelocity.y > 0.01 || agent.prevVelocity.y < -0.01)
         {
             Debug.Log("Flip Y");
             agent.verticalDirection = GetOppositeDirection(agent.verticalDirection);
         }
     }
 }
Esempio n. 6
0
    public override object PerformFunction()
    {
        ADLBaseAgent agent      = this.GetAgent();
        float        conditionY = (float)Math.Round(this.GetY(), 2);

        float   prevY           = (float)Math.Round(agent.prevPosition.y, 2);
        Vector2 currentPosition = agent.GetComponent <Rigidbody2D>().position;
        float   currY           = (float)Math.Round(currentPosition.y, 2);

        //Debug.Log("Curr Y: " + currY + " Prev Y: " + prevY + " Condition Y: " + conditionY);
        if ((prevY <= conditionY && currY >= conditionY) || (prevY >= conditionY && currY <= conditionY))
        {
            agent.GetComponent <Rigidbody2D>().position = new Vector2(currentPosition.x, conditionY);
            return(true);
        }

        return(false);
    }
Esempio n. 7
0
    protected override void Perform(ADLAgent agent)
    {
        ADLBaseAgent player = ADLBaseAgent.FindAgent("Player", agent.transform.parent);

        try {
            if (player.transform.localPosition.x > agent.transform.localPosition.x)
            {
                agent.horizonDirection = ADLBaseAgent.Direction.Normal;
            }
            else
            {
                agent.horizonDirection = ADLBaseAgent.Direction.Inverse;
            }
        } catch (Exception e) when(e is NullReferenceException || e is MissingReferenceException)
        {
            Debug.LogError("Player Not Found: " + e.Message);
        }
    }
Esempio n. 8
0
    public override object PerformFunction()
    {
        ADLBaseAgent agent = this.GetAgent();

        float conditionX = (float)Math.Round(this.GetX(), 2);

        float   prevX           = (float)Math.Round(agent.prevPosition.x, 2);
        Vector2 currentPosition = agent.GetComponent <Rigidbody2D>().position;
        float   currX           = (float)Math.Round(currentPosition.x, 2);

        if ((prevX <= conditionX && currX >= conditionX) || (prevX >= conditionX && currX <= conditionX))
        {
            agent.GetComponent <Rigidbody2D>().position = new Vector2(conditionX, currentPosition.y);
            return(true);
        }

        return(false);
    }
Esempio n. 9
0
    public override object PerformFunction()
    {
        ADLBaseAgent agent = this.GetAgent();

        string propertyKey = agent.agentName + "Y";

        float y;

        if (ADLAgent.currentUpdatingAgent.simulationState.singleQueryProperties[ADLAction.performingAction].ContainsKey(this))
        {
            y = (float)ADLAgent.currentUpdatingAgent.simulationState.singleQueryProperties[ADLAction.performingAction][this];
        }
        else
        {
            y = agent.GetComponent <Rigidbody2D>().position.y;
            ADLAgent.currentUpdatingAgent.simulationState.singleQueryProperties[ADLAction.performingAction].Add(this, y);
        }
        return(y);
    }
Esempio n. 10
0
 private float CastToFloat(object obj, ADLBaseAgent agent, int axis)
 {
     if (obj is ADLSinFunction)
     {
         return(System.Convert.ToSingle(((ADLSinFunction)obj).PerformFunction()));
         // if (axis == 0)
         //  return System.Convert.ToSingle(((ADLSinFunction)obj).PerformFunction2(agent.horizonDirection > 0));
         // else
         //  return System.Convert.ToSingle(((ADLSinFunction)obj).PerformFunction2(agent.verticalDirection > 0));
     }
     else if (obj is ADLFunction)
     {
         return(System.Convert.ToSingle(((ADLFunction)obj).PerformFunction()));
     }
     else
     {
         return(System.Convert.ToSingle(obj));
     }
 }
Esempio n. 11
0
    public bool Attack(ADLBaseAgent agent)
    {
        if (agent.IsEnvironment())
        {
            return(false);
        }

        if (this.isProjectile)
        {
            if (this.group != agent.group)
            {
                return(agent.DecreaseLifePoint(this));
            }
            return(false);
        }
        else
        {
            return(agent.DecreaseLifePoint(this));
        }
    }
Esempio n. 12
0
    public override bool DecreaseLifePoint(ADLBaseAgent agent)
    {
        bool isLifePointDecreased = base.DecreaseLifePoint(agent);

        if (isLifePointDecreased)
        {
            if (this.agentLifePointText != null)
            {
                if (this.IsAlive())
                {
                    this.agentLifePointText.text = "LP: " + this.lifePoint;
                }
                else
                {
                    this.agentLifePointText.text = "LP: " + 0;
                }
            }
            StartCoroutine(Fade());
        }

        return(isLifePointDecreased);
    }
    public override object PerformFunction()
    {
        ADLBaseAgent firstAgent  = this.GetAgent(0);
        ADLBaseAgent secondAgent = this.GetAgent(1);

        try{
            float distance;
            if (ADLAgent.currentUpdatingAgent.simulationState.singleQueryProperties[ADLAction.performingAction].ContainsKey(this))
            {
                distance = (float)ADLAgent.currentUpdatingAgent.simulationState.singleQueryProperties[ADLAction.performingAction][this];
            }
            else
            {
                distance = Math.Abs(firstAgent.GetComponent <Rigidbody2D>().transform.localPosition.x - secondAgent.GetComponent <Rigidbody2D>().transform.localPosition.x);
                ADLAgent.currentUpdatingAgent.simulationState.singleQueryProperties[ADLAction.performingAction].Add(this, distance);
            }
            return(distance);
        } catch (NullReferenceException e) {
            Debug.LogError(e.Message);
            return(0);
        }
    }
Esempio n. 14
0
    // Update is called once per frame
    void Update()
    {
        if (state.Equals(GameState.Running) && isControlledByPlayer)
        {
            PlayerInput input = new PlayerInput(ADLBaseAgent.FindAgent("Player", this.transform.parent), Input.GetAxis("Horizontal"), Input.GetButtonDown("Fire1"), Input.GetButtonDown("Jump"), Input.GetButtonUp("Jump"));
            playerInputSequence.Add(input);

            // string json = JsonUtility.ToJson(new ListWrapper<Entity>(entities));
            // entitiesRecord.Add(json.Substring(8, json.Length - 9));
        }

        if (state.Equals(GameState.End))
        {
            if (this.isFileUploaded)
            {
                alertText.text = "Press Enter to Play again";
            }
            else
            {
                alertText.text = "Uploading Report ...";
            }
        }
    }
Esempio n. 15
0
    void OnCollisionEnter2D(Collision2D coll)
    {
        //Debug.Log("Collision between " + this.gameObject.name + " " + coll.gameObject.name);

        ADLBaseAgent agent = coll.gameObject.GetComponent <ADLBaseAgent>();

        this.collisionList.Add(agent);

        this.Flip(agent);

        //Attack Event
        if (this.Attack(agent))
        {
            if (!agent.IsAlive())
            {
                if (agent is PlayerController && agent.gameObject.GetComponent <RockmanVisualAgent>() != null)
                {
                    // Do Nothing
                }
                else
                {
                    Destroy(agent.gameObject);
                }
            }
        }

        if (this.isProjectile && agent.IsEnvironment())
        {
            if (!this.isFlippable || !agent.isFlipper)
            {
                if (this.isHittableByEnvironment && !this.safeEnvironmentList.Contains(agent.agentName))
                {
                    Destroy(this.gameObject);
                }
            }
        }
    }
Esempio n. 16
0
        public Entity(ADLBaseAgent agent)
        {
            this.x = agent.transform.localPosition.x;
            this.y = agent.transform.localPosition.y;

            if (agent is ADLEnvironment)
            {
                this.width  = 0;
                this.height = 0;
            }
            else
            {
                this.width  = agent.transform.localScale.x * agent.GetComponent <BoxCollider2D>().size.x;
                this.height = agent.transform.localScale.y * agent.GetComponent <BoxCollider2D>().size.y;
            }

            this.agentName               = agent.agentName;
            this.lifePoint               = agent.lifePoint;
            this.attack                  = agent.attack;
            this.isAttacker              = agent.isAttacker;
            this.isDefender              = agent.isDefender;
            this.isFlippable             = agent.isFlippable;
            this.isFlipper               = agent.isFlipper;
            this.isProjectile            = agent.isProjectile;
            this.isInvulnerable          = agent.isInvulnerable;
            this.isHittableByProjectile  = agent.isHittableByProjectile;
            this.isHittableByEnvironment = agent.isHittableByEnvironment;
            this.group             = agent.group.ToString();
            this.horizonDirection  = (int)agent.horizonDirection;
            this.verticalDirection = (int)agent.verticalDirection;

            if (agent is ADLAgent)
            {
                this.currentState = ((ADLAgent)agent).simulationState.currentState.name;
            }
        }
Esempio n. 17
0
    public override object PerformFunction()
    {
        ADLBaseAgent agent = this.GetAgent();

        float x;

        if (ADLAgent.currentUpdatingAgent.simulationState.singleQueryProperties[ADLAction.performingAction].ContainsKey(this))
        {
            x = (float)ADLAgent.currentUpdatingAgent.simulationState.singleQueryProperties[ADLAction.performingAction][this];
        }
        else
        {
            try{
                x = agent.GetComponent <Rigidbody2D>().position.x;
            }
            catch (Exception e) when(e is NullReferenceException || e is MissingReferenceException)
            {
                Debug.LogWarningFormat("Specified Agent Not Found - {0}", e.Message);
                x = 0;
            }
            ADLAgent.currentUpdatingAgent.simulationState.singleQueryProperties[ADLAction.performingAction].Add(this, x);
        }
        return(x);
    }
Esempio n. 18
0
 private float GetYVelocity(ADLBaseAgent agent)
 {
     return((int)agent.verticalDirection * this.GetFloatParameter(1));
 }
Esempio n. 19
0
 private float GetXVelocity(ADLBaseAgent agent)
 {
     return((int)agent.horizonDirection * this.GetFloatParameter(0));
 }
Esempio n. 20
0
    /**
     * This method is solely used inside ADLMoveAction
     */
    public object processRPN(ADLBaseAgent agent, int axis)
    {
        Stack resultStack     = new Stack();
        Queue processingQueue = (Queue)this.rpnQueue.Clone();

        while (processingQueue.Count != 0)
        {
            //If Front of Queue is Operand
            //Push Operand into Stack
            if (processingQueue.Peek() is int ||
                processingQueue.Peek() is float ||
                processingQueue.Peek() is bool ||
                processingQueue.Peek() is ADLFunction ||
                processingQueue.Peek() is string && !OPERATOR_LIST.Contains((string)processingQueue.Peek()))
            {
                if (processingQueue.Peek() is int)
                {
                    if (axis == 0)
                    {
                        resultStack.Push((int)agent.horizonDirection * (int)processingQueue.Dequeue());
                    }
                    else
                    {
                        resultStack.Push((int)agent.verticalDirection * (int)processingQueue.Dequeue());
                    }
                }
                else if (processingQueue.Peek() is float)
                {
                    if (axis == 0)
                    {
                        resultStack.Push((int)agent.horizonDirection * (float)processingQueue.Dequeue());
                    }
                    else
                    {
                        resultStack.Push((int)agent.verticalDirection * (float)processingQueue.Dequeue());
                    }
                }
                else
                {
                    resultStack.Push(processingQueue.Dequeue());
                }
            }
            //If Front of Queue is Operator
            //Operate top 2 operands then push the result into Stack
            else
            {
                object op1 = resultStack.Pop();
                object op2 = resultStack.Pop();
                resultStack.Push(operate((string)processingQueue.Dequeue(), CastToFloat(op1, agent, axis), CastToFloat(op2, agent, axis)));
            }
        }

        //Cast the result into appropriate type
        if (resultStack.Peek() is string)
        {
            return(resultStack.Pop() as string);
        }
        else if (resultStack.Peek() is bool)
        {
            return((bool)resultStack.Pop());
        }
        else
        {
            return(this.CastToFloat(resultStack.Pop(), agent, axis));
        }
    }
    private ADLBaseAgent GetAgent(int parameterIndex)
    {
        string agentName = this.GetStringParameter(parameterIndex);

        return(ADLBaseAgent.FindAgent(agentName, ADLAgent.currentUpdatingAgent.transform.parent));
    }
Esempio n. 22
0
    protected override void Perform(ADLAgent agent)
    {
        Rigidbody2D rigidbody2D = agent.GetComponent <Rigidbody2D>();

        agent.horizonDirection = ADLBaseAgent.GetOppositeDirection(agent.horizonDirection);
    }