Exemplo n.º 1
0
 public void BecomeCautious()
 {
     if (CurrentState == ALERTED)
     {
         CurrentState = CAUTIOUS;
     }
 }
Exemplo n.º 2
0
        public Bear(Bear b)
            : base(b.PosX, b.PosY, b.width, b.height, b.objectTexture, b.MaxHealth, b.MaxSpeed)
        {
            whenToMoveCounter = b.whenToMoveCounter;
            whenToMoveMax     = b.whenToMoveMax;
            whenToMoveMin     = b.whenToMoveMin;
            whenToMoveLimiter = b.whenToMoveLimiter;

            timeOfMovementCounter = b.timeOfMovementCounter;
            timeOfMovementLimiter = b.timeOfMovementLimiter;
            timeOfMovementMax     = b.timeOfMovementMax;
            timeOfMovementMin     = b.timeOfMovementMin;

            scoreValue = b.scoreValue;

            visionStandard = b.visionStandard;
            bearVision     = new Rectangle(b.PosX - visionStandard, b.PosY - visionStandard, b.width + (visionStandard * 2), b.height + (visionStandard * 2));

            fieldOfAttackStandard = b.fieldOfAttackStandard;
            fieldOfAttack         = new Rectangle(b.PosX - fieldOfAttackStandard, b.PosY - fieldOfAttackStandard,
                                                  width + (fieldOfAttackStandard * 2), height + (fieldOfAttackStandard * 2));

            bearState     = b.bearState;        // Enum that checks the state of the bear [Looking / Following / Dead]
            bearDirection = b.bearDirection;    // Enum that checks the direction of the bear
            wasAttacked   = b.wasAttacked;
        }
Exemplo n.º 3
0
    public void Awake()
    {
        //_animator = GetComponent<Animator>();

        CurrentState  = PATROLING;
        IsFacingRight = transform.localScale.z > 0;
    }
Exemplo n.º 4
0
        private void Start()
        {
            m_Anim = this.gameObject.GetComponent<Animator>();

            m_Anim.Play("Anim_Bear_Throw");

            m_State = BearState.Throw;
        }
Exemplo n.º 5
0
    protected IEnumerator CautiousCo()
    {
        yield return(new WaitForSeconds(3.0f));

        if (CurrentState != ALERTED)
        {
            CurrentState = PATROLING;
        }
    }
Exemplo n.º 6
0
        } // Position

        private void Jump(GameTime gameTime)
        {
            jumpLapsed += (float)gameTime.ElapsedGameTime.TotalSeconds;

            velocity.Y = JUMP_VELOCITY + (GRAVITY * jumpLapsed);

            timer = 0f;

            // this snipped handles if the bear was initially walking, if so play jump animation. otherwise rolling animation is fine.
            if (bearState == BearState.Walking)
            {
                bearState = BearState.Jumping;
            }

            if (bearState == BearState.Jumping)
            {
                if (jumpLapsed < 1.0f && !walkjumppass)
                {
                    jumpingAnime.currFrame = 0;
                    velocity.X             = 0f;
                    velocity.Y             = 0f;
                    timer = 0f;
                }
                else
                {
                    if (!walkjumppass)
                    {
                        jumpLapsed   = 0f;
                        walkjumppass = true;
                    }
                    velocity.X              = -WALK_SPEED * 2.0f;
                    jumpingAnime.currFrame  = 1;
                    jumpingAnime.SourceRect = new Rectangle(jumpingAnime.SourceRect.Width, 0, jumpingAnime.SourceRect.Width, jumpingAnime.SourceRect.Height);
                }
            }
            // walkingState jump

            if (position.Y > SCREEN_HEIGHT - 148)
            {
                if (bearState == BearState.Jumping)
                {
                    bearState = BearState.Walking;
                    jumpingAnime.SourceRect = new Rectangle(0, 0, jumpingAnime.SourceRect.Width, jumpingAnime.SourceRect.Height);
                    jumpingAnime.currFrame  = 0;
                }

                walkjumppass = false;
                position.Y   = SCREEN_HEIGHT - 148;
                velocity.Y   = 0;
                isJumping    = false;
                jumpLapsed   = 0f;
                timer        = 0f;
            }
        } // Jump
