Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- == Changelog ==
- (10/27/14 4:02PM)
- - Fixed health bug regarding going into the negitive numbers..
- (10/27/14 11:09AM)
- - Fixed the crashing bug [Involved the health balls, which are a part of the script that hasn't been finished yet]...
- - Updated the move speed, may be a little bit more realistic, I want to make it really smooth eventually..
- - Added a brief instruction to the title.
- */
- PFont Font1;
- color b1, b2, c1, c2;
- float moveSpeed = 15;
- int nextBall = 3;
- int lives = 5;
- float ballSize;
- int score = 0;
- int difficulty;
- int[] selected = {1,0,0};
- float[] yPos = { -50, -50, -50 };
- float p_ballNumber;
- float ballNumber;
- boolean DebugMode = false;
- boolean started = true;
- boolean ballMoving = false;
- public boolean sketchFullScreen() {
- return true;
- }
- void setup() {
- Font1 = createFont("Arial Black", 32);
- size(displayWidth,displayHeight);
- frameRate(60);
- smooth();
- noCursor();
- }
- void draw() {
- if (DebugMode == true) {
- debug();
- }
- if (started) {
- c1 = color(8, 110, 121);
- c2 = color(7,179 , 198);
- if (displayHeight >= 1024) {
- ballSize = 10;
- } else {
- ballSize = 20;
- }
- started = false;
- }
- if (lives != 5) {
- checkLives();
- drawPlayground();
- moveBalls();
- drawBalls();
- } else {
- background(0);
- fill(255,255,255,128);
- stroke(0);
- strokeWeight(2);
- rectMode(CORNER);
- rect(0,height*.20,width,height*.60);
- textSize(32);
- fill(0);
- textAlign(CENTER);
- text("Ivan's Game | Press Space to continue",width/2,height/2);
- text("Press the A, S, and D buttons depending on what lane the ball is coming down.",width/2,height/1.8);
- textSize(16);
- text("Yes, this is a temporary menu.",width/2,height/1.2);
- }
- }
- void checkLives() {
- if (lives <= 0) {
- System.out.println("Dead");
- resetBall(3);
- lives = 4;
- moveSpeed = 15;
- score = 0;
- }
- }
- void keyPressed() {
- if (key == ' ') {
- if (lives == 4) {
- lives = 3;
- } if (lives == 5) {
- lives = 3;
- }
- }
- if (key == 'p') {
- DebugMode = true;
- }
- if (key == '1' && DebugMode == true) {
- nextBall = 0;
- }
- if (key == '2' && DebugMode == true) {
- nextBall = 1;
- }
- if (key == '3' && DebugMode == true) {
- nextBall = 2;
- }
- if (key == 'w' || key == 'W') {
- if (selected[0] == 1) {
- selected[0] = 0;
- selected[1] = 0;
- selected[2] = 1; // Just in case.
- } else if (selected[1] == 1) {
- selected[0] = 1;
- selected[1] = 0;
- selected[2] = 0;
- } else if (selected[2] == 1) {
- selected[0] = 0;
- selected[1] = 1;
- selected[2] = 0;
- }
- }
- if (key == 'a' || key == 'A') {
- if (yPos[0] != -50 && yPos[0]+ballSize/2 < height*0.60 && yPos[0]-ballSize/2 > height*0.40) {
- score++;
- resetBall(0);
- updateSpeed();
- } else {
- lives = lives - 1;
- }
- }
- if (key == 's' || key == 'S') {
- if (yPos[1] != -50 && yPos[1]+ballSize/2 < height*0.60 && yPos[1]-ballSize/2 > height*0.40) {
- score++;
- resetBall(1);
- updateSpeed();
- } else if (lives == 5 && difficulty == 0) {
- if (selected[0] == 1) {
- selected[0] = 0;
- selected[1] = 1;
- selected[2] = 0; // Just in case.
- } else if (selected[1] == 1) {
- selected[0] = 0;
- selected[1] = 0;
- selected[2] = 1;
- } else if (selected[2] == 1) {
- selected[0] = 1;
- selected[1] = 0;
- selected[2] = 0;
- }
- } else {
- lives = lives - 1;
- }
- }
- if (key == 'd' || key == 'D') {
- if (yPos[2] != -50 && yPos[2]+ballSize/2 < height*0.60 && yPos[2]-ballSize/2 > height*0.40) {
- score++;
- resetBall(2);
- updateSpeed();
- } else {
- lives = lives - 1;
- }
- }
- }
- void debug() {
- System.out.println(lives);
- //System.out.println(moveSpeed);
- //System.out.println(ballMoving);
- //System.out.println(displayHeight);
- //System.out.println(yPos[0] + " | " + yPos[1] + " | " + yPos[2]);
- }
- void moveBalls() {
- if (!ballMoving) {
- if (lives != 4) {
- if (nextBall == 3) {
- p_ballNumber = ballNumber; // Ensures that we don't have repeats.
- ballNumber = int(random(0,3));
- if (p_ballNumber == ballNumber) {
- if (p_ballNumber == 0) {
- ballNumber = int(random(1,3));
- } else if ( p_ballNumber == 1) {
- ballNumber = int(random(1,3));
- if (ballNumber == 1) {
- ballNumber = 0;
- }
- } else if ( p_ballNumber == 2) {
- ballNumber = int(random(0,2));
- }
- }
- } else {
- ballNumber = nextBall;
- nextBall = 3;
- }
- ballMoving = true;
- }
- } else {
- if (ballNumber == 0) {
- if (yPos[0] <= displayHeight) {
- yPos[0] = yPos[0] + moveSpeed;
- } else {
- ballMoving = false;
- resetBall(0);
- lives = lives - 1;
- }
- }
- if (ballNumber == 1) {
- if (yPos[1] <= displayHeight) {
- yPos[1] = yPos[1] + moveSpeed;
- } else {
- ballMoving = false;
- resetBall(1);
- lives = lives - 1;
- }
- }
- if (ballNumber == 2) {
- if (yPos[2] <= displayHeight) {
- yPos[2] = yPos[2] + moveSpeed;
- } else {
- ballMoving = false;
- resetBall(2);
- lives = lives - 1;
- }
- }
- }
- }
- void drawBalls() {
- fill(255);
- strokeWeight(1);
- stroke(255,255,255);
- ellipse(width*.30,yPos[0],ballSize,ballSize);
- ellipse(width*.50,yPos[1],ballSize,ballSize);
- ellipse(width*.60,yPos[2],ballSize,ballSize);
- }
- void drawPlayground() {
- background(0);
- fill(255);
- strokeWeight(3);
- stroke(255,255,255);
- if (lives != 4) {
- textAlign(CENTER);
- textSize(32);
- text("| " + lives + " |",width/2,height*0.15);
- text("| " + score + " |", width/2,height*0.25);
- line(0,height*.40,width,height*.40);
- line(0,height*.60,width,height*.60);
- } else {
- textAlign(CENTER);
- textSize(32);
- text("| " + score + " |", width/2,height*0.25);
- text("You've died. Press the spacebar to start again.",width/2,height/2);
- }
- }
- void updateSpeed() {
- moveSpeed = moveSpeed + .40;
- }
- void resetBall(int ballResetNumber) {
- if (ballResetNumber == 0) {
- yPos[0] = -50;
- ballMoving = false;
- }
- if (ballResetNumber == 1) {
- yPos[1] = -50;
- ballMoving = false;
- }
- if (ballResetNumber == 2) {
- yPos[2] = -50;
- ballMoving = false;
- }
- if (ballResetNumber == 3) {
- yPos[0] = -50;
- yPos[1] = -50;
- yPos[2] = -50;
- ballMoving = false;
- }
- }
- /*
- void drawHealthBalls() {
- if (lives != 5) {
- if (lives <= 3 && lives >= 1) { // So I can add on more lives once I add a configuration file..
- if (lives == 3) {
- fill(255,0,0);
- ellipse(healthX[0],healthY[0]);
- // to be completed..
- fill(fillColor);
- }
- }
- }
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement