-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
177 lines (134 loc) · 3.64 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
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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Voice Racing</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.CANVAS, '', { preload: preload, create: create, update: update, render: render});
function preload() {
game.stage.backgroundColor = "CDE5FF";
game.load.spritesheet('dude', 'assets/dude.png', 32, 48);
game.load.image('land_1', 'assets/land_1.png');
game.load.image('land_2', 'assets/land_2.png');
}
var player;
var player_height = 24;
var ground;
var ground_height = new Array(10000);
var ground_now = 0;
var fall_count = 0;
var fall_step = 6;
var alive = true;
var lose = 'YOU LOSE';
var lose_style = {font: "65px Arial", fill: "#ff0044", align: "center"};
var index_text;
var height_text;
var movespeed = 5;
var bump_step = 5;
var bump_height = 5;
var trumble_step = 5;
var trumble_height = 5;
var next_gene_ground = 240; // index
var next_ground = 50; // index
var space_width = 100; // index
var movespeed_arr = new Array(5, 10, 20, 25);
function create() {
game.world.setBounds(0, 0, 5000000, 600);
player = game.add.sprite(50, 500, 'dude');
player.anchor.setTo(0.5, 1);
player.animations.add('right', [5, 6, 7, 8], 10, true);
player.animations.play('right');
ground = game.add.group();
ground.create(-2200, 500, 'land_1');
for(var i=0;i<150;i++)
ground_height[i] = 100;
for(var i=150;i<100000;i++)
ground_height[i] = 0;
index_text = game.add.text(10, 10, ground_now);
height_text = game.add.text(10, 50, ground_height[ground_now]);
}
function update() {
if (alive){
compute_fall();
// falling();
// bumping();
// trumbling();
ground.position.x -= 5 ;
ground_now++;
if(ground_now == 100000)
ground_now = 0;
fall_step++;
if(fall_step == 100000)
fall_step = 0;
bump_step++;
if(bump_step == 100000)
bump_step = 0;
trumble_step = bump_step;
index_text.setText(ground_now);
height_text.setText(ground_height[ground_now]);
}
else{
game.add.text(200, 200, lose, lose_style);
}
if (ground_now == next_ground){
create_ground();
}
}
function render(){
}
function compute_fall(){
if(ground_height[fall_step] == 0)
fall_count++;
else
fall_count = 0;
}
function falling(){
if(fall_count == 7){
alive = false;
game.time.events.repeat(10, 120, fall_down, this);
}
}
function fall_down(){
player.position.y += 5;
}
function bumping(){
if(ground_height[bump_step]-ground_height[ground_now] > bump_height){
alive = false;
game.time.events.repeat(1, 10, rot_back, this);
}
}
function rot_back(){
player.angle-=6;
}
function trumbling(){
if(ground_height[ground_now]-ground_height[trumble_step] > trumble_height){
alive = false;
game.time.events.repeat(1, 10, rot_front, this);
}
}
function rot_front(){
player.angle+=6;
}
function create_ground(){
var y = game.world.randomY;
ground.create(next_gene_ground*movespeed, 600-y, 'land_2');
var len = 1000/movespeed;
for(var i=0; i<len; i++){
ground_height[i+next_gene_ground] = y;
}
next_ground += space_width+1000/movespeed;
if(next_ground >= 100000)
next_ground -= 100000;
next_gene_ground += space_width+1000/movespeed;
}
</script>
</body>
</html>