じ☆ve冰风 发表于 2024-4-12 16:27:02

【脚写脚本】简易跑步时长限制

嗯,功能如题目所说,其他的不多说了,直接放图放脚本。
希望收脚本的客官能留个评论。



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在线咨询功能删除,谢谢。
页: [1]
查看完整版本: 【脚写脚本】简易跑步时长限制