public void Init()
        {
            if (!_gameDefinitions.playerDefinition)
            {
                throw new Exception($"{nameof(PlayerDefinition)} doesn't exists!");
            }

            int playerCount = 0;
            PlayerDefinition playerDefinition = _gameDefinitions.playerDefinition;

            GameObject[] playerObjects = GameObject.FindGameObjectsWithTag("Player");
            foreach (GameObject player in playerObjects)
            {
                EcsEntity playerEntity = _ecsWorld.NewEntityWith(
                    out PlayerComponent playerComponent,
                    out MoveComponent moveComponent);

                Vector2Int startPosition = player.transform.position.ToVector2Int();
                moveComponent.Heading = playerCount % 2 != 0
                    ? Directions.Right
                    : Directions.Left;

                moveComponent.DesiredPosition = startPosition;
                moveComponent.Speed           = playerDefinition.StartSpeed;

                playerComponent.Lives         = playerDefinition.StartLives;
                playerComponent.Num           = ++playerCount;
                playerComponent.SpawnPosition = startPosition;

                playerEntity.Set <CreateWorldObjectEvent>().Transform = player.transform;
            }
        }
Beispiel #2
0
        private void GeneratePlayer(int gamepadNumber)
        {
            if (AllocatedGamepads.Count < MaxPlayerCount)
            {
                var newDef = new PlayerDefinition()
                {
                    AssignedGamepad = gamepadNumber
                };
                AllocatedGamepads.Add(gamepadNumber, newDef);

                if (PlayerDefinitionEditorPrefab.IsAvailable)
                {
                    var newEditor = PlayerDefinitionEditorPrefab.Res.Instantiate();
                    var editor    = newEditor.GetComponent <PlayerDefinitionEditor>();
                    editor.PlayerDef = newDef;
                    for (int i = 1; i < AllocatedGamepads.Count; i++)
                    {
                        newDef.NextColor();
                    }

                    newDef.Editor = editor;
                    Editors.Add(editor);
                    Editors.Sort(Comparer <PlayerDefinitionEditor> .Create((one, two) => { return(one.PlayerDef.AssignedGamepad.CompareTo(two.PlayerDef.AssignedGamepad)); }));
                    Scene.Current.AddObject(newEditor);
                }
            }
        }
Beispiel #3
0
        public void Init(PlayerDefinition def)
        {
            playerDefinition = def;
            view.CreateLimits(def.LimitLeft, def.LimitRight, def.LimitTop, def.LimitBottom);

            disposables = new CompositeDisposable(newFireSubject
                                                  .Throttle(TimeSpan.FromMilliseconds(def.FireRate))
                                                  .Select(_ => NewFireEvent.FromPlayer(view.GetScreenPosition()))
                                                  .Subscribe(newFireEvent => playerShoots.Execute(view.GetScreenPosition(), enhancedGun)));
        }
Beispiel #4
0
 public ConfirmJoiningGame ToBase()
 {
     return(new ConfirmJoiningGame()
     {
         gameId = GameId,
         PlayerDefinition = PlayerDefinition?.ToBase(),
         playerId = PlayerId,
         privateGuid = GUID
     });
 }
