3D塔防游戏实现 5.1 3D炮塔能攻击了(Feekood语言)

(Feekood语言介绍与习) (学习) (首页) (开发页面)

——————————

在前面的阶段实现了:3D地图、2D地图、视角控制、创建炮塔、创建怪物、怪物移动、怪物连续刷新等功能。下面也是最后的一个阶段:炮塔攻击、怪物死亡、信息展示这3个方面的介绍。 今天来介绍3D炮塔能攻击了:

修改原“TurretMesh.ais”脚本

LoadImage(“TurretImg”,”:/Wooyoo/tower/turret01.jpg”); //炮塔纹理//炮塔模型LoadModel(“TurretA1model”,”:/Wooyoo/tower/flame_thrower_01.obj”,”obj”);//炮弹模型BulletA=IncludeAisx(“:/Wooyoo/window7/ROCKETMOUNT3.aisx”);BulletA.action=”WALK”;//炮弹动画BulletA.Scale={0.2,0.2,0.2};//缩放炮弹模型//炮塔模型数据TurretBaseMesh= {type:”mesh”; //类型 meshmodel:”TurretA1model”; //模型为炮塔Atexture:”TurretImg”; //模型的纹理SimplerState:”wrap”; Shader:”phong”;Scale:{0.6,0.6,0.6}; //缩放下模型大小leftName:””;//存储左炮弹名称rightName::::0;OldXZ:{}; //保存炮弹的初始XZ坐标 //isloaded为创建后执行一次的事件,,这里为创建左右炮弹isloaded:=>{PX=1.25; //右炮弹X平移炮弹的 PX1=-1.25; //左炮弹X平移PZ=1.3;//炮弹Z平移//根据炮塔模型的旋转角度来计算左右两炮弹的位置xx1=PX*cos(pi()*owner.rotation/180)+PZ*sin(pi()*owner.rotation/180);zz1=(-1*PX)*sin(pi()*owner.rotation/180)+PZ*cos(pi()*owner.rotation/180);xx2=PX1*cos(pi()*owner.rotation/180)+PZ*sin(pi()*owner.rotation/180);zz2=(-1*PX1)*sin(pi()*owner.rotation/180)+PZ*cos(pi()*owner.rotation/180); //创建左右两炮塔owner.leftName=create({x:owner.x+xx1;y:owner.y+1;z:owner.z+zz1;Rotation:owner.Rotation;show:owner.show}::BulletA);owner.rightName=create({x:owner.x+xx2;y:owner.y+1;z:owner.z+zz2;Rotation:owner.Rotation;show:owner.show}::BulletA);//保存初始化的炮弹位置owner.OldXZ={Lx:owner.x+xx1;Lz:owner.z+zz1;Rx:owner.x+xx2;Rz:owner.z+zz2};};//炮塔旋转度变化时刷新炮弹角度与位置BreakRotation:false;BreakRotation:=>{PX=1.25; //右炮弹X平移PX1=-1.25; //左炮弹X平移PZ=1.3; //炮弹Z平移//根据炮塔模型的旋转角度来计算左右两炮弹的位置xx1=PX*cos(pi()*owner.rotation/180)+PZ*sin(pi()*owner.rotation/180);zz1=(-1*PX)*sin(pi()*owner.rotation/180)+PZ*cos(pi()*owner.rotation/180);xx2=PX1*cos(pi()*owner.rotation/180)+PZ*sin(pi()*owner.rotation/180);zz2=(-1*PX1)*sin(pi()*owner.rotation/180)+PZ*cos(pi()*owner.rotation/180); //更新两炮弹的及旋转度Getdata(owner.leftName).x=owner.x+xx1;Getdata(owner.leftName).y=owner.y+1;Getdata(owner.leftName).z=owner.z+zz1;Getdata(owner.leftName).Rotation=owner.Rotation; Getdata(owner.rightName).x=owner.x+xx2;Getdata(owner.rightName).y=owner.y+1;Getdata(owner.rightName).z=owner.z+zz2;Getdata(owner.rightName).Rotation=owner.Rotation;//保存初始化的两炮弹位置owner.OldXZ={Lx:owner.x+xx1;Lz:owner.z+zz1;Rx:owner.x+xx2;Rz:owner.z+zz2};};Rotation:0; //旋转度//新增加内容%%%%%%%%%%%%%%%%%%%%%range:30;//攻击范围TargetName:””;//对象名称AttackValue:50; //攻击力AttackSpeed:1;//秒AttackSpeed:->{ //攻击速度控制case(owner.AttackSpeed>7,owner.AttackSpeed=7); };ClickTime:0;//攻击时间控制IsAttack:true; //是否攻击IsUpdated:=> { //每次刷新执行owner.ClickTime+=Sys().USEDTIME; //累加时间//当时间大于该攻击时间后执行case(owner.ClickTime>(1100-owner.AttackSpeed*100),{ owner.ClickTime=0;//攻击时间清0owner.IsAttack=true;//设置攻击Siz=Size($(“FoePanel”).FoeAssemble);for(i=0;i<Siz;i+=1,{ Tname=$(“FoePanel”).FoeAssemble->i;//怪物存在、怪物未死亡、能攻击case(Tname!=null&&Getdata(Tname)!=null&&!Getdata(Tname).Die&&owner.IsAttack,{TargetX=Getdata(Tname).x; //怪物X点TargetZ=Getdata(Tname).z; //怪物z点//计算距离leng2=pow(owner.x-TargetX,2)+pow(owner.z-TargetZ,2);case(leng2<Pow(owner.range,2),{ owner.IsAttack=false; //关闭攻击owner.TargetName=Tname; //攻击怪物对象//调整炮塔角度owner.Rotation=Angle2(TargetZ-owner.z,TargetX-owner.x); owner.Attack=true;//炮塔攻击owner.BreakRotation=true;//刷新炮弹角度});});});});};//攻击Attack:false;owner.Attack==>{owner.Attack=false; //关闭攻击case(owner.TargetName!=””&&Getdata(owner.TargetName)!=null&&owner.leftName!=””&&owner.rightName!=””,{TargetX=Getdata(owner.TargetName).x;Targetz=Getdata(owner.TargetName).z;Targety=Getdata(owner.TargetName).y;//重置炮弹位置Getdata(ownerGetdata(ownerGetdata(owner.leftName).y=owner.y+1;Getdata(ownerGetdata(ownerGetdata(owner.rightName).y=owner.y+1;//炮弹攻向怪物Getdata(owner.leftName).x<:”Clear”<:{TargetX,400};Getdata(owner.leftName).z<:”Clear”<:{Targetz,400};Getdata(owner.leftName).y<:”Clear”<:{Targety,400}<::{owner.BreakRotation=true;};Getdata(owner.rightName).x<:”Clear”<:{TargetX,400};Getdata(owner.rightName).z<:”Clear”<:{Targetz,400};Getdata(owner.rightName).y<:”Clear”<:{Targety,400}<::{owner.BreakRotation=true;//炮弹刷新case(Getdata(owner.TargetName).Data.Blood!=null,{ //怪物的血量-少炮塔攻击力数Getdata(owner});};});}; //新增加内容%%%%%%%%%%%%%%%%%%%%%ScopeRadius: 2; //模型的范围半径ShowScope: true; //显示模型的范围半径show:true;//显示show:->//控制左右炮弹的显示与隐藏{Getdata(owner.leftName).show=owner.show;Getdata(owner.rightName).show=owner.show; };//炮塔移动时炮弹也跟着移动x:->{Getdata(owner.leftName).x=owner.x;Getdata(owner.rightName).x=owner.x; };z:->{Getdata(owner.leftName).z=owner.z;Getdata(owner.rightName).z=owner.z; };};// create(TurretBaseMesh);// print(TurretMesh);

却又小到连一粒嫉妒的沙石也不能容纳

3D塔防游戏实现 5.1 3D炮塔能攻击了(Feekood语言)

相关文章:

你感兴趣的文章:

标签云: