-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathScene1.js
More file actions
156 lines (131 loc) · 4.18 KB
/
Copy pathScene1.js
File metadata and controls
156 lines (131 loc) · 4.18 KB
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
class Scene1 extends Phaser.Scene {
constructor() {
super("bootGame");
}
preload() { //Runs before the game starts. Loads all the game assets: music, sprites, images, fonts, etc.
this.load.image("background", "assets/background.png");
this.load.image("heart", "assets/heart.png");
this.load.spritesheet('characterSheet', 'assets/p51.png', { //each plane is loaded as a character sprite to support animation.
frameWidth: 109, //each frame is 109px wide; Phaser then extrapolates how many frames are in the animation based on how
frameHeight: 97 //wide the image is. The images are 218px wide (excluding the P-51), meaning the animation is 2 frames (again,
}); //excluding the P-51
this.load.spritesheet('zero1', 'assets/zero.png', { //all the enemy planes are the same, excluding color. This loads the normal zero with the standard camo.
frameWidth: 108,
frameHeight: 87
});
this.load.spritesheet('zero2', 'assets/zeroBlack.png', { //loads zero two. not the anime character.
frameWidth: 108,
frameHeight: 87
});
this.load.spritesheet('zero3', 'assets/zeroWhite.png', {
frameWidth: 108,
frameHeight: 87
});
this.load.spritesheet('zero4', 'assets/zeroBrown.png', {
frameWidth: 108,
frameHeight: 87
});
this.load.spritesheet('bullet', 'assets/bullet.png', {
frameWidth: 3,
frameHeight: 7
});
this.load.spritesheet('zero4', 'assets/zeroBrown.png', {
frameWidth: 108,
frameHeight: 87
});
this.load.spritesheet("explosion", "assets/explosion1.png",{
frameWidth: 108,
frameHeight: 87
});
this.load.bitmapFont("pixelFont", "assets/font.png", "assets/font.xml"); //loading the font
this.load.audio("audio_pew", ["assets/pew.ogg", "assets/pew.mp3"]); //gun noises? check.
this.load.audio("audio_explode", ["assets/explode.ogg", "assets/explode.mp3"]); //explosion sounds? check.
this.load.audio("audio_gameOver", ["assets/gameOver.ogg", "assets/gameOver.mp3"]); //jumpscare? check.
this.load.audio("music", ["assets/dangerZone.ogg", "assets/dangerZone.mp3"]); //kick-ass background track? check.
}
create() {
this.scene.start("playGame");
this.anims.create ({ //anims.create creates the animations from the character sheets defined in preload()
key: 'still', //'still' specifies that this animation will be played when the character is not moving (no keys are pressed)
frames: this.anims.generateFrameNumbers('characterSheet', { //where the animation begins on the sprite sheet. This animation begins on the first frame and ends on the second.
start: 0,
end: 1
}),
frameRate: 40, //how fast the animation is played.
repeat: -1 //repeat on a loop
});
this.anims.create ({
key: 'right',
frames: this.anims.generateFrameNumbers('characterSheet', {
start: 2,
end: 3
}),
frameRate: 40,
repeat: -1
});
this.anims.create ({
key: 'left',
frames: this.anims.generateFrameNumbers('characterSheet', {
start: 4,
end: 5
}),
frameRate: 40,
repeat: -1
});
this.anims.create ({
key: 'zero1',
frames: this.anims.generateFrameNumbers('zero1', {
start: 0,
end: 1
}),
frameRate: 40,
repeat: -1
});
this.anims.create ({
key: 'zero2',
frames: this.anims.generateFrameNumbers('zero2', {
start: 0,
end: 1
}),
frameRate: 40,
repeat: -1
});
this.anims.create ({
key: 'zero3',
frames: this.anims.generateFrameNumbers('zero3', {
start: 0,
end: 1
}),
frameRate: 40,
repeat: -1
});
this.anims.create ({
key: 'zero4',
frames: this.anims.generateFrameNumbers('zero4', {
start: 0,
end: 1
}),
frameRate: 40,
repeat: -1
});
this.anims.create ({
key: 'bullet_anim',
frames: this.anims.generateFrameNumbers('bullet', {
start: 0,
end: 1
}),
frameRate: 20,
repeat: -1
});
this.anims.create ({
key: 'explode',
frames: this.anims.generateFrameNumbers('explosion', {
start: 0,
end: 3
}),
frameRate: 20,
repeat: 0,
hideOnComplete: true //the animation should be hidden after it's finished.
});
}
}