Example #1
0
        public void LoadGameData()
        {
            try
            {
                countdowneffect = new PreRenderEffect("number", 64, 64);
                countdowneffect.Initialize(GameConst.Content);
                countdowneffect.Loop = false;
                countdowneffect.Scene = this;
                countdowneffect.CoordinateSystem = RenderChunk.CoordinateSystemType.Screen;
                countdowneffect.PlaySpeed = 1.0f;

                using(System.IO.Stream stream = TitleContainer.OpenStream(name + ".xml"))
                {
                XDocument doc = XDocument.Load(stream);
                XElement defelement = doc.Element("SceneDef");
                if (defelement != null)
                {
                    XElement configelement = defelement.Element("Config");
                    if (configelement != null)
                    {
                        if (configelement.Element("FixedEnemyNum") != null)
                        {
                            GameConst.FixedEnemyNum = int.Parse(configelement.Element("FixedEnemyNum").Value);
                        }
                        if (configelement.Element("PlayerSpeed") != null)
                        {
                            GameConst.PlayerSpeed = int.Parse(configelement.Element("PlayerSpeed").Value);
                        }
                        if (configelement.Element("PlayerHP") != null)
                        {
                            GameConst.PlayerHP = int.Parse(configelement.Element("PlayerHP").Value);
                        }
                        if (configelement.Element("PlayerATK") != null)
                        {
                            GameConst.PlayerAtk = int.Parse(configelement.Element("PlayerATK").Value);
                        }
                        if (configelement.Element("BossRushMode") != null)
                        {
                            GameConst.BossRushMode = int.Parse(configelement.Element("BossRushMode").Value);
                        }
                        if (configelement.Element("BossRushMode1Offset") != null)
                        {
                            GameConst.BossRushMode1Offset = int.Parse(configelement.Element("BossRushMode1Offset").Value);
                        }
                        if (configelement.Element("ViewportScrollRange") != null)
                        {
                            GameConst.ViewportScrollRange = float.Parse(configelement.Element("ViewportScrollRange").Value);
                        }
                        if (configelement.Element("ViewportScrollResetTime") != null)
                        {
                            GameConst.ViewportScrollResetTime = float.Parse(configelement.Element("ViewportScrollResetTime").Value);
                        }
                    }
                    foreach (XElement element in defelement.Elements("NpcDef"))
                    {
                        XElement npcelement = element.Element("Npc");
                        if (npcelement != null)
                        {
                            string npcname = "";
                            float x = 0;
                            float y = 0;
                            int hp = 0;
                            float speed = 0;
                            string pic = "";
                            int layer = 0;
                            bool visible = true;
                            List<string> quests = new List<string>();

                            if (npcelement.Element("Name") != null)
                            {
                                npcname = npcelement.Element("Name").Value;
                            }
                            if (npcelement.Element("HP") != null)
                            {
                                hp = int.Parse(npcelement.Element("HP").Value);
                            }
                            if (npcelement.Element("ScreenX") != null)
                            {
                                x = int.Parse(npcelement.Element("ScreenX").Value);
                            }
                            if (npcelement.Element("ScreenY") != null)
                            {
                                y = int.Parse(npcelement.Element("ScreenY").Value);
                            }
                            if (npcelement.Element("Speed") != null)
                            {
                                speed = int.Parse(npcelement.Element("Speed").Value);
                            }
                            if (npcelement.Element("Picture") != null)
                            {
                                pic = npcelement.Element("Picture").Value;
                            }
                            if (npcelement.Element("Layer") != null)
                            {
                                layer = int.Parse(npcelement.Element("Layer").Value);
                            }
                            if (npcelement.Element("Quest") != null)
                            {
                                //layer = int.Parse(npcelement.Element("Layer").Value);
                                foreach (XElement qelement in npcelement.Elements("Quest").Elements())
                                {
                                    quests.Add(qelement.Name.LocalName);
                                }
                            }
                            if (npcelement.Element("Visible") != null)
                            {
                                visible = bool.Parse(npcelement.Element("Visible").Value);
                            }

                            Npc npc = new Npc(npcname, this);
                            CharacterDefinition.PicDef pd = GameConst.Content.Load<CharacterDefinition.PicDef>(@"chardef/" + pic);
                            CharacterPic cpic = new CharacterPic(pd, layer);
                            npc.Picture = cpic;

                            CharacterTitle title = new CharacterTitle(GameConst.CurrentFont);
                            title.NameString = npcname;
                            title.Layer = layer;
                            title.Character = npc;

                            npc.Position = new Vector2(x, y);
                            npc.HP = hp;

                            npc.State = CharacterState.Idle;
                            npc.Speed = speed;
                            npc.Title = title;
                            npc.Picture.State = visible ? RenderChunk.RenderChunkState.Show : RenderChunk.RenderChunkState.Invisible;
                            npc.Title.State = visible ? RenderChunk.RenderChunkState.Show : RenderChunk.RenderChunkState.Invisible;
                            foreach (string qn in quests)
                            {
                                npc.AddQuest(qn);
                            }
                            AddCharacter(npc);
                            //npc.
                        }
                    }

                    foreach (XElement element in defelement.Elements("HoverStoneDef"))
                    {
                        XElement stoneelement = element.Element("HoverStone");
                        if (stoneelement != null)
                        {
                            HoverStone hs = new HoverStone();
                            if (stoneelement.Element("Texture") != null)
                            {
                                hs.TextureFileName = stoneelement.Element("Texture").Value;
                                hs.Texture = GameConst.Content.Load<Texture2D>(@"stone/" + stoneelement.Element("Texture").Value);
                            }
                            if (stoneelement.Element("Position") != null)
                            {
                                float x = 0, y = 0;
                                if (stoneelement.Element("Position").Element("X") != null)
                                {
                                    x = float.Parse(stoneelement.Element("Position").Element("X").Value);
                                }
                                if (stoneelement.Element("Position").Element("Y") != null)
                                {
                                    y = float.Parse(stoneelement.Element("Position").Element("Y").Value);
                                }

                                hs.Position = new Vector2(x, y);
                            }
                            if (stoneelement.Element("Layer") != null)
                            {
                                hs.Layer = int.Parse(stoneelement.Element("Layer").Value);
                            }
                            if (stoneelement.Element("Size") != null)
                            {
                                float x = 0, y = 0;
                                if (stoneelement.Element("Size").Element("X") != null)
                                {
                                    x = float.Parse(stoneelement.Element("Size").Element("X").Value);
                                }
                                if (stoneelement.Element("Size").Element("Y") != null)
                                {
                                    y = float.Parse(stoneelement.Element("Size").Element("Y").Value);
                                }

                                hs.Size = new Vector2(x, y);
                            }
                            if (stoneelement.Element("Range") != null)
                            {
                                hs.AMP = float.Parse(stoneelement.Element("Range").Value);
                            }
                            if (stoneelement.Element("CycleTime") != null)
                            {
                                hs.TimeOfCycle = float.Parse(stoneelement.Element("CycleTime").Value);
                            }
                            AddRenderChunk(hs);
                        }
                    }
                }

               }
                //create task track
                UIDialog dialog = UIMgr.AddUIControl("UIDialog", "dlg_questtrck", /*755, 174,*/(int)UILayout.Right, (int)UILayout.Center, 247, 345, -1, 99, this) as UIDialog;
                if (dialog != null)
                {
                    UITextBlock text = UIMgr.CreateUIControl("UITextBlock") as UITextBlock;
                    if (text != null)
                    {
                        text.FontColor = Color.DarkGray;
                        dialog.AddUIControl(text, "text_questname", 18, 18, 211, 24, -1, this);
                    }
                    UITextBlock text1 = UIMgr.CreateUIControl("UITextBlock") as UITextBlock;
                    if (text1 != null)
                    {
                        text1.FontColor = Color.Gold;
                        dialog.AddUIControl(text1, "text_questtrack", 28, 50, 190, 24, -1, this);
                    }
                }
                dialog.State = RenderChunk.RenderChunkState.Hide;

            }
            catch (Exception e)
            {
                //MessageBox box;
                Debug.WriteLine(e.Message);
            }
        }
Example #2
0
 protected void addbtn_OnClick(object sender, MouseEventArgs e)
 {
     UITextButton btn = sender as UITextButton;
     btn.Parent.State = RenderChunk.RenderChunkState.FadeOutToDel;
     HoverStone hs = new HoverStone();
     hs.TextureFileName = "stone1";
     hs.Texture = GameConst.Content.Load<Texture2D>(@"stone/stone1");
     hs.Position = new Vector2(viewport.X + e.X, viewport.Y + e.Y);
     hs.Layer = Convert.ToInt32(random.Next(18,22));
     hs.Size = new Vector2(1, 1);
     hs.AMP = 10;
     hs.TimeOfCycle = 2;
     AddRenderChunk(hs);
 }