示例#1
0
    private void Start()
    {
        DataScript.LoadData();
        TextInfo.text += "\n" + SystemInfo.graphicsShaderLevel + "\n" + SystemInfo.graphicsMemorySize;
        if (PlayerPrefs.GetInt("Music") == 0)
        {
            Audio.GetComponent <Image>().sprite = ImageArr[0];
        }
        else
        {
            Audio.GetComponent <Image>().sprite = ImageArr[1];
        }
        if (s_Ranch[0] == true)
        {
            Ranch.SetActive(true);
        }
        int nameLvl = 1;

        for (int i = 0; i < 4; i++)
        {
            for (int j = 0; j < 4; j++)
            {
                Button but = Instantiate(LvlButton, new Vector2(-300 + (200 * j), 330 - (200 * i)),
                                         Quaternion.identity);
                but.gameObject.transform.SetParent(LvlButtons.transform, false);
                but.name = nameLvl.ToString();
                but.onClick.AddListener(delegate { StartGame(System.Convert.ToInt32(but.name)); });
                Text txt = but.GetComponentInChildren <Text>();
                if (PlayerPrefs.HasKey(nameLvl.ToString()))
                {
                    txt.text = $"{nameLvl}\n\n{PlayerPrefs.GetFloat(nameLvl.ToString()):f3}";
                }
                else
                {
                    if (nameLvl == 1 || PlayerPrefs.HasKey((nameLvl - 1).ToString()))
                    {
                        txt.text = $"{nameLvl}\n\n";
                    }
                    else
                    {
                        txt.text         = $"{nameLvl}\n\n";
                        but.interactable = false;
                    }
                }
                nameLvl++;
            }
        }
        try
        {
            s_Score             = PlayerPrefs.GetFloat("Score");
            s_Money             = PlayerPrefs.GetInt("Money");
            s_AdditionalDelay   = PlayerPrefs.GetFloat("Delay");
            s_AddtitionalChance = PlayerPrefs.GetInt("Chance");
        }
        catch { }
        if (!s_Score.Equals(0))
        {
            ScoreTxt.text = $"Best:{s_Score}";
        }
    }
示例#2
0
        public Ranch Login(string username, string password)
        {
            List <Ranch> ranches = rancheDAL.GetAll();
            Ranch        ranch   = ranches.FirstOrDefault(x => x.UserName == username && x.UserPassword == password);

            return(ranch);
        }
示例#3
0
        public IActionResult Index()
        {





            SingleFamily sf = new SingleFamily();
            HomeFactory homeFactory = new Homes.HomeFactory(sf);
            Home singleFamily=homeFactory.BuildTheHome();


            Ranch ranch = new Ranch();
            homeFactory = new HomeFactory(ranch);
            Home ranchHome = homeFactory.BuildTheHome();

            //Logger l = new Logger();
            //LoggerFactory lf = new LoggerFactory(l);
            //lf.NotifyLog("");
            //l.Number = 5;
            //var test = l.total;
            //l.Number = 4;
            //var t = l.total;

            return View();
        }
示例#4
0
 public void SetRanchData(Ranch ranch)
 {
     _ranch = ranch;
     if (ranch == null)
     {
         Icon.SetClip(RanchIcon.Type.Empty, 0);
         Window.SetText(string.Empty);
         CareButton.Lock();
     }
     else
     {
         Icon.SetClip(Function.GetId2RanchType(_ranch.id), _ranch.growth);
         if (_ranch.growth < 100)
         {
             Window.SetText(Function.SearchItemById(_ranch.id).name);
         }
         else
         {
             Window.SetText(Function.SearchItemById(_ranch.id).name +
                            "(" + HarvestItemName + ")");
         }
         if (_ranch.care)
         {
             CareButton.Lock();
         }
         else
         {
             CareButton.Unlock();
         }
     }
 }
