Inheritance: SpaceObject
        void LoadData(Stream stream, int index)
        {
            if (stream != null)
            {
                try
                {
                    List<PlayerShip> ships = new List<PlayerShip>();
                    using (MemoryStream dataStream = stream.GetMemoryStream(index))
                    {
                        int position = 0;
                        do
                        {
                            PlayerShip p = new PlayerShip(dataStream, position);
                            ships.Add(p);
                            position += p.Length;

                        } while (position < dataStream.Length);
                    }
                    Ships = new ReadOnlyCollection<PlayerShip>(ships);
                }
                catch (Exception ex)
                {
                    errors.Add(ex);
                }
            }
        }
Esempio n. 2
0
    public void Save(PlayerShip ship)
    {
        if(ship == null)
        {
            GameObject go = transform.GetChild(0).gameObject;
            ship = go.GetComponent<PlayerShip>();
        }

        SaveGameShip ssg = new SaveGameShip();
        ssg.shipId = ship.id;
        ssg.SetItems(ship.GetComponent<Inventory>().items);

        // foreach weapon slot
        ssg.WeaponSlots = new SaveGameItem[ship.weaponSlots.Length];
        for (int i = 0; i < ship.weaponSlots.Length; i++)
        {
            if(ship.weaponSlots[i].items[0] != null)
            {
                SaveGameItem weapon = new SaveGameItem();
                weapon.id = ship.weaponSlots[i].items[0].id;
                ssg.WeaponSlots[i]  = weapon;
            }
            else
            {
                ssg.WeaponSlots[i] = null;
            }

        }

        string fileName = PlayerPrefs.GetString(LoadPannel.current);
        SaveGameSystem.SaveGame(ssg,fileName + shipSaveName);
    }
Esempio n. 3
0
 public Enemy(Vector2 centerPosition, PlayerShip playerShip)
     : base(centerPosition)
 {
     IsAlive = false;
     _playerShip = playerShip;
     Generate();
 }
Esempio n. 4
0
    public void HireCrewMember(PlayerShip player, SpaceStation fromStation, CrewMember crewMember)
    {
        Debug.Assert(fromStation.AvailableCrew.Contains(crewMember), "can't buy crew who aren't available to buy");

        var ship = player.Ship;
        Debug.Assert(ship != null, "can't buy stuff without a ship");

        //check ship has space
        var passengerCount = ship.GetPassengers().Count();
        if (passengerCount == ship.CurrentStats.PassengerCapacity)
        {
            throw new InvalidOperationException("no room for more passengers");
        }

        //check player has enough money
        var price = GetHirePrice(crewMember);
        if (player.Money < price)
        {
            throw new InvalidOperationException("player can't afford price of " +price);
        }

        player.AddMoney(-price);
        crewMember.Assign(ship, CrewAssignment.Passenger);
        fromStation.AvailableCrew.Remove(crewMember);
    }
Esempio n. 5
0
 public virtual void Init(float leftBound, float rightBound, PlayerShip playerShip)
 {
     this.playerShip = playerShip;
     xBoundaryLeft   = leftBound;
     xBoundaryRight  = rightBound;
     hitPoints       = maxHitPoints;
     isDeactivated   = true;
 }
Esempio n. 6
0
 public Enemies(Vector2 centerPosition, PlayerShip playerShip)
     : base(centerPosition)
 {
     for (int i = 0; i < MAX_ENEMIES; i++)
     {
         _enemies[i] = new Enemy(centerPosition, playerShip);
     }
 }
Esempio n. 7
0
 private void Awake()
 {
     ship       = GetComponent <PlayerShip>();
     navigation = GetComponent <Navigation>();
     orbiter    = GetComponent <Orbiter>();
     engine     = GetComponent <Engine>();
     hold       = GetComponent <Hold>();
 }
Esempio n. 8
0
 private void Start()
 {
     if (playerShip != null)
     {
         Destroy(playerShip);
     }
     playerShip = this;
 }
 private new void OnEnable()
 {
     _cost             = 50;
     _costIncreaseRate = 1.5f;
     buysLeft          = 20;
     playerShip        = GameObject.FindWithTag("Player").GetComponent <PlayerShip>();
     base.OnEnable();
 }
