/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } //Om spelet är i gång if (currentGameState == GamesStates.InGame) { //FRÅGA 1: Hur fungerar den här uträkningen? //countdown minskas med tiden det gått sedan förra uppdateringen countdown -= gameTime.ElapsedGameTime.TotalMilliseconds; if (countdown <= 0) { Vector2 newVelocity = new Vector2(); //FRÅGA 3: Varför används NextDouble() i stället för Next()? //För att kunna få "alla" tal, inte bara heltal newVelocity.X = (float)(-10 * rng.NextDouble()); newVelocity.Y = -(float)rng.NextDouble(); pipes.Add(new NormalPipe(pipeTexture, newVelocity)); //FRÅGA 2: Vad kan vi göra här med countdown för att inte få så många pipes? //Återställ countdown, t ex //countdown = 1000; } player.Update(); //FRÅGA 8: Hur fungerar en foreach-sats? //Den loopar igenom varje objekt i en lista eller array foreach (NormalPipe pipe in pipes.ToArray()) { pipe.Update(); if (pipe.Hitbox.Intersects(player.Hitbox)) { pipes.Remove(pipe); //Exit(); } //FRÅGA 10: Hur skulle vi kunna ta bort alla pipes som har passerat vänsterkanten av skärmen? //Undersöka positionens x-komposant. Om den är "tillräckligt negativ", ta bort den //ur listan. } } //Om titelskärmen visas else { if (Keyboard.GetState().IsKeyDown(Keys.Space)) { //STARTA SPELET!!1 currentGameState = GamesStates.InGame; } } base.Update(gameTime); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { IsMouseVisible = true; graphics.PreferredBackBufferHeight = 800; graphics.PreferredBackBufferWidth = 1200; graphics.ApplyChanges(); gravity = new Vector2(0, 0.4f); currentGameState = GamesStates.StartScreen; base.Initialize(); }
IEnumerator MiniGameStart() { int RandomInt; GameObject SpanwedObject; yield return(new WaitUntil(MessageBoxEnabled)); RandomInt = Random.Range(0, MiniGames.Count); SceneObject.gameObject.SetActive(false); SpanwedObject = Instantiate(MiniGames[RandomInt], MiniGamesObject); yield return(new WaitUntil(MiniGameFinished)); SceneObject.gameObject.SetActive(true); GameState = GamesStates.TurnLoop; GameLoop(); }
IEnumerator DecideTurnOrder() { DisplayMessage("Roll for the turn order!", 3); yield return(new WaitUntil(MessageBoxEnabled)); GameObject SpawndObject; GameObject[] SpawedObjects = new GameObject[4]; int Counter = 0; DiceRollCanvas.SetActive(true); foreach (var Player in PlayerList) { SpawndObject = Instantiate(DiceRollObject, DiceRollLocations[Counter]); SpawndObject.GetComponent <NumberRollScript>().Player = Player.GetComponent <GamePlayerInformation>(); SpawndObject.GetComponent <NumberRollScript>().FirstRoll = true; SpawedObjects[Counter] = SpawndObject; Counter++; } yield return(new WaitUntil(HasEveryoneRolled)); PlayerList.Sort(SortByScore); foreach (var Player in PlayerList) { Player.transform.parent = PlayersObject; } yield return(new WaitForSeconds(5)); foreach (GameObject Object in SpawedObjects) { GameObject.Destroy(Object); } Counter = 0; GameState = GamesStates.TurnLoop; GameLoop(); // Now start the main loop of player getting a turn }
IEnumerator OneTurnLoop() { GameObject SpawndObject; MainCamera.enabled = false; foreach (var Player in PlayerList) { PlayerInfo = Player.GetComponent <GamePlayerInformation>(); PlayerInfo.BoardObject.SwitchCam(); DisplayMessage($"{PlayerInfo.PlayerName} his turn!", 2); yield return(new WaitUntil(MessageBoxEnabled)); SpawndObject = Instantiate(DiceRollObject, DiceRollLocations[4]); SpawndObject.GetComponent <NumberRollScript>().Player = Player.GetComponent <GamePlayerInformation>(); yield return(new WaitUntil(HasPlayerRolled)); yield return(new WaitForSeconds(3)); GameObject.Destroy(SpawndObject.gameObject); SpawndObject = null; PlayerInfo.PlayerDoneMoving = false; Player.GetComponent <GamePlayerInformation>().BoardObject.MovePlayerOnBoard(); yield return(new WaitUntil(PlayerMoved)); PlayerInfo.BoardObject.SwitchCam(); PlayerInfo.CurrentRoll = 0; PlayerInfo = null; } MainCamera.enabled = true; GameState = GamesStates.MiniGame; GameLoop(); }
public void load(string FileNameToLoad) { Debug.Log(Application.persistentDataPath + "/" + FileNameToLoad); // Open the file containing the data that you want to deserialize. FileStream fs = new FileStream(Application.persistentDataPath + "/" + FileNameToLoad, FileMode.Open); try { BinaryFormatter formatter = new BinaryFormatter(); this.gamesStates = (GamesStates)formatter.Deserialize(fs); this.FileName = this.gamesStates.FileName; } catch (SerializationException e) { Console.WriteLine("Failed to deserialize. Reason: " + e.Message); throw; } finally { fs.Close(); } }
public GameSaves() { gamesStates = new GamesStates(); }
private void Start() { GameState = GamesStates.GameSetup; GameLoop(); }