protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); gameLand = new GameLand(spriteBatch, height, width); gameLand.load(Content); bonuses = new Bonuses(spriteBatch, gameLand.H, gameLand.W); bonuses.load(Content, gameLand.GameBoard); enemys = new Enemys(Content, spriteBatch, 12, gameLand.H, gameLand.W); enemys.load(gameLand.GameBoard); hero = new Hero(Content.Load <Texture2D>("heroright"), new Vector2(3, 3), 1.7f); hero.Content = Content; userInterface = new UserInterface(spriteBatch); userInterface.Load(Content, height, width); }
public void Move(Game1.Direction direction, GameLand gameLand, GameObject[,] block, int height, int width, Bonuses bonuses, int[,] bonusBoard, GameTime gameTime) { bushSpeed = speed - 0.8f; if (direction == Game1.Direction.UP) { Position.Y = Position.Y - velocity.Length(); CheckLandCollision(direction, gameLand, block, height, width); CheckBonuseCollision(bonuses, bonusBoard, height, width, gameTime); checkForGameLandAnd(direction, height, width); } if (direction == Game1.Direction.Down) { Position.Y = Position.Y + velocity.Length(); CheckLandCollision(direction, gameLand, block, height, width); CheckBonuseCollision(bonuses, bonusBoard, height, width, gameTime); checkForGameLandAnd(direction, height, width); } if (direction == Game1.Direction.Right) { texture = content.Load <Texture2D>("heroright"); Position.X = Position.X + velocity.Length(); CheckLandCollision(direction, gameLand, block, height, width); CheckBonuseCollision(bonuses, bonusBoard, height, width, gameTime); checkForGameLandAnd(direction, height, width); } if (direction == Game1.Direction.Left) { texture = content.Load <Texture2D>("heroleft"); Position.X = Position.X - velocity.Length(); CheckLandCollision(direction, gameLand, block, height, width); CheckBonuseCollision(bonuses, bonusBoard, height, width, gameTime); checkForGameLandAnd(direction, height, width); } }
public void CheckBonuseCollision(Bonuses bonuses, int[,] bonusBoard, int height, int width, GameTime gameTime) { if (bonuses.BonusCount != 0) { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (bonusBoard[y, x] > 0) { if (bonusBoard[y, x] == 1) { if (BoundingBox.Intersects(bonuses.Bonus[y, x].BoundingBox)) { if (hp + 15 < 100) { hp = hp + 15; } else { hp = 100; } bonusBoard[y, x] = 0; bonuses.Bonus[y, x] = null; bonuses.BonusCount--; } } else if (bonusBoard[y, x] == 2) { if (BoundingBox.Intersects(bonuses.Bonus[y, x].BoundingBox)) { if (hp + 10 < 100) { hp = hp + 10; } else { hp = 100; } velocity = new Vector2(speed + 0.5f); speed += 0.5f; bonusBoard[y, x] = 0; bonuses.Bonus[y, x] = null; bonuses.BonusCount--; } } else if (bonusBoard[y, x] == 3) { if (BoundingBox.Intersects(bonuses.Bonus[y, x].BoundingBox)) { if (armor + 30 < 100) { armor = armor + 30; } else { armor = 100; } bonusBoard[y, x] = 0; bonuses.Bonus[y, x] = null; bonuses.BonusCount--; } } } } } } }