PImage aUp; // up arrow PImage aLft; // left arrow PImage aDwn; // down arrow PImage aRt; // right arrow //WHITE VERSIONS PImage aUpW; // up arrow PImage aLftW; // left arrow PImage aDwnW; // down arrow PImage aRtW; // right arrow int y; int [] _chordCoords = new int[5]; PImage [] _images = new PImage[4]; PImage Up; PImage Dwn; PImage Lft; PImage Rt; PImage blank; int curImageIndex; int hit = 0; int miss = 0; void setup() { size(600, 600); background(0); frameRate(30); //inactive images aUp = loadImage("images/upArrow.GIF"); aLft = loadImage("images/leftArrow.GIF"); aDwn = loadImage("images/downArrow.GIF"); aRt = loadImage("images/rightArrow.GIF"); blank = loadImage("images/blank.GIF"); //active images aUpW = loadImage("images/upArrowWhite.GIF"); aLftW = loadImage("images/leftArrowWhite.GIF"); aDwnW = loadImage("images/downArrowWhite.GIF"); aRtW = loadImage("images/rightArrowWhite.GIF"); Up = aUp; Dwn = aDwn; Lft = aLft; Rt = aRt; setCurImageIndex(); position(Up, 1); position(Lft, 2); position(Dwn, 3); position(Rt, 4); } void position(PImage buttonImage, int xPlacement){ if(xPlacement <= 0 || xPlacement >= 5) {return;} else if(xPlacement == 1) { _chordCoords[1] = 0; _images[0] = buttonImage; } else if(xPlacement == 2) { _chordCoords[2] = width/4; _images[1] = buttonImage; } else if(xPlacement == 3) { _chordCoords[3] = width/2; _images[2] = buttonImage; } else { _chordCoords[4] = width-width/4; _images[3] = buttonImage; } } void setCurImageIndex(){ curImageIndex = int(random(3)+1); } void cycle(){ int speed = int(random(15,25)); if(y<600) {y+=speed; } else { y = -200; setCurImageIndex(); } _chordCoords[0] = y; image(_images[curImageIndex-1],_chordCoords[curImageIndex],_chordCoords[0],width/4,height/4); // println(curImageIndex-1); } void draw(){ background(0); image(Up, 0, height-height/4, width/4, height/4); image(Lft, width/4, height-height/4, width/4, height/4); image(Dwn, width/2, height-height/4, width/4, height/4); image(Rt, width-width/4, height-height/4, width/4, height/4); fill(0,hit,0,hit); rect(0,0,600,600); fill(miss,0,0,miss); rect(0,0,600,600); cycle(); } void keyPressed() { if(key == CODED){ if (keyCode == UP){ Up = aUpW; } else if(keyCode == DOWN){ Dwn = aDwnW; } else if(keyCode == LEFT) { Lft = aLftW; } else if(keyCode == RIGHT) { Rt = aRtW; } else { Up = aUp; Dwn = aDwn; Lft = aLft; Rt = aRt; } } if(key == CODED){ if (keyCode == UP && curImageIndex-1 == 0 && y>=340 && y<=600){ hit=200; println("hit!"); } else if(keyCode == LEFT && curImageIndex-1 == 1 && y>=340 && y<=600){ hit=200; println("hit!"); } else if(keyCode == DOWN && curImageIndex-1 == 2 && y>=340 && y<=600) { hit=200; println("hit!"); } else if(keyCode == RIGHT && curImageIndex-1 == 3 && y>=340 && y<=600) { hit=200; println("hit!"); } else { miss=200; println("miss!"); } } } void keyReleased() { if(key == CODED){ if (keyCode == UP){ Up = aUp; } else if(keyCode == DOWN){ Dwn = aDwn; } else if(keyCode == LEFT) { Lft = aLft; } else if(keyCode == RIGHT) { Rt = aRt; } else { Up = aUp; Dwn = aDwn; Lft = aLft; Rt = aRt; } } if(key == CODED){ if (keyCode == UP && curImageIndex-1 == 0 && y>=340 && y<=600){ hit=0; miss=0; } else if(keyCode == LEFT && curImageIndex-1 == 1 && y>=340 && y<=600){ hit=0; miss=0; } else if(keyCode == DOWN && curImageIndex-1 == 2 && y>=340 && y<=600) { hit=0; miss=0; } else if(keyCode == RIGHT && curImageIndex-1 == 3 && y>=340 && y<=600) { hit=0; miss=0; } else { miss=0; } } }