Esempio n. 1
0
 void Awake()
 {
     _rigidbody2D  = GetComponent <Rigidbody2D>();
     _entityData   = GetComponent <EntityData>();
     _entityAttack = GetComponent <EntityAttack>();
     _animator     = GetComponentInChildren <Animator>();
 }
Esempio n. 2
0
        /// <summary>
        ///   Awake.
        /// </summary>
        private void Awake()
        {
            _stateMachineController = new StateMachineController();
            _navMeshAgent           = GetComponent <NavMeshAgent>();
            _entity = GetComponent <Entity>();

            EntityIdle        entityIdle        = new EntityIdle();
            EntityChasePlayer entityChasePlayer = new EntityChasePlayer(_navMeshAgent);
            EntityAttack      entityAttack      = new EntityAttack();
            EntityDead        entityDead        = new EntityDead();

            _stateMachineController.Add(entityIdle);
            _stateMachineController.Add(entityChasePlayer);
            _stateMachineController.Add(entityAttack);

            _stateMachineController.AddAnyStateTransition(entityDead, () => _entity.IsDead);

            Player player = FindObjectOfType <Player>();

            _stateMachineController.AddStateTransition(entityIdle,
                                                       entityChasePlayer,
                                                       () => FlatDistance(_navMeshAgent.transform.position, player.transform.position) < 5);
            _stateMachineController.AddStateTransition(entityChasePlayer,
                                                       entityAttack,
                                                       () => FlatDistance(_navMeshAgent.transform.position, player.transform.position) < 2);

            _stateMachineController.ChangeState(entityIdle);
        }
Esempio n. 3
0
        private void StartStage(Stage stage)
        {
            EntityHealth playerHealth = stage.PlayerEntity.GetComponent <EntityHealth>();

            playerHealth.OnHealthChanged += UpdateHealth;

            EntityAttack playerAttack = stage.PlayerEntity.GetComponent <EntityAttack>();

            playerAttack.OnDamageChanged += UpdateDamage;
        }
Esempio n. 4
0
        public ActionAttackEntity(Entity owner, Entity target, bool onTargetDeathTryAutoAttack) : base(owner)
        {
            _target = target;

            _entityMovement  = entity.GetCharacterComponent <EntityMovement>();
            _entityDetection = entity.GetCharacterComponent <EntityDetection>();
            _entityAttack    = entity.GetCharacterComponent <EntityAttack>();

            _onTargetDeathTryAutoAttack = onTargetDeathTryAutoAttack;
        }
Esempio n. 5
0
    void Awake()
    {
        _rigidbody2D  = GetComponent <Rigidbody2D>();
        _entityData   = GetComponent <EntityData>();
        _entityAttack = GetComponent <EntityAttack>();

        _animator       = GetComponent <Animator>();
        _spriteRenderer = GetComponent <SpriteRenderer>();

        _factoryManager = FindObjectOfType <FactoryManager>();
        _factoryBound   = _factoryManager.Bound;

        _battlefieldBound = GameObject.FindGameObjectWithTag("BattlefieldBound").transform;
    }
Esempio n. 6
0
    // Use this for initialization
    void Start()
    {
        /// Base class initialisation
        sprRend = GetComponent <SpriteRenderer>();

        rb   = GetComponent <Rigidbody2D>();
        anim = GetComponent <Animator>();

        health   = 100;
        atkSpeed = 2.0f;

        range        = weapon.AtkRange;
        speed        = (int)maxSpeed;
        atk          = weapon.Atk;
        initialAtk   = atk;
        initialSpeed = speed;
        defense      = 10;

        /// This class initialisation
        player       = GameObject.FindGameObjectWithTag("Player");
        entityAttack = GetComponent <EntityAttack>();
        originalPos  = transform.position;

        //remove this later
        initialColor = sprRend.color;

        CurrState = InitialState;

        entityAttack.AtkCooldown = weapon.AtkSpeed;
        colorTime  = 0.2f;
        colorTimer = colorTime;

        ExpValue = 100;

        currDir = new Vector2(1, 1);

        /*
         * if (IsFacingRight)
         * {
         *  localMove = -1.0f;
         * }
         * else
         * {
         *  localMove = 1.0f;
         * }
         */
    }
