public override void MakePreparations(Living living) { ComponentSelectable entityData = living.GetExactComponent <ComponentSelectable>(); Point2D start = entityData.MapLocation; if (start != this.Destination) { List <PathLink> pth; ComponentMovement movementComponent = living.GetExactComponent <ComponentMovement>(); //Handle reroute if (movementComponent.QueuedMovement.Count > 0) { //Get a path to the nearest/next tile so that path finding and the screen location sync up. PathLink previous = movementComponent.QueuedMovement.Peek(); movementComponent.QueuedMovement.Clear(); movementComponent.QueuedMovement.Enqueue(previous); pth = MainPathFinder.GetRoute(living.Dimension, previous.Destination, this.Destination); } //No reroute else { pth = MainPathFinder.GetRoute(living.Dimension, start, this.Destination); } MagicalLifeAPI.Util.Extensions.EnqueueCollection(movementComponent.QueuedMovement, pth); ClientSendRecieve.Send <RouteCreatedMessage>(new RouteCreatedMessage(pth, living.ID, living.Dimension)); } }
private float motorAngleFactor = 0.025f; // 90 degree angle rotates plexi by 15 degree. private void Awake() { xMaxValue = 320f; xMinValue = 0f; yMaxValue = 240f; yMinValue = 0f; distanceMaxValue = 100f; distanceMinValue = 0f; originXValue = (xMaxValue - xMinValue) / 2f; originYValue = (yMaxValue - yMinValue) / 2f; distanceFactor = 6f / distanceMaxValue; xFactor = 8f / xMaxValue; yFactor = 6f / yMaxValue; drawGraph = GraphObject.GetComponent <Hard_DrawGraph>(); ballTransform = ballObject.GetComponent <Transform>(); uiHandler = UIObject.GetComponent <Hard_UIHandler>(); blHandler = BallLocationHandlerObject.GetComponent <Hard_BallLocationHandler>(); bhHandler = BallHeightObject.GetComponent <Hard_BallHeightHandler>(); cMovement = ComponentMovementObject.GetComponent <ComponentMovement>(); clientSide = ClientSideObject.GetComponent <ClientSide>(); }
private void RespondPlayerGhost(Entity player, Entity ghost) { //Debug.WriteLine("collision between player and ghost"); //if ghost is chasing { //play ghost sound ComponentTransform ghostTransform = (ComponentTransform)ghost.FindComponent(ComponentTypes.COMPONENT_TRANSFORM); ComponentAudio ghostAudio = (ComponentAudio)ghost.FindComponent(ComponentTypes.COMPONENT_AUDIO); Vector3 emitterPosition = (ghostTransform).Position; int source = (ghostAudio).Source; AL.Source(source, ALSource3f.Position, ref emitterPosition); ghostAudio.Play(); //kill player ComponentLives livesComponent = (ComponentLives)player.FindComponent(ComponentTypes.COMPONENT_LIVES); livesComponent.Lives -= 1; ComponentTransform transformComponent = (ComponentTransform)player.FindComponent(ComponentTypes.COMPONENT_TRANSFORM); transformComponent.Position = new Vector3(0, 1, 2); ComponentMovement movementComponent = (ComponentMovement)player.FindComponent(ComponentTypes.COMPONENT_MOVEMENT); movementComponent.DesiredLocation = new Vector3(0, 1, 2); } //else if ghost is fleeing //kill ghost //add 100 points to player }
public void OnAction(Entity entity) { if ((entity.Mask & mask) == mask) { ComponentTransform transformComponent = (ComponentTransform)entity.FindComponent(ComponentTypes.COMPONENT_TRANSFORM); ComponentMovement movementComponent = (ComponentMovement)entity.FindComponent(ComponentTypes.COMPONENT_MOVEMENT); transformComponent.Position = movementComponent.DesiredLocation; } }
private void RespondCreatureWall(Entity creature, Entity wall) { //dont allow them to move //Debug.WriteLine("collsion between creature and wall"); ComponentTransform transformComponent = (ComponentTransform)creature.FindComponent(ComponentTypes.COMPONENT_TRANSFORM); Vector3 position = transformComponent.Position; ComponentMovement movementComponent = (ComponentMovement)creature.FindComponent(ComponentTypes.COMPONENT_MOVEMENT); Vector3 desiredLocation = movementComponent.DesiredLocation; movementComponent.DesiredLocation = position; }
/// <summary> /// Moves the entity as far along on its path as possible. /// </summary> /// <param name="entity"></param> public static void MoveEntity(Living entity) { ComponentMovement movementComponent = entity.GetExactComponent <ComponentMovement>(); ProtoQueue <PathLink> path = movementComponent.QueuedMovement; while (movementComponent.Movement.GetValue() > 0 && path.Count > 0) { PathLink section = path.Peek(); Tile sourceTile = World.Data.World.Dimensions[entity.Dimension][section.Origin.X, section.Origin.Y]; Tile destinationTile = World.Data.World.Dimensions[entity.Dimension][section.Destination.X, section.Destination.Y]; Move(entity, sourceTile, destinationTile); } }
private static void FootStepSound(Living living, Tile footStepsOn) { ComponentMovement movementComponent = living.GetExactComponent <ComponentMovement>(); if (movementComponent.FootStepTimer.Allow()) { Point2DFloat screenLocation = new Point2DFloat((float)movementComponent.TileLocation.X, (float)movementComponent.TileLocation.Y); screenLocation.X *= Tile.GetTileSize().X; screenLocation.Y *= Tile.GetTileSize().Y; FMODUtil.RaiseEvent(SoundsTable.FootSteps, "Material", footStepsOn.FootStepSound, screenLocation.ToPoint2D()); } }
public void OnAction(Entity entity) { if ((entity.Mask & MASK) == MASK) { ComponentTransform transformComponent = (ComponentTransform)entity.FindComponent(ComponentTypes.COMPONENT_TRANSFORM); Vector3 location = transformComponent.Position; ComponentMovement movementComponent = (ComponentMovement)entity.FindComponent(ComponentTypes.COMPONENT_MOVEMENT); Vector3 velocity = movementComponent.Velocity; velocity.Y = 0; location += velocity * SceneManager.dt; movementComponent.DesiredLocation = location; } }
private static void Uni_TickEvent(object sender, ulong e) { lock (SyncObject) { foreach (Dimension ii in World.Dimensions) { int chunkWidth = ii.Width; int chunkHeight = ii.Height; for (int chunkX = 0; chunkX < chunkWidth; chunkX++) { for (int chunkY = 0; chunkY < chunkHeight; chunkY++) { Chunk chunk = ii.GetChunk(chunkX, chunkY); List <Guid> keys = chunk.Creatures.Keys.ToList(); int length = keys.Count; for (int i = 0; i < length; i++) { chunk.Creatures.TryGetValue(keys[i], out Living l); if (l != null) { ComponentMovement movementComponent = l.GetExactComponent <ComponentMovement>(); movementComponent.Movement.WearOff(); if (movementComponent.QueuedMovement.Count > 0) { EntityWorldMovement.MoveEntity(l); } if (l.Task != null && !l.Task.IsFinished) { l.Task.Tick(l); } else { TaskManager.Manager.AssignTask(l); //Find a job } } } } } } } }
private Vector3 GetPosition(Entity entity) { Vector3 position; if (entity.HasComponent(ComponentTypes.COMPONENT_MOVEMENT)) { ComponentMovement movementComponent = (ComponentMovement)entity.FindComponent(ComponentTypes.COMPONENT_MOVEMENT); position = movementComponent.DesiredLocation; } else { ComponentTransform transformComponent = (ComponentTransform)entity.FindComponent(ComponentTypes.COMPONENT_TRANSFORM); position = transformComponent.Position; } return(position); }
/// <summary> /// Draws the entities. /// </summary> /// <param name="dimension">The dimension.</param> /// <param name="chunk">The chunk.</param> public static void DrawEntities(int dimension, Chunk chunk) { int length = chunk.Creatures.Count; lock (chunk.Creatures) { for (int i = 0; i < length; i++) { KeyValuePair <System.Guid, Living> item = chunk.Creatures.ElementAt(i); if (item.Value != null) { ComponentMovement movementComponent = item.Value.GetExactComponent <ComponentMovement>(); LivingScreenLocation.X = (int)(movementComponent.TileLocation.X * TileSize.X); LivingScreenLocation.Y = (int)(movementComponent.TileLocation.Y * TileSize.Y); item.Value.Visual.Render(MapDrawer, LivingScreenLocation); } } } }
private Matrix4 GetTransform(Entity entity, bool shouldScale) { Matrix4 transformMatrix; ComponentTransform transformComponent = (ComponentTransform)entity.FindComponent(ComponentTypes.COMPONENT_TRANSFORM); Matrix4 translationMatrix; if (entity.HasComponent(ComponentTypes.COMPONENT_MOVEMENT)) { ComponentMovement movementComponent = (ComponentMovement)entity.FindComponent(ComponentTypes.COMPONENT_MOVEMENT); translationMatrix = Matrix4.CreateTranslation(movementComponent.DesiredLocation); } else { translationMatrix = transformComponent.PositionMatrix; } Matrix4 scaleMatrix; if (shouldScale) { scaleMatrix = transformComponent.ScaleMatrix; } else { scaleMatrix = Matrix4.CreateScale(1, 1, 1); //this } //scaleMatrix = transformComponent.ScaleMatrix; //Matrix4 rotationMatrix = transformComponent.RotationMatrix; Matrix4 rotationMatrix = Matrix4.Identity; transformMatrix = scaleMatrix * rotationMatrix * translationMatrix; //transformMatrix = rotationMatrix * scaleMatrix * translationMatrix; return(transformMatrix); }
private void Move(HasComponents selectable, Point2D target) { if (World.Dimensions[RenderInfo.Dimension][target.X, target.Y].IsWalkable) { switch (selectable) { case Living living: ComponentSelectable positionData = living.GetExactComponent <ComponentSelectable>(); Point2D start = positionData.MapLocation; if (start != target) { List <PathLink> pth; ComponentMovement movementComponent = living.GetExactComponent <ComponentMovement>(); //Handle reroute if (movementComponent.QueuedMovement.Count > 0) { //Get a path to the nearest/next tile so that path finding and the screen location sync up. PathLink previous = movementComponent.QueuedMovement.Peek(); movementComponent.QueuedMovement.Clear(); movementComponent.QueuedMovement.Enqueue(previous); pth = MainPathFinder.GetRoute(RenderInfo.Dimension, previous.Destination, target); } //No reroute else { pth = MainPathFinder.GetRoute(RenderInfo.Dimension, positionData.MapLocation, target); } Extensions.EnqueueCollection(movementComponent.QueuedMovement, pth); } break; default: break; } } }
public override void HandleMessage(BaseMessage message) { RouteCreatedMessage msg = (RouteCreatedMessage)message; if (this.Validated(msg.Path, msg.Dimension)) { Point2D location = msg.Path[0].Origin; Point2D chunkLocation = WorldUtil.CalculateChunkLocation(location); Chunk chunk = World.GetChunk(msg.Dimension, chunkLocation.X, chunkLocation.Y); Living l = chunk.Creatures.Where(t => t.Value.GetExactComponent <ComponentSelectable>().MapLocation.Equals(location)).ElementAt(0).Value; if (l != null && l.ID == msg.LivingID) { ComponentMovement movementComponent = l.GetExactComponent <ComponentMovement>(); movementComponent.QueuedMovement.Clear(); MagicalLifeAPI.Util.Extensions.EnqueueCollection <PathLink>(movementComponent.QueuedMovement, msg.Path); } } else { MasterLog.DebugWriteLine("Server received invalid path"); } }
/// <summary> /// Moves the entity in a direction. /// </summary> /// <param name="entity"></param> /// <param name="source"></param> /// <param name="destination"></param> public static void Move(Living entity, Tile source, Tile destination) { ComponentSelectable sLocation = source.GetExactComponent <ComponentSelectable>(); ComponentSelectable dLocation = destination.GetExactComponent <ComponentSelectable>(); Direction direction = DetermineMovementDirection(sLocation.MapLocation, dLocation.MapLocation); float xMove = 0; float yMove = 0; AnimatedTexture animated = (AnimatedTexture)entity.Visual; switch (direction) { case Direction.North: yMove = -1; animated.StartSequence(Human.UpSequence); break; case Direction.South: yMove = 1; animated.StartSequence(Human.DownSequence); break; case Direction.East: xMove = 1; animated.StartSequence(Human.RightSequence); break; case Direction.West: xMove = -1; animated.StartSequence(Human.LeftSequence); break; case Direction.NorthWest: xMove = -1; yMove = -1; break; case Direction.NorthEast: xMove = 1; yMove = -1; break; case Direction.SouthWest: xMove = -1; yMove = 1; break; case Direction.SouthEast: xMove = 1; yMove = 1; break; default: throw new InvalidOperationException("Unexpected value for direction: " + direction.ToString()); } ComponentMovement movementComponent = entity.GetExactComponent <ComponentMovement>(); xMove *= (float)movementComponent.Movement.GetValue(); yMove *= (float)movementComponent.Movement.GetValue(); float movementPenalty = (float)Math.Abs(CalculateMovementReduction(xMove, yMove)) * -1; if (MathUtil.GetDistance(movementComponent.TileLocation, dLocation.MapLocation) > movementComponent.Movement.GetValue()) { //The character fell short of reaching the next tile movementComponent.TileLocation = new Point2DDouble((float)movementComponent.TileLocation.X + xMove, (float)movementComponent.TileLocation.Y + yMove); FootStepSound(entity, source); } else { //The character made it to the next tile. entity.GetExactComponent <ComponentSelectable>().MapLocation = dLocation.MapLocation; movementComponent.TileLocation = new DataTypes.Point2DDouble(dLocation.MapLocation.X, dLocation.MapLocation.Y); movementComponent.QueuedMovement.Dequeue(); movementPenalty = (float)MathUtil.GetDistance(movementComponent.TileLocation, dLocation.MapLocation); FootStepSound(entity, destination); //If this entity is the current client's and therefore that clients responsibility to report about if (entity.PlayerID == SettingsManager.PlayerSettings.Settings.PlayerID) { ClientSendRecieve.Send(new WorldModifierMessage(new LivingLocationModifier(entity.ID, sLocation.MapLocation, dLocation.MapLocation, entity.Dimension))); } } movementComponent.Movement.AddModifier(new ModifierDouble(movementPenalty, new TimeRemoveCondition(1), Lang.NormalMovement)); }
public void OnAction(Entity entity) { if ((entity.Mask & MASK) == MASK) { ComponentMovement movementComponent = (ComponentMovement)entity.FindComponent(ComponentTypes.COMPONENT_MOVEMENT); ComponentAIGhost aiComponent = (ComponentAIGhost)entity.FindComponent(ComponentTypes.COMPONENT_AI_GHOST); string targetID = aiComponent.Target; //get the target location Entity target = entityManager.FindEntity(targetID); if (target != null && target.HasComponent(ComponentTypes.COMPONENT_TRANSFORM)) { ComponentTransform transformComponent = (ComponentTransform)entity.FindComponent(ComponentTypes.COMPONENT_TRANSFORM); ComponentTransform targetTransform = (ComponentTransform)target.FindComponent(ComponentTypes.COMPONENT_TRANSFORM); Vector3 ghostPosition = transformComponent.Position; Vector3 targetPosition = targetTransform.Position; //get direction between entity and target Vector3 direction = targetPosition - ghostPosition; direction.Y = 0; if (direction.Length != 0) { direction.Normalize(); } //set direction to max speed of ghost if (movementComponent.HasMaxSpeed) { direction *= movementComponent.MaxSpeed; } //set velocity if (state == GhostAIState.Chasing) { movementComponent.Velocity = direction; } else if (state == GhostAIState.Fleeing) { movementComponent.Velocity = -direction; } else if (state == GhostAIState.Dead) { //stay still for a time TimeSpan timeSinceDeath = DateTime.Now - aiComponent.DeathTime; if (timeSinceDeath.Seconds >= 5) { state = GhostAIState.Chasing; } else { movementComponent.Velocity = new Vector3(0, 0, 0); } } } else { movementComponent.Velocity = new Vector3(0, 0, 0); } } }
public void OnAction(Entity entity) { if ((entity.Mask & mask) == mask) { ComponentPlayerControl playerControl = (ComponentPlayerControl)entity.FindComponent(ComponentTypes.COMPONENT_PLAYER_CONTROL); if (playerControl.Enabled) { ComponentTransform transformComponent = (ComponentTransform)entity.FindComponent(ComponentTypes.COMPONENT_TRANSFORM); ComponentMovement movementComponent = (ComponentMovement)entity.FindComponent(ComponentTypes.COMPONENT_MOVEMENT); Vector3 rotation = transformComponent.Rotation; float maxSpeed; if (movementComponent.HasMaxSpeed) { maxSpeed = movementComponent.MaxSpeed; } else { maxSpeed = 0.5f; } Vector3 velocity = new Vector3(0, 0, 0); //movement if (sceneManager.KeyPressed(Key.Up)) { //move entity forward Matrix4 turn = Matrix4.CreateRotationY(0f); //0 degrees Matrix4 facing = Matrix4.CreateRotationY(rotation.Y); Vector4 moveVector = turn * facing * new Vector4(0, 0, -1, 0); velocity += moveVector.Xyz * maxSpeed; } if (sceneManager.KeyPressed(Key.A)) { //move entity left Matrix4 turn = Matrix4.CreateRotationY(-1.5708f); //90 degrees left Matrix4 facing = Matrix4.CreateRotationY(rotation.Y); Vector4 moveVector = turn * facing * new Vector4(0, 0, -1, 0); velocity += moveVector.Xyz * maxSpeed; } if (sceneManager.KeyPressed(Key.Down)) { //move entity back Matrix4 turn = Matrix4.CreateRotationY(3.1415f); //180 degrees Matrix4 facing = Matrix4.CreateRotationY(rotation.Y); Vector4 moveVector = turn * facing * new Vector4(0, 0, -1, 0); velocity += moveVector.Xyz * maxSpeed; } if (sceneManager.KeyPressed(Key.D)) { //move entity right Matrix4 turn = Matrix4.CreateRotationY(1.5708f); //90 degrees right Matrix4 facing = Matrix4.CreateRotationY(rotation.Y); Vector4 moveVector = turn * facing * new Vector4(0, 0, -1, 0); velocity += moveVector.Xyz * maxSpeed; } //turning if (sceneManager.KeyPressed(Key.Right)) { //turn entity right float angleInDeg = 60f; float angleInRad = angleInDeg * (float)Math.PI / 180; rotation.Y += angleInRad * SceneManager.dt; } if (sceneManager.KeyPressed(Key.Left)) { //turn entity left float angleInDeg = 60f; float angleInRad = angleInDeg * (float)Math.PI / 180; rotation.Y -= angleInRad * SceneManager.dt; } movementComponent.Velocity = velocity; transformComponent.Rotation = rotation; } } }
public override bool IsQualified(Living l) { ComponentMovement movementComponent = l.GetExactComponent <ComponentMovement>(); return(movementComponent.Movement.GetValue() > 0); }