Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
onUp(pointer) {
const { navMesh, spriteGroup } = this;
const isRightButton = pointer.rightButton.isDown;
const { withinGame, worldX, worldY } = pointer;
const paths = [];
if (!withinGame || !isRightButton || !navMesh) {
return;
}
const destination = new Point(worldX, worldY);
spriteGroup.forEachAlive(sprite => {
const { position, width, height } = sprite;
const size = Math.max(width, height);
const path = navMesh.getPath(position, destination, size);
// If no path found, do nothing with the sprite
if (!path) {
return sprite.addPath([]);
}
paths.push(path);
sprite.addPath(path);
}, this);
this.renderPaths(paths);
}
/*
* Star
* ====
*
* Individual star paritcles in the background star emitters
*/
import Phaser from 'phaser-ce';
console.log(Phaser)
export default class Star extends Phaser.Particle {
constructor(game, x, y) {
super(game, x, y, Star.getTexture(game));
this.checkWorldBounds = true;
this.events.onOutOfBounds.add(this.__resetPos, this);
}
__resetPos() {
this.x = this.game.world.width * Math.random();
this.y = 0;
}
static getTexture(game) {
const radius = 12;
import Phaser from 'phaser-ce'
import config from '../config'
import Keyboard from '../objects/Keyboard'
import { makeGreen } from '../utils'
import Db from '../objects/Db'
export default class extends Phaser.State {
init(action, finalScore = 300, highScore = 0) {
this.game.add.plugin(window.PhaserInput.Plugin)
this.jumpInputs = Keyboard.addKeyboard(this.game)
this.enterKey = Keyboard.addEnter(this.game)
this.action = action
this.finalScore = finalScore
this.highScore = highScore
this.db = new Db(this.game)
}
create() {
const game = this.game
const { width, height } = game
const { lg, xl, center } = config.text
updateMarker({ leftButton, worldX, worldY }, originalEvent, c) {
const { tileLayer, tileMap } = this;
if (this.isSpriteStamp) {
return this.updateSprite(leftButton, worldX, worldY);
}
this.stamp && this.stamp.clear();
const tile = Math.floor(PhaserMath.random(0, COLLISION_INDICES.length));
const x = tileLayer.getTileX(worldX) * TILE_SIZE;
const y = tileLayer.getTileY(worldY) * TILE_SIZE;
if (leftButton.isDown) {
tileMap.putTile(tile, tileLayer.getTileX(x), tileLayer.getTileY(y), tileLayer);
this.updateNavMesh(1000);
}
}
const startAtY = 3;
const yLength = startAtY + 10;
let y = startAtY;
let xLength;
let x;
let tileIndex;
for (y; y < yLength; y++) {
x = startAtX;
xLength = startAtX + 20;
for (x; x < xLength; x++) {
if (x !== startAtX && y !== startAtY && x !== xLength - 4 && y !== yLength - 1) {
continue;
}
tileIndex = Math.floor(PhaserMath.random(0, COLLISION_INDICES.length));
tileMap.putTile(tileIndex, x, y, tileLayer);
}
}
}
PhaserCEBridge.prototype.isMySkin = function (skin) {
return skin instanceof PIXI.DisplayObject;
};
/**
public isMySkin(skin:any):boolean
{
return skin instanceof PIXI.DisplayObject;
}
constructor(game, x, y, group, tileLayer) {
super(game, x, y, 'agent');
this.path = DEFAULT_PATH;
this.anchor.setTo(ANCHOR, ANCHOR);
this.tileLayer = tileLayer;
game.physics.enable(this, Physics.ARCADE);
game.world.bringToTop(this);
group.add(this);
}
import 'phaser';
import { Game } from 'phaser-ce';
import DemoState from './demoState';
const config = {
width: 800,
height: 600,
renderer: Phaser.AUTO,
parent: '',
transparent: false,
antialias: true,
physicsConfig: { arcade: true }
};
const game = new Game(config);
game.state.add('demo', DemoState);
game.state.start('demo');
this.drawAllGround();
this.drawInitGrid();
this.updateNavMesh();
game.input.addMoveCallback(this.updateMarker, this);
game.input.onUp.add(this.onUp, this);
game.canvas.oncontextmenu = this.onRightClick;
this.cursors = game.input.keyboard.createCursorKeys();
this.isSpriteStamp = false;
this.spriteUUIDs = [];
game.input.keyboard.addKey(Keyboard.P).onDown.add(() => game.paused = !game.paused, this);
game.input.keyboard.addKey(Keyboard.SPACEBAR).onDown.add(() => game.paused = !game.paused, this);
game.input.keyboard.addKey(Keyboard.S).onDown.add(() => this.isSpriteStamp = !this.isSpriteStamp);
game.input.keyboard.addKey(Keyboard.K).onDown.add(() => this.removeSprite());
this.spriteGroup = new Phaser.Group(game);
new DemoSprite(game, 200, 500, this.spriteGroup, this.tileLayer);
}