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

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

enemy_move1 = function(node, sgroot, w, h){
    node.xyz[2] -= node.dz; 
    if(node.xyz[2] < -10){
        node.set_move_collision(homing_shot, enemy_collision_2d);
    }
}

enemy_move2 = function(node, sgroot, w, h){
    node.xyz[2] += node.dz;
    if(node.xyz[2] > -120){
        node.set_move_collision(homing_shot, enemy_collision_2d);
    }
}

enemy_move3 = function(node, sgroot, w, h){
    node.xyz[2] -= node.dz;
    if(node.xyz[2] < -65){
        node.set_move_collision(homing_shot, enemy_collision_2d);
    }
}

enemy_move4 = function(node, sgroot, w, h){
    node.xyz[2] += node.dz;
    if(node.xyz[2] > -65){
        node.set_move_collision(circle_shot, enemy_collision_2d);
    }
}

enemy_move5 = function(node, sgroot, w, h){
    node.xyz[2] -= node.dz;
    if(node.xyz[2] < -65){
        node.set_move_collision(circle_shot, enemy_collision_2d);
    }
}

enemy_move6 = function(node, sgroot, w, h){
    node.xyz[2] -= node.dz; 
    if(node.xyz[2] < -10){
        node.set_move_collision(circle_shot, enemy_collision_2d);
    }
}

enemy_move7 = function(node, sgroot, w, h){
    node.xyz[2] += node.dz;
    if(node.xyz[2] > -120){
        node.set_move_collision(circle_shot, enemy_collision_2d);
    }
}

fort_move = function(node, sgroot, w, h){
    node.xyz[2] += node.dz;
    if(node.xyz[2] > -130){
        node.set_move_collision(homing_shot_fort, enemy_collision_2d);
    }
}

run_away_right = function(node, sgroot, w, h){
    node.xyz[0] += 2.0;
    if(node.xyz[0] > 400){
        node.remove(node);
    }
}

run_away_left = function(node, sgroot, w, h){
    node.xyz[0] -= 2.0;
    if(node.xyz[0] < -130){
        node.remove(node);
    }
}

run_away_up = function(node, sgroot, w, h){
    node.xyz[2] += 2.0;
    if(node.xyz[2] > 200){
        node.remove(node);
    }
}

run_away_down = function(node, sgroot, w, h){
    node.xyz[2] -= 2.0;
    if(node.xyz[2] < -200){
       node.remove(node);
    } 
}

fort_down = function(node, sgroot, w, h){
    node.xyz[0] -= node.dx;
    if(node.frame > 50){
        node.xyz[2] -= 1.0;
        if(node.xyz[2] < -200){
            node.remove(node);
        }
    }
}

machida_down = function(node, sgroot, w, h){
    node.xyz[1] += node.dy;
    if(node.xyz[1] > 45){
        node.frame = 0;
        node.set_move_collision(machida_shot, machida_collision);
    }
}

machida_down2 = function(node, sgroot, w, h){
    node.xyz[1] += node.dy;
    if(node.xyz[1] > 45){
        node.frame = 0;
        node.set_move_collision(machida_shot2, machida_collision);
    }
}

machida_down3 = function(node, sgroot, w, h){
    node.xyz[1] += node.dy;
    if(node.xyz[1] > 45){
        node.frame = 0;
        node.set_move_collision(machida_shot, machida_collision2);
    }
}

machida_up = function(node, sgroot, w, h){
    node.xyz[1] -= node.dy;
    if(node.xyz[1] < -400){
        node.frame = 0;
        node.set_move_collision(no_move_idle, no_collision_idle);
        node.remove(node);
    }
}

