Rejigger input parsing to be stateless and better match CC2; syncs SCAVENGER HUNT!
This commit is contained in:
parent
cfdbe0705a
commit
413fdce590
61
js/main.js
61
js/main.js
@ -966,66 +966,44 @@ class Player extends PrimaryView {
|
|||||||
let input = this.get_input();
|
let input = this.get_input();
|
||||||
|
|
||||||
// Replica of CC2 input handling, based on experimentation
|
// Replica of CC2 input handling, based on experimentation
|
||||||
// FIXME unclear how this should interact with undo when playing normally, and
|
let primary_action = null, secondary_action = null;
|
||||||
// definitely wrong when playing a replay; should this be in Level??
|
let current_action = DIRECTIONS[this.level.player.direction].action;
|
||||||
if ((input.has('up') && input.has('down')) || (input.has('left') && input.has('right'))) {
|
if ((input.has('up') && input.has('down')) || (input.has('left') && input.has('right'))) {
|
||||||
// If opposing keys are ever held, stop moving and forget our state
|
// If opposing keys are ever held, stop moving and forget our state
|
||||||
this.primary_action = null;
|
primary_action = null;
|
||||||
this.secondary_action = null;
|
secondary_action = null;
|
||||||
}
|
}
|
||||||
else if (this.primary_action && input.has(this.primary_action)) {
|
else if (input.has(current_action)) {
|
||||||
// Our primary action is locked in as long as it's held down, but check for a
|
// If we're already holding in the same direction we're facing, that wins
|
||||||
// newly pressed secondary action; remember, there can't be two opposing keys held,
|
primary_action = current_action;
|
||||||
// because we already checked for that above, so this is only necessary if there's
|
// Any other key we're holding is secondary; remember, there can't be two opposing
|
||||||
// not already a secondary action
|
// keys held, because we just checked for that, so at most one of these qualifies
|
||||||
if (this.secondary_action && ! input.has(this.secondary_action)) {
|
|
||||||
this.secondary_action = null;
|
|
||||||
}
|
|
||||||
if (! this.secondary_action) {
|
|
||||||
for (let action of ['down', 'left', 'right', 'up']) {
|
for (let action of ['down', 'left', 'right', 'up']) {
|
||||||
if (action !== this.primary_action &&
|
if (action !== primary_action && input.has(action)) {
|
||||||
input.has(action) && ! this.previous_input.has(action))
|
secondary_action = action;
|
||||||
{
|
|
||||||
this.secondary_action = action;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
// Either we weren't holding any keys, or we let go of our primary action; either
|
// Check for other keys, horizontal first
|
||||||
// way, act like we're starting from scratch and check keys in priority order
|
for (let action of ['left', 'right', 'up', 'down']) {
|
||||||
// TODO actually i'm not sure these are necessary if we check the player's facing
|
|
||||||
// first?
|
|
||||||
this.primary_action = null;
|
|
||||||
this.secondary_action = null;
|
|
||||||
|
|
||||||
// As a tiebreaker, first check if we're holding the key corresponding to the
|
|
||||||
// player's facing direction
|
|
||||||
let player_facing_action = DIRECTIONS[this.level.player.direction].action;
|
|
||||||
if (input.has(player_facing_action)) {
|
|
||||||
this.primary_action = player_facing_action;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let action of ['down', 'left', 'right', 'up']) {
|
|
||||||
if (! input.has(action))
|
if (! input.has(action))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (! this.primary_action) {
|
if (primary_action === null) {
|
||||||
this.primary_action = action;
|
primary_action = action;
|
||||||
}
|
}
|
||||||
else if (action !== this.primary_action) {
|
else {
|
||||||
// Note that because of the opposing keys check, there can never be more
|
secondary_action = action;
|
||||||
// than two keys held down here
|
|
||||||
this.secondary_action = action;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let player_actions = {
|
let player_actions = {
|
||||||
primary: this.primary_action ? ACTION_DIRECTIONS[this.primary_action] : null,
|
primary: primary_action ? ACTION_DIRECTIONS[primary_action] : null,
|
||||||
secondary: this.secondary_action ? ACTION_DIRECTIONS[this.secondary_action] : null,
|
secondary: secondary_action ? ACTION_DIRECTIONS[secondary_action] : null,
|
||||||
cycle: input.has('cycle') && ! this.previous_input.has('cycle'),
|
cycle: input.has('cycle') && ! this.previous_input.has('cycle'),
|
||||||
drop: input.has('drop') && ! this.previous_input.has('drop'),
|
drop: input.has('drop') && ! this.previous_input.has('drop'),
|
||||||
swap: input.has('swap') && ! this.previous_input.has('swap'),
|
swap: input.has('swap') && ! this.previous_input.has('swap'),
|
||||||
@ -1082,7 +1060,6 @@ class Player extends PrimaryView {
|
|||||||
if (dt < 10) {
|
if (dt < 10) {
|
||||||
num_advances = Math.ceil(10 / dt);
|
num_advances = Math.ceil(10 / dt);
|
||||||
dt = 10;
|
dt = 10;
|
||||||
console.log(this.play_speed, dt, num_advances);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.state === 'playing') {
|
if (this.state === 'playing') {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user