Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const width = opts.deadzone.width <= 1 ? this.game.width * opts.deadzone.width : opts.deadzone.width
this.game.camera.deadzone = new Phaser.Rectangle( left, 0, width, this.game.height )
}
}
// Set up speed and force values
this.xSpeed = opts.speed || 350
this.jumpForce = opts.jump || -250
this.totalJumps = opts.hasOwnProperty('jumps') ? opts.jumps : 1
this.currentJump = 0
// Set up controls
if( opts.hasOwnProperty('controls') && opts.controls ){
this.cursors = this.game.input.keyboard.createCursorKeys()
this.jumpButton = this.game.input.keyboard.addKey( Phaser.Keyboard.SPACEBAR )
// Jump
this.jumpButton.onDown.add( function(){ this.jump() }, this )
}
// Set up where the sprite is facing
this.facing = 1
}
this.game.world.setBounds(0, 0, 19200, 19200);
// Create leaderboard
this.leaderboard = new Leaderboard({
game: this.game,
x: 100,
y: 10,
width: 30,
height: 100,
});
this.leaderboard.fixedToCamera = true;
this.uiLayer.add(this.leaderboard);
this.cursors = this.game.input.keyboard.createCursorKeys();
this.wasd = {
left: this.game.input.keyboard.addKey(Phaser.Keyboard.A),
right: this.game.input.keyboard.addKey(Phaser.Keyboard.D),
up: this.game.input.keyboard.addKey(Phaser.Keyboard.W),
down: this.game.input.keyboard.addKey(Phaser.Keyboard.S)
};
this.cntSeqNum = 0;
this.pending_inputs = [];
var emitter = this.game.add.emitter(200, 200, 200);
this.uiLayer.add(emitter);
this.setupEvent(this.socket, this);
}
init(action, finalScore, highScore) {
if(this.game.device.desktop) {
this.jumpInput = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR)
} else {
this.jumpInput = this.game.input.pointer1
}
this.action = action
this.finalScore = finalScore
this.highScore = highScore
}
init() {
this.game.sound.mute = this.loadSoundMuteState()
this.skipIntro = this.loadSkipIntro()
if(this.game.device.desktop) {
this.jumpInput = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR)
} else {
this.jumpInput = this.game.input.pointer1
}
this.initialOrientation = this.game.scale.isLandscape ? 'landscape' : 'portrait'
}
this.p1.anchor.setTo(0.5, 0.5)
this.p1.frame = 2
this.p2 = this.game.add.sprite(this.game.world.centerX, 130, 'text')
this.p2.anchor.setTo(0.5, 0.5)
this.p2.frame = 3
this.credits = this.game.add.sprite(this.game.world.centerX, 140, 'text')
this.credits.anchor.setTo(0.5, 0.5)
this.credits.frame = 4
this.help = this.game.add.sprite(this.game.world.centerX, 150, 'text')
this.help.anchor.setTo(0.5, 0.5)
this.help.frame = 5
this.keys = {
k1: this.game.input.keyboard.addKey(Phaser.Keyboard.ONE),
k2: this.game.input.keyboard.addKey(Phaser.Keyboard.TWO),
c: this.game.input.keyboard.addKey(Phaser.Keyboard.C),
h: this.game.input.keyboard.addKey(Phaser.Keyboard.H)
}
}
create () {
const world = this.game.world
this.startTime = new Date().getTime()
this.tune.play()
this.tick = 0
this.game.input.gamepad.start()
this.pad = this.game.input.gamepad.pad1
this.pa2 = this.game.input.gamepad.pad2
this.spaceKey = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR)
this.logo = this.game.add.sprite(world.centerX, world.centerY - 50, 'logo')
this.logo.anchor.setTo(0.5, 0.5)
this.text = this.game.add.sprite(this.game.world.centerX, 180, 'text')
this.text.anchor.setTo(0.5, 0.5)
this.text.frame = 0
this.p1 = this.game.add.sprite(this.game.world.centerX, 120, 'text')
this.p1.anchor.setTo(0.5, 0.5)
this.p1.frame = 2
this.p2 = this.game.add.sprite(this.game.world.centerX, 130, 'text')
this.p2.anchor.setTo(0.5, 0.5)
this.p2.frame = 3
this.credits = this.game.add.sprite(this.game.world.centerX, 140, 'text')
this.credits.anchor.setTo(0.5, 0.5)
this.credits.frame = 4
static addKeyboard(game) {
return game.device.desktop
? [
game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR),
game.input.keyboard.addKey(Phaser.Keyboard.UP)
]
: [game.input.pointer1]
}
this.animations.add('left', anims.left, 10, true)
this.animations.add('right', anims.right, 10, true)
this.animations.add('up', anims.up, 10, true)
this.animations.add('down', anims.down, 10, true)
this.animations.play('idle')
this.vx = 1
this.vy = 0
this.facing = { x: this.vx, y: this.vy }
this.dir = 'left'
this.bulletDelay = 2
this.game.input.gamepad.start()
if (this.name === 'dude') {
this.pad = this.game.input.gamepad['pad1']
this.keys = {
shoot: this.game.input.keyboard.addKey(Phaser.Keyboard.SHIFT),
up: this.game.input.keyboard.addKey(Phaser.Keyboard.UP),
down: this.game.input.keyboard.addKey(Phaser.Keyboard.DOWN),
left: this.game.input.keyboard.addKey(Phaser.Keyboard.LEFT),
right: this.game.input.keyboard.addKey(Phaser.Keyboard.RIGHT)
}
} else {
this.pad = this.game.input.gamepad['pad2']
this.keys = {
shoot: this.game.input.keyboard.addKey(Phaser.Keyboard.R),
up: this.game.input.keyboard.addKey(Phaser.Keyboard.W),
down: this.game.input.keyboard.addKey(Phaser.Keyboard.S),
left: this.game.input.keyboard.addKey(Phaser.Keyboard.A),
right: this.game.input.keyboard.addKey(Phaser.Keyboard.D)
}
}
}
create() {
this._game.input.mouse.capture = true;
this._keyMap = {};
for(let inputEvent in InputEvent) {
let keyEvent = parseInt(inputEvent);
let key = this._config.keyConfig[InputEvent[keyEvent]];
if(!!key) {
this._keyMap[keyEvent] = this._initKey(Phaser.Keyboard[key]);
}
}
}
this.animations.add('down', anims.down, 10, true)
this.animations.play('idle')
this.vx = 1
this.vy = 0
this.facing = { x: this.vx, y: this.vy }
this.dir = 'left'
this.bulletDelay = 2
this.game.input.gamepad.start()
if (this.name === 'dude') {
this.pad = this.game.input.gamepad['pad1']
this.keys = {
shoot: this.game.input.keyboard.addKey(Phaser.Keyboard.SHIFT),
up: this.game.input.keyboard.addKey(Phaser.Keyboard.UP),
down: this.game.input.keyboard.addKey(Phaser.Keyboard.DOWN),
left: this.game.input.keyboard.addKey(Phaser.Keyboard.LEFT),
right: this.game.input.keyboard.addKey(Phaser.Keyboard.RIGHT)
}
} else {
this.pad = this.game.input.gamepad['pad2']
this.keys = {
shoot: this.game.input.keyboard.addKey(Phaser.Keyboard.R),
up: this.game.input.keyboard.addKey(Phaser.Keyboard.W),
down: this.game.input.keyboard.addKey(Phaser.Keyboard.S),
left: this.game.input.keyboard.addKey(Phaser.Keyboard.A),
right: this.game.input.keyboard.addKey(Phaser.Keyboard.D)
}
}
}