public void SheetInvaders(Game game, ref Texture2D texture) { for (int i = 0; i < INVASORS; i++) { Invasor invasor = new Invasor(game, ref texture, i, INVASORSHOOTERS, this.difficult); if (i > INVASORS - INVASORSHOOTERS) { invasor.shootin = true; } Game.Components.Add(invasor); } }
public Invasor(Game game, Invasor invasor) : base(game) { #region CONSTRUCTOR this.texture = invasor.texture; this.speed = invasor.speed; this.frameSize = invasor.frameSize; this.currentFrame = invasor.currentFrame; this.sheetSize = new Point(9, 0); this.collisionOffset = new Point(10, 14); this.position = invasor.position; this.millisecondsPerFrame = 60; this.timeToMove = invasor.timeToMove; visible = true; enable = true; die = true; random = new Random((int)(DateTime.Now.Ticks));//new Random(this.GetHashCode()); #endregion }
public void Intesects(Invasor invasor, List <Invasor> list) { #region VARIABLES invasor.enable = false; int shootinInvasorNum = -1; int invasorShooter = -1; bool shootNoAssigned = true; #endregion #region REASIGNACION SHOOT for (int i = Game.Components.Count - 1; i >= 0; i--) { if (Game.Components[i] is Invasor) { #region ASSIGN SHOOT X1 + NOT SHOOT FRIEND if (((Invasor)Game.Components[i]).numInvader == invasor.numInvader - INVASORSHOOTERS && shootNoAssigned) { ((Invasor)Game.Components[i]).shootin = true; shootinInvasorNum = ((Invasor)Game.Components[i]).numInvader; invasorShooter = i; #region NOT SHOOT FRIEND foreach (GameComponent gc in Game.Components) { if (gc is Invasor) { if (((Invasor)gc).numInvader - shootinInvasorNum > 0 && (((Invasor)gc).numInvader - shootinInvasorNum) % INVASORSHOOTERS == 0 && ((Invasor)gc).numInvader != invasor.numInvader) { ((Invasor)Game.Components[i]).shootin = false; } } } #endregion i = 0; } #endregion #region ASSIGN SHOOT X2 else if (((Invasor)Game.Components[i]).numInvader == invasor.numInvader - INVASORSHOOTERS * 2 && shootNoAssigned) { ((Invasor)Game.Components[i]).shootin = true; shootinInvasorNum = ((Invasor)Game.Components[i]).numInvader; shootNoAssigned = false; i = 0; } #endregion #region ASSIGN SHOOT X3 else if (((Invasor)Game.Components[i]).numInvader == invasor.numInvader - INVASORSHOOTERS * 3 && shootNoAssigned) { ((Invasor)Game.Components[i]).shootin = true; shootinInvasorNum = ((Invasor)Game.Components[i]).numInvader; shootNoAssigned = false; i = 0; } #endregion #region ASSIGN SHOOT X4 else if (((Invasor)Game.Components[i]).numInvader == invasor.numInvader - INVASORSHOOTERS * 4 && shootNoAssigned) { ((Invasor)Game.Components[i]).shootin = true; shootinInvasorNum = ((Invasor)Game.Components[i]).numInvader; shootNoAssigned = false; i = 0; } #endregion } } #endregion if (!invasor.die) { Invasor invasorDie = new Invasor(Game, invasor); Game.Components.Add(invasorDie); } Game.Components.Remove(invasor); #region SPEED INCREMENTS if (!invasor.die) { foreach (GameComponent gc in Game.Components) { if (gc is Invasor) { if (((Invasor)gc).speed.X * ((Invasor)gc).speed.X > (INCREMENTSHOOTS * (INVASORS - 1)) * (INCREMENTSHOOTS * (INVASORS - 1))) { if (((Invasor)gc).speed.X > 0) { ((Invasor)gc).speed = new Vector2(((Invasor)gc).speed.X * (0.4f + INCREMENTSHOOTS), ((Invasor)gc).speed.Y); ((Invasor)gc).timeToMove = 0; } else { ((Invasor)gc).speed = new Vector2(((Invasor)gc).speed.X * (0.4f + INCREMENTSHOOTS), ((Invasor)gc).speed.Y); ((Invasor)gc).timeToMove = 0; } } else { if (((Invasor)gc).speed.X > 0) { ((Invasor)gc).speed = new Vector2(((Invasor)gc).speed.X + INCREMENTSHOOTS, ((Invasor)gc).speed.Y); } else { ((Invasor)gc).speed = new Vector2(((Invasor)gc).speed.X - INCREMENTSHOOTS, ((Invasor)gc).speed.Y); } } ((Invasor)gc).millisecondsPerFrame -= SPEEDINCREMENT; //((Invasor)gc).timeToMove = ((Invasor)gc).timeToMove - 25; if (((Invasor)gc).shootquick > difficult) { if (difficult == 90) { ((Invasor)gc).shootquick -= 1; } if (difficult == 70) { ((Invasor)gc).shootquick += 1; } if (difficult == 50) { ((Invasor)gc).shootquick -= 1; } if (difficult == 30) { ((Invasor)gc).shootquick -= 1; } } } } } #endregion }
private void DoLogic() { #region VARIABLES List <Shoot> listShoot = new List <Shoot>(); List <Shoot> listCollShoot = new List <Shoot>(); List <Invasor> listCollInvasor = new List <Invasor>(); List <Background> listCollBackground = new List <Background>(); Tank collTank = null; Ufo collUfo = null; int countInvasor = 0; Invasor invasorDied = null; #endregion foreach (GameComponent gc in Components) { if (gc is Shoot) { if (((Shoot)gc).die) { listCollShoot.Add((Shoot)gc); } else { listShoot.Add((Shoot)gc); } } if (gc is Invasor) { countInvasor++; if (((Invasor)gc).die) { invasorDied = ((Invasor)gc); } } } if (countInvasor == 1 && invasorDied != null) { listCollInvasor.Add(invasorDied); } foreach (GameComponent gc in Components) { foreach (Shoot sh in listShoot) { #region TANK if (gc is Tank) { if (sh.collisionRect.Intersects(((Tank)gc).collisionRectOffset) && !((Tank)gc).die) { collTank = (Tank)gc; listCollShoot.Add(sh); } if (!((Tank)gc).enable && ((Tank)gc).die) { collTank = (Tank)gc; } } #endregion #region INVASOR if (gc is Invasor) { if (sh.collisionRect.Intersects(((Invasor)gc).collisionRectOffset) && !((Invasor)gc).die && !((Invasor)gc).shooted) { ((Invasor)gc).shooted = true; listCollInvasor.Add((Invasor)gc); listCollShoot.Add(sh); } if (!((Invasor)gc).enable && ((Invasor)gc).die) { listCollInvasor.Add((Invasor)gc); } } #endregion #region BACKGROUND if (gc is Background) { if (sh.collisionRect.Intersects(((Background)gc).collisionRect)) { listCollBackground.Add((Background)gc); listCollShoot.Add(sh); } } #endregion #region UFO if (gc is Ufo) { if (sh.collisionRect.Intersects(((Ufo)gc).collisionRectOffset) && !((Ufo)gc).die) { collUfo = (Ufo)gc; listCollShoot.Add(sh); } if (!((Ufo)gc).enable && ((Ufo)gc).die) { collUfo = (Ufo)gc; ufoBonus = true; } } #endregion #region SHOOT if (gc is Shoot) { if (sh.collisionRect.Intersects(((Shoot)gc).collisionRect) && sh.position != ((Shoot)gc).position) { listCollShoot.Add(sh); listCollShoot.Add((Shoot)gc); } } #endregion } } #region INTERSECTIONS if (collTank != null) { player.Intesects(collTank); } if (listCollInvasor.Count > 0) { foreach (Invasor ivr in listCollInvasor) { invasorsManager.Intesects(ivr, listCollInvasor); } } if (listCollBackground.Count > 0) { foreach (Background bg in listCollBackground) { backgoundManager.Intesects(bg); } } if (listCollShoot.Count > 0) { foreach (Shoot sh in listCollShoot) { sh.Intesects(); } } if (collUfo != null) { ufo.Intesects(collUfo); } #endregion }
public void Intesects(Invasor invasor, List<Invasor> list) { #region VARIABLES invasor.enable = false; int shootinInvasorNum = -1; int invasorShooter = -1; bool shootNoAssigned = true; #endregion #region REASIGNACION SHOOT for (int i = Game.Components.Count - 1; i >= 0; i--) if (Game.Components[i] is Invasor) { #region ASSIGN SHOOT X1 + NOT SHOOT FRIEND if (((Invasor)Game.Components[i]).numInvader == invasor.numInvader - INVASORSHOOTERS && shootNoAssigned) { ((Invasor)Game.Components[i]).shootin = true; shootinInvasorNum = ((Invasor)Game.Components[i]).numInvader; invasorShooter = i; #region NOT SHOOT FRIEND foreach (GameComponent gc in Game.Components) { if (gc is Invasor) { if (((Invasor)gc).numInvader - shootinInvasorNum > 0 && (((Invasor)gc).numInvader - shootinInvasorNum) % INVASORSHOOTERS == 0 && ((Invasor)gc).numInvader != invasor.numInvader) { ((Invasor)Game.Components[i]).shootin = false; } } } #endregion i = 0; } #endregion #region ASSIGN SHOOT X2 else if (((Invasor)Game.Components[i]).numInvader == invasor.numInvader - INVASORSHOOTERS * 2 && shootNoAssigned) { ((Invasor)Game.Components[i]).shootin = true; shootinInvasorNum = ((Invasor)Game.Components[i]).numInvader; shootNoAssigned = false; i = 0; } #endregion #region ASSIGN SHOOT X3 else if (((Invasor)Game.Components[i]).numInvader == invasor.numInvader - INVASORSHOOTERS * 3 && shootNoAssigned) { ((Invasor)Game.Components[i]).shootin = true; shootinInvasorNum = ((Invasor)Game.Components[i]).numInvader; shootNoAssigned = false; i = 0; } #endregion #region ASSIGN SHOOT X4 else if (((Invasor)Game.Components[i]).numInvader == invasor.numInvader - INVASORSHOOTERS * 4 && shootNoAssigned) { ((Invasor)Game.Components[i]).shootin = true; shootinInvasorNum = ((Invasor)Game.Components[i]).numInvader; shootNoAssigned = false; i = 0; } #endregion } #endregion if (!invasor.die) { Invasor invasorDie = new Invasor(Game, invasor); Game.Components.Add(invasorDie); } Game.Components.Remove(invasor); #region SPEED INCREMENTS if (!invasor.die) { foreach (GameComponent gc in Game.Components) if (gc is Invasor) { if (((Invasor)gc).speed.X * ((Invasor)gc).speed.X > (INCREMENTSHOOTS * (INVASORS - 1)) *(INCREMENTSHOOTS * (INVASORS - 1))) { if (((Invasor)gc).speed.X > 0) { ((Invasor)gc).speed = new Vector2(((Invasor)gc).speed.X * (0.4f+INCREMENTSHOOTS), ((Invasor)gc).speed.Y); ((Invasor)gc).timeToMove = 0; } else { ((Invasor)gc).speed = new Vector2(((Invasor)gc).speed.X * (0.4f+INCREMENTSHOOTS), ((Invasor)gc).speed.Y); ((Invasor)gc).timeToMove = 0; } } else { if (((Invasor)gc).speed.X > 0) { ((Invasor)gc).speed = new Vector2(((Invasor)gc).speed.X + INCREMENTSHOOTS, ((Invasor)gc).speed.Y); } else { ((Invasor)gc).speed = new Vector2(((Invasor)gc).speed.X - INCREMENTSHOOTS, ((Invasor)gc).speed.Y); } } ((Invasor)gc).millisecondsPerFrame -= SPEEDINCREMENT; //((Invasor)gc).timeToMove = ((Invasor)gc).timeToMove - 25; if (((Invasor)gc).shootquick > difficult) { if (difficult == 90) ((Invasor)gc).shootquick -= 1; if (difficult == 70) ((Invasor)gc).shootquick += 1; if (difficult == 50) ((Invasor)gc).shootquick -= 1; if (difficult == 30) ((Invasor)gc).shootquick -= 1; } } } #endregion }
public void SheetInvaders(Game game, ref Texture2D texture) { for (int i = 0; i < INVASORS; i++) { Invasor invasor = new Invasor(game, ref texture, i, INVASORSHOOTERS, this.difficult); if (i > INVASORS - INVASORSHOOTERS) invasor.shootin = true; Game.Components.Add(invasor); } }