示例#5
0
 public ActionResult AddRanch(Ranch ranch, HttpPostedFileBase File)
 {
     if (!new BLL.AdminController().AddRanch(ranch, new WebImage(File.InputStream).GetBytes()))
     {
         return(HttpNotFound());
     }
     return(RedirectToAction("Index", "Home"));
 }
示例#6
0
        public bool Login(string UserName, string UserPassword, bool RememberMe, string token)
        {
            BLL.LoginController loginController = new BLL.LoginController();
            Ranch rn = loginController.Login(UserName, UserPassword);

            if (rn == null)
            {
                return(false);
            }
            else
            {
                if (RememberMe)
                {
                    FormsAuthentication.SetAuthCookie(UserName, true);
                    CreateCookie("UserName", rn.UserName);
                    CreateCookie("UserPassword", rn.UserPassword);
                }
                else
                {
                    FormsAuthentication.SetAuthCookie(UserName, false);
                    DeleteCookie("UserName");
                    DeleteCookie("UserPassword");
                }

                Session.Add("Username", rn.UserName);
                Session.Add("Id", rn.ID);
                Session.Add("Name", rn.Name);
                Session.Add("Logo", rn.Logo);
                Session.Add("Role", rn.Role);
                if (token != null)
                {
                    new BLL.LoginController().RegisterToken(token, rn.ID);
                }
                return(true);
            }
        }
示例#7
0
 public int Delete(Ranch ranch)
 {
     db.Entry(ranch).State = EntityState.Deleted;
     return(db.SaveChanges());
 }
示例#8
0
 public int Update(Ranch ranch)
 {
     db.Entry(ranch).State = EntityState.Modified;
     return(db.SaveChanges());
 }
示例#9
0
 public int Add(Ranch ranch)
 {
     db.Entry(ranch).State = EntityState.Added;
     return(db.SaveChanges());
 }
