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

Project1

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

[已经过期] 關於增加一個事件作判定

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
114 小时
注册时间
2010-12-3
帖子
74
跳转到指定楼层
1
发表于 2010-12-16 23:11:37 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本人剛接觸RM..完全是超級新手.最近整合了一個640*480的系統.但mouse在戰鬥時錯位了.所以想請高手幫我改一改這個腳本----加一個判斷,當戰鬥時,mouse停用.以下是傳說中的mouse腳本...
#================================================= =============================
# ■ Sprite_Cursor
#================================================= =============================
class Spriteset_Cursor
  #------------------------------------------------- -------------------------
  # ○ 參數
  #------------------------------------------------- -------------------------
  FRAME = 8 # 動畫格數
  TIMING = 6 # 每格動畫時間
  #------------------------------------------------- -------------------------
  # ○ 讀取
  #------------------------------------------------- -------------------------
  attr_accessor :ani_enable
  #------------------------------------------------- -------------------------
  # ○ 初始化對象
  # viewport : 視區
  #------------------------------------------------- -------------------------
  def initialize
    @cursor_sprite = Sprite.new
    @ani_sprite = Sprite.new
    @cursor_sprite.bitmap = Cache.system("Pointer")
    @ani_width = Cache.system("ani").width/FRAME
    @ani_height = Cache.system("ani").height
    @ani_sprite.bitmap = Bitmap.new(@ani_width, @ani_height)
    @ani_sprite.ox = @ani_width/2.0
    @ani_sprite.oy = @ani_height/2.0
    @ani_sprite.visible = false
    @ani_count = 0
    @ani_enable = true
  end
  #------------------------------------------------- -------------------------
  # ○ 釋放
  #------------------------------------------------- -------------------------
  def dispose
    @cursor_sprite.dispose
    @ani_sprite.dispose
  end
  #------------------------------------------------- -------------------------
  # ○ 刷新畫面
  #------------------------------------------------- -------------------------
  def update
    @cursor_sprite.update
    update_ani
  end
  #------------------------------------------------- -------------------------
  # ○ 判斷動畫是否正在顯示
  #------------------------------------------------- -------------------------
  def animation?
    return @ani_sprite.visible
  end
  #------------------------------------------------- -------------------------
  # ○
  #------------------------------------------------- -------------------------
  def x
    return @cursor_sprite.x
  end
  #------------------------------------------------- -------------------------
  # ○
  #------------------------------------------------- -------------------------
  def y
    return @cursor_sprite.y
  end
  #------------------------------------------------- -------------------------
  # ○
  #------------------------------------------------- -------------------------
  def z
    return @cursor_sprite.z
  end
  #------------------------------------------------- -------------------------
  # ○
  #------------------------------------------------- -------------------------
  def visible
    return @cursor_sprite.visible
  end
  #------------------------------------------------- -------------------------
  # ○
  #------------------------------------------------- -------------------------
  def bitmap
    return @cursor_sprite.bitmap
  end
  #------------------------------------------------- -------------------------
  # ○
  #------------------------------------------------- -------------------------
  def x=(x)
    @cursor_sprite.x = x
  end
  #------------------------------------------------- -------------------------
  # ○
  #------------------------------------------------- -------------------------
  def y=(y)
    @cursor_sprite.y = y
  end
  #------------------------------------------------- -------------------------
  # ○
  #------------------------------------------------- -------------------------
  def z=(z)
    @cursor_sprite.z = z
  end
  #------------------------------------------------- -------------------------
  # ○
  #------------------------------------------------- -------------------------
  def visible=(visible)
    @cursor_sprite.visible = @visible = visible
  end
  #------------------------------------------------- -------------------------
  # ○
  #------------------------------------------------- -------------------------
  def bitmap=(bitmap)
    @cursor_sprite.bitmap = bitmap
  end
  #------------------------------------------------- -------------------------
  # ○
  #------------------------------------------------- -------------------------
  def start_ani(x, y)
    @ani_x = x
    @ani_y = y
    @ani_count = 0
    @ani_sprite.viewport = $scene.map_viewport## unless @ani_sprite.viewport
    @ani_sprite.x = ani_x(@ani_x)
    @ani_sprite.y = ani_y(@ani_y)
    @ani_sprite.z = 10
    @ani_sprite.visible = true
  end
  #------------------------------------------------- -------------------------
  # ○
  #------------------------------------------------- -------------------------
  def update_ani
    return unless @ani_sprite.visible
    if @ani_count > TIMING * FRAME
      @ani_count = 0
      @ani_sprite.visible = false
    end
    @ani_sprite.x = ani_x(@ani_x)
    @ani_sprite.y = ani_y(@ani_y)
    src_bitmap = Cache.system("ani")
    src_rect = Rect.new(@ani_width * (@ani_count/TIMING), 0, @ani_width, @ani_height)
    @ani_sprite.bitmap.clear
    @ani_sprite.bitmap.blt(0, 0, src_bitmap, src_rect)
    @ani_count += 1
    @ani_sprite.update
  end
  #------------------------------------------------- -------------------------
  # ○
  #------------------------------------------------- -------------------------
  def ani_x(x)
    return ($game_map.adjust_x(x) + 8007) / 8 - 1000 + 16
  end
  #------------------------------------------------- -------------------------
  # ○
  #------------------------------------------------- -------------------------
  def ani_y(y)
    return ($game_map.adjust_y(y) + 8007) / 8 - 1000 + 32
  end
