Ejemplo n.º 1
0
    public override void _Ready()
    {
        GD.Randomize();

        stats = GetNode <Stats>("Stats");
        stats.OnZeroHealth += Death;

        hurtbox = GetNode <Hurtbox>("Hurtbox");
        hurtbox.OnInvincibilityEnded   += BlinkStop;
        hurtbox.OnInvincibilityStarted += BlinkStart;

        playerZone = GetNode <PlayerDetection>("PlayerDetection");
        batSprite  = GetNode <AnimatedSprite>("AnimatedSprite");

        softCollision = GetNode <SoftCollision>("SoftCollision");

        wanderController = GetNode <WanderController>("WanderController");

        rng = new RandomNumberGenerator();

        stateArray = new List <AIState> {
            AIState.IDLE, AIState.WANDER
        };

        state = PickRandomState(stateArray);

        animPlayer = GetNode <AnimationPlayer>("AnimationPlayer");
    }
Ejemplo n.º 2
0
 void Awake()
 {
     stateHandler    = GetComponent <EnemyStateHandler>();
     playerDetection = GetComponent <PlayerDetection>();
     movement        = GetComponent <EnemyMovement>();
     gunHandler      = GetComponent <EnemyGunHandler>();
 }
Ejemplo n.º 3
0
    int HEALTH = 2 + 1;     // idk why he takes damage instantly when spawning

    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        audio           = GetNode <AudioStreamPlayer>("AudioStreamPlayer");
        playerDetection = GetNode <Area2D>("PlayerDetection") as PlayerDetection;
        animationPlayer = GetNode <AnimationPlayer>("AnimationPlayer");
        animationPlayer.Play("PreIdle");
    }
Ejemplo n.º 4
0
    int HEALTH = 1 + 1; // idk why he takes damage instantly when spawning

    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        audio           = GetNode <AudioStreamPlayer>("AudioStreamPlayer");
        audio.VolumeDb  = 2;
        animationPlayer = GetNode <AnimationPlayer>("AnimationPlayer");
        playerDetection = GetNode <Area2D>("PlayerDetection") as PlayerDetection;
    }
Ejemplo n.º 5
0
 private void Awake()
 {
     navMeshAgent                 = GetComponent <NavMeshAgent>();
     playerDetection              = GetComponent <PlayerDetection>();
     playerDetection.OnDetection += PlayerDetection_OnDetection;
     animator = GetComponentInChildren <Animator>();
 }
Ejemplo n.º 6
0
    void OnSceneGUI()
    {
        PlayerDetection fov = (PlayerDetection)target;

        Handles.color = Color.red;
        Handles.DrawWireArc(fov.transform.position, Vector3.up, Vector3.forward, 360, fov.attackRadius);
        Handles.color = Color.yellow;
        Handles.DrawWireArc(fov.transform.position, Vector3.up, Vector3.forward, 360, fov.viewRadius);
        Handles.color = new Color(0, 1, 1, .2f);
        Vector3 viewAngleA = fov.DirectionFromAngle(-fov.viewAngle / 2, false);
        Vector3 viewAngleB = fov.DirectionFromAngle(fov.viewAngle / 2, false);

        Handles.DrawLine(fov.transform.position, fov.transform.position + viewAngleA * fov.viewRadius);
        Handles.DrawLine(fov.transform.position, fov.transform.position + viewAngleB * fov.viewRadius);
        Handles.DrawSolidArc(fov.transform.position, fov.transform.up, viewAngleA, fov.viewAngle, fov.viewRadius);

        foreach (Transform visibleTarget in fov.visibleTargets)
        {
            if (Vector3.Distance(fov.transform.position, visibleTarget.position) < fov.attackRadius)
            {
                Handles.color = Color.red;
            }
            else
            {
                Handles.color = Color.yellow;
            }

            Handles.DrawLine(fov.transform.position, visibleTarget.position);
        }
    }
Ejemplo n.º 7
0
 public void Initialize()
 {
     ThisPlayer   = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerControl>();
     ThisAnimator = this.gameObject.GetComponent <Animator>();
     ThisDetector = this.GetComponentInChildren <PlayerDetection>();
     ThisEnemy    = new EmptyEnemy();
 }
