/// <summary> /// Sets the path for the object to follow. /// </summary> /// <param name="path">The path to follow.</param> /// <param name="speed">The velocity or acceleration of the object as it moves along the path.</param> /// <param name="type">The path movement type.</param> /// <param name="axis">The allowed movement axis of the object.</param> /// <param name="movement">Determines whether to set the object's velocity or acceleration as it moves along the path.</param> /// <returns>The path that was set.</returns> public GenPath SetPath( GenPath path, float speed, GenPath.Type type = GenPath.Type.Clockwise, GenMove.Axis axis = GenMove.Axis.Both, GenPath.Movement movement = GenPath.Movement.Instant) { Path = path; PathSpeed = speed; PathType = type; PathAxis = axis; PathMovement = movement; // Set the initial path node index relative to the path movement type. switch (PathType) { case GenPath.Type.Counterclockwise: PathNodeIndex = Path.Nodes.Count - 1; break; case GenPath.Type.Random: PathNodeIndex = GenU.Random(0, Path.Nodes.Count); break; default: PathNodeIndex = 0; break; } return path; }
/// <summary> /// A physical object that can be moved around in screen space. /// </summary> /// <param name="x">The x position of the top-left corner of the object.</param> /// <param name="y">The y position of the top-left corner of the object.</param> /// <param name="width">The width of the object.</param> /// <param name="height">The height of the object.</param> public GenObject(float x, float y, float width, float height) { _position = new Vector2(x, y); _oldPosition = _position; _hasMoved = false; _bounds = new GenAABB(x, y, width, height); _centerPosition = new Vector2(x + _bounds.HalfWidth, y + _bounds.HalfHeight); _origin = new Vector2(_bounds.HalfWidth, _bounds.HalfHeight); _originPosition = new Vector2(x + _origin.X, y + _origin.Y); _boundingRect = new Rectangle(0, 0, (int)width, (int)height); _rotation = 0f; RotationSpeed = 0f; _moveDistance = Vector2.Zero; _moveBounds = new GenAABB(x, y, width, height); Immovable = false; Solid = true; Mass = 1f; Velocity = Vector2.Zero; OldVelocity = Velocity; Acceleration = Vector2.Zero; Deceleration = Vector2.Zero; MaxVelocity = Vector2.Zero; _facing = Direction.None; OldTouching = Direction.None; Touching = Direction.None; Parent = null; ParentMode = ParentType.None; ParentOffset = Vector2.Zero; IsPlatform = false; Platform = null; OldPlatform = null; Path = null; PathNodeIndex = 0; PathDirection = 1; PathSpeed = 0f; PathType = GenPath.Type.Clockwise; PathAxis = GenMove.Axis.Both; PathMovement = GenPath.Movement.Instant; }