end
#================================================= =============================
# ■ Game_Map
#================================================= =============================
class Game_Map
  def adjust_x1(x)
    if loop_horizontal? and x < @display_x - @margin_x
      return x + @display_x + @map.width * 256
    else
      return x + @display_x
    end
  end
  def adjust_y1(y)
    if loop_vertical? and y < @display_y - @margin_y
      return y + @display_y + @map.height * 256
    else
      return y + @display_y
    end
  end
end
#================================================= =============================
# ■ Spriteset_Map
#================================================= =============================
class Spriteset_Map
  attr_reader :viewport1
end
#================================================= =============================
# ■ Scene_Map
#================================================= =============================
class Scene_Map < Scene_Base
  def map_viewport
    return @spriteset.viewport1
  end
end
#================================================= =============================
# ** Mouse Input Module (Revised)
#------------------------------------------------- -----------------------------
# by DerVVulfman
# version 1.2
# 08-18-2007
#------------------------------------------------- -----------------------------
# Based on...
# Mouse Input Module
# by Near Fantastica
#------------------------------------------------- -----------------------------
# Set_Pos feature by
# Freakboy
#------------------------------------------------- -----------------------------
#
# THE CALLS:
#
# Mouse.click?
# This returns a true/false value when you test whether a button is clicked.
# The values you pass are 1 (for the left mouse button), 2 (for the right) or
# 3 (for the middle button).
#
# Mouse.press?
# This returns a true/false value when you test whether a button is pressed
# and kept depressed. The values you pass are 1 (for the left mouse button),
# 2 (for the right mouse button), or 3 (for the middle).
#
# Mouse.pixels
# This returns the mouse's screen coordinates in pixels. Based on a screen
# with a 640x480 dimension, this returns an array of the mouse's position in
# index values. Calling Mouse.pixels returns both x & y positions in a sin-
# gle string, but calling Mouse.pixels[0] returns the x position (0-639) and
# calling Mouse.pixels[1] returns the y position (0-439). If the mouse is
# outside of the game's window region, this call returns nil.
#
# Mouse.tiles
# This returns the mouse's screen coordinates in map tiles. Based on the
# system's 20x15 tile size, this returns it in index values (a 0-19 width &
# a 0-14 height). This functions the same manner as Mouse.pixels.
#
# Mouse.set_pos
# This allows you to forcefully position the mouse at an x/y position within
# the game screen by pixel coordinates. Given the game's normal screen width
# of 640x480, adding: Mouse.set_pos(320,240) should position the mouse dead
# center of the gaming window.
#
# Mouse.update
# Add this routine into your update routines to update the mouse position.
# It must be called otherwise you won't get valid mouse coordinates.
#
#================================================= =============================

