/
index.html
157 lines (137 loc) · 3.91 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
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>...</title>
<meta charset="utf-8">
<style>
html, body { margin: 0; padding: 0; border: 0; }
#c { display: block; } /* kill scrollbars from hell */
</style>
</head>
<body>
<canvas height="635" style="width: 1366px; height: 635px;" width="1366" id="c"></canvas>
<script>
var a = document.getElementsByTagName('canvas')[0];
var b = document.body;
var d = function(e){ return function(){ e.parentNode.removeChild(e); }; }(a);
// unprefix some popular vendor prefixed things (but stick to their original name)
var AudioContext =
window.AudioContext ||
window.webkitAudioContext;
var requestAnimationFrame =
window.requestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(f){ setInterval(f, 1000/30); };
// stretch canvas to screen size (once, wont onresize!)
a.style.width = (a.width = innerWidth) + 'px';
a.style.height = (a.height = innerHeight) + 'px';
var c = a.getContext('2d');
</script>
<script>
// Variables
// a: the canvas
// b: the body
// c: the canvas's 2d context
// d: (reused) game has started (0/1)
// e: game has ended (0/1)
// f: score
// g: the random map
// h: dragon's vertical speed
// i, j: dragon's coordinates x, y
// k: steps already passed (1 step = 20px)
// l: the game's framerate
// n: the game's loop function
// o: loop var
// p: dragon's drawing path
// v, w, y, z: temp vars
// Initialization
c.scale(a.height/1E3,a.height/1E3);
// Reset
d=e=f=h=0;
g=[];
for(o=0;o<1E3;o++)
g[o]=g[o+1E3]=8*Math.random()|1-1;
i=j=300;
k=20;
l=50;
// Controls (click/tap)
ontouchstart=onmousedown=function(){
// If game is over, reset
if(e){
d=e=f=h=0;
g=[];
for(o=0;o<1E3;o++)
g[o]=g[o+1E3]=8*Math.random()|1-1;
i=j=300;
k=20;
l=50;
}
// If game is not over, start the game if it's not started, and jump
else{
h=45;
d=1;
}
};
// Game loop
(n=function(){
// Background
c.fillStyle="#E50";
c.fillRect(0,0,4E4,4E4);
// Walls
c.fillStyle="#920";
// Roof
c.beginPath();
c.moveTo(-k,0);
for(o=2E3;o--;)
o%20
?
c.lineTo(40*o-k,20+4*g[o])
:
(c.lineTo(40*o-k,100*g[o]),c.lineTo(40*o-k-4,100*g[o]));
c.lineTo(40*o-k,0);
c.fill();
// Ceiling
c.beginPath();
c.moveTo(-k,2E3);
for(o=2E3;o--;)
o%20
?
c.lineTo(40*o-k,980-4*g[o])
:
(c.lineTo(40*o-k,100*(g[o]+3)),c.lineTo(40*o-k-4,100*(g[o]+3)));
c.lineTo(40*o-k,1E3);
c.fill();
// Dragon
p="fEFf&{{~_=,;=vviJ.jfVi/.OoyizyhkhEwf74)\n$fwwuvtU`"+(10<h?"iZ[*)yj:*im**y|Ktdww54#5Dy\iz[Kzi[Jiijk[e@1!":"zl]LfU{\lKtBUh{zzU66iigig5\n&iiyz{vfwwiyDfwiiE");
c.fillStyle="#000";
c.beginPath();
c.moveTo(v=i-e,w=(j-=h)-e);
for(o in p){
y=8-2*(p.charCodeAt(o)>>4);
z=16-2*(p.charCodeAt(o)&15);
c.lineTo(v+=(e?y:z),w+=(e?-z:y));
}
c.fill();
// Apply gravity if the game has started
d&&(h-=6);
// Loop on the map if we are far enough
d&&!e&&(k+=20,4E4<k&&(k-=4E4));
// Increase score and game speed after each obstacle
!d||e||(k+280)%800||(f++,20<l&&l--);
// Game over
if(50>j||950<j||!((k+300)%800)&&(j<100*g[20*~~(k/800)+20]+50||j>100*g[20*~~(k/800)+20]+250))
e=40;
// Text
c.fillStyle="#fff";
c.font="6em Arial";
d&&c.fillText(f,a.width/(a.height/1E3)/2,500);
d||c.fillText("Flappy Dragon",a.width/(a.height/1E3)/2-300,500);
e&&c.fillText("score",a.width/(a.height/1E3)/2-80,400);
c.fillText(e?"restart":!d?"start":"",a.width/(a.height/1E3)/2-100,600);
// Loop
setTimeout(n,l)
})()
</script>
</body></html>