Exemple #1
0
    public void DoMove(MoleEnemyController c, GameObject o)
    {
        // Is in range, so he fight!
        if (c.IsAtMeleeRange() == true)
        {
            // Chance that he flee the fight to charge again!
            if (RandomHelper.tossRandom(c.chanceChargeInMelee * Time.deltaTime))
            {
                //Debug.Log("[MELEE] Flee melee to charge again!!!! Yeeaaaah!");
                c.SetState(MoleStateFactory.creaChargePlayer());
            }
        }

        // Try to stay on range, if not, go on range
        // There is a little chance he try to charge again instead of following
        else if (c.IsAtMeleeRange() == false)
        {
            if (RandomHelper.tossRandom(c.changeChargeOnPlayerFlee * Time.deltaTime))
            {
                //Debug.Log("[MELEE] Player Flee and enemy try to charge again!!");
                c.SetState(MoleStateFactory.creaChargePlayer());
            }
            else
            {
                //Debug.Log("[MELEE] Try to fight but enemy to far away");
                EnemyMovements.MoveTowardPlayer(c, o, c.meleeWalkSpeed);
            }
        }
    }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        //De arriba hacia abajo
        if (enemySpawnPosS == "up")
        {
            EnemyMovements.moveUpToDown(gameObject, enemySpeed);
            //movement(randomType);
        }

        //Derecha a izquierda
        if (enemySpawnPosS == "right")
        {
            EnemyMovements.moveRightToLeft(gameObject, enemySpeed);
            //movement(randomType);
        }
        //Izquierda a Derecha.
        if (enemySpawnPosS == "left")
        {
            EnemyMovements.moveLeftToRight(gameObject, enemySpeed);
            //movement(randomType);
        }

        //De abajo hacia arriba
        if (enemySpawnPosS == "down")
        {
            EnemyMovements.moveDownToUp(gameObject, enemySpeed);
            //movement(randomType);
        }

        //Una vez dentro de la pantalla activar
        if (inField)
        {
            StartCoroutine(checkResult());
        }
    }
Exemple #3
0
    public void DoMove(MoleEnemyController c, GameObject o)
    {
        // If is already chargin, continue
        if (c.isCharging)
        {
            EnemyMovements.MoveTowardPlayer(c, o, c.chargeSpeed);
        }

        // If is a charge range, chaaaarge!!
        if (c.IsAtChargeRange() == 0)
        {
            c.isCharging = true;
            //Debug.Log("[CHARGE]: Start charging!!!! (On chargerange = " + c.IsAtChargeRange() + ")");
            EnemyMovements.MoveTowardPlayer(c, o, c.chargeSpeed);
        }

        // If is to far, move toward player
        if (c.IsAtChargeRange() == -1)
        {
            //Debug.Log("[CHARGE]: To far... (On chargerange = " + c.IsAtChargeRange() + ")");
            EnemyMovements.MoveTowardPlayer(c, o, c.walkspeed);
        }

        // If is to close, try to go away (And is not already charging)
        if (c.IsAtChargeRange() == -2)
        {
            //Debug.Log("[CHARGE]: To close... (On chargerange = " + c.IsAtChargeRange() + ")");
            EnemyMovements.MoveTowardPlayer(c, o, -(c.chargeFleeSpeed));
        }
    }
Exemple #4
0
    public void DoMove(MoleEnemyController c, GameObject o)
    {
        // Look for player, can see only at specific distance
        // If player is not in vision, do nothing (Yeah, that's kind of stupid behavior, but time is running low)
        float distance = Mathf.Abs(o.transform.position.x - c.gameObject.transform.position.x);

        if (distance > c.seePlayerDistance)
        {
            return; // Do nothing XD (He's so stupid)
        }

        // Move toward player
        EnemyMovements.MoveTowardPlayer(c, o, c.walkspeed);

        if (c.IsAtChargeRange() == 0)
        {
            //If reached chargerange
            c.SetState(MoleStateFactory.creaChargePlayer());
        }
        else if (c.IsAtMeleeRange())
        {
            // If is not at chargerange but at meleerange
            c.SetState(MoleStateFactory.creaMeleeAttack());
        }
    }
    private void Awake()
    {
        enemyAttack    = GetComponent <EnemyAttack>();
        enemyMovements = GetComponent <EnemyMovements>();

        for (int i = 0; i < previousLocations.Length; i++)
        {
            previousLocations[i] = Vector3.zero;
        }

        health = maxHealth;
    }
