129 lines
3.0 KiB
JavaScript
129 lines
3.0 KiB
JavaScript
function Automaton(async, dom, messaging, screen, session, ui) {
|
|
var menus = {
|
|
start: {
|
|
entries: [
|
|
{label: 'New Game', action: newGame, close: true},
|
|
{label: 'Settings', action: settings}
|
|
],
|
|
cancel: intro,
|
|
name: 'start'
|
|
},
|
|
settings: {
|
|
entries: [
|
|
{label: 'Buttons', action: ui.setLayout},
|
|
{label: 'Text speed', action: function() {
|
|
ui.setTextSpeed(choices.textSpeed);
|
|
}}
|
|
],
|
|
cancel: function() {},
|
|
name: 'settings'
|
|
}
|
|
};
|
|
var choices = {
|
|
name: {
|
|
entries: [
|
|
{label: 'Alex', value: 'Alex'},
|
|
{label: 'Lenore', value: 'Lenore'},
|
|
{label: 'Thomas', value: 'Thomas'},
|
|
{label: null, size: 15}
|
|
],
|
|
name: 'name'
|
|
},
|
|
skin: {
|
|
},
|
|
textSpeed: {
|
|
entries: [
|
|
{label: 'Slow', value: 'slow'},
|
|
{label: 'Medium', value: 'medium'},
|
|
{label: 'Fast', value: 'fast'}
|
|
],
|
|
cancel: function() {},
|
|
name: 'textSpeed'
|
|
}
|
|
};
|
|
var game = session.getGame();
|
|
if(game != undefined) {
|
|
menus.start.entries.unshift(
|
|
{label: 'Continue', action: function() { messaging.send({tag: 'Resume', game: game}); }}
|
|
);
|
|
}
|
|
intro();
|
|
|
|
return {};
|
|
|
|
function intro() {
|
|
var title = dom.make('p', {textContent: "P O K E M O N", class: 'title'});
|
|
var subtitle = dom.make('p', {textContent: "< press start >", class: 'subtitle'});
|
|
ui.frame('Intro');
|
|
async.run(
|
|
ui.cinematic([
|
|
{action: function() {}, delay: 500},
|
|
{action: function() { screen.show(title); }, delay: 1000},
|
|
{action: function() { screen.show(subtitle); }, delay: null}
|
|
], {
|
|
B: function() { intro(); },
|
|
Start: startMenu
|
|
})
|
|
);
|
|
}
|
|
|
|
function startMenu() {
|
|
ui.frame('Start');
|
|
ui.menu(menus.start);
|
|
}
|
|
|
|
function settings() {
|
|
ui.menu(menus.settings);
|
|
}
|
|
|
|
function newGame() {
|
|
var message = { tag: 'Initialize' };
|
|
var set = function(key) {
|
|
return function(value) {
|
|
message[key] = value;
|
|
return async.wrap(value);
|
|
};
|
|
};
|
|
ui.frame('GameInit');
|
|
messaging.send({tag: 'NewGame'});
|
|
async.run(
|
|
session.update(),
|
|
async.bind(
|
|
askName(),
|
|
set('name'),
|
|
askSkin,
|
|
set('skin'),
|
|
askGender,
|
|
set('gender')
|
|
),
|
|
async.apply(messaging.send, message)
|
|
);
|
|
}
|
|
|
|
function askName() {
|
|
return async.sequence(
|
|
async.sequence(
|
|
ui.text("Bonjour ! Bienvenue dans le monde merveilleux des pokémons !"),
|
|
ui.text("Pour certains, les pokemons sont des amis. Pour d'autres, ils sont une ressource. Pour ma part, hé bien l'étude des pokémons est mon métier mais aussi ma passion."),
|
|
ui.text("Mais, dis-moi, tu viens d'arriver dans la ville non ? Comment t'appelles-tu ?")
|
|
),
|
|
ui.ask(choices.name)
|
|
);
|
|
}
|
|
|
|
function askSkin(name) {
|
|
return async.sequence(
|
|
async.apply(screen.clear, 'text'),
|
|
ui.text("Ah ? Tu t'appelles " + name + " ? C'est un joli nom, ma foi. Mais je ne te vois pas très bien avec le jour tombant, dis-moi, à quoi ressembles-tu ?"),
|
|
async.wrap('/images/characters/0.png')
|
|
);
|
|
}
|
|
|
|
function askGender() {
|
|
return async.sequence(
|
|
async.apply(screen.clear, 'text'),
|
|
async.wrap('NB')
|
|
);
|
|
}
|
|
}
|