public void Update(MouseState newcurrent, MouseState newprevious, ref double ClickTimer, KeyboardState keyPress, ref Dictionary<Keys, List<GameObject>> groupedUnits, ref List<GameObject> units, ref List<GameObject> aunits, ref LoadManager loadManager, ref ProjectileManager projMan, ContentManager theContent, ref int playerResources, bool dbuildPhase) { Rectangle holder = mouseRec; mouseRec = new Rectangle(newcurrent.X, newcurrent.Y, 2, 2); if (!loaded) { loadMouseOvers(theContent); loaded = true; } mouseOver(); mouseRec = holder; bool singleClick = false; current = newcurrent; previous = newprevious; buildPhase = dbuildPhase; if (keyPress.IsKeyDown(Keys.S)&¤t.LeftButton==ButtonState.Pressed&&previous.LeftButton==ButtonState.Released) { int x = Convert.ToInt32(current.X); int y = Convert.ToInt32(current.Y); Vector2 mousePosition = new Vector2(x,y); ClickBox temp = new ClickBox(mousePosition); //temp.LoadContent(theContent); foreach (GameObject unit in units) { if (unit.selected&&unit.GetType()==typeof(Tower)) { if (!((Tower)unit).placed) { ((Tower)unit).placed = true; unit.position = mousePosition; } } } } // Select units after releasing mouse and clear rectangle: if (current.LeftButton == ButtonState.Released && previous.LeftButton == ButtonState.Pressed ) { for (int i = 0; i < units.Count; i++) { if (!selectSimilar) units[i].selected = false; if (units[i].Bounds.Intersects(mouseRec)) { units[i].selected = true; } } mouseRec = Rectangle.Empty; } if (current.LeftButton == ButtonState.Pressed && previous.LeftButton == ButtonState.Released && prevclick) { if (ClickTimer < TimerDelay) { selectSimilar = true; } else { ClickTimer = 0; selectSimilar = false; } } // Select with a single mouse click: if (current.LeftButton == ButtonState.Pressed && previous.LeftButton == ButtonState.Released ) { mouseRec = new Rectangle((int)current.X, (int)current.Y, 0, 0); mouseRecOrigin = new Vector2(current.X, current.Y); GameObject selectedUnit = null; for (int i = 0; i < units.Count; i++) { units[i].selected = false; if (units[i].isSelectable(current) == true) { units[i].selected = true; selectedUnit = units[i]; InfoCard.info(units[i]); break; } } if (selectSimilar && selectedUnit != null) { for (int i = 0; i < units.Count; i++) { if (units[i].GetType() == selectedUnit.GetType()) { units[i].selected = true; } } } singleClick = true; prevclick = true; } // Move selected units or attack: if (current.RightButton == ButtonState.Pressed && previous.RightButton == ButtonState.Released ) { Vector2 testvec = new Vector2(current.X, current.Y); GameObject selectedTarget = null; for (int i = 0; i < aunits.Count; i++) { if (aunits[i].isLoaded) { if (aunits[i].isSelectable(current)) { selectedTarget = aunits[i]; break; } } } for (int i = 0; i < units.Count; i++) { if (units[i].selected == true) { units[i].aiTarget = selectedTarget; } } MovementManager.changeDestination(units, testvec); } if (keyPress.GetPressedKeys().Length > 0 && IsKeyADigit(keyPress.GetPressedKeys()[0])) { Keys pressedKey = keyPress.GetPressedKeys()[0]; if (previousKeyboard.IsKeyDown(Keys.LeftControl) && keyPress.IsKeyDown(pressedKey)) { List<GameObject> groupList = new List<GameObject>(); foreach (GameObject gobj in units) { if (gobj.selected) { groupList.Add(gobj); } } if (groupList.Count > 0) { if (!groupedUnits.ContainsKey(pressedKey)) groupedUnits.Add(pressedKey, groupList); else groupedUnits[pressedKey] = groupList; } } if (!previousKeyboard.IsKeyDown(pressedKey) && keyPress.IsKeyDown(pressedKey)) { if (groupedUnits.ContainsKey(pressedKey)) { deselect(ref groupedUnits, pressedKey); List<GameObject> groupList = groupedUnits[pressedKey]; foreach (GameObject gobj in groupList) gobj.selected = true; } } } if (!previousKeyboard.IsKeyDown(Keys.Delete) && keyPress.IsKeyDown(Keys.Delete) && units.Count > 0) { if (dbuildPhase) // complete refund { int refund = getCost(units[units.Count - 1]); playerResources += refund; } if (units.Count == 1) { if (units[0].GetType() == typeof(Warrior)) { if (((Warrior)(units[0])).moveSpeed == 7) { return; } } } units.RemoveAt(units.Count - 1); offset -= 50; if (offset < 0 && default_player_y > 608) { offset = 300; default_player_y -= 32; } // what to do when not in build phase? partial refund? currently can't undo build in play phase } if (!previousKeyboard.IsKeyDown(Keys.Back) && keyPress.IsKeyDown(Keys.Back)) { foreach (GameObject gobj in units) { if (gobj.selected) { if (gobj.GetType() == typeof(Warrior)) { if (((Warrior)(gobj)).moveSpeed == 7) return; } int refund = getCost(gobj); playerResources += refund; } } units.RemoveAll(gobj => gobj.selected); } Rectangle rect; // Purchase Archer gui.buttonCols.TryGetValue("ARCHER", out rect); if (!previousKeyboard.IsKeyDown(Keys.Z) && keyPress.IsKeyDown(Keys.Z)||(buttonClick(rect)&&singleClick)) { if (playerResources >= Archer.cost) { modelManager.addUnit("PLAYER", "ARCHER", placementUtil()); playerResources-=Archer.cost; } } // Purchase tower gui.buttonCols.TryGetValue("TOWER", out rect); if (!previousKeyboard.IsKeyDown(Keys.X) && keyPress.IsKeyDown(Keys.X) || (buttonClick(rect)&&singleClick)) { if (playerResources >= Tower.cost) { modelManager.addUnit("PLAYER", "TOWER", placementUtil()); playerResources -=Tower.cost; } } // Purchase warrior gui.buttonCols.TryGetValue("WARRIOR", out rect); if (!previousKeyboard.IsKeyDown(Keys.C) && keyPress.IsKeyDown(Keys.C) || (buttonClick(rect)&&singleClick)) { if (playerResources >= Warrior.cost) { modelManager.addUnit("PLAYER", "WARRIOR", placementUtil()); playerResources -=Warrior.cost; } } // Spawn Pawn For Free!!!! Yay gui.buttonCols.TryGetValue("PAWN", out rect); if (!previousKeyboard.IsKeyDown(Keys.V) && keyPress.IsKeyDown(Keys.V) || (buttonClick(rect)&&singleClick)) { if (playerResources >= Pawn.cost) { modelManager.addUnit("PLAYER", "PAWN", placementUtil()); playerResources -=Pawn.cost; } } // Spawn Apprentice For Free!!!! Yay gui.buttonCols.TryGetValue("APPRENTICE", out rect); if (!previousKeyboard.IsKeyDown(Keys.B) && keyPress.IsKeyDown(Keys.B) || (buttonClick(rect)&&singleClick)) { if (playerResources >= Apprentice.cost) { modelManager.addUnit("PLAYER", "APPRENTICE", placementUtil()); playerResources -=Apprentice.cost; } } // Spawn Commander For Free!!!! Yay gui.buttonCols.TryGetValue("COMMANDER", out rect); if (!previousKeyboard.IsKeyDown(Keys.N) && keyPress.IsKeyDown(Keys.N) || (buttonClick(rect)&&singleClick)) { if (playerResources >= Commander.cost) { modelManager.addUnit("PLAYER", "COMMANDER", placementUtil()); playerResources -= Commander.cost; } } // Spawn Catapult For Free!!!! Yay gui.buttonCols.TryGetValue("CATAPULT", out rect); if (!previousKeyboard.IsKeyDown(Keys.M) && keyPress.IsKeyDown(Keys.M) || (buttonClick(rect)&&singleClick)) { if (playerResources >= Catapult.cost) { modelManager.addUnit("PLAYER", "CATAPULT", placementUtil()); playerResources -=Catapult.cost; } } // Spawn Catapult For Free!!!! Yay gui.buttonCols.TryGetValue("ROGUE", out rect); if (!previousKeyboard.IsKeyDown(Keys.J) && keyPress.IsKeyDown(Keys.J) || (buttonClick(rect)&&singleClick)) { if (playerResources >= Rogue.cost) { modelManager.addUnit("PLAYER", "ROGUE", placementUtil()); playerResources -= Rogue.cost; } } gui.buttonCols.TryGetValue("CLERIC", out rect); if (!previousKeyboard.IsKeyDown(Keys.K) && keyPress.IsKeyDown(Keys.K) || (buttonClick(rect)&&singleClick)) { if (playerResources >= Cleric.cost) { modelManager.addUnit("PLAYER", "CLERIC", placementUtil()); playerResources -= Cleric.cost; } } // Skill - When F is pressed, units selected will perform skill foreach (GameObject unit in units) { // Skill - Apprentice Fireball if (unit.selected && unit.GetType() == typeof(Apprentice) && !previousKeyboard.IsKeyDown(Keys.F) && keyPress.IsKeyDown(Keys.F)) { ((Apprentice)unit).fireball(projMan, theContent, unit, new Vector2(current.X, current.Y)); } if (unit.selected && unit.GetType() == typeof(Archer) && !previousKeyboard.IsKeyDown(Keys.F) && keyPress.IsKeyDown(Keys.F)) ((Archer)unit).rapidFire(); if (unit.selected && unit.GetType() == typeof(Warrior) && !previousKeyboard.IsKeyDown(Keys.F) && keyPress.IsKeyDown(Keys.F)) ((Warrior)unit).juggernaut(); if (unit.selected && unit.GetType() == typeof(Rogue) && !previousKeyboard.IsKeyDown(Keys.F) && keyPress.IsKeyDown(Keys.F)) ((Rogue)unit).stealth(); if (unit.selected && unit.GetType() == typeof(Commander) && !previousKeyboard.IsKeyDown(Keys.F) && keyPress.IsKeyDown(Keys.F)) ((Commander)unit).rally(); if (unit.selected && unit.GetType() == typeof(Tower) && !previousKeyboard.IsKeyDown(Keys.F) && keyPress.IsKeyDown(Keys.F)) ((Tower)unit).entrench(); if (unit.selected && unit.GetType() == typeof(BossUnit) && !previousKeyboard.IsKeyDown(Keys.F) && keyPress.IsKeyDown(Keys.F)) ((BossUnit)unit).pound(); // Skill - Rogue stealth // SKill - etc. } // Update mouse rectangle: if (current.LeftButton == ButtonState.Pressed && previous.LeftButton == ButtonState.Pressed ) { if (current.X > mouseRecOrigin.X) { mouseRec.Width = current.X - mouseRec.X; } else { mouseRec.Width = (int)mouseRecOrigin.X - current.X; mouseRec.X = current.X; } if (current.Y > mouseRecOrigin.Y) { mouseRec.Height= current.Y - mouseRec.Y; } else { mouseRec.Height = (int)mouseRecOrigin.Y - current.Y; mouseRec.Y = current.Y; } } previousKeyboard = keyPress; //MoraleBar.resourceVal(playerResources); }
public void Update(MouseState newcurrent, MouseState newprevious, ref double ClickTimer, KeyboardState keyPress, ref Dictionary <Keys, List <GameObject> > groupedUnits, ref List <GameObject> units, ref List <GameObject> aunits, ref LoadManager loadManager, ref ProjectileManager projMan, ContentManager theContent, ref int playerResources, bool dbuildPhase) { Rectangle holder = mouseRec; mouseRec = new Rectangle(newcurrent.X, newcurrent.Y, 2, 2); if (!loaded) { loadMouseOvers(theContent); loaded = true; } mouseOver(); mouseRec = holder; bool singleClick = false; current = newcurrent; previous = newprevious; buildPhase = dbuildPhase; if (keyPress.IsKeyDown(Keys.S) && current.LeftButton == ButtonState.Pressed && previous.LeftButton == ButtonState.Released) { int x = Convert.ToInt32(current.X); int y = Convert.ToInt32(current.Y); Vector2 mousePosition = new Vector2(x, y); ClickBox temp = new ClickBox(mousePosition); //temp.LoadContent(theContent); foreach (GameObject unit in units) { if (unit.selected && unit.GetType() == typeof(Tower)) { if (!((Tower)unit).placed) { ((Tower)unit).placed = true; unit.position = mousePosition; } } } } // Select units after releasing mouse and clear rectangle: if (current.LeftButton == ButtonState.Released && previous.LeftButton == ButtonState.Pressed ) { for (int i = 0; i < units.Count; i++) { if (!selectSimilar) { units[i].selected = false; } if (units[i].Bounds.Intersects(mouseRec)) { units[i].selected = true; } } mouseRec = Rectangle.Empty; } if (current.LeftButton == ButtonState.Pressed && previous.LeftButton == ButtonState.Released && prevclick) { if (ClickTimer < TimerDelay) { selectSimilar = true; } else { ClickTimer = 0; selectSimilar = false; } } // Select with a single mouse click: if (current.LeftButton == ButtonState.Pressed && previous.LeftButton == ButtonState.Released ) { mouseRec = new Rectangle((int)current.X, (int)current.Y, 0, 0); mouseRecOrigin = new Vector2(current.X, current.Y); GameObject selectedUnit = null; for (int i = 0; i < units.Count; i++) { units[i].selected = false; if (units[i].isSelectable(current) == true) { units[i].selected = true; selectedUnit = units[i]; InfoCard.info(units[i]); break; } } if (selectSimilar && selectedUnit != null) { for (int i = 0; i < units.Count; i++) { if (units[i].GetType() == selectedUnit.GetType()) { units[i].selected = true; } } } singleClick = true; prevclick = true; } // Move selected units or attack: if (current.RightButton == ButtonState.Pressed && previous.RightButton == ButtonState.Released ) { Vector2 testvec = new Vector2(current.X, current.Y); GameObject selectedTarget = null; for (int i = 0; i < aunits.Count; i++) { if (aunits[i].isLoaded) { if (aunits[i].isSelectable(current)) { selectedTarget = aunits[i]; break; } } } for (int i = 0; i < units.Count; i++) { if (units[i].selected == true) { units[i].aiTarget = selectedTarget; } } MovementManager.changeDestination(units, testvec); } if (keyPress.GetPressedKeys().Length > 0 && IsKeyADigit(keyPress.GetPressedKeys()[0])) { Keys pressedKey = keyPress.GetPressedKeys()[0]; if (previousKeyboard.IsKeyDown(Keys.LeftControl) && keyPress.IsKeyDown(pressedKey)) { List <GameObject> groupList = new List <GameObject>(); foreach (GameObject gobj in units) { if (gobj.selected) { groupList.Add(gobj); } } if (groupList.Count > 0) { if (!groupedUnits.ContainsKey(pressedKey)) { groupedUnits.Add(pressedKey, groupList); } else { groupedUnits[pressedKey] = groupList; } } } if (!previousKeyboard.IsKeyDown(pressedKey) && keyPress.IsKeyDown(pressedKey)) { if (groupedUnits.ContainsKey(pressedKey)) { deselect(ref groupedUnits, pressedKey); List <GameObject> groupList = groupedUnits[pressedKey]; foreach (GameObject gobj in groupList) { gobj.selected = true; } } } } if (!previousKeyboard.IsKeyDown(Keys.Delete) && keyPress.IsKeyDown(Keys.Delete) && units.Count > 0) { if (dbuildPhase) // complete refund { int refund = getCost(units[units.Count - 1]); playerResources += refund; } if (units.Count == 1) { if (units[0].GetType() == typeof(Warrior)) { if (((Warrior)(units[0])).moveSpeed == 7) { return; } } } units.RemoveAt(units.Count - 1); offset -= 50; if (offset < 0 && default_player_y > 608) { offset = 300; default_player_y -= 32; } // what to do when not in build phase? partial refund? currently can't undo build in play phase } if (!previousKeyboard.IsKeyDown(Keys.Back) && keyPress.IsKeyDown(Keys.Back)) { foreach (GameObject gobj in units) { if (gobj.selected) { if (gobj.GetType() == typeof(Warrior)) { if (((Warrior)(gobj)).moveSpeed == 7) { return; } } int refund = getCost(gobj); playerResources += refund; } } units.RemoveAll(gobj => gobj.selected); } Rectangle rect; // Purchase Archer gui.buttonCols.TryGetValue("ARCHER", out rect); if (!previousKeyboard.IsKeyDown(Keys.Z) && keyPress.IsKeyDown(Keys.Z) || (buttonClick(rect) && singleClick)) { if (playerResources >= Archer.cost) { modelManager.addUnit("PLAYER", "ARCHER", placementUtil()); playerResources -= Archer.cost; } } // Purchase tower gui.buttonCols.TryGetValue("TOWER", out rect); if (!previousKeyboard.IsKeyDown(Keys.X) && keyPress.IsKeyDown(Keys.X) || (buttonClick(rect) && singleClick)) { if (playerResources >= Tower.cost) { modelManager.addUnit("PLAYER", "TOWER", placementUtil()); playerResources -= Tower.cost; } } // Purchase warrior gui.buttonCols.TryGetValue("WARRIOR", out rect); if (!previousKeyboard.IsKeyDown(Keys.C) && keyPress.IsKeyDown(Keys.C) || (buttonClick(rect) && singleClick)) { if (playerResources >= Warrior.cost) { modelManager.addUnit("PLAYER", "WARRIOR", placementUtil()); playerResources -= Warrior.cost; } } // Spawn Pawn For Free!!!! Yay gui.buttonCols.TryGetValue("PAWN", out rect); if (!previousKeyboard.IsKeyDown(Keys.V) && keyPress.IsKeyDown(Keys.V) || (buttonClick(rect) && singleClick)) { if (playerResources >= Pawn.cost) { modelManager.addUnit("PLAYER", "PAWN", placementUtil()); playerResources -= Pawn.cost; } } // Spawn Apprentice For Free!!!! Yay gui.buttonCols.TryGetValue("APPRENTICE", out rect); if (!previousKeyboard.IsKeyDown(Keys.B) && keyPress.IsKeyDown(Keys.B) || (buttonClick(rect) && singleClick)) { if (playerResources >= Apprentice.cost) { modelManager.addUnit("PLAYER", "APPRENTICE", placementUtil()); playerResources -= Apprentice.cost; } } // Spawn Commander For Free!!!! Yay gui.buttonCols.TryGetValue("COMMANDER", out rect); if (!previousKeyboard.IsKeyDown(Keys.N) && keyPress.IsKeyDown(Keys.N) || (buttonClick(rect) && singleClick)) { if (playerResources >= Commander.cost) { modelManager.addUnit("PLAYER", "COMMANDER", placementUtil()); playerResources -= Commander.cost; } } // Spawn Catapult For Free!!!! Yay gui.buttonCols.TryGetValue("CATAPULT", out rect); if (!previousKeyboard.IsKeyDown(Keys.M) && keyPress.IsKeyDown(Keys.M) || (buttonClick(rect) && singleClick)) { if (playerResources >= Catapult.cost) { modelManager.addUnit("PLAYER", "CATAPULT", placementUtil()); playerResources -= Catapult.cost; } } // Spawn Catapult For Free!!!! Yay gui.buttonCols.TryGetValue("ROGUE", out rect); if (!previousKeyboard.IsKeyDown(Keys.J) && keyPress.IsKeyDown(Keys.J) || (buttonClick(rect) && singleClick)) { if (playerResources >= Rogue.cost) { modelManager.addUnit("PLAYER", "ROGUE", placementUtil()); playerResources -= Rogue.cost; } } gui.buttonCols.TryGetValue("CLERIC", out rect); if (!previousKeyboard.IsKeyDown(Keys.K) && keyPress.IsKeyDown(Keys.K) || (buttonClick(rect) && singleClick)) { if (playerResources >= Cleric.cost) { modelManager.addUnit("PLAYER", "CLERIC", placementUtil()); playerResources -= Cleric.cost; } } // Skill - When F is pressed, units selected will perform skill foreach (GameObject unit in units) { // Skill - Apprentice Fireball if (unit.selected && unit.GetType() == typeof(Apprentice) && !previousKeyboard.IsKeyDown(Keys.F) && keyPress.IsKeyDown(Keys.F)) { ((Apprentice)unit).fireball(projMan, theContent, unit, new Vector2(current.X, current.Y)); } if (unit.selected && unit.GetType() == typeof(Archer) && !previousKeyboard.IsKeyDown(Keys.F) && keyPress.IsKeyDown(Keys.F)) { ((Archer)unit).rapidFire(); } if (unit.selected && unit.GetType() == typeof(Warrior) && !previousKeyboard.IsKeyDown(Keys.F) && keyPress.IsKeyDown(Keys.F)) { ((Warrior)unit).juggernaut(); } if (unit.selected && unit.GetType() == typeof(Rogue) && !previousKeyboard.IsKeyDown(Keys.F) && keyPress.IsKeyDown(Keys.F)) { ((Rogue)unit).stealth(); } if (unit.selected && unit.GetType() == typeof(Commander) && !previousKeyboard.IsKeyDown(Keys.F) && keyPress.IsKeyDown(Keys.F)) { ((Commander)unit).rally(); } if (unit.selected && unit.GetType() == typeof(Tower) && !previousKeyboard.IsKeyDown(Keys.F) && keyPress.IsKeyDown(Keys.F)) { ((Tower)unit).entrench(); } if (unit.selected && unit.GetType() == typeof(BossUnit) && !previousKeyboard.IsKeyDown(Keys.F) && keyPress.IsKeyDown(Keys.F)) { ((BossUnit)unit).pound(); } // Skill - Rogue stealth // SKill - etc. } // Update mouse rectangle: if (current.LeftButton == ButtonState.Pressed && previous.LeftButton == ButtonState.Pressed ) { if (current.X > mouseRecOrigin.X) { mouseRec.Width = current.X - mouseRec.X; } else { mouseRec.Width = (int)mouseRecOrigin.X - current.X; mouseRec.X = current.X; } if (current.Y > mouseRecOrigin.Y) { mouseRec.Height = current.Y - mouseRec.Y; } else { mouseRec.Height = (int)mouseRecOrigin.Y - current.Y; mouseRec.Y = current.Y; } } previousKeyboard = keyPress; //MoraleBar.resourceVal(playerResources); }