/// <summary> /// Initializes the client after it has successfully joined a game on /// a game server. /// </summary> /// <param name="spawnPosition"> /// The position on the map where the server has created the <see cref="PlayerEntity"/> /// for the player /// </param> /// <param name="serverStub"> /// An object that can invoke methods on the game server /// </param> /// <returns></returns> protected async Task InitializeAsync(Point spawnPosition, IGameServerStub serverStub) { _serverStub = serverStub; PlayerPosition = spawnPosition; Map = new Map(new RemoteChunkStorage(PlayerInfo.PlayerId, _serverStub)); // Load chunk at spawn position await Map.GetAsync(spawnPosition); }
public async Task DisconnectAsync() { if (_serverStub == null) return; await _serverStub.LeaveAsync(PlayerInfo.PlayerId); _serverStub = null; PlayerPosition = Point.Zero; Map = null; }
public void Initialize(IGameplayMap map) { _eventSubscription = map.Events.OfType<IAudioHint>().Subscribe(PlaySound); var soundUri = new Func<string, Uri>(s => new Uri($"ms-appx:///Assets/Sounds/{s}")); _sounds["GateTile-Opened"] = soundUri("GateOpen.mp3"); _sounds["GateTile-Closed"] = soundUri("GateClose.mp3"); _sounds["InkTile-Consumed"] = soundUri("SplishSploshSplosh.mp3"); _sounds["BalloonEntity-Popped"] = soundUri("Balloon Pop.mp3"); _sounds["ButtonTile-Toggled-On"] = soundUri("Button Click.mp3"); _sounds["ButtonTile-Toggled-Off"] = soundUri("Button Click Release.mp3"); _sounds["TeleporterTile-Teleported"] = soundUri("teleport.mp3"); _sounds["PistonTile-Extended"] = soundUri("PistonExtend.mp3"); _sounds["PistonTile-Retracted"] = soundUri("PistonRetract.mp3"); }
private GameplayArgs(ITransactionWithMoveSupport transaction, IGameplayMap map, Tile tile, Point suggestedPushDirection) : this(transaction, map) { Tile = tile; SuggestedPushDirection = suggestedPushDirection; }
private void DetachMap(IGameplayMap map) { if (map == null) return; _spawnSubscription?.Dispose(); _spawnSubscription = null; _moveSubscription?.Dispose(); _moveSubscription = null; lock (_entitiesLock) { foreach (var e in _entities) e.Dispose(); _entities.Clear(); } }
private void AttachMap(IGameplayMap map) { if (map == null) return; _spawnSubscription = map.Events.OfType<EntitySpawnEvent>().Subscribe(OnEntitySpawned); _moveSubscription = map.Events.OfType<EntityMoveEvent>() .Where(e => (e.Source.Entity as PlayerEntity)?.PlayerId == FollowedPlayerId && FollowedPlayerId != null) .Subscribe(OnFollowedPlayerMoved); var chunkBounds = new Rectangle(0, 0, Chunk.Size - 1, Chunk.Size - 1); // Add the entities of the already loaded chunks // (if after that a chunk is loaded or unloaded the map will // emit appropiate spawn/despawn events) var entitySpawnEvents = map.ChunkLoader.Chunks .SelectMany(chunk => chunkBounds.Select(p => new { Position = chunk.Key * Chunk.Size + p, Entity = chunk.Value[p].Tile.Entity })) .Where(o => o.Entity != Entity.None) .Select(o => new EntitySpawnEvent(o.Position, o.Entity)); foreach (var e in entitySpawnEvents) OnEntitySpawned(e); }
public GameServer(IGameplayMap map) { Map = map; map.ChunkLoader.Chunks.ItemAdded += OnChunkLoaded; _updateTask = RunAsync(); }