Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'use strict'
import Phaser from 'phaser';
import loki from './../utils/lokijs/lokijs.min.js';
import IsArray from './../utils/array/IsArray.js';
const GetFastValue = Phaser.Utils.Objects.GetFastValue;
const instDB = new loki(); // global db for all scenes
class InstDBPlugin {
constructor(scene, config) {
this.scene = scene;
this.systems = scene.sys;
this.collName = scene.sys.settings.key;
this.coll = instDB.addCollection(this.collName, {
disableMeta: true
});
this.boot();
}
boot() {
var eventEmitter = this.systems.events;
var self = {};
var Phaser = require('phaser');
var {game} = require('./scope');
self.colorCase = function(color){
return color.indexOf('#') != -1 ? '0x'+color.replace(/#/g,'') : color;
}
self.extend = Phaser.Utils.extend.bind(null,true) // always deep;
self.colorShapeBmd = function(key, colorHex, frame=undefined) {
var source = game.make.sprite(0,0,key,frame);
var color = Phaser.Color.hexToColor(colorHex);
var texture = game.make.bitmapData(source.width, source.height);
texture.fill(color.r, color.g, color.b);
var bmd = texture;
bmd.blendDestinationAtop();
bmd.draw(source, 0, 0, source.texture.crop.width, source.texture.crop.height);
source.pendingDestroy = true;
return bmd;
createdNewGround(ground) {
if (!Phaser.Utils.chanceRoll(30)) return;
const padding = 1;
const template = this.game.rnd.pick(this.templates);
// if (ground.data.small) {
// template = this.templates[this.game.rnd.pick([1, 2, 3])]
// } else {
// }
const direction = this.game.rnd
.pick([this.getOffsetRight, this.getOffsetTop, this.getOffsetTopRight])
.bind(this)(ground, template);
const offsetX = direction.x;
const offsetY = direction.y;
addTile () {
const emptyTiles = []
for (let y = 0; y < gameOptions.boardSize.rows; ++y) {
for (let x = 0; x < gameOptions.boardSize.cols; ++x) {
if (this.boardArray[y][x].tileValue === 0) {
emptyTiles.push({ col: x, row: y })
}
}
}
if (emptyTiles.length > 0) {
const { col, row } = Phaser.Utils.Array.GetRandom(emptyTiles)
this.boardArray[row][col].tileValue = 1
this.boardArray[row][col].tileSprite.visible = true
this.boardArray[row][col].tileSprite.setFrame(0)
this.boardArray[row][col].tileSprite.alpha = 0
this.tweens.add({
alpha: 1,
callbackScope: this,
duration: gameOptions.tweenSpeed,
onComplete: function () {
console.log('tween completed')
this.canMove = true
},
targets: [this.boardArray[row][col].tileSprite]
})
generate(ground) {
const maxChance = 25;
const maxDistance = 100;
const { currentDistance } = this.score;
const currentChance =
this.cubicInOut(currentDistance / maxDistance) * maxChance;
if (!Phaser.Utils.chanceRoll(currentChance)) return null;
const marginLeft = this.game.rnd.between(50, 150);
let x = 0;
let y = 0;
x = ground.x + ground.width + marginLeft;
y = ground.y + this.game.rnd.between(-75, 75);
const TypeClass = this.game.rnd.pick(this.types);
let enemy = this.children.find(
item => item.constructor === TypeClass && !item.alive
);
if (enemy == null) {
enemy = new TypeClass(this.game, x, y);
import Phaser from 'phaser';
const DATA_KEY = '_follow';
const GetFastValue = Phaser.Utils.Objects.GetFastValue;
const RotateAround = Phaser.Math.RotateAround;
export default class FollowPlugin extends Phaser.Plugins.ScenePlugin {
boot () {
this.gameObjects = new Phaser.Structs.Set();
this.systems.events
.on('postupdate', this.sceneUpdate, this)
.on('shutdown', this.sceneShutdown, this)
.once('destroy', this.sceneDestroy, this);
}
sceneUpdate () {
this.gameObjects.iterate(this.updateObject, this);
}
generate(ground) {
if (this.bunny.data.jetPack) return null;
if (!Phaser.Utils.chanceRoll(3)) return null;
const x = this.game.rnd.between(
ground.x,
ground.x + ground.width - this.prototype.width
);
const y = ground.y - this.prototype.height;
const types = [PowerUp.type.MAGNET, PowerUp.type.GOD, PowerUp.type.WINGS];
let type = this.game.rnd.pick(types);
if (Phaser.Utils.chanceRoll(10)) {
type = PowerUp.type.JETPACK;
}
let powerUp = this.getFirstDead();
if (powerUp == null) {
generate(ground) {
if (this.bunny.data.jetPack) return null;
if (!Phaser.Utils.chanceRoll(3)) return null;
const x = this.game.rnd.between(
ground.x,
ground.x + ground.width - this.prototype.width
);
const y = ground.y - this.prototype.height;
const types = [PowerUp.type.MAGNET, PowerUp.type.GOD, PowerUp.type.WINGS];
let type = this.game.rnd.pick(types);
if (Phaser.Utils.chanceRoll(10)) {
type = PowerUp.type.JETPACK;
}
let powerUp = this.getFirstDead();
if (powerUp == null) {
powerUp = new PowerUp(this.game, x, y, type);
this.add(powerUp);
} else {
powerUp.reset(x, y, type);
}
return powerUp;
}
}
generate(ground) {
const absoluteY = this.game.world.height - this.game.height + ground.y;
if (absoluteY < JumperGenerator.MIN_HEIGHT) return null;
if (!Phaser.Utils.chanceRoll(15)) return null;
const x = this.game.rnd.between(
ground.x,
ground.x + ground.width - this.prototype.width
);
const { y } = ground;
let jumper = this.getFirstDead();
if (jumper == null) {
jumper = new Jumper(this.game, x, y);
this.add(jumper);
} else {
jumper.reset(x, y);
}
import Phaser from 'phaser';
import GridTablePlugin from '../../plugins/gridtable-plugin.js';
import TouchStatePlugin from '../../plugins/touchstate-plugin.js';
import ContainerLitePlugin from '../../plugins/containerlite-plugin.js';
const GetValue = Phaser.Utils.Objects.GetValue;
class Demo extends Phaser.Scene {
constructor() {
super({
key: 'examples'
})
}
preload() {
this.load.image('bg', 'assets/images/white-dot.png');
}
create() {
var database = getDataBase();
var config = {