Exemplo n.º 1
0
        public UIElement(UIContainer uicSet, Vector2 posSet, Vector2 sizeSet, Color colorSet)
        {
            pos  = posSet;
            size = sizeSet;
            clr  = colorSet;

            T = this.GetType();

            uic = uicSet;
            uic.uiElements.Add(this);

            texture = uic.uim.block;
        }
Exemplo n.º 2
0
 public UIButton(UIContainer uic, Vector2 posSet, Vector2 sizeSet, Color colorSet) : base(uic, posSet, sizeSet, colorSet)
 {
     baseColor    = colorSet;
     hoverColor   = new Color(Convert.ToInt32(colorSet.R * 0.66), Convert.ToInt32(colorSet.R * 0.66), Convert.ToInt32(colorSet.R * 0.66));
     pressedColor = new Color(Convert.ToInt32(colorSet.R * 0.33), Convert.ToInt32(colorSet.R * 0.33), Convert.ToInt32(colorSet.R * 0.33));
 }
Exemplo n.º 3
0
 public UIBlock(UIContainer uic, Vector2 posSet, Vector2 sizeSet, Color colorSet) : base(uic, posSet, sizeSet, colorSet)
 {
 }
Exemplo n.º 4
0
 public UIText(UIContainer uic, Vector2 posSet, Vector2 sizeSet, Color colorSet, SpriteFont spritefont, string textSet) : base(uic, posSet, sizeSet, colorSet)
 {
     text = textSet;
     font = spritefont;
 }
