comparison webGL/dandy/resources/Player.js @ 6:881478004f18

update Bullet.js
author NOBUYASU Oshiro
date Mon, 21 Jun 2010 17:37:26 +0900
parents 7f615f5f5220
children 4343c1feedb5
comparison
equal deleted inserted replaced
5:e6bdfa6616a6 6:881478004f18
1 function Pad() 1 function Pad()
2 { 2 {
3 this.up=0;
4 this.down=0;
3 this.right=0; 5 this.right=0;
4 this.left=0; 6 this.left=0;
5 this.up=0;
6 this.down=0;
7 this.count=0; 7 this.count=0;
8 this.state=0; 8 this.state=0;
9 this.k0=0;
10 this.k1=0;
11 this.k2=0;
12 this.k3=0;
13 this.k4=0;
14 this.r2=0;
15 this.r1=0;
16 this.r2=0;
17 this.l1=0;
18 this.l2=0;
19 this.l3=0;
20 this.se=0;
21 this.st=0;
22
23 //勝手につけた
24 this.quit=0;
9 return this; 25 return this;
10 } 26 }
11 27
12 function Player( object ) 28 function makePlayer( object )
13 { 29 {
14 this.x = 0; 30 this.x = 0;
15 this.y = 0; 31 this.y = 0;
16 this.z = 10; 32 this.z = 10;
17 this.dx = 0; 33 this.dx = 0;
25 return this; 41 return this;
26 } 42 }
27 function movePlayer( player, pad ) 43 function movePlayer( player, pad )
28 { 44 {
29 45
30 pad.right = Math.min(pad.right, 3); 46 pad.right = Math.min(pad.right, 0.7);
31 pad.left = Math.min(pad.left, 3); 47 pad.left = Math.min(pad.left, 0.7);
32 pad.up = Math.min(pad.up, 4); 48 pad.up = Math.min(pad.up, 0.7);
33 pad.down = Math.min(pad.down, 4); 49 pad.down = Math.min(pad.down, 0.7);
34 50
35 player.x += pad.right; 51 player.x -= pad.right;
36 player.x -= pad.left; 52 player.x += pad.left;
37 player.y += pad.up; 53 player.y += pad.up;
38 player.y -= pad.down; 54 player.y -= pad.down;
55
56 player.x = Math.min(player.x, 100);
57 player.x = Math.max(player.x, -100);
58 player.y = Math.min(player.y, 70);
59 player.y = Math.max(player.y, -70);
39 60
40 if( pad.count == 1) pad.state=0; 61 if( pad.count == 1) pad.state=0;
41 if( pad.count > 0) pad.state=1; 62 if( pad.count > 0) pad.state=1;
42 if( pad.count > 10 ) pad.state=2; 63 if( pad.count > 10 ) pad.state=2;
43 64
44 if( pad.state == 0 ) player.image = player.idle; 65 if( pad.state == 0 ) player.image = player.idle;
45 if( pad.state == 1 ) { 66 if( pad.state == 1 ) {
46 if( pad.right > 0 ) player.image = player.turntoleft; 67 if( pad.right > 0 ) player.image = player.turntoright;
47 if( pad.left > 0 ) player.image = player.turntoright; 68 if( pad.left > 0 ) player.image = player.turntoleft;
48 } 69 }
49 if( pad.state == 2 ) { 70 if( pad.state == 2 ) {
50 if( pad.right > 0 ) player.image = player.leftmove; 71 if( pad.right > 0 ) player.image = player.rightmove;
51 if( pad.left > 0 ) player.image = player.rightmove; 72 if( pad.left > 0 ) player.image = player.leftmove;
52 } 73 }
53 74
54 if ( pad.right > 0) pad.right -= 1.5; 75
55 if ( pad.left > 0) pad.left -= 1.5; 76
56 if ( pad.up > 0) pad.up -= 2; 77
57 if ( pad.down > 0) pad.down -= 2; 78 }
58 79
59 }
60 function drawPlayer(ctx, player, scale) 80 function drawPlayer(ctx, player, scale)
61 { 81 {
62 // setup VBOs 82 // setup VBOs
63 ctx.enableVertexAttribArray(0); 83 ctx.enableVertexAttribArray(0);
64 ctx.enableVertexAttribArray(1); 84 ctx.enableVertexAttribArray(1);
93 ctx.uniformMatrix4fv(ctx.getUniformLocation(ctx.program, "u_modelViewProjMatrix"), false, mvpMatrix.getAsWebGLFloatArray()); 113 ctx.uniformMatrix4fv(ctx.getUniformLocation(ctx.program, "u_modelViewProjMatrix"), false, mvpMatrix.getAsWebGLFloatArray());
94 114
95 ctx.bindTexture(ctx.TEXTURE_2D, player.image.texture); 115 ctx.bindTexture(ctx.TEXTURE_2D, player.image.texture);
96 ctx.drawElements(ctx.TRIANGLES, player.image.numIndices, ctx.UNSIGNED_SHORT, 0); 116 ctx.drawElements(ctx.TRIANGLES, player.image.numIndices, ctx.UNSIGNED_SHORT, 0);
97 } 117 }
118
119
120 function Player(ctx, player, pad )
121 {
122 pad.right = Math.min(pad.right, 0.7);
123 pad.left = Math.min(pad.left, 0.7);
124 pad.up = Math.min(pad.up, 0.7);
125 pad.down = Math.min(pad.down, 0.7);
126
127 player.x -= pad.right;
128 player.x += pad.left;
129 player.y += pad.up;
130 player.y -= pad.down;
131
132 player.x = Math.min(player.x, 100);
133 player.x = Math.max(player.x, -100);
134 player.y = Math.min(player.y, 70);
135 player.y = Math.max(player.y, -70);
136
137 if( pad.count == 1) pad.state=0;
138 if( pad.count > 0) pad.state=1;
139 if( pad.count > 10 ) pad.state=2;
140
141 if( pad.state == 0 ) player.image = player.idle;
142 if( pad.state == 1 ) {
143 if( pad.right > 0 ) player.image = player.turntoright;
144 if( pad.left > 0 ) player.image = player.turntoleft;
145 }
146 if( pad.state == 2 ) {
147 if( pad.right > 0 ) player.image = player.rightmove;
148 if( pad.left > 0 ) player.image = player.leftmove;
149 }
150
151
152 drawPlayer(ctx, player, 1.2);//自機の描画(一先ずここでしておく)
153
154
155 //玉レベル1登録
156 if ((pad.k4 % 3 == 1) && (pad.k3 % 3 == 0)){
157 pad.k4 = 1;
158
159 tama_lv1_end++;
160
161 // if(tama_lv1_end > 19) tama_lv1_end = 0;
162 var i = tama_lv1_end;
163
164
165 var tama = new Tama1();
166 tama.x = player.x;
167 tama.y = player.y;
168 tama.r = 1;
169 tama.l = 1;
170 tama_lv1[i] = tama;
171 }
172
173 //玉レベル1表示
174 for (i = 0; i < tama_lv1_end + 1; i++)
175 {
176 tama_lv1[i].y += 10;
177
178 if (tama_lv1[i].r == 1) {
179 PutSpriteBullet(ctx, tama_lv1[i], bullets[1]);
180 }
181 if (tama_lv1[i].y < -70) {
182 if(tama_lv1_end == i){
183 tama_lv1_end--;
184 break;
185 }
186 if(tama_lv1_end > i){
187 tama_lv1[i] = tama_lv1[tama_lv1_end];
188 tama_lv1_end--;
189 break;
190 }
191
192 }
193
194 }
195
196 }
197
198
199 function PutSpriteBullet( ctx, tama, glObj)
200 {
201
202 // setup VBOs
203 ctx.enableVertexAttribArray(0);
204 ctx.enableVertexAttribArray(1);
205 ctx.enableVertexAttribArray(2);
206
207 ctx.bindBuffer(ctx.ARRAY_BUFFER, glObj.vertexObject);
208 ctx.vertexAttribPointer(2, 3, ctx.FLOAT, false, 0, 0);
209 ctx.bindBuffer(ctx.ARRAY_BUFFER, glObj.normalObject);
210 ctx.vertexAttribPointer(0, 3, ctx.FLOAT, false, 0, 0);
211
212 ctx.bindBuffer(ctx.ARRAY_BUFFER, glObj.texCoordObject);
213 ctx.vertexAttribPointer(1, 2, ctx.FLOAT, false, 0, 0);
214
215 ctx.bindBuffer(ctx.ELEMENT_ARRAY_BUFFER, glObj.indexObject);
216
217 // generate the model-view matrix
218 var mvMatrix = new CanvasMatrix4();
219 mvMatrix.scale(1, 1, 1);
220 mvMatrix.translate(0,0,0);
221 mvMatrix.rotate(180, 0,0,1);
222 mvMatrix.translate(tama.x,tama.y,10);
223
224 // construct the normal matrix from the model-view matrix
225 var normalMatrix = new CanvasMatrix4(mvMatrix);
226 normalMatrix.invert();
227 normalMatrix.transpose();
228 ctx.uniformMatrix4fv(ctx.getUniformLocation(ctx.program, "u_normalMatrix"), false, normalMatrix.getAsWebGLFloatArray());
229
230 // construct the model-view * projection matrix
231 var mvpMatrix = new CanvasMatrix4(mvMatrix);
232 mvpMatrix.multRight(ctx.perspectiveMatrix);
233 ctx.uniformMatrix4fv(ctx.getUniformLocation(ctx.program, "u_modelViewProjMatrix"), false, mvpMatrix.getAsWebGLFloatArray());
234
235 ctx.bindTexture(ctx.TEXTURE_2D, glObj.texture);
236 ctx.drawElements(ctx.TRIANGLES, glObj.numIndices, ctx.UNSIGNED_SHORT, 0);
237 }