Esempio n. 7
0
    // Use this for initialization
    void Start()
    {
        // base class initialisation
        rb      = gameObject.GetComponent <Rigidbody2D>();
        anim    = gameObject.GetComponent <Animator>();
        sprRend = GetComponent <SpriteRenderer>();

        //remove this later
        initialColor = sprRend.color;

        maxHealth = 100;
        health    = maxHealth;

        speed = 5;

        colorTime  = 0.2f;
        colorTimer = colorTime;

        // this class initialisation
        entityAttack = GetComponent <EntityAttack>();
        skillControl = GetComponent <SkillControl>();
        inv          = GetComponent <Inventory>();
        menuManager  = GameObject.FindGameObjectWithTag("MenuManager").GetComponent <MenuManager>();

        maxStamina = 100;
        stamina    = maxStamina;

        exp = 0;

        isJumping = false;

        weapon.SetWeapon((byte)Game.current.equippedWeaponID);
        atk   = weapon.Atk;
        range = weapon.AtkRange;
        entityAttack.AtkCooldown = weapon.AtkSpeed;
        Defense = armor.Defense;

        LayerMask enemyLayer    = LayerMask.GetMask("Enemy");
        LayerMask obstacleLayer = LayerMask.GetMask("Obstacle");
        LayerMask targetLayer   = enemyLayer | obstacleLayer;

        entityAttack.targetLayer = targetLayer;
    }
Esempio n. 8
0
    // Use this for initialization
    void Start()
    {
        /// Base class initialisation
        sprRend = GetComponent <SpriteRenderer>();

        rb   = GetComponent <Rigidbody2D>();
        anim = GetComponent <Animator>();

        #region StatInit
        atkCount    = 0;
        comboDelay  = 0.5f;
        health      = 100;
        atkSpeed    = 2.0f;
        attackDelay = atkSpeed;

        skillCounter = 0;
        attackCd     = 0;
        atkCount     = 0;

        range   = weapon.AtkRange;
        speed   = (int)maxSpeed;
        atk     = weapon.Atk;
        defense = 10;
        #endregion

        /// This class initialisation
        player       = GameObject.FindGameObjectWithTag("Player");
        entityAttack = GetComponent <EntityAttack>();
        originalPos  = transform.position;

        CurrState = InitialState;

        #region Color
        colorTime    = 0.2f;
        colorTimer   = colorTime;
        initialColor = sprRend.color;
        #endregion

        ExpValue = 100;

        currDir = new Vector2(1, 1);
    }
 private void Awake()
 {
     entityAttack = GetComponent <EntityAttack>();
     cellEntity   = GetComponent <CellEntity>();
 }
 public VampirismWeaponEffect(VampirismWeaponEffectData data, GameObject target) : base(data, target)
 {
     attack = target.GetComponent <EntityAttack>();
     health = target.GetComponent <EntityHealth>();
 }
 public ActionMoveToPositionAggressively(Entity owner, Vector3 position) : base(owner)
 {
     _position     = position;
     _entityAttack = entity.GetCharacterComponent <EntityAttack>();
 }
Esempio n. 12
0
 private void UpdateDamage(EntityAttack entityAttack)
 {
     damageText.text = entityAttack.AttackDamage.ToString();
 }
 public FireDamageWeaponEffect(FireDamageWeaponEffectData data, GameObject target) : base(data, target)
 {
     attack = target.GetComponent <EntityAttack>();
 }