Exemplo n.º 5
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.White);
            spriteBatch.Begin();

            //grafik för om speldelen av spelet är startat
            if (goc.gocActivate)
            {
                //bakgrund
                goc.bm.Draw(spriteBatch);

                //loopar igenom alla objekt efter deras renderlayer vilket gör att de ritas på varandra i rätt ordning, ex. planeter ritas bakom skepp och kometer
                for (int r = 6; r > 0; r--)
                {
                    foreach (GameObject go in goc.gos)
                    {
                        if (Math.Floor((double)go.rendLayer) == r)
                        {
                            go.Draw(spriteBatch, graphics);
                        }
                    }
                }



                //UI

                //rita spelarens föråd
                goc.player.inv.Draw(spriteBatch, graphics, gamefont);

                //ui för hälsa och värden
                UIContainer statusbar = new UIContainer(uim, new Vector2(0, graphics.PreferredBackBufferHeight - 30), new Vector2(graphics.PreferredBackBufferWidth, 30), Color.Gray, 2);
                int         i         = 0;
                new UIBlock(statusbar, statusbar.rendObj.pos + new Vector2(5 * (i + 1) + 200 * i, 5), new Vector2(200, 20), Color.Red);
                new UIBlock(statusbar, statusbar.rendObj.pos + new Vector2(5 * (i + 1) + 200 * i, 5), new Vector2(200 * (goc.player.fuel / 7000f), 20), Color.Green);
                new UIText(statusbar, statusbar.rendObj.pos + new Vector2(5 * (i + 1) + 200 * i, 5), new Vector2(200, 20), Color.Yellow, gamefont, goc.player.fuel / 10 + "/700 fuel");
                i++;
                new UIBlock(statusbar, statusbar.rendObj.pos + new Vector2(5 * (i + 1) + 200 * i, 5), new Vector2(200, 20), Color.Red);
                new UIBlock(statusbar, statusbar.rendObj.pos + new Vector2(5 * (i + 1) + 200 * i, 5), new Vector2(200 * goc.player.ship.hp / 100, 20), Color.Green);
                new UIText(statusbar, statusbar.rendObj.pos + new Vector2(5 * (i + 1) + 200 * i, 5), new Vector2(200, 20), Color.Yellow, gamefont, goc.player.ship.hp.ToString() + "/100 hp");
                i++;
                new UIBlock(statusbar, statusbar.rendObj.pos + new Vector2(5 * (i + 1) + 200 * i, 5), new Vector2(200, 20), Color.Red);
                new UIBlock(statusbar, statusbar.rendObj.pos + new Vector2(5 * (i + 1) + 200 * i, 5), new Vector2(200 * goc.player.ship.bulletCount / 100, 20), Color.Green);
                new UIText(statusbar, statusbar.rendObj.pos + new Vector2(5 * (i + 1) + 200 * i, 5), new Vector2(200, 20), Color.Yellow, gamefont, goc.player.ship.bulletCount.ToString() + "/100 bullets");

                statusbar.Draw(spriteBatch, graphics);

                spriteBatch.DrawString(gamefont, (new Vector2(Convert.ToInt32(goc.player.ship.pos.X / 100), Convert.ToInt32(goc.player.ship.pos.Y / 100))).ToString(), new Vector2(2, 2), Color.Yellow);

                //Animation för att gå i måll eller förlora
                goc.DrawFade(spriteBatch, graphics, uim);
            }

            //grafik för om huvudmenyn visas
            if (!goc.gocActivate)
            {
                //ui för huvudmenyn
                UIContainer startmenu   = new UIContainer(uim, new Vector2(400, 200), new Vector2(graphics.PreferredBackBufferWidth - 400 * 2, graphics.PreferredBackBufferHeight - 400), Color.Gray, 5);
                UIButton    startButton = new UIButton(startmenu, new Vector2(500, 450), new Vector2(graphics.PreferredBackBufferWidth - 800 - 200, graphics.PreferredBackBufferHeight - 600 - 100), Color.DarkSlateBlue);
                UIText      startText   = new UIText(startmenu, startButton.pos + new Vector2(startButton.size.X / 2, startButton.size.Y / 3), startButton.size, new Color(-startButton.clr.R, -startButton.clr.G, -startButton.clr.B), gamefont, "START");

                UIText titleText = new UIText(startmenu, startText.pos + new Vector2(0, -200), startButton.size, Color.Red, gamefont, menuMessage);
                titleText.pos.X -= (titleText.text.Length) * 9 / 1.5f;
                startText.pos.X -= (startText.text.Length - 1) * 9;

                //starta spelet om startknappen är tryckt
                if (startButton.ButtonPressed())
                {
                    goc.Activate();
                    IsMouseVisible = false;
                }

                //ui för hjälpmenyn
                UIContainer helpMenu = new UIContainer(uim, new Vector2(10, 20 * 8), new Vector2(100, 25), new Color(0, 0, 0, 20), 2);
                new UIText(helpMenu, helpMenu.rendObj.pos, helpMenu.rendObj.size, Color.Gray, gamefont, "[H] Help");

                //visas bara om man tryckt på H knappen för att få hjälp
                if (Keyboard.GetState().IsKeyDown(Keys.H))
                {
                    int i = 2;
                    new UIText(helpMenu, helpMenu.rendObj.pos + new Vector2(0, 20 * i), helpMenu.rendObj.size, Color.Gray, gamefont, "[ESC] Exit Game");
                    i++;
                    i++;
                    new UIText(helpMenu, helpMenu.rendObj.pos + new Vector2(0, 20 * i), helpMenu.rendObj.size, Color.Gray, gamefont, "Movement:");
                    i++;
                    new UIText(helpMenu, helpMenu.rendObj.pos + new Vector2(0, 20 * i), helpMenu.rendObj.size, Color.Gray, gamefont, "[W] Forward");
                    i++;
                    new UIText(helpMenu, helpMenu.rendObj.pos + new Vector2(0, 20 * i), helpMenu.rendObj.size, Color.Gray, gamefont, "[A][D] Rotate");
                    i++;
                    new UIText(helpMenu, helpMenu.rendObj.pos + new Vector2(0, 20 * i), helpMenu.rendObj.size, Color.Gray, gamefont, "[K] Shoot");
                    i++;
                    i++;
                    new UIText(helpMenu, helpMenu.rendObj.pos + new Vector2(0, 20 * i), helpMenu.rendObj.size, Color.Gray, gamefont, "Goal:");
                    i++;
                    new UIText(helpMenu, helpMenu.rendObj.pos + new Vector2(0, 20 * i), helpMenu.rendObj.size, Color.Gray, gamefont, "Reach the Edge of the Universe (at");
                    i++;
                    new UIText(helpMenu, helpMenu.rendObj.pos + new Vector2(0, 20 * i), helpMenu.rendObj.size, Color.Gray, gamefont, Player.winDistance / 100 + " possitive or negative on the x or y axsis)");
                    i++;
                    i++;
                    new UIText(helpMenu, helpMenu.rendObj.pos + new Vector2(0, 20 * i), helpMenu.rendObj.size, Color.Gray, gamefont, "Obsticles:");
                    i++;
                    new UIText(helpMenu, helpMenu.rendObj.pos + new Vector2(0, 20 * i), helpMenu.rendObj.size, Color.Gray, gamefont, "Comets can strike from any direction");
                    i++;
                    new UIText(helpMenu, helpMenu.rendObj.pos + new Vector2(0, 20 * i), helpMenu.rendObj.size, Color.Gray, gamefont, "Limited Resources (Fuel, Health, Ammunition)");
                    i++;
                    i++;
                    new UIText(helpMenu, helpMenu.rendObj.pos + new Vector2(0, 20 * i), helpMenu.rendObj.size, Color.Gray, gamefont, "Crafting");
                    i++;
                    new UIText(helpMenu, helpMenu.rendObj.pos + new Vector2(0, 20 * i), helpMenu.rendObj.size, Color.Gray, gamefont, "Gather Resources on planets to craft, and ");
                    i++;
                    new UIText(helpMenu, helpMenu.rendObj.pos + new Vector2(0, 20 * i), helpMenu.rendObj.size, Color.Gray, gamefont, "replenish Vitality (Fuel, Health, Ammunition)");
                    i++;

                    new UIBlock(helpMenu, helpMenu.rendObj.pos + new Vector2(0, 20 * 2), helpMenu.rendObj.size + new Vector2(285, 20 * (i - 3) + 3), new Color(0, 0, 0, 30));
                }

                startmenu.Draw(spriteBatch, graphics);
                helpMenu.Draw(spriteBatch, graphics);
            }

            spriteBatch.End();
            base.Draw(gameTime);
        }