지네와 같은 조각 된 생물을 상상해보십시오. 헤드 세그먼트의 제어로, 바디 세그먼트는 이전 바디 세그먼트에 포인트로 첨부됩니다.Point (1) 또는 Vector2 (1)에 Point (2) 또는 Vector2 (2)를 유지하십시오.
머리가 움직이면서 (지금은 8 추기경/추기경 방향으로) 점은 회전과 관련하여 움직입니다.
public static Vector2 RotatePoint(Vector2 pointToRotate, Vector2 centerOfRotation, float angleOfRotation)
{
Matrix rotationMatrix = Matrix.CreateRotationZ(angleOfRotation);
return Vector2.Transform(pointToRotate - centerOfRotation, rotationMatrix);
}
여기에 다이어그램을 게시하는 거라고하지만 당신은 알고 ...
center(2) point(2) center(1) point(1)
point(1)
point(2) ^ |
/\ |
| |
center(2) center(1) \/
V
나는 기본 스프라이트 사각형 속성/필드를 사용하여 생각을 한
private Rectangle bounds = new Rectangle(-16, 16, 32, 32);
및 본문 세그먼트 내의 사전 정의 된 점이 헤드 스프라이트 경계 내에 있는지 확인합니다.
비록 내가 현재하고있는 중이 야 :
private static void handleInput(GameTime gameTime)
{
Vector2 moveAngle = Vector2.Zero;
moveAngle += handleKeyboardMovement(Keyboard.GetState()); // basic movement, combined to produce 8 angles
// of movement
if (moveAngle != Vector2.Zero)
{
moveAngle.Normalize();
baseAngle = moveAngle;
}
BaseSprite.RotateTo(baseAngle);
BaseSprite.LeftAnchor = RotatePoint(BaseSprite.LeftAnchor,
BaseSprite.RelativeCenter, BaseSprite.Rotation); // call RotatePoint method
BaseSprite.LeftRect = new Rectangle((int)BaseSprite.LeftAnchor.X - 1,
(int)BaseSprite.LeftAnchor.Y - 1, 2, 2);
// All segments use a field/property that is a point which is suppose to rotate around the center
// point of the sprite (left point is (-16,0) right is (16,0) initially
// I then create a rectangle derived from that point to make use of the .Intersets method of the
// Rectangle class
BodySegmentOne.RightRect = BaseSprite.LeftRect; // make sure segments are connected?
BaseSprite.Velocity = moveAngle * wormSpeed;
//BodySegmentOne.RightAnchor = BaseSprite.LeftAnchor;
if (BodySegmentOne.RightRect.Intersects(BaseSprite.LeftRect)) // as long as there two rects occupy the
{ // same space move segment with head
BodySegmentOne.Velocity = BaseSprite.Velocity;
}
}
지금의 약자로서
, 머리 만 병렬 방식으로 세그먼트로 이동합니다. 헤드가 끌고 갈 때 세그먼트의 움직임을 좀 더 뉘앙 거리게하고 싶습니다.나는이 운동의 코딩이 내가 여기있는 것보다 훨씬 더 복잡 할 것이라는 것을 이해한다. 이 문제를 어떻게보아야하는지에 대한 몇 가지 힌트 나 지시 사항은 크게 감사하겠습니다.
직접 구현 하시겠습니까? 아니면 Farseer (http://farseerphysics.codeplex.com)와 같은 물리 엔진을 사용해도 괜찮습니까? 내가 묻는 이유는 당신이하고 싶은 것이 사소하지 않고 물리 엔진 개념에 대한 지식을 필요로한다는 것입니다. – Ani
공칭 솔루션은 내 솔루션을 작성하는 것입니다. 그러나 기존 시스템을 사용하면 내 능력을 가속화하여 모든 솔루션을 제공 할 수 있으며 Farseer를 더 자세히 살펴볼 것입니다. – Dialock