class G_Codigo < Window_Base
def initialize(combinacao, s1,s2 = -1)
@play_shit = true # fazer barulinho ou não
@numeros = ["7","8","9","4","5","6","1","2","3","#","0","*"]
@ccerta = combinacao # se acertar, altera uma switch, se errar altera outra
@cagora = ""
@sa = s1 # que switch ativa se acertar
@se = s2 # que switch ativa se errar
@index = 0 # qual número tá selecionado
@status = 0 # 0 nada, 1 acertou, -1 errou
super(0,0,128,192)
self.contents = Bitmap.new(width-32,height-32)
self.active = true
self.opacity = 127
self.x = 320 - 64
self.y = 240 - 96
main
Input.update
self.dispose
end
def main
loop do
Graphics.update
Input.update
update
break unless self.active
end
end
def ps
if @play_shit then $game_system.se_play($data_system.cursor_se) end
end
def ps_clica
if @play_shit then $game_system.se_play($data_system.decision_se) end
end
def ps_acerta
if @play_shit then $game_system.se_play($data_system.buzzer_se) end
end
def ps_erra
if @play_shit then $game_system.se_play($data_system.cancel_se) end
end
def update
# desisto
if Input.trigger?(Input::B)
ps_erra
self.active = false
end
# cursor desce
if Input.trigger?(Input::DOWN)
@index += 3
if @index > 11 then @index -= 12 end
ps
end
# cursor sobe
if Input.trigger?(Input::UP)
@index -= 3
if @index < 0 then @index += 12 end
ps
end
# cursor vai pra esquerda
if Input.trigger?(Input::LEFT)
@linha = (@index / 3) # pro cursor ficar sempre na mesma linha
@index -= 1
if @index < (@linha * 3) then @index += 3 end
ps
end
# cursor vai pra direita
if Input.trigger?(Input::RIGHT)
@linha = (@index / 3) + 1
@index += 1
if @index == (@linha * 3) then @index -= 3 end
ps
end
# aperta num número
if Input.trigger?(Input::C)
@cagora += @numeros[@index]
if @cagora.length == @ccerta.length
if @cagora == @ccerta
# pra fazer um tranca/destranga
ps_acerta
$game_switches[@sa] = !$game_switches[@sa]
$game_map.need_refresh = true
else
# se errar errou
ps_erra
if @se != -1
$game_switches[@se] = true
$game_map.need_refresh = true
end
end
self.active = false
else
ps_clica
end
end
# Desenha tudo a partir daqui
self.contents.clear
# escreve asterÃscos indicando quantos números já botou
@t = ""
for i in
0..@cagora.length-1
@t += "*"
end
self.contents.draw_text($fontsize/2,0,$fontsize*3,32,@t,1)
# escreve os números
@lx = 0
@ly = 0
for i in 0..11
self.contents.draw_text((@lx * 32)+($fontsize/2), (@ly * 32)+32,32,32,@numeros[i])
@lx += 1
if @lx == 3
@lx = 0
@ly += 1
end
end
# põe o cursor
@cy = (@index / 3)
@cx = (@index) - (@cy * 3)
self.cursor_rect.set(@cx*32,(@cy*32)+32,32,32)
end
end