// Getters public GameObject GetBoardObjectView(BoardObject sourceObject) { if (sourceObject is BeamGoal) { return(BeamGoalView); } if (sourceObject is BeamSource) { return(BeamSourceView); } if (sourceObject is Crate) { return(CrateView); } if (sourceObject is CrateGoal) { return(CrateGoalView); } if (sourceObject is ExitSpot) { return(ExitSpotView); } if (sourceObject is Player) { return(PlayerView); } if (sourceObject is Voyd) { return(VoydView); } Debug.LogError("Trying to add BoardObjectView from BoardObject, but no clause to handle this type! " + sourceObject.GetType().ToString()); return(null); }
private void OnRightDown() { if (!modifiable) { return; } if (dragging) { return; } if (boardObject == null) { boardObject = GetComponent <BoardObject>(); } if (argumentLoader != null) { argumentLoader.SetBoardObject(boardObject); } boardObject.Rotate(1); string name = boardObject.GetName(); TrackerAsset.Instance.setVar("element_type", name.ToLower()); TrackerAsset.Instance.setVar("element_name", boardObject.GetNameWithIndex().ToLower()); TrackerAsset.Instance.setVar("position", lastPos.ToString()); TrackerAsset.Instance.setVar("rotation", boardObject.GetDirection().ToString().ToLower()); TrackerAsset.Instance.setVar("action", "rotate"); TrackerAsset.Instance.GameObject.Interacted(boardObject.GetID()); }
protected override void init() { uniqueProperties.Add(Property.Track); BoardObject htgoElement = GameManager.Instance.Game.FindBO( (BoardObject htgo) => { bool retVal = true; uniqueProperties.ForEach(p => retVal &= htgo.Properties.Contains(p)); return(retVal); })[0]; SelectKey = htgoElement; track = (Track)htgoElement; int numBoxes = track.MaxValue - track.MinValue + 1; float xAnchorInc = 1.0f / numBoxes; for (int i = 0; i < numBoxes; ++i) { TrackBoxElement trackBox = Instantiate <TrackBoxElement>(trackBoxPrefab); RectTransform trans = trackBox.GetComponent <RectTransform>(); trans.anchorMin = new Vector2(i * xAnchorInc, 0); trans.anchorMax = new Vector2((i + 1) * xAnchorInc, 1); trans.SetParent(boxParent.transform, false); trackBox.SetValue(i + track.MinValue); trackBoxes.Add(trackBox); } }
private void setColor(BoardObject obj, Bitmap bitmap) { if (obj.isCarry()) { setColor(bitmap, obj.Coords, COLOR_PLAYER1_CARRY, COLOR_PLAYER2_CARRY, (obj as Ant).Owner); } else if (obj.isScout()) { setColor(bitmap, obj.Coords, COLOR_PLAYER1_SCOUT, COLOR_PLAYER2_SCOUT, (obj as Ant).Owner); } else if (obj.isWarrior()) { setColor(bitmap, obj.Coords, COLOR_PLAYER1_WARRIOR, COLOR_PLAYER2_WARRIOR, (obj as Ant).Owner); } else if (obj.isBase()) { Base playerbase = obj as Base; if (playerbase.RangeLevel > 0) { for (int i = 0; i < playerbase.RangeCoords.Count; i++) { setColor(bitmap, playerbase.RangeCoords[i], COLOR_PLAYER1_BASE, COLOR_PLAYER2_BASE, playerbase.Player); } } setColor(bitmap, obj.Coords, COLOR_PLAYER1_BASE, COLOR_PLAYER2_BASE, (obj as Base).Player); } else if (obj.isSugar()) { setColor(bitmap, obj.Coords, COLOR_GAME_SUGAR, Color.Transparent, null); } }
private IEnumerator InternalRotateObject(BoardObject bObject, int direction, float time) { // Get direction BoardObject.Direction currentDirection = bObject.GetDirection(); BoardObject.Direction targetDirection = (BoardObject.Direction)((((int)currentDirection + direction) + 8) % 8); // Froze direction bObject.SetDirection(BoardObject.Direction.PARTIAL, false); Vector3 fromAngles = bObject.transform.localEulerAngles; fromAngles.y = (int)currentDirection * 45.0f; Vector3 toAngles = bObject.transform.localEulerAngles; toAngles.y = ((int)currentDirection + direction) * 45.0f; // Interpolate movement float auxTimer = 0.0f; while (auxTimer < time) { Vector3 lerpAngles = Vector3.Lerp(fromAngles, toAngles, auxTimer / time); bObject.transform.localEulerAngles = lerpAngles; auxTimer += Time.deltaTime; yield return(null); } // Set final rotation (defensive code) bObject.SetDirection(targetDirection); }
// FINISHED public void CreateNewObjectIn(BoardPosition Position, int level) { if (GamePaused) { return; } Assert.IsTrue(level >= 1 && level <= ObjectMaterialsByLevel.Length, "Level is correct: " + level); // Create object and its connections BoardObject BoardObject = GameObject.Instantiate <GameObject>(BoardObjectPrefab).GetComponent <BoardObject>(); BoardObject.BoardManager = this; BoardObject.CurrentPosition = Position; // Give it its material BoardObject.GetComponentInChildren <Renderer>().material = ObjectMaterialsByLevel[level - 1]; // Give it its level value BoardObject.SetLevel(level); // Register the object with its position Position.SetObject(BoardObject); // Increment points by an appropriate amount UIManager.IncrementPointsBy(level); }
public void RotateObject(Vector2Int origin, int direction, float time, out Coroutine coroutine) { // Check direction coroutine = null; if (direction == 0) { return; } direction = direction < 0 ? -1 : 1; // Check if origin object exists if (!IsInBoardBounds(origin)) { return; } BoardObject bObject = board[origin.x, origin.y].GetPlacedObject(); if (bObject == null) { return; // No to rotate } // You cannot rotate an object that is already rotating if (bObject.GetDirection() == BoardObject.Direction.PARTIAL) { return; } coroutine = StartCoroutine(InternalRotateObject(bObject, direction, time)); }
// We assume, all are valid arguments private IEnumerator InternalMoveObject(BoardCell from, BoardCell to, float time) { // All cells to PARTIALLY_OCUPPIED from.SetState(BoardCell.BoardCellState.PARTIALLY_OCUPPIED); to.SetState(BoardCell.BoardCellState.PARTIALLY_OCUPPIED); BoardObject bObject = from.GetPlacedObject(); Vector3 fromPos = bObject.transform.position; Vector3 toPos = to.transform.position; // Interpolate movement float auxTimer = 0.0f; while (auxTimer < time) { Vector3 lerpPos = Vector3.Lerp(fromPos, toPos, auxTimer / time); bObject.transform.position = lerpPos; auxTimer += Time.deltaTime; yield return(null); } // Replace from.RemoveObject(false); to.PlaceObject(bObject); // All cells to correct state from.SetState(BoardCell.BoardCellState.FREE); to.SetState(BoardCell.BoardCellState.OCUPPIED); }
public void ReplaceCell(int id, int x, int y) { if (!IsInBoardBounds(x, y) || id == board[x, y].GetObjectID()) { return; } BoardCell currentCell = board[x, y]; BoardObject boardObject = currentCell.GetPlacedObject(); currentCell.RemoveObject(false); BoardCell cell = AddBoardCell(id, x, y); cell.SetState(BoardCell.BoardCellState.FREE); if (boardObject != null) { cell.PlaceObject(boardObject); } if (cells[id].Contains(currentCell)) { cells[id].Remove(currentCell); } Destroy(currentCell.gameObject); }
public bool MoveBoardObject(Vector2Int from, Vector2Int to) { if (IsInBoardBounds(from) && IsInBoardBounds(to) && from != to) { BoardCell cell = board[to.x, to.y]; if (cell.GetState() != BoardCell.BoardCellState.FREE) { return(false); } BoardObject bObject = board[from.x, from.y].GetPlacedObject(); if (bObject == null) { return(false); } board[from.x, from.y].RemoveObject(false); board[to.x, to.y].PlaceObject(bObject); if (elementPositions != null) { elementPositions[bObject.GetNameAsLower()].Remove(from); elementPositions[bObject.GetNameAsLower()].Add(to); } return(true); } return(false); }
void OnPlaced(BoardObject obj, Vector2Int pos) { if (obj == BoardObject) { transform.position = pos.ToFloat(); } }
private void HandleRightButtonDown(MouseEventArgs e) { Position pos = GameGraphics.TranslateMousePosition(e.Location); if (!_isCreatingBuilding && !_isCreatingUnit) { BoardObject bo = boardObjectAt(pos); if (bo != null) { _gameLogic.AttackOrder(bo); } else { _gameLogic.MoveOrder(pos); } return; } if (_isCreatingBuilding) { _buildManager.OnBadLocation(_objectCreatorId); } _isCreatingUnit = false; InfoLog.WriteInfo("_isCreatingUnit = false; in HandleRightButtonDown", EPrefix.BMan); _isCreatingBuilding = false; }
public void SetBoardObject(Vector2Int pos, BoardObject newObject) { if (IsWithinBoard(pos)) { Tiles[ConvertPositionToBoardCoord(pos)] = newObject; } }
public void GenerateSelector() { DestroySelector(); columns = elements.Length; rows = 1; int elementIndex = 0; for (int y = 0; y < rows; y++) { for (int x = 0; x < columns; x++) { BoardCell cell = Instantiate(cellPrefab, cellsParent); cell.SetPosition(x, y); if (elementIndex < elements.Length) { BoardObject boardObject = Instantiate(elements[elementIndex++], elementsParent); Selectable selectable = boardObject.gameObject.AddComponent <Selectable>(); selectable.SetBoard(board); selectable.SetArgumentLoader(loader); cell.PlaceObject(boardObject); } } } transform.position = board.transform.position + (Vector3.back * (rows + 1)) + Vector3.right * (board.GetColumns() - columns) / 2.0f; }
// ---------------------------------------------------------------- // Initialize // ---------------------------------------------------------------- override public void Initialize(BoardView _myBoardView, BoardObject bo) { MyCrate = bo as Crate; base.Initialize(_myBoardView, bo); // Auto-move visuals! if (MyCrate.DoAutoMove) { i_body.color = new ColorHSB(0.5f, 0.3f, 1f).ToColor(); } else { Destroy(i_autoMoveDir.gameObject); i_autoMoveDir = null; } // Add dimple images! for (int corner = 0; corner < Corners.NumCorners; corner++) { if (MyCrate.IsDimple[corner]) { Image newImg = new GameObject().AddComponent <Image>(); GameUtils.ParentAndReset(newImg.gameObject, rt_contents); GameUtils.FlushRectTransform(newImg.rectTransform); newImg.name = "Dimple" + corner; newImg.sprite = s_dimple; newImg.transform.localEulerAngles = new Vector3(0, 0, -90 * corner); } } }
public void OnMouseButtonDown(int index) { if (index != 0) { return; } if (!board.GetOrbitCamera().IsReset()) { return; } BoardObject boardObject = Instantiate(myBoardObject, transform.position, Quaternion.identity); boardObject.transform.localScale = transform.lossyScale; Destroy(boardObject.gameObject.GetComponent <Selectable>()); DraggableObject draggable = boardObject.gameObject.AddComponent <DraggableObject>(); draggable.SetBoard(board); draggable.SetArgumentLoader(argumentLoader); draggable.SetCameraInput(board.GetMouseInput()); draggable.SetOrbitCamera(board.GetOrbitCamera()); string name = boardObject.GetName(); TrackerAsset.Instance.setVar("element_type", name.ToLower()); TrackerAsset.Instance.setVar("element_name", boardObject.GetNameWithIndex().ToLower()); TrackerAsset.Instance.setVar("action", "create"); TrackerAsset.Instance.GameObject.Interacted(boardObject.GetID()); draggable.OnMouseButtonDown(index); }
public bool IsOrientationMatch(BoardObject other) { return(BoardPos == other.BoardPos); //&& ChirH == other.ChirH //&& ChirV == other.ChirV //&& SideFacing == other.SideFacing; }
public void SetBoardObject(int i, BoardCell elementCell) { if (i >= boardElements.Length) { return; } BoardObject element = elementCell.GetPlacedObject(); if (element == null) { return; } BoardObjectState objectState = new BoardObjectState(); objectState.id = element.GetObjectID(); Vector2Int pos = elementCell.GetPosition(); objectState.x = pos.x; objectState.y = pos.y; objectState.args = element.GetArgs(); objectState.orientation = (int)element.GetDirection(); boardElements[i] = objectState; }
/// <param name="resettable"> /// true if the objects which are being moved already exists, /// and thus has a valid start position /// </param> public MovingSelectionState(Vec2 localPoint, HashSet <BoardObject> selections, BoardObject selectedObject, BoardState state, bool resettable) : base(selections) { //Make sure all selections start in a gridded position; foreach (var selection in selections) { if (selection.Gridded) { selection.SetPosition(selection.StartPoint.Round()); } } this.selectedObject = selectedObject; this.resettable = resettable; foreach (var selection in selections) { resetBoxes.Add(selection.HitBox); } //Calculate offset from held location to current Mouse position startPosition = selectedObject.StartPoint; offset = selectedObject.StartPoint - localPoint; if (resettable) { state.DetatchAll(selections); } else { //set startPosition to an invalid start value startPosition = new Vec2(float.MinValue, float.MinValue); } CheckIntersections(state); }
public void evaluateGame(BoardObject o) { if (isFinished(o)) { endGame(o); } }
public void SetBoardObject(BoardObject newObject) { if (newObject == null) { return; } currentObject = newObject; gameObject.SetActive(true); text.text = currentObject.GetNameWithIndex(); string[] argsNames = currentObject.GetArgsNames(); if (argsNames.Length == 0) { gameObject.SetActive(false); } for (int i = 0; i < inputs.Length; i++) { if (i < argsNames.Length) { int index = i; inputs[i].Init((bool action) => TraceCheckBox(action, argsNames[index])); inputs[i].FillArg(argsNames[i]); } else { inputs[i].gameObject.SetActive(false); } } }
void Start() { visualLasers = new List <VisualLaser>(); UnplacedObjects = new List <BoardObject>(); level = FindObjectOfType <Level>(); StartCoroutine(tutorialCoroutine(FindObjectOfType <TutorialMessageQueue>())); for (int i = 0; i < level.board.Width; i++) { for (int j = 0; j < level.board.Height; j++) { Vector2Int pos = new Vector2Int(i, j); BoardObject current = level.board.GetBoardObject(pos); if (current) { if (!current.Placed) { UnplacedObjects.Add(current); level.board.SetBoardObject(pos, null); } } } } displayer.ReloadButtons(); CalculateLaserPaths(); PositionCamera(); GenerateBackground(); SceneManager.SetActiveScene(SceneManager.GetSceneAt(1)); }
private void AddToUnplaced(BoardObject obj) { SelectObject(UnplacedObjects.Count); UnplacedObjects.Add(obj); displayer.ReloadButtons(); CalculateLaserPaths(); }
/// <summary> /// Creates bomb booster at given position. /// </summary> /// <param name="boardPos">Board position.</param> /// <param name="worldPos">World position.</param> public void CreateBombAtPosition(GridCoordinate boardPos, Vector3 worldPos) { BoardObject newBoardObj = Instantiate(bombPrefab).GetComponent <BoardObject>(); newBoardObj.GridPosition = boardPos; newBoardObj.transform.position = worldPos; BoardController.Instance.AssignToBoard(newBoardObj); }
public void SpawnExclamation(BoardObject boardObject) { GameObject go = Instantiate(_exclamationPrefab, boardObject.transform.position + Vector3.up, Quaternion.identity); go.transform.SetParent(transform); GameObject.Destroy(go, 1.5f); }
// FINISHED public void SetObject(BoardObject CurrentObject) { this.CurrentObject = CurrentObject; // Put inside this position CurrentObject.transform.SetParent(transform); CurrentObject.transform.localPosition = Vector3.zero; }
/// <summary> /// Creates a disco ball booster at position. /// </summary> /// <param name="boardPos">Board position.</param> /// <param name="worldPos">World position.</param> /// <param name="color">Color.</param> public void CreateDiscoBallAtPosition(GridCoordinate boardPos, Vector3 worldPos, ColorController.ToonColor color) { BoardObject newBoardObj = Instantiate(discoBallPrefab).GetComponent <BoardObject>(); newBoardObj.GetComponent <ColorController>().SetColor(color); newBoardObj.GridPosition = boardPos; newBoardObj.transform.position = worldPos; BoardController.Instance.AssignToBoard(newBoardObj); }
// ---------------------------------------------------------------- // Initialize // ---------------------------------------------------------------- override public void Initialize(BoardView _myBoardView, BoardObject bo) { myCrateGoal = bo as CrateGoal; base.Initialize(_myBoardView, bo); // Rotate i_body by corner! i_body.transform.localEulerAngles = new Vector3(0, 0, -90 * myCrateGoal.Corner); i_body.sprite = myCrateGoal.DoStayOn ? s_bodyStayOn : s_bodyNoStayOn; }
// ---------------------------------------------------------------- // Initialize / Destroy // ---------------------------------------------------------------- override public void Initialize(BoardView _myBoardView, BoardObject bo) { MyBeamSource = bo as BeamSource; BeamColor = Colors.GetBeamColor(MyBeamSource.ChannelID); base.Initialize(_myBoardView, bo); beamView.Initialize(_myBoardView.tf_beamLines); i_body.color = BeamColor; i_body.sprite = MyBoardOccupant.IsMovable ? s_bodyMovable : s_bodyNotMovable; }
// Getters //override protected Color GetPrimaryFillMovable () { return new Color (beamColor.r, beamColor.g, beamColor.b); } // ---------------------------------------------------------------- // Initialize // ---------------------------------------------------------------- override public void Initialize(BoardView _myBoardView, BoardObject bo) { myBeamGoal = bo as BeamGoal; beamColor = Colors.GetBeamColor(myBeamGoal.ChannelID); base.Initialize(_myBoardView, bo); i_body.color = beamColor; i_body.sprite = myBeamGoal.IsMovable ? s_bodyMovable : s_bodyNotMovable; }
public GhostAI getGhostByNumber( int num, BoardObject Data ) { if ( num == 0 ) { return new BlinkyAI( Players, Accessor, Data ); } else if ( num == 1 ) { return new PinkyAI( Players, Accessor, Data ); } else if ( num == 2 ) { return new InkyAI( Players, Accessor, Data ); } else if ( num == 3 ){ return new ClydeAI( Players, Accessor, Data ); } else { throw new NotImplementedException(); } }
public IntVector2 moveTowardsBFS( BoardObject boardObjectData, HashSet<IntVector2> target, int maxSpeed, out int distance ) { return moveTowardsBFS( boardObjectData, target, maxSpeed, out distance, false ); }
public IntVector2 moveTowardsBFS( BoardObject boardObjectData, HashSet<IntVector2> targets, int maxSpeed, out int distance, bool canReverse ) { BoardLocation pos = boardObjectData.boardLocation.Clone(); // get grid positions IntVector2 thisPos = pos.location; HashSet<IntVector2> visited = new HashSet<IntVector2>(); Dictionary<IntVector2, IntVector2> previous = new Dictionary<IntVector2, IntVector2>(); LinkedList<IntVector2> queue = new LinkedList<IntVector2>(); queue.AddLast( thisPos ); IntVector2 reverseDir = boardObjectData.direction.Normalized(); reverseDir = reverseDir * -1; IntVector2 closestReachable = null; int closestDistance = int.MaxValue; while ( queue.Count > 0 ) { IntVector2 p = queue.First.Value; queue.RemoveFirst(); foreach ( IntVector2 target in targets ) { if ( IntVector2.OrthogonalDistance( p, target ) < closestDistance ) { closestReachable = p.Clone(); closestDistance = IntVector2.OrthogonalDistance( p, target ); } } // found a destination if ( targets.Contains( p ) ) break; foreach ( IntVector2 dir in Constants.directions ) { if ( !canReverse && p.Equals( pos.location ) && dir.Equals( reverseDir ) ) { // not allowed continue; } IntVector2 posToVisit = dir + p; if ( !isOpen( posToVisit ) ) continue; if ( visited.Contains( posToVisit ) ) continue; visited.Add( posToVisit ); previous[posToVisit] = p; queue.AddLast( posToVisit ); } } LinkedList<IntVector2> path = new LinkedList<IntVector2>(); IntVector2 curr = closestReachable; try { while ( !curr.Equals( thisPos ) && previous.ContainsKey( curr ) ) { path.AddFirst( curr ); curr = previous[curr]; } } catch ( KeyNotFoundException e ) { int x = 0; x++; } distance = path.Count; // there is a path and its length is not 0 if ( path.Count > 0 ) { // head in the direction of first IntVector2 direction = new IntVector2( path.First.Value.x, path.First.Value.y ) - new IntVector2( thisPos.x, thisPos.y ); direction.Normalize(); direction *= maxSpeed; // direction will be orthogonal BoardLocation afterMove = tryMove( pos, direction ); if ( BoardLocation.SqrDistance( afterMove, pos ) > maxSpeed * maxSpeed / 4 ) { // move there return direction; } } //otherwise, we are at our target. Any move will suffice distance = int.MaxValue; return new IntVector2(0, 0); }
public GhostAI( PacmanData[] players, BoardAccessor Accessor, BoardObject Data ) { this.Players = players; this.Accessor = Accessor; this.Data = Data; }
public ClydeAI( PacmanData[] players, BoardAccessor Accessor, BoardObject Data ) : base(players, Accessor, Data) { }
void Awake() { obj = GetComponent<BoardObject>(); data = BoardData.getBoardData(); }