2016-02-16 03:42:12 -05:00
|
|
|
package diveengine2d;
|
|
|
|
|
|
2016-02-23 23:10:45 -05:00
|
|
|
import java.awt.Color;
|
|
|
|
|
import java.awt.Graphics2D;
|
|
|
|
|
|
2016-02-16 03:42:12 -05:00
|
|
|
public class RigidBody extends DiveScript{
|
2016-02-23 23:10:45 -05:00
|
|
|
|
|
|
|
|
private static Color xAxisColor = new Color(244, 67, 54); //A500 red
|
|
|
|
|
private static Color yAxisColor = new Color(33, 150, 243); //A500 blue
|
|
|
|
|
private static Color debugColor = new Color(76, 175, 80); //A500 green
|
2016-02-23 08:02:06 -05:00
|
|
|
public double dx, dy, drot;
|
|
|
|
|
public double friction;
|
2016-02-23 23:10:45 -05:00
|
|
|
public boolean physics = false;
|
|
|
|
|
//public bool
|
2016-02-16 04:04:05 -05:00
|
|
|
|
2016-02-16 03:42:12 -05:00
|
|
|
public void update() {
|
2016-02-23 23:10:45 -05:00
|
|
|
dx += (dx*friction - dx) * Time.deltaTime;
|
|
|
|
|
dy += (dy*friction - dy) * Time.deltaTime;
|
|
|
|
|
drot += (drot*friction - drot) * Time.deltaTime;
|
|
|
|
|
|
2016-02-23 08:02:06 -05:00
|
|
|
entity.x += dx * Time.deltaTime;
|
|
|
|
|
entity.y += dy * Time.deltaTime;
|
|
|
|
|
entity.rotation += drot * Time.deltaTime;
|
2016-02-23 23:10:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void render(Graphics2D g) {
|
|
|
|
|
if(DebugSettings.debugLevel > 0) {
|
|
|
|
|
g.setColor(xAxisColor);
|
|
|
|
|
g.drawLine((int)entity.x, (int)entity.y, (int)entity.x+(int)(dx*20), (int)entity.y);
|
|
|
|
|
g.setColor(yAxisColor);
|
|
|
|
|
g.drawLine((int)entity.x, (int)entity.y, (int)entity.x, (int)entity.y+(int)(dy*20));
|
|
|
|
|
g.setColor(debugColor);
|
|
|
|
|
g.drawLine((int)entity.x, (int)entity.y, (int)entity.x+(int)(dx*15), (int)entity.y+(int)(dy*15));
|
|
|
|
|
}
|
2016-02-16 03:42:12 -05:00
|
|
|
}
|
|
|
|
|
}
|