Esempio n. 10
0
 void DeactivatePowerup(PlayerShip playerShip)
 {
     // revert player powerup. - will subtract
     playerShip?.SetSpeed(-_speedIncreaseAmount);
     // visuals
     playerShip?.SetBoosters(false);
     AudioHelper.PlayClip2D(_depowered, 1);
 }
 public void Start()
 {
     nextShot_        = 0.0f;
     m_PlayerShip     = Camera.main.GetComponent <SpawnPlayer>().m_Player.GetComponent <PlayerShip>();
     m_ShipController = Camera.main.GetComponent <SpawnPlayer>().m_Player.GetComponent <ShipController>();
     //set player ammo to max
     ResetProjectileAmmo();
 }
Esempio n. 12
0
 // Called when the node enters the scene tree for the first time.
 public override void _Ready()
 {
     camera        = FindNode("Camera2D", true, true) as Camera2D;
     playerShip    = FindNode("PlayerShip", true, true) as PlayerShip;
     AsteroidField = FindNode(nameof(AsteroidField)) as Node2D;
     hud           = FindNode("HUD") as HUD;
     hud.Say("Go!");
 }
Esempio n. 13
0
 void ActivatePowerup(PlayerShip playerShip)
 {
     if (playerShip != null)
     {
         // powerup player
         playerShip.SetSize(_SizeDecreaseAmount);
     }
 }
Esempio n. 14
0
        //methods

        public static void GoToPort(int score, PlayerShip ship)
        {
            Console.Clear();
            Console.WriteLine("Your score is " + score + "\n\n");
            Console.WriteLine("What would you like to do?\n" +
                              "A) Repair 3 hull for 2 score\n" +
                              "B) Increase Weapons for 4 score\n" +
                              "C) Increase Engines for 4 score\n" +
                              "Any other key: return to the skys");
            ConsoleKey portChoice = Console.ReadKey(true).Key;

            switch (portChoice)
            {
            case ConsoleKey.A:
                if (score >= 2)
                //if (score >= 2 && ship.Hull -3 <= ship.MaxHull)
                //Add in later if the ship max hull cant take another 3
                {
                    ship.Hull = ship.Hull + 3;
                    score--;
                    score--;
                    Console.WriteLine("Hull repaired by 3.");
                }
                else if (score < 2)
                {
                    Console.WriteLine("Not high enough score to do this option.");
                }
                break;

            case ConsoleKey.B:
                if (score >= 4)
                {
                    ship.Weapons++;
                    score--;
                    score--;
                    score--;
                    score--;
                    Console.WriteLine("Ship weapons increase by 1. They are now " + ship.Weapons);
                }
                break;

            case ConsoleKey.C:
                if (score >= 4)
                {
                    ship.Engines++;
                    score--;
                    score--;
                    score--;
                    score--;
                    Console.WriteLine("Ship engines increase by 1. They are now " + ship.Engines);
                }
                break;

            default:
                Console.WriteLine("Until next time, good port");
                break;
            }
        }
Esempio n. 15
0
    public void AcceptQuest(PlayerShip player, Quest quest)
    {
        Debug.Assert(quests.Any(a => a.Quest == quest && !a.Player), "quest should not already be assigned");

        var assignment = quests.Where(a => a.Quest == quest).First();
        assignment.Player = player;

        quest.OnAccepted();
    }
 //called when a second speed boost is activated, to deactivate the first ones effects without giving wrong audio/visual feedback
 public override void RemoveDuplicateEffects(PlayerShip playerShip)
 {
     //dont apply twice
     if (poweredUp)
     {
         // prevent deactivation from happening twice
         poweredUp = false;
     }
 }
Esempio n. 17
0
 public WaitingState(GameContext gameContext, LevelContext levelContext, PlayerShip playerShip, ShipsFormation shipsFormation,
                     HudPanel hudPanel)
 {
     _gameContext    = gameContext;
     _levelContext   = levelContext;
     _playerShip     = playerShip;
     _shipsFormation = shipsFormation;
     _hudPanel       = hudPanel;
 }