module Mouse
  #------------------------------------------------- -------------------------
  # ## 常量
  #------------------------------------------------- -------------------------
  GetAsyncKeyState = Win32API.new("user32","GetAsyncKeyState",['i'],'i')
  GetKeyState = Win32API.new("user32","GetKeyState",['i'],'i')
  
  ScreenToClient = Win32API.new('user32', 'ScreenToClient', 'lp', 'i')
  
  GetCursorPos = Win32API.new('user32', 'GetCursorPos', 'p', 'i')
  GetClientRect = Win32API.new('user32', 'GetClientRect', 'lp', 'i')
  
  #------------------------------------------------- -------------------------
  # * Mouse Click
  # button : button
  #------------------------------------------------- -------------------------
  def Mouse.click?(button)
    return false if button == 1 and !$click_abled
    return true if @keys.include?(button)
    return false
  end
  #------------------------------------------------- -------------------------
  # * Mouse Pressed
  # button : button
  #------------------------------------------------- -------------------------
  def Mouse.press?(button)
    return true if @press.include?(button)
    return false
  end
  #------------------------------------------------- -------------------------
  # * Mouse Pressed
  # button : button
  #------------------------------------------------- -------------------------
  def Mouse.area?(x, y, width=32, height=32)
    return false if @pos == nil
    return true if @pos[0] >= x and @pos[0] <= (x+width) and @pos[1] >= y and @pos[1] <= (y+height)
    return false
  end
  #------------------------------------------------- -------------------------
  # * Mouse Pixel Position
  #------------------------------------------------- -------------------------
  def Mouse.pixels
    return @pos == nil ? [0, 0] : @pos
  end
  #------------------------------------------------- -------------------------
  # * Mouse Tile Position
  #------------------------------------------------- -------------------------
  def Mouse.tiles
    return nil if @pos == nil
    x = @pos[0] / 32
    y = @pos[1] / 32
    return [x, y]
  end
  #------------------------------------------------- -------------------------
  # * Set Mouse Position
  #------------------------------------------------- -------------------------
  def Mouse.set_pos(x_pos=0, y_pos=0)
    width, height = Mouse.client_size
    if (x_pos.between?(0, width) && y_pos.between?(0, height))
      x = Mouse.client_pos[0] + x_pos; y = Mouse.client_pos[1] + y_pos
      Win32API.new('user32', 'SetCursorPos', 'NN', 'N').call(x, y)
    end
  end
  #------------------------------------------------- -------------------------
  # * Mouse Update
  #------------------------------------------------- -------------------------
  def Mouse.update
    @pos = Mouse.pos
    @keys, @press = [], []
    @keys.push(1) if GetAsyncKeyState.call(1) & 0X01 == 1
    @keys.push(2) if GetAsyncKeyState.call(2) & 0X01 == 1
    @keys.push(3) if GetAsyncKeyState.call(4) & 0X01 == 1
    @press.push(1) if GetKeyState.call(1) & 0X01 == 1
    @press.push(2) if GetKeyState.call(2) & 0X01 == 1
    @press.push(3) if GetKeyState.call(4) & 0X01 == 1
    ## 鼠標雙擊
    @wait ||= 0
    @wait += 1 if @key != nil
    (@key = nil; @wait = 0) if @wait > 30 # 雙擊時間
  end
  #------------------------------------------------- -------------------------
  # * Automatic functions below
  #------------------------------------------------- -------------------------
  #
  #------------------------------------------------- -------------------------
  # * Obtain Mouse position in screen
  #------------------------------------------------- -------------------------
  def Mouse.global_pos
    pos = [0, 0].pack('ll')
    if GetCursorPos.call(pos) != 0
      return pos.unpack('ll')
    else
      return nil
    end
  end
  #------------------------------------------------- -------------------------
  # * Return Screen mouse position within game window
  #------------------------------------------------- -------------------------
  def Mouse.pos
    x, y = Mouse.screen_to_client(*Mouse.global_pos)
    width, height = Mouse.client_size
    begin
      if (x >= 0 and y >= 0 and x < width and y < height)
        return x, y
      else
        return nil
      end
    rescue
      return nil
    end
  end
  #------------------------------------------------- -------------------------
  # * Pass Screen to Game System
  #------------------------------------------------- -------------------------
  def Mouse.screen_to_client(x, y)
    return nil unless x and y
    pos = [x, y].pack('ll')
    if ScreenToClient.call(HWND, pos) != 0
      return pos.unpack('ll')
    else
      return nil
    end
  end
  #------------------------------------------------- -------------------------
  # * Get Game Window Size
  #------------------------------------------------- -------------------------
  def Mouse.client_size
    rect = [0, 0, 0, 0].pack('l4')
    GetClientRect.call(HWND, rect)
    right, bottom = rect.unpack('l4')[2..3]
    return right, bottom
  end
  #------------------------------------------------- -------------------------
  # * Get Window Position
  #------------------------------------------------- -------------------------
  def Mouse.client_pos
    rect = [0, 0, 0, 0].pack('l4')
    ## 用戶區
    GetClientRect.call(HWND, rect)
    left, upper = rect.unpack('l4')[0..1]
    return left, upper
  end
  #------------------------------------------------- -------------------------
  # ## 句柄
  #------------------------------------------------- -------------------------
  def Mouse.get_hwnd
    game_name = "\0" * 256
    Win32API.new('kernel32', 'GetPrivateProfileStringA', 'pppplp', 'l').call('Game','Title','',game_name,255,".\\Game.ini")
    game_name.delete!("\0")
    return Win32API.new('user32', 'FindWindowA', 'pp', 'l').call('RGSS Player',game_name)
  end
  #------------------------------------------------- -------------------------
  # ## 雙擊
  #------------------------------------------------- -------------------------
  def self.double_click?(key)
    if @keys.include?(key)
      @key !=key ? (@key = key; return false) : (@key = nil; return true)
    end
  end
  ## 句柄常量
  HWND = Mouse.get_hwnd
  
  ###############
  GetMessage = Win32API.new('user32','GetMessage','plll','l')
  
  Point = Struct.new(:x, :y)
  Message = Struct.new(:message, :wparam, :lparam, :pt)
  Param = Struct.new(:x, :y, :scroll)
  
  def self.scroll
    msg = "\0"*32
    GetMessage.call(msg,0,0,0)
    r = wmcallback(unpack_msg(msg))
    return r unless r.nil?
  end
  
  def wmcallback(msg)
    return unless msg.message == Scroll
    param = Param.new
    param.x = word2signed_short(loword(msg.lparam))
    param.y = word2signed_short(hiword(msg.lparam))
    param.scroll = word2signed_short(hiword(msg.wparam))
    return [param.x,param.y,param.scroll]
  end
  
  def hiword(dword)
    ###return ((dword&0xffff0000)>>16)&0x0000ffff
    return (dword & 0xffff0000) / 0x10000
  end
  
  def loword(dword)
    return dword&0x0000ffff
  end