示例#10
0
        public override void LoadContent()
        {
            base.LoadContent();

            // Load the compiled map
            _map = Content.Load <TiledMap>("maps/passage/screen");
            // Create the map renderer
            _mapRenderer = new TiledMapRenderer(GraphicsDevice, _map);

            foreach (var layer in _map.ObjectLayers)
            {
                if (layer.Name == "objects")
                {
                    foreach (var obj in layer.Objects)
                    {
                        if (obj.Type == "player_start")
                        {
                            if (obj.Name == "ranch-start" && _arrival == HarvestMoon.Arrival.Ranch)
                            {
                                var objectPosition = obj.Position;

                                objectPosition.X = obj.Position.X + obj.Size.Width * 0.5f;
                                objectPosition.Y = obj.Position.Y + obj.Size.Height * 0.5f;

                                _player = _entityManager.AddEntity(new Jack(Content, _entityManager, this, objectPosition));

                                _player.PlayerFacing = Jack.Facing.LEFT;
                            }
                            else if (obj.Name == "mountain-start" && _arrival == HarvestMoon.Arrival.Mountain)
                            {
                                var objectPosition = obj.Position;

                                objectPosition.X = obj.Position.X + obj.Size.Width * 0.5f;
                                objectPosition.Y = obj.Position.Y + obj.Size.Height * 0.5f;

                                _player = _entityManager.AddEntity(new Jack(Content, _entityManager, this, objectPosition));

                                _player.PlayerFacing = Jack.Facing.DOWN;
                            }
                            else if (obj.Name == "town-start" && _arrival == HarvestMoon.Arrival.Town)
                            {
                                var objectPosition = obj.Position;

                                objectPosition.X = obj.Position.X + obj.Size.Width * 0.5f;
                                objectPosition.Y = obj.Position.Y + obj.Size.Height * 0.5f;

                                _player = _entityManager.AddEntity(new Jack(Content, _entityManager, this, objectPosition));

                                _player.PlayerFacing = Jack.Facing.RIGHT;
                            }
                        }

                        if (obj.Type == "npc")
                        {
                            var objectPosition = obj.Position;

                            objectPosition.X = obj.Position.X + obj.Size.Width * 0.5f;
                            objectPosition.Y = obj.Position.Y + obj.Size.Height * 0.5f;

                            var objectSize = obj.Size;

                            var objectMessageKP = obj.Properties.First(p => p.Key.Contains("message"));

                            var objectMessage = HarvestMoon.Instance.Strings.Get(objectMessageKP.Value);

                            _entityManager.AddEntity(new BasicMessage(objectPosition, objectSize, objectMessage));
                        }
                    }
                }
                else if (layer.Name == "doors")
                {
                    foreach (var obj in layer.Objects)
                    {
                        if (obj.Type == "door")
                        {
                            var objectPosition = obj.Position;

                            objectPosition.X = obj.Position.X + obj.Size.Width * 0.5f;
                            objectPosition.Y = obj.Position.Y + obj.Size.Height * 0.5f;

                            var objectSize = obj.Size;

                            var door = new Door(objectPosition, objectSize);
                            _entityManager.AddEntity(door);

                            if (obj.Name == "ranch")
                            {
                                door.OnTriggerEnd(() =>
                                {
                                    if (!door.Triggered)
                                    {
                                        door.Triggered = true;
                                        var screen     = new Ranch(Game, HarvestMoon.Arrival.Passage);
                                        var transition = new FadeTransition(GraphicsDevice, Color.Black, 1.0f);
                                        ScreenManager.LoadScreen(screen, transition);
                                    }
                                });
                            }

                            if (obj.Name == "mountain")
                            {
                                door.OnTriggerEnd(() =>
                                {
                                    if (!door.Triggered)
                                    {
                                        door.Triggered = true;
                                        var screen     = new Mountain(Game, HarvestMoon.Arrival.Passage);
                                        var transition = new FadeTransition(GraphicsDevice, Color.Black, 1.0f);
                                        ScreenManager.LoadScreen(screen, transition);
                                    }
                                });
                            }

                            if (obj.Name == "town")
                            {
                                door.OnTriggerEnd(() =>
                                {
                                    if (!door.Triggered)
                                    {
                                        door.Triggered = true;
                                        var screen     = new Town(Game, HarvestMoon.Arrival.Passage);
                                        var transition = new FadeTransition(GraphicsDevice, Color.Black, 1.0f);
                                        ScreenManager.LoadScreen(screen, transition);
                                    }
                                });
                            }
                        }
                    }
                }
                else if (layer.Name == "walls")
                {
                    foreach (var obj in layer.Objects)
                    {
                        if (obj.Type == "wall")
                        {
                            var objectPosition = obj.Position;

                            objectPosition.X = obj.Position.X + obj.Size.Width * 0.5f;
                            objectPosition.Y = obj.Position.Y + obj.Size.Height * 0.5f;

                            var objectSize = obj.Size;

                            _entityManager.AddEntity(new Wall(objectPosition, objectSize));
                        }
                    }
                }
            }
        }
示例#11
0
 public bool AddRanch(Ranch ranch, byte[] image)
 {
     ranch.Logo = image;
     ranch.Role = false;
     return(ranchDAL.Add(ranch) > 0);
 }
示例#12
0
        public override void LoadContent()
        {
            base.LoadContent();


            if (MediaPlayer.State == MediaState.Stopped)
            {
                var song = Content.Load <Song>("audio/music/spring");

                MediaPlayer.Play(song);
                MediaPlayer.IsRepeating = true;
            }


            if (_arrival == HarvestMoon.Arrival.Diary)
            {
                HarvestMoon.Instance.LoadGameState(HarvestMoon.Instance.Diary);
            }


            // Load the compiled map
            _map = Content.Load <TiledMap>("maps/House");
            // Create the map renderer
            _mapRenderer = new TiledMapRenderer(GraphicsDevice, _map);

            foreach (var layer in _map.ObjectLayers)
            {
                if (layer.Name == "Arrivals")
                {
                    foreach (var obj in layer.Objects)
                    {
                        if (obj.Name == "from-ranch" && _arrival == HarvestMoon.Arrival.Ranch)
                        {
                            var objectPosition = obj.Position;

                            objectPosition.X = obj.Position.X + obj.Size.Width * 0.5f;
                            objectPosition.Y = obj.Position.Y + obj.Size.Height * 0.5f;

                            _player = HarvestMoon.Instance.RanchState.Entities.FirstOrDefault(e => e is Jack) as Jack;

                            if (_player == null)
                            {
                                _player = _entityManager.AddEntity(new Jack(Content, _entityManager, this, objectPosition));
                            }
                            else
                            {
                                _entityManager.AddEntity(_player);
                                _player.EntityManager = _entityManager;
                            }


                            _player.Position = new Vector2(objectPosition.X, objectPosition.Y);

                            _player.PlayerFacing = Jack.Facing.UP;
                        }
                        else if (obj.Name == "from-diary" && (_arrival == HarvestMoon.Arrival.Wake || _arrival == HarvestMoon.Arrival.Diary))
                        {
                            var objectPosition = obj.Position;

                            objectPosition.X = obj.Position.X + obj.Size.Width * 0.5f;
                            objectPosition.Y = obj.Position.Y + obj.Size.Height * 0.5f;

                            _player = _entityManager.AddEntity(new Jack(Content, _entityManager, this, objectPosition));
                            _player.PlayerFacing = Jack.Facing.DOWN;

                            HarvestMoon.Instance.ResetDayTime();
                        }
                        else if (obj.Name == "from-tools" && _arrival == HarvestMoon.Arrival.Tools)
                        {
                            var objectPosition = obj.Position;

                            objectPosition.X = obj.Position.X + obj.Size.Width * 0.5f;
                            objectPosition.Y = obj.Position.Y + obj.Size.Height * 0.5f;

                            _player = HarvestMoon.Instance.RanchState.Entities.FirstOrDefault(e => e is Jack) as Jack;

                            if (_player == null)
                            {
                                _player = _entityManager.AddEntity(new Jack(Content, _entityManager, this, objectPosition));
                            }
                            else
                            {
                                _entityManager.AddEntity(_player);
                                _player.EntityManager = _entityManager;
                            }

                            _player.Position = new Vector2(objectPosition.X, objectPosition.Y);

                            _player.PlayerFacing = Jack.Facing.LEFT;
                        }
                    }
                }
                else if (layer.Name == "Interactables")
                {
                    foreach (var obj in layer.Objects)
                    {
                        if (obj.Type == "npc")
                        {
                            var objectPosition = obj.Position;

                            objectPosition.X = obj.Position.X + obj.Size.Width * 0.5f;
                            objectPosition.Y = obj.Position.Y + obj.Size.Height * 0.5f;

                            var objectSize = obj.Size;

                            var objectMessageKP = obj.Properties.First(p => p.Key.Contains("message"));

                            var objectMessage = HarvestMoon.Instance.Strings.Get(objectMessageKP.Value);

                            var yes = HarvestMoon.Instance.Strings.Get("STR_YES");
                            var no  = HarvestMoon.Instance.Strings.Get("STR_NO");

                            if (obj.Name == "diary")
                            {
                                _entityManager.AddEntity(new YesNoMessage(objectPosition,
                                                                          objectSize,
                                                                          objectMessage,
                                                                          new List <string>()
                                {
                                    yes, no
                                },
                                                                          new List <Action>()
                                {
                                    () => {
                                        HarvestMoon.Instance.ResetDay();
                                        HarvestMoon.Instance.IncrementDay();
                                        HarvestMoon.Instance.SaveGameState(HarvestMoon.Instance.Diary);

                                        var screen     = new House(Game, HarvestMoon.Arrival.Wake);
                                        var transition = new FadeTransition(GraphicsDevice, Color.Black, 2.0f);
                                        ScreenManager.LoadScreen(screen, transition);
                                    },
                                    () => {
                                        /*ShowYesNoMessage("I'm going to bed.",
                                         *               "Oh, I've got something to do.",
                                         *              () =>
                                         *              {
                                         *                  HarvestMoon.Instance.ResetDay();
                                         *                  HarvestMoon.Instance.IncrementDay();
                                         *                  var screen = new House(Game, HarvestMoon.Arrival.Wake);
                                         *                  var transition = new FadeTransition(GraphicsDevice, Color.Black, 2.0f);
                                         *                  ScreenManager.LoadScreen(screen, transition);
                                         *
                                         *              },
                                         *              () =>
                                         *              {
                                         *              });*/
                                    }
                                }));
                            }
                            else if (obj.Name == "calendar")
                            {
                                var replacedDayName   = objectMessage.Replace("day", HarvestMoon.Instance.DayName);
                                var replacedDayNumber = replacedDayName.Replace("number", HarvestMoon.Instance.DayNumber.ToString());
                                var replacedSeason    = replacedDayNumber.Replace("season", HarvestMoon.Instance.Season);

                                _entityManager.AddEntity(new BasicMessage(objectPosition, objectSize, replacedSeason));
                            }
                            else
                            {
                                _entityManager.AddEntity(new BasicMessage(objectPosition, objectSize, objectMessage));
                            }
                        }
                    }
                }
                else if (layer.Name == "Doors")
                {
                    foreach (var obj in layer.Objects)
                    {
                        var objectPosition = obj.Position;

                        objectPosition.X = obj.Position.X + obj.Size.Width * 0.5f;
                        objectPosition.Y = obj.Position.Y + obj.Size.Height * 0.5f;

                        var objectSize = obj.Size;

                        var door = new Door(objectPosition, objectSize);
                        _entityManager.AddEntity(door);

                        door.OnTriggerStart(() =>
                        {
                            _player.Freeze();
                        });

                        if (obj.Name == "ranch")
                        {
                            door.OnTriggerEnd(() =>
                            {
                                if (!door.Triggered)
                                {
                                    door.Triggered = true;
                                    var screen     = new Ranch(Game, HarvestMoon.Arrival.House);
                                    var transition = new FadeTransition(GraphicsDevice, Color.Black, 1.0f);
                                    ScreenManager.LoadScreen(screen, transition);
                                }
                            });
                        }
                        else if (obj.Name == "tools")
                        {
                            door.OnTriggerEnd(() =>
                            {
                                if (!door.Triggered)
                                {
                                    door.Triggered = true;
                                    var screen     = new ToolsRoom(Game);
                                    var transition = new FadeTransition(GraphicsDevice, Color.Black, 1.0f);
                                    ScreenManager.LoadScreen(screen, transition);
                                }
                            });
                        }
                    }
                }
                else if (layer.Name == "Walls")
                {
                    foreach (var obj in layer.Objects)
                    {
                        var objectPosition = obj.Position;

                        objectPosition.X = obj.Position.X + obj.Size.Width * 0.5f;
                        objectPosition.Y = obj.Position.Y + obj.Size.Height * 0.5f;

                        var objectSize = obj.Size;

                        _entityManager.AddEntity(new Wall(objectPosition, objectSize));
                    }
                }
            }

            LoadPlayer();


            if (_arrival != HarvestMoon.Arrival.Ranch)
            {
                HarvestMoon.Instance.Stamina = HarvestMoon.Instance.MaxStamina;

                HarvestMoon.Instance.Gold     += HarvestMoon.Instance.TodayGold;
                HarvestMoon.Instance.TodayGold = 0;

                var soilSegments = HarvestMoon.Instance.RanchState.Entities.Where(e => e is Soil).Cast <Soil>().ToArray();

                foreach (var soilSegment in soilSegments)
                {
                    soilSegment.GrowAccordingly();
                    soilSegment.Dry();
                }

                for (int i = 0; i < HarvestMoon.Instance.CowAliveList.Count; ++i)
                {
                    bool fed = HarvestMoon.Instance.CowFooderList[i];

                    if (!fed)
                    {
                        if (HarvestMoon.Instance.CowAliveList[i])
                        {
                            HarvestMoon.Instance.CowStarvingList[i] += 1;
                        }
                    }
                    else
                    {
                        HarvestMoon.Instance.CowStarvingList[i] = 0;
                        HarvestMoon.Instance.CowFooderList[i]   = false;
                    }

                    if (HarvestMoon.Instance.CowStarvingList[i] >= 5)
                    {
                        HarvestMoon.Instance.CowStarvingList[i] = 0;
                        HarvestMoon.Instance.CowAliveList[i]    = false;

                        string toRemove = "";

                        foreach (var kvp in HarvestMoon.Instance.CowNameIndexDictionary)
                        {
                            if (kvp.Value == i)
                            {
                                toRemove = kvp.Key;
                                break;
                            }
                        }

                        HarvestMoon.Instance.CowNameIndexDictionary.Remove(toRemove);

                        //@TODO display cow starved to death message here
                        HarvestMoon.Instance.GUI.ShowMessage("Some of the cows passed away.",
                                                             () => { _player.Freeze(); _player.Busy(); }, () => {
                            _player.UnFreeze();
                            _player.Cooldown();
                        });
                    }
                }
            }
        }
