设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 5290|回复: 20
打印 上一主题 下一主题

[已经解决] 好难的脚本啊,看不懂… 求指教~~~~

[复制链接]

Lv1.梦旅人

梦石
0
星屑
45
在线时间
282 小时
注册时间
2012-2-18
帖子
161
跳转到指定楼层
1
发表于 2012-5-14 11:26:51 | 显示全部楼层 |只看大图 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 dabojun 于 2012-5-14 20:34 编辑

def passable?(x, y, d)
71.            return bigevent_passable?(x, y, d) if @bigevent.length == 0        
72.         
73.            return @bigevent.map { |i|                                                # 这一段到这儿就完全不懂该怎么翻译了呵… “| |”这个符号又是啥意思呢…??{:2_277:}
74.              bigevent_passable?(x + i[0], y + i[1], d)
75.            }.all? && bigevent_passable?(x, y, d)
76.          end
77.         
78.          def areas(x = nil, y = nil)                                                      #还可以这样用啊?好神奇…{:2_272:}
79.            x ||= self.x
80.            y ||= self.y
81.            return @bigevent.map { |i|                                                #这边又是如何push呢?{:2_270:}
82.              [x + i[0], y + i[1]]
83.            }.push([x, y])
84.          end
85.        end
        

# 能否给这段加上中文注释??
真实的我不是这样子的~@

Lv1.梦旅人

梦石
0
星屑
45
在线时间
282 小时
注册时间
2012-2-18
帖子
161
2
 楼主| 发表于 2012-5-14 13:53:12 | 显示全部楼层
本帖最后由 dabojun 于 2012-5-14 14:39 编辑

能否帮我翻译一下上面那段脚本的内容呢? {:2_249:}

那个集合处理能否举例说明怎么用啊?集合处理和迭代器有关吗?{:2_283:}

用了push会产生什么结果呢?
return @bigevent.map { |i|                                             
             [x + i[0], y + i[1]]
            }.push([x, y])
这个写出来是什么样子呢?{:2_253:}
真实的我不是这样子的~@
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
45
在线时间
282 小时
注册时间
2012-2-18
帖子
161
3
 楼主| 发表于 2012-5-14 16:39:38 | 显示全部楼层
这个“栈”是指……push?好像越来越复杂了,

能否帮我翻译一下上面那段脚本的内容呢?  {:2_269:}

那个集合处理能否举例说明怎么用啊?集合处理和迭代器有关吗?{:2_264:}
真实的我不是这样子的~@
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
45
在线时间
282 小时
注册时间
2012-2-18
帖子
161
4
 楼主| 发表于 2012-5-14 17:17:56 | 显示全部楼层
请细心的看一下我的问题在回答啊~~~!
我知道push是推到结尾的意思,帮助里我也看过,我想问的是在这句编程里加入….push([x,y])是会变成[x+i[0],y+i[1],[x,y]]这样吗?
return @bigevent.map { |i|                                               
           [x + i[0], y + i[1]]
            }.push([x, y])
能否完整的回答一下问题呀~~~?
真实的我不是这样子的~@
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
45
在线时间
282 小时
注册时间
2012-2-18
帖子
161
5
 楼主| 发表于 2012-5-14 17:27:09 | 显示全部楼层
嗯,对,你写的。各种想弄明白啥意思

