Skip to content

Instantly share code, notes, and snippets.

@SemonCat
Created July 14, 2016 02:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SemonCat/8299207261868677c8a1041892b6bd88 to your computer and use it in GitHub Desktop.
Save SemonCat/8299207261868677c8a1041892b6bd88 to your computer and use it in GitHub Desktop.
console.log("test");
var wolfRoleList = [{
name: "fake_postman",
show_up: "videos/En_033.1_34.1_b.mp4",
knocking: "videos/En_035.mp4",
let_me_in: "videos/En_041.mp4",
press_open_door: "videos/En_045.mp4",
first_reject: "videos/En_052.mp4",
second_reject: "videos/En_055.mp4",
leave: "videos/En_058.1.mp4",
come_in: "videos/En_066.mp4",
open_door_1: "videos/En_063.mp4",
open_door_2: "videos/En_065.1.mp4",
do_motion_33: function() {
var moveHeadRight45 = function() {
return RobotAPI.moveHead(-45, 1, 0, 0);
}
var moveBodyRight180 = function() {
return RobotAPI.moveBody(0, 0, -180, 2);
}
var moveHeadDown = function() {
return RobotAPI.moveHead(0, 0, -15, 1);
}
var moveBodyToForward = function() {
return RobotAPI.moveBody(1, 0, 0, 4);
}
var moveHeadRight10 = function() {
return RobotAPI.moveHead(-10, 1, 0, 0);
}
var moveHeadLeft10 = function() {
return RobotAPI.moveHead(10, 1, 0, 0);
}
var keepShakeHead = function(){
moveHeadRight10()
.then(moveHeadLeft10)
.then(moveHeadRight10)
.then(moveHeadLeft10);
}
moveHeadRight45()
.then(function(){
Promise.all([moveBodyRight180(), moveHeadDown()])
})
.then(function(){
Promise.all([moveBodyToForward(), keepShakeHead()])
});
}
}, {
name: "fake_gasman",
show_up: "videos/En_033.2_34.2_b.mp4",
knocking: "videos/En_036.mp4",
let_me_in: "videos/En_043.mp4",
press_open_door: "videos/En_047.mp4",
first_reject: "videos/En_053.mp4",
second_reject: "videos/En_056.mp4",
leave: "videos/En_058.2.mp4",
come_in: "videos/En_067.mp4",
open_door_1: "videos/En_063.mp4",
open_door_2: "videos/En_065.2.mp4",
do_motion_33: function() {
var moveHeadRight45 = function() {
return RobotAPI.moveHead(-45, 1, 0, 0);
}
var moveBodyRight180 = function() {
return RobotAPI.moveBody(0, 0, -180, 2);
}
var moveHeadDown = function() {
return RobotAPI.moveHead(0, 0, -15, 1);
}
var moveBodyToForward = function() {
return RobotAPI.moveBody(1, 0, 0, 4);
}
var moveHeadRight10 = function() {
return RobotAPI.moveHead(-10, 1, 0, 0);
}
var moveHeadLeft10 = function() {
return RobotAPI.moveHead(10, 1, 0, 0);
}
var keepShakeHead = function(){
moveHeadRight10()
.then(moveHeadLeft10)
.then(moveHeadRight10)
.then(moveHeadLeft10);
}
moveHeadRight45()
.then(function(){
Promise.all([moveBodyRight180(), moveHeadDown()])
})
.then(function(){
Promise.all([moveBodyToForward(), keepShakeHead()])
});
}
}, {
name: "fake_mom",
show_up: "videos/En_033.3_34.3_b.mp4",
knocking: "videos/En_037.mp4",
let_me_in: "videos/En_042.mp4",
press_open_door: "videos/En_046.mp4",
first_reject: "videos/En_054.mp4",
second_reject: "videos/En_057.mp4",
leave: "videos/En_058.3.mp4",
come_in: "videos/En_068.mp4",
open_door_1: "videos/En_062.mp4",
open_door_2: "videos/En_065.3.mp4",
do_motion_33: function() {
var moveBodyRight180 = function() {
return RobotAPI.moveBody(0, 0, -180, 2);
}
var moveHeadDown = function() {
return RobotAPI.moveHead(0, 0, -15, 1);
}
var moveBodyToForward = function() {
return RobotAPI.moveBody(1, 0, 0, 4);
}
var moveHeadRight10 = function() {
return RobotAPI.moveHead(-10, 1, 0, 0);
}
var moveHeadLeft10 = function() {
return RobotAPI.moveHead(10, 1, 0, 0);
}
var keepShakeHead = function(){
moveHeadRight10()
.then(moveHeadLeft10)
.then(moveHeadRight10)
.then(moveHeadLeft10);
}
moveBodyRight180()
.then(moveHeadDown)
.then(function(){
Promise.all([moveBodyToForward(), keepShakeHead()])
});
}
}];
var clickPeepHoleTip = ["videos/En_038.mp4", "videos/En_039.mp4"];
var clickDoorTip = ["videos/En_044.mp4", "videos/En_040_2.mp4"];
shuffle(wolfRoleList);
shuffle(clickPeepHoleTip);
shuffle(clickDoorTip);
console.log(wolfRoleList);
console.log(clickDoorTip);
new Scene({
name: "scene_031",
exec: function() {
var moveHeadToLeft = function() {
return RobotAPI.moveHead(10, 1, 0, 0);
}
var moveHeadToRight = function() {
return RobotAPI.moveHead(-10, 1, 0, 0);
}
resetHead()
.then(moveHeadToLeft)
.then(moveHeadToRight);
var playVideo = function() {
return VideoPlayer.playVideo("videos/En_031.mp4");
}
var doneAction = function() {
goToScene("scene_032");
}
playVideo()
.then(doneAction);
}
}).create();
new Scene({
name: "scene_032",
exec: function() {
var moveHeadToUp = function() {
return RobotAPI.moveHead(0, 0, 25, 1);
}
var moveHeadToDown = function() {
return RobotAPI.moveHead(0, 0, 5, 1);
}
resetHead()
.then(moveHeadToUp)
.then(moveHeadToDown);
var playVideo = function() {
return VideoPlayer.playVideo("videos/En_032.mp4");
}
var doneAction = function() {
goToScene("scene_032.1");
}
playVideo()
.then(doneAction);
}
}).create();
new Scene({
name: "scene_032.1",
exec: function() {
var moveHeadRight45 = function() {
return RobotAPI.moveHead(-45, 1, 0, 0);
}
var moveBodyRight180 = function() {
return RobotAPI.moveBody(0, 0, -180, 2);
}
var moveBodyToForward = function() {
return RobotAPI.moveBody(1, 0, 0, 2);
}
var playVideo = function() {
return VideoPlayer.playVideo("videos/En_087.1.mp4");
}
var doneAction = function() {
goToScene("scene_033");
}
moveHeadRight45()
.then(function() {
return Promise.all([moveBodyRight180(), resetHead()])
})
.then(moveBodyToForward);
playVideo()
.then(doneAction);
}
}).create();
new Scene({
name: "scene_033",
exec: function() {
var playShowOut = function() {
return VideoPlayer.playVideo(wolfRoleList[0].show_up);
}
var doneAction = function() {
goToScene("scene_035_1");
}
wolfRoleList[0].do_motion_33();
playShowOut()
.then(doneAction);
}
}).create();
new Scene({
name: "scene_035_1",
exec: function() {
var moveBodyToForward = function() {
return RobotAPI.moveBody(0.09, 0, 0, 1);
}
var moveBodyToBackward = function() {
return RobotAPI.moveBody(-0.09, 0, 0, 1);
}
var playKnocking = function() {
return VideoPlayer.playVideo(wolfRoleList[0].knocking);
}
var doneAction = function() {
goToScene("scene_038_1");
}
resetHead()
.then(moveBodyToForward)
.then(moveBodyToBackward);
playKnocking()
.then(doneAction);
}
}).create();
new Scene({
name: "scene_035_2",
exec: function() {
var moveBodyToForward = function() {
return RobotAPI.moveBody(0.09, 0, 0, 1);
}
var moveBodyToBackward = function() {
return RobotAPI.moveBody(-0.09, 0, 0, 1);
}
var playKnocking = function() {
return VideoPlayer.playVideo(wolfRoleList[1].knocking);
}
var doneAction = function() {
goToScene("scene_038_2");
}
resetHead()
.then(moveBodyToForward)
.then(moveBodyToBackward);
playKnocking()
.then(doneAction);
}
}).create();
new Scene({
name: "scene_038_1",
exec: function() {
var firstTimeoutId;
var secondTimeoutId;
var isTouchPeepHole = false;
var secondTouchPeepHoleTimeout = function() {
if (isTouchPeepHole) {
return;
}
secondTimeoutId = setTimeout(changeSceneTo45, 3000);
};
var firstTouchPeepHoleTimeout = function() {
if (isTouchPeepHole) {
return;
}
VideoPlayer
.playVideo(clickPeepHoleTip[1])
.then(secondTouchPeepHoleTimeout);
};
var addTouchPeepHoleEvent = function() {
ClickHandler.set("peephole", "50%", "45%", "20%", "30%", function() {
console.log("peephole click");
isTouchPeepHole = true;
ClickHandler.remove("peephole");
clearTimeout(firstTimeoutId);
clearTimeout(secondTimeoutId);
changeSceneTo41();
});
}
var playClickPeepHoleTip = function() {
return VideoPlayer.playVideo(clickPeepHoleTip[0]);
}
var play401 = function() {
return VideoPlayer.playVideo("videos/En_040_1.mp4");
}
var doneAction = function() {
firstTimeoutId = setTimeout(firstTouchPeepHoleTimeout, 3000);
}
var changeSceneTo41 = function() {
ClickHandler.remove("peephole");
goToScene("scene_041_1");
}
var changeSceneTo45 = function() {
ClickHandler.remove("peephole");
goToScene("scene_045_1");
}
addTouchPeepHoleEvent();
playClickPeepHoleTip()
.then(play401)
.then(doneAction);
}
}).create();
new Scene({
name: "scene_038_2",
exec: function() {
var firstTimeoutId;
var secondTimeoutId;
var isTouchPeepHole = false;
var secondTouchPeepHoleTimeout = function() {
if (isTouchPeepHole) {
return;
}
secondTimeoutId = setTimeout(changeSceneTo45, 3000);
};
var firstTouchPeepHoleTimeout = function() {
if (isTouchPeepHole) {
return;
}
VideoPlayer
.playVideo(clickPeepHoleTip[1])
.then(secondTouchPeepHoleTimeout);
};
var addTouchPeepHoleEvent = function() {
ClickHandler.set("peephole", "50%", "45%", "20%", "30%", function() {
console.log("peephole click");
isTouchPeepHole = true;
ClickHandler.remove("peephole");
clearTimeout(firstTimeoutId);
clearTimeout(secondTimeoutId);
changeSceneTo41();
});
}
var playClickPeepHoleTip = function() {
return VideoPlayer.playVideo(clickPeepHoleTip[0]);
}
var play401 = function() {
return VideoPlayer.playVideo("videos/En_040_1.mp4");
}
var doneAction = function() {
firstTimeoutId = setTimeout(firstTouchPeepHoleTimeout, 3000);
}
var changeSceneTo41 = function() {
ClickHandler.remove("peephole");
goToScene("scene_041_2");
}
var changeSceneTo45 = function() {
ClickHandler.remove("peephole");
goToScene("scene_045_2");
}
addTouchPeepHoleEvent();
playClickPeepHoleTip()
.then(play401)
.then(doneAction);
}
}).create();
new Scene({
name: "scene_041_1",
exec: function() {
var moveHeadRight10 = function() {
return RobotAPI.moveHead(-10, 2, 0, 0);
}
var moveHeadLeft10 = function() {
return RobotAPI.moveHead(10, 4, 0, 0);
}
var moveHeadCenter = function() {
return RobotAPI.moveHead(0, 2, 0, 0);
}
var playLetMeIn = function() {
return VideoPlayer.playVideo(wolfRoleList[0].let_me_in);
}
var doneAction = function() {
goToScene("scene_045_1");
}
moveHeadRight10()
.then(moveHeadLeft10)
.then(moveHeadCenter);
playLetMeIn()
.then(doneAction);
}
}).create();
new Scene({
name: "scene_041_2",
exec: function() {
var moveHeadRight10 = function() {
return RobotAPI.moveHead(-10, 2, 0, 0);
}
var moveHeadLeft10 = function() {
return RobotAPI.moveHead(10, 4, 0, 0);
}
var moveHeadCenter = function() {
return RobotAPI.moveHead(0, 2, 0, 0);
}
var playLetMeIn = function() {
return VideoPlayer.playVideo(wolfRoleList[1].let_me_in);
}
var doneAction = function() {
goToScene("scene_045_2");
}
moveHeadRight10()
.then(moveHeadLeft10)
.then(moveHeadCenter);
playLetMeIn()
.then(doneAction);
}
}).create();
new Scene({
name: "scene_045_1",
exec: function() {
var firstTimeoutId;
var secondTimeoutId;
var thirdTimeoutId;
var isTouchDoor = false;
var firstTouchDoorTimeout = function(){
console.log("first touch door time out");
if(isTouchDoor){
return;
}
resetHead()
.then(moveBodyToForward)
.then(moveBodyToBackward);
VideoPlayer
.playVideo(wolfRoleList[0].press_open_door)
.then(function(){
secondTimeoutId = setTimeout(secondTouchDoorTimeout, 3000)
});
}
var secondTouchDoorTimeout = function(){
console.log("second touch door time out");
if(isTouchDoor){
return;
}
VideoPlayer
.playVideo(clickDoorTip[1])
.then(function(){
thirdTimeoutId = setTimeout(thirdTouchDoorTimeout, 3000)
});
}
var thirdTouchDoorTimeout = function(){
console.log("third touch door time out");
if(isTouchDoor){
return;
}
moveHeadToDown();
VideoPlayer
.playVideo("videos/En_060.mp4")
.then(changeSceneTo52);
}
var addTouchDoorEvent = function(){
ClickHandler.set("door", "40%", "80%", "30%", "40%", function(){
console.log("door click");
isTouchDoor = true;
ClickHandler.remove("door");
clearTimeout(firstTimeoutId);
clearTimeout(secondTimeoutId);
clearTimeout(thirdTimeoutId);
changeSceneTo66();
});
}
var changeSceneTo66 = function(){
console.log("change Scene To 66");
ClickHandler.remove("door");
goToScene("scene_066");
}
var changeSceneTo52 = function(){
console.log("change Scene To 52");
ClickHandler.remove("door");
goToScene("scene_052");
}
var playClickDoorTip = function() {
return VideoPlayer.playVideo(clickDoorTip[0]);
}
var doneAction = function() {
firstTimeoutId = setTimeout(firstTouchDoorTimeout, 3000);
}
var moveHeadToDown = function(){
return RobotAPI.moveHead(30, 3, -5, 3);
}
var moveBodyToForward = function(){
return RobotAPI.moveBody(0.09, 0, 0, 1.5);
}
var moveBodyToBackward = function(){
return RobotAPI.moveBody(-0.09, 0, 0, 1.5);
}
addTouchDoorEvent();
playClickDoorTip()
.then(doneAction);
}
}).create();
new Scene({
name: "scene_045_2",
exec: function() {
var firstTimeoutId;
var secondTimeoutId;
var thirdTimeoutId;
var isTouchDoor = false;
var firstTouchDoorTimeout = function(){
console.log("first touch door time out");
if(isTouchDoor){
return;
}
resetHead()
.then(moveBodyToForward)
.then(moveBodyToBackward);
VideoPlayer
.playVideo(wolfRoleList[1].press_open_door)
.then(function(){
secondTimeoutId = setTimeout(secondTouchDoorTimeout, 3000)
});
}
var secondTouchDoorTimeout = function(){
console.log("second touch door time out");
if(isTouchDoor){
return;
}
VideoPlayer
.playVideo(clickDoorTip[1])
.then(function(){
thirdTimeoutId = setTimeout(thirdTouchDoorTimeout, 3000)
});
}
var thirdTouchDoorTimeout = function(){
console.log("third touch door time out");
if(isTouchDoor){
return;
}
VideoPlayer
.playVideo(wolfRoleList[1].second_reject)
.then(play061)
.then(playOpenDoor1)
.then(changeSceneTo65);
}
var play061 = function(){
ClickHandler.remove("door");
return VideoPlayer.playVideo("videos/En_061.mp4");
}
var playOpenDoor1 = function(){
return VideoPlayer.playVideo(wolfRoleList[1].open_door_1);
}
var addTouchDoorEvent = function(){
ClickHandler.set("door", "40%", "80%", "30%", "40%", function(){
console.log("door click");
isTouchDoor = true;
ClickHandler.remove("door");
clearTimeout(firstTimeoutId);
clearTimeout(secondTimeoutId);
clearTimeout(thirdTimeoutId);
changeSceneTo66();
});
}
var changeSceneTo65 = function(){
console.log("change Scene To 65");
ClickHandler.remove("door");
goToScene("scene_065");
}
var changeSceneTo66 = function(){
console.log("change Scene To 66");
ClickHandler.remove("door");
goToScene("scene_066");
}
var changeSceneTo52 = function(){
console.log("change Scene To 52");
ClickHandler.remove("door");
goToScene("scene_052");
}
var playClickDoorTip = function() {
return VideoPlayer.playVideo(clickDoorTip[0]);
}
var doneAction = function() {
firstTimeoutId = setTimeout(firstTouchDoorTimeout, 3000);
}
var moveBodyToForward = function(){
return RobotAPI.moveBody(0.09, 0, 0, 1.5);
}
var moveBodyToBackward = function(){
return RobotAPI.moveBody(-0.09, 0, 0, 1.5);
}
addTouchDoorEvent();
playClickDoorTip()
.then(doneAction);
}
}).create();
new Scene({
name: "scene_065",
exec: function() {
var playOpenDoor2 = function() {
return VideoPlayer.playVideo(wolfRoleList[1].open_door_2);
}
var doneAction = function() {
goToScene("scene_058");
}
var moveHeadRight15 = function() {
return RobotAPI.moveHead(-15, 1, 0, 0);
}
var moveHeadLeft15 = function() {
return RobotAPI.moveHead(15, 2, 0, 0);
}
var moveBodyToLeft15 = function(){
return RobotAPI.moveBody(0, 0, 15, 1);
}
var moveBodyToRight30 = function(){
return RobotAPI.moveBody(0, 0, -30, 2);
}
resetHead()
.then(function(){
return Promise.all([moveHeadRight15(), moveBodyToLeft15()])
})
.then(function(){
return Promise.all([moveHeadLeft15(), moveBodyToRight30()])
})
.then(function(){
return Promise.all([resetHead(), moveBodyToLeft15()])
});
playOpenDoor2();
}
}).create();
new Scene({
name: "scene_052",
exec: function() {
var playWolfComeIn = function() {
return VideoPlayer.playVideo(wolfRoleList[0].first_reject);
}
var moveHeadDown = function() {
return RobotAPI.moveHead(0, 0, -15, 2);
}
var doneAction = function() {
goToScene("scene_058");
}
moveHeadDown();
playWolfComeIn()
.then(doneAction);
}
}).create();
new Scene({
name: "scene_058",
exec: function() {
var moveHeadRight45 = function() {
return RobotAPI.moveHead(-45, 1, 0, 0);
}
var moveBodyRight180 = function() {
return RobotAPI.moveBody(0, 0, -180, 2);
}
var moveBodyToForward = function() {
return RobotAPI.moveBody(1, 0, 0, 2);
}
var playWolfLeave = function() {
return VideoPlayer.playVideo(wolfRoleList[0].leave);
}
var doneAction = function() {
goToScene("scene_035_2");
}
moveHeadRight45()
.then(function() {
return Promise.all([moveBodyRight180(), resetHead()])
})
.then(moveBodyToForward);
playWolfLeave()
.then(doneAction);
}
}).create();
new Scene({
name: "scene_066",
exec: function() {
var playWolfComeIn = function() {
return VideoPlayer.playVideo(wolfRoleList[0].come_in);
}
var doneAction = function() {
goToScene("scene_045");
}
playWolfComeIn();
}
}).create();
enableDebug(true);
startScene("scene_031");
/** function **/
/**
* Shuffles array in place.
* @param {Array} a items The array containing the items.
*/
function shuffle(a) {
var j, x, i;
for (i = a.length; i; i--) {
j = Math.floor(Math.random() * i);
x = a[i - 1];
a[i - 1] = a[j];
a[j] = x;
}
}
var resetHead = function() {
return RobotAPI.moveHead(0, 1, 15, 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment