protected void initializePlayer() { PlayerSpawnInfo psi = PlayerSpawn; player.transform.position = new Vector2(psi.x, psi.y); player.anim.direction = psi.direction; this.addEntity(this.player); camera.entity.addComponent(new FollowCamera(this.player)); }
IEnumerator Initialize(Player player) { while (player.fileDetails == null) { yield return(null); } PlayerSpawnInfo spawn = new PlayerSpawnInfo(Vector2Int.zero, new Vector2(player.fileDetails.position_x, player.fileDetails.position_y), Direction.Right); player.Spawn(spawn); player.rigidbody2d.gravityScale = 1; player.initialized = true; CanTransitionOutOf = true; }
IEnumerator Initialize() { while (fileDetails == null) { yield return(null); } PlayerSpawnInfo spawn = new PlayerSpawnInfo(Vector2Int.zero, new Vector2(fileDetails.position_x, fileDetails.position_y), Direction.Right); Spawn(spawn); StartCoroutine(RunStateMachine()); rigidbody2d.gravityScale = 1; initialized = true; }
public void AssignPlayersToSpawn(PlayerLobby[] players) { playerWaitingSpawn = new List <PlayerSpawnInfo>(); for (int i = 0; i < players.Length; i++) { if (players[i].PlayerID != "") { PlayerSpawnInfo player = new PlayerSpawnInfo(); player.CharacterIndex = players[i].CharacterIndex; player.PlayerName = players[i].playerName; player.PlayerTeam = players[i].playerTeam; player.UserID = players[i].PlayerID; player.CharacterKey = ""; playerWaitingSpawn.Add(player); } } }
protected void createTileMap(string mapName) { Entity tiledEntity = createEntity("tiled-map-entity"); TiledMap tiledMap = this.content.Load <TiledMap>("Maps/" + mapName); TiledMapComponent tiledMapComponent = tiledEntity.addComponent(new TiledMapComponent(tiledMap, "Collisions")); tiledMapComponent.setLayersToRender(new string[] { "Ground", "Walls", "Details" }); tiledMapComponent.renderLayer = 10; TiledMapComponent tiledMapDetailsComp = tiledEntity.addComponent(new TiledMapComponent(tiledMap)); tiledMapDetailsComp.setLayerToRender("Above-Details"); tiledMapDetailsComp.renderLayer = -1; List <TiledObjectGroup> tiledObjects = tiledMap.objectGroups; tiledEntity = TransitionManager.attachTransitionColliders(tiledObjects, tiledEntity, mapName); this.PlayerSpawn = TransitionManager.findPlayerSpawn(tiledObjects, PrevMapName); tiledMapDetailsComp.material = Material.stencilWrite(); tiledMapDetailsComp.material.effect = this.content.loadNezEffect <SpriteAlphaTestEffect>(); }
public void Spawn(PlayerSpawnInfo spawn) { levelgrid.InitializeActiveGrid(spawn); rigidbody2d.position = spawn.position; //set facing }
// Use this for initialization void Start() { paused = false; gameOver = false; gameOverMenu = GameObject.Find("GameOverMenu"); gameOverMenu.SetActive(false); currentTime = settings.matchLengthSeconds; currentWarmup = warmupTime; numberOfNests = settings.numPlayers; navigator = GameObject.Find("EventSystem").GetComponent <EventSystem> (); sea = GameObject.Find("Sea").transform; winText = GameObject.Find("WinText").GetComponent <Text> (); winText.text = ""; countDownSFX = GameObject.Find("WinText").GetComponents <AudioSource>()[0]; goSFX = GameObject.Find("WinText").GetComponents <AudioSource>()[1]; filledPickups = new ArrayList(); // This block randomly chooses a set of spawn points for each player and nest playerInfo = new Dictionary <int, PlayerSpawnInfo> (); GameObject pSpawnList = GameObject.Find("PlayerSpawnPoints"); GameObject nSpawnList = GameObject.Find("NestSpawnPoints"); // If the spawnpoint system does not exist, do not run this code if (pSpawnList != null) { Transform[] pspawnpoints = pSpawnList.GetComponentsInChildren <Transform> (); Transform[] nspawnpoints = nSpawnList.GetComponentsInChildren <Transform> (); List <int> pointNumbers = new List <int>(); for (int i = 1; i < pspawnpoints.Length; i++) { pointNumbers.Add(i); } // Assure we don't try to use more players than spawnpoints settings.numPlayers = Mathf.Min(settings.numPlayers, pointNumbers.Count); for (int i = 1; i <= settings.numPlayers; i++) { PlayerSpawnInfo info = new PlayerSpawnInfo(); // Randomly select an available spawn position int sp; do { sp = Random.Range(1, pspawnpoints.Length); } while (!pointNumbers.Contains(sp)); GameObject newHUD = GameObject.Instantiate(hudPrefab, GameObject.Find("Canvas").transform); GameObject newplayer = GameObject.Instantiate(playerPrefab.transform.FindChild("Character" + settings.skinNumbers[i - 1]).gameObject, pspawnpoints[sp].position, pspawnpoints[sp].rotation); GameObject newnest = GameObject.Instantiate(nestPrefab, nspawnpoints[sp].position, nspawnpoints[sp].rotation); Material[] beacons = Resources.LoadAll <Material> ("Materials"); newHUD.name = "HUD" + i; newplayer.name = "Player" + i; newnest.name = "Nest" + i; info.id = i; info.playerObject = newplayer; info.player = newplayer.GetComponent <PlayerController> (); info.player.playerNumber = i; info.nest = newnest.GetComponent <NEST> (); info.nest.nestId = i; info.hud = newHUD; info.hud.transform.SetSiblingIndex(0); info.hud.GetComponent <RectTransform> ().anchoredPosition = Vector2.zero; newplayer.transform.FindChild("Identifier").GetComponent <MeshRenderer> ().material = beacons[info.player.playerNumber - 1]; newnest.transform.FindChild("Beacon").GetComponent <MeshRenderer>().material = beacons[info.player.playerNumber - 1]; playerInfo [i] = info; pointNumbers.Remove(sp); } // Set up cameras Camera mainCamera = GameObject.FindObjectOfType <Camera> (); playerInfo [1].camera = mainCamera; mainCamera.GetComponent <TransformFollower> ().target = playerInfo[1].playerObject.transform; for (int i = 2; i <= settings.numPlayers; i++) { Camera newCam = Instantiate <Camera> (mainCamera); newCam.name = "Camera(P" + i + ")"; newCam.GetComponent <TransformFollower> ().target = playerInfo[i].playerObject.transform; playerInfo [i].camera = newCam; } // Play that funky music! But only from one camera mainCamera.GetComponent <AudioListener> ().enabled = true; mainCamera.GetComponent <AudioSource> ().enabled = true; mainCamera.GetComponent <AudioSource> ().volume = settings.musicVolume / 100f; // Scale cameras and HUDs switch (settings.numPlayers) { case 1: playerInfo [1].camera.rect = new Rect(0f, 0f, 1f, 1f); break; case 2: playerInfo [1].camera.rect = new Rect(0f, 0f, 0.5f, 1f); playerInfo [2].camera.rect = new Rect(0.5f, 0f, 0.5f, 1f); playerInfo [2].hud.GetComponent <RectTransform> ().anchorMin = new Vector2(0.5f, 1f); break; case 3: playerInfo [1].camera.rect = new Rect(0f, 0.5f, 1f, 0.5f); playerInfo [2].camera.rect = new Rect(0f, 0f, 0.5f, 0.5f); playerInfo [3].camera.rect = new Rect(0.5f, 0f, 0.5f, 0.5f); playerInfo [2].hud.GetComponent <RectTransform> ().anchorMax = new Vector2(0f, 0.5f); playerInfo [3].hud.GetComponent <RectTransform> ().anchorMin = new Vector2(0.5f, 0f); playerInfo [3].hud.GetComponent <RectTransform> ().anchorMax = new Vector2(1f, 0.5f); break; case 4: playerInfo [1].camera.rect = new Rect(0f, 0.5f, 0.5f, 0.5f); playerInfo [2].camera.rect = new Rect(0.5f, 0.5f, 0.5f, 0.5f); playerInfo [3].camera.rect = new Rect(0f, 0f, 0.5f, 0.5f); playerInfo [4].camera.rect = new Rect(0.5f, 0f, 0.5f, 0.5f); playerInfo [2].hud.GetComponent <RectTransform> ().anchorMin = new Vector2(0.5f, 0f); playerInfo [3].hud.GetComponent <RectTransform> ().anchorMax = new Vector2(0f, 0.5f); playerInfo [4].hud.GetComponent <RectTransform> ().anchorMin = new Vector2(0.5f, 0f); playerInfo [4].hud.GetComponent <RectTransform> ().anchorMax = new Vector2(1f, 0.5f); break; } } Pause(false); }
public void InitializeActiveGrid(PlayerSpawnInfo spawn) { //once saving is implemented, set Position based on save data //when starting a new game, remember to set the Position accordingly Position = spawn.gridPosition; activeScenes = new Dictionary <int, Vector2Int>(); curIndex = Position.x + dimensions.x * Position.y; currentScene = levels[curIndex].sceneIndex; LoadLevel(curIndex); activeScenes.Add(currentScene, Position); Debug.Log("levels length: " + levels.Length); Debug.Log("EditorBuildSettingsSceneLength: " + EditorBuildSettings.scenes.Length); int index; for (int x = Position.x - activeRadius; x <= Position.x + activeRadius; x++) { if (x < 0 || x >= dimensions.x) { //Debug.Log("x: " + x + " outside bounds"); continue; } for (int y = Position.y - activeRadius; y <= Position.y + activeRadius; y++) { if (y < 0 || y >= dimensions.y) { //Debug.Log("y: " + y + " outside bounds"); continue; } index = x + dimensions.x * y; if (x == Position.x && y == Position.y) { continue; } if (levels[index] == null) { //Debug.Log("level at x,y: " + x + ", " + y + " is null"); continue; } if (levels[index].scene == null) { //Debug.Log("level at x, y: " + x + ", " + y + " scene is null"); continue; } if (levels[index].sceneIndex < 0) { //Debug.Log("scene index at x,y: " + x + ", " + y + " is " + levels[index].sceneIndex); continue; } if (levels[index].sceneIndex >= EditorBuildSettings.scenes.Length) { //Debug.Log("scene index at x,y " + x + ", " + y + " is " + levels[index].sceneIndex + " >= build order length" + EditorBuildSettings.scenes.Length); continue; } //Debug.Log("loading " + levels[index].scene.name + " at buildIndex: " + levels[index].sceneIndex); activeScenes.Add(levels[index].sceneIndex, new Vector2Int(x, y)); LoadLevel(index); } } }