public static PlayerSpawner FindNearest(UniversePosition universePosition) { Debug.Log("FIND SPAWNER NEAR: " + universePosition.CellIndex); var nearestSpawner = _spawners .OrderBy(s => (s.Shiftable.CellLocalPosition - universePosition.CellLocalPosition).sqrMagnitude) .ThenBy(s => (s.Shiftable.UniverseCellIndex - universePosition.CellIndex).SquareMagnitude()) .FirstOrDefault(); Debug.Log("NEAREST SPAWNER AT: " + nearestSpawner.Shiftable.UniverseCellIndex); return nearestSpawner; }
void Awake() { _naturalScale = transform.localScale.x; _finalDestination = Universe.Current.GetUniversePosition(transform.position); _warpPos = transform.position - (transform.forward * Distance); _cooldown = Timeout; _shiftable = GetComponent<Shiftable>(); //_rigidBody = GetComponent<Rigidbody>(); //_rigidBody.isKinematic = true; }
public void SpawnSquadronVehicle(Fighter member, UniversePosition position, Quaternion rotation) { member.SpawnVehicle(member.gameObject, member.VehiclePrefab, position, rotation); var memberTracker = member.VehicleInstance.GetComponent<VehicleTracker>(); var profile = member.GetComponent<ShipProfile>(); if (profile.PrimaryWeapon != null) member.VehicleInstance.SetPrimaryWeapon(profile.PrimaryWeapon.gameObject); if (profile.SecondaryWeapon != null) member.VehicleInstance.SetSecondaryWeapon(profile.SecondaryWeapon.gameObject); var squadronTracker = member.VehicleInstance.gameObject.AddComponent<SquadronTracker>(); squadronTracker.ArrowSprite = memberTracker.ArrowSprite; //squadronTracker.TrackerSprite = memberTracker.TrackerSprite; //squadronTracker.FarTrackerSprite = memberTracker.FarTrackerSprite; //squadronTracker.VeryFarTrackerSprite = memberTracker.VeryFarTrackerSprite; squadronTracker.LockingSprite = memberTracker.LockingSprite; squadronTracker.LockedSprite = memberTracker.LockedSprite; squadronTracker.TrackerPlanePrefab = TrackerPlanePrefab; Destroy(memberTracker); squadronTracker.CallSign = profile.CallSign; squadronTracker.TrackerColor = TrackerColor; squadronTracker.LabelFont = SquadronTrackerFont; squadronTracker.IsDisabled = false; member.IsFollowIdleDestination = true; var mapPin = member.VehicleInstance.gameObject.AddComponent<MapPin>(); mapPin.ActivePin = PlayerController.Current.PlayerPinPrefab; mapPin.InactivePin = SquadronPinPrefab; mapPin.SetPinState(MapPin.MapPinState.Inactive); // Apply power profile member.VehicleInstance.Killable.MaxShield = profile.GetShield(); member.VehicleInstance.Killable.Shield = member.VehicleInstance.Killable.MaxShield; var squadronShieldRegenerator = member.VehicleInstance.gameObject.AddComponent<ShieldRegenerator>(); squadronShieldRegenerator.RegenerationDelay = ShieldRegenerateDelay; squadronShieldRegenerator.RegenerationRate = ShieldRegenerateRate; BindMemberEvents(member); member.enabled = true; }
public Vector3 GetWorldPosition(UniversePosition universePosition) { return GetWorldPosition(universePosition.CellIndex, universePosition.CellLocalPosition); }
public Vector3 GetAbsoluteUniversePosition(UniversePosition universePosition) { _cell = universePosition.CellIndex; return _cell.ToVector3() * CellSize + universePosition.CellLocalPosition; }
public void WarpTo(UniversePosition universePosition) { _cell = universePosition.CellIndex - ViewPort.Shiftable.UniverseCellIndex; ViewPort.Shiftable.SetShiftPosition(universePosition); Shift(_cell); }
private void Update() { if (Input.GetKeyDown(KeyCode.LeftControl)) { Debug.Break(); } if (_controlEnabled) { if (_playVehicleInstance != null) { var mouseHorizontal = Input.GetAxis("MouseHorizontal"); //AimSensitivity*Input.GetAxis("MouseHorizontal")/Screen.width; var mouseVertical = Input.GetAxis("MouseVertical"); //AimSensitivity*_screenAspect*Input.GetAxis("MouseVertical")/Screen.height; var controllerHorizontal = 0f;// AimSensitivity*Input.GetAxis("Horizontal")/Screen.width; var controllerVertical = 0f;// AimSensitivity*_screenAspect*Input.GetAxis("Vertical")/Screen.height; var _pitchYaw = Vector2.ClampMagnitude(new Vector2(controllerVertical + mouseVertical, controllerHorizontal + mouseHorizontal), MouseMoveClamp); if (InvertY) { _playVehicleInstance.PitchThotttle = _pitchYaw.x * -1; } else { _playVehicleInstance.PitchThotttle = _pitchYaw.x; } _playVehicleInstance.YawThrottle = _pitchYaw.y; _playVehicleInstance.RollThrottle = Input.GetAxis("Roll") + Input.GetAxis("KeyboardRoll"); if (_playVehicleInstance.PrimaryWeaponInstance != null) _playVehicleInstance.PrimaryWeaponInstance.IsTriggered = (Input.GetAxis("FireTrigger") + Input.GetAxis("MouseFireTrigger")) > 0; if (_playVehicleInstance.SecondaryWeaponInstance != null) _playVehicleInstance.SecondaryWeaponInstance.IsTriggered = (Input.GetAxis("AltFireTrigger") + Input.GetAxis("MouseAltFireTrigger")) > 0; _playVehicleInstance.SetAimAt(GetAimAt()); // Barrel roll trigger var curRollSign = Mathf.RoundToInt(_playVehicleInstance.RollThrottle); if (curRollSign != lastRollSign) { if (lastRollSign == 0) { if (curRollSign == -1) { if (Time.time - lastLeftTime < DoubleTapTime) _playVehicleInstance.TriggerBarrelRoll(curRollSign); lastLeftTime = Time.time; } if (curRollSign == 1) { if (Time.time - lastRightTime < DoubleTapTime) _playVehicleInstance.TriggerBarrelRoll(curRollSign); lastRightTime = Time.time; } } } lastRollSign = curRollSign; _playVehicleInstance.TriggerAccelerate = false; if (Input.GetButton("Accelerate") || Input.GetButton("KeyboardAccelerate")) { _playVehicleInstance.TriggerAccelerate = true; } _playVehicleInstance.TriggerBrake = false; if (Input.GetButton("Brake") || Input.GetButton("KeyboardBrake")) { _playVehicleInstance.TriggerBrake = true; } _playVehicleInstance.TriggerBoost = false; if (Input.GetButton("Boost") || Input.GetButton("KeyboardBoost")) { _playVehicleInstance.TriggerBoost = true; } if (Input.GetKeyUp(KeyCode.G)) { _playVehicleInstance.Killable.MaxHealth = 10000f; _playVehicleInstance.Killable.Health = _playVehicleInstance.Killable.MaxHealth; } _droneHive = _playVehicleInstance.GetComponent<DroneHive>(); if (_droneHive != null) { if (Input.GetKeyUp(KeyCode.T)) { _droneHive.ReleaseDrones(5); } } if (_playVehicleInstance.IsBoosting) { //Universe.Current.ViewPort.GetComponent<VehicleCamera>().TriggerShake(0.04f, 1f); } PickupCollectibles(); _isAllowRespawn = false; } else { if (_deathCooldown >= 0f) { _deathCooldown -= Time.deltaTime; if (_deathCooldown < 0f) { Debug.Log("ALLOW RESPAWN"); _isAllowRespawn = true; } } } if (_isAllowRespawn) { if (Squadron.GetLiveCount() == 0) { if (Input.GetButtonUp("SquadronNext")) { Respawn(); } if (Input.GetButtonUp("SquadronPrevious")) { Respawn(); } if ((Input.GetAxis("FireTrigger") + Input.GetAxis("MouseFireTrigger")) > 0) { Respawn(); } if ((Input.GetAxis("AltFireTrigger") + Input.GetAxis("MouseAltFireTrigger")) > 0) { Respawn(); } } else { if ((Input.GetAxis("FireTrigger") + Input.GetAxis("MouseFireTrigger")) > 0) { CycleSquadron(1); } if ((Input.GetAxis("AltFireTrigger") + Input.GetAxis("MouseAltFireTrigger")) > 0) { CycleSquadron(-1); } } } if (Input.GetKeyUp(KeyCode.R)) { Respawn(); } if (Input.GetKeyUp(KeyCode.Escape)) { Menus.Current.ToggleQuitMenu(); } // Shortcut to hangar screen if (Input.GetKeyUp(KeyCode.H)) { ShipProfileScreen.Current.Fighters.Clear(); foreach (var member in Squadron.Members) { ShipProfileScreen.Current.Fighters.Add(member); } ShipProfileScreen.Current.Populate(Squadron.GetCurrentIndex()); ShipProfileScreen.Current.Show(); } if (Input.GetKeyUp(KeyCode.Z)) { if (_playVehicleInstance != null) _playVehicleInstance.Killable.Die(); } if (Input.GetButtonUp("SquadronNext")) { CycleSquadron(1); } if (Input.GetButtonUp("SquadronPrevious")) { CycleSquadron(-1); } if (Input.GetKey(KeyCode.M)) { Universe.Current.ViewPort.GetComponent<VehicleCamera>().TriggerShake(0.3f, 0.7f); //_playVehicleInstance.GetComponent<Killable>().Damage(5f, Vector3.zero, Vector3.forward); } } if (Input.GetKeyUp(KeyCode.Tab)) { Map.Current.Toggle(); } if (Input.GetKeyUp(KeyCode.T)) { _playVehicleInstance.TriggerUTurn(); } if (Input.GetKeyUp(KeyCode.I)) { InventoryScreen.Current.Toggle(); } Vehicle leaderVehicle; var playerSquadronIndex = Squadron.GetCurrentIndex(); if (playerSquadronIndex == 0) { leaderVehicle = VehicleInstance; } else { _leader = Squadron.GetMember(playerSquadronIndex); leaderVehicle = _leader.VehicleInstance; if (leaderVehicle != null && _playVehicleInstance != null) { _leader.IdleDestination = leaderVehicle.transform.position + leaderVehicle.transform.forward * 10f; var leaderToPlayer = leaderVehicle.Shiftable.transform.position - _playVehicleInstance.transform.position; if (leaderToPlayer.sqrMagnitude > 1000f * 1000f) _leader.IdleDestination = _playVehicleInstance.transform.position; _leader.IdleUpDestination = leaderVehicle.transform.up; } } if (leaderVehicle != null) { for (var i = 1; i < Squadron.GetLiveCount(); i++) { var formationOffset = Formations.GetArrowOffset(i, 10f); var formationDestination = leaderVehicle.transform.position + leaderVehicle.transform.rotation * formationOffset; Squadron.GetMember(i).IdleDestination = formationDestination; Squadron.GetMember(i).IdleUpDestination = leaderVehicle.transform.up; //Debug.DrawLine(formationDestination, formationDestination + Vector3.up*100f, Color.white); } // Swap player controlled vehicle as leader. if (playerSquadronIndex != 0) { var formationOffset = Formations.GetArrowOffset(playerSquadronIndex, 10f); Squadron.GetMember(0).IdleDestination = leaderVehicle.transform.position + leaderVehicle.transform.rotation * formationOffset; Squadron.GetMember(0).IdleUpDestination = leaderVehicle.transform.up; } } if (_playVehicleInstance != null) { if (_threatCheckCooldown >= 0f) { _threatCheckCooldown -= Time.deltaTime; if (_threatCheckCooldown < 0f) { // TODO: Use non allocated Physics.OverlapSphereNonAlloc //var count = Physics.OverlapSphereNonAlloc(_playVehicleInstance.transform.position, ThreatRadius, colliders, _detectableMask); //for (var i=0; i<count;i++) //{ // var //} var detected = Physics.OverlapSphere(_playVehicleInstance.transform.position, ThreatRadius, _detectableMask); _threatCount = detected.Count(d => d.GetComponent<Detectable>().TargetTransform.GetComponent<Targetable>() != null && d.GetComponent<Detectable>().TargetTransform.GetComponent<Targetable>().Team == Targeting.GetEnemyTeam(Team)); _threatCheckCooldown = 1f; if (_threatCount == 0) _noThreatCooldown = 0f; } } /* if (_threatCount > 0) { _noThreatCooldown = NoThreatTime; } else { if (_noThreatCooldown > 0f) { _noThreatCooldown -= Time.deltaTime; } } */ if (_noThreatCooldown >= 0f) _noThreatCooldown -= Time.deltaTime; if (Squadron.GetLiveCount() < Squadron.GetMemberCount()) { //Debug.Log("REPLENISH CHECK!"); if (_noThreatCooldown < 0f) { //Debug.Log("REPLENISH!!!"); for (var i = 0; i < Squadron.GetMemberCount(); i++) { if (i != Squadron.GetCurrentIndex()) { if (Squadron.GetMember(i).VehicleInstance == null) { _spawnPos = Universe.Current.GetUniversePosition(Utility.GetRandomDirection(-Universe.Current.ViewPort.transform.forward, 80f) * 2000f); Squadron.SpawnSquadronVehicle(Squadron.GetMember(i), _spawnPos, Quaternion.identity); } } } HeadsUpDisplay.Current.RefreshSquadronIcons(); } } } if (_playVehicleInstance != null) { Debug.DrawLine(_playVehicleInstance.transform.position, _playVehicleInstance.transform.position + Vector3.up * 100f, Color.magenta); } }
private void PlayerController_OnDie(Killable sender) { _noThreatCooldown = NoThreatTime; _deathCooldown = DeathOptionTime; _lastDeathUniversePosition = new UniversePosition(_playVehicleInstance.Shiftable.UniversePosition.CellIndex, _playVehicleInstance.Shiftable.UniversePosition.CellLocalPosition); Debug.Log("PLAYER VEHICLE DESTROYED AT: " + _lastDeathUniversePosition.CellIndex); HeadsUpDisplay.Current.RefreshSquadronIcon(0); HeadsUpDisplay.Current.TriggerCrosshairFadeOut(); }
public void SpawnVehicle(Vehicle vehiclePrefab, UniversePosition universePosition, Quaternion rotation) { _playVehicleInstance = ((GameObject)Instantiate(vehiclePrefab.gameObject, universePosition.CellLocalPosition, rotation)).GetComponent<Vehicle>(); _playVehicleInstance.Controller = gameObject; _playVehicleInstance.Shiftable.SetShiftPosition(universePosition); _playVehicleInstance.GetComponent<Targetable>().Team = Team; var member = GetComponent<Fighter>(); member.SetVehicleInstance(_playVehicleInstance); _playVehicleInstance.Initialize(); var playerCurrent = Squadron.GetMember(Squadron.GetCurrentIndex()).GetComponent<ShipProfile>(); if (playerCurrent.PrimaryWeapon != null) _playVehicleInstance.SetPrimaryWeapon(playerCurrent.PrimaryWeapon.gameObject); if (playerCurrent.SecondaryWeapon != null) _playVehicleInstance.SetSecondaryWeapon(playerCurrent.SecondaryWeapon.gameObject); _playVehicleInstance.UTurnPath = UTurnPath; _playVehicleInstance.UTurnDuration = UTurnDuration; //Destroy(_playVehicleInstance.GetComponent<Tracker>()); Destroy(_playVehicleInstance.GetComponent<VehicleTracker>()); var squadronTracker = _playVehicleInstance.gameObject.AddComponent<SquadronTracker>(); squadronTracker.ArrowSprite = Squadron.ArrowSprite; //squadronTracker.TrackerSprite = Squadron.TrackerSprite; //squadronTracker.FarTrackerSprite = Squadron.FarTrackerSprite; //squadronTracker.VeryFarTrackerSprite = Squadron.VeryFarTrackerSprite; squadronTracker.LockingSprite = Squadron.LockingTrackerSprite; squadronTracker.LockedSprite = Squadron.LockedTrackerSprite; squadronTracker.CallSign = CallSign; squadronTracker.TrackerColor = TrackerColor; squadronTracker.LabelFont = Squadron.SquadronTrackerFont; squadronTracker.IsDisabled = true; var mapPin = VehicleInstance.gameObject.AddComponent<MapPin>(); mapPin.ActivePin = PlayerPinPrefab; mapPin.InactivePin = Squadron.SquadronPinPrefab; _playVehicleInstance.gameObject.layer = LayerMask.NameToLayer("Player"); _playVehicleInstance.Killable.OnDamage += PlayerController_OnDamage; _playVehicleInstance.Killable.OnDie += PlayerController_OnDie; // Apply power profile var powerProfile = GetComponent<ShipProfile>(); _playVehicleInstance.Killable.MaxShield = powerProfile.GetShield(); _playVehicleInstance.Killable.Shield = _playVehicleInstance.Killable.MaxShield; var shieldRegenerator = _playVehicleInstance.gameObject.GetComponent<ShieldRegenerator>(); shieldRegenerator.RegenerationDelay = Squadron.ShieldRegenerateDelay; shieldRegenerator.RegenerationRate = Squadron.ShieldRegenerateRate; shieldRegenerator.OnRegenerate += PlayerController_OnRegenerate; }
public void SetShiftPosition(UniversePosition position) { UniverseCellIndex = position.CellIndex; CellLocalPosition = position.CellLocalPosition; }