Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const height = 1160;
const ignoreKeys = ['company', 'onboarder', 'player'];
function extractData(obj) {
return _.reduce(_.keys(obj), function(o, k) {
var val = obj[k];
if (!_.isFunction(val) && !_.contains(ignoreKeys, k)) {
o[k] = val;
}
return o;
}, {});
}
// singleton
const Manager = {
game: new Phaser.Game(width, height, Phaser.AUTO, 'game', null, true),
save: function() {
// juggle some properties to avoid circular refs
var playerData = extractData(this.player),
companyData = extractData(this.player.company);
localStorage.setItem('saveGame', JSON.stringify({
player: playerData,
company: companyData
}));
var lifetimeProfit = this.player.company.lifetimeRevenue - this.player.company.lifetimeCosts,
highScore = this.highScore();
if (lifetimeProfit > highScore) {
localStorage.setItem('highScore', lifetimeProfit.toString());
}
},
load: function() {
var data = JSON.parse(localStorage.getItem('saveGame'));
import Phaser from 'phaser'
import { Boot, Game } from 'scenes'
const config = {
type: Phaser.AUTO,
parent: 'phaser-example',
width: 800,
height: 600,
scene: [
Boot,
Game
]
}
const game = new Phaser.Game(config) // eslint-disable-line no-unused-vars
export function createGame(store, socket, gameData, gameState, playerProps) {
const game = new Game(
get(gameData, 'config.gameWidth') || 800,
get(gameData, 'config.gameHeight') || 600,
Phaser.AUTO,
'phaser',
null/* state */,
false/* transparent */,
false/* antialias */
);
game.state.add('game', new Castle(store, socket, gameData, gameState, playerProps), true/* autoStart */);
return game;
}
},
{
key: 'rexTouchState',
plugin: TouchStatePlugin,
start: true
},
{
key: 'rexContainerLite',
plugin: ContainerLitePlugin,
start: true
}
]
}
};
var game = new Phaser.Game(config);
const state = this.gameState
const {playerId} = this.props
if (this.game) {
const scene = this.game.scene.getScene("GameScene") as GameScene
if (scene) {
scene.state = state
scene.render()
if (state.activePlayer.id === playerId) {
//scene.sys.resume()
} else {
//scene.sys.pause()
}
}
} else {
this.game = new Phaser.Game(config)
this.game.events.once("ready", () => {
if (!this.game)
return
this.game.canvas.addEventListener("contextmenu", (e: MouseEvent) => {
e.preventDefault()
return false
})
const scene = new GameScene(state, playerId!, this.dispatch, width, height)
this.game.scene.add("GameScene", scene, true)
})
}
}
}
}
import Phaser from "phaser";
import logoImg from "./assets/logo.png";
const config = {
type: Phaser.AUTO,
parent: "phaser-example",
width: 800,
height: 600,
scene: {
preload: preload,
create: create
}
};
const game = new Phaser.Game(config);
function preload() {
this.load.image("logo", logoImg);
}
function create() {
const logo = this.add.image(400, 150, "logo");
this.tweens.add({
targets: logo,
y: 450,
duration: 2000,
ease: "Power2",
yoyo: true,
loop: -1
});
window.addEventListener('load', () => {
const config = {
type: Phaser.AUTO,
width: 750,
height: 1334,
backgroundColor: '#05424C',
scene: [
BootScene,
LoadingScene,
GameScene,
],
}
window.game = new Game(config)
window.focus()
bindEvents()
resize()
})
import Loading from "./scene/Loading";
import Start from "./scene/Start";
const config: Phaser.Types.Core.GameConfig = {
type: Phaser.AUTO,
width: 960,
height: 600,
physics: {
default: "arcade",
arcade: {
gravity: { y: 1200 },
debug: false
}
},
scene: [Loading, Start]
};
new Phaser.Game(config);