private void UpdateThingyPositions() { foreach (Thingy thingy in thingies) { if (thingy.isGood) { int maxVelocity = 250; if (RXRandom.Float() < 0.2f) { thingy.xVelocity += RXRandom.Range(-100, 100); } if (RXRandom.Float() < 0.2f) { thingy.yVelocity += RXRandom.Range(-100, 100); } if (thingy.xVelocity > maxVelocity) { thingy.xVelocity = maxVelocity; } if (thingy.xVelocity < -maxVelocity) { thingy.xVelocity = -maxVelocity; } if (thingy.yVelocity > maxVelocity) { thingy.yVelocity = maxVelocity; } if (thingy.yVelocity < -maxVelocity) { thingy.yVelocity = -maxVelocity; } } float deltaX = thingy.xVelocity * Time.deltaTime; float deltaY = thingy.yVelocity * Time.deltaTime; FSprite sprite = thingy.GetChildAt(0) as FSprite; Vector2 maxes = sprite.GetGlobalTextureRectMaxes(); Vector2 mins = sprite.GetGlobalTextureRectMins(); if (maxes.x + deltaX > playAreaRect.width) { deltaX = playAreaRect.width - maxes.x; thingy.xVelocity *= -1; } else if (mins.x + deltaX < 0) { deltaX = -mins.x; thingy.xVelocity *= -1; } if (maxes.y + deltaY > playAreaRect.height) { deltaY = playAreaRect.height - maxes.y; thingy.yVelocity *= -1; } else if (mins.y + deltaY < 0) { deltaY = -mins.y; thingy.yVelocity *= -1; } thingy.x += deltaX; thingy.y += deltaY; } }