Ejemplo n.º 8
0
    /// <summary>
    /// On collision with the enemy then check object tag and match with enemy.
    /// </summary>
    /// <param name="collision"> Default collision component.
    /// </param>
    private void OnCollisionEnter(Collision collision)
    {
        // if an enemy is collided.
        if (collision.gameObject.CompareTag("Enemy"))
        {
            // asssign the collided object to the current object.
            cObject = collision.gameObject;
            // detect the player from the enemies side.
            PD = cObject.GetComponentInParent <PlayerDetection>();
            // reduce health.
            health.takeDamage(PD.damage);
            // Destroy the script component.
            PD.isDestroyed();
            PD      = null;
            cObject = null;
        }

        // if collision is with an enemy projectile then take damage.
        if (collision.gameObject.CompareTag("Projectile"))
        {
            cObject = collision.gameObject;
            PJB     = cObject.GetComponentInParent <ProjectileBehaviour>();
            health.takeDamage(PJB.damage);
            PJB.IsDestroyed();
            PJB     = null;
            cObject = null;
        }
    }
Ejemplo n.º 9
0
 void Start()
 {
     playerObj       = GameObject.FindGameObjectWithTag("Player"); // Find the player object
     src             = GetComponent <AudioSource>();               // Get audio source
     detectionScript = detectionZone.GetComponent <PlayerDetection>();
     detectionZone.transform.parent = null;                        // Make sure detection zone doesn't move with parent
 }
Ejemplo n.º 10
0
 public void Stunned(float stunTime)
 {
     StartCoroutine(StunnedZombieTimer(stunTime));
     destinationSetter         = gameObject.GetComponentInParent <AIDestinationSetter>();
     destinationSetter.enabled = false;
     playerDetection           = gameObject.GetComponentInParent <PlayerDetection>();
     playerDetection.enabled   = false;
 }
Ejemplo n.º 11
0
 void Awake()
 {
     _detector    = transform.GetChild(0).GetComponent <PlayerDetection>();
     _postSearch  = GetComponentInChildren <FindPlayer>();
     _patrolBehav = GetComponent <Patrol>();
     _spriteHand  = GetComponent <Spritehandler>();
     _coneRender  = transform.GetChild(0).GetComponent <VisionConeRender>();
 }
Ejemplo n.º 12
0
        private void Start()
        {
            //set components
            navigator = GetComponent <NavMeshAgent>();
            if (GetComponent <DetectionMeter>())
            {
                detection = GetComponent <DetectionMeter>();
            }

            if (pathParent && pathParent.GetComponent <PathController>())
            {
                pathController = pathParent.GetComponent <PathController>();
            }

            //set search pos
            lastKnownPlayerPosition = Vector3.zero;
            SearchPosition          = Vector3.zero;

            //set FOV
            CurrentFOV = patrolFOV;

            //set current point to first point
            if (pathController && pathController.listPoints.Count > 0)
            {
                currentPathPoint = pathController.listPoints[0];
            }
            currentListIndex = 0;

            //find the player
            if (player == null)
            {
                player = GameObject.FindGameObjectWithTag("Player");
                if (player == null)
                {
                    player = GameObject.FindGameObjectWithTag("Player");
                    if (player.transform.root.gameObject.tag == "Player")
                    {
                        player = player.transform.root.gameObject;
                    }
                }
            }

            //check if player has detection component
            if (player.GetComponent <PlayerDetection>())
            {
                playerDetection  = player.GetComponent <PlayerDetection>();
                playerComponents = playerDetection.components;
            }

            if (headTransform == null)
            {
                headTransform = transform;
            }

            //set state
            currentState = StealthState.PATROL;
            EnterPatrol();
        }
Ejemplo n.º 13
0
 void Awake()
 {
     playerDetection = GetComponentInChildren <PlayerDetection>();
     if (playerDetection)
     {
         playerDetection.onEnemyEnter += OnEnemyEnter;
         playerDetection.onEnemyLeave += OnEnemyLeave;
     }
 }
 // Use this for initialization
 void Start()
 {
     //Getting components of the drone
     anim          = GetComponent <Animator>();
     playerDetect  = GetComponent <PlayerDetection>();
     droneMovement = GetComponent <DroneMovementManagement>();
     rb            = GetComponent <Rigidbody>();
     Pillars       = GameObject.FindGameObjectWithTag(name + "Pillars");
 }
 protected void AssignComponents()
 {
     _pathFinding    = GetComponentInParent <Pathfinding>();
     _patrolBehav    = GetComponentInParent <Patrol>();
     _soundHandler   = GetComponentInParent <GuardSoundHandler>();
     _spriteHandler  = GetComponentInParent <Spritehandler>();
     _playerDetector = GetComponent <PlayerDetection>();
     _visionCone     = GetComponent <LineRenderer>();
     _detection      = GetComponent <DetectionCommon>();
 }
