Repository navigation
Expand file tree
/
Copy pathCell.java
More file actions
executable file
·80 lines (69 loc) · 1.75 KB
/
Copy pathCell.java
File metadata and controls
executable file
·80 lines (69 loc) · 1.75 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
package com.github.marioariasga.cellsimulator;
import java.awt.Color;
import com.github.marioariasga.cellsimulator.environment.Environment;
public abstract class Cell {
protected double x, y;
protected double angle;
protected double speed;
protected double eaten=0;
protected double odometer=0;
protected double energy=Constants.INITIAL_ENERGY;
protected Color color=Color.red;
public Cell(double x, double y, double angle, double speed) {
super();
this.x = x;
this.y = y;
this.angle = angle;
this.speed = speed;
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public double getAngle() {
return angle;
}
public void setColor(Color color) {
this.color = color;
}
public Color getColor() {
return color;
}
void reset() {
eaten=0;
odometer=0;
energy = Constants.INITIAL_ENERGY;
}
public abstract void move(Environment e);
public void checkInside(Environment e) {
// Specular
if(Constants.CONTAINER_TYPE == Constants.CONTAINER_TYPE_SPECULAR) {
x = Util.clamp(0, x, e.getWidth());
y = Util.clamp(0, y, e.getHeight());
// Periodic
} else if(Constants.CONTAINER_TYPE == Constants.CONTAINER_TYPE_PERIODIC) {
x = x<0 ? x+e.getWidth() : x;
x = x>e.getWidth() ? x-e.getWidth() : x;
y = y<0 ? y+e.getHeight() : y;
y = y>e.getHeight() ? y-e.getHeight() : y;
// Rebound
} else if(Constants.CONTAINER_TYPE == Constants.CONTAINER_TYPE_REBOUND) {
if(x<0) {
x=0;
angle = Math.PI-angle;
} else if(x>e.getWidth()) {
x=e.getWidth();
angle = Math.PI-angle;
}
if(y<0) {
y=0;
angle = -angle;
} else if(y>e.getHeight()) {
y=e.getHeight();
angle = -angle;
}
}
}
}