forked from wolfgangmeyers/spacehorse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstarfield.html
109 lines (86 loc) · 2.66 KB
/
starfield.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
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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Phaser - Making your first game, part 7</title>
<script type="text/javascript" src="js/phaser.min.js"></script>
<style type="text/css">
body {
margin: 0;
}
</style>
</head>
<body>
<script type="text/javascript">
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });
function preload() {
game.load.image('sky', 'assets/sky.png');
game.load.image('star', 'assets/star.png');
}
var layers = [];
var cursors;
function create() {
// We're going to be using physics, so enable the Arcade Physics system
game.physics.startSystem(Phaser.Physics.ARCADE);
// A simple background for our game
//game.add.sprite(0, 0, 'sky');
// The player and its settings
for (var layer = 1; layer < 4; layer ++) {
var stars = [];
layers.push(stars);
for (var i = 0; i < 100; i++) {
var x = parseInt(Math.random() * (game.world.width + 200));
var y = parseInt(Math.random() * game.world.height);
var star = game.add.sprite(x, y, 'star');
game.physics.arcade.enable(star);
star.body.velocity.x = - (layer * (Math.random() * 100 + 50));
stars.push(star);
}
}
// Our controls.
cursors = game.input.keyboard.createCursorKeys();
}
function update() {
for (var layer in layers) {
for (var i in layers[layer]) {
var star = layers[layer][i];
if (star.body.x < -100) {
star.body.x = 900;
}
}
}
// for (var i in stars) {
// var star = stars[i];
// star.body.velocity.x = -1;
// }
// Collide the player and the stars with the platforms
//game.physics.arcade.collide(player, platforms);
// Reset the players velocity (movement)
//player.body.velocity.x = 0;
if (cursors.left.isDown)
{
// Move to the left
//player.body.velocity.x = -150;
//player.animations.play('left');
}
else if (cursors.right.isDown)
{
// Move to the right
//player.body.velocity.x = 150;
//player.animations.play('right');
}
else
{
// Stand still
//player.animations.stop();
//player.frame = 4;
}
// Allow the player to jump if they are touching the ground.
if (cursors.up.isDown && player.body.touching.down)
{
//player.body.velocity.y = -350;
}
}
</script>
</body>
</html>