private void Update()
    {
        bool isPressed = PlayerKeyboard.IsKeyboardThrustersOn;

        if (isPressed && Thrusters.OfShipInitialized)
        {
            //determine how to move the ship
            PlayerMoveEnum choice = PlayerMoveEnum.Undetermined;
            if (Input.GetAxis("Horizontal") > 0) //right
            {
                choice = PlayerMoveEnum.LeftThruster;
            }
            else if (Input.GetAxis("Horizontal") < 0) //left
            {
                choice = PlayerMoveEnum.RightThruster;
            }
            if (Input.GetAxis("Vertical") > 0) //up
            {
                //retain horizontal movement in choice
                choice = (PlayerMoveEnum)((int)PlayerMoveEnum.BottomThruster + (int)choice);
            }

            //determine how much to move in choice direction
            Thrusters thrusters = new Thrusters()
            {
                ThrusterBottom = Globals.BottomThruster,
                ThrusterLeft   = Globals.LeftThruster,
                ThrusterRight  = Globals.RightThruster,
            };
            Vector3 shipForce = thrusters.ThrustOn(choice);

            //move the ship
            Globals.PlayerShip.AddForce(shipForce);
        }
    }
    private void Update()
    {
        bool isPressed = PlayerKeyboard.IsKeyboardThrustersOn;
        if (isPressed && Thrusters.OfShipInitialized)
        {
            //determine how to move the ship
            PlayerMoveEnum choice = PlayerMoveEnum.Undetermined;
            if (Input.GetAxis("Horizontal") > 0) //right
            {
                choice = PlayerMoveEnum.LeftThruster;
            }
            else if (Input.GetAxis("Horizontal") < 0) //left
            {
                choice = PlayerMoveEnum.RightThruster;
            }
            if (Input.GetAxis("Vertical") > 0) //up
            {
                //retain horizontal movement in choice
                choice = (PlayerMoveEnum)((int)PlayerMoveEnum.BottomThruster + (int)choice);
            }

            //determine how much to move in choice direction
            Thrusters thrusters = new Thrusters()
            {
                ThrusterBottom = Globals.BottomThruster,
                ThrusterLeft = Globals.LeftThruster,
                ThrusterRight = Globals.RightThruster,
            };
            Vector3 shipForce = thrusters.ThrustOn(choice);

            //move the ship
            Globals.PlayerShip.AddForce(shipForce);
        }
    }
示例#3
0
        void Main()
        {
            var blocks = new List <IMyTerminalBlock>();

            GridTerminalSystem.GetBlocksOfType <IMyShipController>(blocks, NoPassenger);
            if (blocks.Count == 0)
            {
                throw new Exception("No ship controller (cockpit, etc.) available.");
            }

            controller = blocks[0] as IMyShipController;
            blocks     = new List <IMyTerminalBlock>();
            GridTerminalSystem.GetBlocksOfType <IMyThrust>(blocks);

            Thrusters thrusts = new Thrusters(controller, blocks);

            debug.Append(thrusts.MinAcceleration).AppendLine();
            debug.Append(thrusts.MaxAcceleration).AppendLine();
            debug.Append(thrusts.DefaultAcceleration).AppendLine();

            thrusts.AccelerateForward(thrusts.MaxAcceleration);
            thrusts.AccelerateBackward(thrusts.MaxAcceleration);
            thrusts.AccelerateUp(thrusts.MaxAcceleration);
            thrusts.AccelerateDown(thrusts.MaxAcceleration);
            thrusts.AccelerateRight(thrusts.MaxAcceleration);
            thrusts.AccelerateLeft(thrusts.MaxAcceleration);

            Debug(debug.ToString());
            debug.Clear();
        }
示例#4
0
    void Update()
    {
        if (isPressed && Thrusters.OfShipInitialized)
        {
            //determine how much to move in choice direction
            Thrusters thrusters = new Thrusters()
            {
                ThrusterBottom = Globals.BottomThruster,
                ThrusterLeft   = Globals.LeftThruster,
                ThrusterRight  = Globals.RightThruster,
            };
            Vector3 shipForce = thrusters.ThrustOn(choice);

            //move the ship
            Globals.PlayerShip.AddForce(shipForce);

            if (Globals.IsSoundOn && clipWhilePressed != null && clipWhilePressed.isReadyToPlay)
            {
                PlaySound(clipWhilePressed);
            }
        }
        else
        {
            //TODO: turn off thruster audio
        }
    }
