//tristan Peskett /* W,A,S,D to move space to launch a bomb click mouse to shoot guns dodge enemy fire while taking out opposing ships. be careful, if you run out of health, its game over. */ int timeScore= 0; int timeScore2 = 0; int ammo = 5; int shipVisibility= 255; int shipVisibility2 =255; int explotionVisibility1=0; int explotionVisibility2=0; int score= 0; int highScore=0; int lives = 3; int lifeVisibility3 = 255; int lifeVisibility2 = 255; int lifeVisibility1 = 255; int health = 10; int healthVisibility= 255; int enemyHealth1=100; int enemyHealth2=50; float eXL, eXR, eYT, eYB; float lasttimecheck; float lasttimecheck2; float timeinterval; float timeinterval2; float efR=(80); float efG=(180); float efB=(200); float backR = (5); float backG = (0); float backB = (20); float sR =(255); float sG =(255); float sB =(255); float bombVisibility1=(255); float bombVisibility2=(255); float bombVisibility3=(255); float bombVisibility4=(255); float bombVisibility5=(255); float r= random(10, 20); float r2= random(10, 20); float r3= random(10, 20); float r4= random(10, 20); float r5= random(10, 20); float r6= random(10, 20); float r7= random(10, 20); float r8= random(10, 20); float r9= random(10, 20); float r12= random(10, 20); float r13= random(10, 20); float r14= random(10, 20); float r15= random(10, 20); float r16= random(10, 20); float r17= random(10, 20); float r18= random(10, 20); float r19= random(10, 20); float rWidth= random(400); float rWidth2= random(400); float rWidth3=random(400); float rWidth4= random(400); float rWidth5= random(400); float rWidth6= random(400); float rWidth7= random(400); float rWidth8= random(400); float rWidth9= random(400); float rWidth12= random(400); float rWidth13=random(400); float rWidth14= random(400); float rWidth15= random(400); float rWidth16= random(400); float rWidth17= random(400); float rWidth18= random(400); float rWidth19= random(400); float rHeight= random(400); float rSize= random(6); float rSize2= random(3, 5); float rSize3= random(3, 5); float rSize4= random(3, 5); float rSize5= random(3, 5); float rSize6= random(3, 5); float rSize7= random(3, 5); float rSize8= random(3, 5); float playerHealth = 200; float playerDamage =20; float speedX =(0.1); float speedY =(0.1); float shipCenterX =(200); float shipCenterY =(450); float shipSpeed = 1; float bulletSpeed1= (0); float bulletSpeed2= (0); float bulletSpeed3= (0); float bulletSpeed4= (0); float bulletSpeed5= (0); float bulletCenterX=(300); float bulletCenterY=(300); float eShipX= 380; float eShipY= -200; float eShipX2= 380; float eShipY2= -600; float eGGun1X=(315); float eGGun2X=(325); float eGGun3X=(340); float eGGun4X=(350); float eGGun1Y=(60); float eGGun2Y=(55); float eGGun3Y=(55); float eGGun4Y=(60); float eGGun5X=(200); float eGGun6X=(210); float eGGun7X=(230); float eGGun8X=(240); float eGGun5Y=(80); float eGGun6Y=(75); float eGGun7Y=(75); float eGGun8Y=(80); float eGGun9X=(50); float eGGun10X=(60); float eGGun11X=(80); float eGGun12X=(90); float eGGun9Y=(60); float eGGun10Y=(55); float eGGun11Y=(55); float eGGun12Y=(60); float eGGun1X2=(315); float eGGun2X2=(325); float eGGun3X2=(340); float eGGun4X2=(350); float eGGun1Y2=(60); float eGGun2Y2=(55); float eGGun3Y2=(55); float eGGun4Y2=(60); float eGGun5X2=(200); float eGGun6X2=(210); float eGGun7X2=(230); float eGGun8X2=(240); float eGGun5Y2=(80); float eGGun6Y2=(75); float eGGun7Y2=(75); float eGGun8Y2=(80); float eGGun9X2=(50); float eGGun10X2=(60); float eGGun11X2=(80); float eGGun12X2=(90); float eGGun9Y2=(60); float eGGun10Y2=(55); float eGGun11Y2=(55); float eGGun12Y2=(60); float eBulletSpeed1= 0; float eBulletSpeed2= 0; float eBulletSpeed3= 0; float eBulletSpeed4= 0; float eBulletSpeed5= 0; float eBulletSpeed6= 0; float eBulletSpeed7= 0; float eBulletSpeed8= 0; float eBulletSpeed9= 0; float eBulletSpeed10= 0; float eBulletSpeed11= 0; float eBulletSpeed12= 0; float eBulletSpeed21= 0; float eBulletSpeed22= 0; float eBulletSpeed23= 0; float eBulletSpeed24= 0; float eBulletSpeed25= 0; float eBulletSpeed26= 0; float eBulletSpeed27= 0; float eBulletSpeed28= 0; float eBulletSpeed29= 0; float eBulletSpeed210= 0; float eBulletSpeed211= 0; float eBulletSpeed212= 0; boolean keyUp = false; boolean keyLeft = false; boolean keyDown = false; boolean keyRight = false; boolean bomb = false; boolean startable=false; boolean shoot = false; boolean shoot1= false; boolean shoot2 = false; boolean shoot3 = false; boolean shoot4 = false; boolean shoot5 = false; boolean shipSpawn = false; boolean backGroundSpawn = false; boolean uiSpawn = false; boolean start = false; boolean show = false; boolean explode = false; boolean timeStart = false; boolean timeStart2 = false; boolean bomb1 = true; boolean bomb2 = true; boolean bomb3 = true; boolean bomb4 = true; boolean bomb5 = true; boolean eShipSpawn = false; boolean eShip=false; boolean eShip2=false; boolean explosion = false; //set 1 boolean eBulletG1= false; boolean eBullet2G1= false; boolean eBullet3G1= false; boolean eBullet4G1= false; //set 2 boolean eBullet5G1= false; boolean eBullet6G1= false; boolean eBullet7G1= false; boolean eBullet8G1= false; //set 3 boolean eBullet9G1= false; boolean eBullet10G1= false; boolean eBullet11G1= false; boolean eBullet12G1= false; //set 4 boolean eBulletG2= false; boolean eBullet2G2= false; boolean eBullet3G2= false; boolean eBullet4G2= false; //set 5 boolean eBullet5G2= false; boolean eBullet6G2= false; boolean eBullet7G2= false; boolean eBullet8G2= false; //set 6 boolean eBullet9G2= false; boolean eBullet10G2= false; boolean eBullet11G2= false; boolean eBullet12G2= false; boolean gameOver= false; boolean hit=false; boolean health10= true; boolean health9= true; boolean health8= true; boolean health7= true; boolean health6= true; boolean health5= true; boolean health4= true; boolean health3= true; boolean health2= true; boolean health1= true; boolean health0= true; void setup() { //define window size size(400, 400); //set to 60fps frameRate(60); //remove cursor noCursor(); //set time points timeinterval= 2000;// 2 sec timeinterval2= 5000;// 5 sec rectMode (CENTER); } void draw() { //start the game and load components if (startable == true) { bootSequence(); backGround(); playerJet(); enemyBulletG(); enemyShipG(); enemyShipG2(); ui(); hitBoxes(); bombDetonate(); colourchange(); pointSystem(); } else { titleScreen(); }//if player looses health game over if (startable ==true && gameOver==true) { gameOverScreen(); } } //Player ship void playerJet() { if (shipSpawn == true) { //////ship///////// if (shipSpawn == true && shipCenterY > 300) { shipCenterY=shipCenterY-2; } shipMovement(); shooting(); bombs(); //ship front fill(230); stroke(158); strokeWeight(1); triangle(shipCenterX, shipCenterY-15, shipCenterX-6, shipCenterY, shipCenterX+6, shipCenterY); fill(1); triangle(shipCenterX, shipCenterY+8, shipCenterX-6, shipCenterY, shipCenterX+6, shipCenterY); fill(221); stroke(79); strokeWeight(1); triangle(shipCenterX, shipCenterY-8, shipCenterX-5, shipCenterY+5, shipCenterX+5, shipCenterY+5); fill(80); triangle(shipCenterX, shipCenterY+15, shipCenterX-5, shipCenterY+5, shipCenterX+5, shipCenterY+5); noStroke(); fill(230); triangle(shipCenterX, shipCenterY+6, shipCenterX-2, shipCenterY+10, shipCenterX+2, shipCenterY+10); //ship wings fill(160); stroke(60); triangle(shipCenterX-18, shipCenterY+30, shipCenterX-5, shipCenterY+12, shipCenterX-1, shipCenterY+14); triangle(shipCenterX+18, shipCenterY+30, shipCenterX+1, shipCenterY+14, shipCenterX+5, shipCenterY+12); fill(240); triangle(shipCenterX-25, shipCenterY+25, shipCenterX-5, shipCenterY+6, shipCenterX-1, shipCenterY+9); triangle(shipCenterX+25, shipCenterY+25, shipCenterX+1, shipCenterY+9, shipCenterX+5, shipCenterY+6); noStroke(); fill(240); noStroke(); rect(shipCenterX, shipCenterY+9, 9, 4); stroke(40); fill(60); rect(shipCenterX, shipCenterY+18, 8, 3); //central booster fill(255, 230, 230); ellipse(shipCenterX, shipCenterY+20, 10, 3); noStroke(); fill(255, 255, 255, 150+cos(millis()/20)*20); ellipse(shipCenterX, shipCenterY+22, 13, 5); //ship cockpit stroke(40); fill(255, 0, 140); ellipse(shipCenterX, shipCenterY-2, 4, 6); //ship boosters quad(shipCenterX-19, shipCenterY+20, shipCenterX-25, shipCenterY+25, shipCenterX-19, shipCenterY+29, shipCenterX-16, shipCenterY+28); quad(shipCenterX+19, shipCenterY+20, shipCenterX+25, shipCenterY+25, shipCenterX+19, shipCenterY+29, shipCenterX+16, shipCenterY+28); fill(255, 220, 255); quad(shipCenterX-20, shipCenterY+23, shipCenterX-24, shipCenterY+25, shipCenterX-19, shipCenterY+28, shipCenterX-16, shipCenterY+28); quad(shipCenterX+20, shipCenterY+23, shipCenterX+24, shipCenterY+25, shipCenterX+19, shipCenterY+28, shipCenterX+16, shipCenterY+28); //thusters strokeCap(ROUND); stroke(234, 1, 255, 80); strokeWeight(6+cos(millis()/20)*.5); line(shipCenterX-21, shipCenterY+27, shipCenterX-21, shipCenterY+2+cos(millis()/80)*8+ 250); line(shipCenterX+21, shipCenterY+27, shipCenterX+21, shipCenterY+2+cos(millis()/80)*8+ 250); stroke(234, 150, 255, 100); strokeWeight(3+cos(millis()/20)*.5); line(shipCenterX-21, shipCenterY+27, shipCenterX-21, shipCenterY+2+cos(millis()/80)*8+ 300); line(shipCenterX+21, shipCenterY+27, shipCenterX+21, shipCenterY+2+cos(millis()/80)*8+ 300); strokeWeight(4+cos(millis()/20)*.5); stroke(252, 34, 202, 50); line(shipCenterX, shipCenterY+23, shipCenterX, shipCenterY+2+cos(millis()/80)*8+ 415); strokeWeight(4.5+cos(millis()/20)*.5); stroke(252, 40, 242, 60); line(shipCenterX, shipCenterY+23, shipCenterX, shipCenterY+2+cos(millis()/70)*8+ 345); strokeWeight(5+cos(millis()/20)*.5); stroke(255, 100, 242, 70); line(shipCenterX, shipCenterY+23, shipCenterX, shipCenterY+2+cos(millis()/70)*6+ 295); strokeWeight(5.5+cos(millis()/20)*.5); stroke(255, 150, 242, 80); line(shipCenterX, shipCenterY+23, shipCenterX, shipCenterY+2+cos(millis()/60)*5+ 185); strokeWeight(6+cos(millis()/20)*.5); stroke(255, 200, 242, 90); line(shipCenterX, shipCenterY+23, shipCenterX, shipCenterY+2+cos(millis()/50)*4+ 115); strokeWeight(6.5+cos(millis()/20)*.5); stroke(255, 240, 242, 100); line(shipCenterX, shipCenterY+23, shipCenterX, shipCenterY+2+cos(millis()/40)*3+ 55); strokeWeight(7+cos(millis()/20)*.5); stroke(255, 250, 252, 150); line(shipCenterX, shipCenterY+23, shipCenterX, shipCenterY+2+cos(millis()/30)*2+ 35); fill(255); } } //ship movement void shipMovement() { if (keyUp ==false) { shipCenterY = shipCenterY+0; bulletCenterY = bulletCenterY+0; } else shipCenterY = shipCenterY-5; bulletCenterY = bulletCenterY-5; if (keyDown ==false) { shipCenterY = shipCenterY+0; } else shipCenterY = shipCenterY+5; if (keyLeft ==false) { shipCenterX = shipCenterX+0; } else shipCenterX = shipCenterX-5; if (keyRight ==false) { shipCenterX = shipCenterX+0; } else shipCenterX = shipCenterX+5; //ship constraints if (shipCenterY < 20) { shipCenterY = 20; } if (shipCenterY > 360) { shipCenterY = 360; } if (shipCenterX > 370 ) { shipCenterX = 370; } if (shipCenterX <30) { shipCenterX = 30; } if (shipSpawn== true) { } } //bomb void bombs () { //check if bomb can be launched, if yes, launch if (bomb1 == true &&bomb==true&&timeScore == 0) { bomb1=false; colourchange(); explode=true; timeScore=1; } //resets after 2 seconds if (millis() > lasttimecheck + timeinterval ) { ammo=4; //4 second cooldown so player cant spam bombs if (millis() > lasttimecheck + timeinterval2 ) { timeScore=0; } } //bomb 2 if (bomb1==false&&bomb2==true && bomb == true&&timeScore == 0) { bomb2=false; colourchange(); explode=true; timeScore=1; } if (millis() > lasttimecheck + timeinterval ) { ammo=3; if (millis() > lasttimecheck + timeinterval2 ) { timeScore=0; } //bomb3 if ((bomb1==false&&bomb2==false&&bomb3==true && bomb == true&&timeScore == 0)) { bomb3=false; colourchange(); explode=true; timeScore=1; } if (millis() > lasttimecheck + timeinterval ) { ammo=2; if (millis() > lasttimecheck + timeinterval2 ) { timeScore=0; } //bomb 4 if ((bomb1==false&&bomb2==false&&bomb3==false&&bomb4==true && bomb == true&&timeScore == 0)) { bomb4=false; colourchange(); explode=true; timeScore=1; } if (millis() > lasttimecheck + timeinterval ) { ammo=1; if (millis() > lasttimecheck + timeinterval2 ) { timeScore=0; } //bomb 5 if ((bomb1==false&&bomb2==false&&bomb3==false&&bomb4==false&&bomb5==true && bomb == true&&timeScore == 0)) { bomb5=false; colourchange(); explode=true; timeScore=1; } if (millis() > lasttimecheck + timeinterval ) { ammo=0; if (millis() > lasttimecheck + timeinterval2 ) { timeScore=0; } //disable bombs if ammo = 0 if ((bomb1==false&&bomb2==false&&bomb3==false&&bomb4==false&&bomb5==false && bomb == true&&timeScore == 0)) { bomb5=false; explode=false; timeScore=1; } } } } } } //background void backGround() { if (backGroundSpawn == true) { //lines background(backR, backG, backB); strokeWeight(2+cos(millis()*1/100)); stroke(efR, efG, efB); line(80, height-400, 25, height+20); line(320, height-400, 375, height+20); star(); light(); } } void points() { //display score fill(255); textSize(20); text("score: ", 10, 20); text(score, 70, 21); } //create stars void star() { loop(); noStroke(); //random colour variables fill(sR, sG, sB, 190); //draw stars at random locations and speeds ellipse(-50+rWidth, -rHeight-rHeight+(frameCount*r%1000), rSize, rSize+cos(millis()/45)*10); ellipse(-50+rWidth2, -rWidth2-rHeight+(frameCount*r2%1000), rSize2, rSize3+cos(millis()/45)*10); ellipse(0+rWidth3, -rWidth15-rHeight+(frameCount*r3%1000), rSize3, rSize4+cos(millis()/45)*10); ellipse(-50+rWidth4, -200-rHeight+(frameCount*r4%1000), rSize4, rSize2+cos(millis()/45)*10); ellipse(0+rWidth5, -200-rHeight+(frameCount*r5%1000), rSize, rSize2+cos(millis()/45)*10); ellipse(-50+rWidth6, -200-rHeight+(frameCount*r6%1000), rSize5, rSize+cos(millis()/45)*10); ellipse(0+rWidth7, -200-rHeight+(frameCount*r7%1000), rSize3, rSize7+cos(millis()/45)*10); ellipse(-50+rWidth8, -rWidth2-rHeight+(frameCount*r8%1000), rSize4, rSize+cos(millis()/45)*10); ellipse(0+rWidth12, -200-rHeight+(frameCount*r%1000), rSize, rSize+cos(millis()/45)*10); ellipse(-50+rWidth13, -rWidth15-rHeight+(frameCount*r12%1000), rSize6, rSize6+cos(millis()/45)*10); ellipse(0+rWidth14, -200-rHeight+(frameCount*r13%1000), rSize5, rSize4+cos(millis()/45)*10); ellipse(-50+rWidth15, -200-rHeight+(frameCount*r14%1000), rSize7, rSize5+cos(millis()/45)*10); ellipse(0+rWidth16, -200-rHeight+(frameCount*r15%1000), rSize2, rSize2+cos(millis()/45)*10); ellipse(-50+rWidth17, -200-rHeight+(frameCount*r16%1000), rSize6, rSize4+cos(millis()/5)*10); ellipse(0+rWidth18, -rWidth2-rHeight+(frameCount*r17%1000), rSize, rSize+cos(millis()/45)*10); ellipse(0+rWidth19, -200-rHeight+(frameCount*r18%1000), rSize4, rSize7+cos(millis()/45)*10); ellipse(0+rWidth, -rHeight-rHeight+(frameCount*r%1000), rSize, rSize+cos(millis()/45)*10); ellipse(0+rWidth2, -200-rHeight+(frameCount*r12%1000), rSize2, rSize3+cos(millis()/45)*10); ellipse(0+rWidth3, -200-rHeight+(frameCount*r13%1000), rSize3, rSize4+cos(millis()/45)*10); ellipse(50+rWidth16, -rWidth2-rHeight+(frameCount*r14%1000), rSize4, rSize2+cos(millis()/45)*10); ellipse(0+rWidth5, -200-rHeight+(frameCount*r5%1000), rSize, rSize2+cos(millis()/45)*10); ellipse(0+rWidth6, -rWidth15-rHeight+(frameCount*r6%1000), rSize5, rSize+cos(millis()/45)*10); ellipse(0+rWidth7, -200-rHeight+(frameCount*r7%1000), rSize3, rSize7+cos(millis()/45)*10); ellipse(-50+rWidth8, -200-rHeight+(frameCount*r8%1000), rSize4, rSize+cos(millis()/45)*10); ellipse(0+rWidth12, -rWidth2-rHeight+(frameCount*r%1000), rSize, rSize+cos(millis()/45)*10); ellipse(-50+rWidth13, -rWidth15-rHeight+(frameCount*r2%1000), rSize6, rSize6+cos(millis()/45)*10); ellipse(0+rWidth14, -200-rHeight+(frameCount*r3%1000), rSize5, rSize4+cos(millis()/45)*10); ellipse(-50+rWidth15, -rWidth2-rHeight+(frameCount*r4%1000), rSize7, rSize5+cos(millis()/45)*10); ellipse(0+rWidth16, -200-rHeight+(frameCount*r5%1000), rSize2, rSize2+cos(millis()/45)*10); ellipse(-50+rWidth17, -200-rHeight+(frameCount*r6%1000), rSize6, rSize4+cos(millis()/5)*10); ellipse(0+rWidth18, -rWidth15-rHeight+(frameCount*r17%1000), rSize, rSize+cos(millis()/45)*10); ellipse(0+rWidth19, -rWidth2-rHeight+(frameCount*r8%1000), rSize4, rSize7+cos(millis()/45)*10); } //check if keys pressed void keyPressed() { if (key == 'w') { keyUp = true; println("w"); } else if (key == 's') { println("s"); keyDown = true; } else if (key =='a') { keyLeft=true; println("a"); } else if (key =='d') { keyRight = true; println("d"); } else if (keyCode== ' '|keyCode== ' ') { bomb = true; println("boom"); } else if (key =='p') { startable = true; } } //check if key released void keyReleased() { if (key == 'w') { keyUp = false; println("w"); } else if (key == 's') { println("s"); keyDown = false; } else if (key =='a') { keyLeft=false; println("a"); } else if (key =='d') { keyRight = false; println("d"); } else if (keyCode== ' '|keyCode== ' ') { bomb = false; println("boom"); } else if (key =='p') { } } //player shooting void shooting() { //check if mouse pressed if (mousePressed== true) { shoot = true; } if (shoot==true) { bullet1(); } if (shoot ==true&&shoot2==true) { bullet2(); } if (shoot ==true&&shoot2==true&&shoot3==true) { bullet3(); } if (shoot ==true&&shoot2==true&&shoot3==true&&shoot4==true) { bullet4(); } if (shoot ==true&&shoot2==true&&shoot3==true&&shoot4==true&&shoot5==true) { bullet5(); } } //startup command void bootSequence() { if (start == false) { start= true; backGroundSpawn=true; shipSpawn=true; uiSpawn=true; eShip = true; eShip2 = true; } else { titleScreen(); } } //bullets call on eachother so there is a delay void bullet1() { //check if clicked if (shoot== true) { //activate second bullet shoot2= true; bullet2(); bulletSpeed1=bulletSpeed1+25; strokeWeight(2); stroke(255, 120, 255); fill(255, 255, 255); ellipse(shipCenterX, shipCenterY-bulletSpeed1, 2, 15); if ( bulletSpeed1 >= 400) { shoot= false; bulletSpeed1=0; } } } void bullet2() { if (shoot==true&&shoot2==true) { shoot3=true; bullet3(); bulletSpeed2=bulletSpeed2+24; strokeWeight(2); stroke(255, 160, 255); fill(255, 255, 255); ellipse(shipCenterX+3, shipCenterY+1-bulletSpeed2, 2, 15); if (shoot == true & bulletSpeed2 >= 400) { shoot2= false; bulletSpeed2=0; } } } void bullet3() { if ( shoot3==true) { shoot4=true; bulletSpeed3=bulletSpeed3+23; noStroke(); fill(240, 240, 255, 120); ellipse(shipCenterX, shipCenterY-15, 10+cos(millis()/10)*5, 10+cos(millis()/10)*5); strokeWeight(2); stroke(255, 160, 255); fill(255, 255, 255); ellipse(shipCenterX-3, shipCenterY+2-bulletSpeed3, 2, 15); if (bulletSpeed3 >= 400) { shoot3= false; bulletSpeed3=0; } } } void bullet4() { if ( shoot4==true) { shoot5=true; bulletSpeed4=bulletSpeed4+22; strokeWeight(2); stroke(255, 160, 255); fill(255, 255, 255); ellipse(shipCenterX-3, shipCenterY+2-bulletSpeed4, 2, 15); if (bulletSpeed3 >= 400) { shoot4= false; bulletSpeed4=0; } } } void bullet5() { if ( shoot5==true) { bulletSpeed5=bulletSpeed5+21; strokeWeight(2); stroke(255, 160, 255); fill(255, 255, 255); ellipse(shipCenterX-3, shipCenterY+2-bulletSpeed5, 2, 15); if (bulletSpeed3 >= 400) { shoot5= false; bulletSpeed5=0; } } } //background lights void light() { //light effects for background fill(efR, efG, efB, 80+cos(millis()/50)*5); ellipse(200, 550, 380+cos(millis()/100)*10, 380+cos(millis()/100)*10); ellipse(200, 500, 362+cos(millis()/100)*10, 362+cos(millis()/100)*10); ellipse(200, 450, 345+cos(millis()/100)*10, 345+cos(millis()/100)*10); ellipse(200, 400, 335+cos(millis()/100)*10, 335+cos(millis()/100)*10); ellipse(200, 350, 315+cos(millis()/100)*10, 315+cos(millis()/100)*10); ellipse(200, 300, 305+cos(millis()/100)*10, 305+cos(millis()/100)*10); ellipse(200, 250, 290+cos(millis()/100)*10, 290+cos(millis()/100)*10); ellipse(200, 200, 280+cos(millis()/100)*10, 280+cos(millis()/100)*10); ellipse(200, 150, 270+cos(millis()/100)*10, 270+cos(millis()/100)*10); ellipse(200, 100, 255+cos(millis()/100)*10, 255+cos(millis()/100)*10); ellipse(200, 50, 245+cos(millis()/100)*10, 245+cos(millis()/100)*10); ellipse(200, 0, 235+cos(millis()/100)*10, 235+cos(millis()/100)*10); } //UI void ui() { //spawn ui components if (uiSpawn==true) { bombCount(); points(); healthBar(); } } //Title Screeen void titleScreen() { if (startable==false) { //background background(0); int x = 195; int spacing = 20; int len = 20; while (x<=1000 ) { fill(55, 0, 55, 10+len); rect(200, x-len, x+len, x+len); x=x+spacing; } noStroke(); fill(122, 0, 220, 70); //ellipse(width/2, height/2, 10, 10); //print START stroke(225, 200, 255, 100+cos(millis()/100)*10); //S strokeWeight(6); strokeCap(SQUARE); line(100, 100, 120, 100); line(97, 103, 97, 125); line(100, 127, 120, 127); line(123, 150, 123, 130); line(100, 153, 120, 153); noStroke(); fill(225, 200, 255, 100+cos(millis()/100)*10); rect(97, 147, 6, 6); rect(124, 107, 6, 6); //T rect(150, 100, 36, 6); rect(150, 130, 6, 54); //A rect(194, 100, 20, 6); rect(181, 130, 6, 54); rect(207, 130, 6, 54); rect(194, 127, 20, 6); //R rect(225, 127, 6, 60); rect(238, 100, 20, 6); rect(251, 113, 6, 20); rect(238, 127, 20, 6); rect(245, 137, 6, 14); rect(251, 150, 6, 14); //T rect(280, 100, 36, 6); rect(280, 130, 6, 54); //print Press P fill(255, 255, 255, 150+cos(millis()/100)*10); rect(195, 200, 40, 40, 7); fill(0, 0, 0); rect(189, 200, 3, 25); rect(195, 189, 10, 3); rect(202, 196, 3, 10); rect(195, 202, 10, 3); //show control keys fill(255); //score textSize(20); text("score: ", 10, 20); text(score, 70, 21); //highScore textSize(20); text("high-Score: ", 200, 20); text(highScore, 340, 21); fill(255); textSize(20); text("Movement", 45, 280); fill(255); textSize(10); text("W", 95, 300); //W fill(255, 255, 255, 100+cos(millis()/150)*15); rect(95, 300, 20, 20, 4); fill(0); fill(255); textSize(10); text("D", 120, 322); //D fill(255, 255, 255, 100+cos(millis()/150)*15); rect(120, 322, 20, 20, 4); fill(255); textSize(10); text("S", 97, 322); //S fill(255, 255, 255, 100+cos(millis()/150)*15); rect(95, 322, 20, 20, 4); fill(255); textSize(10); text("A", 70, 322); //A fill(255, 255, 255, 100+cos(millis()/150)*15); rect(70, 322, 20, 20, 4); fill(255); textSize(15); text("launch bomb", 46, 360); fill(255); textSize(10); text("SpaceBar", 75, 378); //spaceBar fill(255, 255, 255, 100+cos(millis()/150)*15); rect(95, 375, 120, 20, 4); fill(255); textSize(9); text("(5 sec cooldown)", 60, 394); //mouse fill(255); textSize(15); text("Shoot", 277, 280); fill(100+cos(millis()/150)*15); ellipse(300, 320, 40, 60); rect(300, 330, 40, 40, 30); fill(0); rect(300, 310, 4, 15, 70); } } //change backdrop colours on bomb for effect void colourchange() { if (bomb == true&&timeScore == 0) { lasttimecheck=(millis()); backR = (255); backG = (255); backB = (255); efR=(255); efG=(200); efB=(100); sR =(0); sG =(0); sB =(0); explode=true; } //reset to original colours after 2 seconds if (millis() > lasttimecheck + timeinterval ) { backR= (5); backG=(0); backB=(20); efR=(80); efG=(180); efB=(200); sR =(255); sG =(255); sB =(255); timeScore=1; explode=false; } if (millis() > lasttimecheck + timeinterval2 ) { timeScore=0; } } //display bomb count UI void bombCount () { if (bomb1==true) { strokeWeight(1); stroke(102, 51, 0); fill(255, 102, 0, bombVisibility1); ellipse(20, 230, 15, 15); } if (bomb2==true) { strokeWeight(1); stroke(102, 51, 0); fill(255, 102, 0, bombVisibility2); ellipse(31, 241, 15, 15); } if (bomb3==true) { strokeWeight(1); stroke(102, 51, 0); fill(255, 102, 0); ellipse(20, 252, 15, 15); } if (bomb4==true) { strokeWeight(1); stroke(102, 51, 0); fill(255, 102, 0); ellipse(31, 263, 15, 15); } if (bomb5==true) { strokeWeight(1); stroke(102, 51, 0); fill(255, 102, 0); ellipse(20, 274, 15, 15); } //replace bomb icons with transparent version if (bomb1==false) { strokeWeight(1); stroke(102, 51, 0); fill(255, 102, 0, bombVisibility1); ellipse(20, 230, 15, 15); bombVisibility1=40; } if (bomb2==false) { strokeWeight(1); stroke(102, 51, 0); fill(255, 102, 0, bombVisibility2); ellipse(31, 241, 15, 15); bombVisibility2=40; } if (bomb3==false) { strokeWeight(1); stroke(102, 51, 0); fill(255, 102, 0, bombVisibility3); ellipse(20, 252, 15, 15); bombVisibility3=40; } if (bomb4==false) { strokeWeight(1); stroke(102, 51, 0); fill(255, 102, 0, bombVisibility4); ellipse(31, 263, 15, 15); bombVisibility4=40; } if (bomb5==false) { strokeWeight(1); stroke(102, 51, 0); fill(255, 102, 0, bombVisibility5); ellipse(20, 274, 15, 15); bombVisibility5=40; } } //destroys all enemies on-screen if bomb is available void bombDetonate() { if (explode == true) { shipVisibility= 0; shipVisibility2 =0; if (shipVisibility== 0) { score=score+200 ; } if (shipVisibility2== 0) { score=score+200 ; } // animates explosion strokeWeight(5); stroke(255, 220, 255, 200+cos(millis()/100)*10); fill(0, 0, 0, 0); ellipse(width/2, height/2, 50+((frameCount)*5.5%800)+cos(millis()/100)*10, 0+((frameCount)*5.5%800)+cos(millis()/100)*10); fill(0, 0, 0, 60); strokeWeight(2); ellipse(width/2, height/2, 50+((frameCount)*5.5%800)+cos(millis()/100)*10, 50+((frameCount)*5.5%800)+cos(millis()/100)*10); if (millis() > lasttimecheck + timeinterval2 ) { explode = false; } } } //green enemy ship void enemyShipG() { if (eShip == true) { if (enemyHealth1==0&&timeScore == 0) { lasttimecheck=(millis()); explotionVisibility1=255; shipVisibility = 0; score=score+100; } if (millis() > lasttimecheck + timeinterval ) { explotionVisibility1=0; } if (millis() > lasttimecheck + timeinterval2 ) { timeScore=0; } //explotion effect(hidden) noFill(); strokeWeight(8+cos(millis()/20*50)); stroke(255, 102, 0, explotionVisibility1+cos(millis()/20*50)); ellipse(eShipX, eShipY, 3+(frameCount*5%50), 3+(frameCount*5%50)); //rockets noStroke(); fill(51, 204, 204, shipVisibility); triangle(eShipX+cos(millis()/40*400), eShipY-50+cos(millis()/40*500), eShipX-7, eShipY-25, eShipX+7, eShipY-25); //engine strokeWeight(1); stroke(0, 0, 0, shipVisibility); fill(22, 22, 22, shipVisibility); rect(eShipX, eShipY-18, 15, 20); //front wings quad(eShipX, eShipY, eShipX+7, eShipY-11, eShipX+26, eShipY+5, eShipX+23, eShipY+12); quad(eShipX, eShipY, eShipX-7, eShipY-11, eShipX-26, eShipY+5, eShipX-23, eShipY+12); fill(0, 102, 102, shipVisibility); triangle(eShipX+23, eShipY+12, eShipX+26, eShipY+5, eShipX+38, eShipY); triangle(eShipX-23, eShipY+12, eShipX-26, eShipY+5, eShipX-38, eShipY); //nose fill(22, 22, 22, shipVisibility); triangle(eShipX, eShipY+23, eShipX+8, eShipY-5, eShipX-8, eShipY-5); //back wings triangle(eShipX, eShipY+8, eShipX-25, eShipY-30, eShipX, eShipY-20); triangle(eShipX, eShipY+8, eShipX+25, eShipY-30, eShipX, eShipY-20); stroke(0, 51, 0, shipVisibility); fill(0, 102, 102, shipVisibility); triangle(eShipX, eShipY, eShipX-25, eShipY-30, eShipX, eShipY-20); triangle(eShipX, eShipY, eShipX+25, eShipY-30, eShipX, eShipY-20); //cockpit stroke(0, 0, 0, shipVisibility); fill(5, 5, 5, shipVisibility); ellipse(eShipX, eShipY-10, 10, 20); fill(200, 200, 200, shipVisibility); ellipse(eShipX+2, eShipY-10, 2, 10); //guns fill(5, 5, 5, shipVisibility); rect(eShipX-20, eShipY+10, 3, 8); rect(eShipX-10, eShipY+6, 3, 8); rect(eShipX+20, eShipY+10, 3, 8); rect(eShipX+10, eShipY+6, 3, 8); } //if ship is off screen, move down till its on screen if (eShip == true && eShipY< 100 && eShipX >200) { eShipY= eShipY +2; eShip2=true; } //if ship reaches top right of the screen move left in a parabale if (eShipY>20 && eShipX > 30) { eShipY=-0.0012345679*(eShipX-20)*(eShipX-380)+30; eShipX= eShipX-1; }//move ship back out of screen if (eShipY > -120 && eShipX <100) { eShipY= eShipY-2; } //reset ship location and visibility if destroyed if (eShipY<= -100 && eShipX < 40) { eShipY=-200; eShipX=380; shipVisibility=255; explotionVisibility1=0; enemyHealth1=100; } if (explode==true) { explotionVisibility1=255; shipVisibility=0; } if (explode==false) { explotionVisibility1=0; } //enemy bullet launch zones //set1 if (eShipX <=320 && eShipY>=10) { eBulletG1= true; eBullet2G1= true; eBullet3G1= true; eBullet4G1= true; } else { eBulletG1= false; eBullet2G1= false; eBullet3G1= false; eBullet4G1= false; } //set 2 if (eShipX <=200 && eShipY>=10) { eBullet5G1= true; eBullet6G1= true; eBullet7G1= true; eBullet8G1= true; } else { eBullet5G1= false; eBullet6G1= false; eBullet7G1= false; eBullet8G1= false; } //set 3 if (eShipX <=50 && eShipY>=-100) { eBullet9G1= true; eBullet10G1= true; eBullet11G1= true; eBullet12G1= true; } else { eBullet9G1= false; eBullet10G1= false; eBullet11G1= false; eBullet12G1= false; } } //green enemy ship #2 void enemyShipG2() { if (eShip2 == true) { if (enemyHealth2<=0&&timeScore == 0) { lasttimecheck=(millis()); explotionVisibility2=255; shipVisibility2 = 0; //give score if destroyed score=score+100; } if (millis() > lasttimecheck + timeinterval ) { //hide explotions after 2 seconds explotionVisibility2=0; } if (millis() > lasttimecheck + timeinterval2 ) { //reset timeScore=0; explotionVisibility2=0; } //explotion effect(hidden) noFill(); strokeWeight(8+cos(millis()/20*50)); stroke(255, 102, 0, explotionVisibility2+cos(millis()/20*50)); ellipse(eShipX2, eShipY2, 3+(frameCount*5%50), 3+(frameCount*5%50)); //rockets noStroke(); fill(51, 204, 204, shipVisibility2); triangle(eShipX2+cos(millis()/40*400), eShipY2-50+cos(millis()/40*500), eShipX2-7, eShipY2-25, eShipX2+7, eShipY2-25); //engine strokeWeight(1); stroke(0, 0, 0, shipVisibility2); fill(22, 22, 22, shipVisibility2); rect(eShipX2, eShipY2-18, 15, 20, shipVisibility2); //front wings quad(eShipX2, eShipY2, eShipX2+7, eShipY2-11, eShipX2+26, eShipY2+5, eShipX2+23, eShipY2+12); quad(eShipX2, eShipY2, eShipX2-7, eShipY2-11, eShipX2-26, eShipY2+5, eShipX2-23, eShipY2+12); fill(0, 102, 102, shipVisibility2); triangle(eShipX2+23, eShipY2+12, eShipX2+26, eShipY2+5, eShipX2+38, eShipY2); triangle(eShipX2-23, eShipY2+12, eShipX2-26, eShipY2+5, eShipX2-38, eShipY2); //nose fill(22, 22, 22, shipVisibility2); triangle(eShipX2, eShipY2+23, eShipX2+8, eShipY2-5, eShipX2-8, eShipY2-5); //back wings triangle(eShipX2, eShipY2+8, eShipX2-25, eShipY2-30, eShipX2, eShipY2-20); triangle(eShipX2, eShipY2+8, eShipX2+25, eShipY2-30, eShipX2, eShipY2-20); stroke(0, 51, 0, shipVisibility2); fill(0, 102, 102, shipVisibility2); triangle(eShipX2, eShipY2, eShipX2-25, eShipY2-30, eShipX2, eShipY2-20); triangle(eShipX2, eShipY2, eShipX2+25, eShipY2-30, eShipX2, eShipY2-20); //cockpit stroke(0, 0, 0, shipVisibility2); fill(5, 5, 5, shipVisibility2); ellipse(eShipX2, eShipY2-10, 10, 20); fill(200, 200, 200, shipVisibility2); ellipse(eShipX2+2, eShipY2-10, 2, 10); //guns fill(5, 5, 5, shipVisibility2); rect(eShipX2-20, eShipY2+10, 3, 8); rect(eShipX2-10, eShipY2+6, 3, 8); rect(eShipX2+20, eShipY2+10, 3, 8); rect(eShipX2+10, eShipY2+6, 3, 8); } if (eShipY2< 100 && eShipX2 >200) { eShipY2= eShipY2 +2; } if (eShipY2>20 && eShipX2 > 30) { eShipY2=-0.0012345679*(eShipX2-20)*(eShipX2-380)+30; eShipX2= eShipX2-1; } if (eShipY2 > -200 && eShipX2 <100) { eShipY2= eShipY2-2; } if (eShipY2<= -150 && eShipX2 < 40) { eShipY2=-600; eShipX2=380; shipVisibility2=255; explotionVisibility2=0; enemyHealth2=100; } //check if bomb launched if (explode==true) { //if true ship dissapears and explotion effect appears intead shipVisibility2=0; explotionVisibility2=255; } if (explode==false) { explotionVisibility2=0; } //enemy bullet launch zones //set1 if (eShipX2 <=320 && eShipY2>=10) { eBulletG2= true; eBullet2G2= true; eBullet3G2= true; eBullet4G2= true; } else { eBulletG2= false; eBullet2G2= false; eBullet3G2= false; eBullet4G2= false; } //set 2 if (eShipX2 <=200 && eShipY2>=10) { eBullet5G2= true; eBullet6G2= true; eBullet7G2= true; eBullet8G2= true; } else { eBullet5G2= false; eBullet6G2= false; eBullet7G2= false; eBullet8G2= false; } //set 3 if (eShipX2 <=50 && eShipY2>=-100) { eBullet9G2= true; eBullet10G2= true; eBullet11G2= true; eBullet12G2= true; } else { eBullet9G2= false; eBullet10G2= false; eBullet11G2= false; eBullet12G2= false; } } //reset ship position if they go off screen void respawnEShip() { if (shipVisibility == 0 &&shipVisibility2 == 0 && bomb == false) { eShipY2=-600; eShipX2=380; eShipY=-200; eShipX=380; shipVisibility = 255; shipVisibility2 = 255; eShip = true; } } //green ship bullets void enemyBulletG() { if (hit==true) { }//if ship is in launching zone, shoot bullet set1 if (eBulletG1==true&&eBullet2G1==true&&eBullet3G1==true&&eBullet4G1==true&&shipVisibility==255) { eBulletSpeed1=eBulletSpeed1+5; eBulletSpeed2=eBulletSpeed2+5; eBulletSpeed3=eBulletSpeed3+5; eBulletSpeed4=eBulletSpeed4+5; strokeWeight(3); stroke(0, 255, 0); fill(255, 255, 255); ellipse(eGGun1X-20, eGGun1Y+eBulletSpeed1, 2, 5+cos(millis()/4*50)); ellipse(eGGun2X-20, eGGun2Y+eBulletSpeed2, 2, 5+cos(millis()/4*50)); ellipse(eGGun3X-20, eGGun3Y+eBulletSpeed3, 2, 5+cos(millis()/4*50)); ellipse(eGGun4X-20, eGGun4Y+eBulletSpeed4, 2, 5+cos(millis()/4*50)); } else if (eBulletG1==false&&eBullet2G1==false&&eBullet3G1==false&&eBullet4G1==false&&shipVisibility==255) { eBulletSpeed1=0; eBulletSpeed2=0; eBulletSpeed3=0; eBulletSpeed4=0; } //if ship is in launching zone, shoot bullet set 2 if (eBullet5G1==true&&eBullet6G1==true&&eBullet7G1==true&&eBullet8G1==true&&shipVisibility==255) { eBulletSpeed5=eBulletSpeed5+5; eBulletSpeed6=eBulletSpeed6+5; eBulletSpeed7=eBulletSpeed7+5; eBulletSpeed8=eBulletSpeed8+5; strokeWeight(3); stroke(0, 255, 0); fill(255, 255, 255); ellipse(eGGun5X-20, eGGun5Y+eBulletSpeed5, 2, 5+cos(millis()/4*50)); ellipse(eGGun6X-20, eGGun6Y+eBulletSpeed6, 2, 5+cos(millis()/4*50)); ellipse(eGGun7X-20, eGGun7Y+eBulletSpeed7, 2, 5+cos(millis()/4*50)); ellipse(eGGun8X-20, eGGun8Y+eBulletSpeed8, 2, 5+cos(millis()/4*50)); } else if (eBullet5G1==false&&eBullet6G1==false&&eBullet7G1==false&&eBullet8G1==false&&shipVisibility==255) { eBulletSpeed5=0; eBulletSpeed6=0; eBulletSpeed7=0; eBulletSpeed8=0; } //if ship is in launching zone, shoot bullet set3 if (eBullet9G1==true&&eBullet10G1==true&&eBullet11G1==true&&eBullet12G1==true&&shipVisibility==255) { eBulletSpeed9=eBulletSpeed9+5; eBulletSpeed10=eBulletSpeed10+5; eBulletSpeed11=eBulletSpeed11+5; eBulletSpeed12=eBulletSpeed12+5; strokeWeight(3); stroke(0, 255, 0); fill(255, 255, 255); ellipse(eGGun9X-20, eGGun9Y+eBulletSpeed9, 2, 5+cos(millis()/4*50)); ellipse(eGGun10X-20, eGGun10Y+eBulletSpeed10, 2, 5+cos(millis()/4*50)); ellipse(eGGun11X-20, eGGun11Y+eBulletSpeed11, 2, 5+cos(millis()/4*50)); ellipse(eGGun12X-20, eGGun12Y+eBulletSpeed12, 2, 5+cos(millis()/4*50)); //if ship goes off screen, bullets are reset } else if (eBullet9G1==false&&eBullet10G1==false&&eBullet11G1==false&&eBullet12G1==false&&shipVisibility==255) { eBulletSpeed9=0; eBulletSpeed10=0; eBulletSpeed11=0; eBulletSpeed12=0; } //ship2 if (eBulletG2==true&&eBullet2G2==true&&eBullet3G2==true&&eBullet4G2==true&&shipVisibility2==255) { eBulletSpeed21=eBulletSpeed21+5; eBulletSpeed22=eBulletSpeed22+5; eBulletSpeed23=eBulletSpeed23+5; eBulletSpeed24=eBulletSpeed24+5; strokeWeight(3); stroke(0, 255, 0); fill(255, 255, 255); ellipse(eGGun1X2-20, eGGun1Y2+eBulletSpeed21, 2, 5+cos(millis()/4*50)); ellipse(eGGun2X2-20, eGGun2Y2+eBulletSpeed22, 2, 5+cos(millis()/4*50)); ellipse(eGGun3X2-20, eGGun3Y2+eBulletSpeed23, 2, 5+cos(millis()/4*50)); ellipse(eGGun4X2-20, eGGun4Y2+eBulletSpeed24, 2, 5+cos(millis()/4*50)); } else if (eBulletG2==false&&eBullet2G2==false&&eBullet3G2==false&&eBullet4G2==false&&shipVisibility2==255) { eBulletSpeed21=0; eBulletSpeed22=0; eBulletSpeed23=0; eBulletSpeed24=0; } if (eBullet5G2==true&&eBullet6G2==true&&eBullet7G2==true&&eBullet8G2==true&&shipVisibility2==255) { eBulletSpeed25=eBulletSpeed25+5; eBulletSpeed26=eBulletSpeed26+5; eBulletSpeed27=eBulletSpeed27+5; eBulletSpeed28=eBulletSpeed28+5; strokeWeight(3); stroke(0, 255, 0); fill(255, 255, 255); ellipse(eGGun5X2-20, eGGun5Y2+eBulletSpeed25, 2, 5+cos(millis()/4*50)); ellipse(eGGun6X2-20, eGGun6Y2+eBulletSpeed26, 2, 5+cos(millis()/4*50)); ellipse(eGGun7X2-20, eGGun7Y2+eBulletSpeed27, 2, 5+cos(millis()/4*50)); ellipse(eGGun8X2-20, eGGun8Y2+eBulletSpeed28, 2, 5+cos(millis()/4*50)); } else if (eBullet5G2==false&&eBullet6G2==false&&eBullet7G2==false&&eBullet8G2==false&&shipVisibility2==255) { eBulletSpeed25=0; eBulletSpeed26=0; eBulletSpeed27=0; eBulletSpeed28=0; } if (eBullet9G2==true&&eBullet10G2==true&&eBullet11G2==true&&eBullet12G2==true&&shipVisibility2==255) { eBulletSpeed29=eBulletSpeed29+5; eBulletSpeed210=eBulletSpeed210+5; eBulletSpeed211=eBulletSpeed211+5; eBulletSpeed212=eBulletSpeed212+5; strokeWeight(3); stroke(0, 255, 0); fill(255, 255, 255); ellipse(eGGun9X2-20, eGGun9Y2+eBulletSpeed29, 2, 5+cos(millis()/4*50)); ellipse(eGGun10X2-20, eGGun10Y2+eBulletSpeed210, 2, 5+cos(millis()/4*50)); ellipse(eGGun11X2-20, eGGun11Y2+eBulletSpeed211, 2, 5+cos(millis()/4*50)); ellipse(eGGun12X2-20, eGGun12Y2+eBulletSpeed212, 2, 5+cos(millis()/4*50)); } else if (eBullet9G2==false&&eBullet10G2==false&&eBullet11G2==false&&eBullet12G2==false&&shipVisibility2==255) { eBulletSpeed29=0; eBulletSpeed210=0; eBulletSpeed211=0; eBulletSpeed212=0; } } //display health bar void healthBar() { if (uiSpawn==true&&health== 10&&health10 == true) { strokeWeight(6); strokeCap(SQUARE); stroke(150, 0, 0); line(10, 390, 390, 390); if (hit== true &&health==9) { health10=false; } } //hide part of healthbar if player takes damage if (health ==9 &&health9==true) { strokeWeight(6); strokeCap(SQUARE); stroke(150, 0, 0); line(10, 390, 352, 390); } if (hit== true &&health==8) { health9=false; } if (health ==8 &&health8==true) { strokeWeight(6); strokeCap(SQUARE); stroke(150, 0, 0); line(10, 390, 314, 390); } if (hit== true &&health==7) { health8=false; } if (health ==7 &&health7==true) { strokeWeight(6); strokeCap(SQUARE); stroke(150, 0, 0); line(10, 390, 276, 390); } if (hit== true &&health==6) { health7=false; } if (health ==6 &&health6==true) { strokeWeight(6); strokeCap(SQUARE); stroke(150, 0, 0); line(10, 390, 238, 390); } if (hit== true &&health==5) { health6=false; } if (health ==5 &&health5==true) { strokeWeight(6); strokeCap(SQUARE); stroke(150, 0, 0); line(10, 390, 238, 390); } if (hit== true &&health==4) { health5=false; } if (health ==4 &&health4==true) { strokeWeight(6); strokeCap(SQUARE); stroke(150, 0, 0); line(10, 390, 200, 390); } if (hit== true &&health==3) { health4=false; } if (health ==3 &&health3==true) { strokeWeight(6); strokeCap(SQUARE); stroke(150, 0, 0); line(10, 390, 162, 390); } if (hit== true &&health==2) { health3=false; } if (health ==2 &&health2==true) { strokeWeight(6); strokeCap(SQUARE); stroke(150, 0, 0); line(10, 390, 124, 390); } if (hit== true &&health==1) { health2=false; } if (health ==1 &&health1==true) { strokeWeight(6); strokeCap(SQUARE); stroke(150, 0, 0); line(10, 390, 86, 390); } if (hit== true &&health==0) { health1=false; } if (health ==0 &&health0==true) { strokeWeight(6); strokeCap(SQUARE); stroke(150, 0, 0); line(10, 390, 48, 390); }//if health = 0, game over if (hit== true &&health==-1) { health0=false; gameOver=true; } } //scores given for destroying enemies void pointSystem() { highScore = score; if (shipVisibility == 255 &&explode == true) { score = score + 200; } if (shipVisibility2 == 255 &&explode == true) { score = score + 200; } if (shipVisibility2 == 255&&shipVisibility == 255 &&explode == true) { score = score + 200; } } void hitBoxes() { //check if ship is in the way of enemy bullet. if so take 1 damage //ship 1 if (((shipCenterY == eBulletSpeed1 - 20) && (shipCenterX < eGGun1X -20) && ( shipCenterX > 275)) ||((shipCenterY == eBulletSpeed2 - 20) && (shipCenterX < eGGun2X -20) && ( shipCenterX > 275)) ||((shipCenterY == eBulletSpeed3 - 20) && (shipCenterX < eGGun3X -20) && ( shipCenterX > 275)) ||((shipCenterY == eBulletSpeed4 - 20) && (shipCenterX < eGGun4X -20) && ( shipCenterX > 275))) { hit=true; if (hit==true) { health=health-1; } } //ship 2 if (((shipCenterY == eBulletSpeed21 - 20) && (shipCenterX < eGGun1X2-20 ) && ( shipCenterX > 275)) ||((shipCenterY == eBulletSpeed22 - 20) && (shipCenterX < eGGun2X2-20 ) && ( shipCenterX > 275)) ||((shipCenterY == eBulletSpeed23 - 20) && (shipCenterX < eGGun3X2-20 ) && ( shipCenterX > 275)) ||((shipCenterY == eBulletSpeed24 - 20) && (shipCenterX < eGGun4X2 -20) && ( shipCenterX > 275))) { hit=true; if (hit==true) { health=health-1; } } //ship 1 pos 2 if (((shipCenterY == eBulletSpeed5 - 20) && (shipCenterX < eGGun5X -20 ) && ( shipCenterX > 190)) ||((shipCenterY == eBulletSpeed6 - 20) && (shipCenterX < eGGun6X -20 ) && ( shipCenterX > 190)) ||((shipCenterY == eBulletSpeed7 - 20) && (shipCenterX < eGGun7X -20 ) && ( shipCenterX > 190)) ||((shipCenterY == eBulletSpeed8 - 20) && (shipCenterX < eGGun8X -20) && ( shipCenterX > 190))) { hit=true; if (hit==true) { health=health-1; } } //ship 2 pos 2 if (((shipCenterY == eBulletSpeed25 - 20) && (shipCenterX < eGGun5X2-20 ) && ( shipCenterX > 190)) ||((shipCenterY == eBulletSpeed26 - 20) && (shipCenterX <eGGun6X2-20 ) && ( shipCenterX > 190)) ||((shipCenterY == eBulletSpeed27 - 20) && (shipCenterX < eGGun7X2 -20) && ( shipCenterX > 190)) ||((shipCenterY == eBulletSpeed28 - 20) && (shipCenterX < eGGun8X2 -20) && ( shipCenterX > 190))) { hit=true; if (hit==true) { health=health-1; } } //ship 1 pos 3 if (((shipCenterY == eBulletSpeed9 - 20) && (shipCenterX < eGGun9X -20 ) && ( shipCenterX > 20)) ||((shipCenterY == eBulletSpeed10 - 20) && (shipCenterX < eGGun10X -20 ) && ( shipCenterX > 20)) ||((shipCenterY == eBulletSpeed11 - 20) && (shipCenterX < eGGun11X -20 ) && ( shipCenterX > 20)) ||((shipCenterY == eBulletSpeed12 - 20) && (shipCenterX < eGGun12X -20) && ( shipCenterX > 20))) { hit=true; if (hit==true) { health=health-1; } } //ship 2 pos 3 if (((shipCenterY == eBulletSpeed29 - 20) && (shipCenterX < eGGun9X2-20 ) && ( shipCenterX > 20)) ||((shipCenterY == eBulletSpeed210 - 20) && (shipCenterX <eGGun10X2-20 ) && ( shipCenterX > 20)) ||((shipCenterY == eBulletSpeed211 - 20) && (shipCenterX < eGGun11X2 -20) && ( shipCenterX > 20)) ||((shipCenterY == eBulletSpeed212 - 20) && (shipCenterX < eGGun12X2 -20) && ( shipCenterX > 20))) { hit=true; if (hit==true) { health=health-1; } } //player damage if ((shipCenterY +bulletSpeed1 >= eShipY+80 )&& (shipCenterY+bulletSpeed1 >=eShipY-80) && (shipCenterX <= eShipX+20)&&(shipCenterX >= eShipX-20) && (shoot==true)) { enemyHealth1=enemyHealth1-1; } if ((shipCenterY +bulletSpeed1 >= eShipY2 +80)&& (shipCenterY+bulletSpeed1 >=eShipY2-80) && (shipCenterX <= eShipX2+20)&&(shipCenterX >= eShipX2-20) && (shoot==true)) { ; enemyHealth2=enemyHealth2-1; } } //reset to title screen if player looses void gameOverScreen() { startable=false; start=false; titleScreen(); gameOver=false; }