end

#================================================= =============================
# Path Finding
# Version: 2.0
# Author: modern algebra (rmrk.net)
# Date: April 10, 2008
#================================================= =============================
# Lets the Player or Event draw a path from an desonation to the source. This
# method is very fast and because the pathfinding is imbedded into the Game
# Character the pathfinding can be interrupted or redrawn at any time.
#================================================= =============================
# Player :: $game_player.find_path(x,y)
# Event Script Call :: self.event.find_path(x,y)
# Event Movement Script Call :: self.find_path(x,y)
#================================================= =============================
# [VX] Simple Mouse System Note: I edited the method
# character.passable?(x, y, direction) to character.passable?(x, y)
# according to change of this method in VX.
#================================================= =============================

class Game_Character
  #------------------------------------------------- -------------------------
  alias nf_pf_game_character_initialize initialize
  alias nf_pf_game_character_update update
  #------------------------------------------------- -------------------------
  attr_accessor :map
  attr_accessor :runpath
  #------------------------------------------------- -------------------------
  def initialize
    nf_pf_game_character_initialize
    @map = nil
    @runpath = false
  end
  #------------------------------------------------- -------------------------
  def update
    run_path if @runpath == true
    nf_pf_game_character_update
  end
  #------------------------------------------------- -------------------------
  def run_path
    return if moving?
    step = @map[@x,@y]
    if step == 1
      @map = nil
      @runpath = false
      return
    end
    dir = rand(2)
    case dir
    when 0
      move_right if @map[@x+1,@y] == step - 1 and step != 0
      move_down if @map[@x,@y+1] == step - 1 and step != 0
      move_left if @map[@x-1,@y] == step -1 and step != 0
      move_up if @map[@x,@y-1] == step - 1 and step != 0
    when 1
      move_up if @map[@x,@y-1] == step - 1 and step != 0
      move_left if @map[@x-1,@y] == step -1 and step != 0
      move_down if @map[@x,@y+1] == step - 1 and step != 0
      move_right if @map[@x+1,@y] == step - 1 and step != 0
    end
  end
  #------------------------------------------------- -------------------------
  def find_path(x,y)
    sx, sy = @x, @y
    result = setup_map(sx,sy,x,y)
    @runpath = result[0]
    @map = result[1]
    @map[sx,sy] = result[2] if result[2] != nil
  end
  #------------------------------------------------- -------------------------
  def clear_path
    @map = nil
    @runpath = false
  end
  #------------------------------------------------- -------------------------
  def setup_map(sx,sy,ex,ey)
    map = Table.new($game_map.width, $game_map.height)
    map[ex,ey] = 1
    old_positions = []
    new_positions = []
    old_positions.push([ex, ey])
    depth = 2
    depth.upto(100){|step|
      loop do
        break if old_positions[0] == nil
        x,y = old_positions.shift
        return [true, map, step] if x == sx and y+1 == sy
        ## 修改通行條件
        if $game_player.map_passable?(x, y) and map[x,y + 1] == 0
          map[x,y + 1] = step
          new_positions.push([x,y + 1])
        end
        return [true, map, step] if x-1 == sx and y == sy
        if $game_player.map_passable?(x, y) and map[x - 1,y] == 0
          map[x - 1,y] = step
          new_positions.push([x - 1,y])
        end
        return [true, map, step] if x+1 == sx and y == sy
        if $game_player.map_passable?(x, y) and map[x + 1,y] == 0
          map[x + 1,y] = step
          new_positions.push([x + 1,y])
        end
        return [true, map, step] if x == sx and y-1 == sy
        if $game_player.map_passable?(x, y) and map[x,y - 1] == 0
          map[x,y - 1] = step
          new_positions.push([x,y - 1])
        end
      end
      old_positions = new_positions
      new_positions = []
    }
    return [false, nil, nil]
  end
