avatar-commander-ai / script.js
Danyray101's picture
Create a Ai system that allows a person to control an avatar in real language and make the avatar do different commands and answer questions and other useful things
744a895 verified
// Main application logic
class AvatarCommander {
constructor() {
this.commands = {
'wave': this.handleWave,
'dance': this.handleDance,
'jump': this.handleJump,
'answer': this.handleAnswer,
'help': this.handleHelp
};
this.answers = {
'hello': 'Hello there! How can I help you today?',
'age': "I'm an AI, I don't have an age!",
'creator': 'I was created by talented developers using cutting-edge AI technology.',
'weather': 'I can check the weather for you if you tell me your location!',
'joke': 'Why don\'t skeletons fight each other? They don\'t have the guts!'
};
}
handleCommand(command) {
const parts = command.toLowerCase().split(' ');
const action = parts[0];
if (this.commands[action]) {
return this.commands[action](parts.slice(1).join(' '));
} else {
return this.handleDefault(command);
}
}
handleWave() {
document.querySelector('#avatar').classList.add('animate-wave');
setTimeout(() => {
document.querySelector('#avatar').classList.remove('animate-wave');
}, 2000);
return "I'm waving at you! πŸ‘‹";
}
handleDance() {
// Would trigger dance animation in a real implementation
return "πŸ’ƒ Dancing like nobody's watching! πŸ•Ί";
}
handleJump() {
// Would trigger jump animation in a real implementation
return "Jumping high! 🦘";
}
handleAnswer(question) {
for (const [key, value] of Object.entries(this.answers)) {
if (question.includes(key)) {
return value;
}
}
return "I'm not sure I understand that question. Try asking something else!";
}
handleHelp() {
return "Available commands: wave, dance, jump, answer [question]. Try saying 'wave' or 'answer what's your age?'";
}
handleDefault() {
return "I didn't understand that command. Type 'help' to see what I can do!";
}
}
// Initialize the commander when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
window.avatarCommander = new AvatarCommander();
});