-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1.html
196 lines (166 loc) · 4.92 KB
/
1.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
<html>
<head>
<script>
/*
Work For Chukka
Do scoring -- can be done on the basis of km traveled ie pixels here.. or no of icebergs passed by the ship.. former is easier
Make collision proper.. if you can come up with a triangle mechanism to check for iceberg collision
Add boundary collision.. make set interval function in ship ant call interval every 100 miliseconds
also write start screen . and game over screen.
Work for Rash
add lines to canvas making wawes
like /\
//\\
///\\\
add one line it will aouto matically replicate
learn on phone inputs and phone porting
*/
score=0;
ship={
width:25,
height:60,
xpeed:0,
spos:120,
hor:360,
img:new Image(),
blank:new Image(),
calx:function(){
this.spos+=this.xpeed;
},
click:function(event){
if(event.pageX<685) this.xpeed+=1;
else this.xpeed-=1;
click:function(event){
if(event.pageX<685) ship.left();
else ship.right();
},
left:function(){
if(ship.xpeed<1) ship.xpeed=3;
else ship.xpeed+=1;
},
right:function(){
if(ship.xpeed>-1) ship.xpeed=-3;
else ship.xpeed-=1;
}
}
turn=false;
stream={
speed:2,
roll:function() {
ship.calx();
if(turn==10)
{//ctx.fillStyle='#342D7E'
ctx.rotate(0.5);
ctx.beginPath();
ctx.rect(138, 120, 200, 100);
ctx.fillStyle = "#342D7E";
ctx.fill();
ctx.lineWidth = 5;
ctx.strokeStyle = "#342D7E";
ctx.stroke();
ctx.rotate(-0.5);
}
else if(turn==20) {ctx.fillStyle='#4863A0'; turn=0;}
turn++;
ctx.fillRect(0,0,w,3);
ctx.drawImage(c, 0, 0, w, h-stream.speed, 0, stream.speed, w, h-stream.speed);
ctx.fillRect(ship.spos,ship.hor,ship.width,ship.height+stream.speed);
//ctx.drawImage(ship.blank, ship.spos-10, ship.hor+stream.speed-5,ship.width+20,ship.height+stream.speed+15);
ctx.drawImage(ship.img, ship.spos, ship.hor,ship.width,ship.height);
},
gravity:function(){
setInterval(function(){
if(ship.spos<150-ship.width/2) ship.xpeed-=1;
else ship.xpeed+=1;
},330)
}
}
function iceberg(vert){
this.speed=0;//random;
this.vert=vert;
this.hor=40;
this.width=
//this.arr=[this.vert,this.hor];
this.appear=function (){
//console.log(vert);
//console.log(this.vert+','+this.hor)
ctx.drawImage(iceberg.img,this.vert,this.hor,50,50);
};
}
iceberg.create=function(){
var a=new iceberg(Math.floor((Math.random()*(w-ship.width))));
a.appear();
setInterval(function (){ iceberg.movecheck.call(a);},33);
//a.movedown();
}
iceberg.movecheck=function(){
var ob=this;
//console.log("klklkl->",ob[0]+','+ob[1])
iceberg.collision.call(ob);
ob.hor+=stream.speed;
}
iceberg.collision=function(){
var ob=this;
var vert=ob.vert;
var hor=ob.hor;
console.log('coll>',vert+','+hor+':'+ship.spos+','+ship.hor)
if(vert>ship.spos+25 || vert+50<ship.spos)
return false;
if( (hor+50 < ship.hor) || (hor > (ship.hor+60)))
return false;
document.write('Game Over');
}
function init()
{
c = document.getElementById('myCanvas');
ctx=c.getContext("2d");
//w=screen.width;
//h=screen.height;
h=1280;
w=720;
c.height=h;
c.width=w;
iceberg.img=new Image();
iceberg.img.src="iceberg.png";
ship.img.src='ship-up.png';
ship.blank.src='ship-up-blank.png';
ctx.fillStyle='blue';
//ctx.fillRect(0,0,w,h);
back12=new Image();
back12.src="ripple.jpg";
ctx.drawImage(back12, 0, 0,w,h);
ctx.drawImage(ship.img, ship.spos, ship.hor,ship.width,ship.height);
c.addEventListener("mousedown",ship.click,false);
}
var scoreboard = function(){
document.getElementById('score').innerHTML =score;
score++;
}
function keys(ev)
{
if(ev.keyCode==52||ev.keyCode==97) ship.left();
else if (ev.keyCode==54||ev.keyCode==100) ship.right();
}
function start()
{
setInterval(stream.roll,33);
stream.gravity();
setInterval(iceberg.create,2000);
}
</script>
</head>
<body onkeypress="keys(event)" onload="init();start();" >
<div><span id="score">0</span></div>
<canvas id="myCanvas" width="300" height="500" style="position:absolute;border:1px solid #000000;background-color:#008AE6">
Your browser does not support the HTML5 canvas tag.
</canvas>
<br/>
<!--button onclick="setInterval(stream.roll,33);stream.gravity();setInterval(iceberg.create,2000);">start</button>
<!--button onclick="setInterval(iceberg.create,1000);">Ice please!</button-->
<br/>
<button onclick="ship.left()">left</button>
<button onclick="ship.right()">right</button>
<br/>
<p>Or use num pad 4,6 to play or use .. WASD .. a and d to play</p>
</body>
</html>