Dive-Engine-2D/src/diveengine2d/RigidBody.java

37 lines
1.1 KiB
Java
Raw Normal View History

2016-02-16 03:42:12 -05:00
package diveengine2d;
import java.awt.Color;
import java.awt.Graphics2D;
2016-02-16 03:42:12 -05:00
public class RigidBody extends DiveScript{
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
public double dx, dy, drot;
public double friction;
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() {
dx += (dx*friction - dx) * Time.deltaTime;
dy += (dy*friction - dy) * Time.deltaTime;
drot += (drot*friction - drot) * Time.deltaTime;
entity.x += dx * Time.deltaTime;
entity.y += dy * Time.deltaTime;
entity.rotation += drot * Time.deltaTime;
}
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
}
}