Exemplo n.º 7
0
    // Update is called once per frame
    void Update()
    {
        switch (bearState)
        {
        case BearState.Tracking:
            float z = player.transform.position.z - transform.position.z > 0 ? moveSpeed : -moveSpeed;
            transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z + z);
            timer -= Time.deltaTime;
            if (timer <= 0)
            {
                bearState = BearState.Waiting;
                timer     = chargeDelay;
            }
            break;

        case BearState.Waiting:
            timer -= Time.deltaTime;
            if (timer <= 0)
            {
                bearState = BearState.Charging;
            }
            break;

        case BearState.Charging:
            float x = bearIsOnRight ? -moveSpeed * 3: moveSpeed * 3;

            transform.position = new Vector3(transform.position.x + x, transform.position.y, transform.position.z);
            distanceCharged   += moveSpeed * 3;
            if (distanceCharged >= chargeDistance)
            {
                bearState = BearState.Cooldown;

                Vector3 scale = Quad.transform.localScale;
                float   newX  = scale.x * -1;
                Quad.transform.localScale = new Vector3(newX, scale.y, scale.z);
                bearIsOnRight             = !bearIsOnRight;
                timer           = cooldownTime;
                distanceCharged = 0;
            }
            break;

        case BearState.Cooldown:
            timer -= Time.deltaTime;
            if (timer <= 0)
            {
                bearState = BearState.Tracking;
                timer     = trackingTime;
            }
            break;
        }
    }
Exemplo n.º 8
0
    public void HeardPlayer(float playerX)
    {
        if (CurrentState != HEARDPLAYER && CurrentState != ALERTED)
        {
            CurrentState = HEARDPLAYER;

            // Turn towards the direction of the sound.
            if ((playerX > transform.position.x && !IsFacingRight) || (playerX < transform.position.x && IsFacingRight))
            {
                Flip();
            }

            // Return CurrentState back to patrolling after 3 seconds.
            StartCoroutine(HeardPlayerCo());
        }
    }
Exemplo n.º 9
0
 private void handleIfDead()
 {
     if (dead)
     {
         bearState = BearState.Dead;
         if (firstdeadpass && timer < 0.5f)
         {
             deadAnime.SourceRect = new Rectangle(0, 0, deadAnime.SourceRect.Width, deadAnime.SourceRect.Height);
         }
         else
         {
             firstdeadpass        = false;
             deadAnime.SourceRect = new Rectangle(deadAnime.SourceRect.Width, 0, deadAnime.SourceRect.Width, deadAnime.SourceRect.Height);
         }
         velocity.X = 0f;
         velocity.Y = GRAVITY;
     }
 } // void handleIfDead
Exemplo n.º 10
0
		private void OnTriggerEnter2D(Collider2D collision)
		{
            if(collision.gameObject.tag == "ScenePlatform")
            {
                this.m_State = BearState.Wait;

                if(SceneFragmentManager.getInstance.CurLevel < SceneFragmentManager.getInstance.m_Levels.Count)
                {
                    int count = SceneFragmentManager.getInstance.m_Levels[SceneFragmentManager.getInstance.CurLevel].m_curReadyFragments.Count;

                    SceneFragment lastsf = SceneFragmentManager.getInstance.GetLastFragment();

                    if(lastsf ==null)
                    {
                        this.m_State = BearState.Boom;
                        m_Anim.Play("Anim_Bear_Boom");
                    }
                    else
                    {
                        this.transform.parent = lastsf.transform;
                    }
                }
                else
                {
                    
                }
                 
            }


            if(collision.gameObject.tag == "Enemy")
            {
                this.m_State = BearState.Boom;
                m_Anim.Play("Anim_Bear_Boom");

                EnemyBase pEnemy = collision.gameObject.GetComponent<EnemyBase>();
                if(pEnemy != null)
                {
                    pEnemy.Hurt(2);
                }

            }
		}
