4
|
1 function Pad()
|
|
2 {
|
6
|
3 this.up=0;
|
|
4 this.down=0;
|
4
|
5 this.right=0;
|
|
6 this.left=0;
|
|
7 this.count=0;
|
|
8 this.state=0;
|
6
|
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;
|
4
|
25 return this;
|
|
26 }
|
|
27
|
6
|
28 function makePlayer( object )
|
4
|
29 {
|
|
30 this.x = 0;
|
|
31 this.y = 0;
|
|
32 this.z = 10;
|
|
33 this.dx = 0;
|
|
34 this.dy = 0;
|
|
35 this.idle = object["player_idle"];
|
|
36 this.rightmove = object["player_rightmove"];
|
|
37 this.leftmove = object["player_leftmove"];
|
|
38 this.turntoright = object["player_turntoright"];
|
|
39 this.turntoleft = object["player_turntoleft"];
|
|
40 this.image = this.idle;
|
|
41 return this;
|
|
42 }
|
|
43 function movePlayer( player, pad )
|
|
44 {
|
|
45
|
6
|
46 pad.right = Math.min(pad.right, 0.7);
|
|
47 pad.left = Math.min(pad.left, 0.7);
|
|
48 pad.up = Math.min(pad.up, 0.7);
|
|
49 pad.down = Math.min(pad.down, 0.7);
|
4
|
50
|
6
|
51 player.x -= pad.right;
|
|
52 player.x += pad.left;
|
4
|
53 player.y += pad.up;
|
|
54 player.y -= pad.down;
|
|
55
|
6
|
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);
|
|
60
|
4
|
61 if( pad.count == 1) pad.state=0;
|
|
62 if( pad.count > 0) pad.state=1;
|
|
63 if( pad.count > 10 ) pad.state=2;
|
|
64
|
|
65 if( pad.state == 0 ) player.image = player.idle;
|
|
66 if( pad.state == 1 ) {
|
6
|
67 if( pad.right > 0 ) player.image = player.turntoright;
|
|
68 if( pad.left > 0 ) player.image = player.turntoleft;
|
4
|
69 }
|
|
70 if( pad.state == 2 ) {
|
6
|
71 if( pad.right > 0 ) player.image = player.rightmove;
|
|
72 if( pad.left > 0 ) player.image = player.leftmove;
|
4
|
73 }
|
|
74
|
6
|
75
|
|
76
|
4
|
77
|
|
78 }
|
6
|
79
|
4
|
80 function drawPlayer(ctx, player, scale)
|
|
81 {
|
|
82 // setup VBOs
|
|
83 ctx.enableVertexAttribArray(0);
|
|
84 ctx.enableVertexAttribArray(1);
|
|
85 ctx.enableVertexAttribArray(2);
|
|
86
|
|
87 ctx.bindBuffer(ctx.ARRAY_BUFFER, player.image.vertexObject);
|
|
88 ctx.vertexAttribPointer(2, 3, ctx.FLOAT, false, 0, 0);
|
|
89
|
|
90 ctx.bindBuffer(ctx.ARRAY_BUFFER, player.image.normalObject);
|
|
91 ctx.vertexAttribPointer(0, 3, ctx.FLOAT, false, 0, 0);
|
|
92
|
|
93 ctx.bindBuffer(ctx.ARRAY_BUFFER, player.image.texCoordObject);
|
|
94 ctx.vertexAttribPointer(1, 2, ctx.FLOAT, false, 0, 0);
|
|
95
|
|
96 ctx.bindBuffer(ctx.ELEMENT_ARRAY_BUFFER, player.image.indexObject);
|
|
97
|
|
98 // generate the model-view matrix
|
|
99 var mvMatrix = new CanvasMatrix4();
|
|
100 mvMatrix.scale(scale, scale, scale);
|
|
101 mvMatrix.rotate(180, 0,0,1);
|
|
102 mvMatrix.translate(player.x, player.y, player.z);
|
|
103
|
|
104 // construct the normal matrix from the model-view matrix
|
|
105 var normalMatrix = new CanvasMatrix4(mvMatrix);
|
|
106 normalMatrix.invert();
|
|
107 normalMatrix.transpose();
|
|
108 ctx.uniformMatrix4fv(ctx.getUniformLocation(ctx.program, "u_normalMatrix"), false, normalMatrix.getAsWebGLFloatArray());
|
|
109
|
|
110 // construct the model-view * projection matrix
|
|
111 var mvpMatrix = new CanvasMatrix4(mvMatrix);
|
|
112 mvpMatrix.multRight(ctx.perspectiveMatrix);
|
|
113 ctx.uniformMatrix4fv(ctx.getUniformLocation(ctx.program, "u_modelViewProjMatrix"), false, mvpMatrix.getAsWebGLFloatArray());
|
|
114
|
|
115 ctx.bindTexture(ctx.TEXTURE_2D, player.image.texture);
|
|
116 ctx.drawElements(ctx.TRIANGLES, player.image.numIndices, ctx.UNSIGNED_SHORT, 0);
|
|
117 }
|
6
|
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 }
|