Beispiel #1
0
        public Player(LunchHourGames lhg, String templateName, String displayName, Player.Type type, bool isComputerControlled, PlayerSprite sprite)
            : base(lhg, EntityType.Player, templateName, displayName)
        {
            this.templateName         = templateName;
            this.type                 = type;
            this.isComputerControlled = isComputerControlled;
            this.isActive             = true;
            this.sprite               = sprite;
            this.roll                 = -1; // indicate that a roll has not taken place
            this.walkingSpeed         = 1.0f;

            this.idNumber    = random.Next(10, 1000);
            this.isIdVisible = false;

            this.attributes = new DerivedAttributes();
        }
        private Player createQuickCopy(Player cachedPlayer)
        {
            PlayerSprite sprite = cachedPlayer.MySprite.copy();

            Player player = null;

            // create a new instance of this player
            if (cachedPlayer.MyType == Player.Type.Human)
            {
                player = new Human(lhg, cachedPlayer.MyTemplateName, cachedPlayer.MyName, sprite);
            }
            else if (cachedPlayer.MyType == Player.Type.Zombie)
            {
                player = new Zombie(lhg, cachedPlayer.MyTemplateName, cachedPlayer.MyName, sprite);
            }

            player.MyHUDSprite = cachedPlayer.MyHUDSprite;
            if (cachedPlayer.MyInventory != null)
            {
                player.MyInventory = cachedPlayer.MyInventory.copy();
            }
            return(player);
        }
Beispiel #3
0
 public Zombie(LunchHourGames lhg, String templateName, String name, PlayerSprite sprite)
     : base(lhg, templateName, name, Type.Zombie, true, sprite)
 {
 }
Beispiel #4
0
 public Human(LunchHourGames lhg, String templateName, String name, PlayerSprite sprite)
     : base(lhg, templateName, name, Type.Human, false, sprite)
 {
     this.stats  = new PrimaryStatistics();
     this.skills = new Skills();
 }
        private Player createPlayerFromTemplate(string referenceName)
        {
            Player player = null;

            if (playersDocument == null)
            {
                this.playersDocument = new XmlDocument();
                playersDocument.Load("Content/Xml/players.xml");
            }

            // Check to see if the player template is in our cache already.
            Player cachedPlayer = lhg.Assets.findPlayerTemplateInCache(referenceName);

            if (cachedPlayer != null)
            {
                progress.updateProgress("Loading player template " + referenceName + " from cache", "Loading", 0);
                return(createQuickCopy(cachedPlayer));
            }
            else
            {
                progress.updateProgress("Loading player template " + referenceName + " from disk", "Loading", 0);
                string  xpath      = "/players/player[@referenceName='" + referenceName + "']";
                XmlNode playerNode = playersDocument.SelectSingleNode(xpath);
                if (playerNode != null)
                {
                    PrimaryStatistics stats = null;

                    List <PlayerSpriteSheet> playerSpriteSheetList = null;
                    StaticSprite             hudSprite             = null;
                    InventoryStorage         inventoryStorage      = null;
                    Player.Type type           = Player.getTypeFromString(playerNode.Attributes["type"].Value);
                    XmlNodeList playerChildren = playerNode.ChildNodes;
                    foreach (XmlNode childNode in playerChildren)
                    {
                        switch (childNode.Name)
                        {
                        case "stats":
                            stats = loadStats(childNode);
                            break;

                        case "hud":
                            hudSprite = loadCombatHUDSprite(childNode);
                            break;

                        case "animations":
                            playerSpriteSheetList = loadAnimations(childNode);
                            break;

                        case "inventory":
                            inventoryStorage = loadInventory(childNode);
                            break;
                        }
                    }

                    PlayerSprite playerSprite = new PlayerSprite(lhg, playerSpriteSheetList, PlayerSpriteSheet.Type.Standing);

                    // Create a player for our cache that won't change, so we can quickly create copies
                    if (type == Player.Type.Human)
                    {
                        cachedPlayer = new Human(lhg, referenceName, referenceName, playerSprite);
                    }
                    else if (type == Player.Type.Zombie)
                    {
                        cachedPlayer = new Zombie(lhg, referenceName, referenceName, playerSprite);
                    }

                    cachedPlayer.MyHUDSprite = hudSprite;
                    cachedPlayer.MyInventory = inventoryStorage;
                    lhg.Assets.addPlayerTemplate(cachedPlayer);

                    // Now, create a copy we will use as the real instance
                    player = createQuickCopy(cachedPlayer);
                }
            }

            return(player);
        }