Exemple #1
0
        internal void Init(ContentManager content)
        {
            Content = content;
            Tileset = Content.Load <Texture2D>("tileset");

            Font = Content.Load <BitmapFont>("font");

            Numbers = Content.Load <Texture2D>("numbers");
            Dirt    = Content.Load <SoundEffect>("dirt");

            Borders = Content.Load <Texture2D>("borders");


            SoundPlayer.Instance.Init(
                Content.Load <SoundEffect>("theme"),
                Content.Load <SoundEffect>("gameover"),
                Content.Load <SoundEffect>("win"),
                Content.Load <SoundEffect>("dirt"),
                Content.Load <SoundEffect>("water_pick"),
                Content.Load <SoundEffect>("water_drop"),
                Content.Load <SoundEffect>("pick"),
                Content.Load <SoundEffect>("cut"),
                Content.Load <SoundEffect>("chicken"),
                Content.Load <SoundEffect>("pig"),
                Content.Load <SoundEffect>("laser")
                );
            Border9Path = new TextureRegion2D[3, 3];
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    Border9Path[i, j] = new TextureRegion2D(Instance.Borders, 16 * i, 16 * j, 16, 16);
                }
            }
        }
Exemple #2
0
 public Meteor(TextureRegion2D textureRegion, Vector2 velocity)
 {
     _sprite      = new Sprite(textureRegion);
     _shape       = new CircleF(_sprite.Position, _radius);
     Velocity     = velocity;
     HealthPoints = 10;
 }
        private void RenderOrthogonal(TiledTile tile, TextureRegion2D region)
        {
            var tx = tile.X * _map.TileWidth;
            var ty = tile.Y * _map.TileHeight;

            _spriteBatch.Draw(region, new Rectangle(tx, ty, region.Width, region.Height), Color.White);
        }
Exemple #4
0
 public void SetTexture(Texture2D texture, bool repeat = true)
 {
     TextureRegion = new TextureRegion2D(texture);
     _currentFrame = 0;
     _repeat       = repeat;
     _looped       = false;
 }
        public void Draw(SpriteBatch spriteBatch)
        {
            if (!CVars.Get <bool>("particle_enable"))
            {
                return;
            }

            Vector2         origin  = Vector2.Zero;
            TextureRegion2D texture = null;

            for (int i = 0; i < _particles.Count; i++)
            {
                Particle particle = _particles[i];

                if (particle.Texture != texture)
                {
                    texture = _particles[i].Texture;
                    origin  = new Vector2(particle.Texture.Width / 2, particle.Texture.Height / 2);
                }

                spriteBatch.Draw(particle.Texture,
                                 particle.Position,
                                 particle.Color,
                                 particle.Rotation,
                                 origin,
                                 particle.Scale,
                                 SpriteEffects.None,
                                 0);
            }
        }
 public TSAImageObject(TextureRegion2D tex, FRectangle rectInitial, Color colInitial, float rotInitial, int order) : base(order)
 {
     _texture = tex;
     _rect0   = rectInitial;
     _col0    = colInitial;
     _rot0    = rotInitial;
 }
Exemple #7
0
        public TSAImageObject AddImage(TextureRegion2D tex, FRectangle r, Color c)
        {
            var obj = new TSAImageObject(tex, r, c, 0f, Elements.Any() ? Elements.Last().Order + 1 : 1);

            AddElement(obj);
            return(obj);
        }
Exemple #8
0
        public TSAImageObject AddImage(TextureRegion2D tex, float x, float y, float w, float h, Color c)
        {
            var obj = new TSAImageObject(tex, new FRectangle(x, y, w, h), c, 0f, Elements.Any() ? Elements.Last().Order + 1 : 1);

            AddElement(obj);
            return(obj);
        }
        public static List <Tile> CreateTiles(Texture2D image, List <RectangleF> tileOrigins, float scaleX, float scaleY)
        {
            List <Tile> tiles = new List <Tile>();

            foreach (var tileOrigin in tileOrigins)
            {
                float scaledXPosition = tileOrigin.X * scaleX;
                float scaledYPosition = tileOrigin.Y * scaleY;
                float scaledWidth     = tileOrigin.Width * scaleX;
                float scaledHeight    = tileOrigin.Height * scaleY;

                var             tile    = new Tile();
                TextureRegion2D newt2ds = new TextureRegion2D(image, tileOrigin.ToRectangle());
                tile.sprite       = new Sprite(newt2ds);
                tile.sprite.Depth = Constants.Depth.GameDepthVariance * 2;

                tile.rotation     = 0f;
                tile.Position     = new Vector2(scaledXPosition + scaledWidth * 0.5f, scaledYPosition + scaledHeight * 0.5f);
                tile.scale        = new Vector2(scaleX, scaleY);
                tile.homePosition = tile.Position;

                tiles.Add(tile);
            }
            return(tiles);
        }
 public ProjectileFactory(IEntityManager entityManager, TextureAtlas atlas)
 {
     _entityManager      = entityManager;
     _atlas              = atlas;
     _projectileTextures = new Dictionary <string, TextureRegion2D>();
     _flashTexture       = _atlas.GetRegion("shotRed");
 }