Ejemplo n.º 16
0
    int HEALTH = 3 + 1; // idk why he takes damage instantly when spawning

    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        audio                = GetNode <AudioStreamPlayer>("AudioStreamPlayer");
        audio.VolumeDb       = 3;
        animationPlayer      = GetNode <AnimationPlayer>("AnimationPlayer");
        animationTree        = GetNode <AnimationTree>("AnimationTree");
        animationTree.Active = true;
        animationState       = animationTree.Get("parameters/playback") as AnimationNodeStateMachinePlayback;
        playerDetection      = GetNode <Area2D>("PlayerDetection") as PlayerDetection;
    }
    private void OnTriggerStay2D(Collider2D other)
    {
        PlayerDetection playerDetection = other.GetComponent <PlayerDetection>();

        if (playerDetection != null)
        {
            diamondEnemy.playerSpotted   = true;
            diamondEnemy.playerTransform = other.transform;
        }
    }
Ejemplo n.º 18
0
    void Start()
    {
        enemy             = GetComponent <Rigidbody>();
        originalPosition  = transform.position;
        leftPos           = new Vector3(originalPosition.x - leftBoundry, originalPosition.y, 0f);
        rightPos          = new Vector3(originalPosition.x + rightBoundry, originalPosition.y, 0f);
        enemy.isKinematic = false;

        Player       = GameObject.Find("Yumi").transform;
        detectPlayer = this.GetComponentInChildren <PlayerDetection>();
    }
Ejemplo n.º 19
0
    //public float time = 0f;
    //public bool canMoveSideways = true;

    void Awake()
    {
        rb              = this.GetComponent <Rigidbody> ();
        anim            = this.GetComponent <Animator> ();
        Physics.gravity = new Vector3(0, -20, 0);
        canMove         = true;
        thisName        = this.gameObject.name;
        pd              = this.GetComponent <PlayerDetection> ();
        dam             = this.GetComponent <DamageSetGet> ();
        ma              = this.GetComponent <MachineAverage> ();
    }
Ejemplo n.º 20
0
    public bool GetCaughtByCops()
    {
        if (!GameManager.Instance().IsTargetAlive())
        {
            PlayerDetection playerDetection = player.GetComponent <PlayerDetection>();
            if (playerDetection.CopsWatchingYou())
            {
                GameManager.Instance().CinematicPlayerDie();
            }
        }

        return(false);
    }
Ejemplo n.º 21
0
    void Start()
    {
        enemy             = GetComponent <Rigidbody>();
        enemy.isKinematic = false;

        Player       = GameObject.Find("Yumi").transform;
        detectPlayer = this.GetComponentInChildren <PlayerDetection>();

        originalPosition = transform.position;

        animator        = this.GetComponentInChildren <Animator>();
        sprite_renderer = this.GetComponentInChildren <SpriteRenderer>();
    }
Ejemplo n.º 22
0
    void OnSceneGUI()
    {
        PlayerDetection fow = (PlayerDetection)target;

        Handles.color = Color.white;
        Handles.DrawWireArc(fow.transform.position, Vector3.up, Vector3.forward, 360, fow.viewRadius);
        Vector3 viewAngleA = fow.DirFromAngle(-fow.viewAngle / 2, false);
        Vector3 viewAngleB = fow.DirFromAngle(fow.viewAngle / 2, false);

        Handles.DrawLine(fow.transform.position, fow.transform.position + viewAngleA * fow.viewRadius);
        Handles.DrawLine(fow.transform.position, fow.transform.position + viewAngleB * fow.viewRadius);

        Handles.color = Color.red;
    }
Ejemplo n.º 23
0
 private void Awake()
 {
     GameCamera                   = Camera.main;
     playerDetection              = GetComponent <PlayerDetection>();
     audioManager                 = GameObject.FindGameObjectWithTag("AudioManager").GetComponent <AudioManager>();
     playerDetection.OnDetection += PlayerDetection_OnDetection;
     enemyMaxHealth               = 5;
     health        = 5;
     minHealth     = 0;
     maxHealth     = 1;
     animator      = GetComponentInChildren <Animator>();
     em            = GetComponent <EnemyMovement>();
     stopAttacking = false;
 }
