-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
77 lines (66 loc) · 1.54 KB
/
index.html
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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Making your first Phaser 3 Game - Part 1</title>
<script src="//cdn.jsdelivr.net/npm/[email protected]/dist/phaser.js"></script>
<style type="text/css">
body {
margin: 0;
}
</style>
</head>
<body>
<script type="text/javascript">
var config = {
type: Phaser.AUTO,
width: 500,
height: 500,
physics: {
default: 'arcade',
arcade: {
gravity: { y: 300 },
debug: false
}
},
scene: {
preload: preload,
create: create,
update: update
}
};
var player;
var obstacles;
var cursors;
var game = new Phaser.Game(config);
function preload ()
{
this.load.image('road', '/assets/road.png');
this.load.spritesheet('car',
'/assets/car.png',
{ frameWidth: 32, frameHeight: 48 }
);
}
function create ()
{
this.add.image(250, 250, 'road');
obstacles = this.physics.add.staticGroup();
player = this.physics.add.sprite(250, 300, 'car');
player.setBounce(0.2);
player.setCollideWorldBounds(true);
cursors = this.input.keyboard.createCursorKeys();
}
function update ()
{
if (cursors.left.isDown)
{
player.x = 300;
}
else if (cursors.right.isDown)
{
player.x = 600;
}
}
</script>
</body>
</html>