private void UpdateRadius() { if (data.GetRadius() != radius) { radius = data.GetRadius(); transform.localScale = new Vector3(radius, radius, 1); } }
public void SetData(CircleData data) { this.data = data; if (spriteRenderer == null) { InitializeSprite(data.GetColor()); } this.radius = data.GetRadius(); UpdateRadius(); UpdatePosition(); }
private void CheckCollisionWithWalls(CircleData circle, float deltaTime) { var position = circle.GetPosition(); var radius = circle.GetRadius(); var invertX = false; var invertY = false; float deltaX = 0; float deltaY = 0; if (position.x + radius > halfWidth) { invertX = true; deltaX = halfWidth - position.x - radius; } else if (position.x - radius < -halfWidth) { invertX = true; deltaX = -halfWidth - position.x + radius; } if (position.y + radius > halfHeight) { invertY = true; deltaY = halfHeight - position.y - radius; } else if (position.y - radius < -halfHeight) { invertY = true; deltaY = -halfHeight - position.y + radius; } float updateTimeX = 0; float updateTimeY = 0; var speed = circle.GetSpeed(); if (invertX) { updateTimeX = deltaX / speed.x; } if (invertY) { updateTimeY = deltaY / speed.y; } if (invertX || invertY) { var updateTime = Mathf.Min(updateTimeX, updateTimeY); circle.UpdatePosition(updateTime); circle.InvertSpeed(invertX, invertY); circle.UpdatePosition(-updateTime); } }
public bool SpawnCircle(CircleData circle) { var circlePosition = circle.GetPosition(); var circleRadius = circle.GetRadius(); foreach (var circleOnField in circles) { var minDistance = circleRadius + circleOnField.GetRadius(); var distance = (circlePosition - circleOnField.GetPosition()).magnitude; if (minDistance > distance) { return(false); } } circles.Add(circle); return(true); }