end
  
class Game_Map
  #------------------------------------------------- -------------------------
  alias pf_game_map_setup setup
  #------------------------------------------------- -------------------------
  def setup(map_id)
    pf_game_map_setup(map_id)
    $game_player.clear_path
  end
end
  
class Game_Player
  #------------------------------------------------- -------------------------
  alias pf_game_player_update update
  #------------------------------------------------- -------------------------
  def update
    $game_player.clear_path if Input.dir4 != 0
    pf_game_player_update
  end
end
  
class Interpreter
  #------------------------------------------------- -------------------------
  def event
    return $game_map.events[@event_id]
  end
end
#================================================= =============================
# [VX] SMS - Simple Mouse System
#------------------------------------------------- -----------------------------
# ◦ by Woratana [[email protected]]
# ◦ Released on: 14/04/2008 (D-M-Y)
# ◦ Version: 1.5
#
# ◦ Credit: DerVVulfman, Near Fantastica, and Freak Boy [Mouse Input Module]
# lambchop, shun, Cybersam, Astro_mech, and Mr.Mo [Super Simple Mouse System]
# - Modern Algebra, Zeriab, Patrick Lester [Path Finding]
# - Near Fantastica, Fuso [Path Finding]
#
# - I will not be able to script this without those people and scripts above
#------------------------------------------------- ----------------------------
#====[REQUIRE]=====
# - DerVVulfman's Mouse Input Module
# (http://rmxp.org/forums/index.php?topic=26993)
# It's XP script, but also works in VX!
#
# - Near Fantastica's Path Finding [version 1.0]
# (http://www.rmxp.org/forums/index.php?topic=26661.0)
# with a little fix to make it works in VX.
# (get fixed version from Simple Mouse System demo)
#
#====[FEATURE]=====
# - Support to use mouse in many scenes / windows
# - Click on map to move player with Path Finding
# - Mouse Pointer
#
#====[PLAN in next version]=====
# - Cursor change when put on other event
# - Better event trigger check by click mouse
#------------------------------------------------- -----------------------------
# 沉影不器的修改:
# ① 修復使用交通工具時鼠標無效的bug (鼠標雙擊:上/下交通工具)
# ② 降低對象靈敏度
# ③ 修復物品或技能有效範圍是"全體"或"使用者"時光標錯誤bug
# ④ 修改角色在地圖上的移動,防止地圖上"滑動"
# ⑤ 鼠標不在選項上時,按左鍵不響應
# ⑥ F2不影響鼠標使用
# ⑦ 鼠標點擊移動中的NPC,該NPC停止移動,原地面向角色
#------------------------------------------------- -----------------------------
# 如果某個窗體重定義了update_mouse,請參照修改之
#------------------------------------------------- -----------------------------

#================================================= =============================
# ** Mouse Input Module
#================================================= =============================
class << Mouse
  Win32API.new('user32', 'ShowCursor', 'l', 'l').call(0)
  ##$mousec = Sprite.new
  $mousec = Spriteset_Cursor.new
  $mousec.z = 10001
  $mousec.x = $mousec.y = 1000
  $mouse_icon = 'Pointer'
  $mousec.bitmap = Cache.system($mouse_icon)
  
  alias wor_mouse_upd_mouse update unless $@
  def Mouse.update
    wor_mouse_upd_mouse
    if $mouse_old_icon.nil? or $mouse_old_icon != $mouse_icon
      $mouse_old_icon = $mouse_icon
      $mousec.bitmap = Cache.system($mouse_old_icon)
    end
    if @pos.nil?
      $mousec.x = 1000 if $mousec.x != 1000
      $mousec.y = 1000 if $mousec.y != 1000
      Win32API.new('user32', 'ShowCursor', 'l', 'l').call(1)
    else
      $mousec.x = @pos[0] if $mousec.x != @pos[0]
      $mousec.y = @pos[1] if $mousec.y != @pos[1]
      Win32API.new('user32', 'ShowCursor', 'l', 'l').call(0)
    end
    ## 鼠標刷新
    $mousec.update
  end
  
  def Mouse.map_pos
    return nil if @pos == nil
    x = ($game_map.display_x / 256) + (@pos[0] / 32)
    y = ($game_map.display_y / 256) + (@pos[1] / 32)
    return [x, y]
  end
  ## 地圖真實坐標
  def Mouse.map_xy
    return nil if @pos == nil
    x = (@pos[0]+1000-16)*8-8007
    y = (@pos[1] + 1000-32)*8 -8007
    m = $game_map.adjust_x1(x)
    n = $game_map.adjust_y1(y)
    return [m, n]
  end