Esempio n. 18
0
    public PlayerShip GetPlayer()
    {
        if (ship_ == null)
        {
            ship_ = scene_.Instance() as PlayerShip;
        }

        return(ship_);
    }
 private void SetInitialValue()
 {
     playerShip = transform.parent.GetComponent <PlayerShip>();
     if (!playerShip)
     {
         Debug.LogError("PlayerShipWeapon (SetInitialValue): PlayerShip not found!");
     }
     lineRenderer = GetComponent <LineRenderer>();
 }
    private void OnTriggerEnter(Collider other)
    {
        PlayerShip playerShip = other.gameObject.GetComponent <PlayerShip>();

        if (playerShip != null)
        {
            playerShip.Kill();
        }
    }
Esempio n. 21
0
        public override void Create(PlayerShip ParentShip)
        {
            if (MyTexture == null)
            {
                MyTexture = AssetManager.Load <Texture2D>("Textures/ShipGame/HUD/HudComponents/HudBox");
            }

            base.Create(ParentShip);
        }
Esempio n. 22
0
 public override void Create(BunnyHopGame game)
 {
     this.game        = game;
     map              = new Map();
     player           = new PlayerShip(20, 80);
     hud              = new Hud(player, STAGE);
     cameraTimer      = new Timer();
     cameraTimeToMove = 0.02f;
 }
Esempio n. 23
0
    public void FireCrewMember(PlayerShip player, SpaceStation atStation, CrewMember crewMember)
    {
        var ship = player.Ship;
        Debug.Assert(ship != null, "can't sell stuff without a ship");
        Debug.Assert(crewMember == ship.GetCaptain() || ship.GetPassengers().Contains(crewMember), "can't fire someone who doesn't work for you");

        atStation.AvailableCrew.Add(crewMember);
        crewMember.Unassign();
    }
    private void OnTriggerEnter(Collider other)
    {
        PlayerShip playerShip = other.gameObject.GetComponent <PlayerShip>();

        if (playerShip != null && _poweredUp == false)
        {
            StartCoroutine(PowerupSequence(playerShip));
        }
    }
 void DeactivatePowerup(PlayerShip playerShip)
 {
     if (playerShip != null)
     {
         WeaponController weaponController = playerShip.GetComponent <WeaponController>();
         weaponController._numLasers = 1;
         _gameAudio.MultiShotClip(false);
     }
 }
Esempio n. 26
0
 void ActivatePowerup(PlayerShip playerShip)
 {
     if (playerShip != null)
     {
         // powerup player
         playerShip.ShrinkScale();
         // visuals
     }
 }
    void Awake()
    {
        S = this;

        JUMPS = startingJumps;

        // NOTE: We don't need to check whether or not rigid is null because of [RequireComponent()] above
        rigid = GetComponent <Rigidbody>();
    }
Esempio n. 28
0
 static void Postfix(PlayerShip __instance, float hitpoints, float damage, float damage_scaled, float damage_min)
 {
     if (MPObserver.ObservedPlayer == __instance.c_player && !MPObserver.ThirdPerson && !__instance.m_dead && !__instance.m_dying)
     {
         // NOTE: This appears to be a bug with the base game... __instance.c_player.m_hitpoints is the value AFTER the damage taken, but shouldn't this be the value BEFORE the damage taken?
         float damageEffects = Mathf.Min(__instance.c_player.m_hitpoints, damage_scaled);
         GameManager.m_viewer.SetDamageEffects(damageEffects);
     }
 }
Esempio n. 29
0
 private void _weaponNotPressed(int slot, IGameTimeService gameTime, Ship playerShip)
 {
     if (playerShip.GetWeapon(slot).IsBeingHeld&& playerShip.GetWeapon(slot) is IChargable)
     {
         PlayerShip.TryFireWeapon(gameTime, slot);
         ((IChargable)playerShip.GetWeapon(slot)).ResetCharge();
     }
     playerShip.GetWeapon(slot).IsBeingHeld = false;
 }
