public void MoveASmoothStepTo(WorldPosition target, float factor) { factor = Math.Min(factor, 1.0f); factor = Math.Max(factor, 0.0f); X = (factor - X) / (target.X - X); Y = (factor - Y) / (target.Y - Y); }
public override void Read(PacketReader reader) { EntityId = reader.ReadInt(); Position = new WorldPosition { X = reader.ReadFloat(), Y = reader.ReadFloat() }; Direction = reader.ReadFloat(); Speed = reader.ReadFloat(); #if DEBUG Console.WriteLine(ToString()); #endif }
protected virtual void SetPosition(WorldPosition position) { _position = position; }
public MovePacket() { Position = new WorldPosition(); }
internal void SendPacketToNearbyPlayers(WorldPosition pos, Packet packet, Client excludedClient = null) { Client[] nearbyClients = GetNearbyPlayers(pos).ToArray(); if (nearbyClients.Length == 0) return; packet.SetShared(nearbyClients.Length); Parallel.ForEach(nearbyClients, client => { if (excludedClient != client) { client.SendPacket(packet); } else { packet.Release(); } }); }
internal IEnumerable<Client> GetNearbyPlayers(WorldPosition pos) { int radius = SightRadius; foreach (Client c in GetClients()) { int playerPatternX = (int) Math.Floor(c.Player.Position.X) >> 5; int playerPatternY = (int) Math.Floor(c.Player.Position.Y) >> 5; if (Math.Abs(pos.X - playerPatternX) <= radius && Math.Abs(pos.Y - playerPatternY) <= radius) yield return c; } }
public WorldPosition SmoothStep(WorldPosition target, float factor) { WorldPosition step = new WorldPosition(this); step.MoveASmoothStepTo(target, factor); return step; }
public WorldPosition(WorldPosition src) { X = src.X; Y = src.Y; }
protected override void SetPosition(WorldPosition position) { if (_position == null) { _position = new WorldPosition(); } _position.X = position.X; _position.Y = position.Y; if (VisualPosition == null) { VisualPosition = new WorldPosition(_position); } }
public void Move(int entityId, WorldPosition position, float direction, float speed) { IEntity entity; if (!GameScene.Entities.TryGetValue(entityId, out entity)) { Console.WriteLine("Couldn't find entity with id" + entityId); return; } entity.StopMoving(null); entity.Position = position; if (speed > 0) { entity.PrepareToMove(direction, speed); } }
public void HandlePlayerPosition(PlayerPositionPacket ppp) { Console.WriteLine("Received Player Position Packet"); if (GameScene.Player != null) { WorldPosition wp = new WorldPosition(ppp.X, ppp.Y); GameScene.Player.Position = wp; } else { Console.WriteLine("Error. Player should exist"); } }