forked from lastleon/EvolutionSimulator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSensor.pde
More file actions
84 lines (67 loc) · 2.57 KB
/
Copy pathSensor.pde
File metadata and controls
84 lines (67 loc) · 2.57 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
class Sensor {
float distance;
float distanceMultiplier = 3.5;
PVector position;
PVector orientation;
Creature c;
Sensor(Creature creature) {
c = creature;
distance = c.getDiameter()*distanceMultiplier;
orientation = new PVector(cos(c.velocity.heading())*distance, sin(c.velocity.heading())*distance);
position = new PVector(0, 0);
}
//updated und malt den Fühler
public void drawSensor() {
distance = c.getDiameter()*distanceMultiplier;
// Fühlerposition wird erstellt
position.set(c.position.x, c.position.y); // c.position.copy() funktioniert manchmal nicht // Position ausgehend von Kreaturenposition gesetzt
orientation.setMag(distance);
position.add(orientation);
// Fühler wird auf die gegenüberliegende Seite teleportiert, wenn er außerhalb der Map ist
if (position.x > map.worldBounds) { // wenn zu weit rechts
position.set(position.x-map.worldBounds, position.y);
}
if (position.x < 0) { // wenn zu weit links
position.set(map.worldBounds+position.x, position.y); // + position.x, weil es immer ein negativer Wert ist
}
if (position.y > map.worldBounds) { // wenn zu weit unten
position.set(position.x, position.y-map.worldBounds);
}
if (position.y < 0) { // wenn zu weit oben
position.set(position.x, map.worldBounds+position.y); // + position.y, weil es immer ein negativer Wert ist
}
// Falls Fühler auf anderer Seite der Map sind, werden die Linien nicht mehr gemalt
if (!(position.dist(c.getPosition()) > distance)) {
line(position.x, position.y, c.position.x, c.position.y);
}
// Körper
ellipse(position.x, position.y, c.getDiameter()/4, c.getDiameter()/4);
}
public void rotateSensor(float angle) {
orientation.rotate(radians(angle));
}
////getter
// gibt die Energie vom Feld des Fühlers
public float getSensorFieldEnergy() {
Field field = map.getField((int)position.x, (int)position.y);
return field.getEnergy();
}
// gibt, wenn Gegner vorhanden, dessen Energie aus
public float getSensorEnemyEnergy() {
Creature c = map.getCreature(position);
if (c != null) {
return c.getEnergy();
} else {
return 0;
}
}
public Creature getSensorPartner() {
return map.getCreature(position);
}
public float getDirection() {
return degrees(orientation.heading());
}
public float getSensorFieldType() {
return map.getField((int)position.x, (int)position.y).isLandInt();
}
}