Advertisement
1vannn

Ball Circle Game [Updated 10/21/14]

Oct 16th, 2014
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.09 KB | None | 0 0
  1. /*
  2. == Changelog ==
  3. (10/27/14 4:02PM)
  4. - Fixed health bug regarding going into the negitive numbers..
  5.  
  6. (10/27/14 11:09AM)
  7. - Fixed the crashing bug [Involved the health balls, which are a part of the script that hasn't been finished yet]...
  8. - Updated the move speed, may be a little bit more realistic, I want to make it really smooth eventually..
  9. - Added a brief instruction to the title.
  10. */
  11. PFont Font1;
  12. color b1, b2, c1, c2;
  13. float moveSpeed = 15;
  14. int nextBall = 3;
  15. int lives = 5;
  16. float ballSize;
  17. int score = 0;
  18. int difficulty;
  19. int[] selected = {1,0,0};
  20. float[] yPos = { -50, -50, -50 };
  21. float p_ballNumber;
  22. float ballNumber;
  23. boolean DebugMode = false;
  24. boolean started = true;
  25. boolean ballMoving = false;
  26. public boolean sketchFullScreen() {
  27.         return true;
  28. }
  29. void setup() {
  30.         Font1 = createFont("Arial Black", 32);
  31.         size(displayWidth,displayHeight);
  32.         frameRate(60);
  33.         smooth();
  34.         noCursor();
  35. }
  36. void draw() {
  37.         if (DebugMode == true) {
  38.                 debug();
  39.         }
  40.         if (started) {
  41.                 c1 = color(8, 110, 121);
  42.                 c2 = color(7,179 , 198);
  43.                 if (displayHeight >= 1024) {
  44.                         ballSize = 10;
  45.                 } else {
  46.                         ballSize = 20;
  47.                 }
  48.                 started = false;
  49.         }
  50.         if (lives != 5) {
  51.                 checkLives();
  52.                 drawPlayground();
  53.                 moveBalls();
  54.                 drawBalls();
  55.         } else {
  56.                 background(0);
  57.                 fill(255,255,255,128);
  58.                 stroke(0);
  59.                 strokeWeight(2);
  60.                 rectMode(CORNER);
  61.                 rect(0,height*.20,width,height*.60);
  62.                 textSize(32);
  63.                 fill(0);
  64.                 textAlign(CENTER);
  65.                 text("Ivan's Game | Press Space to continue",width/2,height/2);
  66.                 text("Press the A, S, and D buttons depending on what lane the ball is coming down.",width/2,height/1.8);
  67.                 textSize(16);
  68.                 text("Yes, this is a temporary menu.",width/2,height/1.2);
  69.  
  70.         }                                      
  71. }
  72. void checkLives() {
  73.         if (lives <= 0) {
  74.                 System.out.println("Dead");
  75.                 resetBall(3);
  76.                 lives = 4;
  77.                 moveSpeed = 15;
  78.                 score = 0;
  79.         }
  80. }
  81. void keyPressed() {
  82.         if (key == ' ') {
  83.                 if (lives == 4) {
  84.                         lives = 3;
  85.                 } if (lives == 5) {
  86.                         lives = 3;
  87.                 }
  88.         }
  89.         if (key == 'p') {
  90.                 DebugMode = true;
  91.         }
  92.         if (key == '1' && DebugMode == true) {
  93.                 nextBall = 0;
  94.         }
  95.         if (key == '2' && DebugMode == true) {
  96.                 nextBall = 1;
  97.         }
  98.         if (key == '3' && DebugMode == true) {
  99.                 nextBall = 2;
  100.         }
  101.         if (key == 'w' || key == 'W') {
  102.                 if (selected[0] == 1) {
  103.                         selected[0] = 0;
  104.                         selected[1] = 0;
  105.                         selected[2] = 1; // Just in case.
  106.                 } else if (selected[1] == 1) {
  107.                         selected[0] = 1;
  108.                         selected[1] = 0;
  109.                         selected[2] = 0;
  110.                 } else if (selected[2] == 1) {
  111.                         selected[0] = 0;
  112.                         selected[1] = 1;
  113.                         selected[2] = 0;
  114.                 }
  115.         }
  116.         if (key == 'a' || key == 'A') {
  117.                 if (yPos[0] != -50 && yPos[0]+ballSize/2 < height*0.60 && yPos[0]-ballSize/2 > height*0.40) {
  118.                         score++;
  119.                         resetBall(0);
  120.                         updateSpeed();
  121.                 } else {
  122.                         lives = lives - 1;
  123.                 }
  124.         }
  125.         if (key == 's' || key == 'S') {
  126.                 if (yPos[1] != -50 && yPos[1]+ballSize/2 < height*0.60 && yPos[1]-ballSize/2 > height*0.40) {
  127.                         score++;
  128.                         resetBall(1);
  129.                         updateSpeed();
  130.                 } else if (lives == 5 && difficulty == 0) {
  131.                         if (selected[0] == 1) {
  132.                                 selected[0] = 0;
  133.                                 selected[1] = 1;
  134.                                 selected[2] = 0; // Just in case.
  135.                         } else if (selected[1] == 1) {
  136.                                 selected[0] = 0;
  137.                                 selected[1] = 0;
  138.                                 selected[2] = 1;
  139.                         } else if (selected[2] == 1) {
  140.                                 selected[0] = 1;
  141.                                 selected[1] = 0;
  142.                                 selected[2] = 0;
  143.                         }
  144.                 } else {
  145.                         lives = lives - 1;
  146.                 }
  147.         }
  148.         if (key == 'd' || key == 'D') {
  149.                 if (yPos[2] != -50 && yPos[2]+ballSize/2 < height*0.60 && yPos[2]-ballSize/2 > height*0.40) {
  150.                         score++;
  151.                         resetBall(2);
  152.                         updateSpeed();
  153.                 } else {
  154.                         lives = lives - 1;
  155.                 }
  156.         }
  157. }
  158. void debug() {
  159.         System.out.println(lives);
  160.         //System.out.println(moveSpeed);
  161.         //System.out.println(ballMoving);
  162.         //System.out.println(displayHeight);
  163.         //System.out.println(yPos[0] + " | " + yPos[1] + " | " + yPos[2]);
  164. }
  165. void moveBalls() {
  166.         if (!ballMoving) {
  167.                 if (lives != 4) {
  168.                         if (nextBall == 3) {
  169.                                 p_ballNumber = ballNumber; // Ensures that we don't have repeats.
  170.                                 ballNumber = int(random(0,3));
  171.                                 if (p_ballNumber == ballNumber) {
  172.                                         if (p_ballNumber == 0) {
  173.                                                 ballNumber = int(random(1,3));
  174.                                         } else if ( p_ballNumber == 1) {
  175.                                                 ballNumber = int(random(1,3));
  176.                                                 if (ballNumber == 1) {
  177.                                                         ballNumber = 0;
  178.                                                 }
  179.                                         } else if ( p_ballNumber == 2) {
  180.                                                 ballNumber = int(random(0,2));
  181.                                         }
  182.                                 }
  183.                         } else {
  184.                                 ballNumber = nextBall;
  185.                                 nextBall = 3;
  186.                         }
  187.                         ballMoving = true;
  188.                 }
  189.         } else {
  190.                 if (ballNumber == 0) {
  191.                         if (yPos[0] <= displayHeight) {
  192.                                 yPos[0] = yPos[0] + moveSpeed;
  193.                         } else {
  194.                                 ballMoving = false;
  195.                                 resetBall(0);
  196.                                 lives = lives - 1;
  197.                         }
  198.                 }
  199.                 if (ballNumber == 1) {
  200.                         if (yPos[1] <= displayHeight) {
  201.                                 yPos[1] = yPos[1] + moveSpeed;
  202.                         } else {
  203.                                 ballMoving = false;
  204.                                 resetBall(1);
  205.                                 lives = lives - 1;
  206.                         }
  207.                 }
  208.                 if (ballNumber == 2) {
  209.                         if (yPos[2] <= displayHeight) {
  210.                                 yPos[2] = yPos[2] + moveSpeed;
  211.                         } else {
  212.                                 ballMoving = false;
  213.                                 resetBall(2);
  214.                                 lives = lives - 1;
  215.                         }
  216.                 }
  217.         }
  218. }
  219. void drawBalls() {
  220.         fill(255);
  221.         strokeWeight(1);
  222.         stroke(255,255,255);
  223.         ellipse(width*.30,yPos[0],ballSize,ballSize);
  224.         ellipse(width*.50,yPos[1],ballSize,ballSize);
  225.         ellipse(width*.60,yPos[2],ballSize,ballSize);
  226. }
  227. void drawPlayground() {
  228.         background(0);
  229.         fill(255);
  230.         strokeWeight(3);
  231.         stroke(255,255,255);
  232.         if (lives != 4) {
  233.                 textAlign(CENTER);
  234.                 textSize(32);
  235.                 text("| " + lives + " |",width/2,height*0.15);
  236.                 text("| " + score + " |", width/2,height*0.25);
  237.                 line(0,height*.40,width,height*.40);
  238.                 line(0,height*.60,width,height*.60);
  239.         } else {
  240.                 textAlign(CENTER);
  241.                 textSize(32);
  242.                 text("| " + score + " |", width/2,height*0.25);
  243.                 text("You've died. Press the spacebar to start again.",width/2,height/2);
  244.         }
  245. }
  246. void updateSpeed() {
  247.         moveSpeed = moveSpeed + .40;
  248. }
  249. void resetBall(int ballResetNumber) {
  250.         if (ballResetNumber == 0) {
  251.                 yPos[0] = -50;
  252.                 ballMoving = false;
  253.         }
  254.         if (ballResetNumber == 1) {
  255.                 yPos[1] = -50;
  256.                 ballMoving = false;
  257.         }
  258.         if (ballResetNumber == 2) {
  259.                 yPos[2] = -50;
  260.                 ballMoving = false;
  261.         }
  262.         if (ballResetNumber == 3) {
  263.                 yPos[0] = -50;
  264.                 yPos[1] = -50;
  265.                 yPos[2] = -50;
  266.                 ballMoving = false;
  267.         }
  268. }
  269. /*
  270. void drawHealthBalls() {
  271.         if (lives != 5) {
  272.                 if (lives <= 3 && lives >= 1) { // So I can add on more lives once I add a configuration file..
  273.                         if (lives == 3) {
  274.                                 fill(255,0,0);
  275.                                 ellipse(healthX[0],healthY[0]);
  276.                                 // to be completed..
  277.                                 fill(fillColor);
  278.                         }
  279.                 }
  280.         }
  281. }
  282. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement