protected HarvestableUnit(TextureValue texture, IResource type, string name, Vector2 size, float totalHealth, float currentHealth, Vector2 position, Color color) : base(texture, position, null, color)
 {
     this.type = type;
     this.name = name;
     this.Size = size;
     stats     = new Stats(new List <Stat>()
     {
         new Health("Health", totalHealth)
     });
     this.CurrentHealth = currentHealth;
     this.Position      = position;
     healthBar          = new HealthBar(new Rectangle(position.ToPoint() - new Point(0, (int)(size.Y * 16 + 1)), size.ToPoint()));
 }
Пример #2
0
        public Rectangle GetStringRectangle(string text, Vector2 position)
        {
            var width = 0;
            var height = 0;

            foreach (var c in text)
            {
                BitmapFontRegion fontRegion;

                if (_characterMap.TryGetValue(c, out fontRegion))
                {
                    width += fontRegion.XAdvance;

                    if (fontRegion.Height + fontRegion.YOffset > height)
                        height = fontRegion.Height + fontRegion.YOffset;
                }
            }

            var p = position.ToPoint();
            return new Rectangle(p.X, p.Y, width, height);
        }
Пример #3
0
 public Rectangle GetStringRectangle(string text, Vector2 position)
 {
     var size = GetSize(text);
     var p = position.ToPoint();
     return new Rectangle(p.X, p.Y, size.Width, size.Height);
 }
Пример #4
0
        /// <summary>
        /// Runs every time the main gameloop reaches it's Update method.
        /// </summary>
        /// <param name="gameTime">The deltatime for the game.</param>
        public virtual void Update(GameTime gameTime, PieceState?statz)
        {
            PieceState stat;

            if (statz.HasValue)
            {
                stat = statz.Value;
            }
            else
            {
                stat = new PieceState(_id, _color, _position);
            }

            if (stat.Id == _id && stat.Color == _color)
            {
                _position = stat.NewPosition;
                Move(ResourceManager.Instance.Fields[(int)stat.NewPosition.X, (int)stat.NewPosition.Y]);
            }

            if (_texture == null)
            {
                return;
            }

            MouseState state = Mouse.GetState();

            Rectangle rect = new Rectangle(_pixelPosition.ToPoint(), new Point(Texture.Height));

            if (rect.Contains(state.Position) && state.LeftButton == ButtonState.Pressed &&
                _oldMouseState.LeftButton == ButtonState.Released && _selected)
            {
                _selected = false;
                _moveableFields.Clear();
            }
            else if (rect.Contains(state.Position) && state.LeftButton == ButtonState.Pressed &&
                     _oldMouseState.LeftButton == ButtonState.Released)
            {
                _selected = true;
            }


            if (_selected && _moveableFields.Count < 1)
            {
                GetMoveableFields();
            }

            if (_selected && _moveableFields.Count > 0)
            {
                for (int i = 0; i < _moveableFields.Count; i++)
                {
                    _moveableFields[i].HoverEnabled = true;

                    if (_moveableFields[i].Rect.Contains(state.Position) && state.LeftButton == ButtonState.Pressed &&
                        _oldMouseState.LeftButton == ButtonState.Released && _selected)
                    {
                        Move(_moveableFields[i]);
                        break;
                    }
                }
            }


            _oldMouseState = state;
        }
Пример #5
0
 public Building(TextureValue texture, Vector2 position, TextureValue Icon, ProjectileManager proj, Stats teamStats) : base(texture, position, teamStats, Color.Blue)
 {
     Cost     = new Wallet();
     name     = "Building";
     Position = new Vector2(0, 0);
     Size     = new Vector2(0, 0);
     stats.Add(new Health("Health", 100000));
     currentHealth       = 0;
     healthBar           = new HealthBar(new Rectangle(this.Position.ToPoint() - new Point(0, (int)(this.Size.Y * 16 + 1)), Size.ToPoint()));
     GarrisonedUnits     = new List <IUnit>();
     this.Icon           = Icon;//if the texture values change this breaks it find a better way to do this
     queueableThings     = new List <IQueueable <TextureValue> >();
     trainingQueue       = new Queue <IQueueable <TextureValue> >();
     BuildingDescription = "";
     techObservers       = new List <ITechObserver>();
     this.proj           = proj;
     this.teamStats      = teamStats;
 }
Пример #6
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                Exit();
            if (ballRect.Right >= screen.Width)
                ballDirection.X = -1;
            if (ballRect.Left <= 0)
                ballDirection.X = 1;

            ballLocation += speed * ballDirection * (float)gameTime.ElapsedGameTime.TotalSeconds;
            ballRect.Location = ballLocation.ToPoint();
            ballRect.X += ballRect.Width / 2;
            ballRect.Y += ballRect.Height / 2;
            base.Update(gameTime);
        }