Exemplo n.º 11
0
        public Bear(ContentManager Content)
        {
            timer         = 0f;
            jumpLapsed    = 0f;
            rand          = new Random();
            isJumping     = false;
            walkjumppass  = false;
            dead          = false;
            firstdeadpass = true;
            walkingAnime  = new Animation(Content, "Bear\\bearwalk", 4, 4);
            rollingAnime  = new Animation(Content, "Bear\\bearroll", 4, 12);
            jumpingAnime  = new Animation(Content, "Bear\\bearjump", 2, 1);
            deadAnime     = new Animation(Content, "Bear\\beardead", 2, 1);

            switch (rand.Next(1, 3))
            {
            case 1: bearState = BearState.Walking;
                position.X    = SCREEN_WIDTH;
                position.Y    = SCREEN_HEIGHT - walkingAnime.SourceRect.Height;
                velocity      = new Vector2(-WALK_SPEED, 0);
                break;

            case 2: bearState = BearState.Rolling;
                position.X    = SCREEN_WIDTH;
                position.Y    = SCREEN_HEIGHT - rollingAnime.SourceRect.Height;
                velocity      = new Vector2(-ROLL_SPEED, 0);
                break;
            }
            #region beartexturesload
            bearJump1 = Content.Load <Texture2D>("BearFrames\\bearJump1");
            bearJump2 = Content.Load <Texture2D>("BearFrames\\bearJump2");
            bearWalk1 = Content.Load <Texture2D>("BearFrames\\bearWalk1");
            bearWalk2 = Content.Load <Texture2D>("BearFrames\\bearWalk2");
            bearWalk3 = Content.Load <Texture2D>("BearFrames\\bearWalk3");
            bearWalk4 = Content.Load <Texture2D>("BearFrames\\bearWalk4");
            bearRoll1 = Content.Load <Texture2D>("BearFrames\\bearRoll1");
            bearRoll2 = Content.Load <Texture2D>("BearFrames\\bearRoll2");
            bearRoll3 = Content.Load <Texture2D>("BearFrames\\bearRoll3");
            bearRoll4 = Content.Load <Texture2D>("BearFrames\\bearRoll4");
            #endregion
        } // constructor
Exemplo n.º 12
0
        public Bear(ContentManager Content)
        {
            timer = 0f;
            jumpLapsed = 0f;
            rand = new Random();
            isJumping = false;
            walkjumppass = false;
            dead = false;
            firstdeadpass = true;
            walkingAnime = new Animation(Content, "Bear\\bearwalk", 4, 4);
            rollingAnime = new Animation(Content, "Bear\\bearroll", 4, 12);
            jumpingAnime = new Animation(Content, "Bear\\bearjump", 2, 1);
            deadAnime = new Animation(Content, "Bear\\beardead", 2, 1);

            switch (rand.Next(1, 3))
            {
                case 1: bearState = BearState.Walking;
                    position.X = SCREEN_WIDTH;
                    position.Y = SCREEN_HEIGHT - walkingAnime.SourceRect.Height;
                    velocity = new Vector2(-WALK_SPEED, 0);
                    break;
                case 2: bearState = BearState.Rolling;
                    position.X = SCREEN_WIDTH;
                    position.Y = SCREEN_HEIGHT - rollingAnime.SourceRect.Height;
                    velocity = new Vector2(-ROLL_SPEED, 0);
                    break;
            }
            #region beartexturesload
            bearJump1 = Content.Load<Texture2D>("BearFrames\\bearJump1");
            bearJump2 = Content.Load<Texture2D>("BearFrames\\bearJump2");
            bearWalk1 = Content.Load<Texture2D>("BearFrames\\bearWalk1");
            bearWalk2 = Content.Load<Texture2D>("BearFrames\\bearWalk2");
            bearWalk3 = Content.Load<Texture2D>("BearFrames\\bearWalk3");
            bearWalk4 = Content.Load<Texture2D>("BearFrames\\bearWalk4");
            bearRoll1 = Content.Load<Texture2D>("BearFrames\\bearRoll1");
            bearRoll2 = Content.Load<Texture2D>("BearFrames\\bearRoll2");
            bearRoll3 = Content.Load<Texture2D>("BearFrames\\bearRoll3");
            bearRoll4 = Content.Load<Texture2D>("BearFrames\\bearRoll4");
            #endregion
        }