Ejemplo n.º 24
0
    // Start is called before the first frame update
    void Start()
    {
        playerObj        = GameObject.FindGameObjectWithTag("Player");
        playerDetection  = detectors.GetComponent <PlayerDetection>();
        playerController = playerObj.GetComponent <PlayerController>();

        Transform[] patrolChildren = patrolWaypointParent.GetComponentsInChildren <Transform>();
        patrolWaypoints = new Vector3[patrolChildren.Length];

        for (int i = 0; i < patrolWaypoints.Length; i++)
        {
            patrolWaypoints[i] = patrolChildren[i].position;
        }
        Destroy(patrolWaypointParent);
    }
Ejemplo n.º 25
0
 // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
 override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     if (enemyTrash == null)
     {
         enemyTrash = animator.transform.gameObject.GetComponent <EnemyTrash>();
     }
     if (playerDetection == null)
     {
         playerDetection = animator.transform.gameObject.GetComponentInChildren <PlayerDetection>();
         artilleryRadius = playerDetection.artillery.GetComponent <CapsuleCollider>().radius;
     }
     animator.ResetTrigger("attackArtillery");
     enemyTrash.ChangeAttack("Attack");
     enemyTrash.nav.Stop();
 }
Ejemplo n.º 26
0
    // Use this for initialization
    void Awake()
    {
        rb = GetComponent <Rigidbody>();
        sprite_renderer = GetComponentInChildren <SpriteRenderer>();
        startPos        = transform.position;
        tempPosition    = transform.position;

        pos1 = new Vector3(transform.position.x - leftBoundry, transform.position.y, 0f);
        pos2 = new Vector3(transform.position.x + rightBoundry, transform.position.y, 0f);

        Player       = GameObject.Find("Yumi").transform;
        detectPlayer = this.GetComponentInChildren <PlayerDetection>();

        frames        = 0;
        savedPosition = Vector3.zero;
    }
Ejemplo n.º 27
0
    private void Awake()
    {
        idleState    = new IdleState(this);
        patrolState  = new PatrolSate(this);
        chaseState   = new ChaseState(this);
        attackState  = new AttackState(this);
        waitState    = new WaitState(this);
        searchState  = new SearchState(this);
        alertState   = new AlertState(this);
        protectState = new ProtectState(this);
        stunnedState = new StunnedState(this);

        //For color testing
        auxMesh = GetComponent <MeshRenderer>();
        //
        playerDetection = GetComponent <PlayerDetection>();
        attackRange     = playerDetection.attackRadius;
    }
Ejemplo n.º 28
0
 /// <summary>
 /// Function that triggers when the player is continuing to collide with an enemy or a projectile
 /// </summary>
 /// <param name="collision">  Default collision component.
 /// </param>
 private void OnCollisionStay(Collision collision)
 {
     if (collision.gameObject.CompareTag("Enemy"))
     {
         cObject = collision.gameObject;
         PD      = cObject.GetComponentInParent <PlayerDetection>();
         health.takeDamage(PD.damage);
         Debug.Log("Collided with enemy, damage dealt is :" + cObject.name);
         PD.isDestroyed();
     }
     if (collision.gameObject.CompareTag("Projectile"))
     {
         cObject = collision.gameObject;
         PJB     = cObject.GetComponentInParent <ProjectileBehaviour>();
         health.takeDamage(PJB.damage);
         PJB.IsDestroyed();
         PJB     = null;
         cObject = null;
     }
 }
Ejemplo n.º 29
0
    // Use this for initialization
    void Start()
    {
        playerDetection = GetComponentInChildren<PlayerDetection>();

        destinationList = new Vector3[destinationNodes.Length];
        for (int i = 0; i < destinationList.Length; i++) {
            destinationList[i] = destinationNodes[i].transform.position;
        }

        transform.position = destinationList[getClosestPoint()];

        //Debug.log (gameObject.transform.position + " " + destinationList [getClosestPoint ()]);
        //Debug.log(Vector3.Distance (gameObject.transform.position, destinationList [currentDestination]));

        fromPosition = transform.position;

        atVector = true;
        playerPosition = Vector3.zero;
        forwards = true;
        currentDestination = 0;
        waitTimer = 0.0f;

        gameObject.transform.LookAt (destinationList[currentDestination]);
    }
