找回密码
 注册用户
查看: 316|回复: 0

[RMVA] 【原创】地图镜头移动、跟随

[复制链接]

88

主题

7

回帖

1277

积分

资深会员

积分
1277
发表于 2024-6-5 22:57:46 | 显示全部楼层 |阅读模式
老脚本,使视野转向或跟随事件,用于剧情演出。


范例:
https://www.123pan.com/s/uBKyVv-J6F3A.html 提取码:zoxX


脚本:

  1. =begin
  2. 笔记:
  3. $game_map.display_x,$game_map.display_y
  4. 指地图的卷动数值,以地图图块数为单位的浮点数

  5. $game_player.real_x,$game_player.real_y
  6. 指玩家角色行走图在地图上的坐标,以地图图块数为单位的浮点数
  7. $game_player.x,$game_playery
  8. 指玩家角色行走图在地图上的坐标,以地图图块数为单位的整数,即real_x,real_y值取整
  9. =end
  10. #==============================================================================
  11. # 平滑镜头移动
  12. #         --by 烁灵
  13. # 使用方法:

  14. #   在【设置移动路径】中输入脚本
  15. #    start_move_screen_to_this
  16. #   则镜头平滑转移向该事件(或角色)

  17. #   在【设置移动路径】中输入脚本
  18. #    keep_screen_on
  19. #   则镜头将跟随该事件(或角色,但不建议)

  20. #   在【设置移动路径】中输入脚本
  21. #    keep_screen_off
  22. #   则镜头将停止跟随该事件(或角色,但不建议)
  23. #   
  24. #==============================================================================

  25. Center_tile_x = ((Graphics.width - 32).to_i / 32 )/ 2 # 距离中心的格子数
  26. Center_tile_y = ((Graphics.height - 32).to_i / 32 )/ 2 # 距离中心的格子数
  27. Max_tile_num_x = Graphics.width / 32 # 地图每行最大图块数
  28. Max_tile_num_y = Graphics.height / 32 # 地图每列最大图块数

  29. class Game_Character < Game_CharacterBase
  30.   #--------------------------------------------------------------------------
  31.   # ● 初始化(追加定义)
  32.   #--------------------------------------------------------------------------
  33.   alias sl_orig_initialize initialize
  34.   def initialize
  35.     sl_orig_initialize
  36.     @screen_keep_up = false
  37.     @move_to_this = false
  38.     @scrollto_speed = 60
  39.     @scrollto_cnt = 0
  40.   end
  41.   #--------------------------------------------------------------------------
  42.   # ● 设置显示位置为地图中央(新增定义)
  43.   #--------------------------------------------------------------------------
  44.   def center(x, y)
  45.     # 自身坐标减去中心坐标,边边角角部分由set_display_pos修正
  46.     center_x = x - Center_tile_x
  47.     center_y = y - Center_tile_y
  48.     $game_map.set_display_pos(center_x, center_y)
  49.   end
  50.   #--------------------------------------------------------------------------
  51.   # ● 缓慢卷动到事件(新增定义)
  52.   #--------------------------------------------------------------------------
  53.   def scroll_to_this
  54.     @scrollto_cnt += 1   
  55.     speed_x = (@distance_x.to_f / @scrollto_speed).abs
  56.     speed_y = (@distance_y.to_f / @scrollto_speed).abs   
  57.     if @distance_x > 0
  58.       $game_map.scroll_right(speed_x)
  59.     else
  60.       $game_map.scroll_left(speed_x)
  61.     end
  62.     if @distance_y > 0
  63.       $game_map.scroll_down(speed_y)
  64.     else
  65.       $game_map.scroll_up(speed_y)
  66.     end     
  67.     return @scrollto_cnt == @scrollto_speed
  68.   end
  69.   #--------------------------------------------------------------------------
  70.   # ● 开启跟踪(新增定义)
  71.   #--------------------------------------------------------------------------
  72.   def keep_screen_on
  73.     @screen_keep_up = true
  74.   end
  75.   #--------------------------------------------------------------------------
  76.   # ● 关闭跟踪(新增定义)
  77.   #--------------------------------------------------------------------------
  78.   def keep_screen_off
  79.     @screen_keep_up = false
  80.   end
  81.   #--------------------------------------------------------------------------
  82.   # ● 判断是否跟踪(新增定义)
  83.   #--------------------------------------------------------------------------
  84.   def screen_keep_up?
  85.     @screen_keep_up
  86.   end
  87.   #--------------------------------------------------------------------------
  88.   # ● 开启镜头移动(新增定义)
  89.   #--------------------------------------------------------------------------
  90.   def start_move_screen_to_this
  91.     @scrollto_cnt = 0
  92.     @move_to_this = true
  93.     start_x = $game_map.display_x
  94.     start_y = $game_map.display_y   
  95.     if @real_x < Center_tile_x
  96.       @end_x = 0
  97.     elsif @real_x > $game_map.width - Max_tile_num_x + Center_tile_x
  98.       @end_x = $game_map.width - Max_tile_num_x
  99.     else
  100.       @end_x = @real_x - Center_tile_x
  101.     end   
  102.     if @real_y < Center_tile_y
  103.       @end_y = 0
  104.     elsif @real_y > $game_map.height - Max_tile_num_y + Center_tile_y
  105.       @end_y = $game_map.height - Max_tile_num_y
  106.     else
  107.       @end_y = @real_y - Center_tile_y
  108.     end
  109.     @distance_x = @end_x - start_x
  110.     @distance_y = @end_y - start_y
  111.   end   
  112.   #--------------------------------------------------------------------------
  113.   # ● 关闭镜头移动(新增定义)
  114.   #--------------------------------------------------------------------------
  115.   def stop_move_screen_to_this
  116.     @move_to_this = false
  117.   end  
  118.   #--------------------------------------------------------------------------
  119.   # ● 判断镜头移动(新增定义)
  120.   #--------------------------------------------------------------------------
  121.   def move_to_this?
  122.     @move_to_this
  123.   end
  124.   #--------------------------------------------------------------------------
  125.   # ● 更新(追加定义)
  126.   #--------------------------------------------------------------------------
  127.   alias sl_orig_update update
  128.   def update
  129.     last_real_x = @real_x
  130.     last_real_y = @real_y
  131.     sl_orig_update
  132.     if screen_keep_up?
  133.       if @real_x > last_real_x  
  134.         $game_map.scroll_right(@real_x - last_real_x)
  135.       else
  136.         $game_map.scroll_left(last_real_x - @real_x)
  137.       end
  138.       if @real_y > last_real_y     
  139.         $game_map.scroll_down(@real_y - last_real_y)
  140.       else
  141.         $game_map.scroll_up(last_real_y - @real_y)
  142.       end      
  143.       center(@real_x,@real_y)
  144.     end
  145.   end
  146. end
  147. class Scene_Map
  148.   alias kds_update update
  149.   def update
  150.     if $game_player.move_to_this?
  151.       $game_player.stop_move_screen_to_this if $game_player.scroll_to_this
  152.     end
  153.     for e in $game_map.events.values
  154.       if e.move_to_this?
  155.         e.stop_move_screen_to_this if e.scroll_to_this
  156.       end      
  157.     end
  158.     kds_update
  159.   end  
  160. end
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册用户

本版积分规则

Archiver|QQ群: 48625831|爱上RPG|哈库纳玛塔塔 |网站地图 Clicky

GMT+8, 2024-10-23 13:33 , Processed in 0.062755 second(s), 18 queries .

Powered by Discuz! X3.5

Copyright © 2001-2020, Tencent Cloud.

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