Exemplo n.º 1
0
 public void GetStuck(float speed)
 {
     Debug.LogFormat("Get stuck {0}", speed);
     Velocity = Vector2.zero;
     State    = WormState.Stuck;
     SetSpriteStuck();
 }
Exemplo n.º 2
0
 private void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.transform.tag == "Player")
     {
         base.attackPlayer(collision.gameObject.GetComponent <Player>());
         foreach (ContactPoint2D hit in collision.contacts)
         {
             if (hit.collider.GetComponent <Player>() != null)
             {
                 Debug.Log("BACKKK!");
                 if (hit.point.x > transform.position.x)
                 {
                     //rb.velocity = new Vector2(0, 0);
                     wormState = WormState.Confused;
                     rb.AddForce(new Vector2(-jumpBack, jumpForce), ForceMode2D.Impulse);
                 }
                 else
                 {
                     // rb.velocity = new Vector2(0, 0);
                     wormState = WormState.Confused;
                     rb.AddForce(new Vector2(jumpBack, jumpForce), ForceMode2D.Impulse);
                     //rb.velocity = new Vector2(rb.velocity.x + jumpBack, rb.velocity.y + jumpForce);
                 }
                 break;
             }
         }
     }
 }
Exemplo n.º 3
0
 // Update is called once per frame
 void Update()
 {
     if (stats.stunAfterAttackTimer > 0)
     {
         wormState = WormState.Confused;
         stats.stunAfterAttackTimer -= Time.deltaTime;
     }
     enemi_ai();
 }
Exemplo n.º 4
0
    public void _on_DamageArea_body_entered(Node body)
    {
        _state = WormState.Attacking;

        if (body.Name == "Player")
        {
            float[] timeArg = { Damage };
            body.PropagateCall(nameof(Light.RemoveTimeFromTimer), new Array(timeArg));
        }
    }
Exemplo n.º 5
0
        public void Shoot(float power)
        {
            //Debug.Log("Shoot");
            State = WormState.Busy;
            Vector2 spawnPos = GetSpawnPosition(CurrentWeapon.GetWidth(), CurrentWeapon.GetHeight(), Angle, 1.0f);
            //Debug.LogFormat("Spawn position to position : {0} / {1}", spawnPos, Position);
            RectObject proj = GameManager.GM.SpawnObject(CurrentWeapon.Projectile, spawnPos);

            proj.AddForce(GetAim() * power);
            //CurrentWeapon = null;
            SetSpriteShooting(Angle);
        }
Exemplo n.º 6
0
 public void PrepareFinished()
 {
     if (Random.Range(0, 2) == 0)
     {
         currentState = WormState.SlowPush;
     }
     else
     {
         currentState = WormState.FastPush;
     }
     Debug.Log("JUMP/from function");
     animator.SetTrigger("Jump");
 }
Exemplo n.º 7
0
 public void SetFalling()
 {
     if (State == WormState.Hurt)
     {
         return;
     }
     ReboundThreshold = 0;
     if (Velocity != Vector2.zero)
     {
         SetSpriteFalling();
         State = WormState.Hurt;
     }
 }
Exemplo n.º 8
0
    // Use this for initialization
    void Awake()
    {
        rb               = GetComponent <Rigidbody2D>();
        sr               = GetComponent <SpriteRenderer>();
        ani              = GetComponent <Animator>();
        gameController   = GameObject.Find("Game").GetComponent <GameController>();
        wormState        = WormState.Idle;
        wormNametxt.text = wormName;
        knockTimer       = knockbackTimer;

        uiHealth.transform.GetChild(0).GetComponent <Text>().text     = wormName;
        uiHealth.transform.GetChild(1).GetComponent <Text>().text     = wormName;
        uiHealth.transform.GetChild(3).GetComponent <Image>().enabled = false;
    }
Exemplo n.º 9
0
    void stateKnockback()
    {
        crosshair.GetComponent <SpriteRenderer>().enabled = false;

        knockTimer -= Time.deltaTime;

        if (knockTimer <= 0)
        {
            wormState  = WormState.Idle;
            knockTimer = knockbackTimer;
        }

        velocity = new Vector2(rb.velocity.x, rb.velocity.y);
    }
Exemplo n.º 10
0
        protected override void OnStop(Vector2 pos)
        {
            //Debug.Log("OnStop");
            ReboundThreshold = reboundThresholdDef;
            Friction         = frictionDef;
            if (State == WormState.Jump)
            {
                State = WormState.Idle;
            }
            if (State != WormState.Stuck)
            {
                SetSpriteIdle();
            }

            //if (State == WormState.Jumping)
            //	State = WormState.Idle;
        }
