import processing.opengl.*; boolean on; int blinkSpeed = 10; void setup() { size (800, 600, OPENGL); noCursor(); } void draw() { background(0); lights(); Rink(); Net(); Controls(); Puck(); Collision(); Player(); Computer(); Score(); if (mousePressed && hit == true) { hit = false; puckY = puckY + puckYpos; puckY = playerY-30; puckYpos = -8; if (playerX < 400) { puckXpos = random(0, 4); } if (playerX > 400) { puckXpos = random(-4, 0); } } //speed reset if (puckYpos == -8 && hit == false) { puckYpos =-5; } //end speed reset } int computerScore; int playerScore; boolean compScore; boolean pScore; void Score() { if (puckX >= net2X-34 && puckX <= net2X+34 && puckY >= 495 && puckY <= 515) { text("COLLISION", width/2, height/2); compScore = true; } else { compScore = false; } 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); if (compScore == true) { puckY = height/2; puckX = width/2; computerScore++; puckYpos = 0; puckXpos = 0; } if (puckX >= netX-34 && puckX <= netX+34 && puckY >= 84 && puckY <= 104) { text("COLLISION", width/2, height/2); pScore = true; } else { pScore = false; } if (pScore == true) { puckY = height/2; puckX = width/2; playerScore++; puckYpos = 0; puckXpos = 0; } } int computerX =400; int computerY =150; void Computer() { pushMatrix(); translate(computerX, computerY); stroke(255, 0, 0); strokeWeight(1); fill(0, 0, 255); box(20, 10, 10); popMatrix(); if (puckX > computerX) { computerX+=2; } if (puckX < computerX) { computerX-=2; } fill(255, 0, 0); text("NY RANGERS", computerX-40, computerY-20); } 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); //center line strokeWeight(0); noStroke(); fill(255, 0, 0); rect(400, height/2, width/2, 5); // blue line 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); // outter circles 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, 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); //Goal Mouth 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); } 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; } float netX = 400; float netY = 100; float net2X = 400; float net2Y = 500; void Net() { pushMatrix(); translate(netX, netY); fill(210); stroke(255, 0, 0); strokeWeight(5); box(75, 30, 30); popMatrix(); pushMatrix(); translate(net2X, net2Y); 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() { /*puckX= mouseX; puckY = mouseY; */ /*if(keyPressed) { if(key == 'd') { puckX+=7; } if(key == 'a') { puckX-=7; } if(key == 'w') { puckY-=7; } if(key == 's') { puckY+=7; } }*/ fill(0); //text(puckX, height/2, width/2); //text(puckY, height/2, width/2+20); 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; if (hit == true) { puckX = playerX; puckY = playerY-10; puckYpos=0; puckXpos=0; } 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; } }