Exemplo n.º 13
0
 public void MakeTransition(BearState state)
 {
     Debug.Log(state);
     currentState = states[state];
     currentState.StartState();
 }
Exemplo n.º 14
0
        private void Jump(GameTime gameTime)
        {
            jumpLapsed += (float)gameTime.ElapsedGameTime.TotalSeconds;

            velocity.Y = JUMP_VELOCITY + (GRAVITY * jumpLapsed);

            timer = 0f;

            // this snipped handles if the bear was initially walking, if so play jump animation. otherwise rolling animation is fine.
            if (bearState == BearState.Walking)
            {
                bearState = BearState.Jumping;
            }

            if (bearState == BearState.Jumping)
            {
                if (jumpLapsed < 1.0f && !walkjumppass)
                {
                    jumpingAnime.currFrame = 0;
                    velocity.X = 0f;
                    velocity.Y = 0f;
                    timer = 0f;
                }
                else
                {
                    if (!walkjumppass)
                    {
                        jumpLapsed = 0f;
                        walkjumppass = true;
                    }
                    velocity.X = -WALK_SPEED * 2.0f;
                    jumpingAnime.currFrame = 1;
                    jumpingAnime.SourceRect = new Rectangle(jumpingAnime.SourceRect.Width, 0, jumpingAnime.SourceRect.Width, jumpingAnime.SourceRect.Height);
                }
            }
            // walkingState jump

            if (position.Y > SCREEN_HEIGHT - 148)
            {
                if (bearState == BearState.Jumping)
                {
                    bearState = BearState.Walking;
                    jumpingAnime.SourceRect = new Rectangle(0, 0, jumpingAnime.SourceRect.Width, jumpingAnime.SourceRect.Height);
                    jumpingAnime.currFrame = 0;
                }

                walkjumppass = false;
                position.Y = SCREEN_HEIGHT - 148;
                velocity.Y = 0;
                isJumping = false;
                jumpLapsed = 0f;
                timer = 0f;
            }
        }
Exemplo n.º 15
0
 private void handleIfDead()
 {
     if (dead)
     {
         bearState = BearState.Dead;
         if (firstdeadpass && timer < 0.5f)
         {
             deadAnime.SourceRect = new Rectangle(0, 0, deadAnime.SourceRect.Width, deadAnime.SourceRect.Height);
         }
         else
         {
             firstdeadpass = false;
             deadAnime.SourceRect = new Rectangle(deadAnime.SourceRect.Width, 0, deadAnime.SourceRect.Width, deadAnime.SourceRect.Height);
         }
         velocity.X = 0f;
         velocity.Y = GRAVITY;
     }
 }
Exemplo n.º 16
0
 public void BecomeAlerted()
 {
     CurrentState = ALERTED;
 }
Exemplo n.º 17
0
    public void Kill()
    {
        CurrentState = DEAD;

        gameObject.SetActive(false);
    }
Exemplo n.º 18
0
 // Use this for initialization
 void Start()
 {
     bearState = BearState.Tracking;
     timer     = trackingTime;
 }