-
Notifications
You must be signed in to change notification settings - Fork 0
/
Transform.java
55 lines (50 loc) · 1.52 KB
/
Transform.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
public class Transform
{
//need smooth collisions for smooth movement
//public long previousTime;
public Vector2 position;
public Vector2 velocity;
public Vector2 acceleration;
public double rotation;
public boolean isStatic;
public GameObject gameObject;
public Transform(GameObject gameObject)
{
//previousTime = System.currentTimeMillis();
this.gameObject = gameObject;
position = new Vector2();
velocity = new Vector2();
acceleration = new Vector2();
}
//dt = time passed
public void Update(double dt)
{
//dt = ((float)(System.currentTimeMillis() - previousTime))/1000f;
//previousTime = System.currentTimeMillis();
if (gameObject != null)
{
if (gameObject.collider.enabled)
{
//use 1/att + vt for position to stop momentum loss
if(gameObject.collider.velocitySet != null)
{
velocity = gameObject.collider.velocitySet;
gameObject.collider.velocitySet = null;
}
if(gameObject.collider.positionSet != null)
{
position = gameObject.collider.positionSet;
gameObject.collider.positionSet = null;
}
}
}
if (!isStatic)
{
velocity = velocity.add(acceleration.multiply((float)dt));
position = position.add(velocity.multiply((float)dt));
}
}
public void draw(double scale)
{
}
}