Ejemplo n.º 1
0
 public void ResetPos()
 {
     while (GamePlay.Collided(this, 0, LastDir))
     {
         int rand = Globals.gen.Next(0, 5);
         if (rand == 0)
         {
             OffSet.X += 1;
         }
         else if (rand == 1)
         {
             OffSet.X -= 1;
         }
         else if (rand == 2)
         {
             OffSet.Y += 1;
         }
         else
         {
             OffSet.Y -= 1;
         }
         SetPos();
     }
     Game.SetScreenByPlayerPos();
 }
Ejemplo n.º 2
0
 public void SetPos()
 {
     if (OffSet.X >= Globals.TileSize)
     {
         CurPos.X += 1;
         OffSet.X  = 0;
     }
     if (OffSet.X <= -Globals.TileSize)
     {
         CurPos.X -= 1;
         OffSet.X  = 0;
     }
     if (OffSet.Y >= Globals.TileSize)
     {
         CurPos.Y += 1;
         OffSet.Y  = 0;
     }
     if (OffSet.Y <= -Globals.TileSize)
     {
         CurPos.Y -= 1;
         OffSet.Y  = 0;
     }
     if (this == Game.Player)
     {
         Game.SetScreenByPlayerPos();
     }
 }
Ejemplo n.º 3
0
        public static void StartGame(bool StartAsEditor = false)
        {
            if (StartAsEditor)
            {
                Player = new Character();
            }

            worldscreen = new WorldScreen();
            ScreenManager.AddScreen(worldscreen);
            if (!StartAsEditor)
            {
                ScreenManager.AddScreen(new SceneScreen(DataHandler.LoadScreneByName("StartScene")));
            }
            MapHandler.LoadMap("StartMap");
            Player.CurPos.X = 14;
            Player.CurPos.Y = 35;
            Player.OffSet   = new Point(0, 0);
            Game.SetScreenByPlayerPos();

            CharType.SetSkill(Player);

            ItemButtons.Add(Key.Z, new iRestoreHP(Player));
            ItemButtons.Add(Key.X, new iRestoreMP(Player));
            ItemButtons.First().Value.Count = 10;
            ItemButtons.Last().Value.Count = 5;

            Globals.InitializeFlags();
            Globals.Money = 50000;

            //BGM.PlayBGM(Globals.GameDir + "\\Content\\BGM\\Departure.mp3");
            InGame = true;
        }
        public override void Update()
        {
            if (!Game.InGame)
            {
                return;
            }

            //Update label Map's Name
            if (!MapName.Visible)
            {
                MapName.Visible = true;
            }
            if (ShowMapNameCounter < ShowMapNameTime)
            {
                ShowMapNameCounter += Game.ElapsedGameTime;
                if (ShowMapNameCounter >= ShowMapNameTime)
                {
                    ShowMapNameCounter = 0;
                    ShowMapNameTime    = 0;
                    UPorDOWN           = 1;
                    MapName.Location   = new Point(MapName.Location.X, -MapName.Height - 2);
                }
                MapNameMoveCounter += Game.ElapsedGameTime;
                if (MapNameMoveCounter >= MapNameMoveInterval)
                {
                    MapNameMoveCounter = 0;
                    MapName.Location   = new Point(MapName.Location.X, MapName.Location.Y + UPorDOWN * (MapName.Height + 20) * MapNameMoveInterval / 1000);
                    if (MapName.Location.Y >= 20)
                    {
                        if (ShowMapNameCounter >= ShowMapNameTime - 2000)
                        {
                            UPorDOWN = -1;
                        }
                        else
                        {
                            UPorDOWN = 0;
                        }
                    }
                }
            }

            //Update tọa độ của Screen theo tọa độ của Player
            if (Game.EditorMode)
            {
                Globals.Editor.DoMouseIsDown();
                Game.Move();
                Game.Player.CurPos.X = Game.ScreenX + Game.PlayerInScreen.X;
                Game.Player.CurPos.Y = Game.ScreenY + Game.PlayerInScreen.Y;
                Game.Player.OffSet.X = Game.ScreenOffsetX;
                Game.Player.OffSet.Y = Game.ScreenOffsetY;
            }
            else
            {
                if (Active)
                {
                    Game.Player.Move();
                }
                Game.SetScreenByPlayerPos();
            }

            //Update Skills
            SkillManager.Update();

            if (Game.World != null)
            {
                //Update arts của skills
                for (int i = 0; i < Game.World.BeforeCharArts.Count; i += 1)
                {
                    if (Game.World.BeforeCharArts[i].remove)
                    {
                        Game.World.BeforeCharArts.RemoveAt(i);
                        i -= 1;
                    }
                    else
                    {
                        Game.World.BeforeCharArts[i].Update();
                    }
                }
                for (int i = 0; i < Game.World.AfterCharArts.Count; i += 1)
                {
                    if (Game.World.AfterCharArts[i].remove)
                    {
                        Game.World.AfterCharArts.RemoveAt(i);
                        i -= 1;
                    }
                    else
                    {
                        Game.World.AfterCharArts[i].Update();
                    }
                }

                //Update Missile trong map
                for (int i = 0; i <= Game.World.MissileList.Count - 1; i += 1)
                {
                    if (Game.World.MissileList[i].remove)
                    {
                        Game.World.MissileList.RemoveAt(i);
                        i -= 1;
                    }
                    else
                    {
                        Game.World.MissileList[i].Update();
                    }
                }

                //Update Item
                Item.UpdateList();

                //Chạy hàm Act của quái, trừ khi là đang trong Map Editor
                if (Game.EditorMode == false)
                {
                    foreach (Character c in Game.World.MapChar)
                    {
                        c.Act();
                    }
                }

                //Remove những char trong diedChar ra khỏi MapChar
                foreach (Character c in Game.World.DiedChar)
                {
                    Game.World.MapChar.Remove(c);
                }
                Game.World.DiedChar.Clear();

                //Add char mới vào MapChar
                foreach (Character c in Game.World.NewChar)
                {
                    Game.World.MapChar.Add(c);
                }
                Game.World.NewChar.Clear();
            }
        }