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

Project1

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

[已经过期] 修成八方向鼠标系统带跑步

[复制链接]

Lv2.观梦者

梦石
0
星屑
445
在线时间
377 小时
注册时间
2012-11-5
帖子
267
跳转到指定楼层
1
发表于 2017-2-3 10:22:35 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 789456qwe 于 2017-2-3 10:24 编辑

这是四方向
RUBY 代码复制
  1. #==============================================================================
  2. # 本脚本来自[url]www.66RPG.com[/url],使用和转载请保留此信息
  3. #==============================================================================
  4.  
  5. #=================以下两个用来调整战斗时的手感问题,可以自己试试。
  6. $敌人选框扩大 = 30
  7. $角色选框扩大 = 20
  8.  
  9.  
  10. #==============================================================================
  11. # API调用
  12. #==============================================================================
  13. $ShowCursor = Win32API.new("user32", "ShowCursor", 'i', 'l')
  14. $GetCursorPos = Win32API.new("user32", "GetCursorPos", 'p', 'i')
  15. $ScreenToClient = Win32API.new("user32", "ScreenToClient", 'ip', 'i')
  16. $GetActiveWindow = Win32API.new("user32", "GetActiveWindow", nil, 'l')
  17. $Window_HWND = $GetActiveWindow.call
  18. $GetKeyState = Win32API.new("user32", "GetKeyState", 'i', 'i')
  19. #$FindWindow = Win32API.new("user32", "FindWindow", 'pp', 'i')
  20. #$HookStart  = Win32API.new("mouse_hook.dll", "HookStart", 'i', nil)
  21. #$HookEnd  = Win32API.new("mouse_hook.dll", "HookEnd", nil, nil)
  22. #$GetMouseStatus  = Win32API.new("mouse_hook.dll", "GetMouseStatus", 'i', 'i')
  23. #$Window_HWND = $FindWindow.call(nil, 'mousetry')
  24.  
  25. module Mouse  
  26.   LEFT = 0x01
  27.   RIGHT = 0x02
  28.  
  29.   def self.init(sprite = nil)
  30. #   $HookStart.call($Window_HWND)
  31.     $ShowCursor.call(0)
  32.  
  33.     @show_cursor = false
  34.  
  35.     @mouse_sprite = Sprite.new
  36.     @mouse_sprite.z = 99999
  37.     @mouse_sprite.bitmap = Bitmap.new('Graphics/System/fox_cursor')
  38.     #@mouse_sprite.bitmap.fill_rect(Rect.new(0, 0, 32, 32), Color.new(0, 0, 0))
  39.  
  40.     @left_press = false
  41.     @right_press = false
  42.     @left_trigger = false
  43.     @right_trigger = false
  44.     @left_repeat = false
  45.     @right_repeat = false
  46.     @click_lock = false
  47.  
  48.     update
  49.   end
  50.   def self.exit
  51.     @mouse_sprite.bitmap.dispose
  52.     @mouse_sprite.dispose
  53.     @show_cursor = true
  54. #    $HookEnd.call
  55.     $ShowCursor.call(1)
  56.   end
  57.   def self.mouse_debug
  58.     return @mouse_debug.bitmap
  59.   end
  60.   def self.update
  61.     left_down = $GetKeyState.call(0x01)
  62.     right_down = $GetKeyState.call(0x02)
  63.  
  64.     @click_lock = false
  65.     mouse_x, mouse_y = self.get_mouse_pos
  66.     if @mouse_sprite != nil
  67.       @mouse_sprite.x = mouse_x
  68.       @mouse_sprite.y = mouse_y
  69.     end
  70.     if left_down[7] == 1
  71.       @left_repeat = (not @left_repeat)
  72.       @left_trigger = (not @left_press)
  73.       @left_press = true
  74.     else
  75.       @left_press = false
  76.       @left_trigger = false
  77.       @left_repeat = false
  78.     end
  79.     if right_down[7] == 1
  80.       @right_repeat = (not @right_repeat)
  81.       @right_trigger = (not @right_press)
  82.       @right_press = true
  83.     else
  84.       @right_press = false
  85.       @right_trigger = false
  86.       @right_repeat = false
  87.     end
  88.   end
  89.   def self.get_mouse_pos
  90.     point_var = [0, 0].pack('ll')
  91.     if $GetCursorPos.call(point_var) != 0
  92.       if $ScreenToClient.call($Window_HWND, point_var) != 0
  93.         x, y = point_var.unpack('ll')
  94.         if (x < 0) or (x > 10000) then x = 0 end
  95.         if (y < 0) or (y > 10000) then y = 0 end
  96.         if x > Graphics.width then x = Graphics.width end
  97.         if y > Graphics.height then y = Graphics.height end
  98.         return x, y
  99.       else
  100.         return 0, 0
  101.       end
  102.     else
  103.       return 0, 0
  104.     end
  105.   end
  106.   def self.press?(mouse_code)
  107.     if mouse_code == LEFT
  108.       if @click_lock
  109.         return false
  110.       else
  111.         return @left_press
  112.       end
  113.     elsif mouse_code == RIGHT
  114.       return @right_press
  115.     else
  116.       return false
  117.     end
  118.   end
  119.   def self.trigger?(mouse_code)
  120.     if mouse_code == LEFT
  121.       if @click_lock
  122.         return false
  123.       else
  124.         return @left_trigger
  125.       end
  126.     elsif mouse_code == RIGHT
  127.       return @right_trigger
  128.     else
  129.       return false
  130.     end
  131.   end
  132.   def self.repeat?(mouse_code)
  133.     if mouse_code == LEFT
  134.       if @click_lock
  135.         return false
  136.       else
  137.         return @left_repeat
  138.       end
  139.     elsif mouse_code == RIGHT
  140.       return @right_repeat
  141.     else
  142.       return false
  143.     end
  144.   end
  145.   def self.click_lock?
  146.     return @click_lock
  147.   end
  148.   def self.click_lock
  149.     @click_lock = true
  150.   end
  151.   def self.click_unlock
  152.     @click_lock = false
  153.   end
  154. end
  155. module Input
  156.   if @self_update == nil
  157.     @self_update = method('update')
  158.     @self_press = method('press?')
  159.     @self_trigger = method('trigger?')
  160.     @self_repeat = method('repeat?')
  161.   end
  162.   def self.update
  163.     @self_update.call
  164.     Mouse.update
  165.   end
  166.   def self.press?(key_code)
  167.     if @self_press.call(key_code)
  168.       return true
  169.     end
  170.     if key_code == C
  171.       return Mouse.press?(Mouse::LEFT)
  172.     elsif key_code == B
  173.       return Mouse.press?(Mouse::RIGHT)
  174.     else
  175.       return @self_press.call(key_code)
  176.     end
  177.   end
  178.   def self.trigger?(key_code)
  179.     if @self_trigger.call(key_code)
  180.       return true
  181.     end
  182.     if key_code == C
  183.       return Mouse.trigger?(Mouse::LEFT)
  184.     elsif key_code == B
  185.       return Mouse.trigger?(Mouse::RIGHT)
  186.     else
  187.       return @self_trigger.call(key_code)
  188.     end
  189.   end
  190.   def self.repeat?(key_code)
  191.     if @self_repeat.call(key_code)
  192.       return true
  193.     end
  194.     if key_code == C
  195.       return Mouse.repeat?(Mouse::LEFT)
  196.     elsif key_code == B
  197.       return Mouse.repeat?(Mouse::RIGHT)
  198.     else
  199.       return @self_repeat.call(key_code)
  200.     end
  201.   end
  202. end
  203.  
  204. class Window_Selectable
  205.   if @self_alias == nil
  206.     alias self_update update
  207.     @self_alias = true
  208.   end
  209.   def update
  210.     #self.cursor_rect.empty
  211.     self_update
  212.     if self.active and item_max > 0
  213.       index_var = @index
  214.       tp_index = @index
  215.       mouse_x, mouse_y = Mouse.get_mouse_pos
  216.       mouse_not_in_rect = true
  217.       for i in 0...item_max
  218.         @index = i
  219.         update_cursor
  220.         top_x = self.cursor_rect.x + self.x + 16
  221.         top_y = self.cursor_rect.y + self.y + 16
  222.         bottom_x = top_x + self.cursor_rect.width
  223.         bottom_y = top_y + self.cursor_rect.height
  224.  
  225.           top_x += self.x_mod
  226.           top_y += self.y_mod
  227.           bottom_x += self.x_mod
  228.           bottom_y += self.y_mod
  229.  
  230.         if (mouse_x > top_x) and (mouse_y > top_y) and
  231.            (mouse_x < bottom_x) and (mouse_y < bottom_y)
  232.           mouse_not_in_rect = false
  233.           if tp_index != @index
  234.             tp_index = @index
  235.             $data_system.sounds[0].play
  236.           end
  237.           break
  238.         end
  239.       end
  240.     if Input.trigger?(Input::F9)
  241.     p top_x,top_y,Mouse.get_mouse_pos
  242.     end
  243.       if mouse_not_in_rect
  244.         @index = index_var
  245.         update_cursor
  246.         Mouse.click_lock
  247.       else
  248.         Mouse.click_unlock               
  249.       end
  250.     end
  251.   end
  252. end
  253.  
  254.  
  255.  
  256.  
  257. class Window_NameInput
  258.   if @self_alias == nil
  259.     alias self_update update
  260.     @self_alias = true
  261.   end
  262.   def update
  263.     #self.cursor_rect.empty
  264.     self_update
  265.     if self.active
  266.       index_var = @index
  267.       mouse_x, mouse_y = Mouse.get_mouse_pos
  268.       mouse_not_in_rect = true
  269.       for i in (0...HIRAGANA.size).to_a.push(180)
  270.         @index = i
  271.         update_cursor
  272.         top_x = self.cursor_rect.x + self.x + 16
  273.         top_y = self.cursor_rect.y + self.y + 16
  274.         bottom_x = top_x + self.cursor_rect.width
  275.         bottom_y = top_y + self.cursor_rect.height
  276.         #
  277.         if (mouse_x > top_x) and (mouse_y > top_y) and
  278.            (mouse_x < bottom_x) and (mouse_y < bottom_y)
  279.           mouse_not_in_rect = false
  280.           break
  281.         end
  282.       end
  283.       if mouse_not_in_rect
  284.         @index = index_var
  285.         update_cursor
  286.         Mouse.click_lock
  287.       else
  288.         Mouse.click_unlock
  289.       end
  290.     end
  291.   end
  292. end
  293. =begin
  294.  
  295. class Window_InputNumber
  296.   if @self_alias == nil
  297.     alias self_update update
  298.     @self_alias = true
  299.   end
  300.   def update
  301.     #self.cursor_rect.empty
  302.     self_update
  303.     mouse_x, mouse_y = Mouse.get_mouse_pos
  304.     if self.active and @digits_max > 0
  305.       index_var = @index
  306.       mouse_not_in_rect = true
  307.       for i in 0...@digits_max
  308.         @index = i
  309.         #update_cursor
  310.         top_x = self.cursor_rect.x + self.x + 16
  311.         bottom_x = top_x + self.cursor_rect.width
  312.         #
  313.         if (mouse_x > top_x) and (mouse_x < bottom_x)
  314.           mouse_not_in_rect = false
  315.           break
  316.         end
  317.       end
  318.       if mouse_not_in_rect
  319.         @index = index_var
  320.         #update_cursor
  321.         Mouse.click_lock
  322.       else
  323.         Mouse.click_unlock
  324.       end
  325.     end
  326.     if @last_mouse_y == nil
  327.       @last_mouse_y = mouse_y
  328.     end
  329.     check_pos = (@last_mouse_y - mouse_y).abs
  330.     if check_pos > 10
  331.       #$game_system.se_play($data_system.cursor_se)
  332.       place = 10 ** (@digits_max - 1 - @index)
  333.       n = @number / place % 10
  334.       @number -= n * place
  335.       n = (n + 1) % 10 if mouse_y < @last_mouse_y
  336.       n = (n + 9) % 10 if mouse_y > @last_mouse_y
  337.       @number += n * place
  338.       refresh
  339.       @last_mouse_y = mouse_y
  340.     end
  341.   end
  342. end
  343. =end
  344.  
  345. class Scene_File
  346.   if @self_alias == nil
  347.     alias self_update update
  348.     @self_alias = true
  349.   end
  350.   def update
  351.     mouse_x, mouse_y = Mouse.get_mouse_pos
  352.     Mouse.click_lock
  353.     idx = 0
  354.     for i in @savefile_windows
  355.       top_x = i.x + 16
  356.       top_y = i.y + 16
  357.       bottom_x = top_x + i.width
  358.       bottom_y = top_y + i.height
  359.       if (mouse_x > top_x) and (mouse_y > top_y) and
  360.          (mouse_x < bottom_x) and (mouse_y < bottom_y)
  361.         i.selected = true
  362.         if @file_index != idx
  363.           @file_index = idx
  364.           $data_system.sounds[0].play
  365.         end            
  366.         Mouse.click_unlock
  367.       else
  368.         i.selected = false
  369.       end
  370.       idx += 1
  371.     end
  372.     self_update
  373.   end
  374. end
  375.  
  376. class Game_Player
  377.   if @self_alias == nil
  378.     alias self_update update
  379.     @self_alias = true
  380.   end
  381.   def update
  382.     mouse_x, mouse_y = Mouse.get_mouse_pos
  383.     if @last_move_x == nil
  384.       @last_move_x = false
  385.     end
  386.     if Mouse.press?(Mouse::LEFT)
  387.    #for event in $game_map.events.values
  388.    #if event.screen_x/32 == mouse_x/32 and event.screen_y/32-1 == mouse_y/32
  389.    #event.start
  390.    #end
  391.    #end
  392.       last_moving = moving?
  393.       last_direction = @direction
  394.     #  return unless movable?
  395.     #  return if $game_map.interpreter.running?
  396.       unless moving? or $game_map.interpreter.running?
  397.       last_x = @x
  398.         if @last_move_x
  399.           @last_move_x = false
  400.         elsif mouse_x > screen_x + 16
  401.           move_straight(6)
  402.         elsif mouse_x < screen_x - 16
  403.           move_straight(4)
  404.         end
  405.         last_y = @y
  406.         if last_x != @x
  407.           @last_move_x = true
  408.         elsif mouse_y > screen_y
  409.           move_straight(2)
  410.         elsif mouse_y < screen_y - 32
  411.           move_straight(8)
  412.         end
  413. =begin        
  414.         if last_y != @y
  415.           @last_move_x = false
  416.         elsif not @last_move_x
  417.           case last_direction
  418.           when 2
  419.             turn_down
  420.           when 4
  421.             turn_left
  422.           when 6
  423.             turn_right
  424.           when 8
  425.             turn_up
  426.           end        
  427.         end
  428. =end         
  429.       end
  430.     end
  431.     self_update
  432.   end
  433. end
  434.  
  435. Mouse.init
  436. END { Mouse.exit }
  437.  
  438.  
  439. class Window_Base < Window
  440.   attr_accessor :x_mod
  441.   attr_accessor :y_mod
  442.   alias ka_initialize initialize
  443.   def initialize(x, y, width, height)
  444.     ka_initialize(x, y, width, height)
  445.     self.x_mod = 0
  446.     self.y_mod = 0
  447.   end
  448. end
  449. class Window_PartyCommand < Window_Command
  450.  
  451.   alias ka1_initialize initialize
  452.   def initialize
  453.     ka1_initialize
  454.     self.y_mod = Graphics.height-128
  455.   end
  456.  
  457. end
  458. class Window_ActorCommand < Window_Command
  459.  
  460.   alias ka2_initialize initialize
  461.   def initialize
  462.     ka2_initialize
  463.     self.x_mod = -128
  464.     self.y_mod = Graphics.height-128
  465.   end
  466.  
  467. end
  468.  
  469. #==============================================================================
  470. # 本脚本来自[url]www.66RPG.com[/url],使用和转载请保留此信息
  471. #==============================================================================

beauty_w@8#4(.png (309.28 KB, 下载次数: 14)

beauty_w@8#4(.png
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

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

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

GMT+8, 2024-4-28 09:03

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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