//On collision
        public override void OnCollision(ICollisionEventHandler otherCollisionHandler, ICollider otherCollider)
        {
            //Attempt to match other object as a wall
            WallGameObject wall = otherCollisionHandler as WallGameObject;

            //Attempt to match other object as a wall
            BulletGameObject bullet = otherCollisionHandler as BulletGameObject;

            //If the other object is a wall
            if (wall != null)
            {
                //Get collider
                BoxCollider wallBoxCollider = otherCollider as BoxCollider;

                //Move out of it's range
                GameObjectHelper.resolveRectangularCollision(this, wallBoxCollider);

                //Choose another action
                PickRandomAction();
            }

            //If the other object is a bullet
            if (bullet != null)
            {
                //If the other object is a player bullet
                if (bullet.Name == "player_bullet")
                {
                    //Destroy the bullet
                    bullet.Destroy();

                    //Destroy this object
                    Destroy();
                }
            }
        }
        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);
        }
        //On collision with a game object
        public override void OnCollision(ICollisionEventHandler otherCollisionHandler, ICollider otherCollider)
        {
            //Attempt to match other object as a wall
            WallGameObject wall = otherCollisionHandler as WallGameObject;

            //If the other object is a wall
            if (wall != null)
            {
                //Destroy this bullet
                Destroy();
            }
        }
Exemple #4
0
        //On collision
        public override void OnCollision(ICollisionEventHandler otherCollisionHandler, ICollider otherCollider)
        {
            //Attempt to match other object as a wall
            WallGameObject wall = otherCollisionHandler as WallGameObject;

            //Attempt to match other object as a wall
            BulletGameObject bullet = otherCollisionHandler as BulletGameObject;

            //Attempt to match other object as an enemy
            EnemyGameObject enemy = otherCollisionHandler as EnemyGameObject;

            //If the other object is a wall
            if (wall != null)
            {
                //Get collider
                BoxCollider wallBoxCollider = otherCollider as BoxCollider;

                //Move out of it's range
                GameObjectHelper.resolveRectangularCollision(this, wallBoxCollider);
            }

            //If the other object is a bullet
            if (bullet != null)
            {
                //If the other object is an enemy bullet
                if (bullet.Name == "enemy_bullet")
                {
                    //Destroy the bullet
                    bullet.Destroy();

                    //Destroy this object
                    Destroy();
                }
            }

            //If the other object is an enemy
            if (enemy != null)
            {
                //If the other object is an enemy bullet
                if (enemy.Name == "enemy")
                {
                    //Destroy this object
                    Destroy();
                }
            }
        }
Exemple #5
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);*/
        }
Exemple #6
0
 internal void addWall(WallGameObject horizontalWallGameObject)
 {
     walls.Add(horizontalWallGameObject);
 }