end

#================================================= =============================
# ** Input
#================================================= =============================
class << Input
  alias wor_input_upd_mouse update unless $@
  alias wor_input_trig_mouse trigger? unless $@
  alias wor_input_rep_mouse repeat? unless $@
  def Input.update
    wor_input_upd_mouse
    Mouse.update
  end
  def Input.trigger?(input)
    return wor_input_trig_mouse(input) if Mouse.pos.nil?
    case input
    when Input::B
      return (wor_input_trig_mouse(input) or Mouse.click?(2))
    when Input::C
      if $scene.is_a?(Scene_Map) and !$game_message.visible
        return wor_input_trig_mouse(input)
      else
        return (wor_input_trig_mouse(input) or Mouse.click?(1))
      end
    else
      return wor_input_trig_mouse(input)
    end
  end
  
  def Input.repeat?(input)
    if input == Input::B
      return (wor_input_rep_mouse(input) or Mouse.click?(2))
    else
      return wor_input_rep_mouse(input)
    end
  end
  
  ## 鼠標雙擊
  def Input.double_click?(input)
    return Mouse.double_click?(input)
  end
end

#================================================= =============================
# ** Graphics
#================================================= =============================
class << Graphics
  alias wor_graph_fadeout_mouse fadeout unless $@
  def Graphics.fadeout(frames = 1)
    $mousec.visible = false if !$mousec.nil?
    wor_graph_fadeout_mouse(frames)
  end
end

#================================================= =============================
# ** Window_Selectable
#================================================= =============================
class Window_Selectable < Window_Base
  alias wor_winsel_ini_mouse initialize
  alias wor_winsel_upd_mouse update
  def initialize(*args)
    wor_winsel_ini_mouse(*args)
    @scroll_wait = 0
    @cursor_wait = 0
  end

  def update
    wor_winsel_upd_mouse
    if self.active and self.visible
      update_mouse
    end
  end
  
  def update_mouse
    @cursor_wait -= 1 if @cursor_wait > 0
    (0...@item_max).each do |i|
      irect = mouse_rect(i)
      irx = self.x + 16 + irect.x - self.ox
      iry = self.y + 16 + irect.y - self.oy
      result = Mouse.area?(irx, iry, irect.width, irect.height)
      move_cursor(i) if result
      ## 控制單擊條件
      $click_abled = false if i == @index and !result
    end
  end
  
  ## 鼠標區域
  def mouse_rect(i)
    rect = item_rect(i)
    return rect if rect.width <= 32
    rect.x += 4
    rect.y += 4
    rect.width -= 8
    rect.height -= 8
    return rect
  end
  
  def move_cursor(index)
    return if @index == index
    @scroll_wait -= 1 if @scroll_wait > 0
    row1 = @index / @column_max
    row2 = index / @column_max
    bottom = self.top_row + (self.page_row_max - 1)
    if row1 == self.top_row and row2 < self.top_row
      return if @scroll_wait > 0
      @index = [@index - @column_max, 0].max
      @scroll_wait = 4
    elsif row1 == bottom and row2 > bottom
      return if @scroll_wait > 0
      @index = [@index + @column_max, @item_max - 1].min
      @scroll_wait = 4
    else
      @index = index
    end
    return if @cursor_wait > 0
    Sound.play_cursor
    @cursor_wait += 2
  end
end

#================================================= =============================
# ** Window_MenuStatus
#================================================= =============================
class Window_MenuStatus < Window_Selectable
  def item_rect(index)
    return Rect.new(0, index * 96, contents.width, 96)
  end
  
  def update_mouse
    @cursor_wait -= 1 if @cursor_wait > 0
    (0...@item_max).each do |i|
      irect = mouse_rect(i)
      irx = self.x + 16 + irect.x - self.ox
      iry = self.y + 16 + irect.y - self.oy
      result = Mouse.area?(irx, iry, irect.width, irect.height)
      move_cursor(i) if result and @index < 99
    end
    irect = mouse_rect(@index)
    irx = self.x + 16 + irect.x - self.ox
    iry = self.y + 16 + irect.y - self.oy
    result = Mouse.area?(irx, iry, irect.width, irect.height)
    $click_abled = false unless result
  end
  
  ## 符合物品範圍的修改
  def item_rect(index)
    if index < 0
      return
    elsif index == 99
      return Rect.new(0, 0, self.contents.width, self.contents.height)
    elsif index >= 100
      return Rect.new(0, (index - 100) * 96, contents.width, 96)
    else
      return Rect.new(0, index * 96, contents.width, 96)
    end
  end
