コード例 #1
0
 private void OnTriggerExit2D(Collider2D collision)
 {
     if (collision.CompareTag("CrewCard"))
     {
         CrewCard cc = collision.GetComponent <CrewCard>();
         SetOccupied(false);
         cc.LeaveDropSpot(rect.position);
     }
 }
コード例 #2
0
 private void OnTriggerExit2D(Collider2D collision)
 {
     if (collision.CompareTag("CrewCard"))
     {
         CrewCard cc = collision.GetComponent <CrewCard>();
         SetOccupied(false);
         cc.LeaveDropSpot(rect.position);
         //dropIndex++; //<-- changes the dropIndex value one time ONLY
     }
     //dropIndex++;
 }
コード例 #3
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.CompareTag("CrewCard") && !occupied && allowDropping)
     {
         CrewCard cc = collision.GetComponent <CrewCard>();
         SetOccupied(true);
         cc.CardIndex = dropIndex;
         cc.OverDropSpot(rect.position, startingPoint);
         //Debug.Log($"Card is over a spot {rect.position.x} {rect.position.y}");
     }
 }
コード例 #4
0
    public void PopulateScreen()
    {
        /*---------------------------------------------------------------------
        *  PIRATE SPAWNING
        *  ---------------------------------------------------------------------*/

        //random number of enemy priates created (1-12)
        //different ranging numbers of pirates will be added later
        pirateRange.y = Mathf.Min(pirateRange.y, crewNum);
        int count = Random.Range(pirateRange.x, pirateRange.y + 1);
        List <CrewMember> possiblePirates = Globals.GameVars.Pirates.Where(x => x.pirateType.Equals(typeToSpawn)).ToList();

        List <CardDropZone> crewSlots = new List <CardDropZone>();

        for (int i = 0; i < count; i++)
        {
            CardDropZone newEnemySlot = Instantiate(enemySlot);
            CardDropZone newCrewSlot  = Instantiate(crewSlot);

            newEnemySlot.transform.SetParent(enemyZones[i < slotsPerRow ? 0 : 1]);
            newCrewSlot.transform.SetParent(crewZones[i < slotsPerRow ? 0 : 1]);

            newEnemySlot.transform.localScale = Vector3.one;
            newCrewSlot.transform.localScale  = Vector3.one;

            newEnemySlot.dropIndex = i;
            newCrewSlot.dropIndex  = i;

            crewSlots.Add(newCrewSlot);
        }

        GetComponent <MiniGameManager>().InitilizePirates(crewSlots);

        for (int i = 0; i < count; i++)
        {
            Pirate   p     = Instantiate(pirate);
            CrewCard pCard = p.GetComponent <CrewCard>();
            switch (typeToSpawn.difficulty)
            {
            case (1):
                pCard.power /= 5;
                break;

            case (2):
                pCard.power /= 3;
                break;

            case (4):
                pCard.power = (int)(pCard.power * 1.5f);
                break;
            }

            CrewMember randomPirate = possiblePirates.RandomElement();
            pCard.SetCrew(randomPirate);
            p.Bind();
            possiblePirates.Remove(randomPirate);
            Transform row = i < slotsPerRow ? enemyZones[0] : enemyZones[1];

            p.transform.SetParent(row.transform.GetChild(i % slotsPerRow));
            p.transform.localScale = Vector3.one;

            StartCoroutine(WaitAndChangeParent(p.transform, pirateParent));

            pCard.cardIndex = i;
        }


        //for (int x = 0; x < count; x++)
        //{
        //	pirateSlots[x].SetActive(true);
        //	//pirateSlots[x].GetComponent<RectTransform>().localScale = canvas.transform.localScale;
        //	Pirate g = Instantiate(pirate);
        //	CrewCard gCard = g.GetComponent<CrewCard>();
        //	//Debug.Log("pirate local scale = " + pirate.transform.localScale);
        //	//Debug.Log("pirate lossy scale = " + pirate.transform.lossyScale);
        //	if (typeToSpawn.difficulty == 1) {
        //		gCard.power = (gCard.power / 5);
        //		gCard.powerText.text = gCard.power.ToString();
        //	}
        //	else if (typeToSpawn.difficulty == 2) {
        //		gCard.power = (gCard.power / 3);
        //		gCard.powerText.text = gCard.power.ToString();
        //	}
        //	else if (typeToSpawn.difficulty == 4) {
        //		gCard.power = (int)(gCard.power * 1.5f);
        //		gCard.powerText.text = gCard.power.ToString();

        //	}

        //	//CrewMember randomPirate = Globals.GameVars.Pirates.RandomElement();
        //	CrewMember randomPirate = possiblePirates.RandomElement();
        //	g.SetCrew(randomPirate);
        //	g.Bind();
        //	possiblePirates.Remove(randomPirate);
        //	g.GetComponent<RectTransform>().position = pirateSlots[x].GetComponent<RectTransform>().position;
        //	g.transform.SetParent(pirateParent);
        //	//no idea why this is necessary, but all cards need to be scaled to the local scale of the canvas of the minigame
        //	//same thing below is done for the crew cards
        //	g.transform.localScale = Vector3.one;
        //	playerSlots[x].SetActive(true);
        //	//playerSlots[x].GetComponent<RectTransform>().localScale = canvas.transform.localScale;

        //	g.GetComponent<CrewCard>().cardIndex = pirateSlots[x].GetComponent<CardDropZone>().dropIndex;
        //}


        /*----------------------------------------------------------------------
        *  SCALING
        *  ----------------------------------------------------------------------*/
        float width = crew.GetComponent <RectTransform>().rect.width;
        //crewSlotParent.GetComponent<RectTransform>().localScale = canvas.transform.localScale;
        //crewParentInOrigin.GetComponent<RectTransform>().localScale = canvas.transform.localScale;


        /*----------------------------------------------------------------------
        *  ORIGIN SLOT SPAWNING
        *  ----------------------------------------------------------------------*/

        int totalCrewRows = Mathf.CeilToInt((crewNum * 1.0f) / crewPerRow);
        int spawnedSlots  = 0;

        spawnedCrewSlots = new CardDropZone[totalCrewRows, crewPerRow];

        for (int r = 0; r < totalCrewRows; r++)
        {
            for (int c = 0; c < crewPerRow; c++)
            {
                //Spawns a new crew slot
                GameObject slot = Instantiate(crewMemberSlot);
                //scaling crew card slots
                slot.transform.SetParent(crewSlotParent);
                slot.transform.localScale = Vector3.one;

                RectTransform slotRect = slot.GetComponent <RectTransform>();
                CardDropZone  cdz      = slot.GetComponent <CardDropZone>();
                spawnedCrewSlots[r, c] = cdz;
            }
        }

        RectTransform crewParentRect = crewSlotParent.GetComponent <RectTransform>();

        crewParentRect.anchoredPosition = new Vector2(crewParentRect.anchoredPosition.x, CenterGrid(totalCrewRows, padding, width));

        /*----------------------------------------------------------------------
        *  CREW SPAWNING
        *  ----------------------------------------------------------------------*/

        float startX = width / 2;
        float startY = crewSlotParent.GetComponent <RectTransform>().rect.height / 2;

        Debug.Log("Height: " + startY);

        float xPos = startX;
        float yPos = startY;

        for (int r = 0; r < totalCrewRows; r++)
        {
            for (int c = 0; c < crewPerRow; c++)
            {
                //Spawns a new crew member
                if (spawnedSlots < crewNum)
                {
                    CrewCard newCrew = Instantiate(crew);
                    newCrew.SetRSP(this);
                    newCrew.Bind();
                    newCrew.transform.SetParent(crewParentInOrigin);
                    newCrew.name = "Card " + r + ", " + c;
                    CardDropZone cdz = spawnedCrewSlots[r, c];
                    //scaling crew cards
                    newCrew.transform.localScale = Vector3.one;
                    newCrew.GetComponent <RectTransform>().anchoredPosition = new Vector2(xPos, yPos);
                    newCrew.SetCrew(Globals.GameVars.playerShipVariables.ship.crewRoster[spawnedSlots]);
                    cdz.SetOccupied(true);
                    //Debug.Log("crewmember scale = " + crew.transform.localScale);
                    //Debug.Log("crewmember lossy scale = " + crew.transform.lossyScale);
                    spawnedSlots++;
                    xPos += width;
                }
            }

            xPos  = startX;
            yPos -= padding + width;
        }
    }
