start menu fixed

This commit is contained in:
John Alanbrook 2023-09-06 17:17:33 +00:00
parent cbeab6af8b
commit 52d08ec085
3 changed files with 25 additions and 33 deletions

View file

@ -24,7 +24,7 @@ f.draw = function() {
Debug.line(f.edge2d.points, Color.green, 0, f.edge2d.thickness*2); Debug.line(f.edge2d.points, Color.green, 0, f.edge2d.thickness*2);
}; };
register_draw(f.draw,f); Register.draw.register(f.draw,f);
var fitbricks = Math.floor(lvlwidth/bwidth); var fitbricks = Math.floor(lvlwidth/bwidth);
@ -33,7 +33,7 @@ var wingame = function() {
Log.warn("WINNER"); Log.warn("WINNER");
Player.players[0].uncontrol(paddle); Player.players[0].uncontrol(paddle);
register_gui(function() { Register.gui.register(function() {
GUI.text("WINNER", Window.dimensions.scale(0.5)); GUI.text("WINNER", Window.dimensions.scale(0.5));
}); });
} }
@ -277,7 +277,7 @@ var pause = {
}, },
unpause() { unpause() {
unregister_gui(pause.gui); Register.gui.unregister(pause.gui);
sim_start(); sim_start();
}, },
@ -291,7 +291,7 @@ var pause = {
var gamepawn = var gamepawn =
{ {
pause() { pause() {
register_gui(pause.gui); Register.gui.register(pause.gui);
sim_pause(); sim_pause();
}, },
@ -332,7 +332,7 @@ function gamegui() {
}).draw(Window.dimensions.scale([0.8,0.8])); }).draw(Window.dimensions.scale([0.8,0.8]));
} }
register_gui(gamegui); Register.gui.register(gamegui);
Player.players[0].control(gamepawn); Player.players[0].control(gamepawn);
@ -340,6 +340,6 @@ let backtomain = function()
{ {
World.clear(); World.clear();
run("startmenu.js"); run("startmenu.js");
unregister_gui(gamegui); Register.gui.unregister(gamegui);
Player.players[0].uncontrol(gamepawn); Player.players[0].uncontrol(gamepawn);
} }

View file

@ -1 +1,2 @@
Window.icon("powerup.png");
load("startmenu.js"); load("startmenu.js");

View file

@ -2,12 +2,12 @@ var startgame = function()
{ {
run("breakout.js"); run("breakout.js");
Player.players[0].uncontrol(startcontroller); Player.players[0].uncontrol(startcontroller);
unregister_gui(startmenu); Register.gui.unregister(startmenu);
}; };
var exitgame = function() var exitgame = function()
{ {
quit(); Game.quit();
}; };
var colorshifter = { var colorshifter = {
@ -25,7 +25,6 @@ var options = GUI.column({
GUI.text_fn("START", {action: startgame}), GUI.text_fn("START", {action: startgame}),
GUI.text_fn("EXIT", {action: exitgame}), GUI.text_fn("EXIT", {action: exitgame}),
], ],
hovered: {},
}); });
Tween.embed(options, 'hovered', [colorshifter, colorshiftend], {time: 0.35, loop: "yoyo", whole: false, ease: Ease.sine.out}); Tween.embed(options, 'hovered', [colorshifter, colorshiftend], {time: 0.35, loop: "yoyo", whole: false, ease: Ease.sine.out});
@ -68,37 +67,29 @@ function startmenu() {
options.draw(Window.dimensions.scale([0.5,0.5])); 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])); GUI.image_fn({path:"coin.png", anchor: [1,0.5]}).draw([item.bb.l, (item.bb.b + item.bb.t)/2].add([-3,1]));
} }
register_gui(startmenu); Register.gui.register(startmenu);
var startcontroller = { var startcontroller = {};
input_s_pressed() { startcontroller.inputs = {};
startcontroller.inputs.s = function() {
item.selected = false; item.selected = false;
idx = Math.clamp(idx+1, 0, options.items.length-1); idx = Math.clamp(idx+1, 0, options.items.length-1);
item = options.items[idx]; item = options.items[idx];
item.selected = true; item.selected = true;
}, };
input_w_pressed() { startcontroller.inputs.w = function() {
item.selected = false; item.selected = false;
idx = Math.clamp(idx-1, 0, options.items.length-1); idx = Math.clamp(idx-1, 0, options.items.length-1);
item = options.items[idx]; item = options.items[idx];
item.selected = true; item.selected = true;
},
input_enter_pressed() {
item.action();
},
input_escape_pressed() {
quit();
},
}; };
Player.players[0].control(startcontroller); startcontroller.inputs.enter = function() { Log.warn("TEST"); item.action(); };
Player.players[0].control(startcontroller);
Game.play();
run("file1.js");
run("file2.js");
Log.warn(x);