-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrack.java
More file actions
60 lines (46 loc) · 1.13 KB
/
Track.java
File metadata and controls
60 lines (46 loc) · 1.13 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
// Track.java
import ch.aplu.robotsim.*;
public class Track {
public Track() {
NxtRobot robot = new NxtRobot();
LightSensor ls1 = new LightSensor(SensorPort.S1);
robot.addPart(ls1);
ls1.activate(true);
LightSensor ls2 = new LightSensor(SensorPort.S2);
robot.addPart(ls2);
ls2.activate(true);
TouchSensor ts = new TouchSensor(SensorPort.S3);
robot.addPart(ts);
Gear gear = new Gear();
robot.addPart(gear);
gear.setSpeed(90);
while (true) {
gear.forward();
int v1 = ls1.getValue();
int v2 = ls2.getValue();
if (ts.isPressed()) {
System.out.println("Wall");
gear.left(180);
//gear.forward(70);
//gear.stop();
}
if (v1 < 50){
gear.left(5);
}
if (v2 < 50){
gear.right(5);
}
}
}
public static void main(String[] args) {
new Track();
}
// ------------------ Environment --------------------------
static {
NxtContext.setStartPosition(70, 412);
NxtContext.setStartDirection(-90);
NxtContext.useBackground("sprites/track.png");
NxtContext.useObstacle("sprites/wall1.gif", 80, 455);
NxtContext.useObstacle("sprites/wall2.gif", 450, 80);
}
}