示例#1
0
        private void createPlayerMeAndTransformIt(int id)
        {
            PlayerOther playerOther = (PlayerOther)TheGame.Instance.gameObjects.GetById(id);

            PlayerMe playerMe = new PlayerMe(playerOther.getPos(),
                                             new Microsoft.Xna.Framework.Vector2(playerOther.getCollisionRectangle().Width, playerOther.getCollisionRectangle().Height));


            //delete it first? meh! i think it works.

            TheGame.Instance.playerMe        = playerMe;
            TheGame.Instance.gameObjects[id] = playerMe;
        }
        //player
        //other else


        /*
         * public static GameObject GetGameObject<T>(int posX, int posY, int dimensionX, int dimensionY) where T: GameObject, new()
         * {
         *  return new T(
         *      new Vector2(posX, posY),
         *      new Vector2(dimensionX, dimensionX));
         * }
         */


        public static GameObject get(JSON.GameObject gameObject)
        {
            GameObject toReturn = null;

            switch (gameObject.GameObjectType)
            {
            case "Player":
                toReturn = new PlayerOther(new Vector2(gameObject.posX, gameObject.posY), new Vector2(gameObject.dimensionX, gameObject.dimensionX));
                break;

            case "PlayerMe":
                toReturn = new PlayerMe(new Vector2(gameObject.posX, gameObject.posY), new Vector2(gameObject.dimensionX, gameObject.dimensionX));
                break;

            case "Bullet":
                toReturn = new Bullet(new Vector2(gameObject.posX, gameObject.posY), new Vector2(gameObject.dimensionX, gameObject.dimensionX));
                break;

            case "Gun":
                toReturn = new Gun(new Vector2(gameObject.posX, gameObject.posY), new Vector2(gameObject.dimensionX, gameObject.dimensionX));
                break;

            case "Guy":
                toReturn = new Guy(new Vector2(gameObject.posX, gameObject.posY), new Vector2(gameObject.dimensionX, gameObject.dimensionX));
                break;

            case "GoodDoor":
                toReturn = new GoodDoor(new Vector2(gameObject.posX, gameObject.posY), new Vector2(gameObject.dimensionX, gameObject.dimensionX));
                break;

            case "BadDoor":
                toReturn = new BadDoor(new Vector2(gameObject.posX, gameObject.posY), new Vector2(gameObject.dimensionX, gameObject.dimensionX));
                break;

            case "Door":
                toReturn = new Door(new Vector2(gameObject.posX, gameObject.posY), new Vector2(gameObject.dimensionX, gameObject.dimensionX));
                break;

            case "ChoiceDoor":
                toReturn = new ChoiceDoor(new Vector2(gameObject.posX, gameObject.posY), new Vector2(gameObject.dimensionX, gameObject.dimensionX));
                break;

            case "Switch":
                toReturn = new Switch(new Vector2(gameObject.posX, gameObject.posY), new Vector2(gameObject.dimensionX, gameObject.dimensionX));
                break;

            case "Block":
                toReturn = new Block(new Vector2(gameObject.posX, gameObject.posY), new Vector2(gameObject.dimensionX, gameObject.dimensionX));
                break;

            case "Key":
                toReturn = new Key(new Vector2(gameObject.posX, gameObject.posY), new Vector2(gameObject.dimensionX, gameObject.dimensionX));
                break;

            case "Platform":
                toReturn = new Platform(new Vector2(gameObject.posX, gameObject.posY), new Vector2(gameObject.dimensionX, gameObject.dimensionX));
                break;


            default:
                break;
            }

            return(toReturn);
        }