Add gamepad support

This commit is contained in:
2023-04-25 19:59:26 +00:00
parent 9b1cead91e
commit dc1fda6611
9 changed files with 2051 additions and 39 deletions

View File

@@ -40,6 +40,16 @@ var sprite = clone(component, {
this._pos = x;
this.sync();
},
input_kp9_pressed() { this.pos = [0,0]; },
input_kp8_pressed() { this.pos = [-0.5,0]; },
input_kp7_pressed() { this.pos = [-1,0]; },
input_kp6_pressed() { this.pos = [0,-0.5]; },
input_kp5_pressed() { this.pos = [-0.5,-0.5]; },
input_kp4_pressed() { this.pos = [-1,-0.5]; },
input_kp3_pressed() { this.pos = [0, -1]; },
input_kp2_pressed() { this.pos = [-0.5,-1]; },
input_kp1_pressed() { this.pos = [-1,-1]; },
get boundingbox() {
if (!this.gameobject) return null;

View File

@@ -1191,7 +1191,7 @@ var editor = {
if (!Keys.ctrl()) return;
if (this.edit_level.dirty) {
Log.warn("Level has changed; save before starting a new one.");
Log.info("Level has changed; save before starting a new one.");
this.openpanel(gen_notify("Level is changed. Are you sure you want to close it?", _ => this.clear_level()));
return;
}
@@ -2432,7 +2432,8 @@ var gen_notify = function(val, fn) {
var panel = Object.create(notifypanel);
panel.msg = val;
panel.yes = fn;
panel.input_y_pressed = function() { panel.yes(); this.close(); };
panel.input_y_pressed = function() { panel.yes(); panel.close(); };
panel.input_enter_pressed = function() { panel.close(); };
return panel;
};

View File

@@ -1,4 +1,3 @@
var Log = {
set level(x) { cmd(92,x); },
get level() { return cmd(93); },
@@ -407,6 +406,22 @@ var physics = {
},
};
/* May be a human player; may be an AI player */
var Player = {
pawns: [],
input(fn, ...args) {
this.pawns.forEach(x => if (fn in x) x[fn](...args));
},
control(pawn) {
this.pawns.pushunique(pawn);
},
uncontrol(pawn) {
this.pawns = this.pawns.filter(x => x !== pawn);
}
};
var Register = {
updates: [],
update(dt) {
@@ -433,14 +448,12 @@ var Register = {
this.pawns.forEach(x => {
if (fn in x) {
x[fn](...args);
return;
var f = x[fn];
if (typeof f !== 'function') return;
x.f(...args);
}
});
},
controller_input(
debugs: [],
debug() {
this.debugs.forEach(x => x[0].call(x[1]));

5
source/scripts/play.js Normal file
View File

@@ -0,0 +1,5 @@
if (load("game.js") === false) {
Log.error("No game.js. No game.");
quit();
}