void Awake() { if (Instance == null) { Instance = this; } else if (Instance != this) { Destroy(gameObject); } DontDestroyOnLoad(gameObject); boardScript = GetComponent <BoardManager>(); textScript = GetComponent <TextManager>(); playerUnitScript = GetComponent <PlayerUnitManager>(); logicScript = GetComponent <LogicManager>(); unitStateMonoScript = GetComponent <UnitStateMono>(); movementScript = GetComponent <MovementManager>(); GameState currentGameState = new GameState(Player1Controller.playerStateSerial); InitGame(); }
public UnitStateMono Revert(UnitStateMono usm) { Transform = Memento.Transform; Facing = Memento.Facing; Active = Memento.Active; return(usm); }
void Start() { animator = GetComponent <Animator>(); rb2D = GetComponent <Rigidbody2D>(); spriteRenderer = GetComponent <SpriteRenderer>(); player1 = GetComponent <UnitStateMono>(); boxCollider2D = GetComponent <BoxCollider2D>(); if (File.Exists(@"C:\Users\marsh\Documents\BackGround Project\Assets\MyTutorialGame\References" + "/savedGames.gd")) { player1Serial = new UnitStateSerial (GameState.Current.Player1Serial.xPos, GameState.Current.Player1Serial.yPos, GameState.Current.Player1Serial.facing, GameState.Current.Player1Serial.active); } else { player1Serial = new UnitStateSerial (0, 0, 0, true); } player1.Memento = player1Serial; player1 = player1.Revert(player1); }
public UnitStateMono Revert(UnitStateMono psm) { this.XPos = this.Memento.xPos; this.YPos = this.Memento.yPos; this.Facing = this.Memento.facing; this.Active = this.Memento.active; return(psm); }
// start void Start() { // component references animator = GetComponent <Animator>(); rb2D = GetComponent <Rigidbody2D>(); spriteRenderer = GetComponent <SpriteRenderer>(); playerStateMono = GetComponent <UnitStateMono>(); boxCollider2D = GetComponent <BoxCollider2D>(); // sets player position from boardScript.player, // sets player facing and active state to 0(up) and true playerStateSerial = new UnitStateSerial (GameManager.boardScript.player.transform, 0, true); // use playerstatemono's memento function to revert from playerStateMono.Memento = playerStateSerial; playerStateMono = playerStateMono.Revert(playerStateMono); }
public abstract int[] Move(float xMove, float yMove, int recentDirectionChange, int facing, Rigidbody2D rb2D, Transform transform, Animator animator, UnitStateMono unit);
public override void Move(float xMove, float yMove, Rigidbody2D rb2D, Transform transform, Animator animator, UnitStateMono unit) { if (unit.Facing == 0 || unit.Facing == 1) { rb2D.AddForce(transform.up * yMove); } if (unit.Facing == 2 || unit.Facing == 3) { rb2D.AddForce(transform.right * xMove); } }
public abstract void Move(float xMove, float yMove, Rigidbody2D rb2D, Transform transform, Animator animator, UnitStateMono unit);
public override int[] Move(float xMove, float yMove, int recentDirectionChange, int facing, Rigidbody2D rb2D, Transform transform, Animator animator, UnitStateMono unit) { if (xMove == 0 && yMove == 0) // not trying to move { recentDirectionChange = 0; } if (xMove == 0 && yMove != 0) // trying to move in y only { animator.SetBool("PlayerMove", true); recentDirectionChange = 0; rb2D.AddForce(transform.up * yMove); if (yMove > 0) { facing = 0; } if (yMove < 0) { facing = 1; } } if (xMove != 0 && yMove == 0) // trying to move in x only { animator.SetBool("PlayerMove", true); recentDirectionChange = 0; rb2D.AddForce(transform.right * xMove); if (xMove > 0) { facing = 3; } if (xMove < 0) { facing = 2; } } if (xMove != 0 && yMove != 0) // trying to move in y and x { animator.SetBool("PlayerMove", true); if (recentDirectionChange == 1) // and we just swapped directions { if (facing == 0) // and are facing up { rb2D.AddForce(transform.up * yMove); if (yMove > 0) { facing = 0; } } if (facing == 1) // and are facing down { rb2D.AddForce(transform.up * yMove); if (yMove < 0) { facing = 1; } } if (facing == 2) // and are facing left { rb2D.AddForce(transform.right * xMove); if (xMove > 0) { facing = 3; } } if (facing == 3) // and are facing right { rb2D.AddForce(transform.right * xMove); if (xMove < 0) { facing = 2; } } } // and we haven't swapped directions else if (facing == 0) // and are facing up { recentDirectionChange = 1; rb2D.AddForce(transform.right * xMove); if (xMove > 0) { facing = 3; } if (xMove < 0) { facing = 2; } } else if (facing == 1) // and are facing down { recentDirectionChange = 1; rb2D.AddForce(transform.right * xMove); if (xMove > 0) { facing = 3; } if (xMove < 0) { facing = 2; } } else if (facing == 2) // and are facing left { recentDirectionChange = 1; rb2D.AddForce(transform.up * yMove); if (yMove > 0) { facing = 0; } rb2D.AddForce(transform.up * yMove); if (yMove < 0) { facing = 1; } } else if (facing == 3) // and are facing right { recentDirectionChange = 1; rb2D.AddForce(transform.up * yMove); if (yMove > 0) { facing = 0; } rb2D.AddForce(transform.up * yMove); if (yMove < 0) { facing = 1; } } } int[] returnedValue = new int[] { recentDirectionChange, facing }; return(returnedValue); }