Exemple #6
0
    private void Awake()
    {
        MyCharacterAnimations = GetComponentInChildren <MyCharacterAnimations>();

        audioSource = GetComponent <AudioSource>();

        if (gameObject.CompareTag(Tags.ENEMY_TAG))
        {
            enemyMovements = GetComponentInParent <EnemyMovements>();
        }
        cameraShake = GameObject.FindWithTag(Tags.MAIN_CAMERA_TAG).GetComponent <CameraShake>();
    }
Exemple #7
0
 // Use this for initialization
 void Start()
 {
     audioSource    = GetComponent <AudioSource>();
     enemyMovements = GetComponentInParent <EnemyMovements>();
     if (GetComponent <WeaponFire>())
     {
         freq     = GetComponent <WeaponFire>().freq;
         waitTime = GetComponent <WeaponFire>().waitTime;
         damage   = GetComponent <WeaponFire>().damage;
     }
     if (transform.parent.parent.tag == "Enemy")
     {
         GetComponent <WeaponFire>().enabled = false;
     }
 }
 private void buildGruntAWave2(EnemyWave newWave, ContentManager _content)
 {
     _creator = new ConcreteGruntACreator();
     for (int j = 0; j < 4; j++)
     {
         EnemyMovements moves = new EnemyMovements();
         for (int i = 0; i < 10; i++)
         {
             moves.addMovement(new MoveDown(3.0));
             moves.addMovement(new MoveUp(3.0));
         }
         Vector2 pos = new Vector2(j * 100, 0);
         Vector2 vel = new Vector2(-1, 1);
         newWave.addEnemy(_creator.CreateEnemy(pos, vel, _content, moves));
     }
 }
