import processing.opengl.*; boolean paused=false; // 'p' key toggle pause mode. void setup() { size (800,600, OPENGL); noCursor(); //-- frameRate(10); } void draw() { background(0); lights(); Rink(); Net(); if (paused) { fill(0,0,255); text( "G A M E P A U S E D", width/2-58, height/2-30 ); text( "(press 'p' to continue)", width/2-58, height/2-10 ); } else { Controls(); Puck(); Collision(); Player(); Computer(); } Score(); //??mousePressed(); } void keyPressed() //// Which key? { if (key == 'p') { paused= ! paused; } } int computerScore; int playerScore; void Score() { // When computer scores a goal if (puckY == 550) { computerScore++; } // when player scores a goal if (puckY == 50) { playerScore++; } // score text and color fill(0); text("Player Score = ", width/2-70,540); fill(0); text("Computer Score = ", width/2-90,70); fill(0); text(playerScore, width/2+20,540); fill(0); text(computerScore, width/2+20,70); // end score text and color } // player shoot void mousePressed() { if(mousePressed && hit == true) { puckYpos = -4; puckXpos *= 1; } } // end player shoot // This is for the computer Paddle int computerX =400; int computerY =150; void Computer() { // Computer Paddle pushMatrix(); translate(computerX,computerY); stroke(255,0,0); strokeWeight(1); fill(0,0,255); box(20,10,10); popMatrix(); // end computer paddle // basic A.I. if(puckX > computerX) { computerX+=2; } if(puckX < computerX) { computerX-=2; } // end A.I fill(255,0,0); text("NY RANGERS", computerX-40,computerY-20); } // End computer paddle void Rink() { fill(255); noStroke(); rectMode(CENTER); rect(width/2,height/2, 400,500); // center circle strokeWeight(5); stroke(255,0,0); ellipse(width/2, height/2, 100,100); // end center circl //center line strokeWeight(0); noStroke(); fill(255,0,0); rect(400,height/2,width/2,5); //end center line // blue lines strokeWeight(0); noStroke(); fill(0,0,255); rect(400,height/2+70,width/2,5); strokeWeight(0); noStroke(); fill(0,0,255); rect(400,height/2-70,width/2,5); // end blue lines // 4 outter circles /* strokeWeight(5); stroke(255,0,0); fill(255); ellipse(width/2-120, height-150, 100,100); */ circ( width/2-120, height-150 ); strokeWeight(5); stroke(255,0,0); fill(255); ellipse(width/2+120, height-150, 100,100); strokeWeight(5); stroke(255,0,0); fill(255); ellipse(width/2-120, 150, 100,100); strokeWeight(5); stroke(255,0,0); fill(255); ellipse(width/2+120, 150, 100,100); // 4 outter circles //Goal Mouths stroke(255,0,0); fill(0,0,255); ellipse(width/2,100,75,75); stroke(255,0,0); fill(0,0,255); ellipse(width/2,height-100,75,75); fill(255); noStroke(); rect(width/2,height-80,100,50); rect(width/2,80,100,50); //Goal Mouths } void circ( float x, float y ) //// Make a circle at (x,y) { strokeWeight(5); stroke(255,0,0); fill(255); ellipse(x, y, 100,100); } int playerX = 400; int playerY = 400; void Player() { pushMatrix(); translate(playerX,playerY); stroke(0); strokeWeight(1); fill(255,150,0); box(20,10,10); popMatrix(); fill(0,0,255); text("NY ISLANDERS", playerX-40,playerY+20); } void Controls() { playerX = mouseX; playerY = mouseY; } void Net() { pushMatrix(); translate(width/2,100); fill(210); stroke(255,0,0); strokeWeight(5); box(75,30,30); popMatrix(); pushMatrix(); translate(width/2,height-100); fill(210); stroke(255,0,0); strokeWeight(5); box(75,30,30); popMatrix(); } float puckX = 400; float puckY = 300; float puckXpos; float puckYpos; void Puck() { noStroke(); fill(0); ellipse(puckX,puckY,15, 15); puckX = puckX + puckXpos; puckY = puckY + puckYpos; if(puckX >600 || puckX <200) { puckXpos *=-1; } if(puckY > 550 || puckY < 50) { puckYpos *=-1; } } boolean hit; void Collision() { if (playerX > puckX-20 && puckX+20 > playerX && playerY > puckY && puckY > playerY -30) { hit = true; fill(255,0,0); text("SHOOT!",playerX+50,playerY+20); } else { hit = false; } if (computerX > puckX-20 && puckX+20 > computerX && computerY > puckY && puckY > computerY -30) { puckYpos = 3; puckXpos = 3; } }