protected override void Initialize() { base.Initialize(); GenericGameObjectsFactory.init(Content, _graphics); scene1 = new Scene(); }
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); }
public Scene() { snake = new Snake(GenericGameObjectsFactory.getContentManager().Load <Texture2D>("segment"), Direction.SOUTH, new Vector2(100, 100), 10); snake.Attach(this); snake.Attach(pointsLabel); //snake.Attach(coordinatesLabel); label.Text = ""; inputController = new InputController(snake); SpawnAppleRandomly(); ComponentManager.attachComponent(inputController); ComponentManager.attachComponent(snake); ComponentManager.attachComponent(pointsLabel); ComponentManager.attachComponent(label); //ComponentManager.attachComponent(coordinatesLabel); }
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)); } }