machida_left = function(node, sgroot, w, h){
    node.xyz[2] += node.dz;
}

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

        var vec_x = dx/r;
        var vec_y = dy/r;
        var vec_z = dz/r; 

        var bullet_speed = node.speed;

        var bullet = new sgroot.createSceneGraph1("red_3d");
        bullet.margin = sgroot.sg_src["red_3d"].model_x;
        bullet.xyz[0] = -node.xyz[2] - bullet.margin;
        bullet.xyz[1] = node.xyz[1];
        bullet.xyz[2] = node.xyz[0];
        bullet.dx = bullet_speed * vec_x;
        bullet.dy = bullet_speed * vec_y;
        bullet.dz = bullet_speed * vec_z;
        bullet.scale = 0.3;
        bullet.set_move_collision(bullet_move3, no_collision_idle);
        node.bullet.addChild(bullet);

        var dx = node.combat.xyz[0] + node.xyz[2];
        var dy = node.combat.xyz[1] - node.xyz[1];
        var dz = node.combat.xyz[2] - node.xyz[0] + 45;
        var ddx = dx*dx;
        var ddy = dy*dy;
        var ddz = dz*dz;
        var r = Math.sqrt(ddx+ddy+ddz);

        var vec_x = dx/r;
        var vec_y = dy/r;
        var vec_z = dz/r; 

        var bullet2 = new sgroot.createSceneGraph1("red_3d");
        bullet2.margin = sgroot.sg_src["red_3d"].model_x;
        bullet2.xyz[0] = -node.xyz[2] - bullet.margin;
        bullet2.xyz[1] = node.xyz[1];
        bullet2.xyz[2] = node.xyz[0] - 45;
        bullet2.dx = bullet_speed * vec_x;
        bullet2.dy = bullet_speed * vec_y;
        bullet2.dz = bullet_speed * vec_z;
        bullet2.scale = 0.3;
        bullet2.set_move_collision(bullet_move3, no_collision_idle);
        node.bullet.addChild(bullet2);
    }
}


machida_shot2 = function(node, sgroot, w, h){
    node.xyz[0] -= node.dx;
    if(node.frame > 80 && 1 == node.frame%node.interval && node.xyz[0] > -300){
        for(var num=1; num < 37; num++){
            var bullet = new sgroot.createSceneGraph1("red_3d");
            var radian = (20*num)/360*Math.PI;
            bullet.margin = sgroot.sg_src["red_3d"].model_x;
            bullet.xyz[0] = -node.xyz[0] - bullet.margin + 51;
            bullet.xyz[1] =  node.xyz[1] + 45;
            bullet.xyz[2] = -node.xyz[2];
            bullet.dx = Math.cos(radian) * 0.4;
            bullet.dy = Math.sin(radian) * 0.4;
            bullet.dz = -3.0;
            bullet.scale = 0.3;
            bullet.set_move_collision(bullet_move3, no_collision_idle);
            node.bullet.addChild(bullet);
        }
    }
    if(node.xyz[0] < -500){
        node.set_move_collision(machida_up, no_collision_idle);
    }
}

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

        var vec_x = dx/r;
        var vec_y = dy/r;
        var vec_z = dz/r; 

        var bullet_speed = 1.5;

        var bullet = new sgroot.createSceneGraph1(node.bullet_kind);
        bullet.margin = sgroot.sg_src[node.bullet_kind].model_x;
        bullet.xyz[0] = node.xyz[0] - bullet.margin;
        bullet.xyz[1] = -node.xyz[2];
        bullet.xyz[2] = node.xyz[1];
        bullet.dx = bullet_speed * vec_x;
        bullet.dy = bullet_speed * vec_y;
        bullet.dz = bullet_speed * vec_z;
        bullet.scale = 0.3;
        bullet.set_move_collision(bullet_move3, no_collision_idle);
        node.bullet.addChild(bullet);
        node.shot++;
        
        if(node.shot > 5){
            node.set_move_collision(run_away_left, enemy_collision_2d);
        }
    }
}

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

            var vec_x = dx/r;
            var vec_y = dy/r;
            var vec_z = dz/r; 
            var bullet_speed = node.speed;

            var bullet = new sgroot.createSceneGraph1(node.bullet_kind);
            bullet.margin = sgroot.sg_src[node.bullet_kind].model_x;
            bullet.xyz[0] = node.xyz[0] - bullet.margin;
            bullet.xyz[1] = -node.xyz[2];
            bullet.xyz[2] = node.xyz[1];
            bullet.dx = bullet_speed * vec_x;
            bullet.dy = bullet_speed * vec_y;
            bullet.dz = bullet_speed * vec_z;
            bullet.scale = 0.3;
            bullet.set_move_collision(bullet_move3, no_collision_idle);
            node.bullet.addChild(bullet);
            node.shot++;

            if(node.shot > 15){
                node.set_move_collision(fort_down, enemy_collision_2d);
                node.frame = 0;
            }
        }
    }
}


