-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
169 lines (130 loc) · 4.37 KB
/
script.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
var cursors;
var game = new Phaser.Game(640,480, Phaser.AUTO, 'world', {
preload: preload, create: create, update: update });
var lift ;
var mySprite;
var x = game.width/2;
var y = game.height/2;
var dirX = 10;
var dirY = 10;
var emitter;
var weapon;
var student;
function preload() {
game.load.image('fire1', 'assets/fire1.png');
game.load.image('fire2', 'assets/fire2.png');
game.load.image('fire3', 'assets/fire3.png');
game.load.image('smoke', 'assets/smoke-puff.png');
game.load.image('pixel', 'assets/trans-pixel.png');
game.load.image('bullet', 'assets/bullet.png');
game.load.atlasJSONHash('student', 'assets/student.png','assets/student.json');
}
function create() {
game.physics.startSystem(Phaser.Physics.ARCADE);
game.stage.backgroundColor = '#333';
emitter = game.add.emitter(game.world.centerX, game.world.centerY, 400);
emitter.makeParticles( [ 'fire1', 'fire2', 'fire3', 'smoke' ] );
emitter.gravity = 800;
emitter.setAlpha(1, 0, 3000);
mySprite = game.add.sprite( 600,480, 'student');
mySprite.animations.add('left', ['left1', 'left2','left3', 'left4','left5', 'left6','left7', 'left8','left9']);
mySprite.animations.add('right', ['right1', 'right2','right3', 'right4','right5', 'right6','right7', 'right8', 'right9']);
mySprite.animations.add('up'), ['up1', 'up2','up3', 'up4','up5', 'up6','up7', 'up8','up9'];
mySprite.animations.add('down', ['down1', 'down2']);
mySprite.anchor.setTo(0.5, 0.5);
game.physics.arcade.enable(mySprite);
mySprite.body.velocity.setTo(200, 200);
// makes image collideable
mySprite.body.collideWorldBounds = true;
// mySprite.bounce.set(0.8);
mySprite.body.gravity.set(0, 180);
//mySprite.inputEnabled = true;
cursors = game.input.keyboard.createCursorKeys();
// Creates 30 bullets, using the 'bullet' graphic
weapon = game.add.weapon(30, 'bullet');
// The bullet will be automatically killed when it leaves the world bounds
weapon.bulletKillType = Phaser.Weapon.KILL_WORLD_BOUNDS;
// The speed at which the bullet is fired
weapon.bulletSpeed = 600;
// Speed-up the rate of fire, allowing them to shoot 1 bullet every 60ms
weapon.fireRate = 100;
// Tell the Weapon to track the 'mySprite' Sprite
// With no offsets from the position
// But the 'true' argument tells the weapon to track sprite rotation
weapon.trackSprite(mySprite, 0, 0, true);
}
function update () {
if ( x > game.width - mySprite.width || x < 0 ) {
dirX = -dirX;
}
if ( y > game.height - mySprite.height || y < 0 ) {
dirY = -dirY;
}
if (cursors.down.isDown) {
mySprite.y = mySprite.y + 1;
}
if (cursors.up.isDown)
{
mySprite.y = mySprite.y - 10;
particleBurst();
// emitter.start(false, 3000, 5);
mySprite.animations.play('up', 30, false);
}
else
{
mySprite.animations.play('stop', 30, false);
}
if (cursors.left.isDown)
{
if (cursors.up.isDown) {
mySprite.x = mySprite.x - 10;
}else{
mySprite.x = mySprite.x - 5;
}
mySprite.animations.play('left', 15, false);
}
else if (cursors.right.isDown)
{
if (cursors.up.isDown) {
mySprite.x = mySprite.x + 10;
}else{
mySprite.x = mySprite.x + 5;
}
mySprite.animations.play('right', 15, false);
} else
{
mySprite.animations.play('stop', 15, false);
}
if (game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR))
{
weapon.fire();
}
}
function particleBurst() {
var px = mySprite.body.velocity.x;
var py = mySprite.body.velocity.y;
px *= -1;
py *= -1;
emitter.minParticleSpeed.set(px, py);
emitter.maxParticleSpeed.set(px, py);
emitter.emitX = mySprite.x;
emitter.emitY = mySprite.y;
// Phaser.Particles.Arcade.Emitter.setScale(minX, maxX, minY, maxY, rate, ease, yoyo) : void;
emitter.setScale(0.01, .5, 0.01, .1, 600);
emitter.start(true, 500, null, 5);
// And 2 seconds later we'll destroy the emitter
game.time.events.add(500, destroyEmitter);
}
function destroyEmitter() {
if (emitter !== null){
// emitter.destroy();
}
}
function yahoo(){
console.log('yahoo');
}
function onDown(dog) {
console.log('clicked');
console.log(mySprite.x);
console.log(mySprite.y);
}