Project1

标题: [RMXP]时间流逝窗口 [打印本页]

作者: 876加几    时间: 2013-9-19 16:44
标题: [RMXP]时间流逝窗口
本帖最后由 876加几 于 2013-9-20 10:07 编辑

呼,终于写好了,目前只支持儒略历。
原创脚本:
RUBY 代码复制
  1. #-------------------------------------------------------------------------------
  2. # 时间流逝 by 876加几
  3. #-------------------------------------------------------------------------------
  4. class Window_Time < Window_Base
  5.   #--------------------------------------------------------------------------
  6.   # ● 初始化窗口
  7.   #--------------------------------------------------------------------------
  8.   def initialize
  9.     super(0, 0, 640, 64)
  10.     self.contents = Bitmap.new(width - 32, height - 32)
  11.     if $game_switches[3] != true
  12.       @year_index = -1 #这个可以随便改,但要符合实际(还要在下面计算出来)
  13.       @month_index = 1
  14.       @day_index = 1
  15.       @hour_index = 9
  16.       @minute_index = 0
  17.       @second_index = 0
  18.       @cycle_index = 1   #后面三个不用计算,并且要符合实际
  19.       @season_index = 4
  20.       @leap = false
  21.       $game_switches[3] = true
  22.     end
  23.     refresh
  24.   end
  25.   #--------------------------------------------------------------------------
  26.   # ● 刷新
  27.   #--------------------------------------------------------------------------
  28.   def refresh
  29.     self.contents.clear
  30.     #存储数据/读取数据
  31.     if @year_index != nil
  32.       $game_variables[1] = @year_index
  33.     else
  34.       @year_index = $game_variables[1]
  35.     end
  36.     if @month_index != nil
  37.       $game_variables[2] = @month_index
  38.     else
  39.       @month_index = $game_variables[2]
  40.     end
  41.     if @day_index != nil
  42.       $game_variables[3] = @day_index
  43.     else
  44.       @day_index = $game_variables[3]
  45.     end
  46.     if @cycle_index != nil
  47.       $game_variables[4] = @cycle_index
  48.     else
  49.       @cycle_index = $game_variables[4]
  50.     end
  51.     if @season_index != nil
  52.       $game_variables[5] = @season_index
  53.     else
  54.       @season_index = $game_variables[5]
  55.     end
  56.     if @leap != nil
  57.       $game_switches[1] = @leap
  58.     else
  59.       @leap = $game_switches[1]
  60.     end
  61.     #时间显示
  62.     time = sprintf("%02d:%02d:%02d", @hour_index, @minute_index, @second_index)
  63.       #判断这个月是什么月
  64.       if @month_index == 1
  65.         @judge_index = 1
  66.       elsif @month_index == 2
  67.         @judge_index = 3
  68.       elsif @month_index == 3
  69.         @judge_index = 1
  70.       elsif @month_index == 4
  71.         @judge_index = 2
  72.       elsif @month_index == 5
  73.         @judge_index = 1
  74.       elsif @month_index == 6
  75.         @judge_index = 2
  76.       elsif @month_index == 7
  77.         @judge_index = 1
  78.       elsif @month_index == 8
  79.         @judge_index = 1
  80.       elsif @month_index == 9
  81.         @judge_index = 2
  82.       elsif @month_index == 10
  83.         @judge_index = 1
  84.       elsif @month_index == 11
  85.         @judge_index = 2
  86.       elsif @month_index == 12
  87.         @judge_index = 1
  88.       end
  89.       #星期变更
  90.       if @hour_index == 23 and @minute_index == 59
  91.         case @cycle_index
  92.         when 1
  93.           @cycle_index = 2
  94.         when 2
  95.           @cycle_index = 3
  96.         when 3
  97.           @cycle_index = 4
  98.         when 4
  99.           @cycle_index = 5
  100.         when 5
  101.           @cycle_index = 6
  102.         when 6
  103.           @cycle_index = 7
  104.         when 7
  105.           @cycle_index = 1
  106.         end
  107.       end
  108.       #制造时间动力
  109.       @total_second = Graphics.frame_count * 50
  110.       @second_index = @total_second % 60
  111.       @minute_index = @total_second / 60 % 60
  112.       @hour_index = @total_second / 60 / 60 % 24
  113.       case @judge_index
  114.       when 1 #大月
  115.         @day_index = @total_second / 60 / 60 / 24 % 30 + 1
  116.         @month_index = @total_second / 60 / 60 / 24 / 30 % 11 + 1
  117.       when 2 #小月
  118.         @day_index = @total_second / 60 / 60 / 24 % 29
  119.         @month_index = @total_second / 60 / 60 / 24 / 29 % 11 + 1
  120.       when 3 #特殊月
  121.         if @leap == true
  122.           @day_index = @total_second / 60 / 60 / 24 % 28
  123.           @month_index = @total_second / 60 / 60 / 24 / 28 % 11 + 1
  124.         else
  125.           @day_index = @total_second / 60 / 60 / 24 % 27
  126.           @month_index = @total_second / 60 / 60 / 24 / 27 % 11 + 1
  127.         end
  128.       end
  129.       if @leap == true
  130.         @year_index = @total_second / 60 / 60 / 24 / 365 + 1
  131.       else
  132.         @year_index = @total_second / 60 / 60 / 24 / 364 + 1
  133.       end
  134.       #季度判断
  135.       case @month_index
  136.       when 2
  137.         @season_index = 1
  138.       when 5
  139.         @season_index = 2
  140.       when 8
  141.         @season_index = 3
  142.       when 11
  143.         @season_index = 4
  144.       end
  145.     self.contents.font.color = normal_color
  146.     self.contents.draw_text(360, 0, 120, 32, time, 2)
  147.     #判断是否为闰年
  148.     @leap_index = @year_index
  149.     @leap_index %= 4
  150.     if @leap_index == 0
  151.       @leap = true
  152.     else
  153.       @leap = false
  154.     end
  155.     #绘制
  156.     mx = self.contents.text_size(@month_index.to_s).width
  157.     dx = self.contents.text_size(@day_index.to_s).width
  158.     if @year_index < 0
  159.       @yearf_index = @year_index * (0 - 1)
  160.       yx = self.contents.text_size(@yearf_index.to_s).width
  161.       self.contents.draw_text(16, 0, 72, 32,"公元前")
  162.       self.contents.draw_text(82, 0, 72, 32, @yearf_index.to_s)
  163.       self.contents.draw_text(82+yx, 0, 32, 32, "年")
  164.       self.contents.draw_text(102+yx, 0, 20, 32, @month_index.to_s)
  165.       self.contents.draw_text(102+yx+mx, 0, 32, 32, "月")
  166.       self.contents.draw_text(122+yx+mx, 0, 20, 32, @day_index.to_s)
  167.       self.contents.draw_text(122+yx+mx+dx, 0, 32, 32, "日")
  168.     else
  169.       yx = self.contents.text_size(@year_index.to_s).width
  170.       self.contents.draw_text(16, 0, 72, 32,"公元")
  171.       self.contents.draw_text(60, 0, 72, 32, @year_index.to_s)
  172.       self.contents.draw_text(60+yx, 0, 32, 32, "年")
  173.       self.contents.draw_text(80+yx, 0, 20, 32, @month_index.to_s)
  174.       self.contents.draw_text(80+yx+mx, 0, 32, 32, "月")
  175.       self.contents.draw_text(100+yx+mx, 0, 20, 32, @day_index.to_s)
  176.       self.contents.draw_text(100+yx+mx+dx, 0, 32, 32, "日")
  177.     end
  178.     case @cycle_index
  179.     when 1 #星期一
  180.       self.contents.draw_text(296, 0, 72, 32, "星期一")
  181.     when 2 #星期二
  182.       self.contents.draw_text(296, 0, 72, 32, "星期二")
  183.     when 3
  184.       self.contents.draw_text(296, 0, 72, 32, "星期三")
  185.     when 4
  186.       self.contents.draw_text(296, 0, 72, 32, "星期四")
  187.     when 5
  188.       self.contents.draw_text(296, 0, 72, 32, "星期五")
  189.     when 6
  190.       self.contents.draw_text(296, 0, 72, 32, "星期六")
  191.     when 7
  192.       self.contents.draw_text(296, 0, 72, 32, "星期日")
  193.     end
  194.     case @season_index
  195.     when 1 # 春季
  196.       self.contents.draw_text(512, 0, 32, 32, "春")
  197.     when 2 # 夏季
  198.       self.contents.draw_text(512, 0, 32, 32, "夏")
  199.     when 3 # 秋季
  200.       self.contents.draw_text(512, 0, 32, 32, "秋")
  201.     when 4 # 冬季
  202.       self.contents.draw_text(512, 0, 32, 32, "冬")
  203.     end
  204.     #色相修改
  205.     case @season_index
  206.     when 1
  207.       if @hour_index == 7
  208.         $game_screen.start_tone_change(Tone.new(64,0,0,0),20)
  209.       elsif @hour_index == 8
  210.         $game_screen.start_tone_change(Tone.new(0,0,0,0),20)
  211.       elsif @hour_index == 19
  212.         $game_screen.start_tone_change(Tone.new(64,0,0,0),20)
  213.       elsif @hour_index == 20
  214.         $game_screen.start_tone_change(Tone.new(-64,-64,64,0),20)
  215.       elsif @hour_index == 0
  216.         $game_screen.start_tone_change(Tone.new(-128,-128,128,0),20)
  217.       end
  218.     when 2
  219.       if @hour_index == 6
  220.         $game_screen.start_tone_change(Tone.new(64,0,0,0),20)
  221.       elsif @hour_index == 7
  222.         $game_screen.start_tone_change(Tone.new(0,0,0,0),20)
  223.       elsif @hour_index == 20
  224.         $game_screen.start_tone_change(Tone.new(64,0,0,0),20)
  225.       elsif @hour_index == 21
  226.         $game_screen.start_tone_change(Tone.new(-64,-64,64,0),20)
  227.       elsif @hour_index == 0
  228.         $game_screen.start_tone_change(Tone.new(-128,-128,128,0),20)
  229.       end
  230.     when 3
  231.       if @hour_index == 7
  232.         $game_screen.start_tone_change(Tone.new(64,0,0,0),20)
  233.       elsif @hour_index == 8
  234.         $game_screen.start_tone_change(Tone.new(0,0,0,0),20)
  235.       elsif @hour_index == 19
  236.         $game_screen.start_tone_change(Tone.new(64,0,0,0),20)
  237.       elsif @hour_index == 20
  238.         $game_screen.start_tone_change(Tone.new(-64,-64,64,0),20)
  239.       elsif @hour_index == 0
  240.         $game_screen.start_tone_change(Tone.new(-128,-128,128,0),20)
  241.       end
  242.     when 4
  243.       if @hour_index == 8
  244.         $game_screen.start_tone_change(Tone.new(64,0,0,0),20)
  245.       elsif @hour_index == 9
  246.         $game_screen.start_tone_change(Tone.new(0,0,0,0),20)
  247.       elsif @hour_index == 18
  248.         $game_screen.start_tone_change(Tone.new(64,0,0,0),20)
  249.       elsif @hour_index == 19
  250.         $game_screen.start_tone_change(Tone.new(-64,-64,64,0),20)
  251.       elsif @hour_index == 0
  252.         $game_screen.start_tone_change(Tone.new(-128,-128,128,0),20)
  253.       end
  254.     end
  255.   end
  256.   #--------------------------------------------------------------------------
  257.   # ● 刷新画面
  258.   #--------------------------------------------------------------------------
  259.   def update
  260.     super
  261.     if Graphics.frame_count * 50 != @total_second
  262.       refresh
  263.     end
  264.   end
  265. end
