コード例 #1
0
        public void Draw(GameTime gameTime, SpriteBatch spriteBatch, SpriteFont spriteFont)
        {
            spriteBatch.Draw(background, Rectangle, Color.White);
            MoneyAndTowers.Draw(gameTime, spriteBatch, spriteFont);

            if (clickedTower != null)
            {
                SelectedTower.Draw(gameTime, spriteBatch, spriteFont);
            }
            else
            {
                PurchaseTower.Draw(gameTime, spriteBatch, spriteFont);
            }

            StatsAndControls.Draw(gameTime, spriteBatch, spriteFont);
        }
コード例 #2
0
        private void InitializeStatsAndControls()
        {
            Text t;
            int  y = StatsAndControls.Dimensions.Top + padding;

            StatsAndControls.Add("Wave", new Text(String.Format("Wave {0} of {1}", waveindex + 1, Session.Map.WaveList.Count), new Vector2(StatsAndControls.Dimensions.Left + padding, y)));

            Vector2 d = spriteFont.MeasureString(Session.HealthDisplay);

            StatsAndControls.Add("Health", new Text(Session.HealthDisplay, new Vector2(StatsAndControls.Dimensions.Right - d.X - padding, y)));

            y += (int)(d.Y + spriteFont.LineSpacing);

            string    bt    = "Launch Next Wave Now";
            Vector2   btdim = spriteFont.MeasureString(bt);
            Texture2D tex   = Session.Map.State == MapState.WaveDelay ? Session.Map.SmallNormalButtonTexture : Session.Map.SmallErrorButtonTexture;
            Color     c     = Session.Map.State == MapState.WaveDelay ? Session.Map.ForeColor : Session.Map.ErrorColor;

            Vector2 bpos = new Vector2((int)(SelectedTower.Dimensions.Left + (tex.Width / 2.0f) +
                                             (SelectedTower.Dimensions.Width - tex.Width) / 2.0f), (int)(y + (tex.Height / 2.0f)));

            Vector2 tpos = new Vector2((int)(bpos.X - tex.Width / 2.0f + padding),
                                       (int)(y + (tex.Height - btdim.Y) / 2.0f));

            Button b = new Button(tex, bpos, new Text(bt, spriteFont, tpos), c, clickedTower);

            b.LeftClickEvent += new EventHandler(nextWave_LeftClick);
            StatsAndControls.Add("LaunchNextWave", b);

            y += tex.Height + padding;

            tex = Session.Map.LargeNormalButtonTexture;
            int x = (int)(SelectedTower.Dimensions.Left + (tex.Width / 2.0f) + padding);

            c     = Session.Map.ForeColor;
            bt    = "Pause";
            btdim = spriteFont.MeasureString(bt);
            bpos  = new Vector2(x, (int)(y + (tex.Height / 2.0f)));

            tpos = new Vector2((int)(bpos.X - tex.Width / 2.0f + padding),
                               (int)(y + (tex.Height - btdim.Y) / 2.0f));

            b = new Button(tex, bpos, new Text(bt, spriteFont, tpos), c, null);
            b.LeftClickEvent += new EventHandler(pause_LeftClick);
            StatsAndControls.Add("Pause", b);

            x    += tex.Width;
            bt    = "Increase\nSpeed";
            btdim = spriteFont.MeasureString(bt);
            bpos  = new Vector2(x, (int)(y + (tex.Height / 2.0f)));

            tpos = new Vector2((int)(bpos.X - tex.Width / 2.0f + padding),
                               (int)(y + (tex.Height - btdim.Y) / 2.0f));

            b = new Button(tex, bpos, new Text(bt, spriteFont, tpos), c, null);
            b.LeftClickEvent += new EventHandler(increaseSpeed_LeftClick);
            StatsAndControls.Add("IncreaseSpeed", b);

            x    += tex.Width;
            bt    = "Decrease\nSpeed";
            btdim = spriteFont.MeasureString(bt);
            bpos  = new Vector2(x, (int)(y + (tex.Height / 2.0f)));

            tpos = new Vector2((int)(bpos.X - tex.Width / 2.0f + padding),
                               (int)(y + (tex.Height - btdim.Y) / 2.0f));

            b = new Button(tex, bpos, new Text(bt, spriteFont, tpos), c, null);
            b.LeftClickEvent += new EventHandler(decreaseSpeed_LeftClick);
            StatsAndControls.Add("DecreaseSpeed", b);
        }
コード例 #3
0
        public void Update(GameTime gameTime)
        {
            MoneyAndTowers.GetText("Money").Value  = Session.MoneyDisplay;
            MoneyAndTowers.GetText("Towers").Value = Session.TowersDisplay;
            Button    lnw = StatsAndControls.GetButton("LaunchNextWave");
            Texture2D tex = Session.Map.State == MapState.WaveDelay ? Session.Map.SmallNormalButtonTexture : Session.Map.SmallErrorButtonTexture;
            Color     c   = Session.Map.State == MapState.WaveDelay ? Session.Map.ForeColor : Session.Map.ErrorColor;

            lnw.Texture = tex;
            lnw.SetColor(c);

            if (clickedTower != null)
            {
                foreach (var b in SelectedTower.Buttons)
                {
                    b.Value.Update(gameTime, Session.UI.mouse);
                }
            }
            else
            {
                foreach (var b in PurchaseTower.Buttons)
                {
                    b.Value.Update(gameTime, Session.UI.mouse);
                }
            }

            foreach (var b in StatsAndControls.Buttons)
            {
                b.Value.Update(gameTime, Session.UI.mouse);
            }

            Button isb = StatsAndControls.GetButton("IncreaseSpeed");
            Button dsb = StatsAndControls.GetButton("DecreaseSpeed");

            if (Session.Speed >= Session.MaxSpeed)
            {
                isb.Texture = Session.Map.LargeErrorButtonTexture;
                isb.SetColor(Session.Map.ErrorColor);
                dsb.Texture = Session.Map.LargeNormalButtonTexture;
                dsb.SetColor(Session.Map.ForeColor);
            }
            else if (Session.Speed <= Session.MinSpeed)
            {
                isb.Texture = Session.Map.LargeNormalButtonTexture;
                isb.SetColor(Session.Map.ForeColor);
                dsb.Texture = Session.Map.LargeErrorButtonTexture;
                dsb.SetColor(Session.Map.ErrorColor);
            }
            else
            {
                isb.Texture = Session.Map.LargeNormalButtonTexture;
                isb.SetColor(Session.Map.ForeColor);
                dsb.Texture = Session.Map.LargeNormalButtonTexture;
                dsb.SetColor(Session.Map.ForeColor);
            }

            if (waveindex != Session.Map.WaveIndex)
            {
                waveindex = Session.Map.WaveIndex;
                StatsAndControls.GetText("Wave").Value = String.Format("Wave {0} of {1}", waveindex + 1, Session.Map.WaveList.Count);
            }
        }
コード例 #4
0
        void s_HealthDecreased(object sender, EventArgs e)
        {
            Text t = StatsAndControls.GetText("Health");

            t.Value = Session.HealthDisplay;
        }