view webGL/dandy/resources/Character.js @ 12:61febc94fa62

upload dandy4.html,new xmlFile
author NOBUYASU Oshiro
date Thu, 15 Jul 2010 07:08:37 +0900
parents 680b5b0cd1e4
children 4684e849866c
line wrap: on
line source

stage = 0;
active_chara_list = new Object();
active_chara_list.enemy = [];
active_chara_list.tama = [];
count = 0;
rinkx = 0;
rinky = 0;
rinkf1 = 0;rinkf2 = 0;
asteroidi = 0;
enemyfaste = 0;
enemycount = 0;
sf = 0;
amari = 0;
tekino0 = new Character();
gameflag = 0;

function Character()
{
    this.x=0;
    this.y=0;
    this.scale=1.0;
    this.dx=0;
    this.dy=0;
    this.w=0;
    this.h=0;
    this.vit=0;
    this.score=0;
    this.dt1=0;
    this.dt2=0;
    this.charano=0;
    this.tama=0;
    this.f=false;
    this.flag=false;
    this.s=0;

    this.state=0;
    this.collision=0;

    this.next=0;
    this.prev=0;

    this.image=new Object();
    this.texture=new Object();

    return this;
}

function PutSprite( ctx, glObj)
{

    // setup VBOs
    ctx.enableVertexAttribArray(0);
    ctx.enableVertexAttribArray(1);
    ctx.enableVertexAttribArray(2);
				
    ctx.bindBuffer(ctx.ARRAY_BUFFER, glObj.image.vertexObject);
    ctx.vertexAttribPointer(2, 3, ctx.FLOAT, false, 0, 0);
    ctx.bindBuffer(ctx.ARRAY_BUFFER, glObj.image.normalObject);
    ctx.vertexAttribPointer(0, 3, ctx.FLOAT, false, 0, 0);
    
    ctx.bindBuffer(ctx.ARRAY_BUFFER, glObj.image.texCoordObject);
    ctx.vertexAttribPointer(1, 2, ctx.FLOAT, false, 0, 0);
				
    ctx.bindBuffer(ctx.ELEMENT_ARRAY_BUFFER, glObj.image.indexObject);

    // generate the model-view matrix
    var mvMatrix = new CanvasMatrix4();
    //    mvMatrix.scale(jiki.scale, jiki.scale, jiki.scale);
    mvMatrix.scale(glObj.scale, glObj.scale, glObj.scale);
    mvMatrix.translate(glObj.x,glObj.y,10);
    
    // construct the normal matrix from the model-view matrix
    var normalMatrix = new CanvasMatrix4(mvMatrix);
    normalMatrix.invert();
    normalMatrix.transpose();
    ctx.uniformMatrix4fv(ctx.getUniformLocation(ctx.program, "u_normalMatrix"), false, normalMatrix.getAsWebGLFloatArray());
    
    // construct the model-view * projection matrix
    var mvpMatrix = new CanvasMatrix4(mvMatrix);
    mvpMatrix.multRight(ctx.perspectiveMatrix);
    ctx.uniformMatrix4fv(ctx.getUniformLocation(ctx.program, "u_modelViewProjMatrix"), false, mvpMatrix.getAsWebGLFloatArray());
    
    ctx.bindTexture(ctx.TEXTURE_2D, glObj.texture);
    ctx.drawElements(ctx.TRIANGLES, glObj.image.numIndices, ctx.UNSIGNED_SHORT, 0);


}

function obj_draw( ctx )
{
    for(var i = 0; Boolean(active_chara_list.enemy[i]); i++)
	{
	    if(active_chara_list.enemy[i].flag == true)
		{
		    PutSprite(ctx,active_chara_list.enemy[i]);
		}
	}
}

function delete_obj( ctx )
{
    for(var i = 0; Boolean(active_chara_list.enemy[i]); i++)
	{
	    //敵が消えたら配列から消す
	    if(active_chara_list.enemy[i].flag == false)
		{
		    active_chara_list.enemy.splice(i,1);
		}
	}
    for(i=0; Boolean(bchar[i]); i++ )
	{
	    //ボム(撃破)処理を終えたら配列から消す
	    if(bchar[i].no == 8) bchar[i].no.splice(i,1);
	}
}