-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
executable file
·79 lines (60 loc) · 2.27 KB
/
Player.java
File metadata and controls
executable file
·79 lines (60 loc) · 2.27 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import com.javagamemaker.javagameengine.JavaGameEngine;
import com.javagamemaker.javagameengine.components.Collider;
import com.javagamemaker.javagameengine.components.GameObject;
import com.javagamemaker.javagameengine.components.PhysicsBody;
import com.javagamemaker.javagameengine.components.shapes.Circle;
import com.javagamemaker.javagameengine.input.Input;
import com.javagamemaker.javagameengine.input.Keys;
import com.javagamemaker.javagameengine.msc.Vector2;
import java.awt.*;
public class Player extends GameObject {
PhysicsBody body = new PhysicsBody();
public Player() {
super();
/*
localVertices.clear();
localVertices.add(new Vector2(-50,-20)); // top left
localVertices.add(new Vector2(-50, 20)); // bottom left
localVertices.add(new Vector2( 50, 20)); // bottom right
localVertices.add(new Vector2( 70,0)); // top right
localVertices.add(new Vector2( 50,-20)); // top right
updateVertices();
*/
localVertices = new Circle(10,8);
//setPosition(new Vector2(100,200));
Collider col = new Collider(localVertices);
col.setVertices(vertices);
body.mass = 200;
add(col);
add(body);
GameObject g = new GameObject();
g.add(new Collider());
g.add(new PhysicsBody());
g.setParentOffset(new Vector2(200,0));
//add(g);
}
@Override
public void update() {
super.update();
// setPosition(Input.getMousePosition());
if(Input.isKeyDown(Keys.A)){
rotate(-1); //body.setRotationalPoint(new Vector2(0,0));
}
if(Input.isKeyDown(Keys.D)){
//body.setRotationalForce(0.9f);
rotate(1);
// body.setRotationalPoint(new Vector2(0,0));
}
if(Input.isKeyDown(Keys.SPACE)){
body.addForce(Vector2.getDirection(angle).multiply(5*2));
}
if(Input.isKeyDown(Keys.SHIFT)){
body.addForce(Vector2.getDirection(angle).multiply(-5*2));
}
JavaGameEngine.getSelectedScene().getCamera().setPosition(getPosition().multiply(-1).add(JavaGameEngine.getWindowSize().divide(2)));
}
@Override
public void render(Graphics2D g) {
super.render(g);
}
}