private void canvas_CreateResources(ICanvasAnimatedControl sender, CanvasCreateResourcesEventArgs args)
        {
            //Initialize image loader with canvas
            //TODO: The image manager may fail for multiple frames
            ImageManager.Initialize(sender);

            //Initialize game systems
            drawIndex    = new DrawableIndex();
            collisions   = new CollisionManager();
            gameObjects  = new GameObjectIndex(drawIndex, collisions);
            inputManager = new InputManager();
            players      = new PlayerRegistry();

            //Load the required images
            ImageManager.LoadImages(PacmanImagePaths.Images);

            //Register key event listeners
            Window.Current.CoreWindow.KeyDown += canvas_KeyDown;
            Window.Current.CoreWindow.KeyUp   += canvas_KeyUp;


            //Create a player
            player = new PlayerGameObject(new Vector2(200, 300), gameObjects, players, inputManager, KeyboardFormat.WASD);
            gameObjects.registerGameObject(player);


            //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
            inputManager.registerInputSource(new PlayerKeyboardInputSource(testingObject, KeyboardFormat.ARROWS));

            //Enable debug drawing
            drawIndex.SetDebugDrawing(true);

            //Add a wall
            WallGameObject wall = new WallGameObject(new Vector2(100, 100), new Vector2(150, 200));

            gameObjects.registerGameObject(wall);
            WallGameObject wall2 = new WallGameObject(new Vector2(150, 200), new Vector2(350, 250));

            gameObjects.registerGameObject(wall2);
            WallGameObject wall3 = new WallGameObject(new Vector2(300, 100), new Vector2(350, 200));

            gameObjects.registerGameObject(wall3);

            //Add an enemy object
            EnemyGameObject enemy = new EnemyGameObject(new Vector2(300, 300), gameObjects, new Random());

            enemy.Target = player;
            gameObjects.registerGameObject(enemy);
        }
Ejemplo n.º 2
0
        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);*/
        }