end

#================================================= =============================
# ** Window_NameInput
#================================================= =============================
class Window_NameInput < Window_Base
  alias wor_winnam_upd_mouse update
  def update
    wor_winnam_upd_mouse
    if self.active and self.visible
      (0..TABLE[@mode].size - 1).each do |i|
      irect = item_rect(i)
      irx = self.x + 16 + irect.x - self.ox
      iry = self.y + 16 + irect.y - self.oy
      @index = i if Mouse.area?(irx, iry, irect.width, irect.height)
      end
    end
  end
end

#================================================= =============================
# ** Window_PartyCommand
#================================================= =============================
class Window_PartyCommand < Window_Command
  def update_mouse
    (0..@item_max - 1).each do |i|
    irect = mouse_rect(i)
    irx = self.viewport.ox + 16 + irect.x - self.ox
    iry = 288 + 16 + irect.y - self.oy
    result = Mouse.area?(irx, iry, irect.width, irect.height)
    self.index = i if result
    ## 控制單擊條件
    $click_abled = false if i == @index and !result
    end
  end
  
end

#================================================= =============================
# ** Window_ActorCommand
#================================================= =============================
class Window_ActorCommand < Window_Command
  def update_mouse
    (0..@item_max - 1).each do |i|
    irect = item_rect(i)
    irx = self.viewport.ox + 288 + 16 + irect.x
    iry = 288 + 16 + irect.y
    result = Mouse.area?(irx, iry, irect.width, irect.height)
    self.index = i if result
    ## 控制單擊條件
    $click_abled = false if i == @index and !result
    end
  end
end

#================================================= =============================
# ** Window_Message
#================================================= =============================
class Window_Message < Window_Selectable
  def update_mouse
    (0..@item_max - 1).each do |i|
      irect = item_rect(i)
      irx = self.x + 16 + irect.x - self.ox
      iry = self.y + 16 + irect.y - self.oy + ($game_message.choice_start * WLH)
      result = Mouse.area?(irx, iry, irect.width, irect.height)
      self.index = i if result
      ## 控制單擊條件
      $click_abled = false if i == @index and !result
    end
  end
end

#================================================= =============================
# ** Scene_Base
#================================================= =============================
class Scene_Base
  alias wor_scebase_posstr_mouse post_start
  alias wor_scebase_preter_mouse pre_terminate
  def post_start
    $mousec.visible = true if !$mousec.nil?
    wor_scebase_posstr_mouse
  end
  
  def update
    ## 單擊條件初始化
    $click_abled = true
    ## 鼠標動畫條件初始化
    $mousec.ani_enable = false
  end
  
  def pre_terminate
    $mousec.visible = false if !$mousec.nil?
    wor_scebase_preter_mouse
  end
end

#================================================= =============================
# ** Scene_File
#================================================= =============================
class Scene_File < Scene_Base
  alias wor_scefil_upd_mouse update
  def update
    (0..@item_max - 1).each do |i|
      ix = @savefile_windows.x
      iy = @savefile_windows.y
      iw = @savefile_windows.width
      ih = @savefile_windows.height
      if Mouse.area?(ix, iy, iw, ih)
        @savefile_windows[@index].selected = false
        @savefile_windows.selected = true
        @index = i
      end
    end
    wor_scefil_upd_mouse
  end
end

