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

Project1

 找回密码
 注册会员
搜索
查看: 3791|回复: 5

[原创发布] 两款战棋系统的鼠标操纵

[复制链接]

Lv2.观梦者

梦石
0
星屑
382
在线时间
235 小时
注册时间
2009-2-13
帖子
470
发表于 2012-1-18 19:55:30 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 风中承诺 于 2012-1-18 21:02 编辑

刚刚发现自己电脑里有好多战棋范例,都是当年为了制作武林群侠传找来的,其中只有冷血给我那个支持鼠标,刚才又给两个添加了鼠标判定,其实方法很简单。
比如随便的鼠标脚本,末尾几行是控制行走的,条件分歧是按下左键,只要删掉或改成开关就好。
闲话不说。

不过我自己还是认为用半事件半脚本制作武林更好,比如柳大当年的仙剑同人战棋,拓展功能较为强大。

115: http://115.com/file/be436gav#
战棋系统.rar

o
  1. #===========================================================
  2. #===================
  3. # 本脚本来自http://rpg.blue/web/,使用和转载请保留此信息
  4. #==============================================================================

  5. #=================以下两个用来调整战斗时的手感问题,可以自己试试。
  6. $敌人选框扩大 = 20
  7. $角色选框扩大 = 30


  8. #==============================================================================
  9. # API调用
  10. #==============================================================================
  11. $ShowCursor = Win32API.new("user32", "ShowCursor", 'i', 'l')
  12. $GetCursorPos = Win32API.new("user32", "GetCursorPos", 'p', 'i')
  13. $ScreenToClient = Win32API.new("user32", "ScreenToClient", 'ip', 'i')
  14. $GetActiveWindow = Win32API.new("user32", "GetActiveWindow", nil, 'l')
  15. $Window_HWND = $GetActiveWindow.call
  16. $GetKeyState = Win32API.new("user32", "GetKeyState", 'i', 'i')
  17. #$FindWindow = Win32API.new("user32", "FindWindow", 'pp', 'i')#
  18. #$HookStart  = Win32API.new("mouse_hook.dll", "HookStart", 'i', nil)#
  19. #$HookEnd  = Win32API.new("mouse_hook.dll", "HookEnd", nil, nil)#
  20. #$GetMouseStatus  = Win32API.new("mouse_hook.dll", "GetMouseStatus", 'i', 'i')#
  21. #$Window_HWND = $FindWindow.call(nil, 'mousetry')#

  22. module Mouse  
  23.   LEFT = 0x01
  24.   RIGHT = 0x02

  25.   def self.init(sprite = nil)
  26.    #$HookStart.call($Window_HWND)#
  27.     $ShowCursor.call(0)
  28.    
  29.     @show_cursor = false
  30.    
  31.     @mouse_sprite = Sprite.new
  32.     @mouse_sprite.z = 99999
  33.     @mouse_sprite.bitmap = Bitmap.new("Graphics/Icons/002-Weapon02")
  34.     @mouse_sprite2 = Sprite.new
  35.     @mouse_sprite2.z = @mouse_sprite.z - 1
  36.     #@mouse_sprite.bitmap.fill_rect(Rect.new(0, 0, 32, 32), Color.new(0, 0, 0))
  37.     @left_press = false
  38.     @right_press = false
  39.     @left_trigger = false
  40.     @right_trigger = false
  41.     @left_repeat = false
  42.     @right_repeat = false
  43.     @click_lock = false
  44.    
  45.     update
  46.   end
  47. #-----------------------------------------------#----------------------------------------
  48.   def self.exit
  49.     @mouse_sprite.bitmap.dispose
  50.     @mouse_sprite.dispose
  51.     @show_cursor = true
  52.    # $HookEnd.call#
  53.     $ShowCursor.call(1)
  54.   end
  55.   def self.mouse_debug
  56.     return @mouse_debug.bitmap
  57.   end
  58.   def self.update
  59.     left_down = $GetKeyState.call(0x01)
  60.     right_down = $GetKeyState.call(0x02)
  61.     if $build == true
  62.       $cursor_pic = Bitmap.new("Graphics/Icons/002-Weapon01")
  63.       @mouse_sprite2.bitmap=Bitmap.new("Graphics/Icons/002-Weapon01")
  64.       @mouse_sprite2.ox=$cursor_pic.width-32
  65.       @mouse_sprite2.oy=$cursor_pic.height-32
  66.     else
  67.       @mouse_sprite2.bitmap=Bitmap.new(32,32)
  68.     end
  69.     @click_lock = false
  70.     mouse_x, mouse_y = self.get_mouse_pos
  71.     @mouse_sprite.x = mouse_x
  72.     @mouse_sprite.y = mouse_y
  73.     @mouse_sprite2.x = (mouse_x/32)*32
  74.     @mouse_sprite2.y = (mouse_y/32)*32
  75.     if $build  == false
  76.     @mouse_sprite2.opacity=255
  77.     else
  78.     @mouse_sprite2.opacity=160
  79.     end
  80.     if left_down[7] == 1
  81.       @left_repeat = (not @left_repeat)
  82.       @left_trigger = (not @left_press)
  83.       @left_press = true
  84.     else
  85.       @left_press = false
  86.       @left_trigger = false
  87.       @left_repeat = false
  88.     end
  89.     if right_down[7] == 1
  90.       @right_repeat = (not @right_repeat)
  91.       @right_trigger = (not @right_press)
  92.       @right_press = true
  93.     else
  94.       @right_press = false
  95.       @right_trigger = false
  96.       @right_repeat = false
  97.     end
  98.   end
  99.   def self.get_mouse_pos
  100.     point_var = [0, 0].pack('ll')
  101.     if $GetCursorPos.call(point_var) != 0
  102.       if $ScreenToClient.call($Window_HWND, point_var) != 0
  103.         x, y = point_var.unpack('ll')
  104.         if (x < 0) or (x > 10000) then x = 0 end
  105.         if (y < 0) or (y > 10000) then y = 0 end
  106.         if x > 640 then x = 640 end
  107.         if y > 480 then y = 480 end
  108.         return x, y
  109.       else
  110.         return 0, 0
  111.       end
  112.     else
  113.       return 0, 0
  114.     end
  115.   end
  116.   def self.press?(mouse_code)
  117.     if mouse_code == LEFT
  118.       if @click_lock
  119.         return false
  120.       else
  121.         return @left_press
  122.       end
  123.     elsif mouse_code == RIGHT
  124.       return @right_press
  125.     else
  126.       return false
  127.     end
  128.   end
  129.   def self.trigger?(mouse_code)
  130.     if mouse_code == LEFT
  131.       if @click_lock
  132.         return false
  133.       else
  134.         return @left_trigger
  135.       end
  136.     elsif mouse_code == RIGHT
  137.       return @right_trigger
  138.     else
  139.       return false
  140.     end
  141.   end
  142.   def self.repeat?(mouse_code)
  143.     if mouse_code == LEFT
  144.       if @click_lock
  145.         return false
  146.       else
  147.         return @left_repeat
  148.       end
  149.     elsif mouse_code == RIGHT
  150.       return @right_repeat
  151.     else
  152.       return false
  153.     end
  154.   end
  155.   def self.click_lock?
  156.     return @click_lock
  157.   end
  158.   def self.click_lock
  159.     @click_lock = true
  160.   end
  161.   def self.click_unlock
  162.     @click_lock = false
  163.   end
  164. end
  165. module Input
  166.   if @self_update == nil
  167.     @self_update = method('update')
  168.     @self_press = method('press?')
  169.     @self_trigger = method('trigger?')
  170.     @self_repeat = method('repeat?')
  171.   end
  172.   def self.update
  173.     @self_update.call
  174.     Mouse.update
  175.   end
  176.   def self.press?(key_code)
  177.     if @self_press.call(key_code)
  178.       return true
  179.     end
  180.     if key_code == C
  181.       return Mouse.press?(Mouse::LEFT)
  182.     elsif key_code == B
  183.       return Mouse.press?(Mouse::RIGHT)
  184.     else
  185.       return @self_press.call(key_code)
  186.     end
  187.   end
  188.   def self.trigger?(key_code)
  189.     if @self_trigger.call(key_code)
  190.       return true
  191.     end
  192.     if key_code == C
  193.       return Mouse.trigger?(Mouse::LEFT)
  194.     elsif key_code == B
  195.       return Mouse.trigger?(Mouse::RIGHT)
  196.     else
  197.       return @self_trigger.call(key_code)
  198.     end
  199.   end
  200.   def self.repeat?(key_code)
  201.     if @self_repeat.call(key_code)
  202.       return true
  203.     end
  204.     if key_code == C
  205.       return Mouse.repeat?(Mouse::LEFT)
  206.     elsif key_code == B
  207.       return Mouse.repeat?(Mouse::RIGHT)
  208.     else
  209.       return @self_repeat.call(key_code)
  210.     end
  211.   end
  212. end
  213. class Window_Selectable
  214.   if @self_alias == nil
  215.     alias self_update update
  216.     @self_alias = true
  217.   end
  218.   def update
  219.     #self.cursor_rect.empty
  220.     self_update
  221.     if self.active and @item_max > 0
  222.       index_var = @index
  223.       tp_index = @index
  224.       mouse_x, mouse_y = Mouse.get_mouse_pos
  225.       mouse_not_in_rect = true
  226.       for i in 0...@item_max
  227.         @index = i
  228.         update_cursor_rect
  229.         top_x = self.cursor_rect.x + self.x + 16
  230.         top_y = self.cursor_rect.y + self.y + 16
  231.         bottom_x = top_x + self.cursor_rect.width
  232.         bottom_y = top_y + self.cursor_rect.height
  233.         if (mouse_x > top_x) and (mouse_y > top_y) and
  234.            (mouse_x < bottom_x) and (mouse_y < bottom_y)
  235.           mouse_not_in_rect = false
  236.           if tp_index != @index
  237.             tp_index = @index
  238.             $game_system.se_play($data_system.cursor_se)
  239.           end
  240.           break
  241.         end
  242.       end
  243.       if mouse_not_in_rect
  244.         @index = index_var
  245.         update_cursor_rect
  246.         Mouse.click_lock
  247.       else
  248.         Mouse.click_unlock               
  249.       end
  250.     end
  251.   end
  252. end
  253. class Window_NameInput
  254.   if @self_alias == nil
  255.     alias self_update update
  256.     @self_alias = true
  257.   end
  258.   def update
  259.     #self.cursor_rect.empty
  260.     self_update
  261.     if self.active
  262.       index_var = @index
  263.       mouse_x, mouse_y = Mouse.get_mouse_pos
  264.       mouse_not_in_rect = true
  265.       for i in (0...CHARACTER_TABLE.size).to_a.push(180)
  266.         @index = i
  267.         update_cursor_rect
  268.         top_x = self.cursor_rect.x + self.x + 16
  269.         top_y = self.cursor_rect.y + self.y + 16
  270.         bottom_x = top_x + self.cursor_rect.width
  271.         bottom_y = top_y + self.cursor_rect.height
  272.         #
  273.         if (mouse_x > top_x) and (mouse_y > top_y) and
  274.            (mouse_x < bottom_x) and (mouse_y < bottom_y)
  275.           mouse_not_in_rect = false
  276.           break
  277.         end
  278.       end
  279.       if mouse_not_in_rect
  280.         @index = index_var
  281.         update_cursor_rect
  282.         Mouse.click_lock
  283.       else
  284.         Mouse.click_unlock
  285.       end
  286.     end
  287.   end
  288. end
  289. class Window_InputNumber
  290.   if @self_alias == nil
  291.     alias self_update update
  292.     @self_alias = true
  293.   end
  294.   def update
  295.     #self.cursor_rect.empty
  296.     self_update
  297.     mouse_x, mouse_y = Mouse.get_mouse_pos
  298.     if self.active and @digits_max > 0
  299.       index_var = @index
  300.       mouse_not_in_rect = true
  301.       for i in 0...@digits_max
  302.         @index = i
  303.         update_cursor_rect
  304.         top_x = self.cursor_rect.x + self.x + 16
  305.         bottom_x = top_x + self.cursor_rect.width
  306.         #
  307.         if (mouse_x > top_x) and (mouse_x < bottom_x)
  308.           mouse_not_in_rect = false
  309.           break
  310.         end
  311.       end
  312.       if mouse_not_in_rect
  313.         @index = index_var
  314.         update_cursor_rect
  315.         Mouse.click_lock
  316.       else
  317.         Mouse.click_unlock
  318.       end
  319.     end
  320.     if @last_mouse_y == nil
  321.       @last_mouse_y = mouse_y
  322.     end
  323.     check_pos = (@last_mouse_y - mouse_y).abs
  324.     if check_pos > 10
  325.       $game_system.se_play($data_system.cursor_se)
  326.       place = 10 ** (@digits_max - 1 - @index)
  327.       n = @number / place % 10
  328.       @number -= n * place
  329.       n = (n + 1) % 10 if mouse_y < @last_mouse_y
  330.       n = (n + 9) % 10 if mouse_y > @last_mouse_y
  331.       @number += n * place
  332.       refresh
  333.       @last_mouse_y = mouse_y
  334.     end
  335.   end
  336. end
  337. class Scene_File
  338.   if @self_alias == nil
  339.     alias self_update update
  340.     @self_alias = true
  341.   end
  342.   def update
  343.     mouse_x, mouse_y = Mouse.get_mouse_pos
  344.     Mouse.click_lock
  345.     idx = 0
  346.     for i in @savefile_windows
  347.       top_x = i.x + 16
  348.       top_y = i.y + 16
  349.       bottom_x = top_x + i.width
  350.       bottom_y = top_y + i.height
  351.       if (mouse_x > top_x) and (mouse_y > top_y) and
  352.          (mouse_x < bottom_x) and (mouse_y < bottom_y)
  353.         i.selected = true
  354.         if @file_index != idx
  355.           @file_index = idx
  356.           $game_system.se_play($data_system.cursor_se)
  357.         end            
  358.         Mouse.click_unlock
  359.       else
  360.         i.selected = false
  361.       end
  362.       idx += 1
  363.     end
  364.     self_update
  365.   end
  366. end
  367. class Arrow_Enemy
  368.   if @self_alias == nil
  369.     alias self_update update
  370.     @self_alias = true
  371.   end
  372.   def update
  373.     mouse_x, mouse_y = Mouse.get_mouse_pos
  374.     idx = 0
  375.     for i in $game_troop.enemies do
  376.       if i.exist?
  377.         top_x = i.screen_x - self.ox
  378.         top_y = i.screen_y - self.oy
  379.         bottom_x = top_x + self.src_rect.width
  380.         bottom_y = top_y + self.src_rect.height
  381.         if (mouse_x > top_x - $敌人选框扩大) and (mouse_y > top_y - $敌人选框扩大) and
  382.            (mouse_x < bottom_x + $敌人选框扩大) and (mouse_y < bottom_y + $敌人选框扩大)
  383.           if @index != idx
  384.             $game_system.se_play($data_system.cursor_se)
  385.             @index = idx
  386.           end
  387.         end
  388.       end
  389.       idx += 1
  390.     end
  391.     self_update
  392.   end
  393. end
  394. class Arrow_Actor
  395.   if @self_alias == nil
  396.     alias self_update update
  397.     @self_alias = true
  398.   end
  399.   def update
  400.     mouse_x, mouse_y = Mouse.get_mouse_pos
  401.     idx = 0
  402.     for i in $game_party.actors do
  403.       if i.exist?
  404.         top_x = i.screen_x - self.ox
  405.         top_y = i.screen_y - self.oy
  406.         bottom_x = top_x + self.src_rect.width
  407.         bottom_y = top_y + self.src_rect.height
  408.         if (mouse_x > top_x - $角色选框扩大) and (mouse_y > top_y - $角色选框扩大) and
  409.            (mouse_x < bottom_x + $角色选框扩大) and (mouse_y < bottom_y + $角色选框扩大)
  410.           if @index != idx
  411.             $game_system.se_play($data_system.cursor_se)
  412.             @index = idx
  413.           end
  414.         end
  415.       end
  416.       idx += 1
  417.     end
  418.     self_update
  419.   end
  420. end
  421. class Game_Player
  422.   if @self_alias == nil
  423.     alias self_update update
  424.     @self_alias = true
  425.   end
  426.   def update
  427.     mouse_x, mouse_y = Mouse.get_mouse_pos

  428.     if @last_move_x == nil
  429.       @last_move_x = false
  430.     end
  431.    
  432.      
  433.      #if Mouse.trigger?(Mouse::RIGHT)
  434.       
  435.      self_update


  436.     if Mouse.press?(Mouse::LEFT) or  $game_switches[4] == true
  437.      last_moving = moving?
  438.       last_direction = @direction
  439.      unless moving? or $game_system.map_interpreter.running? or
  440.              @move_route_forcing or $game_temp.message_window_showing
  441.         last_x = @x
  442.         if @last_move_x
  443.           @last_move_x = false
  444.        elsif mouse_x > screen_x + 16
  445.           move_right
  446.           @wait_count = 10
  447.         elsif mouse_x < screen_x - 16
  448.           move_left
  449.           @wait_count = 10
  450.         end
  451.         last_y = @y
  452.       if last_x != @x
  453.           @last_move_x = true
  454.        elsif mouse_y > screen_y
  455.    move_down
  456.    @wait_count = 10
  457.         elsif mouse_y < screen_y - 32
  458.           move_up
  459.           @wait_count = 10
  460.         end
  461.         if last_y != @y
  462.           @last_move_x = false
  463.         elsif not @last_move_x
  464.           case last_direction
  465.           when 2
  466.             turn_down
  467.           when 4
  468.             turn_left
  469.           when 6
  470.             turn_right
  471.           when 8
  472.             turn_up
  473.           end
  474.         end
  475.       end
  476.     end
  477.     self_update
  478.   end
  479. end

  480. Mouse.init
  481. END { Mouse.exit }




  482. #==============================================================================
  483. # 本脚本来自http://rpg.blue/web/,使用和转载请保留此信息
  484. #==============================================================================
  485. #==============================================================================
  486. # 本脚本来自www.66RPG.com,使用和转载请保留此信息
  487. #==============================================================================
  488. #格式:显示的cmd图片的命名格式为:
  489. #    cmd调用公共事件编号_名字
  490. #    cmd调用公共事件编号_名字_02 # 此为鼠标经过的图片
  491. #
  492. #即,带有cmd的为可以点击的图片,点击后执行相应的公共事件.....
  493. #不带cmd的图片没任何影响。。。
  494. #==============================================================================
  495. class Game_Picture

  496. def name=(str)
  497.    @name = str
  498. end

  499. end

  500. class Sprite_Picture

  501. alias update_old update
  502. def update
  503.    update_old
  504.    return if @picture_name == "" or @picture_name[/cmd/].nil?
  505.    mx,my = Mouse.get_mouse_pos
  506.    lx = self.x - self.ox
  507.    rx = lx + self.bitmap.width
  508.    ty = self.y - self.oy
  509.    by = ty + self.bitmap.height
  510.    if mx < lx or mx > rx or my < ty or my > by or
  511.      self.bitmap.get_pixel(mx-lx,my-ty).alpha == 0
  512.      @picture.name = @picture.name.split(/_/)[0]+"_"[email protected](/_/)[1]
  513.      return
  514.    end
  515.    if @picture.name.split(/_/)[2].nil?
  516. #    Audio.se_play("Audio/SE/sound00.wav")
  517.      @picture.name = @picture.name + "_2"
  518.    end
  519.    if Input.trigger?(13)
  520.      @picture.name.split(/_/)[0].sub(/cmd([0-9]+)/,"")
  521.      $game_temp.common_event_id = $1.to_i
  522.    end
  523. end

  524. end

  525. #==============================================================================
  526. # 本脚本来自www.66RPG.com,使用和转载请保留此信息
  527. #==============================================================================


  528. #==============================================================================
  529. # 本脚本来自http://rpg.blue/web/,使用和转载请保留此信息
  530. #==============================================================================
复制代码
0.jpg

未命名.jpg

评分

参与人数 1星屑 +2 收起 理由
无双sxa + 2 塞糖

查看全部评分

那些人,那些事,等到明白了,也就无所谓了。
我博客:http://blog.sina.com.cn/gy963

Lv1.梦旅人

AFKの

梦石
0
星屑
48
在线时间
762 小时
注册时间
2011-10-1
帖子
1248

贵宾

发表于 2012-1-18 20:01:26 | 显示全部楼层
可惜是xp……
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
382
在线时间
235 小时
注册时间
2009-2-13
帖子
470
 楼主| 发表于 2012-1-18 20:20:19 | 显示全部楼层
梦回碧落 发表于 2012-1-18 20:01
可惜是xp……

都一样的,我只是来提供思路,让角色跟随鼠标移动。你可以试着改改
那些人,那些事,等到明白了,也就无所谓了。
我博客:http://blog.sina.com.cn/gy963
回复 支持 反对

使用道具 举报

Lv1.梦旅人

龙神

梦石
0
星屑
47
在线时间
512 小时
注册时间
2011-1-19
帖子
984
发表于 2012-1-18 20:51:12 | 显示全部楼层
我还以为是我崩了传不了附件,原来是6R崩了。。
LZ的脚本水平真高超,那么长,鼠标加战棋,辛苦辛苦


神的穿越 THRU OF GOD  完成度1%
脚本2%  行走图10%  剧情1%
复仇の怪物    完成度7%
脚本10%  行走图10%  剧情5%
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
382
在线时间
235 小时
注册时间
2009-2-13
帖子
470
 楼主| 发表于 2012-1-18 20:56:54 | 显示全部楼层
BS包仔 发表于 2012-1-18 20:51
我还以为是我崩了传不了附件,原来是6R崩了。。
LZ的脚本水平真高超,那么长,鼠标加战棋,辛苦辛苦 ...

……实在惭愧啊,我只是在最后的几句添加了一个开关,不过有的时候一些东西的确很容易,只不过我暂时无法上传工程。


新找到了网盘地址,大家可以去下载:
http://fengzhong123.ys168.com



──风中承诺于2012-1-18 21:11补充以上内容
那些人,那些事,等到明白了,也就无所谓了。
我博客:http://blog.sina.com.cn/gy963
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
60
在线时间
46 小时
注册时间
2011-2-28
帖子
5
发表于 2012-1-22 15:36:58 | 显示全部楼层
楼主辛苦了……
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-3-29 22:30

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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