アットウィキロゴ

seiji

<!DOCTYPE html>
<html lang="ja">
    <head>
        <meta charset="utf-8" />
        <script src="sample.js"></script>
        <script src="jquery.js"></script>
<script src="svgpaint.js"></script>
        <title>music</title>
    </head>
    <body onload="sample()">
   <p id="memo"></p>
        <div>  
  <input id="but" type="button" value="ハンドル" />
  </div>
   </body>
</html>
 
 
 
 
var ball = new Array();
var bx = new Array();
var by = new Array();
var dx = new Array();
var dy = new Array();
 
var number;
var nx = new Array();
var ny = new Array();
 
function sample(){
 
 number = 100;
 
for(s=1;s<101;s++){
nx[s]=randn();
ny[s]=randn();
}
 
 
for(s=1;s<101;s++){
bx[s]=0;
by[s]=0;
dx[s]=0;
dy[s]=0;
ball[s]=0;    
}
 
$("#but").click(function () {
 strike();
});
 
var timer;
var delay = 100;
 
var loop = function () {
 
    move();
 
    bomb();
 
    wall();
 
    de();
 
 
   paint();
 
    clearTimeout(timer);
    timer = setTimeout(loop, delay);
}
 
loop();
 
 
 
 
}
 
 
 
function strike(){
 
 
    sx = 0;
for(s=1;s<101;s++){
if(ball[s]<50)sx=s;    
}
 
if (sx > 0) bx[sx] = 500;
if (sx > 0) by[sx] = 1000;
if (sx > 0) ball[sx] = 100;
if (sx > 0) dx[sx] =randx();
if (sx > 0) dy[sx] =0;
 
}
 
function de(){
 
for(s=1;s<101;s++){
h = 0;
if (by[s] < 10) h = h + 1;
if (ball[s] >50) h = h + 1;
if (h == 2) ball[s] = 0;
}
 
 
}
 
function wall() {
 
for(s=1;s<101;s++){
    h = 0;
if(bx[s]>990)h=h+1;    
if(dx[s]>0)h=h+1;
if (h == 2) dx[s] = -dx[s];
h = 0;
if(bx[s]<10)h=h+1;    
if(dx[s]<0)h=h+1;
if (h == 2) dx[s] = -dx[s];
}
 
 
}
 
 
 
 
function move(){
 
g = 1;
 
for(s=1;s<101;s++){
dy[s] = dy[s] - g;
}  
 
for(s=1;s<101;s++){
bx[s]=bx[s]+dx[s];
by[s] = by[s] + dy[s];
}
 
 
 
 
}
 
 
 
function paint(){
 
var sub=new svgpaint();
 
str="<svg width=\"500\" height=\"500\">";
 
str=str+sub.rect(0,0,500,500,"blue"); 
for(s=1;s<101;s++){    
if(ball[s]>50)str=str+sub.circle(5*bx[s]/10,500-5*by[s]/10,5,"red");
}
 
for(s=1;s<101;s++){    
str=str+sub.rect(5*nx[s],500-5*ny[s],5,5,"green");
}
 
str=str+"</svg>";
 
$("#memo").html(str);   
 
}
 
 
 
 
function bomb(){
 
for(s=1;s<101;s++){
    x1 = Math.floor(bx[s] / 10);
    y1 = Math.floor(by[s] / 10);
for(sx=1;sx<101;sx++){
h=0;
if(x1==nx[sx])h=h+1;
if(y1==ny[sx])h=h+1;
if (h == 2) dx[s] = -dx[s];
if (h == 2) dy[s] = -0.5*dy[s];  
}}
 
}
 
 
function randn(){
 
n1=100*Math.random();
n2=Math.floor(n1)+1;
 
return n2;
} 
function randx(){
 
n1=10*Math.random();
n2=Math.floor(n1)+1;
 
return n2;
}
最終更新:2015年06月08日 19:08