示例#5
0
    public void NotifyPartDestroyed(ShipPart part)
    {
        parts.Remove(part);
        parts = parts.Where(p => p != null).ToList(); // HACK! Don't know why I need this. Single cockpit throws errors otherwise
        cameraManager.AddScreenShake(1.5f);

        Thrusters thruster = part.GetComponent <Thrusters>();

        if (thruster != null)
        {
            thrusters.Remove(thruster);
        }

        ProjectileWeapon weapon = part.GetComponent <ProjectileWeapon>();

        if (weapon != null)
        {
            weapons.Remove(weapon);
        }

        if (part.partName == "Cockpit")
        {
            // Inverse for loop because each death will modify parts with the callback
            Debug.LogFormat("Killing remaining {0} parts", parts.Count);
            for (int i = parts.Count - 1; i >= 0; i--)
            {
                // TODO: It would be really cool if we could show each part blowing up in succession
                parts[i].TakeDamage(parts[i].maxHealth);
            }
            Destroy(gameObject);
        }
    }
示例#6
0
    void Start()
    {
        thrusters = new Thrusters();

        //Automatically populate the Gui variable with the Gui script attached to the EmptyObject Gui using its Gui Tag
        Gui = GameObject.FindWithTag("Gui").GetComponent(typeof(GuiInGame)) as GuiInGame;
    }
示例#7
0
    public void RegisterParts(List <ShipPart> parts)
    {
        Debug.Log(string.Join(", ", parts.Where(p => p != null).Select(p => p.name)));
        this.parts = parts.Distinct().ToList();    // Some bug with dupes somewhere... HACK!
        rb         = GetComponent <Rigidbody2D>(); // Might get called before Start

        foreach (ShipPart part in parts)
        {
            if (part == null)
            {
                continue;
            }

            part.transform.parent = transform;

            // Organize thrusters into categories
            Thrusters partThrusters = part.GetComponent <Thrusters>();
            if (partThrusters != null)
            {
                thrusters.Add(partThrusters);
            }
            else if (part.GetComponent <ProjectileWeapon>() != null)
            {
                weapons.Add(part.GetComponent <ProjectileWeapon>());
            }

            // Set density. Every part has the same volume, so just use mass directly
            part.GetComponent <Collider2D>().density = part.mass;

            // Tag to the same layer as the parent
            part.gameObject.layer = gameObject.layer;
        }
    }
示例#8
0
        public void AddThruster()
        {
            RCSThruster          thruster = new RCSThruster();
            RCSThrusterViewModel vm       = new RCSThrusterViewModel(thruster);

            Thrusters.Add(vm);
            _rcs.thrusters.Add(thruster);
        }
示例#9
0
    public void UpdateModuleStatus(ShipModule module, GameTypes.ModuleType type, bool connected)
    {
        switch (type)
        {
        case GameTypes.ModuleType.FuelPack:
            if (connected)
            {
                fuelPack = module.GetComponent <FuelPack>();
                Debug.Log("Ship: Fuel pack connected");
            }
            else
            {
                fuelPack = null;
                Debug.Log("Ship: Fuel pack disconnected");
            }
            break;

        case GameTypes.ModuleType.Thrusters:
            if (connected)
            {
                thrusters = module.GetComponent <Thrusters>();
                Debug.Log("Ship: Thrusters connected");
            }
            else
            {
                thrusters = null;
                Debug.Log("Ship: Thrusters disconnected");
            }
            break;

        case GameTypes.ModuleType.Boosters:
            if (connected)
            {
                boosters = module.GetComponent <Boosters>();
                Debug.Log("Ship: Boosters connected");
            }
            else
            {
                boosters = null;
                Debug.Log("Ship: Boosters disconnected");
            }
            break;

        case GameTypes.ModuleType.QuantumDrive:
            if (connected)
            {
                quantumDrive = module.GetComponent <QuantumDrive>();
                Debug.Log("Ship: Quantum Drive connected");
            }
            else
            {
                quantumDrive = null;
                Debug.Log("Ship: Quantum Drive disconnected");
            }
            break;
        }
    }
        private Vector3D CalculateForces(State state)
        {
            Vector3D weight = new Vector3D(0.0, 0.0, _airplane.World.Gravity * Mass);
            Vector3D thrust = new Vector3D();

            thrust = Thrusters.Aggregate(thrust, (current, thruster) => current + thruster.Trust);
            thrust = new Vector3D(thrust.X * Math.Cos(state.AngularPosition.Y), thrust.X * Math.Sin(state.AngularPosition.Y), 0);
            return(weight + thrust);
        }
