コード例 #1
0
ファイル: GameCore.cs プロジェクト: LoamNet/Bubbles
    // Handles updating positions for the player line, along with line starting and finishing events.
    private void UpdatePlayerLine(bool recordScore)
    {
        if (isPaused)
        {
            return;
        }

        if (inputManager.PrimaryInputDown())
        {
            if (wasDownPreviously)
            {
                lastLineEnd = inputManager.PrimaryInputPosWorld();
                events.OnLineUpdated?.Invoke(lastLineStart, lastLineEnd);
            }
            else
            {
                lastLineStart = inputManager.PrimaryInputPosWorld();
                lastLineEnd   = inputManager.PrimaryInputPosWorld();
                events.OnLineCreated?.Invoke(lastLineStart, lastLineEnd);
            }

            wasDownPreviously = true;
        }
        else
        {
            if (wasDownPreviously)
            {
                DataEarnedScore points = CollectBubblesAsNecessary(recordScore);
                events.OnBubblesChange?.Invoke(bubbles);
                events.OnLineDestroyed?.Invoke(lastLineStart, lastLineEnd, points);
                wasDownPreviously = false;
            }
        }
    }
コード例 #2
0
    private void OnLineDestroyed(DataPoint start, DataPoint end, DataEarnedScore points)
    {
        line?.Destroy();

        if (points.total > 0)
        {
            DataPoint s        = inputManager.ConvertToScreenPoint(start);
            DataPoint e        = inputManager.ConvertToScreenPoint(end);
            DataPoint worldPos = new DataPoint((s.X + e.X) / 2, (s.Y + e.Y) / 2);

            foreach (DataPoint point in points.locations)
            {
                DataPoint loc = inputManager.ConvertToScreenPoint(point);
                visualTextFeedback.CreateText(loc, "+" + GameCore.pointsPerBubble, TextType.ScoreAddition);
            }

            if (points.bonus != 0)
            {
                visualTextFeedback.CreateText(worldPos, "Bonus! +" + points.bonus, TextType.ScoreAdditionBonus);
            }
        }

        line = null;
    }
コード例 #3
0
ファイル: GameCore.cs プロジェクト: LoamNet/Bubbles
    // Returns how much the score changed by
    private DataEarnedScore CollectBubblesAsNecessary(bool impactsScore = true)
    {
        List <DataPoint> locs             = new List <DataPoint>();
        List <int>       collectedIndexes = new List <int>();

        // Collect collisions
        for (int i = bubbles.Count - 1; i >= 0; --i)
        {
            DataBubble bubble = bubbles[i];

            // Determine if we're hitting
            float triggerRadius = bubble.AdjustedRadius();
            bool  isHit         = Utils.IsLineTouchingCircle(lastLineStart, lastLineEnd, bubble.GetPosition(), triggerRadius, bubbleRadiusStandard);

            if (isHit)
            {
                collectedIndexes.Add(i);
                locs.Add(bubble.GetPosition());
            }
        }

        // Score updating
        int hit        = collectedIndexes.Count;
        int scoreBase  = GameCore.pointsPerBubble * hit;
        int scoreBonus = 0;

        if (hit > 0)
        {
            ++linesDrawn;
        }

        if (hit > bonusThreshold)
        {
            int bonusHits = hit - bonusThreshold;
            scoreBonus = bonusHits * bonusHits * pointsPerBonusBubble;
        }

        DataEarnedScore dataEarnedScore = new DataEarnedScore(scoreBase, scoreBonus, locs);

        if (pointsPerBubble != 0)
        {
            DataGeneral gen = data.GetDataGeneral();
            gen.score = gen.score + dataEarnedScore.total;

            if (impactsScore)
            {
                data.SetDataGeneral(gen);
            }
        }

        // Clear colleted bubbles. The indexes are from back to front, so the removal is safe.
        foreach (int index in collectedIndexes)
        {
            DataBubble bubble = bubbles[index];
            events.OnBubbleDestroyed?.Invoke(bubble.GetPosition());
            bubbles.RemoveAt(index);

            DataPoint[] newBubbles = DetermineSplits(bubble, lastLineStart, lastLineEnd);
            if (newBubbles != null)
            {
                foreach (DataPoint point in newBubbles)
                {
                    DataBubble newBubble = new DataBubble(point, new DataPoint(0, 0), speed: 0, BubbleType.Standard);
                    bubbles.Add(newBubble);
                }
            }
        }

        return(dataEarnedScore);
    }