passives
This commit is contained in:
parent
8b60f26fc5
commit
d4bf444021
86
client/src/components/phaser.passives.js
Executable file
86
client/src/components/phaser.passives.js
Executable file
@ -0,0 +1,86 @@
|
|||||||
|
const Phaser = require('phaser');
|
||||||
|
const PassiveNode = require('./passive.node');
|
||||||
|
|
||||||
|
|
||||||
|
class PhaserPassives extends Phaser.Scene {
|
||||||
|
preload() {
|
||||||
|
this.load.image('eye', 'https://labs.phaser.io/assets/particles/green-orb.png');
|
||||||
|
}
|
||||||
|
|
||||||
|
create() {
|
||||||
|
this.passiveNodes = [
|
||||||
|
{ x: 400, y: 300, id: 'A', alloc: false },
|
||||||
|
{ x: 100, y: 100, id: 'B', alloc: false },
|
||||||
|
{ x: 300, y: 200, id: 'C', alloc: false },
|
||||||
|
{ x: 300, y: 800, id: 'D', alloc: false },
|
||||||
|
{ x: 600, y: 500, id: 'E', alloc: false },
|
||||||
|
{ x: 700, y: 400, id: 'F', alloc: false }];
|
||||||
|
|
||||||
|
this.passiveEdges = [
|
||||||
|
['A', 'B'],
|
||||||
|
['F', 'A'],
|
||||||
|
['D', 'A'],
|
||||||
|
];
|
||||||
|
|
||||||
|
this.graphics = this.add.graphics();
|
||||||
|
this.addCamera();
|
||||||
|
this.addPassiveNodes();
|
||||||
|
this.drawPassiveEdges();
|
||||||
|
}
|
||||||
|
|
||||||
|
addPassiveNodes() {
|
||||||
|
this.passiveNodes.forEach((n) => {
|
||||||
|
this.add.existing(new PassiveNode(this, n.x, n.y, n.id, n.alloc)).setInteractive();
|
||||||
|
});
|
||||||
|
this.input.on('pointerover', (event, gameObjects) => {
|
||||||
|
if (gameObjects[0] instanceof PassiveNode) {
|
||||||
|
if (!gameObjects[0].alloc) gameObjects[0].setTint(0xff00ff);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.input.on('pointerout', (event, gameObjects) => {
|
||||||
|
if (gameObjects[0] instanceof PassiveNode) {
|
||||||
|
if (!gameObjects[0].alloc) gameObjects[0].clearTint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.input.on('pointerdown', (event, gameObjects) => {
|
||||||
|
if (gameObjects[0] instanceof PassiveNode) {
|
||||||
|
gameObjects[0].allocate();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
drawPassiveEdges() {
|
||||||
|
this.graphics.clear();
|
||||||
|
this.passiveEdges.forEach((e) => {
|
||||||
|
const drawEdge = this.passiveNodes.filter(n => (e[0] === n.id || e[1] === n.id));
|
||||||
|
if (drawEdge[0].alloc && drawEdge[1].alloc) {
|
||||||
|
this.graphics.lineStyle(50, 0xfff00f, 0.2);
|
||||||
|
} else {
|
||||||
|
this.graphics.lineStyle(10, 0x00ffff, 0.2);
|
||||||
|
}
|
||||||
|
this.graphics.lineBetween(drawEdge[0].x, drawEdge[0].y, drawEdge[1].x, drawEdge[1].y);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
addCamera() {
|
||||||
|
this.cursors = this.input.keyboard.createCursorKeys();
|
||||||
|
this.controls = new Phaser.Cameras.Controls.SmoothedKeyControl({
|
||||||
|
camera: this.cameras.main,
|
||||||
|
left: this.cursors.left,
|
||||||
|
right: this.cursors.right,
|
||||||
|
up: this.cursors.up,
|
||||||
|
down: this.cursors.down,
|
||||||
|
zoomIn: this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.Q),
|
||||||
|
zoomOut: this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.E),
|
||||||
|
acceleration: 0.005,
|
||||||
|
drag: 0.0005,
|
||||||
|
maxSpeed: 0.001,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
update(delta) {
|
||||||
|
this.controls.update(delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = PhaserPassives;
|
||||||
Loading…
x
Reference in New Issue
Block a user