/// <summary> /// Initializes a new instance of the <see cref="GameLayer"/> class. /// </summary> public GameLayer() { this.graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; this.graphics.PreferredBackBufferWidth = this.WindowWidth; this.graphics.PreferredBackBufferHeight = this.WindowHeight; this.ActionScreen = new Rectangle(0, 0, this.WindowWidth, this.WindowHeight); IsMouseVisible = true; this.graphics.IsFullScreen = false; this.RedPlayer = new Player(); this.BluePlayer = new Player(); this.RedPlayer.Initialize(new Animation(), new Vector2(40 * 9, 40 * 15)); this.BluePlayer.Initialize(new Animation(), new Vector2(40 * 10, 40 * 15)); this.MissleBoxOfRedPlayer = new List<Missle>(); this.MissleBoxOfBluePlayer = new List<Missle>(); }
// Initialize the player public void Initialize(Animation animation, Vector2 position, int inflictDmg, float angle, int speed, Player owner, SoundEffect explosionEffect) { MissleAnimation = animation; // Set the starting position of the player around the middle of the screen and to the back MissleAnimation.Position = position; // Set the player to be active Alive = true; MissleAnimation.Angle = angle; // Set the player health RemoveValue = inflictDmg; Speed = speed; this.Owner = owner; this.MissleEffect = explosionEffect; }
/// <summary> /// Create custom missle with specific values /// </summary> /// <param name="MisssleTex"> /// The misssle tex. /// </param> /// <param name="spd"> /// The spd. /// </param> /// <param name="infDmg"> /// The inf dmg. /// </param> /// <param name="ownerOfMissle"> /// The owner Of Missle. /// </param> /// <param name="currentMissleBox"> /// The current Missle Box. /// </param> /// <param name="missleEffect"> /// The missle Effect. /// </param> private void CreateNewMissle(Texture2D MisssleTex, int spd, int infDmg, Player ownerOfMissle, List<Missle> currentMissleBox, SoundEffect missleEffect) { if (currentMissleBox.Count < this.MissleCount) { currentMissleBox.Add(new Missle()); currentMissleBox[currentMissleBox.Count - 1].Initialize( new Animation(), ownerOfMissle.PlayerAnimation.Position, infDmg, ownerOfMissle.PlayerAnimation.Angle, spd, ownerOfMissle, missleEffect); currentMissleBox[currentMissleBox.Count - 1].MissleAnimation.Initialize( MisssleTex, ownerOfMissle.PlayerAnimation.Position, 20, 20, 2, 30, Color.White, 1.0f, true); } else { foreach (Missle missle in currentMissleBox.Where(missle => missle.Alive == false)) { missle.Initialize( new Animation(), ownerOfMissle.PlayerAnimation.Position, infDmg, ownerOfMissle.PlayerAnimation.Angle, spd, ownerOfMissle, missleEffect); missle.MissleAnimation.Initialize( MisssleTex, ownerOfMissle.PlayerAnimation.Position, 20, 20, 2, 30, Color.White, 1.0f, true); return; } } }
/// <summary> /// Check collision of Player in blocks and screen /// </summary> /// <param name="x"> /// The x. /// </param> /// <param name="y"> /// The y. /// </param> /// <returns> /// </returns> private bool CheckOnCollision(float x, float y, Player owner) { Rectangle dest = new Rectangle(x: (int)x - (int)(40 * 1.0f) / 2, y: (int)y - (int)(40 * 1.0f) / 2, width: (int)(40 * 1.0f), height: (int)(40 * 1.0f)); if (!this.ActionScreen.Intersects(dest)) { return false; } if (owner == RedPlayer && BluePlayer.PlayerAnimation.destRect.Intersects(dest)) return false; if (owner == BluePlayer && RedPlayer.PlayerAnimation.destRect.Intersects(dest)) return false; return (from b in this.currentArena.AssetPosition where b.Texture != this.texList[2].Tex select b).All(block => !block.Place.Intersects(dest)); }