Esempio n. 30
0
    void Awake()
    {
        jumpsManager = FindObjectOfType <JumpsManager>();

        S = this;

        // NOTE: We don't need to check whether or not rigid is null because of [RequireComponent()] above
        rigid = GetComponent <Rigidbody>();
    }
Esempio n. 31
0
    private void OnDisable()
    {
        PlayerShip ps = GameObject.FindObjectOfType <PlayerShip>(); // get PlayerShip script component from player object

        if (ps != null)
        {
            ps.OnRefreshGUI -= RefreshUnitDesription;             // remove RefreshUnitDesription from PlayerShip OnRefreshGUI delegate
        }
    }
Esempio n. 32
0
 void OnTriggerExit2D(Collider2D other)
 {
     if (other.GetComponent <PlayerShip> () != null && other.GetComponent <PlayerShip> () == CaughtPlayerShip)
     {
         BattleShip.Target = null;
         CaughtPlayerShip.BattleShip.Target = null;
         CaughtPlayerShip = null;
     }
 }
        static void Prefix(PlayerShip __instance)
        {
            if (!NetworkManager.IsServer())
            {
                return;
            }

            __instance.c_player.m_weapon_picked_up[(int)WeaponType.LANCER] = false;
        }
Esempio n. 34
0
    private void Update()
    {
        if (_playerShip == null)
        {
            _playerShip = FindObjectOfType <PlayerShip>();
        }

        _text.text = _playerShip.Speed.ToString("0#.##");
    }
Esempio n. 35
0
 public ReflectBarrier(PlayerShip owner, XY offset, int lifetime, HashSet <Projectile> reflected)
 {
     this.id        = owner.world.nextId++;
     this.owner     = owner;
     this.offset    = offset;
     this.lifetime  = lifetime;
     this.reflected = reflected;
     UpdatePosition();
 }
Esempio n. 36
0
    void ActivatePowerup(PlayerShip pShip)
    {
        _particles.Play();

        pShip?.SetSpeed(_speedChange);
        pShip?.SetBoosters(true);

        AudioHelper.PlayClip2D(_winSound, _volume);
    }
Esempio n. 37
0
    void Awake()
    {
        S = this;

        // NOTE: We don't need to check whether or not rigid is null because of [RequireComponent()] above
        rigid    = GetComponent <Rigidbody>();
        ui       = FindObjectOfType <UIHandler>();
        startPos = this.transform.position;
    }
Esempio n. 38
0
        public bool CollidesWithShip(PlayerShip ship)
        {
            if (IsActive &&
                 ship.IsActive &&
                 !ship.ShieldIsOn &&
                 _meteorSprite.CollidesWith( ship.Sprite ))
                 return true;

            return false;
        }
Esempio n. 39
0
 public MainWindow()
 {
     InitializeComponent();
     GameCanvas.Focus();
     this.playerShip = new PlayerShip();
     this.gameDrawer = new GameController(GameCanvas, playerShip);
     this.gameDrawer.drawShip();
     this.keyStatus.Add(Key.Up, false);
     this.keyStatus.Add(Key.Left, false);
     this.keyStatus.Add(Key.Right, false);
 }
Esempio n. 40
0
    void OnDestroy()
    {
        CustomInput.instance.RemHeldListener(thrust);
        CustomInput.instance.RemHeldListener(rotatel);
        CustomInput.instance.RemHeldListener(rotater);
        CustomInput.instance.RemHeldListener(dampen);
        CustomInput.instance.RemHeldListener(shoot);

        instance = null;
        Destroy(gameObject, 0);
    }
Esempio n. 41
0
 //Accessors
 //Mutators
 // This function initializes the internal pool and loads in the image to use to create all the
 // 'Enemy1' type ships. It also creates a few bullets in the pool for fast retrieval.
 public static void Initialize(ContentManager content)
 {
     zs_pool = new List<EnemyBullet1>();
     zs_image = content.Load<Texture2D>("Content\\Images\\Missiles\\Ball1");
     zs_randomGen = new Random();
     zs_playerShip = PlayerShip.getInstance();
     for (int i = 0; i < 50; i++)
     {
         zs_pool.Add(new EnemyBullet1(zs_image, null));
     }
 }
