Beispielprojekte

This commit is contained in:
ngb
2022-01-02 22:12:21 +01:00
parent c712826c07
commit ba9d3e9fe3
12 changed files with 526 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
import schule.ngb.zm.*;
public class Attractor extends Mover {
private int mass = 0;
public Attractor( int x, int pY, int pMass ) {
this(x, pY, pMass, new Vector());
}
public Attractor( int x, int pY, int pMass, Vector pVelocity ) {
super(x, pY, pVelocity);
mass = pMass;
setFillColor(YELLOW);
}
public void attract( Mover pMover ) {
if( pMover != this ) {
Vector force = new Vector(this.x, this.y);
force.sub(pMover.getX(), pMover.getY()).scale(mass*Gravity.G).limit(0, 50*Gravity.G);
pMover.applyForce(force);
}
}
}