Ejemplo n.º 1
0
 public Ball ChooseNextBall(Player player)
 {
     if (player.OwnedBalls.Count == null)
         return null;
     else
         return player.OwnedBalls[(player.OwnedBalls.IndexOf(player.ActiveBall) + 1) % player.OwnedBalls.Count];
 }
Ejemplo n.º 2
0
 public InputMessage(MessageType type, bool? pressed, char? value, Player player)
     : base(Message.MessageType.InputMessage)
 {
     Kind = type;
     Key = value;
     Pressed = pressed;
     Player = player;
 }
Ejemplo n.º 3
0
        protected override Session ImplStartSession(Ballz game, GameSettings settings, bool remoteControlled, int localPlayerId)
        {
            var session = new Session(game, new World(new Terrain(settings.MapTexture)), settings)
                              {
                                  UsePlayerTurns = this.UsePlayerTurns,
                                  Terrain = new Terrain(settings.MapTexture)
                              };

            FindSpawnPoints(settings.MapTexture, session.Terrain.Scale);

            var spawnPoints = SelectSpawnpoints(settings.Teams.Select(t=>t.NumberOfBallz).Sum());

            // Create players and Ballz
            var currBallCreating = 0;
            foreach (var team in settings.Teams)
            {
                var player = new Player
                {
                    Id = team.Id,
                    Name = team.Name,
                    TeamName = team.Country,
                    IsLocal = !remoteControlled || localPlayerId == team.Id
                };

                session.Players.Add(player);

                var ballCount = UsePlayerTurns ? team.NumberOfBallz : 1;
                var ballNames = TeamNames.GetBallNames(team.Country, ballCount);

                for (var i = 0; i < ballCount; ++i)
                {
                    var playerBall = new Ball
                    {
                        Name = ballNames[i],
                        Position = spawnPoints[currBallCreating],
                        Velocity = new Vector2(0, 0),
                        IsAiming = true,
                        Player = player,
                        HoldingWeapon = "Bazooka",
                        IsStatic = false
                    };
                    player.OwnedBalls.Add(playerBall);
                    ++currBallCreating;
                    session.World.AddEntity(playerBall);

                    BallControl controller;

                    if (team.ControlledByAI)
                        controller = new AIControl(game, session, playerBall);
                    else
                        controller = new UserControl(game, session, playerBall);

                    session.SessionLogic.BallControllers[playerBall] = controller;

                }

                player.ActiveBall = player.OwnedBalls.FirstOrDefault();
                session.SessionLogic.ActiveControllers[player] = session.SessionLogic.BallControllers[player.ActiveBall];
            }

            return session;
        }
Ejemplo n.º 4
0
 public void InjectInputMessage(InputMessage message, Player player)
 {
     OnInput(message.Kind, message.Pressed, message.Key, player);
 }
Ejemplo n.º 5
0
        private void OnInput(InputMessage.MessageType inputType, bool pressed = false, char key = char.MinValue, Player player = null)
        {
            var inputMessage = new InputMessage(inputType, pressed, key, player);

            if (Ballz.The().MessageOverlay != null)
                Ballz.The().MessageOverlay.HandleInput(inputMessage);
            else
                Input?.Invoke(this, inputMessage); //todo: use object pooling and specify message better
        }
Ejemplo n.º 6
0
 public void AddPlayer(Player player, Ball ball)
 {
     BallControllers[player] = new BallControl(Game, Game.Match, ball);
 }
Ejemplo n.º 7
0
 private void OnInput(InputMessage.MessageType inputMessage, bool? pressed = null, char? key = null, Player player = null)
 {
     Input?.Invoke(this, new InputMessage(inputMessage, pressed, key, player)); //todo: use object pooling and specify message better
 }