因为天气变化放进去过于唐突,所以我不写天气变化。
范例:
Project19.rar (193.65 KB, 下载次数: 83)
发现一转换场景,很多数据变成nil,所以我就占用一些Switches和Variables。
裁图:




Q:leap那些分别是什么?
A:leap判断平闰年,season是季节判断,year、month、day、hour、minute和second各代表年、月、日、小时、分钟、秒。

有的组件千万不能改!!!
范例新添的脚本要用这个脚本全文替换!!!

发现有个bug,先修改了。
作者: chd114    时间: 2013-9-19 16:50
等于现实时间的系统吗?
作者: 芯☆淡茹水    时间: 2013-9-19 21:44
脚本看得人眼花缭乱,需要改进一下,比如:
  1. case @cycle_index
  2. when 1 #星期一
  3.   text = "一"
  4. when 2 #星期二
  5.   text = "二"
  6. when 3
  7.   text = "三"
  8. when 4
  9.   text = "四"
  10. when 5
  11.   text = "五"
  12. when 6
  13.   text = "六"
  14. when 7
  15.   text = "日"
  16. end
  17. text = "星期" + text
  18. self.contents.draw_text(296, 0, 72, 32, text)
复制代码

作者: 恐惧剑刃    时间: 2013-9-20 00:55
加上天气一点也不唐突,效果反而会好(个人看法),去看看我的?
作者: IamI    时间: 2013-9-20 03:20
悄悄告诉你哦,有个类叫做Time
作者: 紫英晓狼1130    时间: 2013-9-20 05:25
LS说得对,RMXP的Ruby有一个Time的类,所以这个麻烦了一些…




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1