//Add a game object to the index public void registerGameObject(GameObject newGameObject) { //Add as a drawable drawableIndex.AddDrawable(newGameObject); //Register the game object's collider collisionManager.registerCollider(newGameObject.Collider, newGameObject); //Add the new object to the index gameObjects.Add(newGameObject); }
private void canvas_CreateResources(ICanvasAnimatedControl sender, CanvasCreateResourcesEventArgs args) { //Initialize image loader with canvas //TODO: The image manager may fail for multiple pages ImageManager.Initialize(sender); //Initialize random number generator randomNumbers = new Random(); //Initialize game systems drawIndex = new DrawableIndex(); collisions = new CollisionManager(); gameObjects = new GameObjectIndex(drawIndex, collisions); inputManager = new InputManager(); players = new PlayerRegistry(randomNumbers); //Load the required images ImageManager.LoadImages(PacmanImagePaths.Images); //Register key event listeners Window.Current.CoreWindow.KeyDown += canvas_KeyDown; Window.Current.CoreWindow.KeyUp += canvas_KeyUp; //Add background image DrawableImage background = new DrawableImage(ImageManager.getImageByName("background1"), Vector2.Zero, false); drawIndex.AddDrawable(background); //Create players player = new PlayerGameObject(new Vector2(200, 300), gameObjects, players, inputManager, KeyboardFormat.WASD); gameObjects.registerGameObject(player); player2 = new PlayerGameObject(new Vector2(250, 300), gameObjects, players, inputManager, KeyboardFormat.ARROWS); gameObjects.registerGameObject(player2); //Create a dummy game object //DummyGameObject testingObject = new DummyGameObject(new Vector2(100, 100), new Vector2(45, 45), gameObjects); //Register the new object in the game object index //gameObjects.registerGameObject(testingObject); //Register the new object as an input listener //Disable debug drawing drawIndex.SetDebugDrawing(false); //Add walls WallGameObject wall = new WallGameObject(new Vector2(0, 0), new Vector2(40, 500)); gameObjects.registerGameObject(wall); WallGameObject wall2 = new WallGameObject(new Vector2(0, 0), new Vector2(850, 20)); gameObjects.registerGameObject(wall2); WallGameObject wall3 = new WallGameObject(new Vector2(830, 0), new Vector2(850, 500)); gameObjects.registerGameObject(wall3); WallGameObject wall4 = new WallGameObject(new Vector2(0, 480), new Vector2(850, 500)); gameObjects.registerGameObject(wall4); WallGameObject wall5 = new WallGameObject(new Vector2(185, 165), new Vector2(200, 330)); gameObjects.registerGameObject(wall5); WallGameObject wall6 = new WallGameObject(new Vector2(185, 165), new Vector2(685, 180)); gameObjects.registerGameObject(wall6); WallGameObject wall7 = new WallGameObject(new Vector2(670, 165), new Vector2(685, 500)); gameObjects.registerGameObject(wall7); WallGameObject wall8 = new WallGameObject(new Vector2(345, 320), new Vector2(525, 330)); gameObjects.registerGameObject(wall8); //Add an enemy object /*EnemyGameObject enemy = new EnemyGameObject(new Vector2(700, 120), gameObjects, new Random()); * enemy.Target = player; * gameObjects.registerGameObject(enemy); * * * EnemyGameObject enemy1 = new EnemyGameObject(new Vector2(400, 200), gameObjects, new Random()); * enemy1.Target = player; * gameObjects.registerGameObject(enemy1); * * EnemyGameObject enemy2 = new EnemyGameObject(new Vector2(250, 300), gameObjects, new Random()); * enemy2.Target = player; * gameObjects.registerGameObject(enemy2); * * EnemyGameObject enemy3 = new EnemyGameObject(new Vector2(100, 350), gameObjects, new Random()); * enemy3.Target = player; * gameObjects.registerGameObject(enemy3); * * EnemyGameObject enemy4 = new EnemyGameObject(new Vector2(750, 400), gameObjects, new Random()); * enemy4.Target = player; * gameObjects.registerGameObject(enemy4);*/ }