Beispiel #1
0
        public virtual void Update(GameTime gameTime, Player player)
        {
            text = string.Format("x{0}", player.CurrentPills);

            double insanity = player.InsanityLevel;
            int x;
            if (insanity < Player.inanimateEnemyThreshold)
            {
                sanityFill.ChangeAnimation("Green");
                x = (int)(insanity * 60 / Player.inanimateEnemyThreshold);

                fillPosition = new Rectangle(30 + x, fillPosition.Y, 240 - x, fillPosition.Height);
            }
            else if (insanity < Player.humanEnemyThreshold)
            {
                sanityFill.ChangeAnimation("Yellow");
                x = (int)(insanity * 60 / (Player.humanEnemyThreshold - Player.inanimateEnemyThreshold)
                    - Player.inanimateEnemyThreshold * 60 / (Player.humanEnemyThreshold - Player.inanimateEnemyThreshold));

                fillPosition = new Rectangle(90 + x, fillPosition.Y, 180 - x, fillPosition.Height);
            }
            else if (insanity < Player.ghastlyEnemyThreshold)
            {
                sanityFill.ChangeAnimation("Orange");

                x = (int)(insanity * 60 / (Player.ghastlyEnemyThreshold - Player.humanEnemyThreshold)
                    - Player.humanEnemyThreshold * 60 / (Player.ghastlyEnemyThreshold - Player.humanEnemyThreshold));

                fillPosition = new Rectangle(150 + x, fillPosition.Y, 120 - x, fillPosition.Height);
            }
            else
            {
                sanityFill.ChangeAnimation("Red");

                x = (int)(insanity * 60 / (Player.deadlyInsane - Player.ghastlyEnemyThreshold)
                    - Player.ghastlyEnemyThreshold * 60 / (Player.deadlyInsane - Player.ghastlyEnemyThreshold));

                fillPosition = new Rectangle(210 + x, fillPosition.Y, 60 - x, fillPosition.Height);
            }
        }
Beispiel #2
0
        private void Initialize(string levelName)
        {
            Camera = new Camera(new Vector2());
            Loaded = false;
            Actors = new List<Actor>();

            using (var reader = new StreamReader("Content/levels/" + levelName + ".actors"))
            {
                while (!reader.EndOfStream)
                {
                    string input = reader.ReadLine();
                    string[] args = input.Split(' ');
                    Type actorType = Type.GetType(args[0]);

                    Actor actor = (Actor)Activator.CreateInstance(actorType, args.Skip(1).ToList());
                    actor.OwnerLevel = this;
                    Actors.Add(actor);
                }
            }

            mPlayer = Actors.First((actor) => { return (actor as Player) != null; }) as Player;

            mGoal = Actors.First((actor) => { return actor is Goal; }) as Goal;

            Tiles = new List<List<Tile>>();

            string[] tileSpriteNames = new string[]
            {
                "tiles/hospital sane spritesheet",
                "tiles/hospital midsane spritesheet",
                "tiles/hospital insane spritesheet"
            };

            for (int i = 0; i < 3; i++)
            {

                Texture2D levelData = InsanityGame.GameTextures["levels/" + levelName + "_" + i];

                if (i == 0)
                {
                    mNumTilesHorizontal = levelData.Width;
                    mNumTilesVertical = levelData.Height;
                }

                Color[] retrievedColors = new Color[levelData.Width * levelData.Height];

                levelData.GetData<Color>(
                    0,
                    null,
                    retrievedColors,
                    0,
                    retrievedColors.Length);

                List<Tile> tiles = new List<Tile>();
                int index = 0;
                foreach (Color color in retrievedColors)
                {
                    tiles.Add(CreateTileFromColor(color, Tile.Width * (index % mNumTilesHorizontal), Tile.Height * (int)(index / mNumTilesHorizontal), tileSpriteNames[i]));
                    index++;
                }
                Tiles.Add(tiles);
            }
            Loaded = true;
        }