查看: 133|回复: 0

[转载发布] 【脚写脚本】简易跑步时长限制

[复制链接]
  • TA的每日心情
    开心
    昨天 10:15
  • 签到天数: 73 天

    连续签到: 1 天

    [LV.6]常住居民II

    2044

    主题

    86

    回帖

    8602

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    -2
    卡币
    6460
    OK点
    16
    积分
    8602
    发表于 2024-4-12 16:27:02 | 显示全部楼层 |阅读模式
    嗯,功能如题目所说,其他的不多说了,直接放图放脚本。
    希望收脚本的客官能留个评论。



    RUBY 代码
    [Ruby] 纯文本查看 复制代码
    ##
    # 跑步时长限制 by Calendar99
    #
    module CLD99
      module DASH_TIME_LIMIT
        # 跑步最长持续时间(单位:帧)
        MAX_DASH_TIME = 90
     
        # 显示体力
        DISPLAY_TIME_LIMIT = true
     
        # 体力较多时的颜色
        COLOR1 = Color.new(0, 0, 255)
     
        # 体力较少时的颜色
        COLOR2 = Color.new(255, 0, 0)
      end
    end
     
    class Game_Player
      attr_reader :dash_time
      alias initialize_for_dash_with_time_limit initialize
      def initialize
        initialize_for_dash_with_time_limit
        @dash_time = CLD99::DASH_TIME_LIMIT::MAX_DASH_TIME
      end
      alias dash_without_time_limit dash?
      def dash?
        dash_without_time_limit && @dash_time > 0
      end
      alias update_for_dash_with_time_limit update
      def update
        update_for_dash_with_time_limit
        if moving? && dash_without_time_limit
          @dash_time = [@dash_time - 1, 0].max
        else
          @dash_time = [@dash_time + 1, CLD99::DASH_TIME_LIMIT::MAX_DASH_TIME].min
        end
      end
    end
     
    class Sprite_Character
      alias update_for_dash_time update
      def update
        update_for_dash_time
        return unless character.is_a?(Game_Player)
        return unless CLD99::DASH_TIME_LIMIT::DISPLAY_TIME_LIMIT
        if character.dash_time < CLD99::DASH_TIME_LIMIT::MAX_DASH_TIME
          display_dash_time
        else
          hide_dash_time
        end
      end
      def display_dash_time
        if !@sprite_dash_time
          @sprite_dash_time = Sprite.new
          @sprite_dash_time.ox = 16
          @sprite_dash_time.oy = 4
        end
        if !@sprite_dash_time.bitmap
          @bmp_dash_time1 = Bitmap.new(32, 8)
          @bmp_dash_time1.fill_rect(0, 0, 32, 8, CLD99::DASH_TIME_LIMIT::COLOR1)
          @bmp_dash_time2 = Bitmap.new(32, 8)
          @bmp_dash_time2.fill_rect(0, 0, 32, 8, CLD99::DASH_TIME_LIMIT::COLOR2)
        end
        @sprite_dash_time.x = self.x
        @sprite_dash_time.y = self.y + 4
        rate = character.dash_time / CLD99::DASH_TIME_LIMIT::MAX_DASH_TIME.to_f
        @sprite_dash_time.bitmap = rate < 0.3 ? @bmp_dash_time2 : @bmp_dash_time1
        @sprite_dash_time.src_rect.width = 32 * rate
        @sprite_dash_time.visible = true
      end
      def hide_dash_time
        return unless @sprite_dash_time
        @sprite_dash_time.visible = false    
      end
      alias dispose_for_dash_time dispose
      def dispose
        dispose_for_dash_time
        @sprite_dash_time.dispose if @sprite_dash_time
        @bmp_dash_time1.dispose if @bmp_dash_time1
        @bmp_dash_time2.dispose if @bmp_dash_time2
      end
    end


                 本帖来自P1论坛作者KB.Driver,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址:https://rpg. blue/forum.php?mod=viewthread&tid=481573  若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。

    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有账号?立即注册

    x
    天天去同能,天天有童年!
    回复 论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2024-9-21 16:45 , Processed in 0.047739 second(s), 41 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

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