请选择 进入手机版 | 继续访问电脑版

 找回密码
 点一下
查看: 10064|回复: 26

舒适的键盘移动+镜头系统(高仿3D)移植方便

[复制链接]
发表于 2009-10-29 05:18:47 | 显示全部楼层 |阅读模式
国际惯例,开头废话
感谢社会,感谢人民,感谢政府.
低智商生物蛐蛐终于脱离了J盲,进化为Jass新手阶段,特此纪念下.
回报社会,回报人民,回报政府.
因为初学J,所以代码有待优化
这个系统用T也可以做,不过效率没那么高
代码简单,不过总之自我感觉操作很流畅
 1.前or后 左or右 不冲突,后按的键优先,释放则返回
 2.自动调节Z旋转和Z偏移,解决上下坡'透视'的尴尬局面
  如:上坡时'抬头',下坡时'低头',幅度根据地形坡度
 3.移动速度无限制,暂时设置为100~1000
 4.暂时只加入边界、水面已经地形装饰物的障碍判断
  若需要单位、可破坏物体判断请自己添加
 5.移植时只要复制代码、触发以及相应全局变量即可

1.gif 2.gif 3.gif

[蟋有的蟀]舒适的键盘移动+镜头系统(高仿3D).w3x (82 KB, 下载次数: 1245)
[jass]
//===========================================================================
//                移动函数
function Move takes nothing returns nothing
    local integer i = 1
    local unit u
    local real array r
    loop
        exitwhen i > 10
        if ( not ( udg_O_b[( i + 70 )] != false ) ) then //为then时禁止移动/转身,如果不需要可以不移植此项
            set u = udg_Hero_u
            set r[0] = RMinBJ(RMaxBJ(udg_O_r, 100.00), 1000.00) //移动速度
            set r[1] = GetUnitFacing(u) //面向角度
            set r[2] = udg_O_r[( i + 10 )] //转身速度
            if ( not ( udg_O_b[( i + 60 )] != true ) ) then  //左转or右转
                if ( not ( udg_O_b[( i + 30 )] != true ) ) then
                    set r[1] = ( r[1] + r[2] )
                else
                    if ( not ( udg_O_b[( i + 40 )] != true ) ) then
                        set r[1] = ( r[1] - r[2] )
                    else
                    endif
                endif
            else
                if ( not ( udg_O_b[( i + 40 )] != true ) ) then
                    set r[1] = ( r[1] - r[2] )
                else
                    if ( not ( udg_O_b[( i + 30 )] != true ) ) then
                        set r[1] = ( r[1] + r[2] )
                    else
                    endif
                endif
            endif
            call SetUnitFacing( u, r[1] ) //转身
            if ( not ( udg_O_b[( i + 50 )] != true ) ) then //前进or后退
                if ( not ( udg_O_b[( i + 10 )] != true ) ) then
                    set r[3] = ( r[0] / 20.00 ) //位移距离
                    set r[4] = ( 0.50 + ( r[0] / 800.00 ) ) //动画速度
                else
                    if ( not ( udg_O_b[( i + 20 )] != true ) ) then
                        set r[3] = ( 0.00 - ( r[0] / 40.00 ) ) //后退距离为负数
                        set r[4] = ( 0.00 - ( 0.20 + ( r[0] / 1600.00 ) ) ) //后退动画速度为负数
                    else
                    endif
                endif
            else
                if ( not ( udg_O_b[( i + 20 )] != true ) ) then
                    set r[3] = ( 0.00 - ( r[0] / 40.00 ) )
                    set r[4] = ( 0.00 - ( 0.20 + ( r[0] / 1600.00 ) ) )
                else
                    if ( not ( udg_O_b[( i + 10 )] != true ) ) then
                        set r[3] = ( r[0] / 20.00 )
                        set r[4] = ( 0.50 + ( r[0] / 800.00 ) )
                    else
                    endif
                endif
            endif
            set r[5] = ( GetUnitX(u) + ( r[3] * Cos(( GetUnitFacing(u) * bj_DEGTORAD )) ) ) //位移目标点x坐标
            set r[6] = ( GetUnitY(u) + ( r[3] * Sin(( GetUnitFacing(u) * bj_DEGTORAD )) ) ) //位移目标点y坐标
            if ( not ( IsTerrainPathable(r[5], r[6], PATHING_TYPE_WALKABILITY) == true ) ) then
                if ( not ( udg_O_b[( i + 10 )] != true ) ) then
                    call SetUnitX( u, r[5] ) //移动单位x坐标
                    call SetUnitY( u, r[6] ) //移动单位y坐标
                    call SetUnitAnimationByIndex( u, R2I(udg_O_r[( i + 20 )]) ) //指定序列播放单位动画
                    call SetUnitTimeScale( u, r[4] ) //动画播放速度
                else
                    if ( not ( udg_O_b[( i + 20 )] != true ) ) then
                        call SetUnitX( u, r[5] )
                        call SetUnitY( u, r[6] )
                        call SetUnitAnimationByIndex( u, R2I(udg_O_r[( i + 20 )]) )
                        call SetUnitTimeScale( u, r[4] )
                    else
                    endif
                endif
            else
            endif
        else
        endif
        set i = i + 1
    endloop
endfunction