Beispiel #5
0
        private void GeneratePlayer(PlayerDefinition playerDef)
        {
            //Look for a free spawn point
            var worldmanager = Scene.Current.FindComponent <WorldManager>();

            if (worldmanager != null)
            {
                var spawnPoints = worldmanager.GetPlayerSpawnPoints();

                var assignedSpawn = spawnPoints.Where(x => x.RestrictToGamepadNumber && x.AssignedGamepadNumber == playerDef.AssignedGamepad).FirstOrDefault();
                if (assignedSpawn == null)
                {
                    assignedSpawn = spawnPoints.Where(x => !x.RestrictToGamepadNumber).FirstOrDefault();
                }

                if (assignedSpawn == null)
                {
                    Logs.Game.WriteError("Unable to assign a spawn for " + playerDef.AssignedGamepad);

                    //get a random spawn point and try.
                    assignedSpawn = spawnPoints.FirstOrDefault();
                    if (assignedSpawn == null)
                    {
                        return;
                    }
                }


                if (PlayerPrefab.IsAvailable)
                {
                    var newObj = PlayerPrefab.Res.Instantiate();
                    newObj.Name = "Player " + playerDef.AssignedGamepad;
                    if (newObj != null)
                    {
                        var rootPlayer = newObj.GetComponent <Player>();
                        if (rootPlayer != null)
                        {
                            rootPlayer.PlayerName = "Player " + playerDef.AssignedGamepad;
                        }

                        rootPlayer.Definition = playerDef;

                        var playerSprite = newObj.GetComponentsDeep <SpriteRenderer>().First();

                        playerSprite.ColorTint = playerDef.PlayerColor.Player;

                        Scene.Current.FindComponent <GameStateManager>()?.AddPlayer(rootPlayer);
                    }
                    newObj.Transform.Pos = assignedSpawn.GameObj.Transform.Pos;

                    Scene.Current.AddObject(newObj);
                    AllocatedGamepads.Add(playerDef.AssignedGamepad, newObj.GetComponentsDeep <Player>().First());
                }
            }
        }
Beispiel #6
0
        public void InstantiatePlayer(PlayerDefinition playerDefinition)
        {
            playerController = Instantiate(playerDefinition.GetPrefab()).GetComponent <PlayerController>();
            var rectTransform = playerController.GetComponent <RectTransform>();

            rectTransform.SetParent(PlayerContainer);
            rectTransform.ScaleOne();
            rectTransform.localPosition = InitialPlayerPosition;
            playerController.Init(playerDefinition);
            disposables.Add(playerController.StartAnimation()
                            .Subscribe(_ => collisionInstantiator.AddCollision(playerController)));
        }
Beispiel #7
0
    /// <summary>
    /// Helper method: Creates players based on desired data.
    /// </summary>
    /// <param name="players">A reference to the desired data in order to create the players needed.</param>
    /// <returns>A list of active players.</returns>
    private static List <UserModel> CreatePlayers(List <PlayerDefinition> players)
    {
        List <UserModel> result = new List <UserModel>();

        for (int i = 0; i < players.Count; i++)
        {
            PlayerDefinition player = players[i];
            UserModel        user   = UserModel.CreatePlayer(player.computerDriven, player.player);
            result.Add(user);
        }

        return(result);
    }
Beispiel #8
0
    public SaveData(List <BoardPiece> board, List <UserModel> players)
    {
        savedPlayers = new List <PlayerDefinition> ();
        savedBoard   = new List <PieceData> ();
        for (int x = 0; x < board.Count; x++)
        {
            savedBoard.Add(new PieceData(board[x]));
        }

        foreach (var player in players)
        {
            PlayerDefinition user = new PlayerDefinition(player);
            savedPlayers.Add(user);
        }

        savedTurn = TestGameModel.currPlayerIndex;
    }
        public static Configuration Parse(object obj)
        {
            var dto          = obj as ConfigurationDto;
            var allGuns      = dto.AllGuns.Select(GunDefinition.FromDto).ToList();
            var allEnemies   = dto.AllEnemies.Select(EnemyDefinition.FromDto).ToList();
            var allPowerUps  = dto.AllPowerUps.Select(PowerUpDefinition.FromDto).ToList();
            var allLevels    = dto.AllLevels.Select(LevelDefinition.FromDto).ToList();
            var levelsConfig = new Configuration
            {
                Player      = PlayerDefinition.FromDto(dto.Player),
                AllGuns     = allGuns,
                AllEnemies  = allEnemies,
                AllPowerUps = allPowerUps,
                AllPaths    = dto.AllPaths.Select(PathDefinition.FromDto).ToList(),
                AllLevels   = allLevels
            };

            return(levelsConfig);
        }
Beispiel #10
0
 public void Init(PlayerDefinition playerDefinition)
 {
     speed = playerDefinition.Speed;
     presenter.Init(playerDefinition);
 }