Esempio n. 1
0
        public CheckBox(Text labelText, bool startValue, int borderSize, int gapSize, int boxSize, Vector2 startPos, Color borderColour, Color checkedButtonColour, Color checkHoverColour, Color backgroundColour, Screen screen) : base(screen)
        {
            label   = labelText;
            Checked = startValue;

            checkedColour = checkedButtonColour;
            hoverColour   = checkHoverColour;

            outlineRectangle = new ColouredRectangle(startPos, new Vector2(boxSize), borderColour);
            innerRectangle   = new ColouredRectangle(new Vector2(startPos.X + borderSize, startPos.Y + borderSize), new Vector2(boxSize - (2 * borderSize)), backgroundColour);
            checkRectangle   = new ColouredRectangle(new Vector2(startPos.X + borderSize + gapSize, startPos.Y + borderSize + gapSize), new Vector2(boxSize - (2 * borderSize) - (2 * gapSize)), checkedButtonColour);
        }
Esempio n. 2
0
        /// <summary>
        /// Construct the button.
        /// </summary>
        /// <param name="buttonStart">The start coordinates of the button.</param>
        /// <param name="buttonStandardColour">The colour of the button (when the mouse is not hovering over it).</param>
        /// <param name="buttonHoverColour">The colour of the button (when the mouse if hovering over it).</param>
        /// <param name="buttonBorderSize">The size of the button's border (in pixels).</param>
        /// <param name="buttonBorderColour">The colour of the button's border.</param>
        /// <param name="buttonCommand">The command for the button to run when clicked.</param>
        public void SetStandardAttributes(Vector2 buttonStart, Color buttonStandardColour, Color buttonHoverColour, int buttonBorderSize, Color buttonBorderColour, Action buttonCommand)
        {
            // Construct the above defined values (this method refactors code from the actual contructors (as there are two of them))
            start          = buttonStart;
            text.Start     = start;
            standardColour = buttonStandardColour;
            hoverColour    = buttonHoverColour;
            borderSize     = buttonBorderSize;
            borderColour   = buttonBorderColour;
            command        = buttonCommand;

            // Get the text size (in pixels) from the text item
            Vector2 textSize = text.font.MeasureString(text.TextString);
            // Get the size that the inner rectangle will be
            Vector2 size = new Vector2(textSize.X + 4, textSize.Y);

            // Construct the rectangles
            rectangle       = new ColouredRectangle(start, size, standardColour);
            borderRectangle = new ColouredRectangle(new Vector2(rectangle.Left - borderSize, rectangle.Top - borderSize), new Vector2(rectangle.Width + (2 * borderSize), rectangle.Height + (2 * borderSize)), borderColour);
        }
Esempio n. 3
0
        public Slider(Vector2 sliderStart, Vector2 sliderLineSize, Vector2 sliderButtonSize, float minValue, float maxValue, Color sliderButtonColour, Color sliderButtonHoverColour, Color sliderButtonPressColour, Color sliderLineColour, Text displayText = null, float initialValue = 0, int displayRound = 2, bool showValueOnRight = true, float textGapLeft = 0, float textGapRight = 0, Screen screen = null) : base(screen)
        {
            start    = sliderStart;
            lineSize = sliderLineSize;
            size     = sliderButtonSize;
            if (displayText != null)
            {
                text = displayText;
            }
            if (displayText != null && showValueOnRight)
            {
                valueText = new Text(text.font);
            }

            buttonColour      = sliderButtonColour;
            buttonHoverColour = sliderButtonHoverColour;
            buttonPressColour = sliderButtonPressColour;
            lineColour        = sliderLineColour;
            activeColour      = buttonColour;

            leftTextOffset  = textGapLeft;
            rightTextOffset = textGapRight;

            sliderLineRectangle          = new ColouredRectangle(start, lineSize, lineColour);
            sliderButtonRectangle        = new ColouredRectangle(new Vector2(0, 0), size, activeColour);
            sliderButtonRectangle.Centre = new Vector2(sliderLineRectangle.Left, sliderLineRectangle.CentreY);

            min   = minValue;
            max   = maxValue;
            range = max - min;
            SetSliderValue(initialValue);

            valueRound = displayRound;

            mousePos       = new Vector2(0, 0);
            leftButtonDown = false;
        }
Esempio n. 4
0
        /// <summary>
        /// Instantiate the world
        /// </summary>
        /// <param name="spriteSheetInstance">The current instance of the sprite sheet</param>
        /// <param name="starCount">The number of stars to render</param>
        /// <param name="maxLaserCount">The number of lasers to be created in memory</param>
        /// <param name="asteroidCount">The number of asteroids to be created</param>
        public World(SpriteSheet spriteSheetInstance, int starCount, int maxLaserCount, int asteroidCount)
        {
            spriteSheet = spriteSheetInstance;

            random = new Random();

            Entities = new List <Entity>();

            GenerateStars(starCount);

            player = new Player(Constants.PLAYER_MAX_HEALTH);
            foreach (Laser laser in player.Lasers)
            {
                AddEntity(laser);
            }
            AddEntity(player);

            foreach (Explosion explosion in player.Explosions)
            {
                AddEntity(explosion);
            }

            enemies = new Enemy[random.Next(2, 6)];
            for (int i = 0; i < enemies.Length; i++)
            {
                enemies[i] =
                    new Enemy(SpriteSheet.Sprite.Enemy,
                              new Vector2(random.Next(0, Shmup.Width),
                                          random.Next(0, Shmup.Height)), true,
                              random.Next(1, 5), 3);
            }
            foreach (Enemy enemy in enemies)
            {
                AddEntity(enemy);
            }

            foreach (Enemy enemy in enemies)
            {
                foreach (Explosion explosion in enemy.Explosions)
                {
                    AddEntity(explosion);
                }
                foreach (Laser laser in enemy.Lasers)
                {
                    AddEntity(laser);
                }
            }

            playerHealths = new PlayerHealth[Constants.PLAYER_MAX_HEALTH];
            for (int i = 0; i < playerHealths.Length; i++)
            {
                playerHealths[i] = new PlayerHealth(SpriteSheet.Sprite.SmallShip, i, new Vector2(Shmup.Width - (i * 15), Shmup.Height - spriteSheet.GetSpriteRectangle(SpriteSheet.Sprite.SmallShip).Height));
            }
            foreach (PlayerHealth playerHealth in playerHealths)
            {
                AddEntity(playerHealth);
            }

            fireModes = new FireMode[10];
            for (int i = 0; i < fireModes.Length; i++)
            {
                fireModes[i] = new FireMode(i, new Vector2());
            }
            foreach (FireMode fireMode in fireModes)
            {
                AddEntity(fireMode);
            }

            asteroids = new List <Asteroid>();
            for (int i = 0; i < asteroidCount; i++)
            {
                asteroids.Add(new Asteroid(SpriteSheet.AsteroidSprites[random.Next(SpriteSheet.AsteroidSprites.Length)], new Vector2(random.Next(0, Shmup.Width), random.Next(0, Shmup.Height)), random.Next(0, 360), (float)random.Next(5, 15) / 10, random.Next(-20, 21) / 10));
            }
            AddEntities(asteroids);

            hitPointVisuals = new ColouredRectangle[player.CollisionPoints.Length + 1 + 4 * enemies.Length];
            for (int i = 0; i < hitPointVisuals.Length; i++)
            {
                hitPointVisuals[i] = new ColouredRectangle(Vector2.Zero, new Vector2(5), Color.Green);
            }
            hitPointVisuals[player.CollisionPoints.Length].Colour = Color.Red;
        }