Esempio n. 42
0
 // Use this for initialization
 void Start()
 {
     if (Globals.PlayerShip != null)
     {
         shipScriptInstance = Globals.PlayerShip.GetComponent(typeof(PlayerShip)) as PlayerShip;
     }
     else
     {
         //populate the shipScriptInstance variable with the PlayerShip script attached to the Ship using its "Player" Tag
         shipScriptInstance = GameObject.FindWithTag("Player").GetComponent(typeof(PlayerShip)) as PlayerShip;
     }
 }
Esempio n. 43
0
 public GameController(Canvas gameCanvas, PlayerShip playerShip)
 {
     this.gameCanvas = gameCanvas;
     this.asteroidCollection = new List<MovableGameEntity>();
     this.gameStartTime = new DateTime();
     this.gameStartTime = DateTime.Now;
     this.asteroidsAdded = 0;
     this.asteroidsKilled = 0;
     this.playerLives = 3;
     this.playerShip = playerShip;
     this.playerShip.theGameDrawer = this;
     this.centerShipOnCanvas();
 }
Esempio n. 44
0
 public Asteroid(PlayerShip thePlayerShip, GameController theGameDrawer)
 {
     this.randomPoint = new Random();
     this.speed = randomPoint.Next(3, 7);
     this.rotation = 5;
     this.thePlayerShip = thePlayerShip;
     this.theGameDrawer = theGameDrawer;
     this.entityHeading = 0;
     this.entityCenterX = 0;
     this.entityCenterY = 0;
     this.entitySize = randomPoint.Next(10, 40);
     this.setInitialEntityPoints();
 }
    internal void Init(PlayerShip player)
    {
        HPBar.SetHP(player.HP / player.HP_MAX);
        SetWeapon("UNARMED");

        _player = player;

        player.OnCollision += OnPlayerCollision;
        player.OnWeaponChanged += OnWeaponChanged;
        _player.OnBeingHit += OnPlayerCollision;

        SetPoints(0);
    }
        public StarDefensePlayingState(StateManager gameStateManager)
        {
            _gameStateManager = gameStateManager;

            IDrawableGameComponent bullets = new Bullets(new Vector2(0.0f, 0.0f));
            IDrawableGameComponent playerShip = new PlayerShip(new Vector2(GameRoot.ScreenSize.X / 2.0f, GameRoot.ScreenSize.Y / 2.0f), (Bullets)bullets);
            IDrawableGameComponent enemies = new Enemies(new Vector2(GameRoot.ScreenSize.X / 2.0f, GameRoot.ScreenSize.Y / 2.0f), (PlayerShip)playerShip);
            IDrawableGameComponent background = new Background(new Vector2(GameRoot.ScreenSize.X / 2.0f, GameRoot.ScreenSize.Y / 2.0f), (PlayerShip)playerShip);

            _gameComponents.Add("background", background);
            _gameComponents.Add("playerShip", playerShip);
            _gameComponents.Add("bullets", bullets);
            _gameComponents.Add("enemies", enemies);
        }
Esempio n. 47
0
	protected override void Start () {
		//base.Start ();
		//cockpit.StartRadar ();
		if(instance!=null) {
			Destroy (gameObject, 0f);
			return;
		}
		instance = this;

		thrust 	= new KeyListener(CustomInput.instance.ThrustKey, 	this.ThrustEngines);
		rotatel = new KeyListener(CustomInput.instance.RotateLKey, this.RotateLeft);
		rotater = new KeyListener(CustomInput.instance.RotateRKey, this.RotateRight);
		dampen 	= new KeyListener(CustomInput.instance.DampenKey, 	this.Dampen);
		shoot 	= new KeyListener(CustomInput.instance.ShootKey, 	this.FireWeapons);

		CustomInput.instance.RegHeldListener(thrust);
		CustomInput.instance.RegHeldListener(rotatel);
		CustomInput.instance.RegHeldListener(rotater);
		CustomInput.instance.RegHeldListener(dampen);
		CustomInput.instance.RegHeldListener(shoot);
	}
Esempio n. 48
0
	public override void Die ()
	{
		instance = null;
		base.Die ();
	}
Esempio n. 49
0
    public void killPlayer(Asteroid asteroid)
    {
        asteroidCollection.Remove(asteroid);
        this.gameCanvas.Children.Remove(asteroid.entityShape);
        if (this.playerShip != null)
        {
            this.gameCanvas.Children.Remove(this.playerShip.entityShape);
            this.playerShip.setEntityCenterX(500);
            this.playerShip.setEntityCenterY(500);
            this.playerShip.setEntityHeading(0);
            this.playerLives -= 1;
        }

        if (this.playerLives > 0)
        {
            this.gameCanvas.Children.Add(this.playerShip.getEntityShape());
        }
        else { this.playerShip = null; }
    }
    void StartNewGame()
    {
        _menu.OnHideComplete -= StartNewGame;
        _menu.gameObject.SetActive(false);
        Player = PlayerShip.Instantiate(PlayerPrefab);
        Player.transform.position = Vector3.zero;

        Player.OnCollision += OnPlayerCollision;
        Player.OnBeingHit += OnPlayerBeingHit;
        Player.OnWeaponChanged += OnWeaponChanged;

        _hud.Init(Player);

        _currentGameState = _introState;
        _currentGameState.Enter();
    }
Esempio n. 51
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            this.Components.Add(this.krypton);
            _camera = new Camera(new Viewport(0, 0, Settings.Screensize.Y, Settings.Screensize.X));

            _particleRenderer = new SpriteBatchRenderer { GraphicsDeviceService = graphics };
            _particleRenderer.LoadContent(Content);
            spriteBatch = new SpriteBatch(GraphicsDevice);

            Services.AddService(typeof(SpriteBatch), spriteBatch);
            Services.AddService(typeof(SpriteBatchRenderer), _particleRenderer);
            Services.AddService(typeof(Camera), _camera);
            Services.AddService(typeof(GameComponentCollection),Components);
            Services.AddService(typeof(KryptonEngine), krypton);

            //var _block = new SmallBlock01(this, spriteBatch, new Vector2(0, 0));

            _roomlist.Add(new Room01(this, new Point(0, 0), 0));
            _roomlist.Add(new Room01(this,new Point(1,0),1));
            _roomlist.Add(new Room01(this, new Point(0,1), 2));

            _lastroom01 = new Room01(this, new Point(1, 1), 3);
            _roomlist.Add(_lastroom01);

            _playership = new PlayerShip(this);
            Components.Add(_playership);

            _cursor = new Cursor(this, spriteBatch);
            Components.Add(_cursor);

            this.krypton.Initialize();

            base.Initialize();
        }
Esempio n. 52
0
 //public void SwitchToShipCore()
 //{
 //    shipCore.SetActive(true);
 //    shipCore.transform.position = mainShip.transform.position;
 //    mainShip.SetActive(false);
 //    //cameraFollower.followObject = shipCore.transform;
 //    menu.SetShip(shipCore);
 //    shipCore.GetComponent<PlayerController>().disableInput = false;
 //    menu.playerController = shipCore.GetComponent<PlayerController>();
 //    shipCore.GetComponent<ShipCore>().SetActualStats(saveGameInfo,true);
 //    inventoryManager.ship = ship;
 //}
 public void SwitchToMainShip()
 {
     mainShip.SetActive(true);
     //mainShip.swi
        // mainShip.transform.position = shipCore.transform.position;
        // shipCore.SetActive(false);
       //  cameraFollower.followObject = mainShip.transform;
     menu.playerController = mainShip.GetComponent<PlayerController>();
     menu.SetShip(mainShip);
     reloadShipStats(true);
     ship = mainShip.GetComponent<PlayerShip>();
     if(logic)
     logic.TrackTarget(mainShip.transform);
     if(inventoryManager)
     inventoryManager.ship = ship;
 }
Esempio n. 53
0
 public void SetShip(PlayerShip newShip)
 {
     if (mainShip)
     {
         mainShip.transform.SetParent(null);
         Destroy(mainShip.gameObject);
     }
     mainShip = newShip.gameObject;
     SwitchToMainShip();
 }
Esempio n. 54
0
    public void BuyItemFromStation(PlayerShip player, int itemIndex)
    {
        var station = player.Moorable.DockedAtStation;
        var playerCargo = player.Ship.Cargo;
        var stationCargo = station.ItemsForSale;

        var itemType = stationCargo[itemIndex];

        var price = GetBuyingItemPrice(itemType, station);

        Debug.Assert(itemIndex < stationCargo.Size,
            "index of item to buy must be valid index of item in station's cargo");
        Debug.Assert(playerCargo.FreeCapacity > 0, 
            "player must have space to put bought item");
        Debug.Assert(player.Money >= price, "player must have enough money to buy item");

        stationCargo.RemoveAt(itemIndex);
        playerCargo.Add(itemType);

        player.AddMoney(-price);
    }
Esempio n. 55
0
    public void SellItemToStation(PlayerShip player, int itemIndex)
    {
        var playerCargo = player.Ship.Cargo;
        var station = player.Moorable.DockedAtStation;
        var stationCargo = station.ItemsForSale;

        var itemType = playerCargo[itemIndex];

        var price = GetSellingItemPrice(itemType, station);

        Debug.Assert(playerCargo && itemIndex < playerCargo.Size,
            "index of item to sell must be valid index of item in player's cargo");

        if (stationCargo.FreeCapacity == 0)
        {
            //station cargo space is infinite
            ++stationCargo.Size;
        }

        playerCargo.RemoveAt(itemIndex);
        stationCargo.Add(itemType);

        player.AddMoney(price);
    }
 void Awake()
 {
     pShip = GetComponent<PlayerShip>();
 }
Esempio n. 57
0
 public void SetUp()
 {
     playerShip = new PlayerShip();
 }
Esempio n. 58
0
    public void BuyShip(PlayerShip player, ShipType shipType, SpaceStation atStation)
    {
        var shipForSale = GetShipForSale(shipType);
        var oldShip = player.Ship;

        //check price
        Debug.Assert(player.Money >= shipForSale.Price, 
            "player can't afford to buy ship");

        var passengers = oldShip.GetPassengers();
        var captain = oldShip.GetCaptain();

        //check crew space
        Debug.Assert(shipForSale.ShipType.Stats.PassengerCapacity < passengers.Count(),
            "ship being bought doesn't have enough room for existing passengers");

        var newShip = shipType.CreateShip(player.transform.position, player.transform.rotation);
        
        //copy player
        var newPlayer = newShip.gameObject.AddComponent<PlayerShip>();
        newPlayer.AddMoney(player.Money - shipForSale.Price);

        //copy crew
        captain.Assign(newShip, CrewAssignment.Captain);
        foreach (var passenger in passengers)
        {
            passenger.Assign(newShip, CrewAssignment.Passenger);
        }
            
        Destroy(player.gameObject);
        SpaceTraderConfig.LocalPlayer = newPlayer;
    }
