breakout/startmenu.js
2023-06-07 13:40:13 +00:00

101 lines
2.4 KiB
JavaScript

var startgame = function()
{
run("breakout.js");
Player.players[0].uncontrol(startcontroller);
unregister_gui(startmenu);
};
var exitgame = function()
{
quit();
};
var colorshifter = {
color: Color.green,
font_size: 1,
};
var colorshiftend = {
color: Color.blue,
font_size: 1.5
};
var options = GUI.column({
items: [
GUI.text_fn("START", {action: startgame}),
GUI.text_fn("EXIT", {action: exitgame}),
],
hovered: {},
});
Tween.embed(options, 'hovered', [colorshifter, colorshiftend], {time: 0.35, loop: "yoyo", whole: false, ease: Ease.sine.out});
var rainbowchain = [
[255,0,0,255],
[255,255,0,255],
[0,255,0,255],
[0,255,255,255],
[0,0,255,255],
[255,0,255,255],
];
var idx = 0;
var item = options.items[idx];
item.selected = true;
var menuopts = {
superpos: [0,0],
color: [],
};
var stt = Tween.embed(menuopts, 'superpos', [Window.dimensions.scale([0.4,0.9]), Window.dimensions.scale([0.6,0.9])], {
time: 1,
loop: "circle",
whole: false,
ease: Ease.cubic.inout
});
Tween.embed(menuopts, 'color', rainbowchain, {time: 1, loop: "circle", whole: false});
var background_gui = GUI.image_fn({path:"hexagon_pattern_gray.png", color: Color.red, width: Window.width, height: Window.height, image_repeat: true});
Tween.embed(background_gui, 'image_repeat_offset', [[0,0], [1,1]], {time: 1, loop: "repeat"});
Tween.embed(background_gui, 'color', [Color.red, Color.blue], {time: 3, loop: "circle"});
function startmenu() {
background_gui.draw([0,0]);
stt.update_vals([Window.dimensions.scale([0.4,0.9]), Window.dimensions.scale([0.6,0.9])]);
GUI.text_fn("SUPER BREAKOUT", {font_size:6, anchor: [0.5,0.5], color: menuopts.color}).draw(menuopts.superpos);
options.draw(Window.dimensions.scale([0.5,0.5]));
// GUI.image_fn({path:"arrow.png", anchor: [1,0.5]}).draw([item.bb.l, (item.bb.b + item.bb.t)/2].add([-3,1]));
}
register_gui(startmenu);
var startcontroller = {
input_s_pressed() {
item.selected = false;
idx = Math.clamp(idx+1, 0, options.items.length-1);
item = options.items[idx];
item.selected = true;
},
input_w_pressed() {
item.selected = false;
idx = Math.clamp(idx-1, 0, options.items.length-1);
item = options.items[idx];
item.selected = true;
},
input_enter_pressed() {
item.action();
},
input_escape_pressed() {
quit();
},
};
Player.players[0].control(startcontroller);