/// <summary> /// Updates the following entity associated with this process. /// </summary> /// <param name="deltaTime">Elapsed time since last frame.</param> public override void Run(float deltaTime) { //if (_entity.IsEnabled == false) return; Transformation entityTransform = _entity.CalculateTransformation(); if (_entity is CameraNode) { entityTransform.X = -entityTransform.X; entityTransform.Y = -entityTransform.Y; } entityTransform.X = (int)entityTransform.X; entityTransform.Y = (int)entityTransform.Y; // Are we using a rectangle or entity as the boundry? Rectangle boundry = new Rectangle((int)_boundry.X, (int)_boundry.Y, (int)_boundry.Width, (int)_boundry.Height); if (_entityBoundry != null) { Transformation boundryTransform = _entityBoundry.CalculateTransformation(); if (_entityBoundry is CameraNode) { boundryTransform.X = -boundryTransform.X; boundryTransform.Y = -boundryTransform.Y; } boundryTransform.X = (int)boundryTransform.X; boundryTransform.Y = (int)boundryTransform.Y; boundry = new Rectangle((int)boundryTransform.X, (int)boundryTransform.Y, (int)(_entityBoundry.Width * boundryTransform.ScaleX), (int)(_entityBoundry.Height * boundryTransform.ScaleY)); } float x = entityTransform.X; // Cast to int to fix jittering bugs. float y = entityTransform.Y; // Cast to int to fix jittering bugs. if (x < boundry.Left) { x = boundry.Left; } if (y < boundry.Top) { y = boundry.Top; } if (x > boundry.Right - (_entity.BoundingRectangle.Width * entityTransform.ScaleX)) { x = (int)(boundry.Right - (_entity.BoundingRectangle.Width * entityTransform.ScaleX)); } if (y > boundry.Bottom - (_entity.BoundingRectangle.Height * entityTransform.ScaleY)) { y = (int)(boundry.Bottom - (_entity.BoundingRectangle.Height * entityTransform.ScaleY)); } if (!float.IsNaN(x) && !float.IsNaN(y)) { _entity.Position(x, y, _entity.Transformation.Z); } }
public void RenderEntity(ScriptThread thread) { EntityNode entity = ((NativeObject)thread.GetObjectParameter(0)).Object as EntityNode; if (entity == null) { DebugLogger.WriteLog((thread.Process.Url != null && thread.Process.Url != "" ? thread.Process.Url : "A script") + " called RenderEntity with an invalid object.", LogAlertLevel.Error); return; } Transformation transformation = entity.CalculateTransformation(); entity.Render(new Transformation(thread.GetFloatParameter(1) - transformation.X, thread.GetFloatParameter(2) - transformation.Y, thread.GetFloatParameter(3), 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f), null, entity.DepthLayer); }
/// <summary> /// Initializes a new instance of this class. /// </summary> /// <param name="entity">Entity that will be moving.</param> /// <param name="x">X position to move to.</param> /// <param name="y">Y position to move to.</param> /// <param name="speed">Speed at which entity moves.</param> public EntityMoveToProcess(EntityNode entity, float x, float y, StartFinishF speed) { _entity = entity; _followSpeed = speed; _x = x; _y = y; Transformation entityTransform = _entity.CalculateTransformation(); float vectorX = entityTransform.X - _x; float vectorY = entityTransform.Y - _y; _originalDistance = (float)Math.Sqrt(vectorX * vectorX + vectorY * vectorY); }
/// <summary> /// Renders the event lines of this entity. /// </summary> /// <param name="transformation">Transformation to render event lines at.</param> protected override void RenderEventLines(Transformation transformation, CameraNode camera) { GraphicsManager.PushRenderState(); GraphicsManager.ClearRenderState(); GraphicsManager.DepthBufferEnabled = false; GraphicsManager.VertexColors.AllVertexs = _eventLineColor; // Normal. foreach (SceneNode node in _eventNodes) { EntityNode entityNode = node as EntityNode; if (entityNode == null) { continue; } Transformation relativeTransformation = entityNode.CalculateTransformation(camera); int x1 = (int)(transformation.X + ((_boundingRectangle.Width * transformation.ScaleX) / 2)); int y1 = (int)(transformation.Y + ((_boundingRectangle.Height * transformation.ScaleY) / 2)); int x2 = (int)(relativeTransformation.X + ((entityNode.BoundingRectangle.Width * relativeTransformation.ScaleX) / 2)); int y2 = (int)(relativeTransformation.Y + ((entityNode.BoundingRectangle.Height * relativeTransformation.ScaleY) / 2)); GraphicsManager.RenderLine(x1, y1, transformation.Z, x2, y2, relativeTransformation.Z); } // Our special ones! GraphicsManager.VertexColors.AllVertexs = _pathLineColor; if (_nextNode != null) { Transformation relativeTransformation = _nextNode.CalculateTransformation(camera); int x1 = (int)(transformation.X + ((_boundingRectangle.Width * transformation.ScaleX) / 2)); int y1 = (int)(transformation.Y + ((_boundingRectangle.Height * transformation.ScaleY) / 2)); int x2 = (int)(relativeTransformation.X + ((_nextNode._boundingRectangle.Width * relativeTransformation.ScaleX) / 2)); int y2 = (int)(relativeTransformation.Y + ((_nextNode._boundingRectangle.Height * relativeTransformation.ScaleY) / 2)); GraphicsManager.RenderLine(x1, y1, transformation.Z, x2, y2, relativeTransformation.Z); } GraphicsManager.PopRenderState(); }
/// <summary> /// Updates the following entity associated with this process. /// </summary> /// <param name="deltaTime">Elapsed time since last frame.</param> public override void Run(float deltaTime) { //if (_entity.IsEnabled == false) return; CameraNode camera = _entity as CameraNode; // Work out the central points. Transformation entityTransform = _entity.CalculateTransformation(); Transformation targetTransform = _targetEntity.CalculateTransformation(); // If its a camera then we need to invert the coordinates as it uses // slightly different ones from normal entities. if (camera != null) { entityTransform.X = -entityTransform.X; entityTransform.Y = -entityTransform.Y; } float entityTransformCenterX = entityTransform.X + ((_entity.BoundingRectangle.Width / 2) * entityTransform.ScaleX); float entityTransformCenterY = entityTransform.Y + ((_entity.BoundingRectangle.Height / 2) * entityTransform.ScaleY); float targetEntityTransformCenterX = targetTransform.X + ((_targetEntity.BoundingRectangle.Width / 2) * targetTransform.ScaleX); float targetEntityTransformCenterY = targetTransform.Y + ((_targetEntity.BoundingRectangle.Height / 2) * targetTransform.ScaleY); float vectorX = entityTransformCenterX - targetEntityTransformCenterX; float vectorY = entityTransformCenterY - targetEntityTransformCenterY; float distance = (float)Math.Sqrt(vectorX * vectorX + vectorY * vectorY); vectorX /= distance; vectorY /= distance; // Are we set to instantly snap to the target? if (_bufferZoneRadius == 0.0f || _followSpeed == 0.0f) { _entity.Position((float)Math.Floor(targetEntityTransformCenterX - ((_entity.BoundingRectangle.Width / 2) * entityTransform.ScaleX)), (float)Math.Floor(targetEntityTransformCenterY - ((_entity.BoundingRectangle.Width / 2) * entityTransform.ScaleX)), targetTransform.Z); return; } // Are we at the correct place? If so why bother with the below code :P. if (entityTransformCenterX == targetEntityTransformCenterX && entityTransformCenterY == targetEntityTransformCenterY) { return; } // Are we in the stationary buffer zone? if (distance <= _bufferZoneRadius) { return; // Yep. } distance = (int)distance; // Work out vector towards entity. float scaleAmount = (distance / _bufferZoneRadius); //if (distance > _bufferZoneRadius * 2) scaleAmount *= 2; float movementX = (float)Math.Round(vectorX * (_followSpeed * scaleAmount), 1); // *deltaTime; float movementY = (float)Math.Round(vectorY * (_followSpeed * scaleAmount), 1); // *deltaTime; movementX = (int)movementX; movementY = (int)movementY; if (!float.IsNaN(movementX) && !float.IsNaN(movementY)) { _entity.Move(-movementX, -movementY, 0.0f); } }
/// <summary> /// Updates the following entity associated with this process. /// </summary> /// <param name="deltaTime">Elapsed time since last frame.</param> public override void Run(float deltaTime) { //if (_entity.IsEnabled == false) return; // Work out the central points. Transformation entityTransform = _entity.CalculateTransformation(); // If its a camera then we need to invert the coordinates as it uses // slightly different ones from normal entities. if (_entity is CameraNode) { entityTransform.X = -entityTransform.X; entityTransform.Y = -entityTransform.Y; } // Are we at the correct place? If so why bother with the below code :P. if (entityTransform.X == _x && entityTransform.Y == _y) { Finish(ProcessResult.Success); return; } // If we can't move then finish. if (_gotPreviousTransformation == true) { if (_previousTransformation.X == entityTransform.X && _previousTransformation.Y == entityTransform.Y && _previousTransformation.Z == entityTransform.Z) { if (_previousTransformationTimer.DurationMillisecond > 500) // Half a second and no movement O_o, oh shiz we must have something in out way. { Finish(ProcessResult.Failed); return; } } else { _previousTransformationTimer.Restart(); _previousTransformation = entityTransform; } } else { _previousTransformation = entityTransform; _previousTransformationTimer.Restart(); _gotPreviousTransformation = true; } float entityTransformCenterX = entityTransform.X + ((_entity.BoundingRectangle.Width / 2) * entityTransform.ScaleX); float entityTransformCenterY = entityTransform.Y + ((_entity.BoundingRectangle.Height / 2) * entityTransform.ScaleY); float vectorX = entityTransformCenterX - _x; float vectorY = entityTransformCenterY - _y; float distance = (float)Math.Sqrt(vectorX * vectorX + vectorY * vectorY); vectorX /= distance; vectorY /= distance; float followSpeed = _followSpeed.Start + (((_followSpeed.Finish - _followSpeed.Start) / _originalDistance) * (_originalDistance - distance)); // Work out vector towards entity. float movementX = (vectorX * followSpeed) * deltaTime; float movementY = (vectorY * followSpeed) * deltaTime; _entity.Move(-movementX, -movementY, 0.0f); // Are we done yet? if (Math.Abs(Math.Round(distance)) <= Math.Max(1, _followSpeed.Finish) * 2)// || followSpeed == _followSpeed.Finish) { Finish(ProcessResult.Success); return; } }