-
Notifications
You must be signed in to change notification settings - Fork 0
/
testscene.js
68 lines (47 loc) · 1.82 KB
/
testscene.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import WeaponPlugin from 'phaser3-weapon-plugin';
export class TestScene extends Phaser.Scene {
constructor() {
super({
key: "TestScene"
});
}
preload() {
this.load.image("bomb","./assets/bomb.png");
this.load.scenePlugin('WeaponPlugin', WeaponPlugin, null, 'weapons');
console.log("prelaoded");
}
create() {
let scoreText = this.add.text(16, 16, 'TEST', { fontSize: '32px', fill: '#ffffff' });
// Creates 1 single bullet, using the 'bullet' graphic
this.weapon = this.weapons.add(1, "bomb");
// Enable physics debugging for the bullets
this.weapon.debugPhysics = true;
// The bullet will be automatically killed when it leaves the world bounds
console.log(`setting bulletKillType`);
this.weapon.bulletKillType = WeaponPlugin.consts.KILL_WORLD_BOUNDS;
// Because our bullet is drawn facing up, we need to offset its rotation:
this.weapon.bulletAngleOffset = 90;
// The speed at which the bullet is fired
this.weapon.bulletSpeed = 400;
this.sprite = this.add.sprite(320, 500, "bomb");
//this.sprite.body.allowGravity = false;
this.physics.add.existing(this.sprite);
this.sprite.body.setDrag(70);
this.sprite.body.maxVelocity.set(200);
// Tell the Weapon to track the 'player' Sprite
this.weapon.trackSprite(this.sprite);
///////////////////////////////////
const {R} = Phaser.Input.Keyboard.KeyCodes;
this.keys = this.input.keyboard.addKeys({
r: R
});
console.log("created");
}
update(time,delta) {
this.weapon.fire();
if (this.keys.r.isDown) {
console.log("restarted");
this.scene.restart();
}
}
}