public gameState(vector2 ballPos, vector2 ballVelocity, lastMoveOutcome outcome, vector2 paddlePos) { this.ballPos = ballPos; this.ballVelocity = ballVelocity; this.outcome = outcome; this.paddlePos = paddlePos; }
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"); } } }
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); }
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); }
public bool trySetChar(vector2 pos, char toSet) { if (screenBuffer.ContainsKey(pos)) { return(false); } else { screenBuffer.Add(pos, toSet); return(true); } }
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, '='); } }
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); } }
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)); }
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; } }
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++; }
public bool clear(vector2 pos) { return(screenBuffer.Remove(pos)); }
public bool Equals(vector2 Y) { return(x == Y.x && y == Y.y); }
public static bool Equals(vector2 X, vector2 Y) { return(X.x == Y.x && X.y == Y.y); }
public float dist(vector2 other) { return((float)Math.Sqrt(Math.Pow(x - other.x, 2) + Math.Pow(y - other.y, 2))); }
public static vector2 add(vector2 v1, vector2 v2) { return(new vector2(v1.x + v2.x, v1.y + v2.y)); }