// smooth movement bool MoveTowards(DevGuy devGuy, int fromBlockInd, int toBlockInd, float speed) { bool destinationReached = false; float trajectory = fElapsedSeconds * speed; int toX, toY, fromX, fromY; waver.BlockIndexToCoords(toBlockInd, out toX, out toY); waver.BlockIndexToCoords(fromBlockInd, out fromX, out fromY); // these are here to account for the borders-of-the-map teleportation if ((fromX - toX) == (MapWidth - 1)) toX += MapWidth; else if ((toX - fromX) == (MapWidth - 1)) toX -= MapWidth; if ((fromY - toY) == (MapHeight - 1)) toY += MapHeight; else if ((toY - fromY) == (MapHeight - 1)) toY -= MapHeight; Vector2 destination = waver.BlockCoordsToPosition(toX, toY); Vector2 direction = destination - devGuy.Position; Vector2 directionN = direction; directionN.Normalize(); float dist = direction.magnitude; destinationReached = dist <= trajectory; if (destinationReached) { devGuy.Position = destination; } else { devGuy.Position += directionN * trajectory; } devGuy.Position = ValidatePosition(devGuy.Position); return destinationReached; }
bool CheckImmediateProximity(DevGuy devGuy, int devBlockInd, HouseIndices houseInds) { IndieHouseLocation location = GlobalObjects.indieHouseLocations[houseInds.houseInd]; bool overlaps = location.isPresent && location.Overlaps(devGuy) && devGuy.lastHousePointInd != houseInds.houseTileInd; if (overlaps) { if (!location.IsFull()) { location.AddDev(devGuy); return true; } } return false; }
public bool Overlaps(DevGuy devGuy) { Vector3 worldPos = devGuy.indieDevBehaviour.GetAIWorldTransform(); if (isPresent) { MeshFilter studioMesh = studio.GetComponent<MeshFilter>(); Transform transform = studio.GetComponent<Transform>(); var bounds = studioMesh.mesh.bounds; Vector3 localPos = transform.InverseTransformPoint(worldPos); bool inside = localPos.x <= bounds.center.x + bounds.extents.x; inside &= localPos.x >= bounds.center.x - bounds.extents.x; inside &= localPos.z <= bounds.center.z + bounds.extents.z; inside &= localPos.z >= bounds.center.z - bounds.extents.z; return inside; } return false; }
IndieDevBehavior() { aiDevGuy = new DevGuy(); aiDevGuy.indieDevBehaviour = this; }
public void AddDev(DevGuy devGuy) { studio.IndieDevCount++; IndieStudioBehavior.Destroy(devGuy.indieDevBehaviour.gameObject); }