-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathSoccerSimulator.pde
93 lines (76 loc) · 2.18 KB
/
SoccerSimulator.pde
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
GameController controller;
float SCALE = 300f;
void settings(){
controller = new GameController(new Match(
// Team A Class
CustomTeamA.class,
// Team B Class
CustomTeamB.class,
// Number of robots on each side
2
));
controller.getSimulator().setFieldSize(2.44f, 1.82f);
size((int)controller.getWidth(SCALE) + 200, (int)controller.getHeight(SCALE) + 100);
}
void draw(){
background(255);
controller.run();
translate(100, 0);
controller.draw(this, SCALE);
translate(-100, 0);
}
/*
Finds out what is closer to the ball that can be moved,
and then move to that position
*/
public void mouseDragged(){
// Checks what is closest to the mouse cursos (Robots and Ball)
PVector mousePoint = new PVector((mouseX - 100) / SCALE, (mouseY - 150) / SCALE);
float closestDist = 0.1f;
Simulatable closest = controller.getSimulator().ball;
for(Simulatable s: controller.getSimulator().simulatables){
// Skip if not Ball or Robot
if(!(s instanceof Ball || s instanceof Robot))
continue;
float dist = PVector.sub(s.getRealPosition(), mousePoint).mag();
if(closestDist > dist){
closestDist = dist;
closest = s;
}
}
if(closest != null){
closest.position.set(mousePoint);
closest.speed = new PVector();
closest.accel = new PVector();
}
}
public void keyPressed(){
if(key == ' '){
if(!controller.hasStarted()){
System.out.println("Start game");
controller.resetGame();
controller.resumeGame();
}else if(controller.isRunning()){
System.out.println("Pause game");
controller.pauseGame();
}else{
System.out.println("Resume game");
controller.resumeGame();
}
}else if(key == 'i'){
controller.resetGame();
controller.resumeGame();
}else if(key == 'r'){
controller.restartPositions(null);
}else if(key == 'd'){
String debug = "DEBUG:";
debug += "\nisRunning:"+controller.isRunning();
debug += "\nController Robots:"+controller.robots.size();
for(Robot r:controller.robots)
debug += "\n\t"+r+" ["+r.position.x+","+r.position.y+"]";
debug += "\nSimulatables:"+controller.getSimulator().simulatables.size();
for(Simulatable r:controller.getSimulator().simulatables)
debug += "\n\t"+r;
System.out.println(debug);
}
}