Esempio n. 14
0
        // all physics calculations are done within here
        // this is called from within MainManager
        public void PhysicsUpdate()
        {
            accum += deltaTime;

            //Calculate physics on the current frame
            while (accum > deltaTime)
            {
                colliderTest1        = null;
                colliderTest2        = null;
                currentCollisionPair = new List <CollisionPair>();
                depthX     = 0f;
                depthY     = 0f;
                xDistance  = 0f;
                yDistance  = 0f;
                xDirection = 0f;
                yDirection = 0f;

                // if no path simulate normally
                //calculate rigidbodies
                for (int i = 0; i < rigidBodiesInScene.Count; i++)
                {
                    // entity calc
                    if (rigidBodiesInScene[i].tag == "Entity")
                    {
                        bool charging = false;
                        recentHit = false;

                        // check if player attacked
                        // player charge attack
                        if (Input.GetMouseButtonDown(0))
                        {
                            chargeDmg  = 0;
                            chargeRate = 1000f;
                            charging   = true;

                            if (charging == true)
                            {
                                chargeDmg += chargeRate * Time.deltaTime;
                            }
                        }
                        if (Input.GetMouseButtonUp(0))
                        {
                            charging  = false;
                            chargeDmg = Mathf.Clamp(chargeDmg, 0f, 100f);
                            //create a player attack area and check if the enemy is inside it
                            GameObject   t       = Instantiate(Resources.Load("EntityAttack")) as GameObject;
                            GameObject   graphic = Instantiate(Resources.Load("AttackGraphic")) as GameObject;
                            EntityAttack et      = t.GetComponent <EntityAttack>();
                            et.InitAttack();
                            CustomRigidbody player = GameObject.FindGameObjectWithTag("Player").GetComponent <CustomRigidbody>();

                            Vector2 direction = et.GetDirection(player).normalized;
                            t.transform.position = (Vector2)player.transform.position + direction;

                            graphic.transform.position = (Vector2)player.transform.position + direction;
                            graphic.transform.SetParent(player.transform);

                            Transform[] q = graphic.GetComponentsInChildren <Transform>();

                            foreach (Transform tr in q)
                            {
                                if (tr.tag == "pointer")
                                {
                                    graphic.transform.rotation = tr.rotation;
                                }
                            }


                            if (et.IsColliding(rigidBodiesInScene[i]))
                            {
                                // if hit, set enemy velocity to the direction of where the player pointed
                                rigidBodiesInScene[i].m_IsIgnoringGravity = false;
                                rigidBodiesInScene[i].m_Velocity          = direction * chargeDmg;
                                rigidBodiesInScene[i].m_IsEnemyDead       = true;
                                Destroy(et.gameObject);
                                DestroyObject(graphic.gameObject, 0.5f);
                            }
                            else
                            {
                                DestroyObject(graphic.gameObject);
                                Destroy(et.gameObject, 0.5f);
                            }
                        }

                        // if entity has been attacked, dont path find
                        AStarPathfind a = new AStarPathfind();
                        if (rigidBodiesInScene[i].m_IsEnemyDead != true)
                        {
                            // calculate entity positions for pathfinding
                            playerPos = new Vector2(0, 0);
                            enemyPos  = new Vector2(0, 0);

                            for (int l = 0; l < entityBoundingBoxes.Count; l++)
                            {
                                if (entityBoundingBoxes[l].tag == "Player")
                                {
                                    playerPos = entityBoundingBoxes[l].transform.position;
                                }
                            }
                            // generate path to player
                            playerNode = grid.NodeFromWorldPoint(playerPos);
                            enemyNode  = grid.NodeFromWorldPoint(rigidBodiesInScene[i].transform.position);

                            path  = a.AStarSearch(grid, enemyNode, playerNode);
                            dPath = path;
                            //path = null;
                        }
                        else
                        {
                            Destroy(a);
                            path = null;
                        }

                        // if path exists move through it
                        if (path != null)
                        {
                            for (int j = 0; j < path.Count; j++)
                            {
                                rigidBodiesInScene[i].m_EnemyHasPath = false;
                                Vector2 direction = (path[j] - (Vector2)rigidBodiesInScene[i].transform.position);
                                direction.Normalize();
                                rigidBodiesInScene[i].m_EnemyMoveDirection = direction;
                                rigidBodiesInScene[i].m_EnemyHasPath       = true;
                                rigidBodiesInScene[i].EnemyPhysicsLoop();
                            }
                        }
                        // if entity has been attacked, re enable gravity
                        else if (path == null || rigidBodiesInScene[i].m_IsEnemyDead == true)
                        {
                            rigidBodiesInScene[i].m_EnemyHasPath      = false;
                            rigidBodiesInScene[i].m_IsIgnoringGravity = false;
                            rigidBodiesInScene[i].EnemyPhysicsLoop();
                        }
                    }
                    // calc player and other rigidbodies
                    if (rigidBodiesInScene[i].tag == "Player")
                    {
                        rigidBodiesInScene[i].PlayerPhysicsLoop();
                    }
                    else if (rigidBodiesInScene[i].tag != "Player" || rigidBodiesInScene[i].tag != "Entity")
                    {
                        rigidBodiesInScene[i].PlayerPhysicsLoop();
                    }
                }

                //calculate collisions
                for (int j = 0; j < entityBoundingBoxes.Count; j++)
                {
                    // this is the current entity we are checking colliders against
                    // we dont need to check collisions between platforms.
                    colliderTest1 = entityBoundingBoxes[j];

                    //collision between entity and ground
                    for (int k = 0; k < floorBoundingBoxes.Count; k++)
                    {
                        colliderTest2 = floorBoundingBoxes[k];

                        if (TestAABBOverlap(colliderTest1, colliderTest2))
                        {
                            if (colliderTest1.GetComponent <CustomRigidbody>().m_IsEnemyDead == true)
                            {
                                entityBoundingBoxes.Remove(colliderTest1);
                                rigidBodiesInScene.Remove(colliderTest1.GetComponent <CustomRigidbody>());
                                Destroy(colliderTest1.gameObject);
                                isEnemyActive = false;
                            }
                            colliderTest1.GetComponent <CustomRigidbody>().m_IsGrounded = true;
                            //Debug.Log(string.Format("Ground Collision between: {0} and {1}", colliderTest1, colliderTest2));
                            PopulateCollisionData(colliderTest1, colliderTest2);
                        }
                    }

                    //collision between entity and entity
                    for (int l = 0; l < entityBoundingBoxes.Count; l++)
                    {
                        colliderTest2 = entityBoundingBoxes[l];

                        //Don't collide with itself
                        if (colliderTest1 == colliderTest2)
                        {
                            continue;
                        }

                        if (TestAABBOverlap(colliderTest1, colliderTest2))
                        {
                            //Debug.Log(string.Format("Entity Collision between: {0} and {1}", colliderTest1, colliderTest2));
                            PopulateCollisionData(colliderTest1, colliderTest2);

                            float[] moveVals = { 12, -12 };

                            int chooseAxis = 0;
                            // enemy 'attacks'
                            // choose a random direction to set the players velocity in
                            if (colliderTest1.tag == "Player")
                            {
                                CustomRigidbody rb = colliderTest1.GetComponent <CustomRigidbody>();
                                rb.m_PlayerHasBeenHit = true;
                                float v = Random.Range(0, moveVals.Length);
                                chooseAxis = Random.Range(0, 1);
                                if (chooseAxis == 0)
                                {
                                    rb.m_Velocity = new Vector2(moveVals[Random.Range(0, moveVals.Length)], 0);
                                }
                                if (chooseAxis == 1)
                                {
                                    rb.m_Velocity = new Vector2(0, moveVals[Random.Range(0, moveVals.Length)]);
                                }
                            }
                            if (colliderTest2.tag == "Player")
                            {
                                CustomRigidbody rb = colliderTest2.GetComponent <CustomRigidbody>();
                                rb.m_PlayerHasBeenHit = true;
                                int v = Random.Range(0, moveVals.Length);
                                chooseAxis = Random.Range(0, 1);
                                if (chooseAxis == 0)
                                {
                                    rb.m_Velocity = new Vector2(moveVals[Random.Range(0, moveVals.Length)], 0);
                                }
                                if (chooseAxis == 1)
                                {
                                    rb.m_Velocity = new Vector2(0, moveVals[Random.Range(0, moveVals.Length)]);
                                }
                            }
                        }
                    }

                    // Finally check whether an entity has hit the boundaries of the screen
                    // and needs to be removed from scene
                    for (int i = 0; i < boundaryBoundingBoxes.Count; i++)
                    {
                        colliderTest2 = boundaryBoundingBoxes[i];

                        if (TestAABBOverlap(colliderTest1, colliderTest2))
                        {
                            if (colliderTest1.tag == "Player")
                            {
                                entityBoundingBoxes.Remove(colliderTest1);
                                rigidBodiesInScene.Remove(colliderTest1.GetComponent <CustomRigidbody>());
                                Destroy(colliderTest1.gameObject);
                                isPlayerActive = false;
                            }
                            if (colliderTest1.tag == "Entity")
                            {
                                entityBoundingBoxes.Remove(colliderTest1);
                                rigidBodiesInScene.Remove(colliderTest1.GetComponent <CustomRigidbody>());
                                Destroy(colliderTest1.gameObject);
                                isEnemyActive = false;
                            }
                        }
                    }
                }


                accum -= deltaTime;
            }
        }