示例#13
0
文件: User.cs 项目: Illya9999/HISP
        public User(GameClient baseClient, int UserId)
        {
            if (!Database.CheckUserExist(UserId))
            {
                throw new KeyNotFoundException("User " + UserId + " not found in database!");
            }

            if (!Database.CheckUserExtExists(UserId))
            {
                Database.CreateUserExt(UserId);
                NewPlayer = true;
            }


            EquipedCompetitionGear = new CompetitionGear(UserId);
            EquipedJewelry         = new Jewelry(UserId);

            Id       = UserId;
            Username = Database.GetUsername(UserId);

            Administrator = Database.CheckUserIsAdmin(Username);
            Moderator     = Database.CheckUserIsModerator(Username);

            chatViolations = Database.GetChatViolations(UserId);
            x      = Database.GetPlayerX(UserId);
            y      = Database.GetPlayerY(UserId);
            charId = Database.GetPlayerCharId(UserId);

            Facing          = PacketBuilder.DIRECTION_DOWN;
            experience      = Database.GetExperience(UserId);
            money           = Database.GetPlayerMoney(UserId);
            bankMoney       = Database.GetPlayerBankMoney(UserId);
            questPoints     = Database.GetPlayerQuestPoints(UserId);
            subscribed      = Database.IsUserSubscribed(UserId);
            subscribedUntil = Database.GetUserSubscriptionExpireDate(UserId);
            profilePage     = Database.GetPlayerProfile(UserId);
            privateNotes    = Database.GetPlayerNotes(UserId);
            hunger          = Database.GetPlayerHunger(UserId);
            thirst          = Database.GetPlayerThirst(UserId);
            tired           = Database.GetPlayerTiredness(UserId);

            if (Ranch.IsRanchOwned(this.Id))
            {
                if (this.Subscribed)
                {
                    OwnedRanch = Ranch.GetRanchOwnedBy(this.Id);
                }
                else // idk what it does here ...
                {
                    OwnedRanch = null;
                    Ranch.GetRanchOwnedBy(this.Id).OwnerId = -1;
                }
            }

            Gender         = Database.GetGender(UserId);
            MailBox        = new Mailbox(this);
            Highscores     = new Highscore(this);
            Awards         = new Award(this);
            MutePlayer     = new MutedPlayers(this);
            TrackedItems   = new Tracking(this);
            HorseInventory = new HorseInventory(this);

            // Generate SecCodes


            SecCodeSeeds[0] = (byte)GameServer.RandomNumberGenerator.Next(40, 60);
            SecCodeSeeds[1] = (byte)GameServer.RandomNumberGenerator.Next(40, 60);
            SecCodeSeeds[2] = (byte)GameServer.RandomNumberGenerator.Next(40, 60);
            SecCodeInc      = (byte)GameServer.RandomNumberGenerator.Next(40, 60);


            Friends        = new Friends(this);
            LoginTime      = DateTime.UtcNow;
            LoggedinClient = baseClient;
            Inventory      = new PlayerInventory(this);
            Quests         = new PlayerQuests(this);

            // Get auctions
            foreach (Auction auction in Auction.AuctionRooms)
            {
                foreach (Auction.AuctionEntry auctionEntry in auction.AuctionEntries)
                {
                    if (auctionEntry.HighestBidder == this.Id)
                    {
                        Auction.AuctionBid bid = new Auction.AuctionBid();
                        bid.BidUser     = this;
                        bid.BidAmount   = auctionEntry.HighestBid;
                        bid.AuctionItem = auctionEntry;

                        if (bid.BidAmount > 0)
                        {
                            Bids.Add(bid);
                            auctionEntry.Bidders.Add(bid);
                        }
                    }
                }
            }
        }
