1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
'use strict'
const FnBase = require('./_base')
function FnP (pico, x, y) {
FnBase.call(this, pico, x, y)
this.name = 'push'
this.glyph = 'p'
this.info = 'Moves away, on bang.'
this.ports = [{ x: 0, y: 0, bang: true }]
this.operation = function () {
const origin = this.bang()
if (!origin) { return }
const direction = { x: this.x - origin.x, y: this.y - origin.y }
const pushed = this.neighbor_by(direction.x, direction.y)
this.move(direction.x, direction.y)
if (pushed) {
pico.add(this.x + (direction.x * 2), this.y + (direction.y * 2), pushed.glyph)
}
}
this.n_offset = function (pos) {
return { x: this.x - pos.x, y: this.y - pos.y }
}
}
module.exports = FnP
|