public virtual bool CollidesWithFarmer(Farmer farmer) { Rectangle farmerBounds = farmer.BoundingRectangle; Rectangle objBounds = BoundingRectangle; return farmerBounds.Intersects(objBounds); }
public void MoveAll(GameTime gameTime, Farmer farmer) { objectList.ForEach(delegate(MovingObject obj) { obj.MoveObject(gameTime, farmer, level); }); }
/// <summary> /// Contructs a new level /// </summary> /// <param name="serviceProvider">The service provider that will be used to construct a ContentManager.</param> public Level(IServiceProvider serviceProvider) { // Create a new content manager to load content used just by this level. content = new ContentManager(serviceProvider, "Content"); cannon = new Cannon(this); farmer = new Farmer(this, new Vector2(200, GAME_HEIGHT - 64)); observer = new MovingObjectObserver(this); deadlyObjectFactory = new DeadlyObjectFactory(this); foregroundClouds = new CloudFactory(new Color(Color.White, .90f), 1f, 5, this); backgroundClouds = new CloudFactory(new Color(.75f, .75f, 1f, .95f), .50f, 17, this); score = 0; cannonCountdown = TimeSpan.FromSeconds(5.5); ground = new Rectangle(0, GAME_HEIGHT - 64, GAME_WIDTH, 64); // Load background layer textures. layers = new Texture2D[4]; for (int i = 0; i < layers.Length; ++i) { // Choose a random segment for each background layer for level variety. int segmentIndex = 0; // random.Next(3); layers[i] = Content.Load<Texture2D>("Backgrounds/Layer" + i + "_" + segmentIndex); } ChangeWind(); //Play BGM levelMusic = Content.Load<Song>("Audio/Music/GameMusic"); MediaPlayer.Play(levelMusic); }
protected override void hitFarmer(Farmer farmer, GameTime gameTime) { //Kill the farmer if (!beginFade) { farmer.KillFarmer(gameTime); hitSFX.Play(1f, -.5f, 0f, false); } }
protected override void hitBottom(Farmer farmer, GameTime gameTime) { //Fade out if (!beginFade) { beginFade = true; remainingFadeTime = fadeDuration; } }
public override bool CollidesWithFarmer(Farmer farmer) { Rectangle farmerBounds = farmer.Basket; return farmerBounds.Intersects(boundingRectangle); }
protected override void hitFarmer(Farmer farmer, GameTime gameTime) { if (!beginFade) { //Score and destroy self level.Score += 10; observer.DeregisterObject(this); } }
protected override void hitBottom(Farmer farmer, GameTime gameTime) { //Kill the farmer, then fade out farmer.KillFarmer(gameTime); if (!beginFade) { sheepSFX.Play(.8f); timeToFade = gameTime.TotalGameTime; beginFade = true; } }
public void MoveObject(GameTime gameTime, Farmer farmer, Level level) { float elapsedTime = (float)gameTime.ElapsedGameTime.Ticks / 10000000; velocity.Y += elapsedTime * gravity; if (mass != 0) velocity.X += elapsedTime * (level.Wind.X / mass); Vector2 velocityVector = velocity * elapsedTime; boundingRectangle.Location = new Point( (int)Math.Round(velocityVector.X) + boundingRectangle.Location.X, (int)Math.Round(velocityVector.Y) + boundingRectangle.Location.Y ); if (boundingRectangle.Intersects(level.Ground)) { boundingRectangle.Location = new Point(boundingRectangle.Left, level.Ground.Y - boundingRectangle.Height); velocity.X = 0f; velocity.Y = 0f; hitBottom(farmer, gameTime); } if (CollidesWithFarmer(farmer)) hitFarmer(farmer, gameTime); }
protected abstract void hitFarmer(Farmer farmer, GameTime gameTime);
protected abstract void hitBottom(Farmer farmer, GameTime gameTime);