示例#11
0
        public void AddThrusters(List <IMyTerminalBlock> blocks)
        {
            if (thrusts == null)
            {
                thrusts = new Thrusters(ReferenceBlock, blocks);
                return;
            }

            thrusts.UpdateThrusters(blocks);
        }
示例#12
0
 public void RefreshModules()
 {
     boosters     = GetComponentInChildren <Boosters>();
     thrusters    = GetComponentInChildren <Thrusters>();
     fuelTank     = GetComponentInChildren <FuelTank>();
     assistModule = GetComponentInChildren <AssistModule>();
     quantumDrive = GetComponentInChildren <QuantumDrive>();
     landingGear  = GetComponentInChildren <LandingGear>();
     lights       = GetComponentInChildren <Lights>();
 }
示例#13
0
    public void ChangeHealth(int points)
    {
        if (!isImmune)
        {
            if (points < 0 || lives[PlayerIndex] < MaxLives)
            {
                lives[PlayerIndex] += points;
                if (lives[PlayerIndex] < 0)
                {
                    lives[PlayerIndex] = 0;
                }
                uIManager.UpdateLives(lives[PlayerIndex], PlayerIndex);
                isImmune = true;
                StartCoroutine(ImmuneTimer());
            }
        }
        else
        {
            isImmune = false;
            Shields.SetActive(false);
        }
        switch (lives[PlayerIndex])
        {
        case 0:
            animator.SetTrigger("DeathTrigger");
            audioSource.PlayOneShot(ExplosionClip);
            Thrusters.SetActive(false);
            RightEngineFire.SetActive(false);
            LeftEngineFire.SetActive(false);
            Destroy(GetComponent <Collider2D>());
            Destroy(this.gameObject, 2.65f);
            break;

        case 1:
            RightEngineFire.SetActive(true);
            break;

        case 2:
            LeftEngineFire.SetActive(true);
            RightEngineFire.SetActive(false);
            break;

        case 3:
            LeftEngineFire.SetActive(false);
            break;

        default:
            Debug.LogError("Error in Player" + PlayerIndex + 1 + "Lives");
            break;
        }
    }
示例#14
0
    void Start()
    {
        // Get Ship Components
        rigidBody2D      = GetComponent <Rigidbody2D>();
        circleCollider2D = GetComponent <CircleCollider2D>();
        shipSensors      = GetComponent <ShipSensors>();
        turret           = GetComponent <Turret>();
        thrusters        = GetComponent <Thrusters>();
        thrusters.thrusterControlInputs.OnWarpJumpTriggered += HandleWarpJumpTriggered;

        UpdateSystemReference();

        // Health Bar
        healthbar       = GameObject.FindGameObjectWithTag("HealthBar").GetComponent <Slider>();
        shipHealth      = 0f;
        healthbar.value = HealthRatio;
    }
示例#15
0
 public bool SetThruster(Thrusters thruster, int value)
 {
     try
     {
         ArduinoCommand command = new ArduinoCommand()
         {
             Command = Command.SetThruster,
             NumberOfReturnedBytes = 0
         };
         command.AddParameter((int)thruster);
         command.AddParameter(value);
         {
             byte[] toWrite = command.GetCommandBytes();
             stream.Write(toWrite, 0, toWrite.Length);
             return(true);
         }
     }
     catch (Exception) { return(false); }
 }
    // Start is called before the first frame update
    void Start()
    {
        _playerAudioSource = GetComponent <AudioSource>();

        ui_Manager   = GameObject.Find("Canvas").GetComponent <UIManager>();
        _waveSpawner = GameObject.Find("WaveSpawner").GetComponent <WaveSpawner>();

        _cameraShake = GameObject.Find("Main Camera").GetComponent <CameraShake>();

        _thrusters = GameObject.Find("Canvas").GetComponentInChildren <Thrusters>();

        healthBar = GameObject.FindGameObjectWithTag("ShieldHealth").GetComponent <HealthBar>();
        healthBar.SetHealth(0);

        ui_Manager.UpdateAmmo(15);

        if (_playerAudioSource == null)
        {
            Debug.LogError("Audio Source on the player is null!");
        }
        else
        {
            _playerAudioSource.clip = _laserSoundClip;
        }

        if (_thrusters == null)
        {
            Debug.LogError("Thrusters Bar is null!");
        }

        if (ui_Manager == null)
        {
            Debug.LogError("UI Manager is null!");
        }

        if (_waveSpawner == null)
        {
            Debug.LogError("Wave Spawner is null!");
        }

        _shield.SetActive(false);
        _sparkPrefab.SetActive(false);
    }
