/// <summary> /// Uppdaterar NonPlayer objekt genom att sudda ut de, skriva ut de, och uppdatera koordinaterna. /// </summary> public void Update() { _updateTimer.Start(); if (Map.SlowTime == true) { Map.MoveSpeed = Map.MoveSpeed + 200; Map.SlowTime = false; } if (_updateTimer.ElapsedMilliseconds > Map.MoveSpeed) { for (int i = 0; i < GameContainer.NonPlayerList.Count; i++) { var nonPlayer = GameContainer.NonPlayerList[i]; if (nonPlayer.CheckCollision(nonPlayer.FetchX(), nonPlayer.FetchY())) { nonPlayer.Remove(nonPlayer.FetchX(), nonPlayer.FetchY()); nonPlayer.Draw(nonPlayer.FetchX(), nonPlayer.FetchY()); _updateTimer.Reset(); } else { if (nonPlayer.FetchX() == Player.X && nonPlayer.FetchY() == Player.Y) { switch (nonPlayer.FetchEntity()) { case "enemy": if (Map.GodMode == false) { GameContainer.EndGame(); } else { GameContainer.NonPlayerList.RemoveAt(i); } break; case "pu": GameContainer.PU.GainPU(); GameContainer.NonPlayerList.RemoveAt(i); break; case "score": Map.UpdateScore(); GameContainer.NonPlayerList.RemoveAt(i); break; } } else if (nonPlayer.FetchX() == 0) { GameContainer.NonPlayerList.RemoveAt(i); nonPlayer.Remove(nonPlayer.FetchX(), nonPlayer.FetchY()); i--; } } } } }
/// <summary> /// CheckMove kollar om player objektet rör sig utanför kartan eller om den kolliderar med ett NonPlayer objekt. /// </summary> /// <param name="x"> /// X koordinaten som player objektet står på. /// </param> /// <param name="y"> /// Y koordinaten som player objektet står på. /// </param> /// <returns> /// Returnar true då player objektet inte kolliderar med NonPlayer objekt eller går utanför kartan, returnerar false då något om de tidigare kraven har hänt. /// </returns> public bool CheckMove(int x, int y) { if (x < 0 || x >= Console.WindowWidth - 1) { return(false); } if (y < 0 || y >= Console.WindowHeight - 2) { return(false); } for (int i = 0; i < GameContainer.NonPlayerList.Count; i++) { var nonPlayer = GameContainer.NonPlayerList[i]; if (nonPlayer.FetchX() == Player.X && nonPlayer.FetchY() == Player.Y) { switch (nonPlayer.FetchEntity()) { case "enemy": if (Map.GodMode == false) { GameContainer.EndGame(); } else { GameContainer.NonPlayerList.RemoveAt(i); } break; case "pu": GameContainer.PU.GainPU(); GameContainer.NonPlayerList.RemoveAt(i); return(true); case "score": Map.UpdateScore(); GameContainer.NonPlayerList.RemoveAt(i); return(true); } } } return(true); }