Exemplo n.º 11
0
    // Called every frame. 'delta' is the elapsed time since the previous frame.
    public override void _PhysicsProcess(float delta)
    {
        if (_state == WormState.Dead)
        {
            return;
        }

        if (_behindCheck.IsColliding())         // If the player is behind the ghost.
        {
            var body = _behindCheck.GetCollider();
            if (body != null)
            {
                var bodyAsNode = (Node2D)body;
                if (bodyAsNode.Name == "Player")
                {
                    _display.Scale = new Vector2(-1, 1);
                    _state         = WormState.Attacking;

                    Speed *= ChangeDirection;

                    _groundCheck.Position *= new Vector2(-1, 1);
                }
            }
        }

        if (IsOnWall() || !_groundCheck.IsColliding())
        {
            Speed *= ChangeDirection;

            _groundCheck.Position *= new Vector2(-1, 1);
        }

        _movement.x = Speed;

        _movement.y = Gravity;

        _movement = MoveAndSlide(_movement, _floor);
    }
Exemplo n.º 12
0
    public void _on_AnimatedSprite_animation_finished()
    {
        if (_movement == Vector2.Zero && IsOnFloor())
        {
            _state = WormState.Walking;
        }

        else if (IsOnFloor())
        {
            _state = WormState.Walking;
        }

        if (_state == WormState.Attacking)
        {
            _state = WormState.Walking;
        }

        if (_state == WormState.Dead || _animationState == WormAnimationState.Death)
        {
            EmitSignal(nameof(WormKilled));

            QueueFree();
        }
    }
Exemplo n.º 13
0
    public override void _Process(float delta)
    {
        // This is garbage, dont do this.
        if (_painDuration > 0)
        {
            _painDuration           -= delta;
            _animations.SelfModulate = Color.Color8(255, 65, 65);
        }
        else
        {
            _animations.SelfModulate = Color.Color8(255, 255, 255);
        }

        if (HitsToDestroy <= 0)
        {
            _state = WormState.Dead;

            GetNodeOrNull <CollisionShape2D>("CollisionShape2D")?.QueueFree();
            GetNodeOrNull <Area2D>("DamageArea")?.QueueFree();
        }

        UpdatePlayerState();
        UpdateAnimation();
    }
Exemplo n.º 14
0
 public void SetJump()
 {
     State = WormState.Jump;
     SetSpriteBeginJump();
 }
Exemplo n.º 15
0
    protected override void Update()
    {
        sprite.sortingOrder = -Mathf.RoundToInt(transform.position.y * 100);

        if (isDead)
        {
            return;
        }

        if (!spottedPlayer)
        {
            if (CanSee(player, vision.GetComponent <CircleCollider2D>().radius) &&
                (room == LevelGeneration.I.GetRoomAtPos(player.transform.position)))
            {
                spottedPlayer = true;
            }
            else
            {
                return;
            }
        }

        if (state == WormState.ATTACKING)
        {
            nextAttackBar.fillAmount = 1 - timeToStateChange;
        }
        else
        {
            nextAttackBG.SetActive(false);
        }

        timeToStateChange -= Time.deltaTime * speed;

        if (timeToStateChange <= 0)                 // if state needs to change
        {
            timeToStateChange = 1;

            switch (state)
            {
            case WormState.BURIED:

                if (room != LevelGeneration.I.GetRoomAtPos(player.transform.position))
                {
                    spottedPlayer = false;
                    return;
                }

                //Emerge();

                break;

            case WormState.EMERGING:

                nextAttackBG.SetActive(true);
                targetPos = player.position;

                break;

            case WormState.ATTACKING:

                FireProjectiles();
                StartSubmerging();

                break;

            case WormState.BURYING:

                //Submerge();
                transform.position = FindEmergePosition();

                UpdateGraph();

                break;
            }

            if (state != WormState.BURYING && room != LevelGeneration.I.GetRoomAtPos(player.transform.position))
            {
                state = WormState.BURYING;
                nextAttackBG.SetActive(false);
            }
            else
            {
                state = (WormState)(((int)state + 1) % NUM_STATES);
            }

            animator.SetInteger("State", (int)state);
        }
    }
Exemplo n.º 16
0
 private void SetState(WormState state)
 {
     this.state = state;
     this.stateTime = 0;
 }