示例#17
0
 void Start()
 {
     thrusters = new Thrusters();
 }
 private double ImmediateHourlyFuelConsumption()
 {
     return(Thrusters.Sum(thruster => thruster.HourlyConsumption));
 }
示例#19
0
 public void RemoveThruster(RCSThrusterViewModel thruster)
 {
     Thrusters.Remove(thruster);
     _rcs.thrusters.Remove(thruster.Model);
 }
示例#20
0
    void Update()
    {
        if (isPressed && Thrusters.OfShipInitialized)
        {
            //determine how much to move in choice direction
            Thrusters thrusters = new Thrusters()
            {
                ThrusterBottom = Globals.BottomThruster,
                ThrusterLeft = Globals.LeftThruster,
                ThrusterRight = Globals.RightThruster,
            };
            Vector3 shipForce = thrusters.ThrustOn(choice);

            //move the ship
            Globals.PlayerShip.AddForce(shipForce);

            if (Globals.IsSoundOn && clipWhilePressed != null && clipWhilePressed.isReadyToPlay)
                PlaySound(clipWhilePressed);
        }
        else
        {
            //TODO: turn off thruster audio
        }
    }
示例#21
0
    public static Components decode(Dictionary <string, dynamic> companion)
    {
        try
        {
            //RootObject shipObj = new RootObject();
            Components shipObj = new Components();

            if (!companion.ContainsKey("ship") && !companion["ship"].ContainsKey("modules"))
            {
                Debug.Write("Companion JSON is missing ship information");
                return(null);
            }

            string currentShip = companion["ship"]["name"];

            // Store in Frontier format, helper methods will expect that.
            shipObj.attributes.shiptype = currentShip;

            // Cargo hatch isn't in the companion API
            CargoHatch newCargoHatch = new CargoHatch();
            newCargoHatch.enabled  = true;
            newCargoHatch.priority = 5;

            shipObj.standard.cargoHatch = newCargoHatch;

            foreach (KeyValuePair <string, dynamic> currModule in companion["ship"]["modules"])
            {
                Dictionary <string, dynamic> mod;
                string moduleName = "";
                if (currModule.Value.GetType() == typeof(System.Collections.ArrayList))
                {
                    // Companion returns an empty array of there is nothing in the slot
                    mod = null;
                }
                else
                {
                    mod        = currModule.Value["module"];
                    moduleName = mod["name"].ToLower();
                }
                if (currModule.Key.Contains("Armour"))
                {
                    shipObj.standard.bulkheads = mapBulkhead(moduleName);
                }
                else if (currModule.Key.Contains("PowerPlant"))
                {
                    PowerPlant newPowerPlant = new PowerPlant();
                    newPowerPlant.@class        = mapClass(moduleName);
                    newPowerPlant.rating        = mapRating(moduleName);
                    newPowerPlant.priority      = 1;
                    newPowerPlant.enabled       = mod["on"];
                    shipObj.standard.powerPlant = newPowerPlant;
                }
                else if (currModule.Key.Contains("MainEngines"))
                {
                    Thrusters newThrusters = new Thrusters();
                    newThrusters.@class        = mapClass(moduleName);
                    newThrusters.rating        = mapRating(moduleName);
                    newThrusters.priority      = mapPriority(mod["priority"]);
                    newThrusters.enabled       = mod["on"];
                    shipObj.standard.thrusters = newThrusters;
                }
                else if (currModule.Key.Contains("FrameShiftDrive"))
                {
                    FrameShiftDrive newFrameShiftDrive = new FrameShiftDrive();
                    newFrameShiftDrive.@class        = mapClass(moduleName);
                    newFrameShiftDrive.rating        = mapRating(moduleName);
                    newFrameShiftDrive.priority      = mapPriority(mod["priority"]);
                    newFrameShiftDrive.enabled       = mod["on"];
                    shipObj.standard.frameShiftDrive = newFrameShiftDrive;
                }
                else if (currModule.Key.Contains("LifeSupport"))
                {
                    LifeSupport newLifeSupport = new LifeSupport();
                    newLifeSupport.@class        = mapClass(moduleName);
                    newLifeSupport.rating        = mapRating(moduleName);
                    newLifeSupport.priority      = mapPriority(mod["priority"]);
                    newLifeSupport.enabled       = mod["on"];
                    shipObj.standard.lifeSupport = newLifeSupport;
                }
                else if (currModule.Key.Contains("PowerDistributor"))
                {
                    PowerDistributor newPowerDistributor = new PowerDistributor();
                    newPowerDistributor.@class        = mapClass(moduleName);
                    newPowerDistributor.rating        = mapRating(moduleName);
                    newPowerDistributor.priority      = mapPriority(mod["priority"]);
                    newPowerDistributor.enabled       = mod["on"];
                    shipObj.standard.powerDistributor = newPowerDistributor;
                }
                else if (currModule.Key.Contains("Radar"))
                {
                    Sensors newSensors = new Sensors();
                    newSensors.@class        = mapClass(moduleName);
                    newSensors.rating        = mapRating(moduleName);
                    newSensors.priority      = mapPriority(mod["priority"]);
                    newSensors.enabled       = mod["on"];
                    shipObj.standard.sensors = newSensors;
                }
                else if (currModule.Key.Contains("FuelTank"))
                {
                    FuelTank newFuelTank = new FuelTank();
                    newFuelTank.@class        = mapClass(moduleName);
                    newFuelTank.rating        = mapRating(moduleName);
                    newFuelTank.priority      = mapPriority(mod["priority"]);
                    newFuelTank.enabled       = mod["on"];
                    newFuelTank.capacity      = mapFuelCapacity(newFuelTank.@class);
                    shipObj.standard.fuelTank = newFuelTank;
                }
                else if (currModule.Key.StartsWith("Slot"))
                {
                    Regex re = new Regex(@"Slot([0-9]+)_Size([0-9]+)");
                    Match m  = re.Match(currModule.Key);
                    if (m.Success)
                    {
                        int slotPos  = Int32.Parse(m.Groups[1].ToString());
                        int slotSize = Int32.Parse(m.Groups[2].ToString());
                        addInternal(slotPos, slotSize, mod, ref shipObj);
                    }
                    else
                    {
                        Debug.Write("Error:  Unexpected module in Companion Output: " + currModule.Key);
                    }
                }
                else if (currModule.Key.StartsWith("Tiny"))
                {
                    Regex re = new Regex(@"[^0-9]*([0-9]+)");
                    Match m  = re.Match(currModule.Key);
                    if (m.Success)
                    {
                        int slotPos = Int32.Parse(m.Groups[1].ToString());
                        addUtility(slotPos, mod, ref shipObj);
                    }
                    else
                    {
                        Utilities.ReportMissingData(currModule.Key);
                        Debug.Write("Error:  Unexpected module in Companion Output: " + currModule.Key);
                    }
                }
                if (currModule.Key.StartsWith("Huge"))
                {
                    Regex re = new Regex(@"[^0-9]*([0-9]+)");
                    Match m  = re.Match(currModule.Key);
                    if (m.Success)
                    {
                        int slotPos = Int32.Parse(m.Groups[1].ToString());
                        addHardpoint("Huge", slotPos, mod, ref shipObj);
                    }
                    else
                    {
                        Utilities.ReportMissingData(currModule.Key);
                        Debug.Write("Error:  Unexpected module in Companion Output: " + currModule.Key);
                    }
                }
                else if (currModule.Key.StartsWith("Large"))
                {
                    Regex re = new Regex(@"[^0-9]*([0-9]+)");
                    Match m  = re.Match(currModule.Key);
                    if (m.Success)
                    {
                        int slotPos = Int32.Parse(m.Groups[1].ToString());
                        addHardpoint("Large", slotPos, mod, ref shipObj);
                    }
                    else
                    {
                        Utilities.ReportMissingData(currModule.Key);
                        Debug.Write("Error:  Unexpected module in Companion Output: " + currModule.Key);
                    }
                }
                else if (currModule.Key.StartsWith("Medium"))
                {
                    Regex re = new Regex(@"[^0-9]*([0-9]+)");
                    Match m  = re.Match(currModule.Key);
                    if (m.Success)
                    {
                        int slotPos = Int32.Parse(m.Groups[1].ToString());
                        addHardpoint("Medium", slotPos, mod, ref shipObj);
                    }
                    else
                    {
                        Utilities.ReportMissingData(currModule.Key);
                        Debug.Write("Error:  Unexpected module in Companion Output: " + currModule.Key);
                    }
                }
                else if (currModule.Key.StartsWith("Small"))
                {
                    Regex re = new Regex(@"[^0-9]*([0-9]+)");
                    Match m  = re.Match(currModule.Key);
                    if (m.Success)
                    {
                        int slotPos = Int32.Parse(m.Groups[1].ToString());
                        addHardpoint("Small", slotPos, mod, ref shipObj);
                    }
                    else
                    {
                        Utilities.ReportMissingData(currModule.Key);
                        Debug.Write("Error:  Unexpected module in Companion Output: " + currModule.Key);
                    }
                }
            }
            return(shipObj);
        }
        catch (Exception ex)
        {
            Debug.Write(ex.ToString());
        }
        return(null);
    }
