初次提交

This commit is contained in:
2022-09-19 18:05:01 +08:00
commit 57051fc44b
5401 changed files with 325410 additions and 0 deletions

View File

@@ -0,0 +1,470 @@
package com.bn.gameView;
import static com.bn.gameView.Constant.ANGLE_X_Z;
import static com.bn.gameView.Constant.ARCHIBALD_X;
import static com.bn.gameView.Constant.ARCHIBALD_Y;
import static com.bn.gameView.Constant.ARCHIBALD_Z;
import static com.bn.gameView.Constant.ARCHIE_BOMB_VELOCITY;
import static com.bn.gameView.Constant.ARSENAL_X;
import static com.bn.gameView.Constant.ARSENAL_Y;
import static com.bn.gameView.Constant.ARSENAL_Z;
import static com.bn.gameView.Constant.ArchieArray;
import static com.bn.gameView.Constant.BOMB_MAX_DISTANCE;
import static com.bn.gameView.Constant.BOMB_VELOCITY;
import static com.bn.gameView.Constant.PLANE_X;
import static com.bn.gameView.Constant.PLANE_X_R;
import static com.bn.gameView.Constant.PLANE_Y;
import static com.bn.gameView.Constant.PLANE_Y_R;
import static com.bn.gameView.Constant.PLANE_Z;
import static com.bn.gameView.Constant.TANK_BOMB_VELOCITY;
import static com.bn.gameView.Constant.archie_List;
import static com.bn.gameView.Constant.archie_bomb_List;
import static com.bn.gameView.Constant.bomb_List;
import static com.bn.gameView.Constant.fire_index;
import static com.bn.gameView.Constant.gradeArray;
import static com.bn.gameView.Constant.isno_Hit;
import static com.bn.gameView.Constant.isno_Lock;
import static com.bn.gameView.Constant.mapId;
import static com.bn.gameView.Constant.nx;
import static com.bn.gameView.Constant.ny;
import static com.bn.gameView.Constant.nz;
import static com.bn.gameView.Constant.tank_bomb_List;
import static com.bn.gameView.GLGameView.arsenal;
import static com.bn.gameView.GLGameView.baoZhaList;
import static com.bn.gameView.GLGameView.bombRect;
import static com.bn.gameView.GLGameView.bombRectr;
import static com.bn.gameView.GLGameView.bomb_height;
import static com.bn.gameView.GLGameView.enemy;
import static com.bn.gameView.GLGameView.tankeList;
import java.util.Iterator;
import com.bn.archieModel.ArchieForControl;
import com.bn.arsenal.Arsenal_House;
import com.bn.commonObject.BallTextureByVertex;
import com.bn.commonObject.DrawBomb;
import com.bn.core.MatrixState;
import com.bn.planeModel.EnemyPlane;
import com.bn.tankemodel.TanKe;
//炮弹的控制类
public class BombForControl
{
GLGameView gv;
private BallTextureByVertex bomb_ball;//子弹类
//定义发射炮弹时飞机的仰角和方位角
private float curr_elevation;
private float curr_direction;
//炮弹的位置
private float curr_x;
private float curr_y;
private float curr_z;
private float distance;//飞行距离
//飞机发射炮弹锁定
private boolean islocked;
private float curr_nx;
private float curr_ny;
private float curr_nz;
private float average;//平均向量
//飞机发射炮弹的构造器
public BombForControl(GLGameView gv,BallTextureByVertex bomb_ball,float plane_x,float plane_y,float plane_z,
float plane_elevation,float plane_direction,float rotationAngle_Plane_X,float rotationAngle_Plane_Y,
float rotationAngle_Plane_Z)
{
this.gv=gv;
//创建纹理球
this.bomb_ball=bomb_ball;
this.curr_elevation=plane_elevation;
this.curr_direction=plane_direction;
this.islocked=isno_Lock;
if(islocked)
{
curr_nx=nx;
curr_ny=ny;
curr_nz=nz;
average=(float) Math.sqrt(curr_nx*curr_nx+curr_ny*curr_ny+curr_nz*curr_nz);
}
//初始化炮弹的发射位置
initData(plane_x,plane_y,plane_z,rotationAngle_Plane_X,rotationAngle_Plane_Y,rotationAngle_Plane_Z);
}
//高射炮和坦克发射炮弹的构造器
public BombForControl(GLGameView gv,BallTextureByVertex bomb_ball,float[]init_position,float init_elevation,float init_direction)
{
this.gv=gv;
this.bomb_ball=bomb_ball;
curr_x=init_position[0];//
curr_y=init_position[1];//
curr_z=init_position[2];//
curr_elevation=init_elevation;
curr_direction=init_direction;
}
//确定飞机机翼炮弹的发射位置
public void initData(float plane_x,float plane_y,float plane_z,float rotationAngle_Plane_X,
float rotationAngle_Plane_Y,float rotationAngle_Plane_Z)
{
//设定左机翼发射炮弹的位置
curr_x=plane_x;
curr_y=plane_y;
curr_z=plane_z;
//炮弹位置的相关参数
float length;
float ori_y;
float ori_z;
length=12;
if(fire_index!=1)//左机翼发射炮弹
{
ori_y=90;
ori_z=-2;
}
else//右机翼发射炮弹
{
ori_y=-90;
ori_z=-2;
}
//确定炮弹的最终位置
curr_y=curr_y-(float)Math.sin(Math.toRadians(rotationAngle_Plane_Z+ori_z))*length;
curr_x=curr_x-(float)Math.cos(Math.toRadians(rotationAngle_Plane_Z+ori_z))*(float)Math.sin(Math.toRadians(rotationAngle_Plane_Y+ori_y))*length;
curr_z=curr_z-(float)Math.cos(Math.toRadians(rotationAngle_Plane_Z+ori_z))*(float)Math.cos(Math.toRadians(rotationAngle_Plane_Y+ori_y))*length;
}
public void drawSelf(int texId)
{
MatrixState.pushMatrix();
MatrixState.translate(curr_x, curr_y, curr_z);
bomb_ball.drawSelf(texId);
MatrixState.popMatrix();
}
//飞机发射炮弹
public void go()
{
distance+=BOMB_VELOCITY;//子弹的行驶路程增加
if(distance>=BOMB_MAX_DISTANCE)//如果子弹步长超出了
{
Iterator<BombForControl> ite=bomb_List.iterator();
gv.activity.playSound(1,0);
while(ite.hasNext())
{
if(ite.next()==this)
{
ite.remove();
return;
}
}
}
float tyy;
if((tyy=KeyThread.isYachtHeadCollectionsWithLandPaodan(curr_x,curr_y,curr_z))>0){
baoZhaList.add(new DrawBomb(bombRectr,curr_x,tyy,curr_z));//如果炮弹撞击地面
Iterator<BombForControl> ite=bomb_List.iterator();
while(ite.hasNext())
{
if(ite.next()==this)
{
ite.remove();
return;
}
}
}
//判断是否和军火库发生碰撞
for(Arsenal_House as:arsenal){
if(//军火库还存在
curr_y>as.ty&&curr_y<as.ty+ARSENAL_Y
&&curr_x>as.tx-ARSENAL_X&&curr_x<as.tx+ARSENAL_X
&&curr_z>as.tz-ARSENAL_Z&&curr_z<as.tz+ARSENAL_Z){
as.blood-=ArchieArray[mapId][8][0];//军火库的血减1
if(as.blood<1){//如果军火库被炸毁
gv.activity.playSound(0,0);
try
{
Iterator<Arsenal_House> ite=arsenal.iterator();
while(ite.hasNext())
{
if(ite.next()==as)
{
ite.remove();
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
baoZhaList.add(new DrawBomb(bombRect,as.tx,as.ty+bomb_height/2,as.tz));
gradeArray[1]+=ArchieArray[mapId][12][3];//得分增加,
}
Iterator<BombForControl> ite=bomb_List.iterator();
while(ite.hasNext())
{
if(ite.next()==this)
{
ite.remove();
return;
}
}
}
}
for(ArchieForControl afc:archie_List){//查看有没有击中高射炮
if(curr_y>afc.position[1]&&curr_y<afc.position[1]+ARCHIBALD_Y*2
&&curr_x>afc.position[0]-ARCHIBALD_X*2&&curr_x<afc.position[0]+ARCHIBALD_X*2
&&curr_z>afc.position[2]-ARCHIBALD_Z*2&&curr_z<afc.position[2]+ARCHIBALD_Z*2){
afc.blood-=ArchieArray[mapId][8][2];//高射炮的血减10
if(afc.blood<0){
gv.activity.playSound(0,1);
try
{
Iterator<ArchieForControl> ite=archie_List.iterator();
while(ite.hasNext())
{
if(ite.next()==afc)
{
ite.remove();
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
baoZhaList.add(new DrawBomb(bombRect,curr_x,afc.position[1]+ARCHIBALD_Y,curr_z));
gradeArray[1]+=ArchieArray[mapId][12][1];//得分增加,
}
Iterator<BombForControl> ite=bomb_List.iterator();
while(ite.hasNext())
{
if(ite.next()==this)
{
ite.remove();
return;
}
}
}
}
for(TanKe afc:tankeList)//查看有没有击中坦克
{
if(curr_y>afc.ty&&curr_y<afc.ty+ARCHIBALD_Y
&&curr_x>afc.tx-ARCHIBALD_X&&curr_x<afc.tx+ARCHIBALD_X
&&curr_z>afc.tz-ARCHIBALD_Z&&curr_z<afc.tz+ARCHIBALD_Z)
{
afc.blood-=ArchieArray[mapId][8][1];//坦克的血减1
if(afc.blood<=0)
{
gv.activity.playSound(0,1);
try
{
Iterator<TanKe> ite=tankeList.iterator();
while(ite.hasNext())
{
if(ite.next()==afc)
{
ite.remove();
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
gradeArray[1]+=ArchieArray[mapId][12][0];//得分增加,
}
baoZhaList.add(new DrawBomb(bombRect,curr_x,curr_y+bomb_height/5,curr_z));
Iterator<BombForControl> ite=bomb_List.iterator();
while(ite.hasNext())
{
if(ite.next()==this)
{
ite.remove();
return;
}
}
}
}
//有没有击中敌机
for(EnemyPlane afc:enemy){//查看有没有击中
if(curr_y>afc.ty-PLANE_Y_R&&curr_y<afc.ty+PLANE_Y_R
&&curr_x>afc.tx-PLANE_X_R&&curr_x<afc.tx+PLANE_X_R
&&curr_z>afc.tz-ANGLE_X_Z&&curr_z<afc.tz+ANGLE_X_Z){
afc.blood-=ArchieArray[mapId][8][3];//敌机的血减1
gv.activity.playSound(8,0);
if(afc.blood<=0){
gv.activity.playSound(0,1);
try
{
Iterator<EnemyPlane> ite=enemy.iterator();
while(ite.hasNext())
{
if(ite.next()==afc)
{
ite.remove();
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
gradeArray[1]+=ArchieArray[mapId][12][2];//得分增加,
}
baoZhaList.add(new DrawBomb(bombRect,curr_x,curr_y+bomb_height/5,curr_z));
Iterator<BombForControl> ite=bomb_List.iterator();
while(ite.hasNext())
{
if(ite.next()==this)
{
ite.remove();
return;
}
}
}
}
//这里判断是否锁定目标
if(islocked)//如果锁定目标
{
curr_x+=curr_nx/average*BOMB_VELOCITY;
curr_z+=curr_nz/average*BOMB_VELOCITY;
curr_y+=curr_ny/average*BOMB_VELOCITY;
}
else
{
//计算炮弹下一步的位置
//计算当前仰角和方向角
curr_x=curr_x-(float)(Math.cos(Math.toRadians(curr_elevation))*Math.sin(Math.toRadians(curr_direction))*BOMB_VELOCITY);
curr_z=curr_z-(float)(Math.cos(Math.toRadians(curr_elevation))*Math.cos(Math.toRadians(curr_direction))*BOMB_VELOCITY);
curr_y=curr_y+(float)(Math.sin(Math.toRadians(curr_elevation))*BOMB_VELOCITY);//飞机的位置
}
}
//高射炮发射炮弹
public void go_archie()
{
float curr_planeX=PLANE_X;
float curr_planeY=PLANE_Y;
float curr_planeZ=PLANE_Z;
distance+=ARCHIE_BOMB_VELOCITY;//子弹的行驶路程增加
if(distance>=BOMB_MAX_DISTANCE)//如果子弹步长超出了
{
try
{
Iterator<BombForControl> ite=archie_bomb_List.iterator();
while(ite.hasNext())
{
if(ite.next()==this)
{
ite.remove();
return;
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
//这里对炮弹是否击中飞机进行判断
float curr_distance=(curr_planeX-curr_x)*(curr_planeX-curr_x)+
(curr_planeY-curr_y)*(curr_planeY-curr_y)+
(curr_planeZ-curr_z)*(curr_planeZ-curr_z);
if(curr_distance<500)//炮弹与飞机相撞
{
gv.activity.playSound(1,0);
isno_Hit=true;//飞机被击中了一下
gv.plane.blood-=ArchieArray[mapId][9][1];//飞机血减少一滴
gv.activity.shake();//手机震动一次
try
{
Iterator<BombForControl> ite=archie_bomb_List.iterator();
while(ite.hasNext())
{
if(ite.next()==this)
{
ite.remove();
return;
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
return ;
}
//计算炮弹下一步的位置
//计算当前仰角和方向角
curr_x=curr_x-(float)(Math.cos(Math.toRadians(curr_elevation))*Math.sin(Math.toRadians(curr_direction))*ARCHIE_BOMB_VELOCITY);
curr_z=curr_z-(float)(Math.cos(Math.toRadians(curr_elevation))*Math.cos(Math.toRadians(curr_direction))*ARCHIE_BOMB_VELOCITY);
curr_y=curr_y+(float)(Math.sin(Math.toRadians(curr_elevation))*ARCHIE_BOMB_VELOCITY);//飞机的位置
}
//坦克发射炮弹
public void go_tank()
{
float curr_planeX=PLANE_X;
float curr_planeY=PLANE_Y;
float curr_planeZ=PLANE_Z;
distance+=TANK_BOMB_VELOCITY;//子弹的行驶路程增加
if(distance>=BOMB_MAX_DISTANCE)//如果子弹步长超出了
{
try
{
Iterator<BombForControl> ite=tank_bomb_List.iterator();
while(ite.hasNext())
{
if(ite.next()==this)
{
ite.remove();
return;
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
//这里对炮弹是否击中飞机进行判断
float curr_distance=(curr_planeX-curr_x)*(curr_planeX-curr_x)+
(curr_planeY-curr_y)*(curr_planeY-curr_y)+
(curr_planeZ-curr_z)*(curr_planeZ-curr_z);
if(curr_distance<500)//炮弹与飞机相撞
{
gv.activity.playSound(1,0);
isno_Hit=true;//飞机杯击中一下了
gv.plane.blood-=ArchieArray[mapId][9][0];//飞机血减少一滴
gv.activity.shake();//手机震动一次
try
{
Iterator<BombForControl> ite=tank_bomb_List.iterator();
while(ite.hasNext())
{
if(ite.next()==this)
{
ite.remove();
return;
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
return ;
}
//计算炮弹下一步的位置
//计算当前仰角和方向角
curr_x=curr_x-(float)(Math.cos(Math.toRadians(curr_elevation))*Math.sin(Math.toRadians(curr_direction))*TANK_BOMB_VELOCITY);
curr_z=curr_z-(float)(Math.cos(Math.toRadians(curr_elevation))*Math.cos(Math.toRadians(curr_direction))*TANK_BOMB_VELOCITY);
curr_y=curr_y+(float)(Math.sin(Math.toRadians(curr_elevation))*TANK_BOMB_VELOCITY);
}
}

View File

@@ -0,0 +1,396 @@
package com.bn.gameView;
import static com.bn.gameView.Constant.ANGLE_X_Z;
import static com.bn.gameView.Constant.ARCHIBALD_X;
import static com.bn.gameView.Constant.ARCHIBALD_Y;
import static com.bn.gameView.Constant.ARCHIBALD_Z;
import static com.bn.gameView.Constant.ARSENAL_X;
import static com.bn.gameView.Constant.ARSENAL_Y;
import static com.bn.gameView.Constant.ARSENAL_Z;
import static com.bn.gameView.Constant.ArchieArray;
import static com.bn.gameView.Constant.BULLET_MAX_DISTANCE;
import static com.bn.gameView.Constant.BULLET_VELOCITY;
import static com.bn.gameView.Constant.PLANE_X;
import static com.bn.gameView.Constant.PLANE_X_R;
import static com.bn.gameView.Constant.PLANE_Y;
import static com.bn.gameView.Constant.PLANE_Y_R;
import static com.bn.gameView.Constant.PLANE_Z;
import static com.bn.gameView.Constant.archie_List;
import static com.bn.gameView.Constant.bullet_List;
import static com.bn.gameView.Constant.gradeArray;
import static com.bn.gameView.Constant.isno_Lock;
import static com.bn.gameView.Constant.mapId;
import static com.bn.gameView.Constant.nx;
import static com.bn.gameView.Constant.ny;
import static com.bn.gameView.Constant.nz;
import static com.bn.gameView.GLGameView.arsenal;
import static com.bn.gameView.GLGameView.baoZhaList;
import static com.bn.gameView.GLGameView.bombRect;
import static com.bn.gameView.GLGameView.bomb_height;
import static com.bn.gameView.GLGameView.cx;
import static com.bn.gameView.GLGameView.cy;
import static com.bn.gameView.GLGameView.cz;
import static com.bn.gameView.GLGameView.enemy;
import static com.bn.gameView.GLGameView.tankeList;
import java.util.Iterator;
import com.bn.archieModel.ArchieForControl;
import com.bn.arsenal.Arsenal_House;
import com.bn.commonObject.DrawBomb;
import com.bn.commonObject.TextureRect;
import com.bn.core.MatrixState;
import com.bn.planeModel.EnemyPlane;
import com.bn.tankemodel.TanKe;
public class BulletForControl implements Comparable<BulletForControl>
{
private TextureRect bullet_rect;//子弹类
//定义发射子弹时的位置
private float curr_x;
private float curr_y;
private float curr_z;
//定义发射子弹时的仰角和方位角
private float curr_elevation;
private float curr_direction;
private float distance;//飞行距离
//锁定状态下的方向
private boolean islocked;
private float curr_nx;
private float curr_ny;
private float curr_nz;
private float average;//平均向量
//子弹的旋转角度
private float curr_rotation;
GLGameView gv;
public int bulletId;//子弹的id看是敌机发出的还是自己发出的子弹1为敌机发出的子弹
public BulletForControl(GLGameView gv,TextureRect bullet_rect,float plane_x,float plane_y,float plane_z,float plane_elevation,float plane_direction
,float rotationAngle_Plane_X,float rotationAngle_Plane_Y,
float rotationAngle_Plane_Z,int bulletIndex,int bulletId)//bulletIndex表示是左机翼发射子弹还是右机翼
{
this.bulletId=bulletId;
this.gv=gv;
//创建纹理球
this.bullet_rect=bullet_rect;
this.curr_x=plane_x;
this.curr_y=plane_y;
this.curr_z=plane_z;
this.curr_elevation=plane_elevation;
this.curr_direction=plane_direction;
this.islocked=isno_Lock;
if(islocked)
{
curr_nx=nx;
curr_ny=ny;
curr_nz=nz;
average=(float) Math.sqrt(curr_nx*curr_nx+curr_ny*curr_ny+curr_nz*curr_nz);
}
initData(plane_x,plane_y,plane_z,rotationAngle_Plane_X,rotationAngle_Plane_Y,rotationAngle_Plane_Z,bulletIndex);
}
//确定飞机机翼子弹的发射位置
public void initData(float plane_x,float plane_y,float plane_z,float rotationAngle_Plane_X,
float rotationAngle_Plane_Y,float rotationAngle_Plane_Z,int bulletIndex)
{
//设定左机翼发射炮弹的位置
curr_x=plane_x;
curr_y=plane_y;
curr_z=plane_z;
//炮弹位置的相关参数
float length;
float ori_y;
float ori_z;
length=6;
if(bulletIndex!=1)//左机翼发射子弹
{
ori_y=90;
ori_z=-2;
}
else//右机翼发射子弹
{
ori_y=-90;
ori_z=-2;
}
//确定子弹的最终位置
curr_y=curr_y-(float)Math.sin(Math.toRadians(rotationAngle_Plane_Z+ori_z))*length;
curr_x=curr_x-(float)Math.cos(Math.toRadians(rotationAngle_Plane_Z+ori_z))*(float)Math.sin(Math.toRadians(rotationAngle_Plane_Y+ori_y))*length;
curr_z=curr_z-(float)Math.cos(Math.toRadians(rotationAngle_Plane_Z+ori_z))*(float)Math.cos(Math.toRadians(rotationAngle_Plane_Y+ori_y))*length;
}
public void drawSelf(int texId)
{
MatrixState.pushMatrix();
MatrixState.translate(curr_x, curr_y, curr_z);//子弹移动到指定的位置
MatrixState.rotate(curr_rotation, 0, 1, 0);//根据摄像机的相对位置进行旋转
bullet_rect.drawSelf(texId);//进行绘制
MatrixState.popMatrix();
}
public void go()
{
distance+=BULLET_VELOCITY;//子弹的行驶路程增加
if(distance>=BULLET_MAX_DISTANCE)//如果子弹步长超出了
{
Iterator<BulletForControl> ite=bullet_List.iterator();
while(ite.hasNext())
{
if(ite.next()==this)
{
ite.remove();
return;
}
}
}
if(bulletId==0)
{
//判断是否和军火库发生碰撞
for(Arsenal_House as:arsenal)
{
if(//军火库还存在
curr_y>as.ty&&curr_y<as.ty+ARSENAL_Y
&&curr_x>as.tx-ARSENAL_X&&curr_x<as.tx+ARSENAL_X
&&curr_z>as.tz-ARSENAL_Z&&curr_z<as.tz+ARSENAL_Z)
{
as.blood-=ArchieArray[mapId][7][0];//军火库
if(as.blood<1){//如果军火库被炸毁
gv.activity.playSound(0,0);
try
{
Iterator<Arsenal_House> ite=arsenal.iterator();
while(ite.hasNext())
{
if(ite.next()==as)
{
ite.remove();
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
gradeArray[1]+=ArchieArray[mapId][12][3];//得分增加,
baoZhaList.add(new DrawBomb(bombRect,as.tx,as.ty+bomb_height/2,as.tz));
}
Iterator<BulletForControl> ite=bullet_List.iterator();
while(ite.hasNext())
{
if(ite.next()==this)
{
ite.remove();
return;
}
}
}
}
for(ArchieForControl afc:archie_List)//查看有没有击中高射炮
{
if(curr_y>afc.position[1]&&curr_y<afc.position[1]+ARCHIBALD_Y
&&curr_x>afc.position[0]-ARCHIBALD_X&&curr_x<afc.position[0]+ARCHIBALD_X
&&curr_z>afc.position[2]-ARCHIBALD_Z&&curr_z<afc.position[2]+ARCHIBALD_Z)
{
afc.blood-=ArchieArray[mapId][7][2];//高射炮的血减1
try
{
if(afc.blood<1)
{
gv.activity.playSound(0,1);
try
{
Iterator<ArchieForControl> ite=archie_List.iterator();
while(ite.hasNext())
{
if(ite.next()==afc)
{
ite.remove();
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
gradeArray[1]+=ArchieArray[mapId][12][1];//得分增加,
baoZhaList.add(new DrawBomb(bombRect,curr_x,curr_y+bomb_height/2,curr_z));
}
}
catch(Exception e)
{
e.printStackTrace();
}
Iterator<BulletForControl> ite=bullet_List.iterator();
while(ite.hasNext())
{
if(ite.next()==this)
{
ite.remove();
return;
}
}
}
}
for(TanKe afc:tankeList){//查看有没有击中坦克
if(curr_y>afc.ty&&curr_y<afc.ty+ARCHIBALD_Y
&&curr_x>afc.tx-ARCHIBALD_X&&curr_x<afc.tx+ARCHIBALD_X
&&curr_z>afc.tz-ARCHIBALD_Z&&curr_z<afc.tz+ARCHIBALD_Z){
afc.blood-=ArchieArray[mapId][7][1];//坦克的血减1
if(afc.blood<=0)
{
gv.activity.playSound(0,1);
try
{
Iterator<TanKe> ite=tankeList.iterator();
while(ite.hasNext())
{
if(ite.next()==afc)
{
ite.remove();
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
baoZhaList.add(new DrawBomb(bombRect,curr_x,curr_y+bomb_height/2,curr_z));
gradeArray[1]+=ArchieArray[mapId][12][0];//得分增加,
}
Iterator<BulletForControl> ite=bullet_List.iterator();
while(ite.hasNext())
{
if(ite.next()==this)
{
ite.remove();
return;
}
}
}
}
//有没有击中敌机
for(EnemyPlane afc:enemy){//
if(curr_y>afc.ty-PLANE_Y_R&&curr_y<afc.ty+PLANE_Y_R
&&curr_x>afc.tx-PLANE_X_R&&curr_x<afc.tx+PLANE_X_R
&&curr_z>afc.tz-ANGLE_X_Z&&curr_z<afc.tz+ANGLE_X_Z){
afc.blood-=ArchieArray[mapId][7][3];//敌机的血减1
if(afc.blood<=0){
gv.activity.playSound(0,1);
try
{
Iterator<EnemyPlane> ite=enemy.iterator();
while(ite.hasNext())
{
if(ite.next()==afc)
{
ite.remove();
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
baoZhaList.add(new DrawBomb(bombRect,curr_x,curr_y+bomb_height/5,curr_z));
gradeArray[1]+=ArchieArray[mapId][12][2];//得分增加,
}
Iterator<BulletForControl> ite=bullet_List.iterator();
while(ite.hasNext())
{
if(ite.next()==this)
{
ite.remove();
return;
}
}
}
}
}
else//敌方的飞机发射的子弹击中我方的飞机
{
float curr_planeX=PLANE_X;
float curr_planeY=PLANE_Y;
float curr_planeZ=PLANE_Z;
//这里对炮弹是否击中飞机进行判断
float curr_distance=(curr_planeX-curr_x)*(curr_planeX-curr_x)+
(curr_planeY-curr_y)*(curr_planeY-curr_y)+
(curr_planeZ-curr_z)*(curr_planeZ-curr_z);
if(curr_distance<500)//炮弹与飞机相撞
{
gv.plane.blood-=ArchieArray[mapId][9][2];//飞机血减少一滴
try
{
Iterator<BulletForControl> ite=bullet_List.iterator();
while(ite.hasNext())
{
if(ite.next()==this)
{
ite.remove();
return;
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
return ;
}
}
//计算子弹下一步的位置
//计算当前仰角和方向角
//这里判断是否锁定目标
if(islocked)//如果锁定目标,则按照锁定方向发射子弹
{
curr_x+=curr_nx/average*BULLET_VELOCITY;
curr_z+=curr_nz/average*BULLET_VELOCITY;
curr_y+=curr_ny/average*BULLET_VELOCITY;
}
else
{
curr_x=curr_x-(float)(Math.cos(Math.toRadians(curr_elevation))*Math.sin(Math.toRadians(curr_direction))*BULLET_VELOCITY);
curr_z=curr_z-(float)(Math.cos(Math.toRadians(curr_elevation))*Math.cos(Math.toRadians(curr_direction))*BULLET_VELOCITY);
curr_y=curr_y+(float)(Math.sin(Math.toRadians(curr_elevation))*BULLET_VELOCITY);//飞机的位置
}
//计算朝向
calculateBillboardDirection();
}
//这里计算标志板的朝向
public void calculateBillboardDirection()
{//根据摄像机位置计算焰火粒子面朝向
float currX_span=curr_x-cx;
float currZ_span=curr_z-cz;
if(currZ_span<=0)
{
curr_rotation=(float)Math.toDegrees(Math.atan(currX_span/currZ_span));
}
else
{
curr_rotation=180+(float)Math.toDegrees(Math.atan(currX_span/currZ_span));
}
}
@Override
public int compareTo(BulletForControl another)
{//重写的比较两个粒子离摄像机距离的方法
float x=curr_x-cx;
float z=curr_y-cz;
float y=curr_z-cy;
float xo=another.curr_x-cx;
float zo=another.curr_y-cz;
float yo=another.curr_z-cy;
float disA=x*x+y*y+z*z;
float disB=xo*xo+yo*yo+zo*zo;
return ((disA-disB)==0)?0:((disA-disB)>0)?-1:1;
}
}

View File

@@ -0,0 +1,125 @@
/**
*
* 用于绘制圆
*/
package com.bn.gameView;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import javax.microedition.khronos.opengles.GL10;
import com.bn.commonObject.Light_Tower;
import com.bn.core.MatrixState;
import android.opengl.GLES20;
//用triangle_fan方式绘制圆面 此圆面是平行于XY平面的
public class CircleForDraw
{
float taizihight=30;
int mProgram;//自定义渲染管线程序id
int muMVPMatrixHandle;//总变换矩阵引用id
int maPositionHandle; //顶点位置属性引用id
int maColorR; //颜色值的R分量引用id
int maColorG; //颜色值的G分量引用id
int maColorB; //颜色值的B分量引用id
int maColorA;
private static FloatBuffer mVertexBuffer;//顶点坐标数据缓冲
private static int vCount;
float r; //颜色值的R分量
float g; //颜色值的G分量
float b; //颜色值的B分量
Light_Tower taizi;
public CircleForDraw
(
int mProgram,
float angleSpan,//切分角度
float radius,//圆半径
float[]color,
int mProgramlitht
)
{
this.r=color[0];
this.g=color[1];
this.b=color[2];
initVertexData(angleSpan,radius);
initShader(mProgram);
taizi=new Light_Tower(radius,radius,taizihight,1);
taizi.initShader(mProgramlitht);
}
public static void initVertexData
(
float angleSpan,//切分角度
float radius//圆半径
)
{
//顶点纹理坐标数据的初始化================begin============================
vCount=1+(int)(360/angleSpan)+1;//顶点的个数
float[] vertices=new float[vCount*3];//初始化顶点数组
//存放中心点坐标
vertices[0]=0;
vertices[1]=0;
vertices[2]=0;
int vcount=3;//当前顶点坐标索引
for(float angle=0;angle<=360;angle=angle+angleSpan)
{
double angleRadian=Math.toRadians(angle);
//顶点坐标
vertices[vcount++]=radius*(float)Math.cos(angleRadian);
vertices[vcount++]=radius*(float)Math.sin(angleRadian);
vertices[vcount++]=0;
}
//创建顶点坐标数据缓冲
//vertices.length*4是因为一个整数四个字节
ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length*4);
vbb.order(ByteOrder.nativeOrder());//设置字节顺序为本地操作系统顺序
mVertexBuffer = vbb.asFloatBuffer();//转换为int型缓冲
mVertexBuffer.put(vertices);//向缓冲区中放入顶点坐标数据
mVertexBuffer.position(0);//设置缓冲区起始位置
}
public void initShader(int mProgramIn)
{
mProgram = mProgramIn;
//获取程序中顶点位置属性引用id
maPositionHandle = GLES20.glGetAttribLocation(mProgram, "aPosition");
muMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
maColorR=GLES20.glGetUniformLocation(mProgram, "colorR");
maColorG=GLES20.glGetUniformLocation(mProgram, "colorG");
maColorB=GLES20.glGetUniformLocation(mProgram, "colorB");
maColorA=GLES20.glGetUniformLocation(mProgram, "colorA");
}
public void drawSelf(float alpha,int texId)
{
//制定使用某套shader程序
GLES20.glUseProgram(mProgram);
//将最终变换矩阵传入shader程序
GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, MatrixState.getFinalMatrix(), 0);
//将位置、旋转变换矩阵传入shader程序
//传入顶点位置数据
GLES20.glVertexAttribPointer
(
maPositionHandle,
3,
GLES20.GL_FLOAT,
false,
3*4,
mVertexBuffer
);
//允许顶点位置、法向量数据数组
GLES20.glEnableVertexAttribArray(maPositionHandle);
GLES20.glUniform1f(maColorR , r);
GLES20.glUniform1f(maColorG , g);
GLES20.glUniform1f(maColorB , b);
GLES20.glUniform1f(maColorA , alpha);
//绘制图形
GLES20.glDrawArrays
(
GL10.GL_TRIANGLE_FAN, //以TRIANGLE_FAN方式填充
0,
vCount
);
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff