示例#1
0
    public void Load()
    {
        shopManager.GetComponent <ResourceInventory>().Load();
        player.Load();                 // must be before levelTree
        levelTree.Load();
        questSystem.loadQuests = true; //Load();
        shopManager.Load();
        money.Load();

        if (loadingFromSave) // will only do this if loading at start. only here to help dev testing
        {
            home.Load();
            planetGenerator.Load();
            //loadingFromSave = false;
        }
        inventory.Load();
        alminac.Load();

        if (PlayerPrefs.GetInt("lightsOn") == 1)
        {
            toggleLights();
        }
        if (PlayerPrefs.GetInt("popupsOn") == 1)
        {
            togglePopups();
        }

        map.Load();
        BM.Broadcast("Loaded");
        player.Load();
        FindObjectOfType <EnemyInvasionManager>().Load();
        MaxItemsManager.Load();
        player.gameObject.GetComponent <PlayerController>().Load();
    }
示例#2
0
 public void damage(float hitPoints)
 {
     health -= hitPoints;
     if (health <= 0)
     {
         GameObject exp = Instantiate(deathExplosion);
         exp.transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z);
         spawnExp();
         MaxItemsManager.destroyLootCrate(rarityLevel);
         Destroy(gameObject);
     }
 }
示例#3
0
    public void Save()
    {
        if (!canSave)
        {
            BM.Broadcast("You can not save at this time!");
            return;
        }
        if (!player.isHome)
        {
            BM.Broadcast("You can not save outside of your home!");
            return;
        }
        PlayerPrefs.SetInt("GameSaved", 1);
        player.Save(); // must be before levelTree
        levelTree.Save();
        questSystem.Save();
        shopManager.Save();
        planetGenerator.Save();
        money.Save();
        shopManager.GetComponent <ResourceInventory>().Save();
        alminac.Save();
        inventory.Save();
        if (popupsOn)
        {
            PlayerPrefs.SetInt("popupsOn", 1);
        }
        else
        {
            PlayerPrefs.SetInt("popupsOn", 0);
        }

        if (lightsOn)
        {
            PlayerPrefs.SetInt("lightsOn", 1);
        }
        else
        {
            PlayerPrefs.SetInt("lightsOn", 0);
        }

        map.Save();
        home.Save();
        BM.Broadcast("Saved");
        player.Save();
        FindObjectOfType <EnemyInvasionManager>().Save();
        MaxItemsManager.Save();
        player.gameObject.GetComponent <PlayerController>().Save();
    }
示例#4
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (Input.GetKey(KeyCode.Mouse0) && main.gameObject.activeSelf && canShoot && newCanShoot)
        {
            float rotation = (rb.rotation + 90);
            if (weapon.GetComponent <Weapon>().Shoot(transform.Find("Barrel").position, new Vector2(Mathf.Cos(((rotation) * Mathf.PI) / 180), Mathf.Sin(((rotation) * Mathf.PI) / 180)), gameObject.GetComponent <Rigidbody2D>().velocity))
            {
                audioManager.Play("LazerShoot");
            }
        }

        if (Input.GetKey("f") && hasSheilds && canSheild && sheilding == false)
        {
            timeToReclick = .25f;
            sheild       -= shieldConsumption;
            sheildBar.GetComponent <RectTransform>().localScale = new Vector3(sheild / maxSheild,
                                                                              sheildBar.GetComponent <RectTransform>().localScale.y,
                                                                              sheildBar.GetComponent <RectTransform>().localScale.z);
            sheilding = true;
            canSheild = false;
            sheildGameObject.SetActive(true);
        }

        else if (Input.GetKey("f") && hasSheilds && !canSheild && sheilding && timeToReclick <= 0)
        {
            sheilding = false;
            sheildGameObject.SetActive(false);
        }

        if (sheilding && hasSheilds && !canSheild)
        {
            timeToReclick -= Time.deltaTime;
            sheild        -= shieldConsumption;
            sheildBar.GetComponent <RectTransform>().localScale = new Vector3(sheild / maxSheild,
                                                                              sheildBar.GetComponent <RectTransform>().localScale.y,
                                                                              sheildBar.GetComponent <RectTransform>().localScale.z);
        }


        if (sheild <= 0 && sheilding && hasSheilds)
        {
            sheilding = false;
            sheildGameObject.SetActive(false);
        }


        if (sheilding == false && canSheild == false && hasSheilds)
        {
            if (fasterCooldown)
            {
                sheild += sheildRegenRate * 1.2f;
            }
            else
            {
                sheild += sheildRegenRate;
            }
            if (sheild >= maxSheild)
            {
                sheild    = maxSheild;
                canSheild = true;
            }

            sheildBar.GetComponent <RectTransform>().localScale = new Vector3(sheild / maxSheild,
                                                                              sheildBar.GetComponent <RectTransform>().localScale.y,
                                                                              sheildBar.GetComponent <RectTransform>().localScale.z);
        }

        if (Input.GetKey("m") && MaxItemsManager.mineAmount > 0 && timeBeforeNextMine <= 0)
        {
            GameObject mineObject = Instantiate(mine);
            mineObject.transform.position = transform.Find("MineSpawn").position;

            MaxItemsManager.useMine();
            mineAmountText.GetComponent <Text>().text = "x" + MaxItemsManager.mineAmount;
            timeBeforeNextMine = timeBetweenMines;
        }
        timeBeforeNextMine -= Time.deltaTime;
    }