示例#22
0
    void Start()
    {
        thrusters = new Thrusters();

        //Automatically populate the Gui variable with the Gui script attached to the EmptyObject Gui using its Gui Tag
        Gui = GameObject.FindWithTag("Gui").GetComponent(typeof(GuiInGame)) as GuiInGame;
    }
示例#23
0
 void Start()
 {
     thrusters = new Thrusters();
 }
示例#24
0
    private void HandleClick()
    {
        Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        int     x        = Mathf.RoundToInt(mousePos.x);
        int     y        = Mathf.RoundToInt(mousePos.y);

        if (x < 0 || x >= levelData.shipWidth || y < 0 || y >= levelData.shipHeight)
        {
            return;
        }

        // TEMP DEBUGGING - FAST BUILDING BUT NO CONSTRAINTS. Or is it? ;)
        if (inFlightPart == null && gridParts[x, y] == null && !nothingUI.gameObject.activeSelf)
        {
            inFlightPart = Instantiate(selectedPart, Utils.GetMouseWorldPos(), Quaternion.identity);
        }

        if (inFlightPart == null)
        {
            gridParts[x, y].transform.rotation = Quaternion.Euler(0, 0, gridParts[x, y].transform.rotation.eulerAngles.z - 90);
            Thrusters gridThrusters = gridParts[x, y].GetComponent <Thrusters>();
            if (gridThrusters != null)
            {
                gridThrusters.ActivateThruster(gridParts[x, y].transform.rotation);
                gridThrusters.DisableThruster();
            }
        }
        else
        {
            RemovePartFromGrid(x, y);
            gridParts[x, y] = inFlightPart;
            inFlightPart.transform.position = new Vector2(x, y);
            string key = inFlightPart.partName + inFlightPart.mark;
            inventory[key]--;
            if (inventory[key] == 0)
            {
                inventory.Remove(key);
                partScrollIndex = Mathf.Min(partScrollIndex, inventory.Count - partSelectButtons.Length);
                if (partScrollIndex < 0)
                {
                    partScrollIndex = 0;
                }
                SetupPartSelectionUI();
                SetupSelectedPartUI(0);
            }
            else
            {
                SP_place.text = "Inventory: " + inventory[key];
            }
            if (inFlightPart.partName == "Cockpit")
            {
                playButton.interactable = true;
            }
            inFlightPart = null;
        }
        if (gridParts[x, y] != null)
        {
            //gridSlotSelectedObj.gameObject.SetActive(true);
            removePartButton.interactable          = true;
            rotatePartButton.interactable          = true;
            gridSlotSelectedObj.transform.position = new Vector2(x, y);
        }
    }