Ejemplo n.º 30
0
 // Use this for initialization
 void Start()
 {
     //currentLevel = gameManager.getCurrentLevel ();
     audioSource = gameObject.AddComponent<AudioSource> ();
     audioSource.clip = noise;
     if (characterType != -1 || characterType != 0) {
         playerDetection = GetComponentInChildren<PlayerDetection>();
     }
 }
Ejemplo n.º 31
0
    public bool IsSomeoneWatching()
    {
        PlayerDetection playerDetection = player.GetComponent <PlayerDetection>();

        return(playerDetection.IsPlayerVisible());
    }
Ejemplo n.º 32
0
    public virtual void Start()
    {
        stats = GetComponent<EnemyStats>();
        patrolSpeed = stats.patrolSpeed;
        chaseSpeed = stats.chaseSpeed;
        chaseTime = stats.chaseTime;
        jumpHeight = stats.jumpHeight;
        pivotTime = stats.pivotTime;
        maxEnragedTimer = stats.maxEnragedTimer;
        maxRageTimer = stats.maxRageTimer;

        controller = GetComponent<Controller2D>();
        enemyAnimationController = GetComponent<Animator>();
        enemyCollider = GetComponent<BoxCollider2D>();
        playerDetection = transform.GetChild(0).GetComponent<PlayerDetection>();
        jumpPoints = transform.GetChild(1).gameObject;
        freeFallPoints = transform.GetChild(2).gameObject;
        player = FindObjectOfType<Player>().gameObject;

        CalculatePhysics();

        input = new Vector2(0, 0);

        airborne = false;
        isAttacking = false;
        changingDirection = false;
        patrolPathCreated = false;
        investigating = false;
        beingAttacked = false;

        enraged = false;
        buildingRage = false;
        losingRage = false;

        engagementCounter = chaseTime + pivotTime;

        eyePositionModifierX = (enemyCollider.size.x / 2) * .5f;
        eyePositionModifierY = (enemyCollider.size.y / 2) * .0f;

        jumpPoints = transform.GetChild(1).gameObject;

        CreatePatrolPath();
        state = EnemyState.Patroling;

        jumpPoint1 = jumpPoints.transform.GetChild(0).GetComponent<BoxCollider2D>();
        jumpPoint2 = jumpPoints.transform.GetChild(1).GetComponent<BoxCollider2D>();
        jumpPoint3 = jumpPoints.transform.GetChild(2).GetComponent<BoxCollider2D>();
        jumpPoint4 = jumpPoints.transform.GetChild(3).GetComponent<BoxCollider2D>();

        fallPoint1 = freeFallPoints.transform.GetChild(0).GetComponent<BoxCollider2D>();
        fallPoint2 = freeFallPoints.transform.GetChild(1).GetComponent<BoxCollider2D>();
        fallPoint3 = freeFallPoints.transform.GetChild(2).GetComponent<BoxCollider2D>();

        CalculateJumpCollders();
    }
Ejemplo n.º 33
0
    void Awake()
    {
        currentHealth = startingHealth;
        attackTimer = 0f;
        poiTimer = 0f;
        turnTimer = 0f;
        destinationReached = false;
        alerted = false;
        playerInRange = false;
        damageTaken = false;
        direction = FacingDirection.Front;

        player = GameObject.FindWithTag("Player");
        playerScript = player.GetComponent<Player>();
        detection = player.GetComponentInChildren<PlayerDetection>();
        enemyRigidbody = GetComponent<Rigidbody2D>();
        if (ranged)
            attackScript = GetComponentInChildren<EnemyShooting>();
        else
            attackScript = GetComponentInChildren<EnemyMelee>();
        attackRangeCollider = attackScript.gameObject.GetComponent<CircleCollider2D>();
        attackRangeCollider.radius = attackScript.GetRange();
        anim = GetComponent<Animator>();
        points = new List<PointOfInterest>();
    }
Ejemplo n.º 34
0
 /*
  * Sets up script dependencies
  */
 void Awake()
 {
     _playerDetection = gameObject.GetComponentInChildren <PlayerDetection>();
     _pathfinding     = gameObject.GetComponent <Pathfinding>();
     map = GameObject.FindGameObjectWithTag("Map").GetComponent <NodeGenerator>().ReturnGeneratedGraph();
 }