-
Notifications
You must be signed in to change notification settings - Fork 0
/
cylon.nxc
94 lines (84 loc) · 2.64 KB
/
cylon.nxc
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
94
#include "alpharex.h"
#include "alpharex.nxc"
#download "Hi.rso"
#download "Bye.rso"
#download "IllBeBack.rso"
#download "Reverse.rso"
#download "Shoot.rso"
#download "Snore.rso"
#download "Beat.rso"
#download "Sleep1.ric"
#download "Sleep2.ric"
#download "Heart1.ric"
#download "Heart2.ric"
#define NUM_SOUNDS 7
#define REVERSE_THRESHOLD 10
#define SHOOT_THRESHOLD 20
#define WALK_THRESHOLD 40
#define SLEEP_THRESHOLD 30
int boogieTime = 0;
const int waitTime = 1000;
const string sleep1 = "Sleep1.ric", sleep2 = "Sleep2.ric";
const string heart1 = "Heart1.ric", heart2 = "Heart2.ric";
const string hi = "Hi.rso", bye = "Bye.rso";
const string illBeBack = "IllBeBack.rso", reverse = "Reverse.rso";
const string shoot = "Shoot.rso", snore = "Snore.rso";
const string beat = "Beat.rso";
const string sounds[NUM_SOUNDS] = {
hi, bye, illBeBack, reverse, shoot, snore, beat
};
task toggleDance() {
for (;;) {
until (ButtonPressed(BTNCENTER, false));
boogieTime = 1;
until (!ButtonPressed(BTNCENTER, false));
boogieTime = 0;
}
}
task main () {
init();
start toggleDance;
for (;;) {
if (boogieTime) {
dance(Random(2));
for (int i=0; boogieTime; ++i) {
setColor(i % NUM_COLORS);
Wait(waitTime);
}
stopMoving();
setLight();
} else if (SENSOR_US_SENSOR < REVERSE_THRESHOLD) {
PlayFile(bye);
walk(2 * Random(3));
PlayFile(reverse);
until (SENSOR_US_SENSOR > REVERSE_THRESHOLD);
stopMoving();
} else if (SENSOR_US_SENSOR < SHOOT_THRESHOLD) {
PlayFile(illBeBack);
setColor(Red);
PlayFile(shoot);
setLight();
} else if (SENSOR_US_SENSOR < WALK_THRESHOLD) {
walk(Forward);
until (SENSOR_US_SENSOR < SHOOT_THRESHOLD || SENSOR_US_SENSOR > WALK_THRESHOLD);
stopMoving();
PlayFile(hi);
} else if (SENSOR_COLOR_SENSOR < SLEEP_THRESHOLD) {
GraphicOut(0, 0, sleep1);
PlayFile(snore);
GraphicOut(0, 0, sleep2);
PlayFile(snore);
ClearScreen();
} else switch (Random(3)) {
case 0: PlayFile(sounds[Random(NUM_SOUNDS)]);
break;
case 1: GraphicOut(0, 0, heart1);
PlayFile(beat);
GraphicOut(0, 0, heart2);
PlayFile(beat);
break;
default: Wait(waitTime);
}
Wait(waitTime);
}
}