public static ProjectileManager getInstance() { if (instance == null) { instance = new ProjectileManager(); return instance; } else return instance; }
public override void Attack(GameObject target, ContentManager content, ProjectileManager projMan) { //attackSound(content); Vector2 corrected = Vector2.Add(position, new Vector2(16, 16)); Projectile projectile = new Rocktile(corrected, 100, target, 100, 0); Vector2 direction = MovementManager.getNormalizedVector(projectile.position, target.position); projectile.setDestination(direction, target.position); projectile.LoadContent(content); projMan.proj.Add(projectile); this.animateState = "attack"; this.animateTime = 0; }
// TyDo: Create a new projectile that deals less damage than an arrow, but for now just make it the fireball // Attack the target (not homing). Create a new object projectile sent in the direction of target // The new attack code public override void Attack(GameObject target, ContentManager content, ProjectileManager projMan) { this.soundEffect = content.Load<SoundEffect>("fireball.wav"); soundEffect.Play(); Vector2 corrected = Vector2.Add(position, new Vector2(16, 16)); Projectile projectile = new Iceball(corrected, 0, target, 1, 0); Vector2 direction = MovementManager.getNormalizedVector(projectile.position, target.position); projectile.setDestination(direction, target.position); projectile.LoadContent(content); projMan.proj.Add(projectile); this.animateState = "attack"; this.animateTime = 0; }
public override void Attack(GameObject target, ContentManager content, ProjectileManager projMan) { base.Attack(target, content, projMan); if (stealthTimer.Enabled) { //stealthTimer.Start(); foreach (GameObject unit in ModelManager.artificial) { if (unit.aiTarget == this) unit.aiTarget = null; } } this.animateState = "attack"; this.animateTime = 0; }
public override void Attack(GameObject target, ContentManager content, ProjectileManager projMan) { //if (!juggernautTimer.Enabled) //{ // damage = 15; // attackSpeed = 320; // moveSpeed = 1; // specialAttack = false; // attackRange = 50; //} attackSound(content); target.health -= this.damage; this.animateState = "attack"; this.animateTime = 0; }
// On skill key press, conjur a fireball and send it to target location // TyNote: Create a fireball unit and set destination to target location (not homing). Dies on first collision or at end of path. // TyDo: Fireball has a life timer // TyDo: Make this a spell. For now, it's implemented as the autoattack public void fireball(ProjectileManager projMan, ContentManager content, GameObject target, Vector2 destination) { Fireball fireballTest = null; if (!fireballTimer.Enabled) { fireballTimer.Start(); fireballTest = new Fireball(this.position,10, target, 1, 0); this.myArrow = fireballTest; Vector2 direction = MovementManager.getNormalizedVector(this.position, destination); fireballTest.setDestination(direction, destination); fireballTest.LoadContent(content); projMan.proj.Add(fireballTest); this.animateState = "attack"; this.animateTime = 0; } }
// The new attack code public override void Attack(GameObject target, ContentManager content, ProjectileManager projMan) { //if (!rapidFireTimer.Enabled) //{ // specialAttack = false; // attackSpeed = 180; //} attackSound(content); Vector2 corrected = Vector2.Add(position, new Vector2(16, 16)); Projectile projectile = new Arrow(corrected, 100, target, 100, 0); myArrow = projectile; Vector2 direction = MovementManager.getNormalizedVector(projectile.position, target.position); projectile.setDestination(direction, target.position); projectile.LoadContent(content); projMan.proj.Add(projectile); this.animateState = "attack"; this.animateTime = 0; }
public override void Attack(GameObject target, ContentManager content, ProjectileManager projMan) { attackSound(content); Vector2 corrected = Vector2.Add(position, new Vector2(16, 16)); Projectile projectile = new Arrow(corrected, 100, target, 100, 0); projectile.damage = this.damage; Vector2 direction = MovementManager.getNormalizedVector(projectile.position, target.position); projectile.setDestination(direction, target.position); projectile.LoadContent(content); projMan.proj.Add(projectile); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { try { Window.AllowUserResizing = true; //graphics.CreateDevice(); graphics.PreferredBackBufferHeight = 704; graphics.PreferredBackBufferWidth = 1024; graphics.IsFullScreen = false; // graphics.ToggleFullScreen(); graphics.ApplyChanges(); } catch { } // Create a new SpriteBatch, which can be used to draw textures. ClickTimer = 0; groupedUnits = new Dictionary<Keys, List<GameObject>>(); spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: Add your initialization logic here defeatScreen = new Map("Content/defeatScreen.txt"); mainScreen = new Map("Content/MainScreen.txt"); levelSelect = new Map("Content/levelSelect.txt"); castleDefense = new Map("Content/castleDefense.txt"); riverDefense = new Map("Content/riverDefense.txt"); castleSiege = new Map("Content/castleSiege.txt"); victoryScreen = new Map("Content/victoryScreen.txt"); mainScreenSelector = new Selector(new Rectangle(448, 0, 128, 64), mainScreen, levelSelect, true); castleDefenseSelector = new Selector(new Rectangle(96, 320, 192, 96), levelSelect, castleDefense, false); riverDefenseSelector = new Selector(new Rectangle(416, 320, 192, 96), levelSelect, riverDefense, false); castleSiegeSelector = new Selector(new Rectangle(736, 320, 192, 96), levelSelect, castleSiege, false); defeatScreenSelector = new Selector(new Rectangle(448, 256, 128, 64), defeatScreen, mainScreen, false); victoryScreenSelector = new Selector(new Rectangle(448, 288, 128, 64), victoryScreen, mainScreen, false); modMan = ModelManager.getInstance(ref mainScreen); loadMan = LoadManager.getInstance(); projMan = ProjectileManager.getInstance(); screenManager = ScreenManager.getInstance(); // Add all maps to screenManager.allMaps screenManager.allMaps.Add(defeatScreen); screenManager.allMaps.Add(mainScreen); screenManager.allMaps.Add(levelSelect); screenManager.allMaps.Add(castleDefense); screenManager.allMaps.Add(riverDefense); screenManager.allMaps.Add(castleSiege); screenManager.allMaps.Add(victoryScreen); // Add all selectors to screenManager.allSelectors screenManager.allSelectors.Add(defeatScreenSelector); screenManager.allSelectors.Add(mainScreenSelector); screenManager.allSelectors.Add(castleDefenseSelector); screenManager.allSelectors.Add(riverDefenseSelector); screenManager.allSelectors.Add(castleSiegeSelector); screenManager.allSelectors.Add(victoryScreenSelector); // Set initial maps; These will always be defeatScreen, mainScreen and levelSelect, // since the user spawns on mainScreen screenManager.prevMap = defeatScreen; screenManager.currentMap = mainScreen; screenManager.nextMap = levelSelect; healthChecker = new HealthSystem(ModelManager.player, ModelManager.artificial); attackChecker = new AttackSystem(ref ModelManager.player, ref ModelManager.artificial); attackChecker.linkSystem(projMan); attackChecker.linkContent(Content); movementManager = MovementManager.getInstance(); movementManager.setMap(mainScreen); inputManager = new InputManager(ref modMan); aiManager = AIManager.getInstance(ref mainScreen); mBar = new MoraleBar(ref modMan); gui = new GUIButtons(ref modMan); info = new InfoCard(ref modMan); inputManager.linkGUI(gui); MoraleBar.resourceVal(buildResources); mousePrev = Mouse.GetState(); //Create Player's units //testInitialization(); testCommander(); base.Initialize(); this.IsMouseVisible = true; }
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); }
// Issue attack. Alpha method that damages target. No other skills or actions are implemented in the Alpha Version public virtual void Attack(GameObject target, ContentManager content, ProjectileManager projMan) { attackSound(content); target.health -= this.damage; this.animateState = "attack"; this.animateTime = 0; }
public override void Attack(GameObject target, ContentManager content, ProjectileManager projMan) { Vector2 corrected = Vector2.Add(position, new Vector2(16, 16)); for (int x = 0; x < 4; x++) { Fireball projectile = new Fireball(corrected, 0, this, 1, 0); Vector2 direction = MovementManager.getNormalizedVector(projectile.position, circleFire(x)); projectile.setDestination(direction, circleFire(x)); projectile.LoadContent(content); projMan.proj.Add(projectile); } }
public void linkSystem(ProjectileManager newMan) { projMan = newMan; }