74 lines
1.5 KiB
Plaintext
Raw Permalink Normal View History

2015-03-05 12:57:02 +01:00
import teilchen.BehaviorParticle;
import mathematik.Vector3f;
class Creature extends BehaviorParticle {
float _scale;
2015-03-05 14:53:49 +01:00
float _rotation;
2015-03-05 12:57:02 +01:00
public Creature(int x, int y, int r) {
super();
position().set(x, y);
maximumInnerForce(100);
radius(r);
_scale = 1.0;
2015-03-05 14:53:49 +01:00
_rotation = 0;
2015-03-05 12:57:02 +01:00
}
2015-03-05 14:53:49 +01:00
///////////////////////////////////
// display method
// + applies transformations
// + draws shape of the subclass
2015-03-05 12:57:02 +01:00
public void display() {
pushMatrix();
translate(position().x, position().y);
2015-03-05 14:53:49 +01:00
if(_rotation != 0)
rotate(_rotation);
else
rotate(getRotation());
2015-03-05 12:57:02 +01:00
scale(_scale);
draw_shape();
popMatrix();
}
2015-03-05 14:53:49 +01:00
/////////////////////////////////
// (absolute) transforms
public void rotate_to(float r) {
_rotation = r;
}
public void scale_to(float s) {
_scale = s;
}
///////////////////////////////////
// (incremental) transforms
public void rotate_increment(float r) {
_rotation += r;
}
public void scale_increment(float s) {
_scale += s;
}
2015-03-05 12:57:02 +01:00
private float getRotation() {
if(velocity().isNaN() || velocity().magnitude() == 0) return 0;
Vector3f v = new Vector3f(-1, 0, 0);
return velocity().angle(v);
}
2015-03-05 14:53:49 +01:00
///////////////////////////////////
// ** METHODS FOR SUBCLASSES **
// draws a (subclass) shape (in own coordinates)
2015-03-05 12:57:02 +01:00
public void draw_shape() {}
2015-03-05 14:53:49 +01:00
// evaluates if mx and my are inside the (subclass) shape
2015-03-05 12:57:02 +01:00
public boolean inside(int mx, int my){return false;}
2015-03-05 14:53:49 +01:00
2015-03-05 12:57:02 +01:00
};