Example #1
0
        public override void Update(State s, Room room)
        {
            frameCounter++;
            if (!Enabled)
            {
                collisionWithDiver = Dimension.Intersects(room.Diver.Dimension);

                if (collisionWithDiver
                    && s.Input.WasPressed(Input.Action.Select)
                    && !disabledThisFrame)
                {
                    int x = X;
                    X = room.Diver.X;
                    room.Diver.X = x;
                    room.Diver.Enabled = false;
                    Enabled = true;
                    OxygenDecrease = false;
                    OxygenIncrease = true;
                    JumpEnabled = false;
                    room.OnDiverChange(this);
                }

                disabledThisFrame = false;
                return;
            }

            isOnGround = IsTileSolidBelow(room) || IsSpecialLadderCase(room) ;

            if (frameCounter % 60 == 0)
                standingGridFrame++;

            if (!Freeze && climbing)
            {
                UpdateClimbingMovement(s, room);
            }
            else if (!Freeze)
            {
                UpdateNormalMovement(s, room);
            }

            if (Tool1 != null)
            {
                Tool1.Update(this, room, s);
            }

            if (Tool2 != null)
            {
                Tool2.Update(this, room, s);
            }

            if (OxygenDecrease)
            {
                Oxygen--;

                if (Oxygen < 0)
                    Oxygen = 0;

                if (s.Time.TotalGameTime.Seconds % 4 == 1 && s.Time.TotalGameTime.Milliseconds % 1000 < 500)
                {
                    if (DiverGame.Random.Next(10) == 0)
                    {
                        room.AddEntity(Particle.MakeBigBubble(new Point(X + Width / 2, Y)));
                    }

                    if (DiverGame.Random.Next(5) == 0)
                    {
                        room.AddEntity(Particle.MakeSmallBubble(new Point(X + Width / 2, Y)));
                    }

                    if (DiverGame.Random.Next(4) == 0)
                    {
                        room.AddEntity(Particle.MakeTinyBubble(new Point(X + Width / 2, Y)));
                    }
                }
            }

            if (OxygenIncrease)
                Oxygen += 5;

            if (Oxygen < 0)
            {
                Freeze = true;
                IsDead = true;
            }

            if (Oxygen > MaxOxygen)
                Oxygen = MaxOxygen;
        }