コード例 #1
0
ファイル: IngamePresentation.cs プロジェクト: khoatle/game
        public static void DrawEnvironmentBar(Game game, SpriteBatch spriteBatch, SpriteFont statsFont, int currentEnvironment, int maxEnvironemnt)
        {
            int barX = game.Window.ClientBounds.Width - 10 - (int)(41 * textScaleFactor);
            int barY = game.Window.ClientBounds.Height / 2 - (int)(EnvironmentBar.Height / 2 * textScaleFactor);
            string type = "ENVIRONMENT";
            Color typeColor = Color.IndianRed;
            int barWidth = (int)(41 * textScaleFactor);// EnvironmentBar.Width / 2;
            double healthiness = (double)currentEnvironment / maxEnvironemnt;
            //Draw the negative space for the health bar
            //spriteBatch.Draw(EnvironmentBar,
            //    new Rectangle(barX, barY, barWidth, EnvironmentBar.Height),
            //    new Rectangle(barWidth + 1, 0, barWidth, EnvironmentBar.Height),
            //    Color.Transparent);
            //Draw the current health level based on the current Health
            Color healthColor = Color.Gold;
            if (healthiness < 0.2)
                healthColor = Color.DarkRed;
            else if (healthiness < 0.5)
                healthColor = Color.Red;
            else if (healthiness < 0.8)
                healthColor = Color.LawnGreen;
            spriteBatch.Draw(EnvironmentBar,
                new Vector2(barX, barY + (EnvironmentBar.Height - (int)(EnvironmentBar.Height * healthiness)) * textScaleFactor),
                new Rectangle(45, EnvironmentBar.Height - (int)(EnvironmentBar.Height * healthiness), 43, (int)(EnvironmentBar.Height * healthiness)),
                healthColor, 0, Vector2.Zero, textScaleFactor, SpriteEffects.None, 0);
            //Draw the box around the health bar
            spriteBatch.Draw(EnvironmentBar, new Vector2(barX, barY), new Rectangle(0, 0, 41, EnvironmentBar.Height), Color.White,
                0, Vector2.Zero, textScaleFactor, SpriteEffects.None, 0);
            //spriteBatch.DrawString(statsFont, type.ToUpper(), new Vector2(game.Window.ClientBounds.Width / 2 - ((type.Length / 2) * 14), heightFromTop - 1), typeColor);
            //spriteBatch.DrawString(statsFont, type.ToUpper(), new Vector2(barX + 10, barY + 20), typeColor, 90.0f, new Vector2(barX + 10, barY + 20), 1, SpriteEffects.FlipVertically, 0);
            type = type.ToUpper();
            //spriteBatch.DrawString(statsFont, type.ToUpper(), new Vector2(barX + 35, barY + 70), typeColor, 3.14f / 2, new Vector2(0, 0), 1, SpriteEffects.None, 0);
            spriteBatch.DrawString(statsFont, type, new Vector2(barX + barWidth / 2, game.Window.ClientBounds.Height / 2), Color.Gold, 3.14f / 2, new Vector2(statsFont.MeasureString(type).X / 2, statsFont.MeasureString(type).Y / 2), textScaleFactor, SpriteEffects.None, 0);

            //draw the lobster on bottom
            //spriteBatch.Draw(lobsterTexture, new Vector2(barX + barWidth / 2, game.Window.ClientBounds.Height / 2 + EnvironmentBar.Height / 2 - 30), null, Color.White, 0, new Vector2(lobsterTexture.Width / 2, lobsterTexture.Height / 2), 1, SpriteEffects.None, 0);

            //draw floating bubbles inside tube
            if (PoseidonGame.playTime.TotalMilliseconds - lastBubbleCreated >= 250)
            {
                Bubble bubble = new Bubble();
                bubble.LoadContentBubbleSmall(PoseidonGame.contentManager, new Vector2(barX + barWidth / 2, barY + (EnvironmentBar.Height) * textScaleFactor - 8), barX, barX + barWidth - 3);
                bubbles.Add(bubble);
                lastBubbleCreated = PoseidonGame.playTime.TotalMilliseconds;
            }
            for (int i = 0; i < bubbles.Count; i++)
            {
                if (bubbles[i].bubble2DPos.Y - bubbles[i].bubbleTexture.Height/2 * bubbles[i].startingScale <= barY + (EnvironmentBar.Height - (int)(EnvironmentBar.Height * healthiness)) * textScaleFactor ||
                    bubbles[i].bubble2DPos.Y - bubbles[i].bubbleTexture.Height/2 * bubbles[i].startingScale <= barY + 4)
                    bubbles.RemoveAt(i--);

            }
            foreach (Bubble aBubble in bubbles)
            {
                aBubble.UpdateBubbleSmall();
                aBubble.DrawBubbleSmall(spriteBatch);
            }
        }