RM计算器!作者:七夕小雨
#==========================================================================
#RM计算机……无用产物之一
#脚本作者by 七夕小雨
#============================================================================
#Window_Command懒得写了……直接用星辰大人的好了……
class Window_Command_Compute < Window_Selectable
#--------------------------------------------------------------------------
# ● 初始化对像
# width : 每格的的宽
# row : 行数 自己根据命令数算好行列的值,否则^^b
# column : 列数
# commands : 命令字符串序列
#--------------------------------------------------------------------------
def initialize(width, commands, column=1)
row = commands.size / column
# 由命令的个数计算出窗口的宽和高
super(0, 0, width, row * 32 + 32)
@item_max = commands.size
@commands = commands
@row = row
@width_txt = (width-32)/column
@column_max = column
self.contents = Bitmap.new(width-32, @row * 32)
refresh
self.index = 0
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.font.size = 18
for i in 0...@item_max
draw_item(i, normal_color)
end
end
#--------------------------------------------------------------------------
# ● 描绘项目
# index : 项目编号
# color : 文字色
#--------------------------------------------------------------------------
def draw_item(index, color)
self.contents.font.color = color
# 计算得出当前index所对应的内容所在的行
row_index = index / @column_max
# 根据余数得出所在的列
for y in 0...@column_max
if index % @column_max == y
rect = Rect.new(y * @width_txt, 32 * row_index , @width_txt, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(rect, @commands,1)
break
end
end
end
#--------------------------------------------------------------------------
# ● 项目无效化
# index : 项目编号
#--------------------------------------------------------------------------
def disable_item(index)
draw_item(index, disabled_color)
end
#--------------------------------------------------------------------------
# ● 项目有效化
# index : 项目编号
#--------------------------------------------------------------------------
def able_item(index)
draw_item(index, normal_color)
end
#--------------------------------------------------------------------------
# ● 更新光标举行
#--------------------------------------------------------------------------
def update_cursor_rect
# 光标位置不满 0 的情况下
if @index < 0
self.cursor_rect.empty
return
end
# 获取当前的行
row = @index / @column_max
# 当前行被显示开头行前面的情况下
if row < self.top_row
# 从当前行向开头行滚动
self.top_row = row
end
# 当前行被显示末尾行之后的情况下
if row > self.top_row + (self.page_row_max - 1)
# 从当前行向末尾滚动
self.top_row = row - (self.page_row_max - 1)
end
# 计算光标的宽
cursor_width = @width_txt
# 计算光标坐标
x = @index % @column_max * cursor_width
y = @index / @column_max * 32 - self.oy
# 更新国标矩形
self.cursor_rect.set(x, y, @width_txt, 32)
end
end
#-------------------------七夕小雨华丽的分割线-------------------------------
class Window_Compute < Window_Base
def initialize
super(250, 64, 182, 64)
self.contents = Bitmap.new(width - 32, height - 32)
$compute = "0"
refresh
end
def refresh
self.contents.clear
self.contents.font.color = normal_color
self.contents.draw_text(-32, 0, 180, 32, $compute.to_s, 2)
end
end
#-------------------------七夕小雨华丽的分割线--------------------------------
class Scene_Compute
#--------------------------------------------------------------------------
# ● 初始化对像
# menu_index : 命令光标的初期位置
#--------------------------------------------------------------------------
def initialize(menu_index = 0)
@menu_index = menu_index
end
#--------------------------------------------------------------------------
# ● 主处理
#--------------------------------------------------------------------------
def main
@back = Spriteset_Map.new
@command_window = Window_Command_Compute.new(180, ["1","2","3","4","5","6","7","8","9","0","+","-","×","÷","=","归零"],4)
@command_window.x = 250
@command_window.y = 140
@command_window.index = @menu_index
@compute_window = Window_Compute.new
# 执行过渡
Graphics.transition
# 主循环
loop do
# 刷新游戏画面
Graphics.update
# 刷新输入信息
Input.update
# 刷新画面
update
# 如果切换画面就中断循环
if $scene != self
break
end
end
# 准备过渡
Graphics.freeze
@compute_window.dispose
@command_window.dispose
@back.dispose
end
#--------------------------------------------------------------------------
# ● 刷新画面
#--------------------------------------------------------------------------
def update
@compute_window.update
@compute_window.refresh
@command_window.update
# 命令窗口被激活的情况下: 调用 update_command
if @command_window.active
update_command
return
end
end
#--------------------------------------------------------------------------
# ● 刷新画面 (命令窗口被激活的情况下)
#--------------------------------------------------------------------------
def update_command
# 按下 B 键的情况下
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Map.new
return
end
# 按下 C 键的情况下
if Input.trigger?(Input::C)
case @command_window.index
when 0 # 1
$game_system.se_play($data_system.decision_se)
if $compute != "0"
$compute += "1"
else
$compute = "1"
end
when 1 # 2
$game_system.se_play($data_system.decision_se)
if $compute != "0"
$compute += "2"
else
$compute = "2"
end
when 2 # 3
$game_system.se_play($data_system.decision_se)
if $compute != "0"
$compute += "3"
else
$compute = "3"
end
when 3 # 4
$game_system.se_play($data_system.decision_se)
if $compute != "0"
$compute += "4"
else
$compute = "4"
end
when 4 # 5
$game_system.se_play($data_system.decision_se)
if $compute != "0"
$compute += "5"
else
$compute = "5"
end
when 5 # 6
$game_system.se_play($data_system.decision_se)
if $compute != "0"
$compute += "6"
else
$compute = "6"
end
when 6 # 7
$game_system.se_play($data_system.decision_se)
if $compute != "0"
$compute += "7"
else
$compute = "7"
end
when 7 # 8
$game_system.se_play($data_system.decision_se)
if $compute != "0"
$compute += "8"
else
$compute = "8"
end
when 8 # 9
$game_system.se_play($data_system.decision_se)
if $compute != "0"
$compute += "9"
else
$compute = "9"
end
when 9 # 0
$game_system.se_play($data_system.decision_se)
if $compute != "0"
$compute += "0"
else
$compute = "0"
end
when 10 # +
$game_system.se_play($data_system.decision_se)
@a = $compute.to_i
@Operation = 1
$compute = "0"
when 11 # -
$game_system.se_play($data_system.decision_se)
@a = $compute.to_i
@Operation = 2
$compute = "0"
when 12 # x
$game_system.se_play($data_system.decision_se)
@a = $compute.to_i
@Operation = 3
$compute = "0"
when 13 # /
$game_system.se_play($data_system.decision_se)
@a = $compute.to_i
@Operation = 4
$compute = "0"
when 14 # =
case @Operation
when 0
$game_system.se_play($data_system.cancel_se)
when 1
$game_system.se_play($data_system.decision_se)
@b = $compute.to_i
$c = @a + @b
$c = $c.to_s
$compute = $c
when 2
$game_system.se_play($data_system.decision_se)
@b = $compute.to_i
$c = @a - @b
$c = $c.to_s
$compute = $c
when 3
$game_system.se_play($data_system.decision_se)
@b = $compute.to_i
$c = @a * @b
$c = $c.to_s
$compute = $c
when 4
$game_system.se_play($data_system.decision_se)
@b = $compute.to_i
$c = @a / @b
$c = $c.to_s
$compute = $c
end
when 15
$game_system.se_play($data_system.cancel_se)
$compute = "0"
@Operation = 0
end
return
end
end
end
用这个脚本做的计算器有什么用?还有,怎么把这个计算器在事件中调出来?你都没写啊?
(小声:既然是无用产物之一,干吗还拿出来?) 这是个很囧的东西…… 还打错了一个字 用这个脚本做的计算器有什么用?还有,怎么把这个计算器在事件中调出来?你都没写啊?
(小声:既然是无用产物之一,干吗还拿出来?)
最爱南宫煌 发表于 2010-3-12 21:36 http://www.palslp.com/bbs/images/common/back.gif
1.调用class
2.这个无用是小雨写的,但有时可以用来挪作他用 这是小雨在博客里写的....
不过这不是计算器吧....是RM计算机 是计算器 不是计算机 = = 这是小雨在博客里写的....
不过这不是计算器吧....是RM计算机
冷剑随风 发表于 2010-3-13 02:21 http://www.palslp.com/bbs/images/common/back.gif
这个是在时空传里翻出来的……
外:就是计算器 事件——》脚本——》$scene = Scene_Compute.new
就调出来了~~
这个计算器问题还很多,零到除数,比如没有浮点运算等等,程序也可以写的更简单,但是却啰嗦的写了一堆~当然是方便新人看懂了 哦,我看也是。
页:
[1]