赞 | 0 |
VIP | 37 |
好人卡 | 0 |
积分 | 1 |
经验 | 48662 |
最后登录 | 2012-11-14 |
在线时间 | 3 小时 |
Lv1.梦旅人 SB們大家好<
- 梦石
- 0
- 星屑
- 50
- 在线时间
- 3 小时
- 注册时间
- 2008-1-7
- 帖子
- 457
|
简化了一些,按照自己的想法去完成了..不过还是多谢赐教
- class Game_Character
- def xy_test(x_plus,y_plus)
- if y_plus == 0
- for i in [0,x_plus].min..[0,x_plus].max
- plusx = x_plus > 0 ? x_plus - i : i
- next if !map_passable?(@x + plusx, @y)
- x_plus = plusx
- break
- end
- elsif x_plus == 0
- for i in [0,y_plus].min..[0,y_plus].max
- plusy = y_plus > 0 ? y_plus - i : i
- next if !map_passable?(@x , @y + plusy)
- y_plus = plusy
- break
- end
- elsif x_plus == y_plus
- for i in [0,x_plus].min..[0,x_plus].max
- plusx = x_plus > 0 ? x_plus - i : i
- next if !map_passable?(@x + plusx, @y + plusx)
- x_plus = plusx
- y_plus = plusx
- break
- end
- elsif x_plus.abs == y_plus.abs
- for i in [0,x_plus].min..[0,x_plus].max
- plusx = x_plus > 0 ? x_plus - i : i
- plusy = y_plus > 0 ? y_plus + i : -i
- next if !map_passable?(@x + plusx, @y + plusy)
- x_plus = plusx
- y_plus = plusy
- break
- end
- end
- return [x_plus,y_plus]
- end
-
- def pb_test(x_plus, y_plus)
- if (y_plus != 0 and x_plus == 0) or (x_plus != 0 and y_plus == 0) or x_plus.abs == y_plus.abs
- x_plus = xy_test(x_plus,0)[0]
- y_plus = xy_test(0,y_plus)[1]
- else
- return []
- end
- return [x_plus, y_plus]
- end
-
-
- def abs_test(x_plus, y_plus)
- s = false
- p = (x_plus.abs - y_plus.abs).abs
- if x_plus.abs > y_plus.abs
- for i in 1..p
- plus = x_plus > 0 ? x_plus - i : x_plus + i
- next if !map_passable?(@x + plus , @y + y_plus)
- x_plus = plus
- s = true
- break
- end
- else
- for i in 1..p
- plus = y_plus > 0 ? y_plus - i : y_plus + i
- next if !map_passable?(@x + x_plus , @y + plus)
- y_plus = plus
- s = true
- break
- end
- end
- if !s
- if x_plus.abs > y_plus.abs
- x_plus = x_plus > 0 ? y_plus.abs : - y_plus.abs
- else
- y_plus = y_plus > 0 ? x_plus.abs : - x_plus.abs
- end
- b = pb_test(x_plus, y_plus)
- x_plus = b[0]
- y_plus = b[1]
- end
- return [x_plus, y_plus]
- end
- def jump(x_plus, y_plus)
- if x_plus.abs > y_plus.abs # 横向距离长
- x_plus < 0 ? turn_left : turn_right
- elsif x_plus.abs > y_plus.abs # 纵向距离长
- y_plus < 0 ? turn_up : turn_down
- end
- if !map_passable?(@x + x_plus, @y + y_plus)
- a = pb_test(x_plus, y_plus)
- if a.empty?
- x_plus = abs_test(x_plus,y_plus)[0]
- y_plus = abs_test(x_plus,y_plus)[1]
- else
- x_plus = a[0]
- y_plus = a[1]
- end
- end
- @x += x_plus
- @y += y_plus
- distance = Math.sqrt(x_plus * x_plus + y_plus * y_plus).round
- @jump_peak = 10 + distance - @move_speed
- @jump_count = @jump_peak * 2
- @stop_count = 0
- straighten
- end
-
- end
复制代码 |
|