1.        # 巨大事件占地面积的处理
2.        # author: Yeechan Lu a.k.a. orzFly
3.         
4.        class Game_Character
5.          alias bigevent_initialize initialize   
6.          def initialize
7.            @bigevent = []
8.            bigevent_initialize
9.          end
10.         
11.          def bigevent_passable?(x, y, d)  
12.            # 求得新的坐标
13.            new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
14.            new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
15.            # 坐标在地图以外的情况
16.            unless $game_map.valid?(new_x, new_y)  
17.              # 不能通行
18.              return false
19.            end
20.            # 穿透是 ON 的情况下
21.            if @through      
22.              # 可以通行
23.              return true
24.            end
25.            # 移动者的元件无法来到指定方向的情况下
26.            unless $game_map.passable?(x, y, d, self)  
27.              # 通行不可
28.              return false
29.            end
30.            # 从指定方向不能进入到移动处的元件的情况下
31.            unless $game_map.passable?(new_x, new_y, 10 - d)
32.              # 不能通行
33.              return false
34.            end
35.            new_point = [new_x, new_y]
36.            # 循环全部事件
37.            for event in $game_map.events.values
38.              # 事件坐标于移动目标坐标一致的情况下
39.              if event.areas.include?(new_point) and self != event
40.                # 穿透为 ON
41.                unless event.through
42.                  # 自己就是事件的情况下
43.                  if self != $game_player
44.                    # 不能通行
45.                    return false
46.                  end
47.                  # 自己是主角、对方的图形是角色的情况下
48.                  if event.character_name != ""
49.                    # 不能通行
50.                    return false
51.                  end
52.                end
53.              end
54.            end
55.            # 主角的坐标与移动目标坐标一致的情况下
56.            if $game_player.areas.include?(new_point)
57.              # 穿透为 ON
58.              unless $game_player.through
59.                # 自己的图形是角色的情况下
60.                if @character_name != ""
61.                  # 不能通行
62.                  return false
63.                end
64.              end
65.            end
66.            # 可以通行
67.            return true
68.          end
69.         
70.          def passable?(x, y, d)
71.            return bigevent_passable?(x, y, d) if @bigevent.length == 0        
72.         
73.            return @bigevent.map { |i|
74.              bigevent_passable?(x + i[0], y + i[1], d)
75.            }.all? && bigevent_passable?(x, y, d)
76.          end
77.         
78.          def areas(x = nil, y = nil)
79.            x ||= self.x
80.            y ||= self.y
81.            return @bigevent.map { |i|
82.              [x + i[0], y + i[1]]
83.            }.push([x, y])
84.          end
85.        end
86.        class Game_Player
87.          #--------------------------------------------------------------------------
88.          # ● 正面事件的启动判定
89.          #--------------------------------------------------------------------------
90.          def check_event_trigger_there(triggers)
91.            result = false
92.            # 事件执行中的情况下
93.            if $game_system.map_interpreter.running?
94.              return result
95.            end
96.            # 计算正面坐标
97.            new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
98.            new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
99.            new_point = [new_x, new_y]
100.            # 全部事件的循环
101.            for event in $game_map.events.values
102.              # 事件坐标与目标一致的情况下
103.              if event.areas.include?(new_point) and
104.                 triggers.include?(event.trigger)
105.                # 跳跃中以外的情况下、启动判定是正面的事件
106.                if not event.jumping? and not event.over_trigger?
107.                  event.start
108.                  result = true
109.                end
110.              end
111.            end
112.            # 找不到符合条件的事件的情况下
113.            if result == false
114.              # 正面的元件是计数器的情况下
115.              if $game_map.counter?(new_x, new_y)
116.                # 计算 1 元件里侧的坐标
117.                new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
118.                new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
119.                new_point = [new_x, new_y]
120.                # 全事件的循环
121.                for event in $game_map.events.values
122.                  # 事件坐标与目标一致的情况下
123.                  if event.areas.include?(new_point) and
124.                     triggers.include?(event.trigger)
125.                    # 跳跃中以外的情况下、启动判定是正面的事件
126.                    if not event.jumping? and not event.over_trigger?
127.                      event.start
128.                      result = true
129.                    end
130.                  end
131.                end
132.              end
133.            end
134.            return result
135.          end
136.          #--------------------------------------------------------------------------
137.          # ● 接触事件启动判定
138.          #--------------------------------------------------------------------------
139.          def check_event_trigger_touch(x, y)
140.            result = false
141.            # 事件执行中的情况下
142.            if $game_system.map_interpreter.running?
143.              return result
144.            end
145.            # 全事件的循环
146.            for event in $game_map.events.values
147.              # 事件坐标与目标一致的情况下
148.              if event.areas.include?([x, y]) and [1,2].include?(event.trigger)
149.                # 跳跃中以外的情况下、启动判定是正面的事件
150.                if not event.jumping? and not event.over_trigger?
151.                  event.start
152.                  result = true
153.                end
154.              end
155.            end
156.            return result
157.          end
158.        end
每张有这种要设置占地面积的事件的地图上,放一个自动执行的事件。
内容:
脚本:
RUBY 代码复制代码
1.        $game_map.events[1].instance_variable_set \
2.        :@bigevent, \
3.        [
4.          [-1, 0],
5.          [1, 0],
6.          [0, 1],
7.          [0, -1],
8.        ]
真实的我不是这样子的~@
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
45
在线时间
282 小时
注册时间
2012-2-18
帖子
161
6
 楼主| 发表于 2012-5-15 18:20:08 | 显示全部楼层
