public void Update(GameTime gameTime, Player player, List<Brick> bricks) { velocity.X = 0; if (!airborn) { if (player.Bounds.X < Bounds.X) { velocity.X = -200; } if (player.Bounds.X > Bounds.X) { velocity.X = 200; } } velocity.Y += 5; //Gravity location += velocity * (float)gameTime.ElapsedGameTime.TotalSeconds; if (Bounds.Intersects(player.Bounds)) { player.Die(); } airborn = true; foreach (Brick brick in bricks) { if (Bounds.Intersects(brick.Bounds)) { Rectangle r = Game1.Intersection(Bounds, brick.Bounds); if (r.Y <= Bounds.Y) { Die(); } else if (r.Y <= brick.Bounds.Y) { location.Y = brick.Bounds.Y - texture.Height; velocity.Y = 0; airborn = false; } } } if (location.Y > ScreenHelper.Viewport.Height - texture.Height) { location.Y = ScreenHelper.Viewport.Height - texture.Height; airborn = false; } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here brickTexture = Content.Load<Texture2D>("Brick"); playerTexture = Content.Load<Texture2D>("Player"); monsterTexture = Content.Load<Texture2D>("Monster"); bulletTexture = Content.Load<Texture2D>("Bullet"); player = new Player(playerTexture, bulletTexture, new Vector2(ScreenHelper.Viewport.Width / 2 - playerTexture.Width / 2, ScreenHelper.Viewport.Height - playerTexture.Height)); wall = new Wall(13, -1); camera = new Camera(GraphicsDevice); }