Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Language - Used for Phrases Pronounced
- var language = {
- 'welcome': 'Welcome',
- 'cycle_execute': 'When you hear a mode you would like to select, hit the gyrosphere.',
- 'welcome_to_hot_potato': 'Welcome to hot potato. Pass me before five seconds is up or loose. Throw me now to get started.',
- 'hot_potato_lost': 'This game has ended. Better luck next time!',
- 'new_color': 'I have a new color!',
- 'throwit_start': 'Welcome to throw it! I count your throws.',
- 'hot_Potato_reset': 'Charge detected. Flying status reset.',
- 'hot_potato_flying': 'I am flying.',
- 'hot_potato_reset_please': 'If I have landed already, please place me on my dock to reset flight status',
- 'charging': 'I am now charging.',
- 'remove_dock': 'You need to remove me from my dock before selecting a mode.',
- 'timer_paused': 'Timer paused.',
- 'timer_started': 'Timer started, shake to pause.',
- 'timer_restarted': 'Timer restarted.'
- };
- // [MODE] Cycle
- function actionCycle(eventKey) {
- switch(eventKey) {
- case 1:
- actionCycleStart();
- break;
- case 2:
- actionCycleCollision();
- break;
- case 6:
- actionCycleCharging();
- break;
- case 7:
- actionCycleNotCharging();
- break;
- }
- }
- async function actionCycleStart() {
- await speak(language['cycle_execute'], true);
- for (var i = 0; i < modes.length; i++) {
- if (modes[i]['announce']) {
- await delay(2);
- if (handler != actionCycle) {
- return;
- }
- data['cycle_select'] = i;
- await speak(modes[i]['title'], true);
- }
- }
- }
- async function actionCycleCollision() {
- if (data['charging']) {
- await speak(language['remove_dock'], true);
- return;
- }
- if (data['cycle_select'] !== null) {
- handler = modes[data['cycle_select']]['actionHandler'];
- handler(1);
- }
- }
- async function actionCycleCharge() {
- await speak(language['charging'], true);
- data['charging'] = true;
- }
- async function actionCycleNotCharging() {
- data['charging'] = false;
- }
- // [MODE] Hot Potato
- function actionHotPotato(eventKey) {
- switch(eventKey) {
- case 1:
- actionHotPotatoStart();
- break;
- case 3:
- actionHotPotatoLanding();
- break;
- case 4:
- actionHotPotatoFreefall();
- break;
- case 6:
- actionHotPotatoCharging();
- break;
- }
- }
- async function actionHotPotatoStart() {
- await setBackLed(125);
- await roll(255, 255, 5);
- await speak(language['welcome_to_hot_potato'], true);
- data['hot_potato_playing'] = true;
- data['hot_potato_counter'] = 0;
- data['hot_potato_flighttime'] = 0;
- data['hot_potato_counted'] = false;
- }
- async function actionHotPotatoLanding() {
- if (data['hot_potato_counted']) {
- data['hot_potato_flying'] = false;
- data['hot_potato_flighttime'] = 0;
- }
- if (data['hot_potato_playing'] && !data['hot_potato_counted']) {
- await setBackLed(25);
- data['hot_potato_counted'] = true;
- while (data['hot_potato_counter'] < 6) {
- while(data['hot_potato_flying']) {
- await speak(language['hot_potato_flying'], true);
- data['hot_potato_flighttime']++;
- if (data['hot_potato_flighttime'] > 6) {
- await speak(language['hot_potato_reset_please'], true);
- }
- velocity = Math.sqrt((getVelocity().x ** 2) + (getVelocity().y ** 2));
- if (velocity < 150) {
- data['hot_potato_flighttime'] = 0;
- data['hot_potato_flying'] = false;
- }
- }
- data['hot_potato_flighttime'] = 0;
- if (data['hot_potato_counter'] == 5) {
- await setBackLed(255);
- await speak(language['hot_potato_lost'], true);
- handler = actionCycle;
- handler(1);
- }
- await delay(1);
- data['hot_potato_counter']++;
- await speak(data['hot_potato_counter'].toString(), true);
- }
- }
- }
- async function actionHotPotatoFreefall() {
- data['hot_potato_counter'] = 0;
- data['hot_potato_flying'] = true;
- }
- async function actionHotPotatoCharging() {
- if (data['hot_potato_flying']) {
- await speak(language['hot_Potato_reset']);
- data['hot_potato_flying'] = false;
- } else {
- handler = actionCycle;
- handler(1);
- }
- }
- // [MODE] Random Light
- async function actionRandomLight() {
- data['main_led_color'] = getRandomColor();
- await setMainLed(data['main_led_color']);
- await speak(language['new_color'], true);
- handler = actionCycle;
- handler(1);
- }
- // [MODE] ThrowIt!
- function actionThrowIt(eventKey) {
- switch(eventKey) {
- case 1:
- actionThrowItStart();
- break;
- case 4:
- actionThrowItFreefall();
- break;
- case 6:
- actionThrowItCharging();
- break;
- }
- }
- async function actionThrowItStart() {
- await speak(language['throwit_start'], true);
- data['throwit_throws'] = 0;
- }
- async function actionThrowItCharging() {
- if (data['throwit_throws'] > 1) {
- await speak(data['throwit_throws'], true);
- data['throwit_throws'] = 0;
- } else {
- handler = actionCycle;
- handler(1);
- }
- }
- async function actionThrowItFreefall() {
- data['throwit_throws']++;
- await setMainLed(getRandomColor());
- await speak(data['throwit_throws'].toString(), true);
- }
- // [MODE] Explore
- function actionExplore(eventKey) {
- switch(eventKey) {
- case 1:
- actionExploreStart();
- break;
- case 2:
- actionExploreCollision();
- break;
- case 6:
- actionExploreCharging();
- break;
- }
- }
- async function actionExploreStart() {
- data['explore_direction'] = 0;
- data['explore_time'] = 0;
- data['explore_seconds'] = 1;
- while(true) {
- await roll(data['explore_direction'], 255, data['explore_seconds']);
- velocity = Math.sqrt((getVelocity().x ** 2) + (getVelocity().y ** 2));
- if (velocity < 40) data['explore_direction'] = data['explore_direction'] + 10;
- data['explore_time']++;
- if (data['explore_time'] > 30) {
- data['explore_time'] = 0;
- data['explore_seconds']++;
- }
- }
- }
- async function actionExploreCollision() {
- data['explore_direction'] + 15;
- }
- async function actionExploreCharging() {
- handler = actionCycle;
- handler(1);
- }
- // [MODE] Recycle - Reruns Cycle
- async function actionRecycle(eventKey) {
- handler = actionCycle;
- handler(1);
- }
- // [MODE] Timer - Times Things
- function actionTimer(eventKey) {
- switch(eventKey) {
- case 1:
- actionTimerStart();
- break;
- case 2:
- actionTimerPause();
- break;
- case 6:
- actionTimerCharging();
- break;
- }
- }
- async function actionTimerStart() {
- data['timer_running'] = true;
- data['timer_time'] = 0;
- await speak(language['timer_started'], true);
- while(data['timer_running']) {
- await delay(1);
- data['timer_time']++;
- }
- }
- async function actionTimerPause() {
- if (data['timer_running']) {
- data['timer_running'] = false;
- await speak(language['timer_paused'], true);
- } else {
- data['timer_running'] = true;
- await speak(language['timer_restarted'], true);
- }
- }
- async function actionTimerCharging() {
- await speak(data['timer_time'].toString(), true);
- handler = actionCycle;
- handler(1);
- }
- // Handler - Function That Should be Executed
- var handler = actionCycle;
- // Modes - Voiced in Cycle
- var modes = [
- {
- 'title': 'Cycle',
- 'announce': false,
- 'actionHandler': actionCycle,
- },
- {
- 'title': 'Timer',
- 'announce': true,
- 'actionHandler': actionTimer
- },
- {
- 'title': 'Hot Potato',
- 'announce': true,
- 'actionHandler': actionHotPotato
- },
- {
- 'title': 'Randomize Main Light Color',
- 'announce': true,
- 'actionHandler': actionRandomLight
- },
- {
- 'title': 'Throw It',
- 'announce': true,
- 'actionHandler': actionThrowIt
- },
- {
- 'title': 'Exploration',
- 'announce': true,
- 'actionHandler': actionExplore
- },
- {
- 'title': 'Recycle Through Modes',
- 'announce': true,
- 'actionHandler': actionRecycle
- }
- ];
- // Events - Registered on Startup
- var events = [
- {
- 'type': EventType.onCollision,
- 'function': onCollision
- },
- {
- 'type': EventType.onLanding,
- 'function': onLanding
- },
- {
- 'type': EventType.onFreefall,
- 'function': onFreefall
- },
- {
- 'type': EventType.onGyroMax,
- 'function': onGyroMax
- },
- {
- 'type': EventType.onCharging,
- 'function': onCharging
- },
- {
- 'type': EventType.onNotCharging,
- 'function': onNotCharging
- }
- ];
- // Data - Set by Individual Modes
- var data = [];
- // System Processing
- async function startProgram() {
- registerSystemEvents();
- executeStartExtras();
- handler(1);
- }
- async function executeStartExtras() {
- await speak(language['welcome'], true);
- }
- async function onCollision() {
- if (!data['lock']) handler(2);
- }
- async function onLanding() {
- if (!data['lock']) handler(3);
- }
- async function onFreefall() {
- if (!data['lock']) handler(4);
- }
- async function onGyroMax() {
- if (!data['lock']) handler(5);
- }
- async function onCharging() {
- handler(6);
- }
- async function onNotCharging() {
- handler(7);
- }
- function registerSystemEvents() {
- let i = 0;
- while (i < events.length) {
- registerSystemEvent(events[i]);
- i++;
- }
- }
- function registerSystemEvent(event) {
- registerEvent(event['type'], event['function']);
- }
Add Comment
Please, Sign In to add comment