예제 #1
0
        public override void Update(GameTime gameTime, double insanityLevel)
        {
            base.Update(gameTime, insanityLevel);
            SanityState newState;

            if (insanityLevel < visibleSanityLevel)
            {
                newState = SanityState.Neither;
            }
            else if (insanityLevel < harmfulSanityLevel)
            {
                newState = SanityState.Visible;
            }
            else
            {
                newState = SanityState.Harmful;
            }

            if (newState != currentState)
            {
                ChangeSprite(newState);
            }

            currentState = newState;
        }
예제 #2
0
        public Enemy(Vector2 position, Vector2 size, string visibleSprite, string harmfulSprite, 
            IInputAgent inputBot, double visSanLevel = 0, double harmSanLevel = 0)
            : base(position, size, new Sprite(visibleSprite), inputBot)
        {
            visibleSanityLevel = visSanLevel;
            harmfulSanityLevel = harmSanLevel;

            VisibleSprite = Sprite;
            HarmfulSprite = new Sprite(harmfulSprite);

            currentState = SanityState.Neither;
        }
예제 #3
0
 private void ChangeSprite(SanityState newState)
 {
     switch (newState)
     {
         case SanityState.Neither:
             break;
         case SanityState.Visible:
             ChangeSprite(VisibleSprite);
             break;
         case SanityState.Harmful:
             ChangeSprite(HarmfulSprite);
             break;
         default:
             break;
     }
 }
예제 #4
0
        public Player(Vector2 position)
            : base(position, new Vector2(40, 180), new Sprite("spriteSheets/player sane spritesheet"), new InputHandler(), 300, 400)
        {
            currentSanity = SanityState.Sane;
            saneSprite = Sprite;
            midsaneSprite = new Sprite("spriteSheets/player midsane spritesheet");
            insaneSprite = new Sprite("spriteSheets/player insane spritesheet");
            Sprite.ChangeAnimation("Stand");

            saneSprite.ChangeAnimation("Stand");
            midsaneSprite.ChangeAnimation("Stand");
            insaneSprite.ChangeAnimation("Stand");

            InsanityLevel = 0;
            CurrentPills = 0;
            hud = new HUD();
        }
    private void Awake()
    {
        //  Get the CharacterController component.
        if (charController == null)
        {
            charController = GetComponent <CharacterController2D>();
            if (charController == null)
            {
                Debug.LogError("CharacterController component not found!");
            }
        }

        //  Get the Animator component.
        if (charAnimator == null)
        {
            charAnimator = GetComponent <Animator>();
            if (charAnimator == null)
            {
                Debug.LogError("Animator componenet not found!");
            }
        }

        //  Get the SpriteRenderer component.
        if (charSpriteRenderer == null)
        {
            charSpriteRenderer = GetComponent <SpriteRenderer>();
            if (charSpriteRenderer == null)
            {
                Debug.LogError("SpriteRenderer componenet not found!");
            }
        }

        //  Get the hand pivot transform
        if (handPivot == null)
        {
            handPivot = transform.Find("Hand Pivot");
            if (handPivot == null)
            {
                Debug.LogError("Hand Pivot not found!");
            }
        }

        //  Get the flashlight transform.
        if (flashlight == null)
        {
            flashlight = handPivot.Find("Flashlight");
            if (flashlight == null)
            {
                Debug.LogError("Flashlight not found!");
            }
        }

        //  Set starting stats.
        currentStamina    = maxStamina;
        currentStress     = 0;
        currentSanity     = maxSanity;
        flashLightBattery = 120.0f;
        charState         = CharacterState.Idle;
        sanityState       = SanityState.High;

        //  Initialize collections.
        nearbyObjects = new List <SceneObject>();
    }
예제 #6
0
 private void ChangeSprite(SanityState newSanity)
 {
     switch (newSanity)
     {
         case SanityState.Sane:
             ChangeSprite(saneSprite);
             break;
         case SanityState.Midsane:
             ChangeSprite(midsaneSprite);
             break;
         case SanityState.Insane:
             ChangeSprite(insaneSprite);
             break;
         default:
             break;
     }
 }
예제 #7
0
        public override void Update(GameTime gameTime, double insanityLevel)
        {
            base.Update(gameTime, insanityLevel);

            OwnerLevel.Camera.Position += (Position + Size/2f - (OwnerLevel.Camera.Position + new Vector2(OwnerLevel.ScreenWidth, OwnerLevel.ScreenHeight)/2)) * (float)gameTime.ElapsedGameTime.TotalSeconds * 4;

            if ((mController as InputHandler).Pause())
            {
                InsanityGame.GamestateManager.Push(new PauseState());
            }

            if ((mController as InputHandler).ViewPhoto() && !IsFrozen)
            {
                mPhotoTimer = mPhotoViewTime;
                IsFrozen = true;
                Sprite.ChangeAnimation("ViewPhoto");
            }

            if (mPhotoTimer > 0)
            {
                mPhotoTimer -= gameTime.ElapsedGameTime.TotalSeconds;
                if (mPhotoTimer <= 0)
                {
                    if (InsanityLevel < inanimateEnemyThreshold)
                    {
                        InsanityLevel = inanimateEnemyThreshold;
                    }
                    else if (InsanityLevel < humanEnemyThreshold)
                    {
                        InsanityLevel = humanEnemyThreshold;
                    }
                    else if (InsanityLevel < ghastlyEnemyThreshold)
                    {
                        InsanityLevel = ghastlyEnemyThreshold;
                    }
                    //IsFrozen = false;
                }
            }

            if ((mController as InputHandler).TakePill() && CurrentPills > 0)
            {
                CurrentPills--;
                if (InsanityLevel < humanEnemyThreshold)
                {
                    InsanityLevel = 0;
                }
                else if (InsanityLevel < ghastlyEnemyThreshold)
                {
                    InsanityLevel = inanimateEnemyThreshold;
                }
                else
                {
                    InsanityLevel = humanEnemyThreshold;
                }
            }

            if (OwnerLevel.Actors.Any((actor) => { return actor is DeathArea && IsTouching(actor); }))
            {
                InsanityLevel = Player.deadlyInsane;
            }

            var pills = OwnerLevel.Actors.Where((actor) =>
            {
                return actor is Pill && IsTouching(actor);
            });

            foreach (Pill pill in pills)
            {
                CurrentPills++;
                OwnerLevel.RemoveActor(pill);
            }

            var enemies = OwnerLevel.Actors.Where((actor) =>
            {
                return actor is Enemy && IsTouching(actor);
            });

            foreach (var enemy in enemies)
            {
                var Enemy = enemy as Enemy;
                if (Enemy.IsHarmful(InsanityLevel))
                {
                    if (IsAttacking)
                        OwnerLevel.RemoveActor(enemy);
                    else if (!IsFrozen)
                    {
                        InsanityLevel += .02;
                        IsFrozen = true;

                        Rectangle enemyBounds = new Rectangle((int)enemy.Position.X, (int)enemy.Position.Y, (int)enemy.Size.X, (int)enemy.Size.Y);

                        int feetHeight = 10;
                        int sideWidth = 10;
                        Rectangle leftSide = new Rectangle((int)Position.X, (int)Position.Y + feetHeight, (int)sideWidth, (int)Size.Y - feetHeight * 2);
                        Rectangle rightSide = new Rectangle((int)Position.X + (int)Size.X - sideWidth, (int)Position.Y + feetHeight, (int)sideWidth, (int)Size.Y - feetHeight * 2);

                        if (enemyBounds.Intersects(leftSide))
                        {
                            //bounce right
                            Velocity.X = 100;
                        }
                        else if (enemyBounds.Intersects(rightSide))
                        {
                            //bounce left
                            Velocity.X = -100;
                        }
                    }
                }
            }

            InsanityLevel += gameTime.ElapsedGameTime.TotalSeconds / 107;

            SanityState newSanity;

            if (InsanityLevel < inanimateEnemyThreshold)
            {
                OwnerLevel.InsanityLevel = 0;
                newSanity = SanityState.Sane;
            }
            else if (InsanityLevel < humanEnemyThreshold)
            {
                OwnerLevel.InsanityLevel = 1;
                newSanity = SanityState.Midsane;
            }
            else if (InsanityLevel < ghastlyEnemyThreshold)
            {
                OwnerLevel.InsanityLevel = 1;
                newSanity = SanityState.Midsane;
            }
            else
            {
                OwnerLevel.InsanityLevel = 2;
                newSanity = SanityState.Insane;
            }

            if (newSanity != currentSanity)
            {
                ChangeSprite(newSanity);
            }
            currentSanity = newSanity;

            hud.Update(gameTime, this);

            IsFinished = OwnerLevel.Actors.Any((actor) => { return actor is Goal && IsTouching(actor); });
        }