-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBridgeAndWall.java
More file actions
50 lines (35 loc) · 897 Bytes
/
BridgeAndWall.java
File metadata and controls
50 lines (35 loc) · 897 Bytes
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
// BridgeAndWall.java
import ch.aplu.robotsim.*;
public class BridgeAndWall {
public BridgeAndWall() {
NxtRobot robot = new NxtRobot();
LightSensor ls = new LightSensor(SensorPort.S3);
robot.addPart(ls);
ls.activate(true);
TouchSensor ts = new TouchSensor(SensorPort.S2);
robot.addPart(ts);
Gear gear = new Gear();
robot.addPart(gear);
gear.setSpeed(100);
while (true) {
gear.forward();
int v = ls.getValue();
if (v < 900) {
gear.left(180);
}
if (ts.isPressed()) {
gear.left(180);
}
}
}
public static void main(String[] args) {
new BridgeAndWall();
}
// ------------------ Environment --------------------------
static {
NxtContext.setStartPosition(250, 300);
NxtContext.setStartDirection(-90);
NxtContext.useBackground("sprites/bridge.gif");
NxtContext.useObstacle("sprites/wall.gif", 245, 380);
}
}