class ElPipe { float x,y; int type; float bottomY; float topY; float rightX; float leftX; float colorTimer; float lastSoundTriggerTime = 0; float newBallTimer; float dirTimer; int r; //red fill value int g; //green fill value int blu; //blue fill value boolean ballEnteredPipe; boolean ballExitedPipe; boolean makeNewBall; boolean pipeDrag = false; //constructor ElPipe(float xpos, float ypos, int typeOfPipe){ x = xpos; y = ypos; type = typeOfPipe; } void doEl1PipeActions(Ball b){ didBallEnterPipe(b); didBallExitPipe(b); if(ballInPipe(b) && ballInRange(b)){ changeDir(b); playSound(b); lightUp(); } else if(ballInRange(b) && (ballInPipe(b) == false)){ lightUpRed(); removeBall(b); } } void doEl2PipeActions(Ball b){ didBallEnterEl2Pipe(b); didBallExitEl2Pipe(b); if(ballInPipe(b) && ballInRange(b)){ changeDir(b); playSound(b); lightUp(); } else if(ballInRange(b) && (ballInPipe(b) == false)){ removeBall(b); lightUpRed(); } } void doEl3PipeActions(Ball b){ didBallEnterEl3Pipe(b); didBallExitEl3Pipe(b); if(ballInPipe(b) && ballInRange(b)){ changeDir(b); playSound(b); lightUp(); } else if(ballInRange(b) && (ballInPipe(b) == false)){ removeBall(b); lightUpRed(); } } void doEl4PipeActions(Ball b){ didBallEnterEl4Pipe(b); didBallExitEl4Pipe(b); if(ballInPipe(b) && ballInRange(b)){ changeDir(b); playSound(b); lightUp(); } else if(ballInRange(b) && (ballInPipe(b) == false)){ removeBall(b); lightUpRed(); } } void doVertPipeActions(Ball b){ didBallEnterVertPipe(b); didBallExitVertPipe(b); if(ballInPipe(b) && ballInRange(b)){ changeDir(b); playSound(b); lightUp(); } else if(ballInVertRange(b) && (ballInPipe(b) == false)){ removeBall(b); lightUpRed(); } } void doHorzPipeActions(Ball b){ didBallEnterHorzPipe(b); didBallExitHorzPipe(b); if(ballInPipe(b) && ballInRange(b)){ changeDir(b); playSound(b); lightUp(); } else if(ballInHorzRange(b) && (ballInPipe(b) == false)){ removeBall(b); lightUpRed(); } } void doTee1PipeActions(Ball b){ didBallEnterTee1Pipe(b); didBallExitTee1Pipe(b); if(ballInPipe(b) && ballInRange(b)){ lightUp(); makeNewBalls(); if(b.direction == D){ changeDir(b); } playSound(b); } else if(ballInTee1Range(b) && (ballInPipe(b) == false) && (millis() - newBallTimer > 1000)){ removeBall(b); lightUpRed(); } else { makeNewBall = false; } } void doTee2PipeActions(Ball b){ didBallEnterTee2Pipe(b); didBallExitTee2Pipe(b); if(ballInPipe(b) && ballInRange(b)){ lightUp(); makeNewBalls(); if(b.direction == U){ changeDir(b); } playSound(b); } else if(ballInTee2Range(b) && (ballInPipe(b) == false) && (millis() - newBallTimer > 1000)){ removeBall(b); lightUpRed(); } else { makeNewBall = false; } } void doDiag1PipeActions(Ball b){ didBallEnterDiag1Pipe(b); didBallExitDiag1Pipe(b); if(ballInPipe(b) && ballInDiag1Range(b)){ changeDir(b); playSound(b); lightUp(); } else if(ballInDiag1Range(b) && (ballInPipe(b) == false)){ removeBall(b); lightUpRed(); } } void doDiag2PipeActions(Ball b){ didBallEnterDiag2Pipe(b); didBallExitDiag2Pipe(b); if(ballInPipe(b) && ballInDiag2Range(b)){ changeDir(b); playSound(b); lightUp(); } else if(ballInDiag2Range(b) && (ballInPipe(b) == false)){ removeBall(b); lightUpRed(); } } void displayEl1(){ noStroke(); if ((millis() - colorTimer) > FLASH && (pipeDrag != true)){//resets the color of the pipe after a flash of another color r = 34; g = 48; blu = 188; } fill(r,g,blu); makeEl1Shape(); } void displayEl2(){ noStroke(); if ((millis() - colorTimer) > FLASH && (pipeDrag != true)){//resets the color of the pipe after a flash of another color r = 34; g = 48; blu = 188; } fill(r,g,blu); makeEl2Shape(); } void displayEl3(){ noStroke(); if ((millis() - colorTimer) > FLASH && (pipeDrag != true)){//resets the color of the pipe after a flash of another color r = 34; g = 48; blu = 188; } fill(r,g,blu); makeEl3Shape(); } void displayEl4(){ noStroke(); if ((millis() - colorTimer) > FLASH && (pipeDrag != true)){//resets the color of the pipe after a flash of another color r = 34; g = 48; blu = 188; } fill(r,g,blu); makeEl4Shape(); } void displayVert(){ noStroke(); if ((millis() - colorTimer) > FLASH && (pipeDrag != true)){//resets the color of the pipe after a flash of another color r = 34; g = 48; blu = 188; } fill(r,g,blu); makeVertShape(); } void displayHorz(){ noStroke(); if ((millis() - colorTimer) > FLASH && (pipeDrag != true)){//resets the color of the pipe after a flash of another color r = 34; g = 48; blu = 188; } fill(r,g,blu); makeHorzShape(); } void displayTee1(){ noStroke(); if ((millis() - colorTimer) > FLASH && (pipeDrag != true)){//resets the color of the pipe after a flash of another color r = 34; g = 48; blu = 188; } fill(r,g,blu); makeTee1Shape(); } void displayTee2(){ noStroke(); if ((millis() - colorTimer) > FLASH && (pipeDrag != true)){//resets the color of the pipe after a flash of another color r = 34; g = 48; blu = 188; } fill(r,g,blu); makeTee2Shape(); } void displayDiag1(){ noStroke(); if ((millis() - colorTimer) > FLASH && (pipeDrag != true)){//resets the color of the pipe after a flash of another color r = 34; g = 48; blu = 188; } fill(r,g,blu); makeDiag1Shape(); } void displayDiag2(){ noStroke(); if ((millis() - colorTimer) > FLASH && (pipeDrag != true)){//resets the color of the pipe after a flash of another color r = 34; g = 48; blu = 188; } fill(r,g,blu); makeDiag2Shape(); } void makeEl1Shape(){ bottomY = (y + GRID_SPACE); topY = (y - GRID_SPACE); rightX = (x + GRID_SPACE); leftX = (x - GRID_SPACE); beginShape(); vertex(x,y); vertex(rightX,y); vertex(rightX,bottomY); vertex(leftX,bottomY); vertex(leftX,topY); vertex(x,topY); endShape(); } void makeEl2Shape(){ bottomY = (y + GRID_SPACE); topY = (y - GRID_SPACE); rightX = (x + GRID_SPACE); leftX = (x - GRID_SPACE); beginShape(); vertex(x,y); vertex(x,topY); vertex(rightX,topY); vertex(rightX,bottomY); vertex(leftX,bottomY); vertex(leftX,y); endShape(); } void makeEl3Shape(){ bottomY = (y + GRID_SPACE); topY = (y - GRID_SPACE); rightX = (x + GRID_SPACE); leftX = (x - GRID_SPACE); beginShape(); vertex(x,y); vertex(x,bottomY); vertex(rightX,bottomY); vertex(rightX,topY); vertex(leftX,topY); vertex(leftX,y); endShape(); } void makeEl4Shape(){ bottomY = (y + GRID_SPACE); topY = (y - GRID_SPACE); rightX = (x + GRID_SPACE); leftX = (x - GRID_SPACE); beginShape(); vertex(x,y); vertex(rightX,y); vertex(rightX,topY); vertex(leftX,topY); vertex(leftX,bottomY); vertex(x,bottomY); endShape(); } void makeVertShape(){ bottomY = (y + GRID_SPACE); topY = (y - GRID_SPACE); rightX = (x + GRID_SPACE); beginShape(); vertex(x,y); vertex(x,bottomY); vertex(rightX,bottomY); vertex(rightX,topY); vertex(x,topY); endShape(); } void makeHorzShape(){ bottomY = (y + GRID_SPACE); rightX = (x + GRID_SPACE); leftX = (x - GRID_SPACE); beginShape(); vertex(x,y); vertex(rightX,y); vertex(rightX,bottomY); vertex(leftX,bottomY); vertex(leftX,y); endShape(); } void makeTee1Shape(){ bottomY = (y + GRID_SPACE); topY = (y - GRID_SPACE); rightX = (x + GRID_SPACE); leftX = (x - GRID_SPACE); beginShape(); vertex(x,y); vertex(x,topY); vertex(rightX,topY); vertex(rightX,y); vertex((x+(GRID_SPACE*2)),y); vertex((x+(GRID_SPACE*2)),bottomY); vertex(leftX,bottomY); vertex(leftX,y); endShape(); } void makeTee2Shape(){ bottomY = (y + GRID_SPACE); topY = (y - GRID_SPACE); rightX = (x + GRID_SPACE); leftX = (x - GRID_SPACE); beginShape(); vertex(x,y); vertex(x,bottomY); vertex(rightX,bottomY); vertex(rightX,y); vertex((x + (GRID_SPACE * 2)), y); vertex((x + (GRID_SPACE * 2)), topY); vertex(leftX,topY); vertex(leftX,y); endShape(); } void makeDiag1Shape(){ bottomY = (y + GRID_SPACE); topY = (y - GRID_SPACE); rightX = (x + GRID_SPACE); leftX = (x - GRID_SPACE); beginShape(); vertex(x,y); vertex(rightX,bottomY); vertex(x,bottomY); vertex(leftX,y); endShape(); } void makeDiag2Shape(){ bottomY = (y + GRID_SPACE); topY = (y - GRID_SPACE); rightX = (x + GRID_SPACE); leftX = (x - GRID_SPACE); beginShape(); vertex(x,y); vertex(rightX,topY); vertex(rightX,y); vertex(x,bottomY); endShape(); } boolean mouseOverPipe(){ if ((abs(pmouseX - x) <= (GRID_SPACE)) && (abs(pmouseY - y) <= (GRID_SPACE))){ return true; } else { return false; } } boolean ballInRange(Ball b){ if((abs(x - b.x) < GRID_SPACE) && (abs(y - b.y) < GRID_SPACE)){ return true; } else { return false; } } boolean ballInVertRange(Ball b){ if((abs(b.x - x) < GRID_SPACE/2) && (abs(y - b.y) < GRID_SPACE)){ return true; } else { return false; } } boolean ballInHorzRange(Ball b){ if((abs(b.y - y) < GRID_SPACE/2) && (abs(x - b.x) < GRID_SPACE)){ return true; } else { return false; } } boolean ballInTee1Range(Ball b){ if(((abs(x - b.x) < GRID_SPACE) && (abs(y - b.y) < GRID_SPACE))){ return true; } if((b.x > x) && ((b.x - x) < (GRID_SPACE * 2)) && (abs(y - b.y) < GRID_SPACE)){ return true; } else { return false; } } boolean ballInTee2Range(Ball b){ if(((abs(x - b.x) < GRID_SPACE) && (abs(y - b.y) < GRID_SPACE))){ return true; } if((b.x > x) && ((b.x - x) < (GRID_SPACE * 2)) && (abs(y - b.y) < GRID_SPACE)){ return true; } else { return false; } } boolean ballInDiag1Range(Ball b){ if(((b.y - y) < GRID_SPACE) && ((b.y - y) > 0) && (abs(x - b.x) < GRID_SPACE)){ return true; } else { return false; } } boolean ballInDiag2Range(Ball b){ if(((b.x - x) < GRID_SPACE) && ((b.x - x) > 0) && (abs(y - b.y) < GRID_SPACE)){ return true; } else { return false; } } boolean ballInPipe(Ball b){ if((b.ballEnteredPipe == true) /*&& (b.ballExitedPipe == false)*/){ return true; } else{ return false; } } void didBallEnterPipe(Ball b){ if((b.previousY <= topY) && (b.y >= topY) && (b.x > leftX) && (b.x < x)){ b.ballEnteredPipe = true; b.ballExitedPipe = false; } else if((b.previousX >= rightX) && (b.x <= rightX) && (b.y < bottomY) && (b.y > y)){ b.ballEnteredPipe = true; b.ballExitedPipe = false; } } void didBallExitPipe(Ball b){ if((b.previousX <= rightX) && (b.x >= rightX) && (b.y < bottomY) && (b.y > y)){ b.ballExitedPipe = true; b.ballEnteredPipe = false; } else if ((b.previousY >= topY) && (b.y <= topY) && (b.x > leftX) && (b.x < x)){ b.ballExitedPipe = true; b.ballEnteredPipe = false; } } void didBallEnterEl2Pipe(Ball b){ if((b.previousY <= topY) && (b.y >= topY) && (b.x < rightX) && (b.x > x)){ b.ballEnteredPipe = true; b.ballExitedPipe = false; } else if((b.previousX <= leftX) && (b.x >= leftX) && (b.y < bottomY) && (b.y > y)){ b.ballEnteredPipe = true; b.ballExitedPipe = false; } } void didBallExitEl2Pipe(Ball b){ if((b.previousX >= leftX) && (b.x <= leftX) && (b.y < bottomY) && (b.y > y)){ b.ballExitedPipe = true; b.ballEnteredPipe = false; } else if ((b.previousY >= topY) && (b.y <= topY) && (b.x < rightX) && (b.x > x)){ b.ballExitedPipe = true; b.ballEnteredPipe = false; } } void didBallEnterEl3Pipe(Ball b){ if((b.previousY >= bottomY) && (b.y <= bottomY) && (b.x < rightX) && (b.x > x)){ b.ballEnteredPipe = true; b.ballExitedPipe = false; } else if((b.previousX <= leftX) && (b.x >= leftX) && (b.y > topY) && (b.y < y)){ b.ballEnteredPipe = true; b.ballExitedPipe = false; } } void didBallExitEl3Pipe(Ball b){ if((b.previousX >= leftX) && (b.x <= leftX) && (b.y > topY) && (b.y < y)){ b.ballExitedPipe = true; b.ballEnteredPipe = false; } else if ((b.previousY <= bottomY) && (b.y >= bottomY) && (b.x < rightX) && (b.x > x)){ b.ballExitedPipe = true; b.ballEnteredPipe = false; } } void didBallEnterEl4Pipe(Ball b){ if((b.previousY >= bottomY) && (b.y <= bottomY) && (b.x > leftX) && (b.x < x)){ b.ballEnteredPipe = true; b.ballExitedPipe = false; } else if((b.previousX >= rightX) && (b.x <= rightX) && (b.y > topY) && (b.y < y)){ b.ballEnteredPipe = true; b.ballExitedPipe = false; } } void didBallExitEl4Pipe(Ball b){ if((b.previousX <= rightX) && (b.x >= rightX) && (b.y > topY) && (b.y < y)){ b.ballExitedPipe = true; b.ballEnteredPipe = false; } else if ((b.previousY <= bottomY) && (b.y >= bottomY) && (b.x > leftX) && (b.x < x)){ b.ballExitedPipe = true; b.ballEnteredPipe = false; } } void didBallEnterVertPipe(Ball b){ if((b.previousY >= bottomY) && (b.y <= bottomY) && (b.x < rightX) && (b.x > x)){ b.ballEnteredPipe = true; b.ballExitedPipe = false; } else if((b.previousY <= topY) && (b.y >= topY) && (b.x < rightX) && (b.x > x)){ b.ballEnteredPipe = true; b.ballExitedPipe = false; } } void didBallExitVertPipe(Ball b){ if((b.previousY <= bottomY) && (b.y >= bottomY) && (b.x < rightX) && (b.x > x)){ b.ballExitedPipe = true; b.ballEnteredPipe = false; } else if((b.previousY >= topY) && (b.y <= topY) && (b.x < rightX) && (b.x > x)){ b.ballExitedPipe = true; b.ballEnteredPipe = false; } } void didBallEnterHorzPipe(Ball b){ if((b.previousX >= rightX) && (b.x <= rightX) && (b.y < bottomY) && (b.y > y)){ b.ballEnteredPipe = true; b.ballExitedPipe = false; } else if((b.previousX <= leftX) && (b.x >= leftX) && (b.y < bottomY) && (b.y > y)){ b.ballEnteredPipe = true; b.ballExitedPipe = false; } } void didBallExitHorzPipe(Ball b){ if((b.previousX <= rightX) && (b.x >= rightX) && (b.y < bottomY) && (b.y > y)){ b.ballExitedPipe = true; b.ballEnteredPipe = false; } else if((b.previousX >= leftX) && (b.x <= leftX) && (b.y < bottomY) && (b.y > y)){ b.ballExitedPipe = true; b.ballEnteredPipe = false; } } void didBallEnterTee1Pipe(Ball b){ if((b.previousY <= topY) && (b.y >= topY) && (b.x < rightX) && (b.x > x)){ b.ballEnteredPipe = true; b.ballExitedPipe = false; } else if((b.previousX <= leftX) && (b.x >= leftX) && (b.y < bottomY) && (b.y > y)){ b.ballEnteredPipe = true; b.ballExitedPipe = false; } else if((b.previousX >= (x + (GRID_SPACE * 2))) && (b.x <= (x + (GRID_SPACE * 2))) && (b.y < bottomY) && (b.y > y)){ b.ballEnteredPipe = true; b.ballExitedPipe = false; } } void didBallExitTee1Pipe(Ball b){ if((b.previousX >= leftX) && (b.x <= leftX) && (b.y < bottomY) && (b.y > y)){ b.ballExitedPipe = true; b.ballEnteredPipe = false; } else if ((b.previousY >= topY) && (b.y <= topY) && (b.x < rightX) && (b.x > x)){ b.ballExitedPipe = true; b.ballEnteredPipe = false; } else if ((b.previousX <= (x + (GRID_SPACE * 2))) && (b.x >= (x + (GRID_SPACE * 2))) && (b.y < bottomY) && (b.y > y)){ b.ballExitedPipe = true; b.ballEnteredPipe = false; } } void didBallEnterTee2Pipe(Ball b){ if((b.previousY >= bottomY) && (b.y <= bottomY) && (b.x < rightX) && (b.x > x)){ b.ballEnteredPipe = true; b.ballExitedPipe = false; } else if((b.previousX <= leftX) && (b.x >= leftX) && (b.y > topY) && (b.y < y)){ b.ballEnteredPipe = true; b.ballExitedPipe = false; } else if((b.previousX >= (x + (GRID_SPACE * 2))) && (b.x <= (x + (GRID_SPACE * 2))) && (b.y > topY) && (b.y < y)){ b.ballEnteredPipe = true; b.ballExitedPipe = false; } } void didBallExitTee2Pipe(Ball b){ if((b.previousX >= leftX) && (b.x <= leftX) && (b.y > topY) && (b.y < y)){ b.ballExitedPipe = true; b.ballEnteredPipe = false; } else if ((b.previousY <= bottomY) && (b.y >= bottomY) && (b.x < rightX) && (b.x > x)){ b.ballExitedPipe = true; b.ballEnteredPipe = false; } else if ((b.previousX <= (x + (GRID_SPACE * 2))) && (b.x >= (x + (GRID_SPACE * 2))) && (b.y > topY) && (b.y < y)){ b.ballExitedPipe = true; b.ballEnteredPipe = false; } } void didBallEnterDiag1Pipe(Ball b){ if((b.previousY <= y) && (b.y >= y) && (b.x > leftX) && (b.x < x)){ b.ballEnteredPipe = true; b.ballExitedPipe = false; } else if((b.previousY >= bottomY) && (b.y <= bottomY) && (b.x < rightX) && (b.x > x)){ b.ballEnteredPipe = true; b.ballExitedPipe = false; } } void didBallExitDiag1Pipe(Ball b){ if((b.previousY <= bottomY) && (b.y >= bottomY) && (b.x < rightX) && (b.x > x)){ b.ballExitedPipe = true; b.ballEnteredPipe = false; } else if((b.previousY >= y) && (b.y <= y) && (b.x < leftX) && (b.x > x)){ b.ballExitedPipe = true; b.ballEnteredPipe = false; } } void didBallEnterDiag2Pipe(Ball b){ if((b.previousX <= x) && (b.x >= x) && (b.y < bottomY) && (b.y > y)){ b.ballEnteredPipe = true; b.ballExitedPipe = false; } else if((b.previousX >= rightX) && (b.x <= rightX) && (b.y > topY) && (b.y < y)){ b.ballEnteredPipe = true; b.ballExitedPipe = false; } } void didBallExitDiag2Pipe(Ball b){ if((b.previousX <= rightX) && (b.x >= rightX) && (b.y < topY) && (b.y > y)){ b.ballExitedPipe = true; b.ballEnteredPipe = false; } else if((b.previousX >= x) && (b.x <= x) && (b.y < bottomY) && (b.y > y)){ b.ballExitedPipe = true; b.ballEnteredPipe = false; } } void removeBall(Ball b){ b.direction = 0; b.x = -100; b.y = -100; } void lightUp(){ colorTimer = millis(); r = 255; g = 255; blu = 255; } void lightUpRed(){ colorTimer = millis(); r = 255; g = 0; blu = 50; } void lightUpDrag(){ r = 10; g = 255; blu = 224; } //============================= void changeDir(Ball b){ if(type == PIPE_EL1){ if(b.direction == L){ b.goUp(); b.x = (x - (GRID_SPACE/2)); } if(b.direction == D){ b.goRight(); b.y = (y + (GRID_SPACE/2)); } if(b.direction == DR){ b.goRight(); b.y = (y + (GRID_SPACE/2)); } if(b.direction == DL && (b.x < x)){ b.goRight(); b.y = (y + (GRID_SPACE/2)); } if(b.direction == DL && (b.x > x)){ b.goUp(); b.x = (x - (GRID_SPACE/2)); } if(b.direction == UL){ b.goUp(); b.x = (x - (GRID_SPACE/2)); b.y = (y + (GRID_SPACE/2)); } if(b.direction == UR){ b.goUp(); b.x = (x - (GRID_SPACE/2)); b.y = (y + (GRID_SPACE/2)); } } else if(type == PIPE_EL2){ if(b.direction == R){ b.goUp(); b.x = (x + (GRID_SPACE/2)); } if(b.direction == D){ b.goLeft(); b.y = (y + (GRID_SPACE/2)); } if(b.direction == DR && (b.y < y)){ b.goLeft(); b.y = (y + (GRID_SPACE/2)); } if(b.direction == DR && (b.y > y)){ b.goUp(); b.x = (x + (GRID_SPACE/2)); } if(b.direction == DL){ b.goLeft(); b.y = (y + (GRID_SPACE/2)); } if(b.direction == UR){ b.goUp(); b.x = (x + (GRID_SPACE/2)); } } else if(type == PIPE_EL3){ if(b.direction == R){ b.goDown(); b.x = (x + (GRID_SPACE/2)); } if(b.direction == U){ b.goLeft(); b.y = (y - (GRID_SPACE/2)); } if(b.direction == DR){ b.goDown(); b.y = (y + (GRID_SPACE/2)); b.x = (x + (GRID_SPACE/2)); } if(b.direction == DL){ b.goDown(); b.y = (y + (GRID_SPACE/2)); } if(b.direction == UL){ b.goLeft(); b.x = (x + (GRID_SPACE/2)); b.y = (y - (GRID_SPACE/2)); } if(b.direction == UR && (b.x > x)){ b.goLeft(); b.y = (y - (GRID_SPACE/2)); } if(b.direction == UR && (b.x < x)){ b.goDown(); b.x = (x + (GRID_SPACE/2)); } } else if(type == PIPE_EL4){ if(b.direction == L){ b.goDown(); b.x = (x - (GRID_SPACE/2)); } if(b.direction == U){ b.goRight(); b.y = (y - (GRID_SPACE/2)); } if(b.direction == DL){ b.goDown(); b.x = (x - (GRID_SPACE/2)); } if(b.direction == UL && (b.x < x)){ b.goRight(); b.y = (y - (GRID_SPACE/2)); } if(b.direction == UL && (b.x > x)){ b.goDown(); b.x = (x - (GRID_SPACE/2)); } if(b.direction == UR){ b.goRight(); b.y = (y - (GRID_SPACE/2)); } } else if(type == PIPE_TEE1){ b.goRight(); b.y = (y + (GRID_SPACE/2)); dirTimer = millis(); } else if(type == PIPE_TEE2){ b.goRight(); b.y = (y - (GRID_SPACE/2)); dirTimer = millis(); } else if(type == PIPE_DIAG1){ if(b.direction == D){ b.goDownRight(); b.x = x; b.y = (y + (GRID_SPACE/2)); } if(b.direction == U){ b.goUpLeft(); b.x = x; b.y = (y + (GRID_SPACE/2)); } if(b.direction == UR){ b.goUpLeft(); b.x = x; b.y = (y + (GRID_SPACE/2)); } } else if(type == PIPE_DIAG2){ if(b.direction == R){ b.goUpRight(); b.y = y; b.x = (x + (GRID_SPACE/2)); } if(b.direction == L){ b.goDownLeft(); b.y = y; b.x = (x + (GRID_SPACE/2)); } if(b.direction == UL){ b.goDownLeft(); b.y = y; b.x = (x + (GRID_SPACE/2)); } if(b.direction == DR){ b.goUpRight(); b.y = y; b.x = (x + (GRID_SPACE/2)); } } else if(type == PIPE_VERT){ if(b.direction == DR){ b.goDown(); b.x = (x + (GRID_SPACE/2)); } if(b.direction == DL){ b.goDown(); b.x = (x + (GRID_SPACE/2)); } if(b.direction == UL){ b.goUp(); b.x = (x + (GRID_SPACE/2)); } if(b.direction == UR){ b.goUp(); b.x = (x + (GRID_SPACE/2)); } } else if(type == PIPE_HORZ){ if(b.direction == DR){ b.goRight(); b.y = (y + (GRID_SPACE/2)); } if(b.direction == UR){ b.goRight(); b.y = (y + (GRID_SPACE/2)); } if(b.direction == DL){ b.goLeft(); b.y = (y + (GRID_SPACE/2)); } if(b.direction == UL){ b.goLeft(); b.y = (y + (GRID_SPACE/2)); } } } void playSound(Ball b){ if(millis() - lastSoundTriggerTime > 1000){ b.playZound(); lastSoundTriggerTime = millis(); } } void makeNewBalls(){ if ((millis() - newBallTimer) > 1000){ makeNewBall = true; newBallTimer = millis(); } else if((millis() - newBallTimer) < 1000){ makeNewBall = false; } } void dragPipe(){ if (pipeDrag == true){//if you are dragging on an el1 pipe x = mouseX;//make the pipe follow the mouse y = mouseY; //this code snaps the pipe piece to a grid float j = x % GRID_SPACE; float n = y % GRID_SPACE; if(j >= (GRID_SPACE/2)){ x = x + (GRID_SPACE-j); } else if (j < (GRID_SPACE/2)){ x = x - (j); } if(n >= (GRID_SPACE/2)){ y = y + (GRID_SPACE-n); } else if (n < (GRID_SPACE/2)){ y = y - (n); } } } }