-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoriginal.html
198 lines (165 loc) · 5.15 KB
/
original.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
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Horse In Space Ninja!</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('horse', 'assets/horse.png');
game.load.image('star', 'assets/star.png');
game.load.image('shuriken', 'assets/shuriken.png');
game.load.image('beatle', 'assets/beatle.png');
game.load.image('gameover', 'assets/gameover.png');
}
var horse;
var layers = [];
var cursors;
var spacebar;
var shuriken;
var gameover;
var isGameover = false;
var shurikenAlive = false;
var enemyAlive = false;
var enemy;
var beatle;
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);
}
}
horse = game.add.sprite(50, game.world.height - 500, "horse");
game.physics.enable(horse);
shuriken = game.add.sprite(0, 0, "shuriken");
game.physics.enable(shuriken);
shuriken.kill();
// Our controls.
cursors = game.input.keyboard.createCursorKeys();
spacebar = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
beatle = game.add.sprite(600, game.world.height - 500, "beatle");
game.physics.enable(beatle);
enemy = beatle;
enemy.kill();
enemyAlive = false;
gameover = game.add.sprite(100, 150, "gameover");
gameover.kill();
}
function killEnemy(shuriken, enemy) {
shuriken.kill();
shurikenAlive = false;
enemy.body.velocity.x = 0;
enemy.kill();
enemyAlive = false;
}
function killHorse(horse, enemy) {
horse.kill();
enemy.kill();
enemyAlive = false;
gameover.revive();
isGameover = true;
}
function enemySpawner() {
if (!isGameover && !enemyAlive) {
//TODO: switch enemies?
enemy.body.x = 800;
enemy.body.y = parseInt(Math.random() * (game.world.height - 100));
enemy.body.velocity.x = -150;
enemy.revive();
enemyAlive = true;
}
}
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;
}
}
}
// Reset the players velocity (movement)
horse.body.velocity.x = 0;
horse.body.velocity.y = 0;
if (cursors.left.isDown)
{
// Move to the left
horse.body.velocity.x = -200;
//player.body.velocity.x = -150;
//player.animations.play('left');
}
else if (cursors.right.isDown)
{
// Move to the right
//player.body.velocity.x = 150;
horse.body.velocity.x = 200;
//player.animations.play('right');
}
else if (cursors.up.isDown) {
horse.body.velocity.y = -200;
} else if (cursors.down.isDown) {
horse.body.velocity.y = 200;
}
else
{
// Stand still
//player.animations.stop();
//player.frame = 4;
}
// Allow the player to jump if they are touching the ground.
if (spacebar.isDown)
{
shuriken.body.x = horse.body.x + 100;
shuriken.body.y = horse.body.y;
shuriken.body.velocity.x = 800;
shuriken.revive();
shurikenAlive = true;
}
if (shuriken.body.x > 1000) {
shuriken.kill();
shurikenAlive = false;
}
if (shurikenAlive) {
game.physics.arcade.overlap(shuriken, enemy, killEnemy, null, this);
}
if (enemyAlive) {
if (enemy.body.x < 0) {
enemy.kill();
enemyAlive = false;
} else {
game.physics.arcade.overlap(horse, enemy, killHorse, null, this);
}
}
enemySpawner();
}
</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-66867410-1', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>