Exemple #11
0
 public ScrollPaneStyle(ScrollPaneStyle style) : base(style)
 {
     HorizontalScrollBackground = style.HorizontalScrollBackground;
     HorizontalScrollKnob       = style.HorizontalScrollKnob;
     VerticalScrollBackground   = style.VerticalScrollBackground;
     VerticalScrollKnob         = style.VerticalScrollKnob;
 }
 public static void Draw(this SpriteBatch spriteBatch, TextureRegion2D region,
                         Vector2 position, float rotation = 0f, Vector2 origin = default(Vector2),
                         SpriteEffects effects            = SpriteEffects.None)
 {
     spriteBatch.Draw(region.Texture, position, region.Bounds, Color.White, rotation,
                      origin, Vector2.One, effects, 0);
 }
Exemple #13
0
        internal static void Dispose()
        {
            _font              = null;
            _fontSmall         = null;
            _uiSpritesheet     = null;
            _uiStylesheet      = null;
            Stylesheet.Current = null;

            _whiteRegion = null;
            if (_white != null)
            {
                _white.Dispose();
                _white = null;
            }

            if (_uiBitmap != null)
            {
                _uiBitmap.Dispose();
                _uiBitmap = null;
            }

            if (_uiRasterizerState != null)
            {
                _uiRasterizerState.Dispose();
                _uiRasterizerState = null;
            }
        }
        public EnhancedHUDDifficultyButton(int depth, FractionDifficulty diff, Action a)
        {
            Depth = depth;

            icon   = FractionDifficultyHelper.GetIcon(diff);
            action = a;
        }
 public void DrawRegion(TextureRegion2D textureRegion, Vector2 position, Color color, Rectangle?clippingRectangle = null)
 {
     if (textureRegion != null)
     {
         _spriteBatch.Draw(textureRegion, position, color, clippingRectangle);
     }
 }
 public void DrawRegion(TextureRegion2D textureRegion, Rectangle rectangle, Color color, Rectangle?clippingRectangle = null)
 {
     if (textureRegion != null)
     {
         _spriteBatch.Draw(textureRegion, rectangle, color, clippingRectangle);
     }
 }
Exemple #17
0
        /// <summary>
        /// Constructs a <see cref="UIManager"/> instance using an existing grayscale region.
        /// </summary>
        /// <param name="grayscaleRegion">
        /// A <see cref="TextureRegion2D"/> containing at least 1x1 white pixel
        /// at (X:0,Y:0) and a 1x1 gray pixel at (X:0,Y:1)
        /// (this can be larger as linear filtering can stretch the texture).
        /// This texture is mostly used for better shading on elements.
        /// </param>
        public UIManager(GraphicsDevice device, TextureRegion2D grayscaleRegion, TextureRegion2D whitePixelRegion)
        {
            GrayscaleRegion = grayscaleRegion ?? throw new ArgumentNullException(nameof(grayscaleRegion));
            if (GrayscaleRegion.Width < 1)
            {
                throw new ArgumentException(nameof(grayscaleRegion));
            }
            if (GrayscaleRegion.Height < 2)
            {
                throw new ArgumentException(nameof(grayscaleRegion));
            }

            WhitePixelRegion = whitePixelRegion ?? throw new ArgumentNullException(nameof(whitePixelRegion));
            if (WhitePixelRegion.Width < 1)
            {
                throw new ArgumentException(nameof(whitePixelRegion));
            }
            if (WhitePixelRegion.Height < 1)
            {
                throw new ArgumentException(nameof(whitePixelRegion));
            }

            GraphicsDevice = device ?? throw new ArgumentNullException(nameof(device));

            Transforms          = new ListArray <UITransform>();
            Transforms.Changed += Transforms_Changed;
            PreferredSampling   = SamplingMode.LinearClamp;

            Input.TextInput += Input_TextInput;
        }
