public MenuState(DodgerX dodgerobj,String[] MenuOptions, Object[] MenuStates) { Vector2 CurrentLocation= new Vector2(dodgerobj.Window.ClientBounds.Width/2-intrologo.Width/2,intrologo.Height+50); for (int i = 0; i < Math.Min(MenuOptions.Length, MenuStates.Length); i++) { MenuStateItem msi = null; if (MenuStates[i] is MenuStateItem.StateAdvanceRoutine) { msi = new MenuStateItem(MenuOptions[i], MenuStates[i] as MenuStateItem.StateAdvanceRoutine, CurrentLocation, MenuFont); } else if (MenuStates[i] is iGameState) msi = new MenuStateItem(MenuOptions[i], MenuStates[i] as iGameState, CurrentLocation, MenuFont); msi.Location = new Vector2((dodgerobj.Window.ClientBounds.Width / 2) - msi.DrawSize.X / 2, msi.Location.Y); CurrentLocation = new Vector2(CurrentLocation.X, CurrentLocation.Y + msi.DrawSize.Y + 5); MenuItems.Add(msi); } }
public MenuState(DodgerX dodgerobj, String[] MenuOptions, MenuStateItem.StateAdvanceRoutine[] stateroutines) : this(dodgerobj,MenuOptions,(Object[])stateroutines) { }
public MenuState(DodgerX dodgerobj, MenuStateItem[] menuitems) { MenuItems = menuitems.ToList(); }
private void AdvanceState(MenuStateItem msi,DodgerX gameobject) { SelectedIndex = (SelectedIndex + 1) % ItemChoices.Length; }
protected void InvokeClick(MenuStateItem itemclicked,DodgerX gameobject) { var copied = ItemClicked; if (copied != null) copied(itemclicked,gameobject); }
public virtual void Update(DodgerX gameobject, GameTime gameTime) { if (prevmousestate == null) prevmousestate = Mouse.GetState(); ElapseCounter += gameTime.ElapsedGameTime; if (ElapseCounter > SpawnObjectDelay) { ElapseCounter = ElapseCounter - SpawnObjectDelay; for (int i = 0; i < 2; i++) { AttackingObject ao = new AttackingObject(new Vector2(0, 0), new Vector2(0, 0), gameobject.attackerTexture); ao.SetRandomStartPosition(gameobject, 8); grd.Attackers.Add(ao); } } _grd.Update(gameobject, gameTime); MenuSelect = DodgerX.soundBank.GetCue("MenuSel"); //Update the selected item based on the mouse position. MenuStateItem foundhit = null; foreach (var msi in MenuItems) { if (msi.HitTest(gameobject, new Vector2(Mouse.GetState().X, Mouse.GetState().Y))) { foundhit = msi; break; } } if (SelectedItem != foundhit) { if (MenuSelect.IsPlaying) MenuSelect.Stop(AudioStopOptions.AsAuthored); try { MenuSelect.Play(); } catch { } } SelectedItem = foundhit; Debug.Print("SelectedItem is now " + (SelectedItem==null?"Null":SelectedItem.Caption)); if (SelectedItem != null) { if (Mouse.GetState().LeftButton == ButtonState.Pressed && prevmousestate.Value.LeftButton==ButtonState.Released) { //gameobject.CurrentState = SelectedItem.AdvanceState; InvokeClick(SelectedItem,gameobject); SelectedItem.AdvanceRoutine(SelectedItem, gameobject); } } prevmousestate = Mouse.GetState(); }
private void RearrangeItems(DodgerX gameobject, Texture2D imagelogo, MenuStateItem[] loopitem) { Vector2 currentlocation = new Vector2(0, imagelogo.Height + 8); for (int i = 0; i < loopitem.Length; i++) { Vector2 measuredsize = loopitem[i].sf.MeasureString(loopitem[i].Caption); loopitem[i].Location = new Vector2(gameobject.Window.ClientBounds.Width / 2 - measuredsize.X / 2, currentlocation.Y); currentlocation.Y += measuredsize.Y + 5; } }