private void SpawnAppleRandomly() { Random rnd = new Random(); int maxX = GenericGameObjectsFactory.getGraphics().PreferredBackBufferWidth; int maxY = GenericGameObjectsFactory.getGraphics().PreferredBackBufferHeight; Vector2 randPos = new Vector2(rnd.Next(maxX), rnd.Next(maxY)); apple = new Apple(GenericGameObjectsFactory.getContentManager().Load <Texture2D>("apple"), randPos); apple.Attach(this); apple.Attach(snake); ComponentManager.attachComponent(apple); }
private void portalBoundaryCheck() { var screenwidth = GenericGameObjectsFactory.getGraphics().PreferredBackBufferWidth; var screenheight = GenericGameObjectsFactory.getGraphics().PreferredBackBufferHeight; if (snake.Position.X < 0) { snake.moveTo(new Vector2(screenwidth, snake.Position.Y)); } if (snake.Position.X > screenwidth) { snake.moveTo(new Vector2(0, snake.Position.Y)); } if (snake.Position.Y < 0) { snake.moveTo(new Vector2(snake.Position.X, screenheight)); } if (snake.Position.Y > screenheight) { snake.moveTo(new Vector2(snake.Position.X, 0)); } }