void OnTriggerEnter2D(Collider2D col) { if (AllowControl && col.gameObject.GetComponent <ShapePieces>() != null) { ShapePieces piece = col.gameObject.GetComponent <ShapePieces>(); float magnitude = ((Vector2)col.transform.position - (Vector2)transform.position).magnitude; if (magnitude < attractDistance) { piece.GetAttracted(this, magnitude / attractDistance * attractForce); } } }
public void PieceSnugFit(ShapePieces piece) { if (masterPiece == null || piece.IsMaster || piece == masterPiece) { SwitchMasterPiece(); } if (ActiveShapePieces.Count == 0) { GameMaster.Instance.AssignPiece(2f); } }
void OnCollisionEnter2D(Collision2D col) { ShapePieces shape = col.gameObject.GetComponent <ShapePieces>(); if (AllowControl && shape != null) { if (!shape.AllowControl) { GameMaster.Instance.PhraseManager.DisplayFindFriendPhrase(); shape.AllowControl = true; } } }
private void SetMasterPiece(ShapePieces currentPiece, ShapePieces newPiece) { masterPiece = newPiece; if (currentPiece != null && currentPiece.IsMaster) { currentPiece.IsMaster = false; } if (newPiece != null) { newPiece.IsMaster = true; } }
public void GetAttracted(ShapePieces shapePiece, float force) { if (!AllowControl) { return; } Vector2 dir = (Vector2)shapePiece.transform.position - (Vector2)transform.position; dir.Normalize(); if (shapePiece.shape == shape) { rb.AddForce(dir * Time.deltaTime * force); } }
public void PoolActors() { points = PoissonDiscSampling.GeneratePoints(actorRadius, regionSize, rejectionSamples); int pointsCounter = 1; int shapeTypes = System.Enum.GetNames(typeof(Shape)).Length; int playerType = Random.Range(0, shapeTypes); GameObject playerPiece = Instantiate(piecePrefab); ShapePieces shapePiece = playerPiece.GetComponent <ShapePieces>(); shapePiece.Instantiate((Shape)playerType, points[0]); shapePiece.AllowControl = true; pieces.Add(shapePiece); GameObject homeToSpawn = Instantiate(homePrefab); homeToSpawn.GetComponent <HomePieces>().Instantiate((Shape)playerType, points[pointsCounter]); homes.Add(homeToSpawn); pointsCounter++; for (int i = 0; i < shapeTypes; i++) { GameObject pieceToSpawn = Instantiate(piecePrefab); shapePiece = pieceToSpawn.GetComponent <ShapePieces>(); shapePiece.Instantiate((Shape)i, points[pointsCounter]); shapePiece.transform.rotation = Quaternion.LookRotation(Vector3.forward, Random.insideUnitCircle); pointsCounter++; pieces.Add(shapePiece); int homesToSpawn = Random.Range(minHomesPerType, maxHomesPerType); for (int j = 0; j < homesToSpawn; j++) { homeToSpawn = Instantiate(homePrefab); homeToSpawn.GetComponent <HomePieces>().Instantiate((Shape)i, points[pointsCounter]); homeToSpawn.transform.rotation = Quaternion.LookRotation(Vector3.forward, Random.insideUnitCircle); homes.Add(homeToSpawn); pointsCounter++; } } }
void OnTriggerStay2D(Collider2D col) { if (Occupied) { return; } ShapePieces piece = col.GetComponentInParent <ShapePieces>(); if (piece) { float magnitude = ((Vector2)col.transform.position - (Vector2)transform.position).magnitude; if (magnitude < snapDistance && Quaternion.Angle(transform.rotation, piece.transform.rotation) < 10f) { piece.SnugFit(this); } else if (magnitude < attractDistance) { piece.GetAttracted(this, ((attractDistance - magnitude) / attractDistance) * attractForce, magnitude / attractDistance); } } }