#================================================= =============================
# ** Scene_Map
#================================================= =============================
class Scene_Map < Scene_Base
  ## 鼠標坐標
  attr_reader :mouse_xy
  attr_accessor :last_click
  alias wor_scemap_upd_mouse update
  def initialize
    ## 初始坐標
    @last_click = [$game_player.x, $game_player.y]
  end
  def update
    ## 還原鼠標動畫標誌
    $mousec.ani_enable = true
    wor_scemap_upd_mouse
    @mouse_xy = Mouse.map_pos
    ## 增加條件判斷修改通行判斷修改清除修改面向
    if Mouse.click?(1) and !@mouse_xy.nil? and !$game_message.visible and
      !$game_map.interpreter.running? and @last_click != @mouse_xy and
      $game_player.move_by_mouse?
      if $game_player.close?(*@mouse_xy) and
        $game_player.check_action_event
        $game_player.clear_path
        return
      end
      #if $game_player.map_passable?(*@mouse_xy)
      if $game_player.passable?(*@mouse_xy)
        $game_player.clear_path
        $game_player.find_path(*@mouse_xy)
        ## 鼠標動畫
        $mousec.start_ani(*Mouse.map_xy) if $mousec.ani_enable
      else
        $game_player.clear_path
        $game_player.turn_toward_pos(*@mouse_xy)
      end
      @last_click = @mouse_xy
    end
    if Mouse.click?(3) and !@mouse_xy.nil? and !$game_message.visible and
      !$game_map.interpreter.running?
      $game_player.clear_path
      $game_player.turn_toward_pos(*@mouse_xy)
    end
  end
end

#================================================= =============================
# ** Game_Character
#================================================= =============================
class Game_Character
  ## 鎖定標誌
  attr_reader :locked
  def turn_toward_pos(x,y)
    sx = distance_x_from_pos(x)
    sy = distance_y_from_pos(y)
    if sx.abs > sy.abs
      sx > 0 ? turn_left : turn_right
    elsif sx.abs < sy.abs
      sy > 0 ? turn_up : turn_down
    end
  end
  
  def distance_x_from_pos(x)
    sx = @x - x
    if $game_map.loop_horizontal?
      if sx.abs > $game_map.width / 2
        sx -= $game_map.width
      end
    end
    return sx
  end
  
  def distance_y_from_pos(y)
    sy = @y - y
    if $game_map.loop_vertical?
      if sy.abs > $game_map.height / 2
        sy -= $game_map.height
      end
    end
    return sy
  end
  
  def close?(x,y)
    sx = (@x - x).abs
    sy = (@y - y).abs
    if sx + sy == 1
      return true
    end
    return false
  end
end

#================================================= =============================
# ## Game_Player
#================================================= =============================
class Game_Player
  #------------------------------------------------- -------------------------
  ## 是否支持鼠標移動?
  #------------------------------------------------- -------------------------
  def move_by_mouse?
    return false if @move_route_forcing # 強制移動路徑中
    return false if @vehicle_getting_on # 正在乘座交通工具中
    return false if @vehicle_getting_off # 正在降下交通工具中
    return false if in_airship? and not $game_map.airship.movable?
    return true
  end
  
  #------------------------------------------------- -------------------------
  ## 不移動時
  #------------------------------------------------- -------------------------
  def update_nonmoving(last_moving)
    return if $game_map.interpreter.running?
    return if moving?
    return if check_touch_event if last_moving
    ## 雙擊激活交通工具
    if not $game_message.visible and Input.trigger?(Input::C) || Input.double_click?(1)
      return if get_on_off_vehicle
      return if check_action_event
    end
    update_encounter if last_moving
    ## 還原鼠標移動標誌
    $scene.last_click = [$game_player.x, $game_player.y]
  end
end

#================================================= =============================
# ## Game_Map
#================================================= =============================
class Game_Map
  #------------------------------------------------- -------------------------
  ## NPC加強
  #------------------------------------------------- -------------------------
  def update_events
    for event in @events.values
      if Mouse.click?(1)
        event.unlock
        if [event.x, event.y] == $scene.mouse_xy and $game_player.move_by_mouse?
          event.lock
          $mousec.ani_enable = false
        end
      end
      event.turn_toward_player if event.locked
      event.update
    end
    for common_event in @common_events.values
      common_event.update
    end
  end
  #------------------------------------------------- -------------------------
  ## 更新交通工具
  #------------------------------------------------- -------------------------
  def update_vehicles
    for vehicle in @vehicles
      if Mouse.click?(1)
        if [vehicle.x, vehicle.y] == $scene.mouse_xy and $game_player.move_by_mouse?
          $mousec.ani_enable = false
        end
      end
      vehicle.update
    end
  end
end

Lv1.梦旅人

梦石
0
星屑
50
在线时间
466 小时
注册时间
2006-2-25
帖子
1863
2
发表于 2010-12-18 11:20:00 | 只看该作者
moudule Mouse里面
def Mouse.update下面加一句
return if $scene.is_a?(Scene_Battle)
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
114 小时
注册时间
2010-12-3
帖子
74
3
 楼主| 发表于 2010-12-19 12:03:20 | 只看该作者
回复 诡异の猫 的帖子

謝謝貓哥的回覆.
我試了,沒效果..大概是因為我使用了橫版戰鬥了吧?
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-9-24 18:23

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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