//===========================================================================
//                镜头函数
//                以下数值可根据自己地图的地形需要进行修改
function Aov takes nothing returns nothing
    local integer i = 1
    local location array p
    loop
        exitwhen i > 10
        if ( not ( udg_Aov_i != 0 ) ) then //停止镜头锁定,如果不需要可以不移植此项
            call ResetToGameCameraForPlayer( ConvertedPlayer(i), 0 )
        else
            if ( not ( udg_Aov_i != 1 ) ) then //锁定镜头
                set p[0] = GetUnitLoc(udg_Hero_u)
                set p[1] = PolarProjectionBJ(p[0], -80.00, GetUnitFacing(udg_Hero_u))
                call SetCameraFieldForPlayer( ConvertedPlayer(i), CAMERA_FIELD_TARGET_DISTANCE, 600.00, 0 ) //镜头距离,如果需要,可以用全局变量记录方便传递
                call SetCameraTargetControllerNoZForPlayer( ConvertedPlayer(i), udg_Hero_u, 0, 0, false ) //锁定镜头
                call SetCameraFieldForPlayer( ConvertedPlayer(i), CAMERA_FIELD_ANGLE_OF_ATTACK, ( 355.00 + ( ( GetLocationZ(p[0]) - GetLocationZ(p[1]) ) * 0.70 ) ), 0.80 ) //X旋转角度,随单位所在地形坡度改变
                call SetCameraFieldForPlayer( ConvertedPlayer(i), CAMERA_FIELD_ZOFFSET, ( 50.00 + ( GetLocationZ(p[0]) / 3.50 ) ), 0.00 ) //Z轴偏移,值越高镜头越高
                call SetCameraFieldForPlayer( ConvertedPlayer(i), CAMERA_FIELD_ROTATION, GetUnitFacing(udg_Hero_u), 0.20 ) //Z轴旋转角度
                call RemoveLocation( p[0] )
                call RemoveLocation( p[1] )
            else
            endif
        endif
        set i = i + 1
    endloop
endfunction

//===========================================================================

function Circulation takes nothing returns nothing
      local timer tm = CreateTimer()
      local timer tm2 = CreateTimer()
      call TimerStart(tm,0.05,true,function Move)
      call TimerStart(tm2,0.05,true,function Aov)
      set tm = null
      set tm2 = null
endfunction
[/jass]

评分

参与人数 1威望 +4 收起 理由
血戮魔动冰 + 4

查看全部评分

发表于 2009-10-29 08:42:15 | 显示全部楼层
能解决透视阿,真舒服。
回复

使用道具 举报

发表于 2009-10-29 11:15:57 | 显示全部楼层
你要是有空来跟我做,起凡的街机类游戏。
回复

使用道具 举报

 楼主| 发表于 2009-10-29 15:22:56 | 显示全部楼层
说道7F。。多少玩了半年
7F编辑器的功能倒是很有趣
回复

使用道具 举报

发表于 2009-10-29 15:28:02 | 显示全部楼层
做个小斗士如何……
回复

使用道具 举报

发表于 2009-10-30 03:35:27 | 显示全部楼层
后按的键优先, 这个太简单.

根据地形和装饰物变化视野角度不错.
回复

使用道具 举报

发表于 2009-10-30 08:53:28 | 显示全部楼层
AD转向的方法?
我不喜欢这个方法……
回复

使用道具 举报

发表于 2010-1-16 15:52:42 | 显示全部楼层
我绝非挖坟,只是这个系统固然好但有什么方法来解决穿树的问题!并且此系统无视路障,希望得以解决
回复

使用道具 举报

发表于 2010-4-9 15:54:30 | 显示全部楼层
我不太懂J 哪位可以告诉我后退的动画是怎么来的?
可以设置动画播放速度为负?
我测试不行诶~~~
回复

使用道具 举报

发表于 2010-4-10 00:57:43 | 显示全部楼层
引用第9楼天然ボケ于2010-04-09 20:55发表的  :
播放向前的动画,向后移动单位。
没懂你的意思
我又仔细看了一下 发现动画的确是向后走的 貌似不是播放向前的动画
回复

使用道具 举报

发表于 2010-4-11 00:54:31 | 显示全部楼层
我也测试了下~~直接播放Walk动画往后移动单位
然后山丘就成杰克逊了~~
回复

使用道具 举报

发表于 2010-6-12 23:06:24 | 显示全部楼层
··········
支持!1
回复

使用道具 举报

发表于 2010-6-19 16:09:46 | 显示全部楼层
我想知道还原默认镜头的代码
回复

使用道具 举报

发表于 2010-6-23 18:12:12 | 显示全部楼层
请问要怎么让山丘不能穿越装饰物啊。。。
回复

使用道具 举报

发表于 2010-6-24 22:25:43 | 显示全部楼层
引用第8楼shxhe01于2010-04-09 15:54发表的  :
我不太懂J 哪位可以告诉我后退的动画是怎么来的?
可以设置动画播放速度为负?
我测试不行诶~~~

可以设置动画播放速度为负
好像这样也行。。。。

test.w3x

13 KB, 下载次数: 76

回复

使用道具 举报

发表于 2010-6-26 12:07:18 | 显示全部楼层
哈哈哈~
回复

使用道具 举报

发表于 2010-9-24 22:01:05 | 显示全部楼层
太诱人了,但为哈我下载之后打不开地图啊!!!!
求指教
回复

使用道具 举报

发表于 2011-4-4 11:24:58 | 显示全部楼层
已经很good了 刚好需要
回复

使用道具 举报

发表于 2011-4-8 18:23:17 | 显示全部楼层

回 7楼(wfr_tc) 的帖子

我也绝非挖坟!

至于穿树问题,无非是能看到后面的景物....但如果看不到呢?
对!就是让你看不到后面的景物,在树里面加上黑色阴影
也就是让你视觉穿越不过....
回复

使用道具 举报

发表于 2011-4-20 15:32:37 | 显示全部楼层
看不懂= -
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 点一下

本版积分规则

Archiver|移动端|小黑屋|地精研究院

GMT+8, 2024-4-19 01:56 , Processed in 0.347527 second(s), 26 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表