import processing.core.*; import java.util.ArrayList; public class PlayerFish extends Fish{ //EnemyFish enemy; PApplet p; int plus; boolean dead; PlayerFish(PApplet p, PVector position, float size){ super(p, position, size); this.p = p; velocity = new PVector(10,10); plus = 0; } boolean eat (Fish otherFish){ boolean eat = false; if (size * 1.5 > otherFish.size * 10){ if (otherFish.size * 10 > size * 1.5 * 0.9){ plus = 40; }else if (otherFish.size * 10 > size * 1.5 * 0.5){ plus = 20; }else if (otherFish.size * 10 < size * 1.5 * 0.5){ plus = 10; } size *= 1.1; eat = true; } return eat; } void drawWaves(){ int distance = 0; p.pushMatrix(); p.stroke(250,0,0); p.strokeWeight(3); for(int i = 1; i <= 2; i++){ p.line(position.x, position.y - (size / 2) - distance * i, position.x, position.y - (size / 2) - distance * i); distance += 5; } p.popMatrix(); } boolean checkHeadOn(Fish otherFish){ if (velocity.x * otherFish.velocity.x < 0 && p.abs (position.y - otherFish.position.y) < p.max((float)(size*1.5/2), otherFish.size*10/2)){ return true; } return false; } void moveRight() { if (velocity.x < 0){ velocity.x *= -1; } position.x += velocity.x; } boolean detectCollision(Fish otherFish) { if (p.abs(position.x - otherFish.position.x) < (size *1.5/2 + otherFish.size * 5.5/2)&& p.abs(position.y - otherFish.position.y) < (size / 2 + otherFish.size *2.5)) { return true; } else { return false; } } void moveLeft() { if (velocity.x > 0){ velocity.x *= -1; //rotate(PI); //scale(1,-1); } position.x += velocity.x; } void moveUp() { position.y -= velocity.y; } void moveDown() { position.y += velocity.y; } void detectBound(){ if (position.x + size > pondWidth + 10){ position.x = pondX + (float)(size * 1.5 / 2); } if (position.x - size * 1.5 / 2 < pondX ){ position.x = pondWidth - size; } if (position.y - size / 2 < pondY){ position.y = pondHeight - size / 2; } if (position.y +size / 2 > pondHeight + 10 ){ position.y = pondY + size / 2; } } void drawFish(){ p.pushMatrix(); p.translate(position.x, position.y); if (velocity.x > 0){ p.rotate(p.PI); p.scale(1,-1); } p.fill(239,125,23); p.noStroke(); //body p.ellipse(0, 0, size*(float)1.5, size); //tail p.triangle(0+size, 0-size/3, (float)(0+size*1.5/2), 0, 0+size, 0+size/3); p.fill(255); p.arc(0-size /(float)2.2, 0-size/6, size/3, size/3, (p.PI/180)*0, (p.PI/180)*180); p.fill(0); p.arc(0-size/(float)2.4, 0-size/6, size/5, size/5, (p.PI/180)*0, (p.PI/180)*180); p.popMatrix(); } }