Exemple #1
0
        public async void SetBombExplosionTimer(BombDTO bomb)
        {
            await Task.Delay(TimeSpan.FromMilliseconds(bomb.IgnitionDuration));

            ExplodeBomb(bomb);
            await _hubContext.Clients.All.SendAsync("RefreshMap", mapService.GetMap());
        }
Exemple #2
0
        public void Add(BombDTO bomb) // TODO: maybe check if there already is a bomb on the tile?
        {
            var position = mapService.GetTilePosition(bomb.Position.X, bomb.Position.Y);

            bomb.Position = new PointF(position.X * MapConstants.tileSize + MapConstants.tileSize / 2,
                                       position.Y * MapConstants.tileSize + MapConstants.tileSize / 2);
            bombs.Add(bomb);
            SetBombExplosionTimer(bomb);
            Console.WriteLine($"Bomb at: {bomb.Position.X} {bomb.Position.Y}");
        }
Exemple #3
0
        //(string OwnerId, float Damage, float IgnitionDuration, int ExplosionRadius, PointF Position, Sprite ProjectileSprite, Sprite ExplosionSp
        public BombDTO getBombDTO(string ownerID, PointF pos)
        {
            Console.WriteLine("Sending hub type: {0}", this.CurrentBombType);
            var bombDTO = new BombDTO(ownerID,
                                      this.Damage,
                                      this.IgnitionDuration,
                                      this.ExplosionRadius,
                                      pos,
                                      (int)this.CurrentBombType);

            return(bombDTO);
        }
Exemple #4
0
        public void AddBomb(BombDTO bomb)
        {
            // global bomb - doesnt know if its player bomb or enemy
            var tmpBomb = new Bomb(20, 2500, 0);

            if (bomb.CurrentBombType == 2)
            {
                tmpBomb = new FastBomb();
            }
            else if (bomb.CurrentBombType == 1)
            {
                tmpBomb = new SuperBomb();
            }

            Spawnable spawnable = new Spawnable(tmpBomb.ProjectileSprite, new Vector2f(bomb.Position.X, bomb.Position.Y), this.Rotation);

            spawnable.DespawnDrawableAfter = tmpBomb.IgnitionDuration; // set type specific speed

            Spawnables.Add(spawnable);
        }
        // [NOTE] Global OnKeyPressed event handler, not just bombs
        void OnKeyPressed(object sender, SFML.Window.KeyEventArgs e)
        {
            var target = mainPlayer.Position;

            if (e.Code == Keyboard.Key.Space)
            {
                BombDTO bombDTO = mainPlayer.getBombDTO();
                _userHubConnection.InvokeAsync("OnBombPlace", bombDTO).Wait();
                chainLogger.logMessage(new Message(2, $"**\nPlayer [{mainPlayer.connectionId.Substring(0, 8)}] placed bomb\n**"));
            }

            if (e.Code == Keyboard.Key.Z)
            {
                mainPlayer.Bomb = new FastBomb();
                mainPlayer.Bomb.CurrentBombType = 2;

                Console.WriteLine("Bomb: [FastBomb]");
                Console.WriteLine("Damage: {0} PlaceSpeed: {1} BombTimer: {2}",
                                  mainPlayer.Bomb.Damage, mainPlayer.Bomb.PlaceSpeed, mainPlayer.Bomb.IgnitionDuration);
            }
            if (e.Code == Keyboard.Key.X)
            {
                mainPlayer.Bomb = new SuperBomb();
                mainPlayer.Bomb.CurrentBombType = 1;


                Console.WriteLine("Bomb: [SuperBomb]");
                Console.WriteLine("Damage: {0} PlaceSpeed: {1} BombTimer: {2}",
                                  mainPlayer.Bomb.Damage, mainPlayer.Bomb.PlaceSpeed, mainPlayer.Bomb.IgnitionDuration);
            }
            if (e.Code == Keyboard.Key.C)
            {
                mainPlayer.Bomb.CurrentBombType = 0;
                mainPlayer.Bomb = new Bomb(20, 2500, 0);

                Console.WriteLine("Bomb: [GeneralBomb]");
                Console.WriteLine("Damage: {0} PlaceSpeed: {1} BombTimer: {2}",
                                  mainPlayer.Bomb.Damage, mainPlayer.Bomb.PlaceSpeed, mainPlayer.Bomb.IgnitionDuration);
            }
        }
Exemple #6
0
        public void ExplodeBomb(BombDTO bomb)
        {
            BombExplosion bombExplosion = new BombExplosion {
                OwnerId = bomb.OwnerId
            };
            var map = mapService.GetMapMatrix();
            var pos = mapService.GetTilePosition(bomb.Position.X, bomb.Position.Y);

            List <Point> tilesToRemove = new List <Point>();

            for (int i = 0; i < directions.GetLength(0); i++)
            {
                int x = pos.X;
                int y = pos.Y;
                for (int j = 1; j < bomb.ExplosionRadius; j++)
                {
                    x = pos.X + (directions[i, 0] * j);
                    y = pos.Y + (directions[i, 1] * j);

                    if (x > MapConstants.mapWidth || x < 0)
                    {
                        break;
                    }
                    if (y > MapConstants.mapHeight || y < 0)
                    {
                        break;
                    }
                    if (mapService.IsObstacle(x, y))
                    {
                        if (destructableObstacles.Contains(map[y, x]))
                        {
                            tilesToRemove.Add(new Point(x, y));
                        }
                        break;
                    }

                    var playerIterator = _playerService.GetPlayerIterator();
                    while (playerIterator.HasNext())
                    {
                        var player = playerIterator.GetNext();
                        if (
                            Math.Abs(x - Math.Floor(player.Position.X / MapConstants.tileSize)) == 0 &&
                            Math.Abs(y - Math.Floor(player.Position.Y / MapConstants.tileSize)) == 0)
                        {
                            _playerDeathMediator.Notify(player.Id);
                        }
                    }

                    var ghostCoordinates = _enemyMovementService.GetGhostCoordinates();
                    if (
                        Math.Abs(x - Math.Floor(ghostCoordinates.X / MapConstants.tileSize)) == 0 &&
                        Math.Abs(y - Math.Floor(ghostCoordinates.Y / MapConstants.tileSize)) == 0)
                    {
                        _enemyMovementService.KillGhost();
                    }
                }
                bombExplosion.ExplosionCoords[i] = new Point(x, y);
            }
            SendExplosionEvent(bombExplosion).Wait();
            RemoveExplodedObstacles(tilesToRemove);
            RemoveBomb(bomb);
        }
Exemple #7
0
 private bool RemoveBomb(BombDTO bomb)
 {
     return(bombs.Remove(bomb));
 }
Exemple #8
0
 // Called when a new bomb is created
 public void OnNewBomb(BombDTO bombDTO)
 {
     _game.mainPlayer.AddBomb(bombDTO);
     _game.mainPlayer.Bomb.accept(_game._debugGui.pVisitor);
 }
Exemple #9
0
 public async Task OnBombPlace(BombDTO bomb) // creating a new bomb
 {
     Console.WriteLine(bomb.ToString());
     _bombService.Add(bomb);
     await Clients.All.SendAsync("ReceiveNewBomb", bomb);
 }
 public void OnNewBomb(BombDTO bombDTO)
 {
     _log.Info(bombDTO.ToString());
     _client.OnNewBomb(bombDTO);
 }