public void PropulsionUpdate(SubsystemReferences subsystemReferences, ThrusterControls thrusterControls) { Vector2 direction = subsystemReferences.Navigation.GetDestination() - (Vector2)subsystemReferences.currentShipPositionWithinGalaxyMapNode; direction /= direction.magnitude; direction *= 10; thrusterControls.UFODriveVelocity = direction; /*Vector3 target = new Vector3(0, 0, 0); * float targetAngle = Vector3.SignedAngle(Vector3.right, target, Vector3.forward); * float angle = Vector3.SignedAngle(Vector3.right, subsystemReferences.forward, Vector3.forward); * if (turning) * { * * if ((angle > 25) && (angle < 35)) * { * turning = false; * * } * thrusterControls.portAftThrust = 3; * * } * else { * thrusterControls.portAftThrust = 0; * } */ }
private void stopRotate(ThrusterControls thrusterControls) { thrusterControls.starboardBowThrust = 0; thrusterControls.portAftThrust = 0; thrusterControls.portBowThrust = 0; thrusterControls.starboardAftThrust = 0; }
private void rotateRight(ThrusterControls thrusterControls, float value) { Debug.Log("Rotateright called"); thrusterControls.portBowThrust = value; thrusterControls.starboardAftThrust = value; thrusterControls.starboardBowThrust = 0; thrusterControls.portAftThrust = 0; }
public void PropulsionUpdate(SubsystemReferences subsystemReferences, ThrusterControls thrusterControls) { subsystemRefs = subsystemReferences; if (engineOn) { rotateToVector2(targetVector, subsystemReferences.forward, thrusterControls); thrusterControls.mainThrust = THRUST_STRENGTH; } }
public void UsePost(GameObject player) { if (!postPlayer) { postPlayer = player; audioData.PlayOneShot(enter, 1); PV.RPC("OccupyPost", RpcTarget.Others); PhotonView playerPV = postPlayer.GetComponentInChildren <PhotonView> (); PhotonView postPV = post.GetComponent <PhotonView> (); // PhotonView[] photonViews = post.GetComponents<PhotonView>(); // foreach (PhotonView view in photonViews) // { // print(view.ViewID); // } if (postPV) { postPV.RequestOwnership(); } switch (type) { case postType.Canon: Canon tmpCanon = post.GetComponent <Canon> (); tmpCanon.enabled = true; break; case postType.Thruster: ThrusterControls tmp = post.GetComponent <ThrusterControls> (); tmp.enabled = true; break; case postType.Turret: Turret turret = post.GetComponent <Turret> (); turret.enabled = true; break; case postType.Rotate: RotateShip rotate = post.GetComponent <RotateShip> (); rotate.enabled = true; break; case postType.Shield: Shield shield = post.GetComponent <Shield> (); shield.enabled = true; break; case postType.MiniShip: postPlayer.transform.GetChild(1).gameObject.SetActive(false); MiniShip ship = post.GetComponent <MiniShip> (); ship.enabled = true; ship.ActivateShip(); break; default: break; } } }
public override void PropulsionUpdate(ShipStatusInfo shipStatusInfo, ThrusterControls thrusters, float deltaTime) { //Student code goes here //Enable the UFO drive override thrusters.IsUFODriveEnabled = true; // fly down and to the right at a speed of 141 pixels per second Vector2 velocity = new Vector2(0, -100); thrusters.UFODriveVelocity = velocity; }
public void GetOutPost() { if (postPlayer) { switch (type) { case postType.Canon: Canon tmpCanon = post.GetComponent <Canon> (); tmpCanon.enabled = false; break; case postType.Thruster: ThrusterControls tmp = post.GetComponent <ThrusterControls> (); tmp.enabled = false; break; case postType.Turret: Turret turret = post.GetComponent <Turret> (); turret.enabled = false; break; case postType.Rotate: RotateShip rotate = post.GetComponent <RotateShip> (); rotate.enabled = false; break; case postType.Shield: Shield shield = post.GetComponent <Shield> (); shield.enabled = false; break; case postType.MiniShip: postPlayer.transform.GetChild(1).gameObject.SetActive(true); MiniShip ship = post.GetComponent <MiniShip> (); ship.ReturnShip(); ship.enabled = false; break; default: break; } audioData.PlayOneShot(exit, 1); postPlayer = null; PV.RPC("FreePost", RpcTarget.Others); } }
public event Action <ColonyShip, string, string> OnShipWarped; //this, departure solar system anme, arrival solar system name //public event Action<ColonyShip, string> JumpDriveTriggered; //this, destination solar system name //public event Action<ColonyShip, bool> LandingSequenceTriggered; //this, is ship above Kepler438 // Called when the node enters the scene tree for the first time. public override void _Ready() { gameCore = FindParent("GameCore") as GameCore; collisionShape = GetNode <CollisionShape2D>("CollisionShape2D"); portForeThruster = GetNode <Thruster>("PortForeThruster"); starboardForeThruster = GetNode <Thruster>("StarboardForeThruster"); portAftThruster = GetNode <Thruster>("PortAftThruster"); starboardAftThruster = GetNode <Thruster>("StarboardAftThruster"); mainThruster = GetNode <Thruster>("MainThruster"); portRetroThruster = GetNode <Thruster>("PortRetroThruster"); starboardRetroThruster = GetNode <Thruster>("StarboardRetroThruster"); TorpedoesFired = 0; overlapArea2D = GetNode <Area2D>("OverlapArea2D"); ThrusterControls = new ThrusterControls(mainThruster, portForeThruster, portAftThruster, starboardForeThruster, starboardAftThruster, portRetroThruster, starboardRetroThruster); ThrusterControls.OnWarpJumpTriggered += TriggerJumpDrive; ThrusterControls.OnLandingSequenceTriggered += TriggerLandingSequence; turret = FindNode("Turret") as Turret; PassiveSensors = GetNode <PassiveSensors>(nameof(PassiveSensors)); ActiveSensors = GetNode <ActiveSensors>(nameof(ActiveSensors)); ActiveSensors.OnScanPerformed += HandleScanPerformed; ufoDriveParticles = GetNode <UFODriveParticles>("UFODriveParticles"); SensorsController = FindNode("SensorsSubsystemController") as AbstractSensorsController; NavigationController = FindNode("NavigationSubsystemController") as AbstractNavigationController; PropulsionController = FindNode("PropulsionSubsystemController") as AbstractPropulsionController; DefenceController = FindNode("DefenceSubsystemController") as AbstractDefenceController; SensorsController.parentShip = this; NavigationController.parentShip = this; PropulsionController.parentShip = this; DefenceController.parentShip = this; shipStatusInfo = new ShipStatusInfo(); UpdateShipStatusInfo(); }
public override void PropulsionUpdate(ShipStatusInfo shipStatusInfo, ThrusterControls thrusters, float deltaTime) { //Student code goes here }
/* * bool sensorsControllerEnabled = true; * public event Action<bool> OnSensorsControllerEnabledChanged; * public bool IsSensorsControllerEnabled {get{return sensorsControllerEnabled;} set{sensorsControllerEnabled = value; OnSensorsControllerEnabledChanged?.Invoke(sensorsControllerEnabled);}} * * * bool navigationControllerEnabled = true; * public event Action<bool> OnNavigationControllerEnabledChanged; * public bool IsNavigationControllerEnabled {get{return navigationControllerEnabled;} set{navigationControllerEnabled = value; OnNavigationControllerEnabledChanged?.Invoke(navigationControllerEnabled);}} * * bool propulsionControllerEnabled = true; * public event Action<bool> OnPropulsionControllerEnabledChanged; * public bool IsPropulsionControllerEnabled {get{return propulsionControllerEnabled;} set{propulsionControllerEnabled = value; OnPropulsionControllerEnabledChanged?.Invoke(propulsionControllerEnabled);}} * * bool defenceControllerEnabled = true; * public event Action<bool> OnDefenceControllerEnabledChanged; * public bool IsDefenceControllerEnabled {get{return defenceControllerEnabled;} set{defenceControllerEnabled = value; OnDefenceControllerEnabledChanged?.Invoke(defenceControllerEnabled);}} */ /* * //Subsystems * public AbstractSensorsController Sensors { get; private set; } * public AbstractNavigationController Navigation { get; private set; } * public AbstractDefenceController Defence { get; private set; } * public AbstractPropulsionController Propulsion { get; private set; } * * public SubsystemReferences(AbstractSensorsController sensors, AbstractNavigationController navigation, AbstractDefenceController defence, AbstractPropulsionController propulsion) * { * * Sensors = sensors; * Defence = defence; * Navigation = navigation; * Propulsion = propulsion; * } */ public abstract void ProcessPhysics(ShipStatusInfo shipStatusInfo, float deltaTime, ActiveSensors ActiveSensors, PassiveSensors passiveSensors, GalaxyMapData galaxyMapData, ThrusterControls thrusterControls, TurretControls turretControls);
public void rotateToVector2(Vector2 target, Vector2 cur, ThrusterControls thrusterControls) { if (targetVector == Vector2.zero) { return; } double otheta = Math.Atan((double)originalVector.y / (double)originalVector.x); double curtheta = Math.Atan((double)cur.y / (double)cur.x); double targettheta = Math.Atan((double)target.y / (double)target.x); double deltatheta = Math.Abs(curtheta - targettheta); // Theta you are supposed to rotate through double deltathetao = Math.Abs(otheta - targettheta); // Correct for negative angles // Dirtheta in default position fluctuates //if (curtheta < 0) { curtheta = (2 * Math.PI + curtheta); } //if (targettheta < 0) { targettheta = (2 * Math.PI + targettheta); } Debug.Log("Curtheta: " + curtheta); Debug.Log("Targettheta: " + targettheta); //Debug.Log("Deltatheta: " + deltatheta); //Debug.Log("Deltathetao: " + deltathetao); // If dirtheta is less than pos, rotate right. lr -1 is right // If dirtheta is greater than pos, rotate left. lr 1 is left int lr = 0; if (curtheta > targettheta) { Debug.Log("Target turning right!"); lr = -1; } else if (curtheta < targettheta) { Debug.Log("Target turning left!"); lr = 1; } // While the spaceship has not yet rotated through half the target distance // continue to accelerate if (deltatheta > deltathetao / 2) { Debug.Log("Speeding up rotation"); Debug.Log("LR: " + lr); if (lr == -1) { //Rotate right Debug.Log("Rotating right!"); rotateRight(thrusterControls, TURN_STRENGTH); } else if (lr == 1) { //Rotate left Debug.Log("Rotating left!"); rotateLeft(thrusterControls, TURN_STRENGTH); } } // Decelerate once the halfway point is passed if (deltatheta < deltathetao / 2) { Debug.Log("Slowing down rotation"); if (lr == -1) { //Rotate left rotateLeft(thrusterControls, TURN_STRENGTH); } else if (lr == 1) { //Rotate right rotateRight(thrusterControls, TURN_STRENGTH); } } if (Math.Abs(curtheta - targettheta) < 0.05) { Debug.Log("STOPPING ROTATE"); targetVector = Vector2.zero; stopRotate(thrusterControls); } }
public void PropulsionUpdate(SubsystemReferences subsystemReferences, ThrusterControls thrusterControls) { }
public abstract void PropulsionUpdate(ShipStatusInfo shipStatusInfo, ThrusterControls thrusters, float deltaTime);