funDown_shot = function(node, sgroot, w, h){
    for(var num=1; num < 21; num++){
        var bullet_speed = 1.5;
        var radian = (30+6*num)/360*Math.PI;

        var bullet = new sgroot.createSceneGraph1("red_3d");
        bullet.margin = sgroot.sg_src["red_3d"].model_x;
        bullet.xyz[0] = node.xyz[0] - bullet.margin;
        bullet.xyz[1] = -node.xyz[2];
        bullet.xyz[2] = node.xyz[1];
        bullet.dx = -bullet_speed * Math.sin(radian) + 0.3;
        bullet.dy = bullet_speed * Math.cos(radian);
        bullet.dz = 0.0;
        bullet.scale = 0.3;
        bullet.set_move_collision(bullet_move3, no_collision_idle);
        node.bullet.addChild(bullet);
    }
    node.set_move_collision(run_away_left, enemy_collision_2d);
}


funUp_shot = function(node, sgroot, w, h){
    for(var num=1; num < 21; num++){
        var bullet_speed = 1.5;
        var radian = (30+6*num)/360*Math.PI;

        var bullet = new sgroot.createSceneGraph1("Red3d");
        bullet.margin = sgroot.sg_src["Red3d"].model_x;
        bullet.xyz[0] = node.xyz[0] - bullet.margin;
        bullet.xyz[1] = -node.xyz[2];
        bullet.xyz[2] = node.xyz[1];
        bullet.dx = -bullet_speed * Math.sin(radian) + 0.3;
        bullet.dy = -bullet_speed * Math.cos(radian);
        bullet.dz = 0.0;
        bullet.scale = 0.3;
        bullet.set_move_collision(bullet_move3, no_collision_idle);
        node.bullet.addChild(bullet);
    }
    node.set_move_collision(run_away_left, enemy_collision_2d);
}


circle_shot = function(node, sgroot, w, h){
    for(var num=1; num < 37; num++){
        var bullet_speed = 1.5;
        var radian = (10*num)/180*Math.PI;

        var bullet = new sgroot.createSceneGraph1(node.bullet_kind);
        bullet.margin = sgroot.sg_src[node.bullet_kind].model_x;
        bullet.xyz[0] = node.xyz[0] - bullet.margin;
        bullet.xyz[1] = -node.xyz[2];
        bullet.xyz[2] = node.xyz[1];
        bullet.dx = -bullet_speed;
        bullet.dy = Math.sin(radian) * 0.4;
        bullet.dz = Math.cos(radian) * 0.4;
        bullet.scale = 0.3;
        bullet.set_move_collision(bullet_move3, no_collision_idle);
        node.bullet.addChild(bullet);
    }
    node.set_move_collision(run_away_left, enemy_collision_2d);
}


circle_shot2 = function(node, sgroot, w, h){
    for(var num=1; num < 37; num++){
        var bullet_speed = 1.5;
        var radian = (20*num)/360*Math.PI;

        var bullet = new sgroot.createSceneGraph1("Blue3d");
        bullet.margin = sgroot.sg_src["Blue3d"].model_x;
        bullet.xyz[0] = node.xyz[0] - bullet.margin;
        bullet.xyz[1] = -node.xyz[2];
        bullet.xyz[2] = node.xyz[1];
        bullet.dx = -bullet_speed;
        bullet.dy = Math.sin(radian) * 0.3;
        bullet.dz = Math.cos(radian) * 0.3;
        bullet.scale = 0.3;
        bullet.set_move_collision(bullet_move3, no_collision_idle);
        node.bullet.addChild(bullet);
    }
    node.set_move_collision(run_away, enemy_collision_2d);
}



circle_shot3_3d = function(node, sgroot, w, h){
    for(var num=1; num < 37; num++){
        var bullet_speed = 1.5;
        var radian = (20*num)/360*Math.PI;

        var bullet = new sgroot.createSceneGraph1("yellow3d");
        bullet.margin = sgroot.sg_src["yellow3d"].model_x;
        bullet.xyz[0] = node.xyz[0] - bullet.margin;
        bullet.xyz[1] = -node.xyz[2];
        bullet.xyz[2] = node.xyz[1];
        bullet.dx = -bullet_speed;
        bullet.dy = Math.sin(radian) * 0.4;
        bullet.dz = Math.cos(radian) * 0.4;
        bullet.scale = 0.3;
        bullet.set_move_collision(bullet_move3, no_collision_idle);
        node.bullet.addChild(bullet);
    }
    node.set_move_collision(run_away, enemy_collision_2d);
}