示例#1
0
 public gameState(vector2 ballPos, vector2 ballVelocity, lastMoveOutcome outcome, vector2 paddlePos)
 {
     this.ballPos      = ballPos;
     this.ballVelocity = ballVelocity;
     this.outcome      = outcome;
     this.paddlePos    = paddlePos;
 }
示例#2
0
        private void drawWalls()
        {
            vector2 topRow = new vector2(0, 0);

            for (int x = 1; x < d.xMax; x++)
            {
                topRow.x = x;

                if (!d.trySetChar(topRow, '='))
                {
                    Log.e("Failed to SetChar");
                }
            }

            vector2 leftRow  = new vector2(0, 0);
            vector2 rightRow = new vector2(d.xMax, 0);

            for (int y = 0; y < d.yMax; y++)
            {
                leftRow.y = y;

                if (!d.trySetChar(leftRow, '|'))
                {
                    Log.e("Failed to SetChar");
                }

                rightRow.y = y;

                if (!d.trySetChar(rightRow, '|'))
                {
                    Log.e("Failed to SetChar");
                }
            }
        }
示例#3
0
        private lastMoveOutcome bounce(vector2 newPos)
        {
            if (newPos.x < 1)
            {
                velocity.x = 1;
                return(lastMoveOutcome.neutral);
            }
            else if (newPos.x > d.xMax - 1)
            {
                velocity.x = -1;
                return(lastMoveOutcome.neutral);
            }

            if (newPos.y < 1)
            {
                velocity.y = 1;
                return(lastMoveOutcome.neutral);
            }
            else if (newPos.y > d.yMax - 1)
            {
                velocity.y = -1;
                return(lastMoveOutcome.good);
            }

            return(lastMoveOutcome.neutral);
        }
示例#4
0
 public paddle(int width, display d, int skipAmount)
 {
     this.d          = d;
     this.width      = width;
     this.skipAmount = skipAmount;
     pos             = d.xMax / 2;
     posCache        = new vector2(pos, d.yMax);
 }
示例#5
0
 public bool trySetChar(vector2 pos, char toSet)
 {
     if (screenBuffer.ContainsKey(pos))
     {
         return(false);
     }
     else
     {
         screenBuffer.Add(pos, toSet);
         return(true);
     }
 }
示例#6
0
        private void setPaddle()
        {
            startPos = pos - width;
            endPos   = pos + width;

            vector2 workingPos = new vector2(startPos, d.yMax);

            for (int i = startPos; i <= endPos; i++)
            {
                workingPos.x = i;
                d.trySetChar(workingPos, '=');
            }
        }
示例#7
0
        private void clearPaddle()
        {
            startPos = pos - width;
            endPos   = pos + width;

            vector2 workingPos = new vector2(startPos, d.yMax);

            for (int i = startPos; i <= endPos; i++)
            {
                workingPos.x = i;
                d.clear(workingPos);
            }
        }
示例#8
0
        public gameState update()
        {
            lastMoveOutcome outcome = lastMoveOutcome.neutral;

            if (counter % skipCounter == 0)
            {
                d.clear(pos);
                vector2 newPos = vector2.add(pos, velocity);

                if (d.screenBuffer.ContainsKey(newPos))
                {
                    outcome = bounce(newPos);
                    if (outcome == lastMoveOutcome.neutral)
                    {
                        Program.bounces++;
                    }
                }
                else
                {
                    if (newPos.y >= d.yMax)
                    {
                        randomizeBall();
                        outcome = lastMoveOutcome.bad;
                    }
                    else
                    {
                        pos = newPos;
                    }
                }

                d.trySetChar(pos, 'o');
            }

            counter++;

            switch (outcome)
            {
            case lastMoveOutcome.good:
                Program.hits++;
                break;

            case lastMoveOutcome.neutral:
                break;

            case lastMoveOutcome.bad:
                Program.misses++;
                break;
            }

            return(new gameState(pos, velocity, outcome, pd.posCache));
        }
示例#9
0
        private void randomizeBall()
        {
            Random r = new Random();

            pos = new vector2(r.Next(1, d.xMax), 1);
            if (r.Next() % 2 == 1)
            {
                velocity.x = 1;
            }
            else
            {
                velocity.x = -1;
            }

            if (r.Next() % 2 == 1)
            {
                velocity.y = 1;
            }
            else
            {
                velocity.y = -1;
            }
        }
示例#10
0
        public void update(vector2 move)
        {
            if (counter % skipAmount == 0)
            {
                if (width > 1)
                {
                    clearPaddle();
                    tryMove(pos + move.x);
                    setPaddle();
                }
                else
                {
                    d.clear(posCache);
                    tryMove(pos + move.x);
                    d.trySetChar(posCache, '=');
                }
            }
            else
            {
            }

            counter++;
        }
示例#11
0
 public bool clear(vector2 pos)
 {
     return(screenBuffer.Remove(pos));
 }
示例#12
0
 public bool Equals(vector2 Y)
 {
     return(x == Y.x && y == Y.y);
 }
示例#13
0
 public static bool Equals(vector2 X, vector2 Y)
 {
     return(X.x == Y.x && X.y == Y.y);
 }
示例#14
0
 public float dist(vector2 other)
 {
     return((float)Math.Sqrt(Math.Pow(x - other.x, 2) + Math.Pow(y - other.y, 2)));
 }
示例#15
0
 public static vector2 add(vector2 v1, vector2 v2)
 {
     return(new vector2(v1.x + v2.x, v1.y + v2.y));
 }