示例#5
0
    public void Load()
    {
        whichShipColorBase = PlayerPrefs.GetInt("whichShipColorBase");
        whichShipLevel     = PlayerPrefs.GetInt("whichShipLevel");
        isCheaper          = PlayerPrefs.GetInt("isCheeper") == 1;
        amountOfWarps      = PlayerPrefs.GetInt("amountOfWarps");

        //shops
        using (Stream stream = File.Open("savedBuyShopItems.dat", FileMode.Open))
        {
            var bformatter = new BinaryFormatter();
            buyShop.GetComponent <Shop>().items.Clear();
            buyShop.GetComponent <Shop>().shopItems.Clear();
            buyShop.GetComponent <Shop>().itemsHudObjects.Clear();
            foreach (Transform itemToBeDeleted in buyShop.transform)
            {
                Destroy(itemToBeDeleted.gameObject);
            }
            buyShop.GetComponent <Shop>().items = (List <ShopItemInfo>)bformatter.Deserialize(stream);
        }

        buyShop.GetComponent <Shop>().loadUp();

        using (Stream stream = File.Open("savedSellShopItems.dat", FileMode.Open))
        {
            var bformatter = new BinaryFormatter();
            sellShop.GetComponent <Shop>().items.Clear();
            sellShop.GetComponent <Shop>().shopItems.Clear();
            sellShop.GetComponent <Shop>().itemsHudObjects.Clear();
            foreach (Transform itemToBeDeleted in sellShop.transform)
            {
                Destroy(itemToBeDeleted.gameObject);
            }
            sellShop.GetComponent <Shop>().items = (List <ShopItemInfo>)bformatter.Deserialize(stream);
        }

        sellShop.GetComponent <Shop>().loadUp();

        numberOfCommon = PlayerPrefs.GetInt("numberOfCommon");
        for (int i = 0; i < numberOfCommon; i++)
        {
            GameObject crate = Instantiate(commonCrate);
            crate.transform.position = crateSpawnPoint.transform.position + new Vector3(0, -10, 0);
            MaxItemsManager.addLootCrate();
        }

        numberOfRare = PlayerPrefs.GetInt("numberOfRare");
        for (int i = 0; i < numberOfRare; i++)
        {
            GameObject crateRare = Instantiate(rareCrate);
            crateRare.transform.position = crateSpawnPoint.transform.position + new Vector3(0, -10, 0);
            MaxItemsManager.addLootCrate();
        }

        numberOfLegendary = PlayerPrefs.GetInt("numberOfLegendary");
        for (int i = 0; i < numberOfLegendary; i++)
        {
            GameObject crateLegendary = Instantiate(legendaryCrate);
            crateLegendary.transform.position = crateSpawnPoint.transform.position + new Vector3(0, -10, 0);
            MaxItemsManager.addLootCrate();
        }
        amountOfWarps = PlayerPrefs.GetInt("amountOfWarps");
        if (amountOfWarps > 0)
        {
            warpHolder.SetActive(true);
            warpAmount.text = "x" + amountOfWarps.ToString();
        }
    }