コード例 #5
0
    /// <summary>
    /// Generates the pirates and the pirate slots behind them, and the crew slots and scrolling crew list
    /// </summary>
    public void PopulateScreen()
    {
        /*---------------------------------------------------------------------
        *  PIRATE SPAWNING
        *  ---------------------------------------------------------------------*/

        //random number of enemy priates within range
        //the number spawned will never exceed the number of crew you have
        int count = Random.Range(pirateRange.x, Mathf.Min(pirateRange.y, crewNum) + 1);
        List <CrewMember> possiblePirates = Globals.GameVars.Pirates.Where(x => x.pirateType.Equals(typeToSpawn)).ToList();

        List <CardDropZone> crewSlots = new List <CardDropZone>();

        //spawns pirate and crew drop zones at the same time, since there will always be the same number
        for (int i = 0; i < count; i++)
        {
            CardDropZone newEnemySlot = Instantiate(enemySlot);
            CardDropZone newCrewSlot  = Instantiate(crewSlot);

            newEnemySlot.transform.SetParent(enemyZones[i < slotsPerRow ? 0 : 1]);
            newCrewSlot.transform.SetParent(crewZones[i < slotsPerRow ? 0 : 1]);

            newEnemySlot.transform.localScale = Vector3.one;
            newCrewSlot.transform.localScale  = Vector3.one;

            newEnemySlot.dropIndex = i;
            newCrewSlot.dropIndex  = i;

            crewSlots.Add(newCrewSlot);
        }

        GetComponent <MiniGameManager>().InitializeCrewSlots(crewSlots);

        //once the slots are in place, they won't be moving, so you can add the pirates
        //you can't add the pirates at the same time because the slots are in a horizontal layout group, so they'll be moving as new slots are added
        //it looks like you can just child the pirates to the slots and just leave it, but because of how the fighting works they have to be children of the pirate parent
        //if you don't change the parent, you'll automatically win every fight, which is obviously wrong
        //so we set the parent to the pirate slots now that they're in place, then switch parent so we get the right coordinates without having to do math
        for (int i = 0; i < count; i++)
        {
            Pirate   p     = Instantiate(pirateCard);
            CrewCard pCard = p.GetComponent <CrewCard>();
            switch (typeToSpawn.difficulty)
            {
            case (1):
                pCard.Power /= 5;
                break;

            case (2):
                pCard.Power /= 3;
                break;

            case (4):
                pCard.Power = (int)(pCard.Power * 1.5f);
                break;
            }

            CrewMember randomPirate = possiblePirates.RandomElement();
            pCard.SetCrew(randomPirate);
            p.Bind();
            //after you've used a pirate, remove it from the list of possibilities to avoid duplicates
            possiblePirates.Remove(randomPirate);
            Transform row = i < slotsPerRow ? enemyZones[0] : enemyZones[1];

            p.transform.SetParent(row.transform.GetChild(i % slotsPerRow));
            p.transform.localScale = Vector3.one;

            StartCoroutine(WaitAndChangeParent(p.transform, pirateParent));

            pCard.CardIndex = i;
        }

        #region Old Spawning Method
        //for (int x = 0; x < count; x++)
        //{
        //	pirateSlots[x].SetActive(true);
        //	//pirateSlots[x].GetComponent<RectTransform>().localScale = canvas.transform.localScale;
        //	Pirate g = Instantiate(pirate);
        //	CrewCard gCard = g.GetComponent<CrewCard>();
        //	//Debug.Log("pirate local scale = " + pirate.transform.localScale);
        //	//Debug.Log("pirate lossy scale = " + pirate.transform.lossyScale);
        //	if (typeToSpawn.difficulty == 1) {
        //		gCard.power = (gCard.power / 5);
        //		gCard.powerText.text = gCard.power.ToString();
        //	}
        //	else if (typeToSpawn.difficulty == 2) {
        //		gCard.power = (gCard.power / 3);
        //		gCard.powerText.text = gCard.power.ToString();
        //	}
        //	else if (typeToSpawn.difficulty == 4) {
        //		gCard.power = (int)(gCard.power * 1.5f);
        //		gCard.powerText.text = gCard.power.ToString();

        //	}

        //	//CrewMember randomPirate = Globals.GameVars.Pirates.RandomElement();
        //	CrewMember randomPirate = possiblePirates.RandomElement();
        //	g.SetCrew(randomPirate);
        //	g.Bind();
        //	possiblePirates.Remove(randomPirate);
        //	g.GetComponent<RectTransform>().position = pirateSlots[x].GetComponent<RectTransform>().position;
        //	g.transform.SetParent(pirateParent);
        //	//no idea why this is necessary, but all cards need to be scaled to the local scale of the canvas of the minigame
        //	//same thing below is done for the crew cards
        //	g.transform.localScale = Vector3.one;
        //	playerSlots[x].SetActive(true);
        //	//playerSlots[x].GetComponent<RectTransform>().localScale = canvas.transform.localScale;

        //	g.GetComponent<CrewCard>().cardIndex = pirateSlots[x].GetComponent<CardDropZone>().dropIndex;
        //}
        #endregion

        /*----------------------------------------------------------------------
        *  SCALING
        *  ----------------------------------------------------------------------*/

        //Everything that's instantiated will need to have its scale set
        //When you change an object's parent, its *actual* size doesn't change, but its *relative* size changes
        //The canvas scales with the screen resolution, so let's pretend it gets scaled to .75
        //When you instantiate a new crew card, it has no parent and its scale is just 1
        //But when you set its parent to something that's been scaled with the canvas to .75, the crew card doesn't change size on the screen
        //Instead, it changes scale to 1.25, which we don't want - we *want* it to get smaller so it fits the screen
        //The solution is that once you've changed the parent, you need to tell it to set its scale back down to 1
        //This line here doesn't actually have to do with any of that - this section had more in it but I figured out it wasn't necessary
        //So instead, I repurposed it into an explanation!
        float width = crewCard.GetComponent <RectTransform>().rect.width;


        /*----------------------------------------------------------------------
        *  ORIGIN SLOT SPAWNING
        *  ----------------------------------------------------------------------*/

        //We need an int here, but we want the *right* int, so we do float division and then cast it up
        //The reason we use ceil and not just round is that we only want full rows. If there's 5 crew per row and you have 3 crew, we want you to still show all 5 slots for aesthetic reasons
        int totalCrewRows = Mathf.CeilToInt((crewNum * 1.0f) / crewPerRow);
        int spawnedSlots  = 0;
        spawnedCrewSlots = new CardDropZone[totalCrewRows, crewPerRow];

        for (int r = 0; r < totalCrewRows; r++)
        {
            for (int c = 0; c < crewPerRow; c++)
            {
                //Spawns a new crew slot
                GameObject slot = Instantiate(crewOriginSlot);
                //scaling crew card slots
                slot.transform.SetParent(crewOriginParent);
                slot.transform.localScale = Vector3.one;

                CardDropZone cdz = slot.GetComponent <CardDropZone>();
                spawnedCrewSlots[r, c] = cdz;
            }
        }

        RectTransform crewParentRect = crewOriginParent.GetComponent <RectTransform>();
        //We're using a grid layout group, which means we might have expanded vertically, so we need to set the grid so the top row is properly centered
        crewParentRect.anchoredPosition = new Vector2(crewParentRect.anchoredPosition.x, CenterGrid(totalCrewRows, padding, width));

        /*----------------------------------------------------------------------
        *  CREW SPAWNING
        *  ----------------------------------------------------------------------*/

        //Figure out where the center of the first crew card is
        //You'd think you can just get the position of the first crew origin slot, but for some reason that doesn't quite work
        float startX = width / 2;
        float startY = crewOriginParent.GetComponent <RectTransform>().rect.height / 2;

        float xPos = startX;
        float yPos = startY;

        for (int r = 0; r < totalCrewRows; r++)
        {
            for (int c = 0; c < crewPerRow; c++)
            {
                //Spawns a new crew member if there's another one to spawn
                //We need to check this because if you don't have an even number of crew members compared to slots per row, there'll be empty slots
                if (spawnedSlots < crewNum)
                {
                    CrewCard newCrew = Instantiate(crewCard);
                    newCrew.SetRSP(this);
                    newCrew.Bind();
                    newCrew.transform.SetParent(crewParentInOrigin);
                    newCrew.name = "Card " + r + ", " + c;
                    CardDropZone cdz = spawnedCrewSlots[r, c];
                    //scaling crew cards
                    newCrew.transform.localScale = Vector3.one;
                    newCrew.GetComponent <RectTransform>().anchoredPosition = new Vector2(xPos, yPos);
                    newCrew.SetCrew(Globals.GameVars.playerShipVariables.ship.crewRoster[spawnedSlots]);
                    cdz.SetOccupied(true);
                    spawnedSlots++;
                    xPos += width;
                }
            }

            xPos  = startX;
            yPos -= padding + width;
        }
    }