// Method to fire a bullet protected void fireBullet() { Bullet bullet = new Bullet(); // Why load content explicitly??? bullet.LoadContent(); // Set bullet position where it should be fired bullet.pos = pos + look * centre.Y; // Set direction at which bullet should be fired bullet.look = look; Game1.Instance.children.Add(bullet); }
// Method to fire a bullet private void fireBullet() { Bullet bullet = new Bullet(); // Why load content explicitly??? bullet.LoadContent(); // Set bullet position where it should be fired bullet.pos = pos + look * (sprite.Height / 2); // Set direction at which bullet should be fired bullet.look = look; Game1.Instance.children.Add(bullet); }
// Method to Move tank public void Move(ConsoleKeyInfo[] array) { // Reads each key in array for (int i = 0; i < array.Length; i++) { if (this.owner.PlayerID == 1) { // Determines movement and direction of tank switch (array[i].Key) { // Move tank 1 up case ConsoleKey.W: this.vertical -= this.gc.TankSpeed; break; // Move tank 1 right case ConsoleKey.D: this.horizontal += this.gc.TankSpeed; break; // Move tank 1 down case ConsoleKey.S: this.vertical += this.gc.TankSpeed; break; // Move tank 1 left case ConsoleKey.A: this.horizontal -= this.gc.TankSpeed; break; // Fire bullet case ConsoleKey.F: if (this.canFire) { this.bullet = new Bullet(this.vertical + this.gc.BulletWidth, this.horizontal + this.gc.BulletHeight, this.direction); } break; } } else { switch (array[i].Key) { // Move tank 2 up case ConsoleKey.UpArrow: this.vertical -= this.gc.TankSpeed; break; // Move tank 2 right case ConsoleKey.RightArrow: this.horizontal += this.gc.TankSpeed; break; // Move tank 2 down case ConsoleKey.DownArrow: this.vertical += this.gc.TankSpeed; break; // Move tank 2 left case ConsoleKey.LeftArrow: this.horizontal -= this.gc.TankSpeed; break; // Fire bullet case ConsoleKey.OemPeriod: if (this.canFire) { this.bullet = new Bullet(this.horizontal + this.gc.BulletWidth, this.vertical + this.gc.BulletHeight, this.direction); } break; } } } }