/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here random = new Random(); textureGen = new TextureGenerator(GraphicsDevice); snake = null; oldSnake = null; food = null; var directory = System.IO.Directory.GetCurrentDirectory(); directory = directory + @"\Levels"; if (!System.IO.Directory.Exists(directory)) { System.IO.Directory.CreateDirectory(directory); } levelAddress = System.IO.Directory.GetFiles(directory); var ScreenHeight = graphics.GraphicsDevice.Viewport.Height; var ScreenWidth = graphics.GraphicsDevice.Viewport.Width; Collision = true; base.Initialize(); }
//int foodToEat; void CheckCollision() { var headRect = snake.segmentsDictionary["Head"].rect; var headPos = snake.segmentsDictionary["Head"].Position; if (Collision) { foreach (var key in snake.segmentsDictionary.Keys) { if (key != "Head") { if (snake.segmentsDictionary[key].Position == headPos) { snake.isDead = true; } } } var wallList = level.GetList(); foreach (var wall in wallList) { if (headRect.Intersects(wall._Rectangle)) { snake.isDead = true; } //if (food.foodblock.getRectangle().Intersects( wall._Rectangle)) //{ // food.createFood(); //} } foreach (var aFood in level.GetFoods()) { if (headRect.Intersects(aFood.foodblock.rect)) { aFood.isEaten = true; snake.SnakeAteCounter++; snake.addSegment(); food = aFood; } } if (food != null) { level.Delete(food); food = null; } } }
public void AddTile(Foods.Food food) { _Foods.Add(food); }
public void Delete(Foods.Food food) { _Foods.Remove(food); }
private void LocateReference() { this.foodReference = Program.GetFoodRegistrar().GetFoodFromName(itemName); }