Exemple #18
0
 private void ParticleInit(TextureRegion2D textureRegion)
 {
     _particleEffect = new ParticleEffect
     {
         Emitters = new[]
         {
             new ParticleEmitter(500, TimeSpan.FromSeconds(2.5), Profile.Ring(150f, Profile.CircleRadiation.In))
             {
                 TextureRegion = textureRegion,
                 Parameters    = new ParticleReleaseParameters
                 {
                     Speed    = new RangeF(50, 0f),
                     Quantity = 3,
                     Rotation = new RangeF(-1f, 1f),
                     Scale    = new RangeF(3.0f, 4.0f)
                 },
                 Modifiers = new IModifier[]
                 {
                     new ColorInterpolator2 {
                         InitialColor = new HslColor(0.33f, 0.5f, 0.5f), FinalColor = new HslColor(0.5f, 0.9f, 1.0f)
                     },
                     new RotationModifier {
                         RotationRate = -2.1f
                     },
                     new RectangleContainerModifier {
                         Width = 800, Height = 480
                     },
                     new LinearGravityModifier {
                         Direction = Axis.Up, Strength = 30f
                     }
                 }
             }
         }
     };
 }
Exemple #19
0
        public static TextureRegion2D BlankRegion(int size)
        {
            var blankTexture = new Texture2D(GameServices.GetService <GraphicsDevice>(), size, size);
            var region       = new TextureRegion2D(blankTexture);

            return(region);
        }
Exemple #20
0
        public static Icon Put(TextureRegion2D region, [CallerLineNumber] int id = 0, bool isAbsoluteId = false)
        {
            // 1. Check if Icon with id already exists.
            //      a. If already exists. Get it.
            //      b  If not, create it.
            // 4. Ping it.
            id = GuiHelper.CurrentIMGUI.CreateId(id, isAbsoluteId);
            GuiHelper.CurrentIMGUI.TryGetValue(id, out IComponent c);

            Icon a;

            if (c is Icon)
            {
                a        = (Icon)c;
                a.Region = region;
            }
            else
            {
                a = new Icon(id, region);
            }

            IParent parent = GuiHelper.CurrentIMGUI.GrabParent(a);

            if (a.LastPing != InputHelper.CurrentFrame)
            {
                a.LastPing = InputHelper.CurrentFrame;
                a.Index    = parent.NextIndex();
            }

            return(a);
        }
        public bool TryGetRegion(string textureName, out TextureRegion2D region)
        {
            bool success = _regions.TryGetValue(textureName, out Region reg);

            region = reg; // 'out' cannot implicitly cast Region to TextureRegion2D
            return(success);
        }
        public HUDDifficultyButton(int depth, FractionDifficulty diff, HUDDifficultyButtonMode mode, Action a)
        {
            Depth      = depth;
            difficulty = diff;

            icon   = FractionDifficultyHelper.GetIcon(diff);
            action = a;

            switch (mode)
            {
            case HUDDifficultyButtonMode.DEACTIVATED:
                BackgroundColor = FlatColors.ButtonHUD;
                ForegroundColor = FlatColors.BackgroundHUD;
                break;

            case HUDDifficultyButtonMode.UNLOCKANIMATION:
                BackgroundColor = FlatColors.ButtonHUD;
                ForegroundColor = FlatColors.SunFlower;
                AddOperation(new HUDDifficultyButtonGainOperation());
                AddOperation(new HUDDifficultyButtonBlinkingIconOperation());
                break;

            case HUDDifficultyButtonMode.ACTIVATED:
                BackgroundColor = FlatColors.BackgroundHUD2;
                ForegroundColor = FlatColors.SunFlower;
                AddOperation(new HUDDifficultyButtonBlinkingIconOperation());
                break;

            default:
                SAMLog.Error("HDB::EnumSwitch_CTR", "value: " + mode);
                break;
            }
        }
        private void ParticlesInit(TextureRegion2D textureRegion)
        {
            var profile = Profile.Spray(Vector2.One, (float)Math.PI * 2);

            _explosionParticleEffect = new ParticleEffect()
            {
                Emitters = new[]
                {
                    new ParticleEmitter(textureRegion, 30, TimeSpan.FromMilliseconds(ExplodingEraseMaxInterval), profile, false)
                    {
                        Parameters = new ParticleReleaseParameters
                        {
                            Speed    = new Range <float>(40f, 120f),
                            Quantity = 30,
                            Rotation = new Range <float>(-1f, 1f),
                            Scale    = new Range <float>(1f, 4.5f),
                            Color    = new HslColor(208.0f, 0.59f, 0.56f)
                        },
                        Modifiers = new IModifier[]
                        {
                            new LinearGravityModifier {
                                Direction = Vector2.UnitY, Strength = 60f
                            },
                            new RotationModifier {
                                RotationRate = 1f
                            },
                            new OpacityFastFadeModifier(),
                            new MapContainerModifier {
                                RestitutionCoefficient = 0.6f
                            }
                        }
                    }
                }
            };
        }