Exemple #9
0
    void movement(int randomType)
    {
        switch (randomType)
        {
        //Mover con funcio seno
        case 0:
            EnemyMovements.moveSin(gameObject, randomDis, randomDisType, enemySpawnPos.x, invert);
            break;

        case 1:
            EnemyMovements.moveX2(gameObject, randomDis, randomDisType, enemySpawnPos.x, invert);
            break;

        case 2:
            EnemyMovements.moveX3(gameObject, randomDis, randomDisType, enemySpawnPos.x, invert);
            break;

        //Mover en diagonal
        default:
            if (enemySpawnPosS == "right" || enemySpawnPosS == "left")
            {
                if (enemySpawnPos.y > 2.0f)
                {
                    EnemyMovements.moveUpToDown(gameObject, enemySpeed);
                }
                if (enemySpawnPos.y < -2.0f)
                {
                    EnemyMovements.moveDownToUp(gameObject, enemySpeed);
                }
            }
            if (enemySpawnPosS == "up" || enemySpawnPosS == "down")
            {
                if (enemySpawnPos.x > 2.0f)
                {
                    EnemyMovements.moveRightToLeft(gameObject, enemySpeed);
                }
                if (enemySpawnPos.x < -2.0f)
                {
                    EnemyMovements.moveLeftToRight(gameObject, enemySpeed);
                }
            }
            break;
        }
    }
        private void buildGruntBWave1(EnemyWave newWave, ContentManager _content)
        {
            _creator = new ConcreteGruntBCreator();
            int height = 50;

            for (int j = 1; j < 5; j++)
            {
                EnemyMovements moves = new EnemyMovements();
                for (int i = 0; i < 10; i++)
                {
                    moves.addMovement(new MoveLeft(6.0));
                    moves.addMovement(new MoveRight(6.0));
                }
                Vector2 pos = new Vector2(800 - (j * 100), height);
                Vector2 vel = new Vector2(-1, 1);
                newWave.addEnemy(_creator.CreateEnemy(pos, vel, _content, moves));
                height += 100;
            }
        }
        private void buildGruntBWave2(EnemyWave newWave, ContentManager _content)
        {
            _creator = new ConcreteGruntBCreator();
            int width = 350;

            for (int j = 1; j < 5; j++)
            {
                EnemyMovements moves = new EnemyMovements();
                for (int i = 0; i < 10; i++)
                {
                    moves.addMovement(new MoveUp(3.0));
                    moves.addMovement(new MoveDown(3.0));
                }
                Vector2 pos = new Vector2(width, 300);
                Vector2 vel = new Vector2(-1, 1);
                newWave.addEnemy(_creator.CreateEnemy(pos, vel, _content, moves));
                width += 100;
            }
        }
        private void buildWaveFromFile(EnemyWave newWave, String filename, ContentManager _content)
        {
            waveObj JSON = JsonConvert.DeserializeObject <waveObj>(File.ReadAllText(dirpath + filename));

            //'C:\Users\elifo\Desktop\MyStuff\School Projects\487sp19_bulletgame\content\BulletGame\wave5.json'.'
            for (int enemyIdx = 0; enemyIdx < JSON.enemies.Count; enemyIdx++)
            {
                if (JSON.enemies[enemyIdx].type == "GruntA")
                {
                    _creator = new ConcreteGruntACreator();
                }
                else if (JSON.enemies[enemyIdx].type == "GruntB")
                {
                    _creator = new ConcreteGruntBCreator();
                }
                else if (JSON.enemies[enemyIdx].type == "MidBoss")
                {
                    _creator = new ConcreteMidBossCreator();
                }
                else if (JSON.enemies[enemyIdx].type == "FinalBoss")
                {
                    _creator = new ConcreteFinalBossCreator();
                }
                EnemyMovements  moves           = new EnemyMovements();
                MovementFactory movementFactory = new MovementFactory();
                for (int rep = 0; rep < JSON.enemies[enemyIdx].movementRepetitions; rep++)
                {
                    for (int moveIdx = 0; moveIdx < JSON.enemies[enemyIdx].movements.Count; moveIdx++)
                    {
                        moves.addMovement(movementFactory.makeMovement(JSON.enemies[enemyIdx].movements[moveIdx].type, JSON.enemies[enemyIdx].movements[moveIdx].duration));
                    }
                }

                Vector2 pos = new Vector2(JSON.enemies[enemyIdx].startPos[0], JSON.enemies[enemyIdx].startPos[1]);
                Vector2 vel = new Vector2(JSON.enemies[enemyIdx].startVel[0], JSON.enemies[enemyIdx].startVel[1]);
                newWave.addEnemy(_creator.CreateEnemy(pos, vel, _content, moves));
            }
        }
        public GruntB(Vector2 newPosition, Vector2 newVelocity, ContentManager gameContent, EnemyMovements newMoves)
        {
            texture  = gameContent.Load <Texture2D>("invader2");
            position = newPosition;

            movementTime  = 0f;
            this.velocity = newVelocity;
            this.moves    = newMoves;

            bullets = new List <Bullets>();
            factory = new BulletFactory(gameContent);
            lives   = 1;
            width   = 32;
            height  = 16;
        }
 public abstract Enemy CreateEnemy(Vector2 pos, Vector2 vel, ContentManager _content, EnemyMovements move);
 public override Enemy CreateEnemy(Vector2 pos, Vector2 vel, ContentManager _content, EnemyMovements moves)
 {
     return(new GruntB(pos, vel, _content, moves));
 }
 public override Enemy CreateEnemy(Vector2 pos, Vector2 vel, ContentManager _content, EnemyMovements moves)
 {
     return(new FinalBoss(pos, _content));
 }
Exemple #17
0
 public void DoMove(MoleEnemyController c, GameObject o)
 {
     // negative value because flee the player
     EnemyMovements.MoveTowardPlayer(c, o, -(c.runAwaySpeed));
 }