-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
170 lines (151 loc) · 4.2 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
<meta charset=utf-8>
<pre id="p"></pre>
<button onclick=location=location>refresh</button>
<script>
/*
o/ | |
/|_ | |
o o o / V
/|\ /|\ /|\ Λ
___/_\_________________,\_________/|___________ ____________________________\o__//__________________| |________________ ________________________________________
| | | |
*/
var run1 = [" "," "," o ","/|.",",\\_"," "];
var run2 = [" "," "," o ","/|\\","/|_"," "];
var jump1 = [" "," "," o/","/|_","/ "," "];
var jump2 = [" "," o/","/|_","/ "," "," "];
var jump3 = [" o/","/|_","/ "," "," "," "];
var slide = [" "," "," "," ","o_<"," "];
var pit = [" "," "," "," "," ","|^^^^^|"];
var stalagtite = [" | | "," | | "," | | "," V ","_______"," "];
var stalagmite = [" "," "," "," Λ ","__| |__"," "];
var obstacles = [];
var obstacle = [];
var state = 0;
var rate = 100;
var obstacleDist = 20;
var obstacleLength = 7;
var worldOffset = 0;
var move = run1;
var garsMauvais = 0;
var currentObstaclePosition = 0;
var score = 0;
var nbObstacles = 5;
var jumpHeight = 0;
jumpstate = 0;
slidestate = 0;
for (var i = 0; i < nbObstacles; ++i) {
obstacles.push(Math.floor(Math.random()*3));
}
obstacles = obstacles.concat(obstacles);
var display = function() {
var level = [];
for( var i = 0; i < 6; ++i ) {
level[i] = "";
for ( var j = 0; j < 2 * nbObstacles; ++j ) {
for ( var k = 0; k < obstacleDist; ++k ) {
if ( i == 4 ) {
level[i] += "_";
} else {
level[i] += " ";
}
}
switch(obstacles[j]) {
case 0:
obstacle = pit;
break;
case 1:
obstacle = stalagtite;
break;
case 2:
obstacle = stalagmite;
break;
}
level[i] += obstacle[i];
}
level[i] = level[i].substr(worldOffset,80);
level[i] = level[i].substr(0,3) + (move[i] != " " ? move[i] : level[i].substr(3,3)) + level[i].substr(6);
}
p.innerHTML = level.join("\n") + "\n" + score;
}
var testCollision = function(){
var currentObstacle = Math.floor(worldOffset / (obstacleDist + obstacleLength));
switch(obstacles[currentObstacle]){
case 0 : //pit
if(state != 2 && currentObstaclePosition > 0) garsMauvais = 1;
break;
case 1 : //stalagtite
if(state != 3 && currentObstaclePosition > 1 && currentObstaclePosition < 5 ) garsMauvais = 1;
break;
case 2 : // stalagmite
if(state != 2 && currentObstaclePosition > 1 && currentObstaclePosition < 5 ) garsMauvais = 1;
break;
}
}
window.addEventListener("keyup", function(e){
if(state <= 1){
//up
if (e.keyCode == 90 || e.keyCode == 38) {
state = 2;
}
//down
if (e.keyCode == 83 || e.keyCode == 40) {
state = 3;
}
}
});
var game = function(){
if(state == 0){
move = run1;
//state = 1;
} /*else if (state == 1) {
move = run2;
state = 0;
}*/
else if (state == 2) {
move = jump1;
jumpstate++;
if(jumpstate == 10){
jumpstate = 0;
jumpHeight = 0
state = 0;
}
else if(jumpstate == 1 || jumpstate == 9){
jumpHeight = 1;
move = jump2;
}
else {
jumpHeight = 2;
move = jump3;
}
} else if (state == 3) {
move = slide;
slidestate++;
if(slidestate == 8){
slidestate = 0;
state = 0;
}
}
display();
worldOffset ++;
if(worldOffset == nbObstacles * 27){
worldOffset = 0;
}
if(currentObstaclePosition == obstacleLength){
currentObstaclePosition = 0;
score ++;
if (rate > 50 ) rate --;
}
if(garsMauvais){
alert("Sale merde");
} else {
setTimeout(game,rate);
}
if(worldOffset % (obstacleDist + obstacleLength) >= obstacleDist - 4
&& worldOffset % (obstacleDist + obstacleLength) <= (obstacleDist + obstacleLength - 1) - 4){
testCollision();
currentObstaclePosition ++;
}
};
game();
</script>