Exemple #24
0
        private void SpawnPlayer(IBulletFactory bulletFactory)
        {
            var spaceshipTexture = Content.Load <Texture2D>("playerShip1_blue");
            var spaceshipRegion  = new TextureRegion2D(spaceshipTexture);

            _player = _entityManager.AddEntity(new Spaceship(spaceshipRegion, bulletFactory));
        }
Exemple #25
0
        //protected override void Initialize()
        //{
        //    base.Initialize();

        //    _graphicsDeviceManager.IsFullScreen = true;
        //    _graphicsDeviceManager.PreferredBackBufferWidth = GraphicsDevice.DisplayMode.Width;
        //    _graphicsDeviceManager.PreferredBackBufferHeight = GraphicsDevice.DisplayMode.Height;
        //    _graphicsDeviceManager.ApplyChanges();
        //}

        protected override void LoadContent()
        {
            _viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480);
            _font            = Content.Load <BitmapFont>("Fonts/montserrat-32");

            _camera = new OrthographicCamera(_viewportAdapter);
            //_explosionAnimations = Content.Load<SpriteSheetAnimationFactory>("explosion-animations");

            _spriteBatch = new SpriteBatch(GraphicsDevice);

            _backgroundTexture = Content.Load <Texture2D>("black");

            var bulletTexture = Content.Load <Texture2D>("laserBlue03");
            var bulletRegion  = new TextureRegion2D(bulletTexture);

            _bulletFactory = new BulletFactory(_entityManager, bulletRegion);

            SpawnPlayer(_bulletFactory);

            _meteorFactory = new MeteorFactory(_entityManager, Content);

            for (var i = 0; i < 13; i++)
            {
                _meteorFactory.SpawnNewMeteor(_player.Position);
            }
        }
        private static BitmapFont LoadFont(string fontDataText, Texture2D texture, Rectangle textureBounds)
        {
            var        lines = fontDataText.Split('\n');
            BitmapFont font  = new BitmapFont(
                int.Parse(ExtractFirstString(lines, "common", "lineHeight"))
                );


            foreach (var line in ExtractLines(lines, "char"))
            {
                var character = (char)ExtractInt(line, "id");
                var x         = ExtractInt(line, "x");
                var y         = ExtractInt(line, "y");
                var width     = ExtractInt(line, "width");
                var height    = ExtractInt(line, "height");
                var offsetX   = ExtractInt(line, "xoffset");
                var offsetY   = ExtractInt(line, "yoffset");
                var advance   = ExtractInt(line, "xadvance");

                var region = new TextureRegion2D(
                    texture,
                    textureBounds.X + x,
                    textureBounds.Y + y,
                    char.IsWhiteSpace(character) ? 0 : width,
                    height
                    );

                font.AddCharacter(new BitmapFontCharacter(region, width, height, advance, new Point(offsetX, offsetY), character));
            }

            return(font);
        }
Exemple #27
0
        private void RenderOrthogonal(TiledTile tile, TextureRegion2D region)
        {
            // not exactly sure why we need to compensate 1 pixel here. Could be a bug in MonoGame?
            var tx = tile.X*(_map.TileWidth - 1);
            var ty = tile.Y*(_map.TileHeight - 1);

            _spriteBatch.Draw(region, new Rectangle(tx, ty, region.Width, region.Height), Color.White);
        }
Exemple #28
0
 public BitmapFontRegion(TextureRegion2D textureRegion, int character, int xOffset, int yOffset, int xAdvance)
 {
     TextureRegion = textureRegion;
     Character     = character;
     XOffset       = xOffset;
     YOffset       = yOffset;
     XAdvance      = xAdvance;
 }
        public PointsCounterComponent(Vector2 position, IGraphicsSystem graphicsSystem, IGamePoints gamePoints)
        {
            _position       = position;
            _graphicsSystem = graphicsSystem ?? throw new ArgumentNullException(nameof(graphicsSystem));
            _gamePoints     = gamePoints ?? throw new ArgumentNullException(nameof(gamePoints));

            _foodTexture2D = graphicsSystem.TextureManager.TextureRegions.GetRegion("Fruit");
        }
Exemple #30
0
 public SpriteComponent(TextureRegion2D textureRegion)
 {
     TextureRegion = textureRegion;
     IsVisible     = true;
     Color         = Color.White;
     Effects       = SpriteEffects.None;
     Alpha         = 1.0f;
 }