标签:
转http://blog.csdn.net/games_maker/article/details/43953879
心血来潮,准备写个小游戏来玩哈,
第一天花了大约20分钟,做了下面这个效果
访问网站可直接运行 http://www.feekood.com/?path=:/tiantian/KeyMove/MoveDog.ais
按上下左右可以控制狗狗移动(镜头跟随狗狗)
注册www.wooyoogame.com的账户,然后进http://www.wooyoogame.com/resource/5373使用狗狗的模型资源了
clear(); LoadImage("floorImg",":/Samples/Images/floor.png");//读取平台内置图片资源 CreateMipmap("floorImg",16);//创建mipmap图片 Create({type:"box",width:100,height:0.01,length:100,texture:"floorImg",IsAutoTexcoord:true,SimplerState:"wrap"});//创建一个地面 mesh=IncludeAisx(":/Wooyoo/window7/PUG.aisx");//读取wooyoo平台狗狗的模型资源 //狗狗动作支持有 //"RUN,STAND,STAND1,STAND2,STAND3,WALK,STAND4,ATTACKUNARMED,COMBATWOUND,DEATH," //创建一个固定视角的摄像头 SetCamera( camera={ position:{0,5,-5}, target:{0,0,0}, up:{0,0,1}, AllowVRotation:false; //关闭鼠标横向旋转 AllowHRotation:false; //关闭鼠标竖向旋转 AllowZoom: false; //关闭鼠标中间缩放 }); // 设定狗狗的配置信息 myDog= { Action:"stand"; Rotation:0; X:0; Y:0; Z:0; //狗狗的x坐标变化则镜头改变(镜头跟踪狗狗) X:-> { camera.position={owner.x,5,owner.z-5}; camera.target={owner.x,0,owner.z}; }; //狗狗的z坐标变化则镜头改变(镜头跟踪狗狗) Z:-> { camera.position={owner.x,5,owner.z-5}; camera.target={owner.x,0,owner.z}; }; doing:"stand";//自定义属性,狗狗动作 moveSpeed:0;//自定义属性,狗狗动作 rotateAnim:0;//自定义属性,狗狗旋转角度目标 lastRotateAnim:0;//自定义属性,狗狗上次一保存的旋转角度 //旋转角度目标变化,则动态的去改变狗狗模型的显示角度 rotateAnim:-> { owner.rotateSin=sign(owner.lastRotateAnim-owner.rotateAnim); owner.rotateOff=abs(owner.lastRotateAnim-owner.rotateAnim); case(owner.rotateOff<=180, { owner.Rotation<:{owner.lastRotateAnim,owner.rotateAnim,300}; }, { owner.Rotation<:{owner.lastRotateAnim, owner.lastRotateAnim+owner.rotateSin*(owner.rotateOff-180), ,300}; }); owner.lastRotateAnim=owner.rotateAnim; }; //每一帧更新的内置属性,按照doing属性的变化来控制狗狗的模型骨骼动画 IsUpdated:=> { owner.moveSpeed=Sys().UsedTime/1000; case(owner.doing=="stand", { owner.Action="stand"; },owner.doing=="GoUp", { owner.Action="walk"; owner.rotateAnim=0; owner.Z+=owner.moveSpeed; },owner.doing=="GoDown", { owner.Action="walk"; owner.rotateAnim=180; owner.Z-=owner.moveSpeed; },owner.doing=="GoLeft", { owner.Action="walk"; owner.rotateAnim=90; owner.X+=owner.moveSpeed; },owner.doing=="GoRight", { owner.Action="walk"; owner.rotateAnim=270; owner.X-=owner.moveSpeed; }); }; }::mesh; //创建一个狗狗实例 Create(myDog); //定义按键事件信息 keyInfo= { ID:0;//事件编号[内置属性] Key:"";//按键内容[内置属性] IsKeyDown:false;//按键按下事件[内置事件] IsKeyUp:false;//按键弹起事件[内置事件] //定义事件触发器,按下按键则运行表达式 IsKeyDown:=> { // 按上下左右控制狗狗的动作 case(owner.key=="UP",myDog.doing="GoUp", owner.key=="DOWN",myDog.doing="GoDown", owner.key=="LEFT",myDog.doing="GoLeft", owner.key=="RIGHT",myDog.doing="GoRight"); }; //定义事件触发器,弹起按键则运行表达式 IsKeyUp:=> { myDog.frame=0; myDog.doing="stand"; }; }; KeyReceive(keyInfo);//接受按键消息
标签:
原文地址:http://www.cnblogs.com/gamemaker/p/4301974.html