示例#6
0
    public void buyShopResultOf(ShopItem shopItem)
    {
        float cheeperMultiplier = 1f;

        if (isCheaper)
        {
            cheeperMultiplier = expCheeperShopMultiplier;
        }
        switch (shopItem.name)
        {
        case "Armor Up":
            player.GetComponent <Player>().maxHealth += 50;
            buyShop.GetComponent <Shop>().changePrice(shopItem.name, (int)(shopItem.cost * upgradeAmount * cheeperMultiplier));
            break;

        //set up lazer gun image
        case "Lazers":
            player.GetComponent <Player>().weapon = lazerGun.gameObject;
            buyShop.GetComponent <Shop>().changePrice(shopItem.name, (int)(shopItem.cost * upgradeAmount * cheeperMultiplier));
            break;

        case "Bigger Tank":
            player.GetComponent <Player>().maxGas += 50;
            buyShop.GetComponent <Shop>().changePrice(shopItem.name, (int)(shopItem.cost * upgradeAmount * cheeperMultiplier));
            break;

        case "Better Thrusters":
            player.GetComponent <PlayerController>().maxSpeed += 3;
            buyShop.GetComponent <Shop>().changePrice(shopItem.name, (int)(shopItem.cost * upgradeAmount * cheeperMultiplier));
            break;

        case "Add Rock Planet":
            home.GetComponent <Home>().addRockPlanet();
            buyShop.GetComponent <Shop>().changePrice(shopItem.name, (int)(shopItem.cost * upgradeAmount * .98f * cheeperMultiplier));

            MaxItemsManager.priceOfPlanet = (int)(shopItem.cost * upgradeAmount * .98f * cheeperMultiplier);
            if (home.GetComponent <Home>().numberOfHomePlanets >= maxHomePlanets)
            {
                buyShop.GetComponent <Shop>().RemoveItem(shopItem.name);
                MaxItemsManager.priceOfPlanet = shopItem.cost;
            }
            break;

        //update to addInventory Slot
        case "More Inventory":
            FindObjectOfType <Inventory>().addInventorySlot();
            buyShop.GetComponent <Shop>().changePrice(shopItem.name, (int)(shopItem.cost * upgradeAmount * cheeperMultiplier));
            if (FindObjectOfType <Inventory>().numberOfInventorySlots == 8)
            {
                buyShop.GetComponent <Shop>().RemoveItem(shopItem.name);
            }
            break;

        case "Switch Color":
            if (whichShipColorBase == playerSprites.Count - 3)
            {
                player.GetComponent <SpriteRenderer>().sprite = playerSprites[whichShipLevel];
                whichShipColorBase = 0;
            }
            else
            {
                player.GetComponent <SpriteRenderer>().sprite = playerSprites[whichShipColorBase + 3 + whichShipLevel];
                whichShipColorBase += 3;
            }
            break;

        case "Drone":
            GameObject droneItem = Instantiate(drone);
            droneItem.transform.position = player.transform.position;
            break;

        case "Turret":
            GameObject turretItem = Instantiate(turret);
            turretItem.transform.position = player.transform.position;
            break;

        case "Decoy":
            GameObject decoyItem = Instantiate(decoy);
            decoyItem.transform.position = player.transform.position;
            break;

        case "Heal":
            GameObject healItem = Instantiate(heal);
            healItem.transform.position = player.transform.position;
            break;

        case "Shield":
            GameObject shieldItem = Instantiate(shield);
            shieldItem.transform.position = player.transform.position;
            break;

        case "Buy Mine":
            MaxItemsManager.addMine();
            mineAmountText.GetComponent <Text>().text = "x" + MaxItemsManager.mineAmount;
            break;

        case "Common Crate":
            GameObject crate = Instantiate(commonCrate);
            crate.transform.position = crateSpawnPoint.transform.position + new Vector3(0, -10, 0);
            BM.Broadcast("Your purchased loot crate has been delivered near spawn!");
            MaxItemsManager.addLootCrate();
            numberOfCommon++;
            break;

        case "Rare Crate":
            GameObject crateRare = Instantiate(rareCrate);
            crateRare.transform.position = crateSpawnPoint.transform.position + new Vector3(0, -10, 0);
            BM.Broadcast("Your purchased loot crate has been delivered near spawn!");
            MaxItemsManager.addLootCrate();
            numberOfRare++;
            break;

        case "Legendary Crate":
            GameObject crateLegendary = Instantiate(legendaryCrate);
            crateLegendary.transform.position = crateSpawnPoint.transform.position + new Vector3(0, -10, 0);
            BM.Broadcast("Your purchased loot crate has been delivered near spawn!");
            MaxItemsManager.addLootCrate();
            numberOfLegendary++;
            break;

        //friendly trader shop
        case "Warp Home Tokens":

            if (amountOfWarps == 0)
            {
                warpHolder.SetActive(true);
                BM.Broadcast("You can press q to be teleported to home");
            }
            amountOfWarps  += 1;
            warpAmount.text = "x" + amountOfWarps.ToString();

            break;

        case "Buy Gas":
            player.GetComponent <Player>().gas += player.GetComponent <Player>().maxGas * .1f;
            if (player.GetComponent <Player>().gas > player.GetComponent <Player>().maxGas)
            {
                player.GetComponent <Player>().gas = player.GetComponent <Player>().maxGas;
            }

            player.GetComponent <Player>().gasBar.transform.localScale = new Vector3(1 * (player.GetComponent <Player>().gas - player.GetComponent <Player>().maxGas * .1f) / (player.GetComponent <Player>().maxGas - player.GetComponent <Player>().maxGas * .1f), player.GetComponent <Player>().gasBar.transform.localScale.y, player.GetComponent <Player>().gasBar.transform.localScale.z);

            if (player.GetComponent <Player>().gas <= player.GetComponent <Player>().maxGas * .1f)
            {
                player.GetComponent <Player>().gasBarEnd.transform.localScale = new Vector3(-1 * (player.GetComponent <Player>().maxGas * .1f - player.GetComponent <Player>().gas) / (player.GetComponent <Player>().maxGas * .1f), player.GetComponent <Player>().gasBarEnd.transform.localScale.y, player.GetComponent <Player>().gasBarEnd.transform.localScale.z);
            }

            break;

        case "Random Recipe":

            List <PlanetCombo> randomList = comboList.planetComboList;

            int         randomIndex = Random.Range(0, randomList.Count - 1);
            PlanetCombo combo       = randomList[randomIndex];
            int         startRandom = randomIndex;

            while (!alminac.AddEntry(combo.planet.gameObject.GetComponent <SpriteRenderer>().sprite, combo.item1.name, combo.item2.name, combo.item3.name) && !(randomIndex == startRandom - 1))
            {
                randomIndex += 1;


                combo = randomList[randomIndex];

                if (randomIndex == randomList.Count - 1)
                {
                    randomIndex = -1;
                }
            }

            if (randomIndex == startRandom - 1)
            {
                FindObjectOfType <canvas>().friendlyBuyShop.RemoveItem("Random Recipe");
                BM.Broadcast("You have bought all of the recipes");
            }

            break;
        }

        //buying resources
        if (listOfResources[0] != null && shopItem.name == listOfResources[0].nameOfResource)
        {
            GameObject resourceSpawn = Instantiate(listOfResources[0].gameObject);
            resourceSpawn.tag = "resource";
            resourceSpawn.transform.position = new Vector2(player.transform.position.x, player.transform.position.y);
            Vector2 velocityDirection = new Vector2(Random.Range(-1f, 1f), Random.Range(-1f, 1f));

            while ((velocityDirection.x < .5f && velocityDirection.x > -.5f) && (velocityDirection.y < .5f && velocityDirection.y > -.5f))
            {
                velocityDirection = new Vector2(Random.Range(-1f, 1f), Random.Range(-1f, 1f));
            }

            resourceSpawn.GetComponent <Rigidbody2D>().velocity        = velocityDirection;
            resourceSpawn.GetComponent <Rigidbody2D>().angularVelocity = 720;
        }
        else if (listOfResources[1] != null && shopItem.name == listOfResources[1].nameOfResource)
        {
            GameObject resourceSpawn = Instantiate(listOfResources[1].gameObject);
            resourceSpawn.tag = "resource";
            resourceSpawn.transform.position = new Vector2(player.transform.position.x, player.transform.position.y);
            Vector2 velocityDirection = new Vector2(Random.Range(-1f, 1f), Random.Range(-1f, 1f));

            while ((velocityDirection.x < .5f && velocityDirection.x > -.5f) && (velocityDirection.y < .5f && velocityDirection.y > -.5f))
            {
                velocityDirection = new Vector2(Random.Range(-1f, 1f), Random.Range(-1f, 1f));
            }

            resourceSpawn.GetComponent <Rigidbody2D>().velocity        = velocityDirection;
            resourceSpawn.GetComponent <Rigidbody2D>().angularVelocity = 720;
        }
        else if (listOfResources[2] != null && shopItem.name == listOfResources[2].nameOfResource)
        {
            GameObject resourceSpawn = Instantiate(listOfResources[2].gameObject);
            resourceSpawn.tag = "resource";
            resourceSpawn.transform.position = new Vector2(player.transform.position.x, player.transform.position.y);
            Vector2 velocityDirection = new Vector2(Random.Range(-1f, 1f), Random.Range(-1f, 1f));

            while ((velocityDirection.x < .5f && velocityDirection.x > -.5f) && (velocityDirection.y < .5f && velocityDirection.y > -.5f))
            {
                velocityDirection = new Vector2(Random.Range(-1f, 1f), Random.Range(-1f, 1f));
            }

            resourceSpawn.GetComponent <Rigidbody2D>().velocity        = velocityDirection;
            resourceSpawn.GetComponent <Rigidbody2D>().angularVelocity = 720;
        }
    }