Esempio n. 59
0
 public Background(Vector2 centerPosition, PlayerShip playerShip)
     : base(centerPosition)
 {
     DrawParallax = true;
     _playerShip = playerShip;
 }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            this.gameFont = this.Content.Load<SpriteFont>("Arial");
            this.waterMapTexture = this.Content.Load<Texture2D>("waterMap");
            this.watermapRect = new Rectangle(0, 0, GlobalConstants.WINDOW_WIDTH, GlobalConstants.WINDOW_HEIGHT);
            this.continent1 = new Continent(this.Content,"con1",500,100,250,250);
            this.continent2 = new Continent(this.Content, "con2", 40, 40, 300, 300);
            this.continent3 = new Continent(this.Content, "con3", 40, 300, 300, 300);
            this.playerShip = new PlayerShip(this.Content, "pirate_ship", GlobalConstants.WINDOW_WIDTH / 2, GlobalConstants.WINDOW_HEIGHT / 2);
            this.npcs = new List<NpcShip>
            {
                new NpcShip(this.Content,"pirate_ship_npc1",300,200,new Vector2(500,100)),
                new NpcShip(this.Content,"pirate_ship_npc1",500,300),
                new NpcShip(this.Content,"pirate_ship_npc1",400,400,new Vector2(240,520)),
                new NpcShip(this.Content,"big_ship",570,490,100,100)
            };
            // add fishing village
            this.fishingVillage1 = new FishingVillage(2, 200, 10, 10000, 150, 1000, 30, Coutries.Tanzania,
                this.Content, "fishing_village", 500, 100, 100, 100);
            // add trade center
            this.tradeCenter1 = new TradeCenter(5000, 50, 100000, 800, 6000, 50, Coutries.Yemen,
                this.Content, "trade_center", 100, 470, 128, 128);
            // add military settlement
            this.militaryPort1 = new MilitaryPort(0, 200, 150, 500, 800, 300, Coutries.Yemen, this.Content, "military_settlement", 180, 310, 128, 128);            
            
            this.continents = new List<PirateGame.Interfaces.IDrawableCustom>
            {
                this.continent1,
                this.continent2,
                this.continent3,
            };
            this.shipMessages = new List<string>
            {
                string.Format("Hull:{0}", this.playerShip.Hull),
                string.Format("Weapons:{0}", this.playerShip.Weapons),
                string.Format("Hit Points:{0}", this.playerShip.Hitpoints),
                string.Format("Damage:{0}", this.playerShip.Damage)
            };
            
            this.fishingMessages = new List<string>
            {
                "Fishing Village",
                string.Format("Population:{0}", this.fishingVillage1.Population),
                string.Format("Wealth:{0}", this.fishingVillage1.Wealth),
                string.Format("Defense Power:{0}", this.fishingVillage1.DefencePower)
            };
            
            this.tradeMessages = new List<string>
            {
                "Trade Center",
                string.Format("Population:{0}", this.tradeCenter1.Population),
                string.Format("Wealth:{0}", this.tradeCenter1.Wealth),
                string.Format("Defense Power:{0}", this.tradeCenter1.DefencePower)
            };
            
            this.militaryMessages = new List<string>
            {
                "Military Port",
                string.Format("Population:{0}", this.militaryPort1.Population),
                string.Format("Wealth:{0}", this.militaryPort1.Wealth),
                string.Format("Defense Power:{0}", this.militaryPort1.DefencePower)
            };
            
            this.shipPopup = new Popup(this.Content, "popup_background", "Arial", this.shipMessages, this.playerShip);
            this.fishingPopup = new Popup(this.Content, "popup_background", "Arial", this.fishingMessages, this.fishingVillage1);
            this.tradePopup = new Popup(this.Content, "popup_background", "Arial", this.tradeMessages, this.tradeCenter1);
            this.militaryPopup = new Popup(this.Content, "popup_background", "Arial", this.militaryMessages, this.militaryPort1);

            this.UIFrameTexture = this.Content.Load<Texture2D>("InventoryHighlight.png");

            Menu main = new Menu(this, "Pirate Menu", menus.OnOpen, menus.OnClose);
            main.Initialize();
            main.LoadContent();
            main.Items.Add(new SelectableItem<string>("Play", this.OnPlay));
            main.Items.Add(new SelectableItem<string>("Test Inventory", this.OnInventoryTest));
            main.Items.Add(new SelectableItem<string>("Test Health Bar", this.OnHealthBarTest));
            main.Items.Add(new SelectableItem<string>("Quit", this.OnExit));
            this.mainMenu = new Frame(main, this.UIFrameTexture, Color.Gray);
            this.UIElements.Add(this.mainMenu);
        }