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

Project1

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

选择地图上的点

[复制链接]

…あたしは天使なんかじゃないわ

梦石
0
星屑
2207
在线时间
4033 小时
注册时间
2010-10-4
帖子
10779

开拓者贵宾

跳转到指定楼层
1
发表于 2015-2-7 14:27:12 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
本帖最后由 taroxd 于 2015-2-18 12:51 编辑

大概是拿来做传送道具之类的吧- -

RUBY 代码复制
  1. #--------------------------------------------------------------------------
  2. # ● 选择地图上的点
  3. #    require Taroxd基础设置,坐标类,修复bug
  4. #--------------------------------------------------------------------------
  5. #
  6. #    事件脚本 select_point(x, y)
  7. #    开始选择,并将光标指定在 x, y 处。注意 x, y 不可以在地图之外。
  8. #    若不指定参数,默认 x, y 为玩家所在的位置。
  9. #    一直等待,直到玩家选择或取消。
  10. #    返回 Taroxd::Point 的实例或 nil(取消)
  11. #
  12. #    可以选择的区域默认为可以通行的区域。该设置可在下方修改。
  13. #
  14. #--------------------------------------------------------------------------
  15.  
  16. module Taroxd::MapSelect
  17.  
  18.   # 颜色设置
  19.   OPACITY = 150
  20.   NG_COLOR = Color.new(255, 0, 0, OPACITY)
  21.   OK_COLOR = Color.new(0, 0, 255, OPACITY)
  22.  
  23.   class << self
  24.  
  25.     attr_reader :point
  26.     attr_reader :selecting
  27.  
  28.     def x
  29.       @point.x
  30.     end
  31.  
  32.     def y
  33.       @point.y
  34.     end
  35.  
  36.     # 是否允许选择点 (x, y)(该方法可以自定义)
  37.     def can_select?(x, y)
  38.       $game_player.passable?(x, y, 10 - $game_player.direction)
  39.     end
  40.  
  41.     def start(x = $game_player.x, y = $game_player.y)
  42.       @point = Taroxd::Point[x, y]
  43.       @selecting = true
  44.     end
  45.  
  46.     def select
  47.       if can_select?(*@point)
  48.         Sound.play_ok
  49.         @selecting = false
  50.       else
  51.         Sound.play_buzzer
  52.       end
  53.     end
  54.  
  55.     def cancel
  56.       @point = nil
  57.       @selecting = false
  58.     end
  59.  
  60.     def update
  61.       move_right if Input.repeat?(:RIGHT)
  62.       move_left  if Input.repeat?(:LEFT)
  63.       move_down  if Input.repeat?(:DOWN)
  64.       move_up    if Input.repeat?(:UP)
  65.       select     if Input.trigger?(:C)
  66.       cancel     if Input.trigger?(:B)
  67.     end
  68.  
  69.     def move_right
  70.       return if screen_x > Graphics.width - 48
  71.       @point.x += 1
  72.       Sound.play_cursor
  73.     end
  74.  
  75.     def move_left
  76.       return if screen_x < 16
  77.       @point.x -= 1
  78.       Sound.play_cursor
  79.     end
  80.  
  81.     def move_up
  82.       return if screen_y < 16
  83.       @point.y -= 1
  84.       Sound.play_cursor
  85.     end
  86.  
  87.     def move_down
  88.       return if screen_y > Graphics.height - 48
  89.       @point.y += 1
  90.       Sound.play_cursor
  91.     end
  92.  
  93.     def screen_x
  94.       @point.screen_x - 16
  95.     end
  96.  
  97.     def screen_y
  98.       @point.screen_y - 32
  99.     end
  100.   end
  101.  
  102.   class Cursor < Sprite
  103.     include Taroxd::DisposeBitmap
  104.  
  105.     # 光标的位图缓存。该方法可以自定义。
  106.     def self.bitmap
  107.       return @bitmap if @bitmap && !@bitmap.disposed?
  108.       @bitmap = Bitmap.new(32, 32)
  109.       skin = Cache.system('Window')
  110.       @bitmap.stretch_blt(@bitmap.rect, skin, Rect.new(64, 0, 64, 64))
  111.       @bitmap
  112.     end
  113.  
  114.     def initialize(_)
  115.       super
  116.       self.bitmap = self.class.bitmap
  117.       self.z = 205
  118.     end
  119.  
  120.     def update
  121.       self.visible = Taroxd::MapSelect.selecting
  122.       return unless visible
  123.       self.x = Taroxd::MapSelect.screen_x
  124.       self.y = Taroxd::MapSelect.screen_y
  125.     end
  126.   end
  127.  
  128.   class Status < Plane
  129.     include Taroxd::DisposeBitmap
  130.     include Taroxd::BugFix::PlaneVisible
  131.  
  132.     def initialize(_)
  133.       super
  134.       self.z = 200
  135.     end
  136.  
  137.     def update
  138.       was_visible = visible
  139.       self.visible = Taroxd::MapSelect.selecting
  140.       return unless visible
  141.       refresh unless was_visible
  142.       self.ox = $game_map.display_x * 32
  143.       self.oy = $game_map.display_y * 32
  144.     end
  145.  
  146.     def refresh
  147.       bitmap.dispose if bitmap
  148.       self.bitmap = Bitmap.new($game_map.width * 32, $game_map.height * 32)
  149.       $game_map.width.times do |x|
  150.         $game_map.height.times do |y|
  151.           draw_point(x, y)
  152.         end
  153.       end
  154.     end
  155.  
  156.     def draw_point(x, y)
  157.       color = Taroxd::MapSelect.can_select?(x, y) ? OK_COLOR : NG_COLOR
  158.       bitmap.fill_rect(x * 32, y * 32, 32, 32, color)
  159.     end
  160.   end
  161.  
  162.   # F12 guard
  163.   DataManager.singleton_def_before(:init, method(:cancel))
  164. end
  165.  
  166. class Game_Interpreter
  167.  
  168.   MapSelect = Taroxd::MapSelect
  169.  
  170.   def select_point
  171.     MapSelect.start
  172.     while MapSelect.selecting
  173.       MapSelect.update
  174.       Fiber.yield
  175.     end
  176.     MapSelect.point
  177.   end
  178. end
  179.  
  180. class Spriteset_Map
  181.   use_sprite(Taroxd::MapSelect::Cursor) { @viewport2 }
  182.   use_sprite(Taroxd::MapSelect::Status) { @viewport2 }
  183. end
拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

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

GMT+8, 2024-5-1 09:20

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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