-
Notifications
You must be signed in to change notification settings - Fork 0
/
13pipegame.html
37 lines (29 loc) · 1.15 KB
/
13pipegame.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
<canvas id='c'></canvas>
<script>
var c = document.getElementById('c').getContext('2d')
var x = 300 // initial pipe position
var my = 102 // initial mario position
var s = 0 // initial speed
// window.ontouchstart = jump // for iOS
window.onclick = function()
{ if (my >= 102) s = -3.5 } // jump, upwards force hence negative
draw()
function draw(){
c.fillStyle = 'skyblue'
c.fillRect(0,0,300,150)
c.fillStyle = 'brown'
c.fillRect(0,130,300,20)
c.fillStyle = 'green'
c.fillRect(x,100,30,50)
c.fillRect(x-10,80,50,20)
x = x - 5 // move pipe left
if (x == -50) x = 300 // if off screen left move to right side
var mario = new Image()
mario.src = "http://i66.tinypic.com/2e3tvsj.gif"
c.drawImage(mario,50,my)
my = my + s // initially 0 then -3.5 onclick
if (my < 102) s = s + 0.1 // downward force
if (my > 102) s = 0 // stop on floor
if (!(x == 65 && my >= 102)) requestAnimationFrame(draw)
}
</script>