Expand file tree
/
Copy pathMedkit.java
More file actions
89 lines (58 loc) · 2.77 KB
/
Copy pathMedkit.java
File metadata and controls
89 lines (58 loc) · 2.77 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
80
81
82
83
84
85
86
87
88
89
public class Medkit extends GameItem {
public static float PICKUP_DIST = 0.5f;
private static MyMesh mesh;
private static Material medKitMat;
private Transform transform;
private static final float TEX_MAX_X = 0;
private static final float TEX_MIN_X = -1;
private static final float TEX_MAX_Y = 0;
private static final float TEX_MIN_Y = -1;
public static final float scale = 0.2f;
public static final float Y_SIZE = scale;
public static float X_SIZE = Y_SIZE;
private static final float START = 0;
private int soundBuff1;
private AudioSource soundSource1;
public Medkit(Vector3F pos){
soundBuff1 = AudioMaster.loadSound("smallmedkit1.wav");
soundSource1 = new AudioSource(pos);
if (medKitMat == null){
medKitMat = new Material(new Texture("MEDIA0.png"));
}
float val1 = medKitMat.getTexture().getHeight() / medKitMat.getTexture().getWidth();
float val2 = medKitMat.getTexture().getWidth() / medKitMat.getTexture().getHeight();
X_SIZE = (float) (Y_SIZE / (Math.max(val1, val2) * 2.0));
if (mesh == null) {
Vertex[] vertices = new Vertex[]{new Vertex(new Vector3F(-X_SIZE, START, START), new Vector2F(TEX_MAX_X, TEX_MAX_Y)),
new Vertex(new Vector3F(-X_SIZE, Y_SIZE, START), new Vector2F(TEX_MAX_X, TEX_MIN_Y)),
new Vertex(new Vector3F(X_SIZE, Y_SIZE, START), new Vector2F(TEX_MIN_X, TEX_MIN_Y)),
new Vertex(new Vector3F(X_SIZE, START, START), new Vector2F(TEX_MIN_X, TEX_MAX_Y))};
int[] indices = new int[]{0, 1, 2,
0, 2, 3,};
mesh = new MyMesh(vertices, indices, true);
}
transform = new Transform();
transform.setTranslation(pos);
}
public void update(){
Vector3F orientation = Transform.getCamera().getPosition().sub(transform.getTranslation());
float angle = (float) Math.toDegrees(Math.atan(orientation.getZ() / orientation.getX()));
if (orientation.getX() < 0) {
angle += 180;
}
transform.getRotation().setY(angle + 90);
if (orientation.length() < PICKUP_DIST){
if (Game.getLevel().getPlayer().getHealth() < Player.MAX_HEALTH){
soundSource1.play(soundBuff1);
Game.getLevel().damagePlayer(-10);
Game.getLevel().removeGameItem(this);
}
}
}
public void render(){
Shader shader = Game.getLevel().getShader();
shader.bind();
shader.updateUniforms(transform.getTransformation(), transform.getProjectedTransformation(), medKitMat);
mesh.draw();
}
}