Exemplo n.º 17
0
 private void movement()
 {
     if (currentState == WormState.Stop)
     {
         rb.velocity = Vector2.zero;
         if (_stopTimer > 0)
         {
             _stopTimer -= Time.deltaTime;
         }
         else
         {
             if (lastState == WormState.FastPush)
             {
                 currentState = WormState.SlowPush;
                 lastState    = WormState.SlowPush;
                 Debug.Log("JUMP/from update");
                 animator.SetTrigger("Jump");
                 animPrepareInitiated = false;
             }
             else
             {
                 currentState = WormState.FastPush;
                 lastState    = WormState.FastPush;
                 Debug.Log("JUMP/from update");
                 animator.SetTrigger("Jump");
                 animPrepareInitiated = false;
             }
             _stopTimer = stopTimer;
         }
     }
     else if (currentState == WormState.SlowPush)
     {
         Debug.Log("SLOW" + rb.velocity);
         if (left)
         {
             if (_slowMoveTimer > 0)
             {
                 _slowMoveTimer -= Time.deltaTime;
                 rb.velocity     = Vector2.right * slowPush;
             }
             else
             {
                 currentState   = WormState.Stop;
                 _slowMoveTimer = slowMoveTimer;
             }
         }
         else
         {
             if (_slowMoveTimer > 0)
             {
                 _slowMoveTimer -= Time.deltaTime;
                 rb.velocity     = Vector2.left * slowPush;
             }
             else
             {
                 currentState   = WormState.Stop;
                 _slowMoveTimer = slowMoveTimer;
             }
         }
     }
     else if (currentState == WormState.FastPush)
     {
         Debug.Log("FAST" + rb.velocity);
         if (left)
         {
             if (_fastMoveTimer > 0)
             {
                 _fastMoveTimer -= Time.deltaTime;
                 rb.velocity     = Vector2.right * fastPush;
             }
             else
             {
                 currentState   = WormState.Stop;
                 _fastMoveTimer = fastMovetimer;
             }
         }
         else
         {
             if (_fastMoveTimer > 0)
             {
                 _fastMoveTimer -= Time.deltaTime;
             }
             else
             {
                 currentState   = WormState.Stop;
                 rb.velocity    = Vector2.left * fastPush;
                 _fastMoveTimer = fastMovetimer;
             }
         }
     }
 }
Exemplo n.º 18
0
 public void SetToDie()
 {
     animator.Play("WormExplode");
     State = WormState.Busy;
 }
Exemplo n.º 19
0
    private void enemi_ai()
    {
        RaycastHit2D hitInfo;
        RaycastHit2D groundInfo;

        switch (wormState)
        {
        case WormState.Move:
            animator.SetBool("playerSeen", false);
            groundInfo = Physics2D.Raycast(groundCheck.position, Vector2.down, groundCheckDistance);
            if (groundInfo.collider == null)
            {
                Flip();
            }
            rb.velocity = new Vector2(patrolSpeed, rb.velocity.y);
            hitInfo     = (facingRight) ? Physics2D.Raycast(lineOfSight.position, lineOfSight.right, LOSDistance, ~ignoreEnv) : Physics2D.Raycast(lineOfSight.position, lineOfSight.right * -1, LOSDistance, ~ignoreEnv);
            if (facingRight)
            {
                if (Mathf.Abs(transform.position.x - startPositionX) >= patrolDistance)
                {
                    Flip();
                }
                Debug.DrawLine(lineOfSight.position, new Vector2(lineOfSight.position.x + LOSDistance, lineOfSight.position.y), Color.red);
            }
            else
            {
                if (Mathf.Abs(startPositionX - transform.position.x) >= patrolDistance)
                {
                    Flip();
                }
                Debug.DrawLine(lineOfSight.position, new Vector2(lineOfSight.position.x - LOSDistance, lineOfSight.position.y), Color.red);
            }

            if (hitInfo.collider != null)
            {
                if (hitInfo.collider.gameObject.CompareTag("Player"))
                {
                    playerSeen = true;
                    seenTimer  = seenTimerSet;
                    wormState  = WormState.Attack;
                }
                else
                {
                    if (facingRight && (Mathf.Abs(hitInfo.point.x - lineOfSight.transform.position.x) < 0.5f))
                    {
                        Flip();
                    }
                    else if (!facingRight && (Mathf.Abs(lineOfSight.transform.position.x - hitInfo.point.x) < 0.5f))
                    {
                        Flip();
                    }
                }
            }
            break;

        case WormState.Attack:
            animator.SetBool("playerSeen", true);
            if (!playerSeen)
            {
                seenTimer -= Time.deltaTime;
            }
            groundInfo = Physics2D.Raycast(groundCheck.position, Vector2.down, groundCheckDistance);
            if (groundInfo.collider == null)
            {
                rb.velocity = new Vector2(0, 0);
            }
            else
            {
                rb.velocity = new Vector2(attackSpeed, rb.velocity.y);
                hitInfo     = (facingRight) ? Physics2D.Raycast(lineOfSight.position, lineOfSight.right, LOSDistance, ~ignoreEnv) : Physics2D.Raycast(lineOfSight.position, lineOfSight.right * -1, LOSDistance, ~ignoreEnv);

                if (hitInfo.collider != null)
                {
                    if (!hitInfo.collider.gameObject.CompareTag("Player"))
                    {
                        playerSeen = false;
                    }
                    else
                    {
                        seenTimer = seenTimerSet;
                    }
                }
                else
                {
                    playerSeen = false;
                }
            }

            if (seenTimer < 0)
            {
                wormState = WormState.Move;
                Flip();
            }
            break;

        case WormState.Confused:
            animator.SetBool("playerSeen", false);
            if (confusedTimer < confusedTimerSet)
            {
                confusedTimer += Time.deltaTime;
            }
            else
            {
                wormState     = WormState.Attack;
                confusedTimer = 0f;
            }
            break;
        }
    }
Exemplo n.º 20
0
 public void GotUp()
 {
     State = WormState.Idle;
 }