import processing.opengl.*; void setup() { size(1024, 768, OPENGL); smooth(); noCursor(); } void draw() { background(90); rectMode(CENTER); Rink(); Markings(); Player(); Controls(); Enemy(); Puck(); lights(); Nets(); ScoreBoard(); collision(); } void collision() { ////////////////PLAYER TO PUCK FRONTAL COLLISION///// if (puckX < playerX+15 && puckX > playerX && puckY < playerY+20 && puckY > playerY-20) { puckXspeed = 0;////RESET THE PUCK X AND Y SPEED puckYspeed = 0; friction=1; if (playerY > height/2) { puckXspeed = 15; puckYspeed = random(-3, -15); } if (playerY < height/2) { puckXspeed = 15; puckYspeed = random(3, 15); } } if (puckX < enemyX+20 && puckX > enemyX && puckY < enemyY+20 && puckY > enemyY-20) { puckXspeed = 0;////RESET THE PUCK X AND Y SPEED puckYspeed = 0; friction=1; if (playerY > height/2) { puckXspeed = -15; puckYspeed = random(-3, -15); } if (playerY < height/2) { puckXspeed = -15; puckYspeed = random(3, 15); } } ////////////////////////GOAL COLLISION/////////// if (puckX < 126 && puckX > 110 && puckY < 403 && puckY > 365 ) { enemyScore++; puckX = width/2; puckY = height/2; puckXspeed = 0; puckYspeed = 0; enemyX= width/2+300; enemyY= height/2; } if (puckX > width-126 && puckX < width-110 && puckY < 403 && puckY > 365 ) { playerScore++; puckX = width/2; puckY = height/2; puckXspeed = 0; puckYspeed = 0; enemyX= width/2+300; enemyY= height/2; } if (puckX > width-50 && puckX < width-110 && puckY < 403 && puckY > 365 ) { puckXspeed=0; puckXspeed=+5; } } int enemyScore; int playerScore; int seconds = 0; int mins=20; float milsecs=60; void ScoreBoard() { fill(0); stroke(175); rect(width/2, 100, 700, 30); fill(255); text("R A N G E R S", width/2-200, 105); fill(255); rect(width/2-85, 100, 30, 30); fill(0); text(enemyScore, width/2-88, 105); fill(255, 0, 0); noStroke(); rect(width/2-177, 110, 150, 7); fill(255); text("I S L A N D E R S", width/2-25, 105); rect(width/2-50, 100, 30, 30); fill(0); text(playerScore, width/2-55, 105); fill(255, 165, 0); noStroke(); rect(width/2+41, 110, 150, 7); fill(255); text("1 S T ", width/2 + 150, 105); // timer// if (milsecs <= 60) { milsecs--; if (milsecs <= 0) { milsecs = 60; if (milsecs <=60) { seconds--; if (seconds <= 0) { seconds = 59; mins--; } } } } fill(255); text(mins, width/2+200, 105); text(":", width/2+221, 105); if (seconds >=10) { text(seconds, width/2+230, 105); } if (seconds < 10) { text(seconds, width/2+240, 105); text("0", width/2+230, 105); } } void Nets() { pushMatrix(); fill(220); stroke(255, 0, 0); translate(width/2-380.5, height/2, 35); box(20, 50, 30); popMatrix(); pushMatrix(); fill(220); stroke(255, 0, 0); translate(width/2+380, height/2, 35); box(20, 50, 30); popMatrix(); } float puckX = 1024/2; float puckY = 768/2; float puckXspeed ; float puckYspeed ; float friction =2; void Puck() { fill(0); stroke(130); ellipse(puckX, puckY, 8, 8); } float playerX = 1024/2-300; float playerY = 768/2; float TargetX = mouseX; float PlayerY = mouseY; float easing = 0.015; void Controls() { //puck controls puckY = (puckY+puckYspeed / friction); puckX = (puckX+puckXspeed / friction) ; friction+=0.03; if (puckY >= height/2+183 ||puckY <= height/2-183 ) { puckYspeed *=-1; friction+= 0.03; } if (puckX >= width/2+440 ||puckX <= width/2-440 ) { puckXspeed *=-1; friction+=0.03; } if (keyPressed) { if (key=='a') { puckX--; } if (key=='d') { puckX++; } if (key=='w') { puckY--; } if (key=='s') { puckY++; } } if (friction >= 50) { puckXspeed = 0; puckYspeed = 0; friction = 1; } //Player Controls -- ice like float targetX = mouseX; float targetY = mouseY; playerX = constrain(mouseX, 100, 930); playerY = constrain(mouseY, height/2-170, height/2+170); //if (targetX > playerX && playerX < width - 12 || targetX < playerX && playerX > 12) { // playerX += (targetX -playerX) * easing; // } /// if (targetY < playerY && playerY > 12 || targetY > playerY && playerY < height - 12) { // playerY += (targetY - playerY) * easing; /// } } void Player() { pushMatrix(); fill(255, 165, 0); stroke(0, 0, 255); strokeWeight(2); translate(playerX, playerY, 50); box(10, 20, 50); popMatrix(); } int enemyX = 1024/2+300; int enemyY = 768/2; void Enemy() { pushMatrix(); fill(200); stroke(0, 0, 255); strokeWeight(2); translate(enemyX, enemyY, 50); box(10, 20, 50); popMatrix(); if (puckY > enemyY) { enemyY+=2; } if (puckY < enemyY) { enemyY-=2; } if (puckX > enemyX-20) { enemyX+=3; } if (puckX < enemyX) { enemyX-=3; } } void Rink() { fill(255); stroke(255, 165, 0); strokeWeight(5); rect(width/2, height/2, 705, 385); //right side corners stroke(0, 0, 255); arc(width/2+350, height/2+92, 200, 200, 0, PI/2); arc(width/2+350, height/2-93, 200, 200, -PI/2, 0); noStroke(); rect(width/2+400, height/2, 100, 200); fill(255, 165, 0); rect(width/2-450, height/2, 6, 200); rect(width/2+450, height/2, 6, 200); // left side corners fill(255); stroke(0, 0, 255); arc(162, height/2+92, 200, 200, PI/2, PI); arc(162, height/2-93, 200, 200, PI, TWO_PI-PI/2); noStroke(); rect(width/2-397, height/2, 100, 200); } void Markings() { noFill(); stroke(0, 0, 255); strokeWeight(1.5); ellipse(width/2, height/2, 140, 140); noStroke(); fill(0, 0, 255); rect(width/2+180, height/2, 13, 385); rect(width/2-180, height/2, 13, 385); noStroke(); fill(255, 0, 0); rect(width/2, height/2, 4, 385); ellipse(width/2-300, height/2+100, 8, 8); ellipse(width/2-300, height/2-100, 8, 8); ellipse(width/2+300, height/2+100, 8, 8); ellipse(width/2+300, height/2-100, 8, 8); fill(0, 0, 255); stroke(255, 0, 0); ellipse(width/2, height/2, 20, 20); noFill(); stroke(255, 0, 0); ellipse(width/2-300, height/2+100, 100, 100); ellipse(width/2-300, height/2-100, 100, 100); ellipse(width/2+300, height/2+100, 100, 100); ellipse(width/2+300, height/2-100, 100, 100); fill(255, 0, 0); rect(width/2+380, height/2, 1, 375); rect(width/2-380, height/2, 1, 375); //lines on circles noFill(); stroke(255, 0, 0); strokeWeight(.5); //BOTTOM RIGHT CIRCLE LINES rect(width/2+311, height/2+103, 10, .5); rect(width/2+311, height/2+97, 10, .5); rect(width/2+287, height/2+103, 10, .5); rect(width/2+287, height/2+97, 10, .5); rect(width/2+307, height/2+108, .5, 10); rect(width/2+307, height/2+91, .5, 10); rect(width/2+293, height/2+108, .5, 10); rect(width/2+293, height/2+91, .5, 10); rect(width/2+287, height/2+47, .5, 10); rect(width/2+311, height/2+47, .5, 10); rect(width/2+287, height/2+154, .5, 10); rect(width/2+311, height/2+154, .5, 10); //TOP RIGHT CIRCLE LINES rect(width/2+311, height/2-103, 10, .5); rect(width/2+311, height/2-97, 10, .5); rect(width/2+287, height/2-103, 10, .5); rect(width/2+287, height/2-97, 10, .5); rect(width/2+307, height/2-108, .5, 10); rect(width/2+307, height/2-91, .5, 10); rect(width/2+293, height/2-108, .5, 10); rect(width/2+293, height/2-91, .5, 10); rect(width/2+287, height/2-47, .5, 10); rect(width/2+311, height/2-47, .5, 10); rect(width/2+287, height/2-154, .5, 10); rect(width/2+311, height/2-154, .5, 10); //TOP LEFT CIRCLE LINES rect(width/2-311, height/2-103, 10, .5); rect(width/2-311, height/2-97, 10, .5); rect(width/2-287, height/2-103, 10, .5); rect(width/2-287, height/2-97, 10, .5); rect(width/2-307, height/2-108, .5, 10); rect(width/2-307, height/2-91, .5, 10); rect(width/2-293, height/2-108, .5, 10); rect(width/2-293, height/2-91, .5, 10); rect(width/2-287, height/2-47, .5, 10); rect(width/2-311, height/2-47, .5, 10); rect(width/2-287, height/2-154, .5, 10); rect(width/2-311, height/2-154, .5, 10); //BOTTOM LEFT CIRCLE LINES rect(width/2-311, height/2+103, 10, .5); rect(width/2-311, height/2+97, 10, .5); rect(width/2-287, height/2+103, 10, .5); rect(width/2-287, height/2+97, 10, .5); rect(width/2-307, height/2+108, .5, 10); rect(width/2-307, height/2+91, .5, 10); rect(width/2-293, height/2+108, .5, 10); rect(width/2-293, height/2+91, .5, 10); rect(width/2-287, height/2+47, .5, 10); rect(width/2-311, height/2+47, .5, 10); rect(width/2-287, height/2+154, .5, 10); rect(width/2-311, height/2+154, .5, 10); //GOAL CREASE fill(0, 0, 255); stroke(255, 0, 0); strokeWeight(3); rect(width/2-370, height/2, 20, 50); arc(width/2-362, height/2, 40, 50, -PI/2, PI/2); rect(width/2+369, height/2, 20, 50); arc(width/2+361, height/2, 40, 50, PI/2, 3*PI/2); //trapazoid strokeWeight(3); line(width/2+380, height/2+50, width/2+450, height/2+80); line(width/2+380, height/2-50, width/2+450, height/2-80); line(width/2-381, height/2+50, width/2-450, height/2+80); line(width/2-381, height/2-50, width/2-450, height/2-80); }