感谢飞3a 的耐心解答,收益颇多~~

点评

善用回复!我好像跟你说过几次了  发表于 2012-5-15 19:49
真实的我不是这样子的~@
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
45
在线时间
282 小时
注册时间
2012-2-18
帖子
161
7
 楼主| 发表于 2012-5-15 20:16:37 | 显示全部楼层
orzfly 发表于 2012-5-15 19:39
看一看 http://sitoto.iteye.com/blog/1488557

a=[1, 2, 3]

写下恢复你就可以收到了吗? 好吧~  x ||= y 终于懂了 呵
真实的我不是这样子的~@
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
45
在线时间
282 小时
注册时间
2012-2-18
帖子
161
8
 楼主| 发表于 2012-5-16 11:42:59 | 显示全部楼层
本帖最后由 dabojun 于 2012-5-17 10:55 编辑
orzfly 发表于 2012-5-15 20:50
这个你要去查阅英文文档……没见过有翻译的目前……

Enumable 提供了 all?……


嗯,all?的方法暂时看懂了,只是应用时层叠的方法摆在一起很容易混乱呵


‘‘──dabojun于2012-5-16 18:26补充以下内容

正在看迭代器的讲解,既http://blog.csdn.net/classwang/article/details/4692856
想知道里面的"/n"是什么意思呀??反复出现@

’’
还有着一段也不理解……~ 划红线的部分都不大理解的说呵…

20.4.4  sort_by方法
sort方法会在每次进行比较时判断元素。让我们来计算一下前面比较字符串长度的示例中,length方法到底被调用了几次。

ary = %w(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20)

num = 0                  # 调用的次数

ary.sort {|a, b|

  num += 2               # 累加调用的次数

  a.length <=> b.length

}

p num                      #=> 54

这个示例可以知道有20个元素的时候,length方法要调用54次。按理说对每个字符串调用一次length方法再排序就可以了,所以这里做了很多次多余的调用动作。当数组很长,或者判断元素的运算很耗时的时候,这些多余的调用动作会对整体执行时间造成很大的影响。




‘‘──dabojun于2012-5-17 14:16补充以下内容

关于over_trigger是否可以这样解释?
# 跳跃中以外的情况下、启动判定是正面的事件
106.                if not event.jumping? and not event.over_trigger?
107.                  event.start
108.                  result = true
109.                end
110.              end
111.            end      # (“if not”用法)(over为:以上,以外,trigger为:触发,启动判定/触发条件:0,1,2,3,4)

’’


‘‘──dabojun于2012-5-17 14:33补充以下内容

还有这段也不知是何意? 和计数器有何关系呢?计数器是计步数,还是时间倒计时窗口呢?
# 找不到符合条件的事件的情况下
113.            if result == false
114.              # 正面的元件是计数器的情况下
115.              if $game_map.counter?(new_x, new_y)
116.                # 计算 1 元件里侧的坐标 (里侧的坐标又是何意?)
117.                new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
118.                new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
119.                new_point = [new_x, new_y]

’’


‘‘──dabojun于2012-5-17 14:51补充以下内容

一坑未平,一坑又起,请转移视线到新坑~
’’
真实的我不是这样子的~@
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-5 17:51

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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