示例#14
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            if (_mediaShouldFadeToRanch)
            {
                if (MediaPlayer.Volume > 0.0f && MediaPlayer.State == MediaState.Playing)
                {
                    MediaPlayer.Volume -= 0.1f;
                }

                if (MediaPlayer.Volume <= 0.0f)
                {
                    MediaPlayer.Stop();
                    MediaPlayer.Volume = 1.0f;

                    var screen     = new Ranch(Game, HarvestMoon.Arrival.Town);
                    var transition = new FadeTransition(GraphicsDevice, Color.Black, 1.0f);
                    ScreenManager.LoadScreen(screen, transition);
                }
            }


            // Update the map
            // map Should be the `TiledMap`
            _mapRenderer.Update(gameTime);
            _entityManager.Update(gameTime);


            if (_player != null && !_player.IsDestroyed)
            {
                _camera.LookAt(_player.Position);
                var constraints = new Vector2();

                if (_camera.BoundingRectangle.Center.X < 320)
                {
                    constraints.X = 320;
                }

                if (_camera.BoundingRectangle.Center.X > _map.Width * _map.TileWidth - 320)
                {
                    constraints.X = _map.Width * _map.TileWidth - 320;
                }

                if (_camera.BoundingRectangle.Center.Y < 240)
                {
                    constraints.Y = 240;
                }

                if (_camera.BoundingRectangle.Center.Y > _map.Height * _map.TileHeight - 240)
                {
                    constraints.Y = _map.Height * _map.TileHeight - 240;
                }

                if (constraints.X != 0)
                {
                    _camera.LookAt(new Vector2(constraints.X, _player.Position.Y));
                }

                if (constraints.Y != 0)
                {
                    _camera.LookAt(new Vector2(_player.Position.X, constraints.Y));
                }

                if (constraints.X != 0 && constraints.Y != 0)
                {
                    _camera.LookAt(new Vector2(constraints.X, constraints.Y));
                }
            }


            CheckCollisions();
        }
