-
Notifications
You must be signed in to change notification settings - Fork 0
/
Trigger.java
104 lines (85 loc) · 2.43 KB
/
Trigger.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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* Author: Clément Petit
* Date: 15.10.2015
*/
package ch.epfl.cs107.play.game.actor;
import ch.epfl.cs107.play.math.BasicContactListener;
import ch.epfl.cs107.play.math.Entity;
import ch.epfl.cs107.play.math.EntityBuilder;
import ch.epfl.cs107.play.math.PartBuilder;
import ch.epfl.cs107.play.math.Transform;
import ch.epfl.cs107.play.math.Vector;
public abstract class Trigger {
private Entity entity;
private ActorGame game;
private EntityBuilder entityBuilder;
private PartBuilder partBuilder;
private BasicContactListener contactListener;
public Trigger(ActorGame game, boolean fixed, Vector position) {
try{
if(game == null|| position == null) {
throw new NullPointerException();
}
this.game = game;
entityBuilder = game.createEntityBuilder();
entityBuilder.setFixed(fixed);
entityBuilder.setPosition(position);
entity = entityBuilder.build();
partBuilder = getEntity().createPartBuilder();
partBuilder.setGhost(true);
contactListener = new BasicContactListener();
getEntity().addContactListener(contactListener);
} catch(NullPointerException e) {
System.out.println("Paramètre(s) indispensable(s) valant null");
}
}
public Trigger(ActorGame game, boolean fixed) {
try {
if (game == null) {
throw new NullPointerException();
}
this.game = game;
entityBuilder = game.createEntityBuilder();
entityBuilder.setFixed(fixed);
entity = entityBuilder.build();
partBuilder = getEntity().createPartBuilder();
partBuilder.setGhost(true);
contactListener = new BasicContactListener();
getEntity().addContactListener(contactListener);
} catch (NullPointerException e) {
System.out.println("Paramètre(s) indispensable(s) valant null");
}
}
public PartBuilder getPartBuilder() {
return partBuilder;
}
public BasicContactListener getListener() {
return contactListener;
}
public boolean hasContactWith(Entity entity) {
return contactListener.hasContactWith(entity);
}
public void destroy() {
entity.destroy();
}
protected Entity getEntity() {
return entity;
}
protected ActorGame getOwner() {
return game;
}
public boolean compare(Entity compared) {
if(getEntity()==compared) {
return true;
}
else {
return false;
}
}
public Transform getTransform() {
return getEntity().getTransform();
}
public Vector getVelocity() {
return getEntity().getVelocity();
}
}