class Ship extends ParticleWrapper2D { float rad; Ship(Particle p) { super(p); rad = 5; } void shoot() { float len = dist(mouseX, mouseY, x(), y()); float dx = (mouseX - x())/len; float dy = (mouseY - y())/len; float bx = x() + dx*rad; float by = y() + dy*rad; Bullet b = new Bullet(phys.makeParticle(0.5, bx, by, 0)); float bspeed = 15; b.addVelocity(dx*bspeed, dy*bspeed); bullets.add(b); } void update() { if ( x() > width - rad ) { addVelocity(-5, 0); } else if ( x() < rad ) { addVelocity(5, 0); } if ( y() > height - rad ) { addVelocity(0, -5); } else if ( y() < rad ) { addVelocity(0, 5); } } void draw() { stroke(100, 255, 255); noFill(); ellipse(x(), y(), 5, 5); float len = dist(mouseX, mouseY, x(), y()); float dx = (mouseX - x())/len; float dy = (mouseY - y())/len; float px = -dy; float py = dx; triangle(x() + px*rad, y() + py*rad, x() + dx*rad*3, y() + dy*rad*3, x() - px*rad, y() - py*rad); } }