public Bullet(GraphicsDeviceManager graphics, float x, float y, Player player, SpriteBatch spriteBatch, Vector2 direction) { position = new Vector2(x, y); size = new Vector2(10, 10); objectTexture = new Texture2D(graphics.GraphicsDevice, 1, 1); objectTexture.SetData<Color>(new[] { player.playerColor }); this.spriteBatch = spriteBatch; this.player = player; this.graphics = graphics; this.direction = direction; }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); if (GamePad.GetState(PlayerIndex.One).IsConnected) { Player player = new Player(this, spriteBatch, PlayerIndex.One, Content, graphics); players.Add(player); } if (GamePad.GetState(PlayerIndex.Two).IsConnected) { Player player = new Player(this, spriteBatch, PlayerIndex.Two, Content, graphics); players.Add(player); } if (GamePad.GetState(PlayerIndex.Three).IsConnected) { Player player = new Player(this, spriteBatch, PlayerIndex.Three, Content, graphics); players.Add(player); } if (GamePad.GetState(PlayerIndex.Four).IsConnected) { Player player = new Player(this, spriteBatch, PlayerIndex.Four, Content, graphics); players.Add(player); } int i = 0; while (i < 20) { Object ob; if (i <= 10) { ob = new Object(this, Content, graphics, 200 * i, r.Next(100, 1000), 1, spriteBatch); } else { ob = new Object(this, Content, graphics, r.Next(100, 1000), 150 * (i - 11), 2, spriteBatch); } objects.Add(ob); i++; } Hit1FX = Content.Load<SoundEffect>("Hit1"); }
public GameplayScreen() { random = new Random(); worldBounds = new Rectangle(0, 0, 800, 600); player = new Player(); playerBullets = new List<Bullet>(); background = new MyBackground(); background2 = new MyBackground(); aliens = new List<Alien>(); alienBullets = new List<Bullet>(); gameOver = true; TransitionOnTime = TimeSpan.FromSeconds(0.0); TransitionOffTime = TimeSpan.FromSeconds(0.0); spriteTexture = new AnimatedTexture(Vector2.Zero, rotation, scale, depth); // Set device frame rate to 30 fps. TargetElapsedTime = TimeSpan.FromSeconds(1 / 30.0); }
/// <summary> /// Creats the effect for when the player fires a bullet. /// </summary> /// <param name="position">Where on the screen to create the effect.</param> public void CreatePlayerFireSmoke(Player player) { for (int i = 0; i < 8; ++i) { Particle p = CreateParticle(); p.Texture = smoke; p.Color = Color.White; p.Position.X = player.Position.X + player.Width / 2; p.Position.Y = player.Position.Y; p.Alpha = 1.0f; p.AlphaRate = -1.0f; p.Life = 1.0f; p.Rotation = 0.0f; p.RotationRate = -2.0f + 4.0f * (float)random.NextDouble(); p.Scale = 0.25f; p.ScaleRate = 0.25f; p.Velocity.X = -4 + 8.0f * (float)random.NextDouble(); p.Velocity.Y = -16.0f + -32.0f * (float)random.NextDouble(); } }
/// <summary> /// Creats the mud/dust effect when the player moves. /// </summary> /// <param name="position">Where on the screen to create the effect.</param> public void CreatePlayerDust(Player player) { for (int i = 0; i < 2; ++i) { Particle p = CreateParticle(); p.Texture = smoke; p.Color = new Color(125, 108, 43); p.Position.X = player.Position.X + player.Width * (float)random.NextDouble(); p.Position.Y = player.Position.Y + player.Height - 3.0f * (float)random.NextDouble(); p.Alpha = 1.0f; p.AlphaRate = -2.0f; p.Life = 0.5f; p.Rotation = 0.0f; p.RotationRate = -2.0f + 4.0f * (float)random.NextDouble(); p.Scale = 0.25f; p.ScaleRate = 0.5f; p.Velocity.X = -4 + 8.0f * (float)random.NextDouble(); p.Velocity.Y = -8 + 4.0f * (float)random.NextDouble(); } }
private void Connected(PlayerIndex pi) { if (GamePad.GetState(pi).IsConnected) { bool found = false; foreach (Player p in players) { if (p.GetIndex == pi) { found = true; } } if (!found) { Player player = new Player(this, spriteBatch, pi, Content, graphics); players.Add(player); } } }
private int Collision(Player p, GameTime gameTime) { foreach (Bullet b in p.bullets) { foreach (Player p3 in players) { if (p != p3) { Rectangle r = new Rectangle((int)b.GetX, (int)b.GetY, (int)b.GetHeight, (int)b.GetWidth); if (r.Intersects(new Rectangle((int)p3.GetX, (int)p3.GetY, (int)p3.GetHeight, (int)p3.GetWidth))) { if (p3.alive) { p3.ResetPlayer(gameTime, graphics); p.GetScore += 10; p.bullets.Remove(b); return 1; } } } } foreach (Object o in objects) { Rectangle r = new Rectangle((int)b.GetX, (int)b.GetY, (int)b.GetHeight, (int)b.GetWidth); if (r.Intersects(new Rectangle((int)o.GetX, (int)o.GetY, (int)o.GetHeight, (int)o.GetWidth))) { Hit1FX.Play(); p.bullets.Remove(b); o.life--; if (o.life == 0) { b.player.GetScore += 100; } return 1; } } } return 0; }