Spaces:
Running
Running
Update index.html
Browse files- index.html +81 -16
index.html
CHANGED
@@ -1,19 +1,84 @@
|
|
1 |
<!DOCTYPE html>
|
2 |
<html>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
</html>
|
|
|
1 |
<!DOCTYPE html>
|
2 |
<html>
|
3 |
+
<head>
|
4 |
+
<meta charset="utf-8">
|
5 |
+
<title>Phaser Game</title>
|
6 |
+
<script src="https://cdn.jsdelivr.net/npm/phaser@3.60.1/dist/phaser.min.js"></script>
|
7 |
+
</head>
|
8 |
+
<body>
|
9 |
+
<script>
|
10 |
+
// initialize the Phaser game
|
11 |
+
const config = {
|
12 |
+
type: Phaser.AUTO,
|
13 |
+
width: 800,
|
14 |
+
height: 600,
|
15 |
+
physics: {
|
16 |
+
default: 'arcade',
|
17 |
+
arcade: {
|
18 |
+
gravity: { y: 300 },
|
19 |
+
debug: false
|
20 |
+
}
|
21 |
+
},
|
22 |
+
scene: {
|
23 |
+
preload: preload,
|
24 |
+
create: create,
|
25 |
+
update: update
|
26 |
+
}
|
27 |
+
};
|
28 |
+
|
29 |
+
const game = new Phaser.Game(config);
|
30 |
+
|
31 |
+
// preload assets
|
32 |
+
function preload() {
|
33 |
+
this.load.image('sky', 'sky.png');
|
34 |
+
this.load.image('ground', 'platform.png');
|
35 |
+
this.load.image('star', 'star.png');
|
36 |
+
this.load.image('bomb', 'bomb.png');
|
37 |
+
this.load.spritesheet('dude', 'dude.png', { frameWidth: 32, frameHeight: 48 });
|
38 |
+
}
|
39 |
+
|
40 |
+
// create game objects
|
41 |
+
function create() {
|
42 |
+
this.add.image(400, 300, 'sky');
|
43 |
+
|
44 |
+
this.platforms = this.physics.add.staticGroup();
|
45 |
+
|
46 |
+
this.platforms.create(400, 568, 'ground').setScale(2).refreshBody();
|
47 |
+
|
48 |
+
this.platforms.create(600, 400, 'ground');
|
49 |
+
this.platforms.create(50, 250, 'ground');
|
50 |
+
this.platforms.create(750, 220, 'ground');
|
51 |
+
|
52 |
+
this.player = this.physics.add.sprite(100, 450, 'dude');
|
53 |
+
|
54 |
+
this.player.setBounce(0.2);
|
55 |
+
this.player.setCollideWorldBounds(true);
|
56 |
+
|
57 |
+
this.physics.add.collider(this.player, this.platforms);
|
58 |
+
|
59 |
+
this.cursors = this.input.keyboard.createCursorKeys();
|
60 |
+
}
|
61 |
+
|
62 |
+
// game loop
|
63 |
+
function update() {
|
64 |
+
if (this.cursors.left.isDown) {
|
65 |
+
this.player.setVelocityX(-160);
|
66 |
+
|
67 |
+
this.player.anims.play('left', true);
|
68 |
+
} else if (this.cursors.right.isDown) {
|
69 |
+
this.player.setVelocityX(160);
|
70 |
+
|
71 |
+
this.player.anims.play('right', true);
|
72 |
+
} else {
|
73 |
+
this.player.setVelocityX(0);
|
74 |
+
|
75 |
+
this.player.anims.play('turn');
|
76 |
+
}
|
77 |
+
|
78 |
+
if (this.cursors.up.isDown && this.player.body.touching.down) {
|
79 |
+
this.player.setVelocityY(-330);
|
80 |
+
}
|
81 |
+
}
|
82 |
+
</script>
|
83 |
+
</body>
|
84 |
</html>
|