view paper_shooting/resources/create_field.js @ 25:158b846e3874

paper
author <e085737>
date Mon, 14 Feb 2011 16:37:16 +0900
parents
children 6468848f4d22
line wrap: on
line source

createField = function(node, sgroot, w, h){
    var floor = new sgroot.createSceneGraph1("purple_cube");
    floor.xyz[0] =  210;
    floor.xyz[1] =  300;
    floor.xyz[2] = 0;
    floor.scale = 25.0;
    floor.set_move_collision(floor_move, no_collision_idle);
    node.addChild(floor);
    node.set_move_collision(createField2, no_collision_idle);
}


createField2 = function(node, sgroot, w, h){
    for(var num=0; num<10; num++){
        var floor = new sgroot.createSceneGraph1("purple_cube");
        floor.xyz[0] = 210 + 300*num;
        floor.xyz[1] = 300;
        floor.xyz[2] = 0;
        floor.scale = 25.0;
        console.log(floor.xyz[0]);
        floor.set_move_collision(floor_move, no_collision_idle);
        node.addChild(floor);
    }
    node.frame = 0;
    node.set_move_collision(createField3, no_collision_idle);
    //node.set_move_collision(no_move_idle, no_collision_idle);
}

createField4 = function(node, sgroot, w, h){
    if(node.frame > 1000 && 1 == node.frame%30){
        var tunnel_kind = node.tunnel_list[node.tunnel_num];
        var column = new sgroot. createSceneGraph1(tunnel_kind);
        column.xyz[0] = 425 + 295 * node.tunnel_num;
        column.xyz[1] =   0;
        column.xyz[2] = 210;
        column.angle[0] = -90;   
        column.dx = 1.0;
        column.dz = 3.0;
        column.limit =  80;
        column.scale = 25.0;
        column.set_move_collision(tunnel_up, no_collision_idle);
        node.addChild(column);
        node.tunnel_num++;

        if(node.tunnel_num > 4){
            node.set_move_collision(no_move_idle, no_collision_idle);
        }
    }
}


createField3 = function(node, sgroot, w, h){
    if(node.frame > 2400){
        var ground = new sgroot.createSceneGraph1("Ground");
        ground.xyz[0] = 2200;
        ground.xyz[1] =   0;
        ground.xyz[2] = 210;
        ground.angle[0] = -90;
        ground.dx = 1.0;
        ground.dz = 3.0;
        ground.limit =130;
        ground.scale = 25.0;
        ground.set_move_collision(ground_up, no_collision_idle);
        node.addChild(ground);
        node.frame = 0;
        node.set_move_collision(createField_meteo, no_collision_idle);
    }
}


createField5 = function(node, sgroot, w, h){
    if(node.frame > 100){
        var column = new sgroot.createSceneGraph1("Cu");
        column.xyz[0] = 0;
        column.xyz[1] = 150;
        column.xyz[2] = 145;
        column.angle[1] = 90;
        column.dx = 1.0;
        column.dz = 1.5;
        column.limit = 60;
        column.scale = 0.7;
        //column.set_move_collision(column_up, no_collision_idle);
        node.addChild(column);
        node.set_move_collision(no_move_idle, no_collision_idle);
    }
}

createField_meteo = function(node, sgroot, w, h){
    if(node.frame > 600 && 1 == node.frame%15){
        var meteo = new sgroot.createSceneGraph1("meteo1");
        meteo.xyz[0] = 200;
        meteo.xyz[1] = -150;
        meteo.xyz[2] = 160 * Math.random() - 160 * Math.random();
        meteo.dx = 0.2 + 1.8 * Math.random();
        meteo.dy = 0.2 + 1.8 * Math.random();
        meteo.scale = 0.6;
        meteo.combat = sgroot.list['Player'];
        meteo.my_bullet = sgroot.list['my_bullet'];
        meteo.set_move_collision(meteo_move, meteo_collision);
        node.addChild(meteo);
        node.set_move_collision(createField_meteo, no_collision_idle);
    }
    if(node.frame > 1300){
        node.set_move_collision(no_move_idle, no_collision_idle);
    }
}

meteo_move = function(node, sgroot, w, h){
    node.xyz[0] -= node.dx;
    node.xyz[1] += node.dy;
    if(node.xyz[0] < -200 || node.xyz[1] > 200){
        node.remove(node);
    }
}

meteo_collision = function(node, sgroot, w, h){
    var dx = node.combat.xyz[0] - node.xyz[0];    
    var dy = node.combat.xyz[1] - node.xyz[1];
    var dz = node.combat.xyz[2] - node.xyz[2];
    var ddx = dx*dx;
    var ddy = dy*dy;
    var ddz = dz*dz;
    var r = Math.sqrt(ddx+ddy+ddz);

    if(r < 12){
        node.all_remove(node.combat);
    }
}


floor_move = function(node, sgroot, w, h){
    node.xyz[0] -= 1;
    if(node.xyz[0] < -350){
        node.remove(node);
    }
}

tunnel_up = function(node, sgroot, w, h){
    node.xyz[2] -= node.dz;
    if(node.xyz[2] < node.limit){
        node.set_move_collision(tunnel_move, no_collision_idle);
    }
}

tunnel_move = function(node, sgroot, w, h){
    node.xyz[0] -= node.dx;
    if(node.xyz[0] < -350){
        node.remove(node);
    }
}

ground_up = function(node, sgroot, w, h){
    node.xyz[2] -= node.dz;
    if(node.xyz[2] < node.limit){
        node.set_move_collision(ground_move, no_collision_idle);
    }
}

ground_move = function(node, sgroot, w, h){
    node.xyz[0] -= node.dx;

    if(-1000 < node.xyz[0] && node.xyz[0] < 150 ){
        node.dx = 15.0;
    }if(node.xyz[0] <= -1000){
        node.dx = 30.0;
    }

    if(node.xyz[0] < -5500){
        node.remove(node);
    }
}

column_move = function(node, sgroot, w, h){
    node.xyz[0] -= node.dx;
    if(node.xyz[0] < -30){
        node.remove(node);
    }
}

column_up = function(node, sgroot, w, h){
    node.xyz[1] -= node.dz;
    if(node.xyz[1] < node.limit){
        node.set_move_collision(column_move, no_collision_idle);
    }
}


set_delay = function(node, sgroot, w, h){
    if(node.frame > 400){
        node.frame = 0;
        node.set_move_collision(createEnemy_fort, no_collision_idle);
    }
}