赞 | 6 |
VIP | 4 |
好人卡 | 58 |
积分 | 5 |
经验 | 58579 |
最后登录 | 2024-6-30 |
在线时间 | 1478 小时 |
Lv2.观梦者
- 梦石
- 0
- 星屑
- 508
- 在线时间
- 1478 小时
- 注册时间
- 2011-9-17
- 帖子
- 1316
|
本帖最后由 iisnow 于 2011-12-17 13:41 编辑
嗯!这是一个好想法,农场游戏~
然后就写了一个脚本,基本可以实现你要的功能,不过要配合事件实现,于是就发个范例给你吧……
不多说了,效果:
脚本:
- $time = {}
- code_time = Thread.new{
- loop do
- $time.each do |k,v|
- $time[k] = [v - 1,0].max
- end
- sleep 1
- end
- }
- class Game_Event
- attr_accessor :event
- end
- class Game_Map
- attr_accessor :map_id
- end
- class Sprite_time < Sprite_Base
-
- def initialize(view_port,ch)
- super(view_port)
- @ch = ch
- @time = $time[[$game_map.map_id,@ch.event.id]]
- @new = true
- self.bitmap = Bitmap.new(64,20)
- end
-
- def clear_self
- if $time[[$game_map.map_id,@ch.event.id]] == 0
- $time.delete([$game_map.map_id,@ch.event.id])
- self.dispose
- return true
- else
- return false
- end
- end
-
- def update
- if @time == nil
- if @ch.event.name =~ /%(\d{0,2}[,,])?(\d+[,,])(\d+)/
- hou = $1 ? $1.to_i : 0
- min = $2.to_i
- sec = $3.to_i
- end
- $time[[$game_map.map_id,@ch.event.id]] = hou * 3600 + min * 60 + sec
- end
- if @time != $time[[$game_map.map_id,@ch.event.id]] || @new
- @time = $time[[$game_map.map_id,@ch.event.id]]
- @new = false
- if @time != 0
- ho = @time / 3600
- mi = @time / 60 - ho * 60
- se = @time % 60
- string = sprintf("%02d:%02d:%02d", ho,mi,se) if ho >0
- string = sprintf("%02d:%02d", mi,se) if ho == 0
- else
- string = "收获啦~"
- end
- self.bitmap.clear
- self.bitmap.font.size = 14
- self.bitmap.draw_text(0,0,64,20,string,1)
- end
- self.x = @ch.screen_x - 32
- self.y = @ch.screen_y - 50
- end
-
- end
- class Game_Interpreter
-
- def add_self
- if $time[[$game_map.map_id,@event_id]] == nil
- view_port = Viewport.new(0, 0, 544, 416)
- sprite = Sprite_time.new(view_port,$game_map.events[@event_id])
- $scene.spriteset.character_sprites.push(sprite)
- $scene.spriteset.update
- end
- end
-
- def get_result
- if $time[[$game_map.map_id,@event_id]] > 0
- return false
- elsif $time[[$game_map.map_id,@event_id]] == 0
- $scene.spriteset.clear_time
- return true
- end
- end
-
- alias :iisnow_command_201 :command_201
- def command_201
- $flag = @params[0] == 0 ? @params[1] : $game_variables[@params[1]]
- iisnow_command_201
- end
- end
-
- class Scene_Map < Scene_Base
- attr_accessor :spriteset
-
- alias :iisnow_start :start
- def start
- $flag = $game_map.map_id
- iisnow_start
- end
- end
- class Spriteset_Map
- attr_accessor :character_sprites
-
- alias :iisnow_update :update
- def update
- if $flag
- $time.each do |k,v|
- if k[0] == $flag && $flag == $game_map.map_id
- view_port = Viewport.new(0, 0, 544, 416)
- sprite = Sprite_time.new(view_port,$game_map.events[k[1]])
- @character_sprites.push(sprite)
- end
- end
- $flag = nil if $flag == $game_map.map_id
- end
- iisnow_update
- end
-
- def clear_time
- @character_sprites.each do |s|
- c = s.clear_self if s.is_a?(Sprite_time)
- @character_sprites[@character_sprites.index(s)] = nil if c
- end
- @character_sprites.compact!
- end
- end
复制代码 然后说说缺点吧:
1.时间的不精确性,就是指精确度为1s小于1s的时间被忽视
2.存档的问题:即存档打开后会有错误,现在我在想办法修改,后面将会改正,就是增加一个文件记录
3.存档期间,游戏的时间会停止运转,即开始游戏蔬菜才会倒计时(估计改正存档以后这个问题可以解决),但是游戏中无论怎么暂停,蔬菜都不会停止生长
附件在下方,注意每个事件的设置方式,以及一定要将事件的优先级调整为“与普通角色相同”
另外时间的名称标识着蔬菜的种植时间格式为:“%x,y,z”
(x指小时,y指分钟,z指秒,其中x和它后面的,可以省略表示时间小于1个小时,x,y,z的值不限大小,但是毕竟希望你设置的合乎情理一点,比如y和z尽量小于60等等……)
iisnow_.rar
(240.77 KB, 下载次数: 141)
下面是存档改正:
脚本:
- $last = false
- $time = {}
- code_time = Thread.new{
- loop do
- $time.each do |k,v|
- $time[k] = [v - 1,0].max
- end
- sleep 1
- end
- }
- class Game_Event
- attr_accessor :event
- end
- class Game_Map
- attr_accessor :map_id
- end
- class Sprite_time < Sprite_Base
-
- def initialize(view_port,ch)
- super(view_port)
- @ch = ch
- @time = $time[[$game_map.map_id,@ch.event.id]]
- @new = true
- self.bitmap = Bitmap.new(64,20)
- end
-
- def clear_self
- if $time[[$game_map.map_id,@ch.event.id]] == 0
- $time.delete([$game_map.map_id,@ch.event.id])
- self.dispose
- return true
- else
- return false
- end
- end
-
- def update
- if @time == nil
- if @ch.event.name =~ /%(\d{0,2}[,,])?(\d+[,,])(\d+)/
- hou = $1 ? $1.to_i : 0
- min = $2.to_i
- sec = $3.to_i
- end
- $time[[$game_map.map_id,@ch.event.id]] = hou * 3600 + min * 60 + sec
- end
- if @time != $time[[$game_map.map_id,@ch.event.id]] || @new
- @time = $time[[$game_map.map_id,@ch.event.id]]
- @new = false
- if @time != 0
- ho = @time / 3600
- mi = @time / 60 - ho * 60
- se = @time % 60
- string = sprintf("%02d:%02d:%02d", ho,mi,se) if ho >0
- string = sprintf("%02d:%02d", mi,se) if ho == 0
- else
- string = "收获啦~"
- end
- self.bitmap.clear
- self.bitmap.font.size = 14
- self.bitmap.draw_text(0,0,64,20,string,1)
- end
- self.x = @ch.screen_x - 32
- self.y = @ch.screen_y - 50
- end
-
- end
- class Game_Interpreter
-
- def add_self
- if $time[[$game_map.map_id,@event_id]] == nil
- view_port = Viewport.new(0, 0, 544, 416)
- sprite = Sprite_time.new(view_port,$game_map.events[@event_id])
- $scene.spriteset.character_sprites.push(sprite)
- $scene.spriteset.update
- end
- end
-
- def get_result
- if $time[[$game_map.map_id,@event_id]] > 0
- return false
- elsif $time[[$game_map.map_id,@event_id]] == 0
- $scene.spriteset.clear_time
- return true
- end
- end
-
- alias :iisnow_command_201 :command_201
- def command_201
- $flag = @params[0] == 0 ? @params[1] : $game_variables[@params[1]]
- iisnow_command_201
- end
- end
-
- class Scene_Map < Scene_Base
- attr_accessor :spriteset
-
- alias :iisnow_start :start
- def start
- $flag = $game_map.map_id
- iisnow_start
- end
- end
- class Spriteset_Map
- attr_accessor :character_sprites
-
- alias :iisnow_update :update
- def update
- if $flag
- $time.each do |k,v|
- if k[0] == $flag && $flag == $game_map.map_id
- view_port = Viewport.new(0, 0, 544, 416)
- sprite = Sprite_time.new(view_port,$game_map.events[k[1]])
- @character_sprites.push(sprite)
- end
- end
- $flag = nil if $flag == $game_map.map_id
- end
- iisnow_update
- end
-
- def clear_time
- @character_sprites.each do |s|
- c = s.clear_self if s.is_a?(Sprite_time)
- @character_sprites[@character_sprites.index(s)] = nil if c
- end
- @character_sprites.compact!
- end
-
- end
- class Scene_File
-
- alias :iisnow_write_save_data :write_save_data
- def write_save_data(file)
- iisnow_write_save_data(file)
- Marshal.dump($time,file)
- end
-
- alias :iisnow_read_save_data :read_save_data
- def read_save_data(file)
- iisnow_read_save_data(file)
- $time = Marshal.load(file)
- if $last
- time_last = (Time.now - file.mtime).to_i
- $time.each do |k,v|
- $time[k] = [v - time_last,0].max
- end
- end
- end
-
- end
-
-
-
复制代码 改变内容:
使得存档变的可行,并加入了$last变量用于管理持续的时间消耗:
$last = true表示存档以后,显示时间的消耗会反应在游戏中,即存档1个小时后打开,你会发现游戏也过了1个小时;
$last = false表示不进行上述操作,也就是,存档时有x分钟成熟,读档就还有x分钟;
那种你喜欢就手动修改吧
脚本修改后,事件的用法不变
增加115分流:http://115.com/file/clj1zpal
改正后附件:
ii_snow_2.rar
(240.83 KB, 下载次数: 147)
(这个附件中的脚本,我改了一行Main,就是kill那个进程用的,改不改应该无所谓吧) |
评分
-
查看全部评分
|