class Player extends General { PImage img1, img2; //Images of the aircrafts int health, pWidth, pHeight, shieldTime, missileCount; //health, dimensions of the aircrafts, available time for shield mode, number of missiles left boolean hit, missileMode, shieldMode; //hit: true when the player gets hit //missileMode: true when the player has missiles //shieldMode: trure when the player has a shield Player(int xPos, int yPos) { super(xPos, yPos); img1 = loadImage("aircraft.png"); img2 = loadImage("aircraft-2.png"); health = 100; pWidth = 127; pHeight = 187; hit = false; missileMode = false; shieldMode = false; shieldTime = 600; //the sield lasts for 20 seconds missileCount = 0; } //Draawing player1 void drawPlayer1() { pushMatrix(); translate(x, y); if (shieldMode && shieldTime > 0) { //if player1 has an available shield shieldTime--; noStroke(); fill(255, 50); ellipse(-40, 30, 100, 100); //draw the shield } if (shieldTime == 0) { //when the shield is not available shieldMode = false; shieldTime = 600; //reset the timer for the shield } rotate(PI/2); image(img1, 0, 0, 60, 110); //show player1's aircraft popMatrix(); if (missileMode) { //if player1 has missiles left image(missileImg, 60, 0, 50, 50); //display the missile icon at the top left corner of the screen } if (shieldMode) image(shieldImg, 5, 0, 50, 50); //if player1 has a shield, display the missile icon at the top left corner of the screen } //Draawing player1 void drawPlayer2() { pushMatrix(); translate(x, y); if (shieldMode && shieldTime > 0) { //if player2 has an available shield shieldTime--; noStroke(); fill(255, 50); ellipse(40, -30, 100, 100); //draw the shield } if (shieldTime == 0) { //when the shield is not available shieldMode = false; shieldTime = 600; //reset the timer for the shield } rotate(-PI/2); image(img2, 0, 0, 60, 110); //show player2's aircraft popMatrix(); if (missileMode) { //if player2 has missiles left image(missileImg, width-180, 0, 50, 50); //display the missile icon at the top right corner of the screen } if (shieldMode) image(shieldImg, width-60, 0, 50, 50); //if player2 has a shield, display the missile icon at the top right corner of the screen } void setY(int yPos) { y = yPos; } void setX(int xPos) { x = xPos; } int getHealth() { return health; } void setHealth(int newHealth) { health = newHealth; } boolean getHit() { return hit; } //Collision detection with the beams void playerandbeamCollide(Beam otherBeam) { if (shieldMode) { //if the player has a shield if ((abs(x - otherBeam.getX()) < (pWidth - 40)) && (abs(y - otherBeam.getY())< (pHeight - 120))) hit = true; //the player gets hit but without getting hurt } if (otherBeam.missileBeam) { //if the player gets hit by a missile if ((abs(x - otherBeam.getX()) < (pWidth - 60)) && (abs(y - otherBeam.getY())< (pHeight - 140))) { hit = true; health = health - 20; //health minus 20 } } else { //if the player gets hit by a normal beam if ((abs(x - otherBeam.getX()) < (pWidth - 70)) && (abs(y - otherBeam.getY())< (pHeight - 150))) { hit = true; health = health - 10; //health minus 10 println(health); } } } void setHit(boolean input) { hit = input; } }