じ☆ve冰风 发表于 2024-4-19 20:38:59

两款战棋系统的鼠标操纵

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

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

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

o#===========================================================#===================# 本脚本来自http://rpg.blue/web/,使用和转载请保留此信息#============================================================================== #=================以下两个用来调整战斗时的手感问题,可以自己试试。$敌人选框扩大 = 20$角色选框扩大 = 30#==============================================================================# API调用#==============================================================================$ShowCursor = Win32API.new("user32", "ShowCursor", 'i', 'l')$GetCursorPos = Win32API.new("user32", "GetCursorPos", 'p', 'i')$ScreenToClient = Win32API.new("user32", "ScreenToClient", 'ip', 'i')$GetActiveWindow = Win32API.new("user32", "GetActiveWindow", nil, 'l')$Window_HWND = $GetActiveWindow.call$GetKeyState = Win32API.new("user32", "GetKeyState", 'i', 'i')#$FindWindow = Win32API.new("user32", "FindWindow", 'pp', 'i')##$HookStart= Win32API.new("mouse_hook.dll", "HookStart", 'i', nil)##$HookEnd= Win32API.new("mouse_hook.dll", "HookEnd", nil, nil)##$GetMouseStatus= Win32API.new("mouse_hook.dll", "GetMouseStatus", 'i', 'i')##$Window_HWND = $FindWindow.call(nil, 'mousetry')#module Mouse    LEFT = 0x01RIGHT = 0x02def self.init(sprite = nil)   #$HookStart.call($Window_HWND)#    $ShowCursor.call(0)      @show_cursor = false      @mouse_sprite = Sprite.new    @mouse_sprite.z = 99999    @mouse_sprite.bitmap = Bitmap.new("Graphics/Icons/002-Weapon02")    @mouse_sprite2 = Sprite.new    @mouse_sprite2.z = @mouse_sprite.z - 1    #@mouse_sprite.bitmap.fill_rect(Rect.new(0, 0, 32, 32), Color.new(0, 0, 0))    @left_press = false    @right_press = false    @left_trigger = false    @right_trigger = false    @left_repeat = false    @right_repeat = false    @click_lock = false      updateend#-----------------------------------------------#----------------------------------------def self.exit    @mouse_sprite.bitmap.dispose    @mouse_sprite.dispose    @show_cursor = true   # $HookEnd.call#    $ShowCursor.call(1)enddef self.mouse_debug    return @mouse_debug.bitmapenddef self.update    left_down = $GetKeyState.call(0x01)    right_down = $GetKeyState.call(0x02)    if $build == true      $cursor_pic = Bitmap.new("Graphics/Icons/002-Weapon01")      @mouse_sprite2.bitmap=Bitmap.new("Graphics/Icons/002-Weapon01")      @mouse_sprite2.ox=$cursor_pic.width-32      @mouse_sprite2.oy=$cursor_pic.height-32    else      @mouse_sprite2.bitmap=Bitmap.new(32,32)    end    @click_lock = false    mouse_x, mouse_y = self.get_mouse_pos    @mouse_sprite.x = mouse_x    @mouse_sprite.y = mouse_y    @mouse_sprite2.x = (mouse_x/32)*32    @mouse_sprite2.y = (mouse_y/32)*32    if $build== false    @mouse_sprite2.opacity=255    else    @mouse_sprite2.opacity=160    end    if left_down == 1      @left_repeat = (not @left_repeat)      @left_trigger = (not @left_press)      @left_press = true    else      @left_press = false      @left_trigger = false      @left_repeat = false    end    if right_down == 1      @right_repeat = (not @right_repeat)      @right_trigger = (not @right_press)      @right_press = true    else      @right_press = false      @right_trigger = false      @right_repeat = false    endenddef self.get_mouse_pos    point_var = .pack('ll')    if $GetCursorPos.call(point_var) != 0      if $ScreenToClient.call($Window_HWND, point_var) != 0      x, y = point_var.unpack('ll')      if (x < 0) or (x > 10000) then x = 0 end      if (y < 0) or (y > 10000) then y = 0 end      if x > 640 then x = 640 end      if y > 480 then y = 480 end      return x, y      else      return 0, 0      end    else      return 0, 0    endenddef self.press?(mouse_code)    if mouse_code == LEFT      if @click_lock      return false      else      return @left_press      end    elsif mouse_code == RIGHT      return @right_press    else      return false    endenddef self.trigger?(mouse_code)    if mouse_code == LEFT      if @click_lock      return false      else      return @left_trigger      end    elsif mouse_code == RIGHT      return @right_trigger    else      return false    endenddef self.repeat?(mouse_code)    if mouse_code == LEFT      if @click_lock      return false      else      return @left_repeat      end    elsif mouse_code == RIGHT      return @right_repeat    else      return false    endenddef self.click_lock?    return @click_lockenddef self.click_lock    @click_lock = trueenddef self.click_unlock    @click_lock = falseendendmodule Inputif @self_update == nil    @self_update = method('update')    @self_press = method('press?')    @self_trigger = method('trigger?')    @self_repeat = method('repeat?')enddef self.update    @self_update.call    Mouse.updateenddef self.press?(key_code)    if @self_press.call(key_code)      return true    end    if key_code == C      return Mouse.press?(Mouse::LEFT)    elsif key_code == B      return Mouse.press?(Mouse::RIGHT)    else      return @self_press.call(key_code)    endenddef self.trigger?(key_code)    if @self_trigger.call(key_code)      return true    end    if key_code == C      return Mouse.trigger?(Mouse::LEFT)    elsif key_code == B      return Mouse.trigger?(Mouse::RIGHT)    else      return @self_trigger.call(key_code)    endenddef self.repeat?(key_code)    if @self_repeat.call(key_code)      return true    end    if key_code == C      return Mouse.repeat?(Mouse::LEFT)    elsif key_code == B      return Mouse.repeat?(Mouse::RIGHT)    else      return @self_repeat.call(key_code)    endendendclass Window_Selectableif @self_alias == nil    alias self_update update    @self_alias = trueenddef update    #self.cursor_rect.empty    self_update    if self.active and @item_max > 0      index_var = @index      tp_index = @index      mouse_x, mouse_y = Mouse.get_mouse_pos      mouse_not_in_rect = true      for i in 0...@item_max      @index = i      update_cursor_rect      top_x = self.cursor_rect.x + self.x + 16      top_y = self.cursor_rect.y + self.y + 16      bottom_x = top_x + self.cursor_rect.width      bottom_y = top_y + self.cursor_rect.height      if (mouse_x > top_x) and (mouse_y > top_y) and         (mouse_x < bottom_x) and (mouse_y < bottom_y)          mouse_not_in_rect = false          if tp_index != @index            tp_index = @index            $game_system.se_play($data_system.cursor_se)          end          break      end      end      if mouse_not_in_rect      @index = index_var      update_cursor_rect      Mouse.click_lock      else      Mouse.click_unlock                      end    endendendclass Window_NameInputif @self_alias == nil    alias self_update update    @self_alias = trueenddef update    #self.cursor_rect.empty    self_update    if self.active      index_var = @index      mouse_x, mouse_y = Mouse.get_mouse_pos      mouse_not_in_rect = true      for i in (0...CHARACTER_TABLE.size).to_a.push(180)      @index = i      update_cursor_rect      top_x = self.cursor_rect.x + self.x + 16      top_y = self.cursor_rect.y + self.y + 16      bottom_x = top_x + self.cursor_rect.width      bottom_y = top_y + self.cursor_rect.height      #      if (mouse_x > top_x) and (mouse_y > top_y) and         (mouse_x < bottom_x) and (mouse_y < bottom_y)          mouse_not_in_rect = false          break      end      end      if mouse_not_in_rect      @index = index_var      update_cursor_rect      Mouse.click_lock      else      Mouse.click_unlock      end    endend endclass Window_InputNumberif @self_alias == nil    alias self_update update    @self_alias = trueenddef update    #self.cursor_rect.empty    self_update    mouse_x, mouse_y = Mouse.get_mouse_pos    if self.active and @digits_max > 0      index_var = @index      mouse_not_in_rect = true      for i in 0...@digits_max      @index = i      update_cursor_rect      top_x = self.cursor_rect.x + self.x + 16      bottom_x = top_x + self.cursor_rect.width      #      if (mouse_x > top_x) and (mouse_x < bottom_x)          mouse_not_in_rect = false          break      end      end      if mouse_not_in_rect      @index = index_var      update_cursor_rect      Mouse.click_lock      else      Mouse.click_unlock      end    end    if @last_mouse_y == nil      @last_mouse_y = mouse_y    end    check_pos = (@last_mouse_y - mouse_y).abs    if check_pos > 10      $game_system.se_play($data_system.cursor_se)      place = 10 ** (@digits_max - 1 - @index)      n = @number / place % 10      @number -= n * place      n = (n + 1) % 10 if mouse_y < @last_mouse_y      n = (n + 9) % 10 if mouse_y > @last_mouse_y      @number += n * place      refresh      @last_mouse_y = mouse_y    endendendclass Scene_Fileif @self_alias == nil    alias self_update update    @self_alias = trueenddef update    mouse_x, mouse_y = Mouse.get_mouse_pos    Mouse.click_lock    idx = 0    for i in @savefile_windows      top_x = i.x + 16      top_y = i.y + 16      bottom_x = top_x + i.width      bottom_y = top_y + i.height      if (mouse_x > top_x) and (mouse_y > top_y) and         (mouse_x < bottom_x) and (mouse_y < bottom_y)      i.selected = true      if @file_index != idx         @file_index = idx          $game_system.se_play($data_system.cursor_se)      end                  Mouse.click_unlock      else      i.selected = false      end      idx += 1    end    self_updateendendclass Arrow_Enemyif @self_alias == nil    alias self_update update    @self_alias = trueenddef update    mouse_x, mouse_y = Mouse.get_mouse_pos    idx = 0    for i in $game_troop.enemies do      if i.exist?      top_x = i.screen_x - self.ox      top_y = i.screen_y - self.oy      bottom_x = top_x + self.src_rect.width      bottom_y = top_y + self.src_rect.height      if (mouse_x > top_x - $敌人选框扩大) and (mouse_y > top_y - $敌人选框扩大) and         (mouse_x < bottom_x + $敌人选框扩大) and (mouse_y < bottom_y + $敌人选框扩大)          if @index != idx            $game_system.se_play($data_system.cursor_se)            @index = idx          end      end      end      idx += 1    end    self_updateendendclass Arrow_Actorif @self_alias == nil    alias self_update update    @self_alias = trueenddef update    mouse_x, mouse_y = Mouse.get_mouse_pos    idx = 0    for i in $game_party.actors do      if i.exist?      top_x = i.screen_x - self.ox      top_y = i.screen_y - self.oy      bottom_x = top_x + self.src_rect.width      bottom_y = top_y + self.src_rect.height      if (mouse_x > top_x - $角色选框扩大) and (mouse_y > top_y - $角色选框扩大) and         (mouse_x < bottom_x + $角色选框扩大) and (mouse_y < bottom_y + $角色选框扩大)          if @index != idx            $game_system.se_play($data_system.cursor_se)            @index = idx          end      end      end      idx += 1    end    self_updateendendclass Game_Playerif @self_alias == nil    alias self_update update    @self_alias = trueenddef update    mouse_x, mouse_y = Mouse.get_mouse_pos    if @last_move_x == nil      @last_move_x = false    end            #if Mouse.trigger?(Mouse::RIGHT)            self_update    if Mouse.press?(Mouse::LEFT) or$game_switches == true   last_moving = moving?      last_direction = @direction   unless moving? or $game_system.map_interpreter.running? or             @move_route_forcing or $game_temp.message_window_showing      last_x = @x      if @last_move_x          @last_move_x = false       elsif mouse_x > screen_x + 16          move_right          @wait_count = 10      elsif mouse_x < screen_x - 16          move_left          @wait_count = 10      end      last_y = @y      if last_x != @x          @last_move_x = true       elsif mouse_y > screen_y   move_down   @wait_count = 10      elsif mouse_y < screen_y - 32          move_up          @wait_count = 10      end      if last_y != @y          @last_move_x = false      elsif not @last_move_x          case last_direction          when 2            turn_down          when 4            turn_left          when 6            turn_right          when 8            turn_up          end      end      end    end    self_updateendendMouse.initEND { Mouse.exit }#==============================================================================# 本脚本来自http://rpg.blue/web/,使用和转载请保留此信息#============================================================================== #==============================================================================# 本脚本来自www.66RPG.com,使用和转载请保留此信息#==============================================================================#格式:显示的cmd图片的命名格式为:#    cmd调用公共事件编号_名字#    cmd调用公共事件编号_名字_02 # 此为鼠标经过的图片##即,带有cmd的为可以点击的图片,点击后执行相应的公共事件.....#不带cmd的图片没任何影响。。。#==============================================================================class Game_Picture def name=(str)   @name = str endendclass Sprite_Picture alias update_old update def update   update_old   return if @picture_name == "" or @picture_name.nil?   mx,my = Mouse.get_mouse_pos   lx = self.x - self.ox   rx = lx + self.bitmap.width   ty = self.y - self.oy   by = ty + self.bitmap.height   if mx < lx or mx > rx or my < ty or my > by or   self.bitmap.get_pixel(mx-lx,my-ty).alpha == 0   @picture.name = @picture.name.split(/_/)+"_"(/_/)   return   end   if @picture.name.split(/_/).nil? #    Audio.se_play("Audio/SE/sound00.wav")   @picture.name = @picture.name + "_2"   end   if Input.trigger?(13)   @picture.name.split(/_/).sub(/cmd(+)/,"")   $game_temp.common_event_id = $1.to_i   end endend#==============================================================================# 本脚本来自www.66RPG.com,使用和转载请保留此信息#==============================================================================#==============================================================================# 本脚本来自http://rpg.blue/web/,使用和转载请保留此信息#============================================================================== 复制代码



             本帖来自P1论坛作者风中承诺,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址:https://rpg.blue/forum.php?mod=viewthread&tid=219902若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。
页: [1]
查看完整版本: 两款战棋系统的鼠标操纵