Skip to content

Commit 4c0c8d5

Browse files
committed
Replace directional input for peke
1 parent 31352ac commit 4c0c8d5

1 file changed

Lines changed: 30 additions & 6 deletions

File tree

src/variety/bunnyhop.js

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,37 @@
2020
this.inputpeke();
2121
}
2222
},
23-
inputpeke: function() {
24-
// TODO replace with triangle inputs
25-
this.inputarrow_cell();
23+
24+
mousereset: function() {
25+
this.prevPekeDir = 0;
26+
this.common.mousereset.call(this);
2627
},
27-
inputarrow_cell_main: function(cell, dir) {
28-
var value = 1 << (dir + 1);
29-
cell.setQsub(cell.qsub ^ value);
28+
29+
inputpeke: function() {
30+
var cell = this.getcell();
31+
if (!cell.isValid()) {
32+
return;
33+
}
34+
35+
var dx = this.inputPoint.bx - cell.bx,
36+
dy = this.inputPoint.by - cell.by;
37+
38+
var dir = 0;
39+
if (Math.abs(dx) > Math.abs(dy)) {
40+
dir = dx > 0.2 ? 4 : dx < -0.2 ? 3 : 0;
41+
} else {
42+
dir = dy > 0.2 ? 2 : dy < -0.2 ? 1 : 0;
43+
}
44+
45+
if (dir && (dir !== this.prevPekeDir || this.mouseCell !== cell)) {
46+
this.mouseCell = cell;
47+
this.prevPekeDir = dir;
48+
49+
// TODO inputData for set/unset instead of xor
50+
var value = 1 << (dir + 1);
51+
cell.setQsub(cell.qsub ^ value);
52+
cell.draw();
53+
}
3054
},
3155

3256
inputLine: function() {

0 commit comments

Comments
 (0)