daily pastebin goal
28%
SHARE
TWEET

Untitled

a guest Dec 15th, 2018 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Language - Used for Phrases Pronounced
  2. var language = {
  3.     'welcome': 'Welcome',
  4.     'cycle_execute': 'When you hear a mode you would like to select, hit the gyrosphere.',
  5.     'welcome_to_hot_potato': 'Welcome to hot potato. Pass me before five seconds is up or loose. Throw me now to get started.',
  6.     'hot_potato_lost': 'This game has ended. Better luck next time!',
  7.     'new_color': 'I have a new color!',
  8.     'throwit_start': 'Welcome to throw it! I count your throws.',
  9.     'hot_Potato_reset': 'Charge detected. Flying status reset.',
  10.     'hot_potato_flying': 'I am flying.',
  11.     'hot_potato_reset_please': 'If I have landed already, please place me on my dock to reset flight status',
  12.     'charging': 'I am now charging.',
  13.     'remove_dock': 'You need to remove me from my dock before selecting a mode.',
  14.     'timer_paused': 'Timer paused.',
  15.     'timer_started': 'Timer started, shake to pause.',
  16.     'timer_restarted': 'Timer restarted.'
  17. };
  18. // [MODE] Cycle
  19. function actionCycle(eventKey) {
  20.    switch(eventKey) {
  21.        case 1:
  22.            actionCycleStart();
  23.            break;
  24.        case 2:
  25.            actionCycleCollision();
  26.            break;
  27.        case 6:
  28.            actionCycleCharging();
  29.            break;
  30.        case 7:
  31.            actionCycleNotCharging();
  32.            break;
  33.    }
  34. }
  35. async function actionCycleStart() {
  36.    await speak(language['cycle_execute'], true);
  37.    for (var i = 0; i < modes.length; i++) {
  38.        if (modes[i]['announce']) {
  39.            await delay(2);
  40.            if (handler != actionCycle) {
  41.                return;
  42.            }
  43.            data['cycle_select'] = i;
  44.            await speak(modes[i]['title'], true);
  45.        }
  46.    }
  47. }
  48. async function actionCycleCollision() {
  49.     if (data['charging']) {
  50.         await speak(language['remove_dock'], true);
  51.         return;
  52.     }
  53.    if (data['cycle_select'] !== null) {
  54.        handler = modes[data['cycle_select']]['actionHandler'];
  55.        handler(1);
  56.    }
  57. }
  58. async function actionCycleCharge() {
  59.     await speak(language['charging'], true);
  60.     data['charging'] = true;
  61. }
  62. async function actionCycleNotCharging() {
  63.     data['charging'] = false;
  64. }
  65. // [MODE] Hot Potato
  66. function actionHotPotato(eventKey) {
  67.    switch(eventKey) {
  68.        case 1:
  69.            actionHotPotatoStart();
  70.            break;
  71.        case 3:
  72.            actionHotPotatoLanding();
  73.            break;
  74.        case 4:
  75.            actionHotPotatoFreefall();
  76.            break;
  77.        case 6:
  78.            actionHotPotatoCharging();
  79.            break;
  80.    }
  81. }
  82. async function actionHotPotatoStart() {
  83.     await setBackLed(125);
  84.     await roll(255, 255, 5);
  85.     await speak(language['welcome_to_hot_potato'], true);
  86.     data['hot_potato_playing'] = true;
  87.     data['hot_potato_counter'] = 0;
  88.     data['hot_potato_flighttime'] = 0;
  89.     data['hot_potato_counted'] = false;
  90. }
  91. async function actionHotPotatoLanding() {
  92.     if (data['hot_potato_counted']) {
  93.         data['hot_potato_flying'] = false;
  94.         data['hot_potato_flighttime'] = 0;
  95.     }
  96.     if (data['hot_potato_playing'] && !data['hot_potato_counted']) {
  97.         await setBackLed(25);
  98.         data['hot_potato_counted'] = true;
  99.         while (data['hot_potato_counter'] < 6) {
  100.             while(data['hot_potato_flying']) {
  101.                 await speak(language['hot_potato_flying'], true);
  102.                 data['hot_potato_flighttime']++;
  103.                 if (data['hot_potato_flighttime'] > 6) {
  104.                     await speak(language['hot_potato_reset_please'], true);
  105.                 }
  106.                 velocity = Math.sqrt((getVelocity().x ** 2) + (getVelocity().y ** 2));
  107.                 if (velocity < 150) {
  108.                     data['hot_potato_flighttime'] = 0;
  109.                     data['hot_potato_flying'] = false;
  110.                 }
  111.             }
  112.             data['hot_potato_flighttime'] = 0;
  113.             if (data['hot_potato_counter'] == 5) {
  114.                 await setBackLed(255);
  115.                 await speak(language['hot_potato_lost'], true);
  116.                 handler = actionCycle;
  117.                 handler(1);
  118.             }
  119.             await delay(1);
  120.             data['hot_potato_counter']++;
  121.             await speak(data['hot_potato_counter'].toString(), true);
  122.        
  123.         }
  124.     }
  125. }
  126. async function actionHotPotatoFreefall() {
  127.     data['hot_potato_counter'] = 0;
  128.     data['hot_potato_flying'] = true;
  129. }
  130. async function actionHotPotatoCharging() {
  131.     if (data['hot_potato_flying']) {
  132.         await speak(language['hot_Potato_reset']);
  133.         data['hot_potato_flying'] = false;
  134.     } else {
  135.         handler = actionCycle;
  136.         handler(1);
  137.     }
  138. }
  139. // [MODE] Random Light
  140. async function actionRandomLight() {
  141.     data['main_led_color'] = getRandomColor();
  142.     await setMainLed(data['main_led_color']);
  143.     await speak(language['new_color'], true);
  144.     handler = actionCycle;
  145.     handler(1);
  146. }
  147. // [MODE] ThrowIt!
  148. function actionThrowIt(eventKey) {
  149.    switch(eventKey) {
  150.        case 1:
  151.            actionThrowItStart();
  152.            break;
  153.        case 4:
  154.            actionThrowItFreefall();
  155.            break;
  156.        case 6:
  157.            actionThrowItCharging();
  158.            break;
  159.    }
  160. }
  161. async function actionThrowItStart() {
  162.     await speak(language['throwit_start'], true);
  163.     data['throwit_throws'] = 0;
  164. }
  165. async function actionThrowItCharging() {
  166.     if (data['throwit_throws'] > 1) {
  167.         await speak(data['throwit_throws'], true);
  168.         data['throwit_throws'] = 0;
  169.     } else {
  170.         handler = actionCycle;
  171.         handler(1);
  172.     }
  173. }
  174. async function actionThrowItFreefall() {
  175.     data['throwit_throws']++;
  176.     await setMainLed(getRandomColor());
  177.     await speak(data['throwit_throws'].toString(), true);
  178. }
  179. // [MODE] Explore
  180. function actionExplore(eventKey) {
  181.     switch(eventKey) {
  182.         case 1:
  183.             actionExploreStart();
  184.             break;
  185.         case 2:
  186.             actionExploreCollision();
  187.             break;
  188.         case 6:
  189.             actionExploreCharging();
  190.             break;
  191.     }
  192. }
  193. async function actionExploreStart() {
  194.     data['explore_direction'] = 0;
  195.     data['explore_time'] = 0;
  196.     data['explore_seconds'] = 1;
  197.     while(true) {
  198.         await roll(data['explore_direction'], 255, data['explore_seconds']);
  199.         velocity = Math.sqrt((getVelocity().x ** 2) + (getVelocity().y ** 2));
  200.         if (velocity < 40) data['explore_direction'] = data['explore_direction'] + 10;
  201.         data['explore_time']++;
  202.         if (data['explore_time'] > 30) {
  203.             data['explore_time'] = 0;
  204.             data['explore_seconds']++;
  205.         }
  206.     }
  207. }
  208. async function actionExploreCollision() {
  209.     data['explore_direction'] + 15;
  210. }
  211. async function actionExploreCharging() {
  212.     handler = actionCycle;
  213.     handler(1);
  214. }
  215. // [MODE] Recycle - Reruns Cycle
  216. async function actionRecycle(eventKey) {
  217.     handler = actionCycle;
  218.     handler(1);
  219. }
  220. // [MODE] Timer - Times Things
  221. function actionTimer(eventKey) {
  222.    switch(eventKey) {
  223.        case 1:
  224.            actionTimerStart();
  225.            break;
  226.        case 2:
  227.            actionTimerPause();
  228.            break;
  229.        case 6:
  230.            actionTimerCharging();
  231.            break;
  232.    }
  233. }
  234. async function actionTimerStart() {
  235.     data['timer_running'] = true;
  236.     data['timer_time'] = 0;
  237.     await speak(language['timer_started'], true);
  238.     while(data['timer_running']) {
  239.         await delay(1);
  240.         data['timer_time']++;
  241.     }
  242. }
  243. async function actionTimerPause() {
  244.     if (data['timer_running']) {
  245.         data['timer_running'] = false;
  246.         await speak(language['timer_paused'], true);
  247.     } else {
  248.         data['timer_running'] = true;
  249.         await speak(language['timer_restarted'], true);
  250.     }
  251. }
  252. async function actionTimerCharging() {
  253.     await speak(data['timer_time'].toString(), true);
  254.     handler = actionCycle;
  255.     handler(1);
  256. }
  257. // Handler - Function That Should be Executed
  258. var handler = actionCycle;
  259. // Modes - Voiced in Cycle
  260. var modes = [
  261.     {
  262.         'title': 'Cycle',
  263.         'announce': false,
  264.         'actionHandler':  actionCycle,
  265.     },
  266.     {
  267.         'title': 'Timer',
  268.         'announce': true,
  269.         'actionHandler': actionTimer
  270.     },
  271.     {
  272.         'title': 'Hot Potato',
  273.         'announce': true,
  274.         'actionHandler': actionHotPotato
  275.     },
  276.     {
  277.         'title': 'Randomize Main Light Color',
  278.         'announce': true,
  279.         'actionHandler': actionRandomLight
  280.     },
  281.     {
  282.         'title': 'Throw It',
  283.         'announce': true,
  284.         'actionHandler': actionThrowIt
  285.     },
  286.     {
  287.         'title': 'Exploration',
  288.         'announce': true,
  289.         'actionHandler': actionExplore
  290.     },
  291.    {
  292.        'title': 'Recycle Through Modes',
  293.        'announce': true,
  294.        'actionHandler': actionRecycle
  295.    }
  296. ];
  297. // Events - Registered on Startup
  298. var events = [
  299.     {
  300.         'type': EventType.onCollision,
  301.         'function': onCollision
  302.     },
  303.     {
  304.         'type': EventType.onLanding,
  305.         'function': onLanding
  306.     },
  307.     {
  308.         'type': EventType.onFreefall,
  309.         'function': onFreefall
  310.     },
  311.     {
  312.         'type': EventType.onGyroMax,
  313.         'function': onGyroMax
  314.     },
  315.     {
  316.         'type': EventType.onCharging,
  317.         'function': onCharging
  318.     },
  319.     {
  320.         'type': EventType.onNotCharging,
  321.         'function': onNotCharging
  322.     }
  323. ];
  324. // Data - Set by Individual Modes
  325. var data = [];
  326. // System Processing
  327. async function startProgram() {
  328.    registerSystemEvents();
  329.    executeStartExtras();
  330.    handler(1);
  331. }
  332. async function executeStartExtras() {
  333.     await speak(language['welcome'], true);
  334. }
  335. async function onCollision() {
  336.     if (!data['lock']) handler(2);
  337. }
  338. async function onLanding() {
  339.     if (!data['lock']) handler(3);
  340. }
  341. async function onFreefall() {
  342.    if (!data['lock']) handler(4);
  343. }
  344. async function onGyroMax() {
  345.    if (!data['lock']) handler(5);
  346. }
  347. async function onCharging() {
  348.    handler(6);
  349. }
  350. async function onNotCharging() {
  351.    handler(7);
  352. }
  353. function registerSystemEvents() {
  354.  let i = 0;
  355.  while (i < events.length) {
  356.    registerSystemEvent(events[i]);
  357.    i++;
  358.  }
  359. }
  360. function registerSystemEvent(event) {
  361.    registerEvent(event['type'], event['function']);
  362. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top