示例#15
0
        public override void LoadContent()
        {
            base.LoadContent();

            // Load the compiled map
            _map = Content.Load <TiledMap>("maps/Barn");
            // Create the map renderer
            _mapRenderer = new TiledMapRenderer(GraphicsDevice, _map);

            foreach (var layer in _map.ObjectLayers)
            {
                if (layer.Name == "Arrivals")
                {
                    foreach (var obj in layer.Objects)
                    {
                        if (obj.Name == "barn" && _arrival == HarvestMoon.Arrival.Ranch)
                        {
                            var objectPosition = obj.Position;

                            objectPosition.X = obj.Position.X + obj.Size.Width * 0.5f;
                            objectPosition.Y = obj.Position.Y + obj.Size.Height * 0.5f;

                            _player = HarvestMoon.Instance.RanchState.Entities.FirstOrDefault(e => e is Jack) as Jack;

                            if (_player == null)
                            {
                                _player = _entityManager.AddEntity(new Jack(Content, _entityManager, this, objectPosition));
                            }
                            else
                            {
                                _entityManager.AddEntity(_player);
                                _player.EntityManager = _entityManager;
                            }

                            _player.Position = new Vector2(objectPosition.X, objectPosition.Y);

                            _player.PlayerFacing = Jack.Facing.UP;
                        }
                    }
                }
                else if (layer.Name == "Doors")
                {
                    foreach (var obj in layer.Objects)
                    {
                        var objectPosition = obj.Position;

                        objectPosition.X = obj.Position.X + obj.Size.Width * 0.5f;
                        objectPosition.Y = obj.Position.Y + obj.Size.Height * 0.5f;

                        var objectSize = obj.Size;

                        var door = new Door(objectPosition, objectSize);
                        _entityManager.AddEntity(door);

                        if (obj.Name == "ranch")
                        {
                            door.OnTriggerStart(() =>
                            {
                                _player.Freeze();
                            });

                            door.OnTriggerEnd(() =>
                            {
                                if (!door.Triggered)
                                {
                                    door.Triggered = true;
                                    var screen     = new Ranch(Game, HarvestMoon.Arrival.Barn);
                                    var transition = new FadeTransition(GraphicsDevice, Color.Black, 1.0f);
                                    ScreenManager.LoadScreen(screen, transition);
                                }
                            });
                        }
                    }
                }
                else if (layer.Name == "Walls")
                {
                    foreach (var obj in layer.Objects)
                    {
                        var objectPosition = obj.Position;

                        objectPosition.X = obj.Position.X + obj.Size.Width * 0.5f;
                        objectPosition.Y = obj.Position.Y + obj.Size.Height * 0.5f;

                        var objectSize = obj.Size;

                        _entityManager.AddEntity(new Wall(objectPosition, objectSize));
                    }
                }
                else if (layer.Name == "Special")
                {
                    foreach (var obj in layer.Objects)
                    {
                        var objectPosition = obj.Position;

                        objectPosition.X = obj.Position.X + obj.Size.Width * 0.5f;
                        objectPosition.Y = obj.Position.Y + obj.Size.Height * 0.5f;

                        var objectSize = obj.Size;

                        var    placementName   = obj.Name;
                        int    lastIndexOf     = placementName.LastIndexOf("-");
                        string specialName     = placementName.Substring(0, lastIndexOf);
                        string specialPosition = placementName.Substring(lastIndexOf + 1, placementName.Length - specialName.Length - 1);

                        var cowPlacement = new CowPlacement();
                        cowPlacement.Position = objectPosition;
                        cowPlacement.Size     = objectSize;

                        _cowPlacements[int.Parse(specialPosition)] = cowPlacement;
                    }
                }
                else if (layer.Name == "Interactables")
                {
                    foreach (var obj in layer.Objects)
                    {
                        if (obj.Name == "fooder")
                        {
                            var objectPosition = obj.Position;

                            objectPosition.X = obj.Position.X + obj.Size.Width * 0.5f;
                            objectPosition.Y = obj.Position.Y + obj.Size.Height * 0.5f;

                            var objectSize = obj.Size;

                            _entityManager.AddEntity(new FooderBin(_player, Content, objectPosition, objectSize));
                        }
                    }
                }
            }

            for (int i = 0; i < _cowPlacements.Count; ++i)
            {
                var fooder = _entityManager.AddEntity(new Fooder(_player, Content, _cowPlacements[i].Position, _cowPlacements[i].Size));
                fooder.Index = i;

                fooder.Feed(HarvestMoon.Instance.CowFooderList[i]);
            }

            foreach (var kvp in HarvestMoon.Instance.CowNameIndexDictionary)
            {
                var i   = kvp.Value;
                var cow = _entityManager.AddEntity(new Cow(_player, Content, _cowPlacements[i].Position, _cowPlacements[i].Size));
                cow.Index = i;
            }



            LoadPlayer();
        }