// private void MovePos(CardinalDirection direction) { // _selectedPos = _selectedPos + direction; // _t.position = _selectedPos.ToVector3(); // UpdatePathPreview(); // } private void DirectionSelected(CardinalDirection direction) { FMODUnity.RuntimeManager.PlayOneShot(selectSound, new Vector3(0, 0, 0)); if (direction == CardinalDirection.North) { if (selectedTile == 0) { selectedTile = maxTiles; } else { selectedTile = selectedTile - 1; } } else if (direction == CardinalDirection.South) { if (selectedTile == maxTiles) { selectedTile = 0; } else { selectedTile = selectedTile + 1; } } this.transform.position = Player.PlayerPlacables[selectedTile].ToVector3(); _selectedPos = Player.PlayerPlacables [selectedTile]; UpdatePathPreview(); }
/// <summary> /// Get the gameplay state at a given tile position /// Performs in O(n) time for the number of entities. Consider using ToDictionary. /// </summary> /// <param name="pos">Position to query</param> public TileData this[TileVector pos] { get { var data = new TileData(); foreach (var entity in Entities) { if (entity.TilePos == pos) { if (entity is StageTile) { data.Tile = entity as StageTile; } else if (entity is Plantable) { data.Plantable = entity as Plantable; } else { data.Occupant = entity; } if (data.Occupant != null && data.Tile != null && data.Plantable != null) { break; } } } return(data); } }
protected virtual void Start() { //Transform = GetComponent<Transform>(); Animator = GetComponent <Animator>(); TilePos = new TileVector(0, 0); RotationOffset = Quaternion.Euler(RotationOffsetEuler); }
public void SetLevel(Level _level, TileVector _tiles, ActionHandler _undoStack) { level = _level; tiles = _tiles; undoStack = _undoStack; Resize(); }
public void SetPositionAndOrientation(TileVector tv, CardinalDirection dir) { Position = tv.ToVector3(); Rotation = dir.GetBearingRotation(); TilePos = tv; _facing = dir; }
// Use this for initialization void Start() { if (TileObjects.Length == 0 || TileObjects == null) { throw new Exception("Missing tile prefabs"); } if (Seed == 0) { _rng = new System.Random(); } else { _rng = new System.Random(Seed); } _scaleFactor = ModelExtensions.Scale / TileEdgeLength / 2; var origin = new TileVector(0, 0); for (var w = 0; w < Radius * 2 - 1; w++) { for (var e = 0; e < Radius * 2 - 1; e++) { if (Math.Abs(w - e) >= Radius) { continue; } MakeTile(origin + new TileVector(w, e)); } } }
Vector3 GetJitter(TileVector pos) { System.Random jitterGen = new System.Random(pos.GetHashCode()); return(new Vector3( (float)jitterGen.NextDouble() * JitterFactor - JitterFactor / 2, (float)jitterGen.NextDouble() * JitterFactor - JitterFactor / 2, (float)jitterGen.NextDouble() * JitterFactor - JitterFactor / 2 )); }
public static TileVectorTriplet ToNearestTileTriplet(this Vector3 v) { var tilePos = FromVec3.MultiplyPoint(v); var horizontal = new TileVector(Mathf.RoundToInt(tilePos.x), Mathf.RoundToInt(tilePos.z)); var vertical = Mathf.RoundToInt(tilePos.y); return(new TileVectorTriplet(horizontal, vertical)); }
public void Move(CardinalDirection dir) { //todo: implement logic if move is allowed TileVector newPos = TilePos + dir; _moveQueue.Enqueue(new MoveAnimation(this, TilePos, newPos)); TilePos = newPos; _facing = dir; OnMove(); }
public MoveAnimation(Unit unit, TileVector origin, TileVector destination, CardinalDirection direction, int energyCost) { _avatar = unit.Avatar; _targetPos = destination.ToVector3(); _targetRot = direction.GetBearingRotation(); // TODO: implement energycost, advanced bar animation _targetEnergy = unit.Energy; _isStep = origin != destination; moveSound = _avatar.moveSound; }
public Room(TileVector vector, RoomPattern roomPattern) { this.roomPattern = roomPattern; direction = vector.direction; int width = roomPattern.GetRoomWidth(vector.direction); int height = roomPattern.GetRoomHeight(vector.direction); startPosition = GetPositionWithLowestCoordinates(vector, width, height); endPosition = GetPositionWithHighestCoordinates(width, height); unusedDirections = roomPattern.GetDirectionsContainer(vector.direction); }
public FollowThingsPlan(Unit unit, World world, FollowThingsAi parent) : base(unit, world) { var last = GetLastMove <FollowThingsPlan>(); if (last != null) { _unitTarget = last._unitTarget; _objectiveTarget = last._objectiveTarget; _objectivePos = last._objectivePos; } _parent = parent; }
void CreateRoomFromCreator(int numberOfRoom, Creator creator, TileVector vector) { if (numberOfRoom < amountOfAllRooms) { Room room = creator.GetRoom(vector); rooms[numberOfRoom] = room; avalibleRooms.Add(room); } else { throw new System.Exception("Created more rooms than amountOfAllRooms."); } }
public static Quaternion GetBearingRotation(this TileVector tv) { Vector3 facing = tv.ToVector3(); float angle = Vector3.Angle(North, tv.ToVector3()); if (angle == 180) { return(Quaternion.AngleAxis(angle, Up)); } else { return(Quaternion.FromToRotation(North, tv.ToVector3())); } }
private List <MapTile> getVisibleTiles() { float[] bounds = viewRectToLatLng(latitude, longitude, zoom); int[] tl = mercator.latLonToTile(-bounds[0], bounds[1], zoom); int[] br = mercator.latLonToTile(-bounds[2], bounds[3], zoom); List <MapTile> tmp = new List <MapTile>(); for (int i = tl[0]; i <= br[0]; i++) { for (int j = tl[1]; j <= br[1]; j++) { string key = mercator.tileXYToQuadKey(i, j, zoom); bool exist = false; foreach (MapTile tile in tiles) { if (key == tile.quadKey) { tmp.Add(tile); exist = true; } } if (!exist) { MapTile tile; if (parent.vectorTiles) { tile = new TileVector(this, key); } else if (parent.tilesElevetion) { tile = new TileElevation(this, key); } else { tile = new TileImage(this, key); } tileLoader.addTile(tile); tiles.Add(tile); keys.Add(key); } } } return(tmp); }
void MakeTile(TileVector pos) { var newObj = Instantiate(TileObjects[_rng.Next(TileObjects.Length)]); // position and scale newObj.transform.position = pos.ToVector3(); newObj.transform.localScale = new Vector3(_scaleFactor, _scaleFactor, _scaleFactor); // rotate, to break up repetition newObj.transform.rotation = RandomDirection().GetBearingRotation(); // apply jitter (if enabled) if (JitterFactor > 0) { newObj.transform.position += GetJitter(pos); } // finally, add to our set of tile vectors _map.Add(pos); }
TileVector GetVectorForNewRoom(RoomType roomType) { if (avalibleRooms.Count > 0) { Room room = avalibleRooms[Random.Range(0, avalibleRooms.Count)]; TileVector vector = room.GetVectorForNewRoomAndRemoveDirection(roomType); if (!room.HaveUnusedDirections) { avalibleRooms.Remove(room); } return(vector); } else { throw new System.Exception("There are no avalibleRooms left."); } }
public IEnumerator MoveTo(TileVectorTriplet target) { TilePos = target.Horizontal; var from = transform.localPosition; var to = target.ToVector3(); var startTime = Time.time; var time = 0.5f; float t; do { t = (Time.time - startTime) / time; transform.localPosition = Vector3.Lerp(from, to, t); yield return(new WaitForFixedUpdate()); } while (t < 1); }
/// <summary> /// Creates a new Unit from a prefab. This includes adding it to the game logic, and creating a visual /// representation. The prefab provided should have a UnitAvatar script attatched, as well as any /// requirements of that script. This operation will fail if the given position is already occupied. /// </summary> /// <param name="unitPrefab">the prefab of the unit to create</param> /// <param name="pos">the TileVector position to spawn it</param> /// <param name="dir">the Direction for it to be facing</param> /// <param name="owner">the Player owner of the Unit</param> /// <param name="mirrored">whether or not the Unit is mirrored</param> /// <returns>true if the operation was successful; false if not</returns> public bool MakeUnit(GameObject unitPrefab, Player owner, TileVector pos, CardinalDirection dir, bool mirrored) { if (_gameOver || _playerUnitPlaced[owner]) { return(false); // stop players placing more than one unit } var avatar = Instantiate(unitPrefab).GetComponent <UnitAvatar>(); var unit = avatar.CreateUnit(owner, pos, dir, mirrored); if (!_worldController.AddUnit(unit)) // oops! bad unit placement, so delete the unit as if nothing happened { Destroy(avatar.gameObject); return(false); } else // successful placement { avatar.SetUnit(unit); _playerUnitPlaced[owner] = true; // set player as placed a unit _allAvatars.Add(avatar); avatar.EnqueueAnimation(new DeployAnimation(avatar)); var allPlaced = true; // check if all players have placed a unit foreach (var placed in _playerUnitPlaced.Values) { if (!placed) { allPlaced = false; break; } } if (allPlaced) // reset players' placement status and run game { DoTurn(); } return(true); } }
Vector2Int GetPositionWithLowestCoordinates(TileVector vector, int width, int height) { Vector2Int positionModyfication; if (vector.direction.IsNorth) { positionModyfication = new Vector2Int(Random.Range(-width, 1), 0); } else if (vector.direction.IsSouth) { positionModyfication = new Vector2Int(Random.Range(-width, 1), -height); } else if (vector.direction.IsEast) { positionModyfication = new Vector2Int(0, Random.Range(-height, 1)); } else { positionModyfication = new Vector2Int(-width, Random.Range(-height, 1)); } return(vector.position + positionModyfication); }
private void Start() { Animator = GetComponent <Animator>(); TilePos = new TileVector(0, 0); RotationOffset = Quaternion.Euler(RotationOffsetEuler); }
// Update is called once per frame void Update() { if (maxTiles == 0) { _selectedPos = Player.PlayerPlacables [selectedTile]; this.transform.position = Player.PlayerPlacables[selectedTile].ToVector3(); maxTiles = Player.PlayerPlacables.Count - 1; } // MOVEMENT // if (Input.GetKeyDown(MoveNorthKey)) MovePos(CardinalDirection.North); // if (Input.GetKeyDown(MoveNortheastKey)) MovePos(CardinalDirection.Northeast); // if (Input.GetKeyDown(MoveSoutheastKey)) MovePos(CardinalDirection.Southeast); // if (Input.GetKeyDown(MoveSouthKey)) MovePos(CardinalDirection.South); // if (Input.GetKeyDown(MoveSouthwestKey)) MovePos(CardinalDirection.Southwest); // if (Input.GetKeyDown(MoveNorthwestKey)) MovePos(CardinalDirection.Northwest); if (Input.GetKeyDown(MoveNorthKey)) { DirectionSelected(CardinalDirection.North); } if (Input.GetKeyDown(MoveSouthKey)) { DirectionSelected(CardinalDirection.South); } if (Input.GetKeyDown(RotateAnticlockwiseKey)) { RotateDir(RelativeDirection.ForwardLeft); } if (Input.GetKeyDown(RotateClockwiseKey)) { RotateDir(RelativeDirection.ForwardRight); } if (Input.GetKeyDown(MirrorToggleKey)) { ToggleMirror(); } if (Input.GetKeyDown(DeployKey)) { PlaceUnit(); } // UNIT SELECTION / PLACEMENT for (var i = 0; i < UnitSelectionKeys.Length; i++) { if (Input.GetKeyDown(UnitSelectionKeys[i])) { for (int j = 0; j < UnitSelectionKeys.Length; j++) { BackGroudImage [j].color = new Color32(205, 205, 205, 225); } BackGroudImage [i].color = _c; SelectUnit(i); break; } } }
void CreateFirstRoom() { TileVector vector = new TileVector(new Vector2Int(0, 0), new Direction(AvalibleDirection.North)); CreateRoomFromCreator(0, GetCreatorForNewRoom(), vector); }
public TileVectorTriplet(TileVector horizontal, int vertical = 0) { Horizontal = horizontal; Vertical = vertical; }
public static Vector3 ToVector3(this TileVector tv) { return(ToVec3.MultiplyPoint(new Vector3(tv.W, 0, tv.E))); }
public MoveAnimation(Mech unit, TileVector from, TileVector to) { _targetRot = (to - from).GetBearingRotation(); _targetPos = to.ToVector3(); _unit = unit; }
public StepPreview(TileVector pos, int index) { Pos = pos; Index = index; }
/// <summary> /// Get distance /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static int Distance(TileVector a, TileVector b) { var diff = b - a; return(Math.Max(diff.W, diff.E)); }
public CardinalDirection?GetApproximateDirectionTo(TileVector other) { return((other - this).GetApproximateDirection()); }
public static readonly Vector3 WVector = Quaternion.AngleAxis(120, Up) * EVector; // 120 from Southeast public static Vector3 ToVector3(this TileVector tv) { return(tv.W * WVector + tv.E * EVector); }
public void SetTiles(TileVector _tv) { tileVector = _tv; tilePanel.DataContext = _tv; }
public Room GetRoom(TileVector vector) { return(new Room(vector, roomPattern)); }