Created
February 24, 2019 10:27
-
-
Save harrybanda/46a7552903fbe02b04653927891cbdf3 to your computer and use it in GitHub Desktop.
Virtual Coder Level Handing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function update(args, ctx) { | |
var area = 0.05; // Area for robot to stand on | |
var yOffset = 0.22; // Offset on the Y axis | |
var py = 0.21; // Y position on 3D space | |
// Check if robot has reached the on goal | |
if (isBetween(ctx.entity.getTranslation().x, ctx.goalx + area, ctx.goalx - area) | |
&& isBetween(ctx.entity.getTranslation().z, ctx.goalz + area, ctx.goalz - area) | |
&& ctx.entity.getTranslation().y === py) { | |
ctx.entity.setTranslation(ctx.goalx, yOffset, ctx.goalz); | |
clearInterval(ctx.worldData.intervalId); | |
SystemBus.emit('levelComplete'); // Emit a message to switch the level | |
// Make AI host talk if level is complete | |
ctx.worldData.speech.updateConfig({body: lvlCompleteSpeech(ctx)}); | |
setTimeout(() => { | |
ctx.worldData.speech.play().then(() => { | |
if (lvlNum === 11) { | |
document.getElementById("btnNext").innerText = 'First'; | |
} else { | |
document.getElementById("btnNext").innerText = 'Next'; | |
} | |
document.getElementById("btnNext").style.display = 'block'; | |
}); | |
}, 1000); | |
} | |
// Check if the robot makes a wrong move | |
for (var i = 0; i < ctx.dangerZones.length; i++) { | |
if (isBetween(ctx.entity.getTranslation().x, ctx.dangerZones[i][0] + area, ctx.dangerZones[i][0] - area) | |
&& isBetween(ctx.entity.getTranslation().z, ctx.dangerZones[i][1] + area, ctx.dangerZones[i][1] - area) | |
&& ctx.entity.getTranslation().y === py) { | |
ctx.entity.setTranslation(ctx.dangerZones[i][0], yOffset, ctx.dangerZones[i][1]); | |
clearInterval(ctx.worldData.intervalId); | |
SystemBus.emit('wrongWay'); // Emit a message restart the level | |
ctx.worldData.speech.updateConfig({body: wrongMoveSpeech()}); | |
setTimeout(() => { | |
ctx.worldData.speech.play(); | |
}, 1000); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment