アットウィキロゴ

hg39876778

var ball = new Array();
var bx = new Array();
var by = new Array();
var dx = new Array();
var dy = new Array();
var nx = new Array();
var ny = new Array();
var x_flag, y_flag;
var mode;
 
function sample() {
 
    faststep();
 
    $("#but").click(function () {
        strike();
    });
 
    var timer;
    var delay = 100;
 
    var loop = function () {
 
        move();
 
        bomb();
 
        de();
 
        check();
 
        paint();
 
        clearTimeout(timer);
        timer = setTimeout(loop, delay);
    }
 
    loop();
 
 
 
 
 
}
 
function check() {
 
    for (s = 1; s < 101; s++) {
        x1 = Math.floor(bx[s] / 10);
        y1 = Math.floor(by[s] / 10);
        h = 0;
        d1 = (x1 - x_flag) * (x1 - x_flag);
        d1 = d1 + (y1 - y_flag) * (y1 - y_flag);
        if (d1 < 25) h = h + 1;
        if (ball[s] > 60) h = h + 1;
        if (h == 2) mode = 2;
        if (h == 2) ball[s] = 0;
 
    }
 
    h = 0;
    if (Math.random() > 0.9) h = h + 1;
    if (mode == 2) h = h + 1;
    if (h == 2) mode = 1;
 
 
}
 
 
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 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 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++) {
        str = str + sub.rect(5 * nx[s], 500 - 5 * ny[s], 5, 5, "black");
    }
 
 
    for (s = 1; s < 101; s++) {
        if (ball[s] > 50) str = str + sub.circle(5 * bx[s] / 10, 500 - 5 * by[s] / 10, 2, "red");
    }
 
    if (mode == 1) str = str + sub.circle(5 * x_flag, 500 - 5 * y_flag, 25, "yellow");
    c1 = "green";
    if (Math.random() > 0.5) c1 = "red";
    if (mode == 2) str = str + sub.circle(5 * x_flag, 500 - 5 * y_flag, 25, c1);
 
 
 
 
    str = str + "</svg>";
 
    $("#memo").html(str);
 
}
 
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 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 randx() {
 
    n1 = 10 * Math.random();
    n2 = Math.floor(n1) + 1;
 
    return n2;
}
 
function randn() {
 
    n1 = 100 * Math.random();
    n2 = Math.floor(n1) + 1;
 
    return n2;
}
 
 
function faststep() {
 
    var s;
 
    for (s = 1; s < 101; s++) {
        bx[s] = 0;
        by[s] = 0;
        dx[s] = 0;
        dy[s] = 0;
        ball[s] = 0;
    }
 
    for (s = 1; s < 101; s++) {
        nx[s] = randn();
        ny[s] = randn();
    }
 
    x_flag = 50;
    y_flag = 50;
 
    mode = 1;
 
}
最終更新:2015年06月20日 10:41