DaxSoft

Dax Core i1.5

Jan 16th, 2014
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 102.11 KB | None | 0 0
  1. #==============================================================================
  2. # * Dax Core
  3. #==============================================================================
  4. # Autor : Dax Aquatic X
  5. # Versão : Core i1.5
  6. # Site : www.dax-soft.weebly.com
  7. # Suporte : [email protected]
  8. #==============================================================================
  9. # Um Core com vários módulos e métodos que facilitará na hora de programar os
  10. # seus scripts, bom proveito.
  11. #==============================================================================
  12. # Conteúdo :
  13. #==============================================================================
  14. # i :
  15. # - API
  16. # - String
  17. # - Integer
  18. # - Float
  19. # - Color
  20. # - ColorBasic
  21. # - DMath
  22. # - Key
  23. # - Mouse
  24. # - Entries
  25. # - Rpg Module
  26. # - Read
  27. # - DRGSS
  28. # - Rect
  29. # - Sprite
  30. # - Bitmap : method (save) by Gab!
  31. # - Object
  32. # - Touch_Picture
  33. # - Simple_Touch_Picture
  34. # - Sprite_Text
  35. # - Text_Base
  36. # - Touch_Icon
  37. # - Simple_Touch_Icon
  38. # - Touch_Text
  39. # - Simple_Touch_Text
  40. # - Opacity
  41. # - DString
  42. # - Background
  43. # - Window_Base
  44. # - Map
  45. #==============================================================================
  46. module Dax
  47. extend self
  48. #----------------------------------------------------------------------------
  49. # * Mensagem de requisito de script :
  50. #----------------------------------------------------------------------------
  51. def required_script(symbol)
  52. msgbox("Você requisita o script : #{symbol} :")
  53. return exit
  54. end
  55. #----------------------------------------------------------------------------
  56. # Ajuste aqui as configurações básicas da fonte padrão do jogo.
  57. #----------------------------------------------------------------------------
  58. Font.default_name = ["Arial"] # Nome padrão da fonte do jogo.
  59. Font.default_size = 18 # Tamanho padrão da fonte do jogo.
  60. Font.default_bold = true # true - Para usar negrito | false - para não usar.
  61. Font.default_italic = false # true - Para usar italico | false - para não usar.
  62. Font.default_shadow = false # true - Para usar sombra na fonte | false - para não usar.
  63. Font.default_outline = true # true - Para usar borda da fonte | false - para não usar.
  64. Font.default_out_color = Color.new(0, 0, 0) # Cor da fonte padrão da borda da fonte.
  65. Font.default_color = Color.new(255, 255, 255) # Cor da fonte padrão.
  66. #----------------------------------------------------------------------------
  67. # * Constantes e variáveis
  68. #----------------------------------------------------------------------------
  69. @register = {} # Armazena os scripts criados que foram registrados.
  70. # A imagem do ícone do Mouse tem que estar na pasta System. Basta você
  71. # por o nome da imagem dentro das áspas. Caso você queira usar um ícone
  72. # do Rpg Maker no lugar de uma imagem, basta você por o id do ícone no lugar
  73. # das áspas.
  74. @benchmark = ""
  75. Mouse_Name = ""
  76. #----------------------------------------------------------------------------
  77. # * Verificar se tem um script :
  78. #----------------------------------------------------------------------------
  79. # ** Este método contém três valores que tem de ser definidos para requirir
  80. # um sistema, eles são : symbol, version, name **
  81. #----------------------------------------------------------------------------
  82. # ** Descrição de cada valor a ser defindo **
  83. #----------------------------------------------------------------------------
  84. # symbol/args[0] : Este valor representa o nome do script a ser requerido em
  85. # formato de simbolo. Ex - :string
  86. #----------------------------------------------------------------------------
  87. def required(name)
  88. required_script(name.to_s) unless @register.has_key?(name)
  89. end
  90. #----------------------------------------------------------------------------
  91. # * Método de registrar scripts :
  92. #----------------------------------------------------------------------------
  93. # ** Este método tem de ser definido alguns valores como :
  94. # symbol - nome do script, que é posto em símbolo : Ex - :arrow
  95. # name - nome do autor do script, que é posto em áspas
  96. # version - versão do script;
  97. # data - data do script;
  98. # Dax.register(symbol, name, version, data)
  99. # ** Você pode usá-lo para somente registrar o nome do script.
  100. # Dax.register(symbol)
  101. # ** Você pode usá-lo para modificar a versão e a data do script.
  102. # --- Mas só funciona caso o script já tenha se registrado.
  103. # Dax.register(symbol, version, data)
  104. #----------------------------------------------------------------------------
  105. def register(*args)
  106. if @register.has_key?(args[0])
  107. @register[args[0]][:version] = args[1]
  108. @register[args[0]][:data] = args[2]
  109. else
  110. @register[args[0]] = {name: args[1], version: args[2], data: args[3], script: nil}
  111. end
  112. end
  113. #----------------------------------------------------------------------------
  114. # * Método de verificar se o script existe ou se está registrado.
  115. #----------------------------------------------------------------------------
  116. # Dax.required_class("Nome_Da_Classe") { }
  117. # Dentro das chaves você poem o script.
  118. # * Exemplo :
  119. # Dax.required_class("Window_Base") {
  120. # class Window_Base < Window
  121. # def example
  122. # self.x = self.x + self.width
  123. # end
  124. # end
  125. # }
  126. #----------------------------------------------------------------------------
  127. #----------------------------------------------------------------------------
  128. def required_class(name, &block)
  129. eval("block.call if defined?(name)")
  130. end
  131. #----------------------------------------------------------------------------
  132. # • Fazer benchmark : recomendado que fique em : 0.016667
  133. #----------------------------------------------------------------------------
  134. # Dax.benchmark(name(opcional)) { SCRIPT }
  135. #----------------------------------------------------------------------------
  136. def benchmark(name="", &block)
  137. time = Time.now
  138. block.call
  139. print "Benchmark: #{(time - Time.now).abs.to_f} segundos!\r\n"
  140. @benchmark += "#{name} : #{(time - Time.now).to_f} segundos!\r\n"
  141. end
  142. #----------------------------------------------------------------------------
  143. # • Benchmark em algum método.
  144. #----------------------------------------------------------------------------
  145. def benchmark_method(method, *args)
  146. start_time = Time.now
  147. self.send(method, args)
  148. end_time = Time.now
  149. print "Benchmark do método: #{(start_time - end_time).to_f.abs} segundos!\r\n"
  150. @benchmark += "Benchmark do método: #{method} : #{(start_time - end_time).to_f.abs} segundos !\r\n"
  151. end
  152. #----------------------------------------------------------------------------
  153. # • Salvar testes benchmark..
  154. #----------------------------------------------------------------------------
  155. def benchmark_save
  156. File.open("Benchmark.txt", "a+") do |file|
  157. file.write(@benchmark)
  158. file.close
  159. end
  160. end
  161. #----------------------------------------------------------------------------
  162. # • Requirir um arquivo.
  163. #----------------------------------------------------------------------------
  164. def require(arquivo)
  165. $: << "./"
  166. Kernel.send(:require, arquivo)
  167. end
  168. #----------------------------------------------------------------------------
  169. # * Verificar se exite um arquivo, o funcionamento é o mesmo que o do required
  170. # class
  171. #----------------------------------------------------------------------------
  172. def required_file(filename, &block)
  173. block.call if FileTest.exist?(filename)
  174. end
  175. #----------------------------------------------------------------------------
  176. # * Desativa um script existente
  177. #----------------------------------------------------------------------------
  178. def remove(symbol_name)
  179. Object.send(:remove_const, symbol_name)
  180. end
  181. #----------------------------------------------------------------------------
  182. # * Retorna a variável $RGSS_SCRITP
  183. #----------------------------------------------------------------------------
  184. def rgss_script
  185. return $RGSS_SCRIPTS
  186. end
  187. #----------------------------------------------------------------------------
  188. # * Tela chéia
  189. #----------------------------------------------------------------------------
  190. def full_screen
  191. res = Win32API.new 'user32', 'keybd_event', %w(l l l l), ''
  192. res.call(18,0,0,0)
  193. res.call(13,0,0,0)
  194. res.call(13,0,2,0)
  195. res.call(18,0,2,0)
  196. end
  197. end
  198. Dax.register(:dax)
  199. #==============================================================================
  200. # * API : Módulo que armazena informações de algumas APIS.
  201. #==============================================================================
  202. Dax.register(:api)
  203. module API
  204. extend self
  205. # Permite acessar as teclas do teclado.
  206. GetKeyState = Win32API.new('user32', 'GetAsyncKeyState', 'i', 'i')
  207. # Permite ativar/desativar o ícone do mouse.
  208. MouseShowCursor = Win32API.new("user32", "ShowCursor", "i", "i")
  209. # Permite achar a posição do mouse.
  210. CursorPosition = Win32API.new('user32', 'GetCursorPos', 'p', 'i')
  211. # Permite achar o tamanho da screen.
  212. ScreenToClient = Win32API.new('user32', 'ScreenToClient', %w(l p), 'i')
  213. # Permite fazer a leitura do game.ini.
  214. ReadIni = Win32API.new('kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l')
  215. # Permite achar o tamando da window.
  216. FindWindow = Win32API.new('user32', 'FindWindowA', %w(p p), 'l')
  217. # API da Message Box.
  218. MessageBoxA = Win32API.new('user32', 'MessageBoxA', %w(p p p i), 'i')
  219. # Recupera uma string especificada de um arquivo em inicialização.
  220. GetPrivateProfileString = Win32API.new('kernel32', 'GetPrivateProfileStringA',%w(p p p p l p),'l')
  221. # Get Systeme Metrics
  222. GetSystemMetrics = Win32API.new("user32", "GetSystemMetrics", "i", "i")
  223. # Posição da janela.
  224. SetWindowPos = Win32API.new("user32", "SetWindowPos", "lliiiii", "i")
  225. # Obtem o 'Rect' da janela.
  226. GetWindowRect = Win32API.new('user32','GetWindowRect',%w(l p),'i')
  227. # Define a Win32API do comando print
  228. MessageBoxW = Win32API.new("user32", "MessageBoxW", "LPPL", "L")
  229. # Caps Lock
  230. CapsLock = Win32API.new("user32", "GetKeyState", "i", "i").call(20) != 0
  231. # State Key
  232. StateKey = Win32API.new("user32", "GetKeyState", ["i"], "i")
  233. # SetCursorPos
  234. SetCursorPos = Win32API.new("user32", "SetCursorPos", "ll", "i")
  235. SetCursorPos = Win32API.new("user32", "SetCursorPos", "ii", "i")
  236. GetKeyboardState = Win32API.new('user32', 'GetKeyboardState', ['P'], 'V')
  237. GetAsyncKeyState = Win32API.new('user32', 'GetAsyncKeyState', 'i', 'i')
  238. # Criar uma nova pasta.
  239. CreateDirectory = Win32API.new("kernel32", "CreateDirectory", "p", "lll")
  240. # Remover uma pasta existente.
  241. RemoveDirectory = Win32API.new("kernel32", "RemoveDirectory", "p", "l")
  242. # retorna para a data do ponteiro.
  243. def copymen(len)
  244. buf = "\0" * len
  245. Win32API.new("kernel32", "RtlMoveMemory", "ppl", "").call(buf, self, len)
  246. buf
  247. end
  248. # Shell
  249. Open = Win32API.new('shell32', 'ShellExecute', 'LPPPPI', 'L')
  250. def open_file(name)
  251. API::Open.call(0, 'open', "#{name}.exe", 0, 0, 1)
  252. end
  253. end
  254. #==============================================================================
  255. # * String
  256. #==============================================================================
  257. Dax.register(:string)
  258. class String
  259. #----------------------------------------------------------------------------
  260. # * Método com a função de decodificar a base 64.
  261. #----------------------------------------------------------------------------
  262. def decode_base64
  263. self.unpack("m")[0]
  264. end
  265. #----------------------------------------------------------------------------
  266. # * Obtem a palavra do méio de uma frase/palavra
  267. #----------------------------------------------------------------------------
  268. def get_string_between(start_at, end_at)
  269. my_string = " #{self}"
  270. ini = my_string.index(start_at)
  271. return my_string if ini == 0
  272. ini += start_at.length
  273. length = my_string.index(end_at, ini).to_i - ini
  274. return my_string[ini,length]
  275. end
  276. end
  277. #==============================================================================
  278. # * Integer
  279. #==============================================================================
  280. Dax.register(:integer)
  281. class Integer
  282. #----------------------------------------------------------------------------
  283. # * Transformar em porcentagem :
  284. # a : Valor atual.
  285. # b : Valor máximo.
  286. #----------------------------------------------------------------------------
  287. def to_p(a, b)
  288. self * a / b
  289. end
  290. #----------------------------------------------------------------------------
  291. # * Grid On : Multiplica o número pelo tamanho de uma grid.
  292. #----------------------------------------------------------------------------
  293. def grid_on(grid_size=32)
  294. return self * grid_size
  295. end
  296. #----------------------------------------------------------------------------
  297. # * Grid Off : Divide o número pelo tamanho de uma grid.
  298. #----------------------------------------------------------------------------
  299. def grid_off(grid_size=32)
  300. return self / grid_size
  301. end
  302. end
  303. #==============================================================================
  304. # * Float
  305. #==============================================================================
  306. Dax.register(:float)
  307. class Float
  308. #----------------------------------------------------------------------------
  309. # * Transformar em porcentagem :
  310. # a : Valor atual.
  311. # b : Valor máximo.
  312. #----------------------------------------------------------------------------
  313. def to_p(a, b)
  314. self * a / b
  315. end
  316. end
  317. #==============================================================================
  318. # * Color
  319. #==============================================================================
  320. Dax.register(:color)
  321. class Color
  322. #----------------------------------------------------------------------------
  323. # • Efeito de cor opaca.
  324. #----------------------------------------------------------------------------
  325. def opacity
  326. self.set(self.red, self.green, self.blue, 128)
  327. end
  328. #----------------------------------------------------------------------------
  329. # • Inverter as cores.
  330. #----------------------------------------------------------------------------
  331. def invert!
  332. self.set(255-self.red, 255-self.green, 255-self.blue, self.alpha)
  333. end
  334. #----------------------------------------------------------------------------
  335. # • Reverter as cores.
  336. #----------------------------------------------------------------------------
  337. def revert
  338. colors = [self.red, self.green, self.blue, self.alpha].reverse!
  339. self.set(*colors)
  340. end
  341. #----------------------------------------------------------------------------
  342. # • Converte para string.
  343. #----------------------------------------------------------------------------
  344. def to_s
  345. "red: #{self.red}\nblue: #{self.blue}\ngreen: #{self.green}\nalpha: #{self.alpha}"
  346. end
  347. #----------------------------------------------------------------------------
  348. # • Comparar cores.
  349. #----------------------------------------------------------------------------
  350. def ==(color)
  351. (self.red == color.red and self.green == color.green and self.blue == color.blue and
  352. self.alpha == color.alpha) ? true : false
  353. end
  354. #----------------------------------------------------------------------------
  355. # • Retorna os valores da classe [COLOR] para hash;;
  356. #----------------------------------------------------------------------------
  357. def to_h
  358. return {
  359. red: self.red, green: self.green, blue: self.blue, alpha: self.alpha,
  360. }
  361. end
  362. #----------------------------------------------------------------------------
  363. # • Retorna os valores da classe [COLOR] para array;;
  364. #----------------------------------------------------------------------------
  365. def to_a
  366. return [self.red, self.green, self.blue, self.alpha]
  367. end
  368. end
  369. #==============================================================================
  370. # * ColorBasic
  371. #==============================================================================
  372. Dax.register(:colorbasic)
  373. module ColorBasic
  374. extend self
  375. #----------------------------------------------------------------------------
  376. # • Cores Hexadécimais
  377. #----------------------------------------------------------------------------
  378. def hex(color)
  379. Color.new(*color.scan(/../).map { |color| color.to_i(16)})
  380. end
  381. #----------------------------------------------------------------------------
  382. # • Cores em Index
  383. #----------------------------------------------------------------------------
  384. def [](id)
  385. case id
  386. when -1 then Color.new(255, 255, 255) # White
  387. when 0 then Color.new(240, 248, 255) # Alice Blue
  388. when 1 then Color.new(250, 235, 215) # Antique_White
  389. when 2 then Color.new(0, 255, 255) # Aqua
  390. when 3 then Color.new(127, 255, 255) # Aqua Marine
  391. when 4 then Color.new(240, 255, 255) # Azure
  392. when 5 then Color.new(245, 245, 220) # Beige
  393. when 6 then Color.new(255, 228, 196) # Bisque
  394. when 7 then Color.new(0, 0, 0) # Black
  395. when 8 then Color.new(255, 235, 205) # Blanchedalmond
  396. when 9 then Color.new(0, 0, 255) # Blue
  397. when 10 then Color.new(138, 43, 226) # Blue Violet
  398. when 11 then Color.new(165, 42, 42) # Brown
  399. when 12 then Color.new(222, 184, 135) # Burly Wood
  400. when 13 then Color.new(93, 158, 160) # Cadet Blue
  401. when 14 then Color.new(127, 255, 0) # Chatreuse
  402. when 15 then Color.new(210, 105, 30) # Chocolate
  403. when 16 then Color.new(255, 127, 80) # Coral
  404. when 17 then Color.new(100, 149, 237) # Corn Flower Blue
  405. when 18 then Color.new(255, 248, 220) # CornSilk
  406. when 19 then Color.new(220, 20, 60) # Crimson
  407. when 20 then Color.new(0, 255, 255) # Cyan
  408. when 21 then Color.new(0, 0, 139) # DarkBlue
  409. when 22 then Color.new(0, 139, 139) # DarkCyan
  410. when 23 then Color.new(184, 134, 11) # DarkGoldEnrod
  411. when 24 then Color.new(169, 169, 169) # Dark Gray
  412. when 25 then Color.new(0, 100, 0) # Dark Green
  413. when 26 then Color.new(189, 183, 107) # Dark Khaki
  414. when 27 then Color.new(139, 0, 139) # Dark Magenta
  415. when 28 then Color.new(85, 107, 47) # Dark Oliver Green
  416. when 29 then Color.new(255, 140, 0) # Dark Orange
  417. when 30 then Color.new(153, 50, 204) # Dark orchid
  418. when 31 then Color.new(139, 0, 0) # Dark Red
  419. when 32 then Color.new(233, 150, 120) # Dark Salmon
  420. when 33 then Color.new(143, 188, 143) # Dark Sea Green
  421. when 34 then Color.new(72, 61, 139) # Dark Slate Blue
  422. when 35 then Color.new(255, 255, 0) # Yellow
  423. when 36 then Color.new(255, 0, 0) # Red
  424. when 37 then Color.new(0, 255, 0) # Green
  425. when 38 then Color.new(255, 128, 0) # Orange
  426. end
  427. end
  428. #----------------------------------------------------------------------------
  429. # • Cor padrão.
  430. #----------------------------------------------------------------------------
  431. def default
  432. return self.hex "ffffff"
  433. end
  434. end
  435. #==============================================================================
  436. # • Rect
  437. #==============================================================================
  438. Dax.register(:rect)
  439. class Rect
  440. #----------------------------------------------------------------------------
  441. # • Verificar se está na área.
  442. #----------------------------------------------------------------------------
  443. def in?(x, y)
  444. x.between?(self.x, self.x + self.width) &&
  445. y.between?(self.y, self.y + self.height)
  446. end
  447. end
  448. #==============================================================================
  449. # • DMath
  450. #==============================================================================
  451. Dax.register(:dmath, 'Dax', 1.5, '04/05/13')
  452. module DMath
  453. extend self
  454. #----------------------------------------------------------------------------
  455. # • Clamp.
  456. #----------------------------------------------------------------------------
  457. def clamp(num, low, high)
  458. return num < low ? low : num > high ? high : low
  459. end
  460. #----------------------------------------------------------------------------
  461. # • Centralizar um objeto n'outro.
  462. #----------------------------------------------------------------------------
  463. def centralize_object(object, object_for_centralize)
  464. x = object.x + (object.width - object_for_centralize.width) / 2
  465. y = object.y + (object.height - object_for_centralize.height) / 2
  466. return x, y
  467. end
  468. #----------------------------------------------------------------------------
  469. # • Centralizar um objeto n'outro.
  470. #----------------------------------------------------------------------------
  471. def centralize_x(objectx, objectwidth, object_for_centralizewidth)
  472. return objectx + (objectwidth - object_for_centralizewidth) / 2
  473. end
  474. #----------------------------------------------------------------------------
  475. # • Centralizar um objeto n'outro.
  476. #----------------------------------------------------------------------------
  477. def centralize_y(objecty=0, objectheight = 0, object_for_centralizeheight=0)
  478. return objecty + (objectheight - object_for_centralizeheight) / 2
  479. end
  480. #----------------------------------------------------------------------------
  481. # • Rotc | Rotacionar.
  482. #----------------------------------------------------------------------------
  483. def rotc(vmn, v, vmx, c = 100)
  484. ((v - vmn) * c) / (vmx - vmn)
  485. end
  486. #----------------------------------------------------------------------------
  487. # • Obter o X do centro da tela para um determinado objeto|sprite,bitmap.
  488. #----------------------------------------------------------------------------
  489. def get_x_center_screen(width)
  490. return (Graphics.width - width) / 2
  491. end
  492. #----------------------------------------------------------------------------
  493. # • Obter o Y do centro da tela para um determinado objeto|sprite,bitmap.
  494. #----------------------------------------------------------------------------
  495. def get_y_center_screen(height)
  496. return (Graphics.height - height) / 2
  497. end
  498. #--------------------------------------------------------------------------
  499. # • Verifica se um objeto está na área. Círculo | Circle
  500. #--------------------------------------------------------------------------
  501. def circle(object, object2, size)
  502. ( (object.x - object2.x) ** 2) + ( (object.y - object2.y) ** 2) <= (size ** 2)
  503. end
  504. #----------------------------------------------------------------------------
  505. # • Converter em graus, multiplique a variável com isto.
  506. #----------------------------------------------------------------------------
  507. def graus
  508. 360 / (2 * Math::PI)
  509. end
  510. #----------------------------------------------------------------------------
  511. # • Radiano
  512. #----------------------------------------------------------------------------
  513. def radian(degree)
  514. return (degree.to_f/180) * Math::PI
  515. end
  516. #----------------------------------------------------------------------------
  517. # • Degree
  518. #----------------------------------------------------------------------------
  519. def degree(radian)
  520. return (radian.to_f/Math::PI) * 180
  521. end
  522. #----------------------------------------------------------------------------
  523. # • Para 4 decimals.
  524. #----------------------------------------------------------------------------
  525. def to_4_dec(n)
  526. ((n * 1000).ceil) / 1000
  527. end
  528. #----------------------------------------------------------------------------
  529. # • Área de um triângulo.
  530. #----------------------------------------------------------------------------
  531. def triangle_area(*args)
  532. x, y, x2, y2, x3, y3 = *args
  533. return (x2 - x) * (y3 - y) - (x3 - x) * (y2 - y)
  534. end
  535. #----------------------------------------------------------------------------
  536. # • Calcular distância para scripts como sensor.
  537. #----------------------------------------------------------------------------
  538. def distance_sensor(target, target2)
  539. return (target.x - target2.x).abs + (target.y - target2.y).abs
  540. end
  541. end
  542. #==============================================================================
  543. # • Keyboard | Método para usar todas as teclas do teclado.
  544. #==============================================================================
  545. Dax.register(:Key, "Dax", 1.0)
  546. module Key
  547. extend self
  548. #--------------------------------------------------------------------------
  549. # * Chaves diversos.
  550. #--------------------------------------------------------------------------
  551. CANCEL = 0x03 # Control-Break Processing
  552. BACKSPACE = 0x08 # Backspace Key
  553. TAB = 0x09 # Tab Key
  554. CLEAR = 0x0C # Clear Key
  555. ENTER = 0x0D # Enter Key
  556. SHIFT = 0x10 # Shift Key
  557. CONTROL = 0x11 # Ctrl Key
  558. MENU = 0x12 # Alt Key
  559. PAUSE = 0x13 # Pause Key
  560. ESC = 0x1B # Esc Key
  561. CONVERT = 0x1C # IME Convert Key
  562. NONCONVERT = 0x1D # IME Nonconvert Key
  563. ACCEPT = 0x1E # IME Accept Key
  564. SPACE = 0x20 # Space Bar Key (Space, usually blank)
  565. PRIOR = 0x21 # Page Up Key
  566. NEXT = 0x22 # Page Down Key
  567. ENDS = 0x23 # End Key
  568. HOME = 0x24 # Home Key
  569. LEFT = 0x25 # Left Arrow Key
  570. UP = 0x26 # Up Arrow Key
  571. RIGHT = 0x27 # Right Arrow Key
  572. DOWN = 0x28 # Down Arrow Key
  573. SELECT = 0x29 # Select Key
  574. PRINT = 0x2A # Print Key
  575. EXECUTE = 0x2B # Execute Key
  576. SNAPSHOT = 0x2C # Print Screen Key
  577. DELETE = 0x2E # Delete Key
  578. HELP = 0x2F # Help Key
  579. LSHIFT = 0xA0 # Left Shift Key
  580. RSHIFT = 0xA1 # Right Shift Key
  581. LCONTROL = 0xA2 # Left Control Key (Ctrl)
  582. RCONTROL = 0xA3 # Right Control Key (Ctrl)
  583. LMENU = 0xA4 # Left Menu Key (Alt)
  584. RMENU = 0xA5 # Right Menu Key (Alt)
  585. PACKET = 0xE7 # Used to Pass Unicode Characters as Keystrokes
  586. MOUSE_RIGHT = 0x01 # Button Mouse Right
  587. MOUSE_LEFT = 0x02 # Button Mouse Left
  588. MOUSE_MIDDLE = 0x04 # Button Mouse Middle
  589. #--------------------------------------------------------------------------
  590. # * Chaves de números.
  591. #--------------------------------------------------------------------------
  592. N0 = 0x30 # 0 Key
  593. N1 = 0x31 # 1 Key
  594. N2 = 0x32 # 2 Key
  595. N3 = 0x33 # 3 Key
  596. N4 = 0x34 # 4 Key
  597. N5 = 0x35 # 5 Key
  598. N6 = 0x36 # 6 Key
  599. N7 = 0x37 # 7 Key
  600. N8 = 0x38 # 8 Key
  601. N9 = 0x39 # 9 Key
  602. #--------------------------------------------------------------------------
  603. # * Chaves de letras
  604. #--------------------------------------------------------------------------
  605. A = 0x41 # A Key
  606. B = 0x42 # B Key
  607. C = 0x43 # C Key
  608. D = 0x44 # D Key
  609. E = 0x45 # E Key
  610. F = 0x46 # F Key
  611. G = 0x47 # G Key
  612. H = 0x48 # H Key
  613. I = 0x49 # I Key
  614. J = 0x4A # J Key
  615. K = 0x4B # K Key
  616. L = 0x4C # L Key
  617. M = 0x4D # M Key
  618. N = 0x4E # N Key
  619. O = 0x4F # O Key
  620. P = 0x50 # P Key
  621. Q = 0x51 # Q Key
  622. R = 0x52 # R Key
  623. S = 0x53 # S Key
  624. T = 0x54 # T Key
  625. U = 0x55 # U Key
  626. V = 0x56 # V Key
  627. W = 0x57 # W Key
  628. X = 0x58 # X Key
  629. Y = 0x59 # Y Key
  630. Z = 0x5A # Z Key
  631. #--------------------------------------------------------------------------
  632. # * Chaves de windows
  633. #--------------------------------------------------------------------------
  634. LWIN = 0x5B # Left Windows Key (Natural keyboard)
  635. RWIN = 0x5C # Right Windows Key (Natural Keyboard)
  636. APPS = 0x5D # Applications Key (Natural keyboard)
  637. SLEEP = 0x5F # Computer Sleep Key
  638. BROWSER_BACK = 0xA6 # Browser Back Key
  639. BROWSER_FORWARD = 0xA7 # Browser Forward Key
  640. BROWSER_REFRESH = 0xA8 # Browser Refresh Key
  641. BROWSER_STOP = 0xA9 # Browser Stop Key
  642. BROWSER_SEARCH = 0xAA # Browser Search Key
  643. BROWSER_FAVORITES = 0xAB # Browser Favorites Key
  644. BROWSER_HOME = 0xAC # Browser Start and Home Key
  645. VOLUME_MUTE = 0xAD # Volume Mute Key
  646. VOLUME_DOWN = 0xAE # Volume Down Key
  647. VOLUME_UP = 0xAF # Volume Up Key
  648. MEDIA_NEXT_TRACK = 0xB0 # Next Track Key
  649. MEDIA_PREV_TRACK = 0xB1 # Previous Track Key
  650. MEDIA_STOP = 0xB2 # Stop Media Key
  651. MEDIA_PLAY_PAUSE = 0xB3 # Play/Pause Media Key
  652. LAUNCH_MAIL = 0xB4 # Start Mail Key
  653. LAUNCH_MEDIA_SELECT = 0xB5 # Select Media Key
  654. LAUNCH_APP1 = 0xB6 # Start Application 1 Key
  655. LAUNCH_APP2 = 0xB7 # Start Application 2 Key
  656. PROCESSKEY = 0xE5 # IME Process Key
  657. ATTN = 0xF6 # Attn Key
  658. CRSEL = 0xF7 # CrSel Key
  659. EXSEL = 0xF8 # ExSel Key
  660. EREOF = 0xF9 # Erase EOF Key
  661. PLAY = 0xFA # Play Key
  662. ZOOM = 0xFB # Zoom Key
  663. PA1 = 0xFD # PA1 Key
  664. #--------------------------------------------------------------------------
  665. # * Chaves do Numpad
  666. #--------------------------------------------------------------------------
  667. NUMPAD0 = 0x60 # Numeric Keypad 0 Key
  668. NUMPAD1 = 0x61 # Numeric Keypad 1 Key
  669. NUMPAD2 = 0x62 # Numeric Keypad 2 Key
  670. NUMPAD3 = 0x63 # Numeric Keypad 3 Key
  671. NUMPAD4 = 0x64 # Numeric Keypad 4 Key
  672. NUMPAD5 = 0x65 # Numeric Keypad 5 Key
  673. NUMPAD6 = 0x66 # Numeric Keypad 6 Key
  674. NUMPAD7 = 0x67 # Numeric Keypad 7 Key
  675. NUMPAD8 = 0x68 # Numeric Keypad 8 Key
  676. NUMPAD9 = 0x69 # Numeric Keypad 9 Key
  677. MULTIPLY = 0x6A # Multiply Key (*)
  678. ADD = 0x6B # Add Key (+)
  679. SEPARATOR = 0x6C # Separator Key
  680. SUBTRACT = 0x6D # Subtract Key (-)
  681. DECIMAL = 0x6E # Decimal Key (.)
  682. DIVIDE = 0x6F # Divide Key (/)
  683. #--------------------------------------------------------------------------
  684. # * Chaves de funções
  685. #--------------------------------------------------------------------------
  686. F1 = 0x70 # F1 Key
  687. F2 = 0x71 # F2 Key
  688. F3 = 0x72 # F3 Key
  689. F4 = 0x73 # F4 Key
  690. F5 = 0x74 # F5 Key
  691. F6 = 0x75 # F6 Key
  692. F7 = 0x76 # F7 Key
  693. F8 = 0x77 # F8 Key
  694. F9 = 0x78 # F9 Key
  695. F10 = 0x79 # F10 Key
  696. F11 = 0x7A # F11 Key
  697. F12 = 0x7B # F12 Key
  698. F13 = 0x7C # F13 Key
  699. F14 = 0x7D # F14 Key
  700. F15 = 0x7E # F15 Key
  701. F16 = 0x7F # F16 Key
  702. F17 = 0x80 # F17 Key
  703. F18 = 0x81 # F18 Key
  704. F19 = 0x82 # F19 Key
  705. F20 = 0x83 # F20 Key
  706. F21 = 0x84 # F21 Key
  707. F22 = 0x85 # F22 Key
  708. F23 = 0x86 # F23 Key
  709. F24 = 0x87 # F24 Key
  710. #--------------------------------------------------------------------------
  711. # * Chaves alternativas
  712. #--------------------------------------------------------------------------
  713. CAPITAL = 0x14 # Caps Lock Key
  714. KANA = 0x15 # IME Kana Mode Key
  715. HANGUL = 0x15 # IME Hangul Mode Key
  716. JUNJA = 0x17 # IME Junja Mode Key
  717. FINAL = 0x18 # IME Final Mode Key
  718. HANJA = 0x19 # IME Hanja Mode Key
  719. KANJI = 0x19 # IME Kanji Mode Key
  720. MODECHANGE = 0x1F # IME Mode Change Request Key
  721. INSERT = 0x2D # Insert Key
  722. NUMLOCK = 0x90 # Num Lock Key
  723. SCROLL = 0x91 # Scroll Lock Key
  724. #--------------------------------------------------------------------------
  725. # * Chaves OEM, variadas
  726. #--------------------------------------------------------------------------
  727. OEM_1 = 0xBA # Misc Characters (; : in USA 101/102 Keyboards)
  728. OEM_PLUS = 0xBB # + = Key
  729. OEM_COMMA = 0xBC # , < Key
  730. OEM_MINUS = 0xBD # - _ Key
  731. OEM_PERIOD = 0xBE # . > Key
  732. OEM_2 = 0xBF # Misc Characters (/ ? in USA 101/102 Keyboards)
  733. OEM_3 = 0xC0 # Misc Characters (` ~ in USA 101/102 Keyboards)
  734. OEM_4 = 0xDB # Misc Characters ([ { in USA 101/102 Keyboards)
  735. OEM_5 = 0xDC # Misc Characters (\ | in USA 101/102 Keyboards)
  736. OEM_6 = 0xDD # Misc Characters (] } in USA 101/102 Keyboards)
  737. OEM_7 = 0xDE # Misc Characters (' " in USA 101/102 Keyboards)
  738. OEM_8 = 0xDF # Misc Characters (Varies by Keyboard)
  739. OEM_9 = 0xE1 # OEM Specific
  740. OEM_10 = 0x92 # OEM Specific
  741. OEM_11 = 0x93 # OEM Specific
  742. OEM_12 = 0x94 # OEM Specific
  743. OEM_13 = 0x95 # OEM Specific
  744. OEM_14 = 0x96 # OEM Specific
  745. OEM_15 = 0xE3 # OEM Specific
  746. OEM_16 = 0xE4 # OEM Specific
  747. OEM_17 = 0xE6 # OEM Specific
  748. OEM_18 = 0xE9 # OEM Specific
  749. OEM_19 = 0xEA # OEM Specific
  750. OEM_20 = 0xEB # OEM Specific
  751. OEM_21 = 0xEC # OEM Specific
  752. OEM_22 = 0xED # OEM Specific
  753. OEM_23 = 0xEE # OEM Specific
  754. OEM_24 = 0xEF # OEM Specific
  755. OEM_25 = 0xF1 # OEM Specific
  756. OEM_26 = 0xF2 # OEM Specific
  757. OEM_27 = 0xF3 # OEM Specific
  758. OEM_28 = 0xF4 # OEM Specific
  759. OEM_29 = 0xF5 # OEM Specific
  760. OEM_102 = 0xE2 # Angle Bracket or Backslash on RT-102 Keyboards
  761. OEM_CLEAR = 0xFE # Clear Key
  762. #--------------------------------------------------------------------------
  763. # * Variáveis do módulo.
  764. #--------------------------------------------------------------------------
  765. @unpack_string = 'b'*256
  766. @last_array = '0'*256
  767. @press = Array.new(256, false)
  768. @trigger = Array.new(256, false)
  769. @repeat = Array.new(256, false)
  770. @release = Array.new(256, false)
  771. @repeat_counter = Array.new(256, 0)
  772. @getKeyboardState = API::GetKeyboardState
  773. @getAsyncKeyState = API::GetAsyncKeyState
  774. @getKeyboardState.call(@last_array)
  775. @last_array = @last_array.unpack(@unpack_string)
  776. for i in 0...@last_array.size
  777. @press[i] = @getAsyncKeyState.call(i) == 0 ? false : true
  778. end
  779. #--------------------------------------------------------------------------
  780. # * Atualização dos objetos do módulo.
  781. #--------------------------------------------------------------------------
  782. def update
  783. @trigger = Array.new(256, false)
  784. @repeat = Array.new(256, false)
  785. @release = Array.new(256, false)
  786. array = '0'*256
  787. @getKeyboardState.call(array)
  788. array = array.unpack(@unpack_string)
  789. for i in 0...array.size
  790. if array[i] != @last_array[i]
  791. @press[i] = @getAsyncKeyState.call(i) == 0 ? false : true
  792. if @repeat_counter[i] <= 0 && @press[i]
  793. @repeat[i] = true
  794. @repeat_counter[i] = 15
  795. end
  796. if !@press[i]
  797. @release[i] = true
  798. else
  799. @trigger[i] = true
  800. end
  801. else
  802. if @press[i] == true
  803. @press[i] = @getAsyncKeyState.call(i) == 0 ? false : true
  804. @release[i] = true if !@press[i]
  805. end
  806. if @repeat_counter[i] > 0 && @press[i] == true
  807. @repeat_counter[i] -= 1
  808. elsif @repeat_counter[i] <= 0 && @press[i] == true
  809. @repeat[i] = true
  810. @repeat_counter[i] = 3
  811. elsif @repeat_counter[i] != 0
  812. @repeat_counter[i] = 0
  813. end
  814. end
  815. end
  816. @last_array = array
  817. end
  818. #--------------------------------------------------------------------------
  819. # * Get Key Pressed State
  820. # key : key index
  821. #--------------------------------------------------------------------------
  822. def press?(key)
  823. return @press[key]
  824. end
  825. #--------------------------------------------------------------------------
  826. # * Get Key Triggered State
  827. # key : key index
  828. #--------------------------------------------------------------------------
  829. def trigger?(key)
  830. return @trigger[key]
  831. end
  832. #--------------------------------------------------------------------------
  833. # * Get Key Repeated State
  834. # key : key index
  835. #--------------------------------------------------------------------------
  836. def repeat?(key)
  837. return @repeat[key]
  838. end
  839. #--------------------------------------------------------------------------
  840. # * Get Key Released State
  841. # key : key index
  842. #--------------------------------------------------------------------------
  843. def release?(key)
  844. return @release[key]
  845. end
  846. end
  847. #==============================================================================
  848. # • Sprite
  849. #==============================================================================
  850. Dax.register(:sprite)
  851. class Sprite
  852. #----------------------------------------------------------------------------
  853. # • Novo método.
  854. #----------------------------------------------------------------------------
  855. alias new_initialize initialize
  856. def initialize(viewport=nil)
  857. if viewport.is_a?(String)
  858. new_initialize(nil)
  859. if viewport.match(/S: ([^>]*)/)
  860. self.bitmap = Cache.system($1.to_s)
  861. elsif viewport.match(/P: ([^>]*)/)
  862. self.bitmap = Cache.picture($1.to_s)
  863. elsif viewport.match(/G: ([^>]*)/)
  864. self.bitmap = Bitmap.new("Graphics/#{$1.to_s}")
  865. else
  866. self.bitmap = Bitmap.new(viewport)
  867. end
  868. elsif viewport.is_a?(Array)
  869. if viewport.size == 2
  870. new_initialize(nil)
  871. self.bitmap = Bitmap.new(viewport[0], viewport[1])
  872. elsif viewport.size == 5
  873. new_initialize(nil)
  874. self.bitmap = Bitmap.new(viewport[0], viewport[1])
  875. self.x, self.y, self.z = viewport[2], viewport[3], viewport[4]
  876. end
  877. elsif viewport.is_a?(Viewport) or viewport.nil?
  878. new_initialize(viewport)
  879. end
  880. end
  881. #----------------------------------------------------------------------------
  882. # • Slide pela direita.
  883. # * speed : Velocidade | point : Ponto da coordenada X que irá chegar.
  884. #----------------------------------------------------------------------------
  885. def slide_right(speed, point)
  886. self.x += speed unless self.x >= point
  887. end
  888. #----------------------------------------------------------------------------
  889. # • Slide pela esquerda.
  890. # * speed : Velocidade | point : Ponto da coordenada X que irá chegar.
  891. #----------------------------------------------------------------------------
  892. def slide_left(speed, point)
  893. self.x -= speed unless self.x <= point
  894. end
  895. #----------------------------------------------------------------------------
  896. # • Slide por cima.
  897. # * speed : Velocidade | point : Ponto da coordenada Y que irá chegar.
  898. #----------------------------------------------------------------------------
  899. def slide_up(speed, point)
  900. self.y -= speed unless self.y <= point
  901. end
  902. #----------------------------------------------------------------------------
  903. # • Slide por baixo.
  904. # * speed : Velocidade | point : Ponto da coordenada Y que irá chegar.
  905. #----------------------------------------------------------------------------
  906. def slide_down(speed, point)
  907. self.y += speed unless self.y >= point
  908. end
  909. #----------------------------------------------------------------------------
  910. # • Define aqui uma posição fixa para um objeto.
  911. #----------------------------------------------------------------------------
  912. def position(command=0)
  913. return if command.nil?
  914. case command
  915. when 0 then self.x = 0
  916. when 1 then self.x = (Graphics.width - self.width) / 2
  917. when 2 then self.x = Graphics.width - self.width
  918. when 3 then self.y = 0
  919. when 4 then self.y = (Graphics.height - self.height) / 2
  920. when 5 then self.y = Graphics.height - self.height
  921. when :center
  922. self.x = (Graphics.width - self.width) / 2
  923. self.y = Graphics.height / 2 - self.height / 2
  924. when :center_left
  925. self.x = 0
  926. self.y = (Graphics.height - self.height) / 2
  927. when :center_right
  928. self.x = Graphics.width - self.height
  929. self.y = (Graphics.height - self.height) / 2
  930. end
  931. end
  932. #----------------------------------------------------------------------------
  933. # • Tamanho geral
  934. #----------------------------------------------------------------------------
  935. def size
  936. return self.width + self.height
  937. end
  938. #----------------------------------------------------------------------------
  939. # • Rect
  940. #----------------------------------------------------------------------------
  941. def rect
  942. return self.bitmap.rect
  943. end
  944. end
  945. #==============================================================================
  946. # • Bitmap
  947. #==============================================================================
  948. Dax.register(:bitmap)
  949. class Bitmap
  950. #-------------------------------------------------------------------------
  951. # Desenhar meter... Gradient
  952. #-------------------------------------------------------------------------
  953. def draw_meter_line(x, y, min, max, width = 156, height = 4,
  954. bar_start = Color.new(255, 0, 0, 192), bar_end = Color.new(255, 255, 0, 192),
  955. background = Color.new(0, 0, 0, 128))
  956. w = width * min / max
  957. 4.times do
  958. fill_rect(x + 8, y + 4, width, height / 4, background)
  959. draw_gradient_line(x, y, x + w, y, height / 4, bar_start, bar_end)
  960. x -= 1
  961. y += height / 4
  962. end
  963. end
  964. #----------------------------------------------------------------------------
  965. # • Definir gradiente..
  966. #----------------------------------------------------------------------------
  967. def gradient_color(colors, width, percentage)
  968. width_per = ((width * 1.0) * percentage)
  969. width_per = width_per.round
  970. if colors.size == 1
  971. return colors[0]
  972. elsif colors.size > 1
  973. i = 0
  974. sections_per = (1.0 / colors.size)
  975. equationa = (sections_per * colors.size)
  976. equationb = (sections_per * (colors.size - 1))
  977. if equationa >= percentage and equationb < percentage
  978. i = (colors.size - 1)
  979. else
  980. for j in 0..(colors.size - 1)
  981. equationc = (sections_per * (j + 1))
  982. equationd = (sections_per * (j + 2))
  983. if equationc < percentage and equationd > percentage
  984. i = j + 1
  985. end
  986. end
  987. end
  988. if i == (colors.size - 1)
  989. for k in 0..width
  990. if k == width_per
  991. r = colors[i - 1].red * (width - k) / width + colors[i].red * k / width
  992. g = colors[i - 1].green * (width - k) / width + colors[i].green * k / width
  993. b = colors[i - 1].blue * (width - k) / width + colors[i].blue * k / width
  994. a = colors[i - 1].alpha * (width - k) / width + colors[i].alpha * k / width
  995. return Color.new(r,g,b,a)
  996. end
  997. end
  998. else
  999. for k in 0..width
  1000. if k == width_per
  1001. r = colors[i].red * (width - k) / width + colors[i + 1].red * k / width
  1002. g = colors[i].green * (width - k) / width + colors[i + 1].green * k / width
  1003. b = colors[i].blue * (width - k) / width + colors[i + 1].blue * k / width
  1004. a = colors[i].alpha * (width - k) / width + colors[i + 1].alpha * k / width
  1005. return Color.new(r,g,b,a)
  1006. end
  1007. end
  1008. end
  1009. elsif colors.size < 1
  1010. msgbox 'ERROR : No Colors Were Supplied'
  1011. exit
  1012. end
  1013. end
  1014. #----------------------------------------------------------------------------
  1015. # • Barra.
  1016. #----------------------------------------------------------------------------
  1017. def bar(color, actual, max, borda=1)
  1018. rate = self.width.to_p(actual, max)
  1019. self.fill_rect(borda, borda, rate-(borda*2), self.height-(borda*2),
  1020. color)
  1021. end
  1022. #----------------------------------------------------------------------------
  1023. # • Barra em forma de gradient;.
  1024. #----------------------------------------------------------------------------
  1025. def gradient_bar(color, actual, max, borda=1)
  1026. rate = self.width.to_p(actual, max)
  1027. self.gradient_fill_rect(borda, borda, rate-(borda*2), self.height-(borda*2),
  1028. color[0], color[1], 2)
  1029. end
  1030. #----------------------------------------------------------------------------
  1031. # • Efeito de Shader Sill
  1032. #----------------------------------------------------------------------------
  1033. def shader_sill
  1034. ra = 500
  1035. re = 0 ; gr = 0 ; bl = 0
  1036. for i in 1..(self.height-1)
  1037. for j in 1..(self.width-1)
  1038. for m in -1..1
  1039. for n in -1..1
  1040. if m != 0 and n != 0
  1041. a = self.get_pixel(j+m,i+n)
  1042. re = re + a.red
  1043. gr = gr + a.green
  1044. bl = bl + a.blue
  1045. end
  1046. end
  1047. end
  1048. b = self.get_pixel(j,i)
  1049. re = (b.red-re/8).abs
  1050. gr = (b.green-gr/8).abs
  1051. bl = (b.blue-bl/8).abs
  1052. self.set_pixel(j,i,Color.new(0, 0, 0, b.alpha) )
  1053. end
  1054. end
  1055. end
  1056. #--------------------------------------------------------------------------
  1057. # * Desenho do gráfico do personagem
  1058. # character_name : nome do gráfico do personagem
  1059. # character_index : índice do gráfico de personagem
  1060. # x : coordenada X
  1061. # y : coordenada Y
  1062. #--------------------------------------------------------------------------
  1063. def draw_character(character_name, character_index, x, y)
  1064. return unless character_name
  1065. bitmap = Cache.character(character_name)
  1066. sign = character_name[/^[\!\$]./]
  1067. if sign && sign.include?('$')
  1068. cw = bitmap.width / 3
  1069. ch = bitmap.height / 4
  1070. else
  1071. cw = bitmap.width / 12
  1072. ch = bitmap.height / 8
  1073. end
  1074. n = character_index
  1075. src_rect = Rect.new((n%4*3+1)*cw, (n/4*4)*ch, cw, ch)
  1076. self.blt(x - cw / 2, y - ch, bitmap, src_rect)
  1077. end
  1078. #--------------------------------------------------------------------------
  1079. # * Desenho do gráfico de personagem do herói
  1080. # actor : herói
  1081. # x : coordenada X
  1082. # y : coordenada Y
  1083. #--------------------------------------------------------------------------
  1084. def draw_actor_graphic(actor, x, y)
  1085. draw_character(actor.character_name, actor.character_index, x, y)
  1086. end
  1087. #----------------------------------------------------------------------------
  1088. # • Limpar uma área num formato de círculo.
  1089. #----------------------------------------------------------------------------
  1090. def clear_rect_circle(x, y, r)
  1091. rr = r*r
  1092. for i in 0...r
  1093. adj = Math.sqrt(rr - (i*i)).ceil
  1094. xd = x - adj
  1095. wd = 2 * adj
  1096. self.clear_rect(xd, y-i, wd, 1)
  1097. self.clear_rect(xd, y+i, wd, 1)
  1098. end
  1099. end
  1100. #----------------------------------------------------------------------------
  1101. # • Novo modo de desenhar textos. Configurações já especificadas.
  1102. #----------------------------------------------------------------------------
  1103. def draw_text_rect(*args)
  1104. self.draw_text(self.rect, *args)
  1105. end
  1106. #----------------------------------------------------------------------------
  1107. # • Salvar em png.
  1108. # --- Autor : Gab! ---
  1109. #----------------------------------------------------------------------------
  1110. def save(file_name)
  1111. def chunk(type, data)
  1112. [data.size, type, data, Zlib.crc32(type + data)].pack("NA4A*N")
  1113. end
  1114. img_data = ""
  1115. width, height = self.width, self.height
  1116. for j in 0...(height)
  1117. img_data << "\0"
  1118. for i in 0...(width)
  1119. pos_c = self.get_pixel(i, j)
  1120. img_data << [pos_c.red, pos_c.green, pos_c.blue, pos_c.alpha].pack("C*")
  1121. end
  1122. end
  1123. c = [
  1124. "\x89PNG\r\n\x1a\n",
  1125. chunk("IHDR", [width, height, 8, 6, 0, 0, 0].pack("N2C5")),
  1126. chunk("IDAT", Zlib::Deflate.deflate(img_data)),
  1127. chunk("IEND", "")
  1128. ]
  1129. File.open(file_name, "wb"){|file| c.each{|chunk| file.write(chunk) }}
  1130. end
  1131. #----------------------------------------------------------------------------
  1132. # • Efeito negativo.
  1133. #----------------------------------------------------------------------------
  1134. def negative
  1135. for i in 0...(self.width)
  1136. for j in 0...(self.height)
  1137. pix = self.get_pixel(i, j)
  1138. pix.red = (pix.red - 255) * -1
  1139. pix.blue = (pix.blue - 255) * -1
  1140. pix.green = (pix.green - 255) * -1
  1141. self.set_pixel(i, j, pix)
  1142. end
  1143. end
  1144. end
  1145. #----------------------------------------------------------------------------
  1146. # • Grayscale
  1147. #----------------------------------------------------------------------------
  1148. def grayscale(rect = Rect.new(0, 0, self.width, self.height))
  1149. for i in rect.x...rect.x + rect.width
  1150. for j in rect.y...rect.y + rect.height
  1151. colour = self.get_pixel(i,j)
  1152. grey_pixel = (colour.red*0.3 + colour.green*0.59 + colour.blue*0.11)
  1153. colour.red = colour.green = colour.blue = grey_pixel
  1154. self.set_pixel(i,j,colour)
  1155. end
  1156. end
  1157. end
  1158. #----------------------------------------------------------------------------
  1159. # • Novo fornecedor de pixel.
  1160. #----------------------------------------------------------------------------
  1161. def set_pixel_s(x, y, color, size)
  1162. for i in 0...size
  1163. self.set_pixel(x+i, y, color)
  1164. self.set_pixel(x-i, y, color)
  1165. self.set_pixel(x, y+i, color)
  1166. self.set_pixel(x, y-i, color)
  1167. self.set_pixel(x+i, y+i, color)
  1168. self.set_pixel(x-i, y-i, color)
  1169. self.set_pixel(x+i, y-i, color)
  1170. self.set_pixel(x-i, y+i, color)
  1171. end
  1172. end
  1173. #----------------------------------------------------------------------------
  1174. # • Desenhar uma linha.
  1175. #----------------------------------------------------------------------------
  1176. def draw_line(start_x, start_y, end_x, end_y, color, size=1)
  1177. set_pixel_s(start_x, start_y, color, size)
  1178. distance = (start_x - end_x).abs + (start_y - end_y).abs
  1179. for i in 1..distance
  1180. x = (start_x + 1.0 * (end_x - start_x) * i / distance).to_i
  1181. y = (start_y + 1.0 * (end_y - start_y) * i / distance).to_i
  1182. set_pixel_s(x, y, color, size)
  1183. end
  1184. set_pixel_s(end_x, end_y, color, size)
  1185. end
  1186. #----------------------------------------------------------------------------
  1187. # • draw_bar_gauge(x, y, current, current_max, border, colors)
  1188. # x : Coordenadas X.
  1189. # y : Coordenadas Y.
  1190. # current : Valor atual da barra.
  1191. # current_max : Valor maxímo da barra.
  1192. # border : Expressura da borda.
  1193. # colors : Cores. [0, 1, 2]
  1194. #----------------------------------------------------------------------------
  1195. # Permite adicionar uma barra.
  1196. #----------------------------------------------------------------------------
  1197. def draw_bar_gauge(x, y, current, current_max, colors=[])
  1198. cw = self.width.to_p(current, current_max)
  1199. ch = self.height
  1200. self.gradient_fill_rect(x, y, self.width, self.height, colors[0], colors[1])
  1201. src_rect = Rect.new(0, 0, cw, ch)
  1202. self.blt(x, y, self, src_rect)
  1203. end
  1204. #----------------------------------------------------------------------------
  1205. # • draw_icon(icon_index, x, y, enabled)
  1206. # icon_index : ID do ícone.
  1207. # x : Coordenadas X.
  1208. # y : Coordenadas Y.
  1209. # enabled : Habilitar flag, translucido quando false
  1210. #----------------------------------------------------------------------------
  1211. #----------------------------------------------------------------------------
  1212. def draw_icon(icon_index, x, y, enabled = true)
  1213. icon_index = icon_index.nil? ? 0 : icon_index
  1214. bitmap = Cache.system("Iconset")
  1215. rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  1216. self.blt(x, y, bitmap, rect, enabled ? 255 : 128)
  1217. end
  1218. #----------------------------------------------------------------------------
  1219. # • draw_gradation_gauge(x, y, width, height, current, current_max, border, colors, align)
  1220. # x : Coordenadas X.
  1221. # y : Coordenadas Y.
  1222. # width : Largura da barra.
  1223. # height : Altura da barra.
  1224. # current : Valor atual da barra.
  1225. # current_max : Valor maxímo da barra.
  1226. # border : Expressura da borda.
  1227. # colors : Cores. [0, 1, 2]
  1228. # align : Alinhamento.
  1229. #----------------------------------------------------------------------------
  1230. # Permite adicionar uma barra.
  1231. #----------------------------------------------------------------------------
  1232. def draw_gradation_gauge(x, y, current, current_max, border, colors=[])
  1233. cw = self.width.to_p(current, current_max)
  1234. ch = self.height
  1235. self.fill_rect(x, y, self.width, self.height, colors[0])
  1236. self.gradient_fill_rect(x+border, y+border, self.width-(border/2), self.height-(border/2), colors[1], colors[2])
  1237. src_rect = Rect.new(0, 0, cw, ch)
  1238. self.blt(x, y, self, src_rect)
  1239. end
  1240. #--------------------------------------------------------------------------
  1241. # • Desenho do gráfico de rosto
  1242. # face_name : nome do gráfico de face
  1243. # face_index : índice do gráfico de face
  1244. # x : coordenada X
  1245. # y : coordenada Y
  1246. # enabled : habilitar flag, translucido quando false
  1247. #--------------------------------------------------------------------------
  1248. def draw_face(face_name, face_index, x, y, enabled = true)
  1249. bitmap = Cache.face(face_name)
  1250. rect = Rect.new(face_index % 4 * 96, face_index / 4 * 96, 96, 96)
  1251. self.blt(x, y, bitmap, rect, enabled ? 255 : 128)
  1252. end
  1253. #--------------------------------------------------------------------------
  1254. # • Desenho do gráfico de face do herói
  1255. # actor : herói
  1256. # x : coordenada X
  1257. # y : coordenada Y
  1258. # enabled : habilitar flag, translucido quando false
  1259. #--------------------------------------------------------------------------
  1260. def draw_actor_face(actor, x, y, enabled = true)
  1261. draw_face(actor.face_name, actor.face_index, x, y, enabled)
  1262. end
  1263. #--------------------------------------------------------------------------
  1264. # • Desenho do nível
  1265. # actor : herói
  1266. # x : coordenada X
  1267. # y : coordenada Y
  1268. #--------------------------------------------------------------------------
  1269. def draw_actor_level(actor, x, y)
  1270. self.font.name = "Comic Sans MS"
  1271. self.font.color = ColorBasic[35]
  1272. self.font.size = 18
  1273. self.draw_text(x, y, 32, 20, Vocab::level_a)
  1274. self.font.size = 22
  1275. draw_text(x + 16, y, 32, 20, actor.level, 2)
  1276. end
  1277. #----------------------------------------------------------------------------
  1278. # • Desenhar um círuclo preenchido.
  1279. #----------------------------------------------------------------------------
  1280. def fill_circle(x, y, r, c)
  1281. rr = r*r
  1282. for i in 0...r
  1283. adj = Math.sqrt(rr - (i*i)).ceil
  1284. xd = x - adj
  1285. wd = 2 * adj
  1286. self.fill_rect(xd, y-i, wd, 1, c)
  1287. self.fill_rect(xd, y+i, wd, 1, c)
  1288. end
  1289. end
  1290. #----------------------------------------------------------------------------
  1291. # • Desenhar um triângulo preenchido
  1292. #----------------------------------------------------------------------------
  1293. def fill_triangle3(pts, c, pos=[0, 0])
  1294. return if pts.size != 3
  1295. pts.sort! {|a, b| a[1] - b[1]}
  1296. pt1, pt2, pt3 = pts
  1297. dxt = (pt3[0] - pt1[0]) / 2
  1298. dyt = (pt3[1] - pt1[1]) / 2
  1299. dxm = pt2[0] - pt1[0]
  1300. dym = pt2[1] - pt1[1]
  1301. dm = dym.abs
  1302. if dm > 0 and dyt != 0
  1303. for i in 0...(dm+2)
  1304. ix = ((dxm*i) / (dm+1))
  1305. iy = ((dym*i) / (dm+1))
  1306. edx = ix - (dxt * iy / dyt)
  1307. self.fill_rect(ix+pt1[0]-[edx,0].max-2+pos[0], iy+pt1[1]+pos[1], edx.abs+4, 1, c)
  1308. end
  1309. end
  1310. dxm = pt2[0] - pt3[0]
  1311. dym = pt2[1] - pt3[1]
  1312. dm = dym.abs
  1313. if dm > 0 and dyt != 0
  1314. for i in 0...(dm+2)
  1315. ix = ((dxm*i) / (dm+1))
  1316. iy = ((dym*i) / (dm+1))
  1317. edx = ix - (dxt * iy / dyt)
  1318. self.fill_rect(ix+pt3[0]-[edx,0].max-2+pos[0], iy+pt3[1]+pos[1], edx.abs+4, 1, c)
  1319. end
  1320. end
  1321. end
  1322. #----------------------------------------------------------------------------
  1323. # • Desenhar um polígono.
  1324. #----------------------------------------------------------------------------
  1325. def fill_polygon(pts, c, pos=[0, 0])
  1326. return if pts.size <= 2
  1327. n = pts.size - 2
  1328. for i in 0...n
  1329. self.fill_triangle3(pts[i..(i + 2)], c, pos)
  1330. end
  1331. end
  1332. end
  1333. #==============================================================================
  1334. # • Mouse
  1335. #==============================================================================
  1336. Dax.register(:Mouse, "Dax", 1.1)
  1337. module Mouse
  1338. extend self
  1339. #--------------------------------------------------------------------------
  1340. # • Inicialização dos objetos.
  1341. #--------------------------------------------------------------------------
  1342. def start
  1343. @cursor = Sprite.new
  1344. @cursor.z = 100000
  1345. @cursor.bitmap = Bitmap.new(1, 1)
  1346. x = Dax::Mouse_Name == "" ? 1 : 0
  1347. API::MouseShowCursor.call(x)
  1348. @dgraphic = Dax::Mouse_Name
  1349. graphic Dax::Mouse_Name
  1350. update
  1351. end
  1352. #--------------------------------------------------------------------------
  1353. # • graphic(graphic_set)
  1354. # graphic_set : Se for número é um ícone; Se for string é uma imagem.
  1355. #--------------------------------------------------------------------------
  1356. def graphic(graphic_set)
  1357. return if graphic_set == "" or graphic_set.nil?
  1358. if graphic_set.is_a?(Fixnum)
  1359. @cursor.bitmap = Bitmap.new(24, 24)
  1360. @cursor.bitmap.draw_icon(graphic_set.to_i, 0, 0)
  1361. else
  1362. @cursor.bitmap = Cache.picture(graphic_set.to_s)
  1363. end
  1364. @dgraphic = graphic_set
  1365. end
  1366. #--------------------------------------------------------------------------
  1367. # • show(visible)
  1368. # visible : True - para mostrar o mouse | False - para esconder o mouse.
  1369. #--------------------------------------------------------------------------
  1370. def show(visible=true)
  1371. @cursor.visible = visible
  1372. end
  1373. #--------------------------------------------------------------------------
  1374. # • update (Atualização das coordenadas)
  1375. #--------------------------------------------------------------------------
  1376. def update
  1377. return if @cursor.nil?
  1378. @cursor.x, @cursor.y = position
  1379. end
  1380. #--------------------------------------------------------------------------
  1381. # • cursor
  1382. #--------------------------------------------------------------------------
  1383. def cursor
  1384. @cursor
  1385. end
  1386. #--------------------------------------------------------------------------
  1387. # • x (Coordenada X do Mouse)
  1388. #--------------------------------------------------------------------------
  1389. def x
  1390. @cursor.x
  1391. end
  1392. #--------------------------------------------------------------------------
  1393. # • y (Coordenada Y do Mouse)
  1394. #--------------------------------------------------------------------------
  1395. def y
  1396. @cursor.y
  1397. end
  1398. #--------------------------------------------------------------------------
  1399. # • position (Posição do Mouse!)
  1400. #--------------------------------------------------------------------------
  1401. def position
  1402. x, y = get_client_position
  1403. return x, y
  1404. end
  1405. #--------------------------------------------------------------------------
  1406. # • get_client_position (Posição original do Mouse!)
  1407. #--------------------------------------------------------------------------
  1408. def get_client_position
  1409. pos = [0, 0].pack('ll')
  1410. API::CursorPosition.call(pos)
  1411. API::ScreenToClient.call(WINDOW, pos)
  1412. return pos.unpack('ll')
  1413. end
  1414. #--------------------------------------------------------------------------
  1415. # • find_window (Tamanho da window)
  1416. #--------------------------------------------------------------------------
  1417. def find_window
  1418. game_name = '\0' * 256
  1419. API::ReadIni.call('Game', 'Title', '', game_name, 255, '.\\Game.ini')
  1420. game_name.delete!('\0') ensure game_name
  1421. return API::FindWindow.call('RGSS Player', game_name)
  1422. end
  1423. #--------------------------------------------------------------------------
  1424. # • Verificação se o mouse está na área de um determinado objeto.
  1425. #--------------------------------------------------------------------------
  1426. def in_area?(object_sprite)
  1427. return @cursor.x.between?(object_sprite.x, object_sprite.x + object_sprite.width) &&
  1428. @cursor.y.between?(object_sprite.y, object_sprite.y + object_sprite.height)
  1429. end
  1430. #----------------------------------------------------------------------------
  1431. # • Mudar posição do cursor.
  1432. #----------------------------------------------------------------------------
  1433. def set_mouse(pos)
  1434. SetCursorPos.call(pos.x, pos.y)
  1435. update
  1436. @cursor.x = @pos.x
  1437. @cursor.y = @pos.y
  1438. end
  1439. WINDOW = find_window
  1440. end
  1441.  
  1442. #==============================================================================
  1443. # • Object
  1444. #==============================================================================
  1445. Dax.register(:object)
  1446. class Object
  1447. #----------------------------------------------------------------------------
  1448. # • Profunda cópia
  1449. #----------------------------------------------------------------------------
  1450. def deep_clone
  1451. Marshal.load(Marshal.dump(self))
  1452. end
  1453. #----------------------------------------------------------------------------
  1454. # * Trigger ou Repeat
  1455. #----------------------------------------------------------------------------
  1456. def trigger_or_repeat?(key)
  1457. trigger?(key) or repeat?(key)
  1458. end
  1459. #----------------------------------------------------------------------------
  1460. # • Trigger
  1461. #----------------------------------------------------------------------------
  1462. def trigger?(key)
  1463. return key.is_a?(Symbol) ? Input.trigger?(key) : Key.trigger?(key)
  1464. end
  1465. #----------------------------------------------------------------------------
  1466. # • Press
  1467. #----------------------------------------------------------------------------
  1468. def press?(key)
  1469. return key.is_a?(Symbol) ? Input.press?(key) : Key.press?(key)
  1470. end
  1471. #----------------------------------------------------------------------------
  1472. # • Repeat
  1473. #----------------------------------------------------------------------------
  1474. def repeat?(key)
  1475. return key.is_a?(Symbol) ? Input.repeat?(key) : Key.repeat?(key)
  1476. end
  1477. end
  1478. #==============================================================================
  1479. # • Entries
  1480. #==============================================================================
  1481. Dax.register(:entries)
  1482. class Entries
  1483. #----------------------------------------------------------------------------
  1484. # • Variável pública da instância.
  1485. #----------------------------------------------------------------------------
  1486. attr_accessor :file
  1487. attr_reader :get_number
  1488. attr_reader :get_file
  1489. attr_reader :get_array
  1490. attr_reader :name
  1491. #----------------------------------------------------------------------------
  1492. # • Inicialização dos objetos.
  1493. #----------------------------------------------------------------------------
  1494. def initialize(directory, typefile)
  1495. return unless FileTest.directory?(directory)
  1496. @file = Dir.glob(directory + "/*.{" + typefile + "}")
  1497. @file.each_index { |i| @get_number = i.to_i }
  1498. @file.each { |i| @get_file = i.to_s }
  1499. @file.each_with_index { |i| @get_array = i }
  1500. @name = split @file[0]
  1501. end
  1502. #----------------------------------------------------------------------------
  1503. # • Split | Separar
  1504. #----------------------------------------------------------------------------
  1505. def split(file)
  1506. file.to_s.split('/').last
  1507. end
  1508. #----------------------------------------------------------------------------
  1509. # • Obter nome.
  1510. #----------------------------------------------------------------------------
  1511. def name(id)
  1512. return split(@file[id])
  1513. end
  1514. end
  1515. #==============================================================================
  1516. # • TextBase
  1517. #==============================================================================
  1518. Dax.register(:text_base)
  1519. class TextBase
  1520. #----------------------------------------------------------------------------
  1521. # • Inicialização dos objetos.
  1522. #----------------------------------------------------------------------------
  1523. def initialize
  1524. @text = ""
  1525. end
  1526. #----------------------------------------------------------------------------
  1527. # • Adicionar texto.
  1528. #----------------------------------------------------------------------------
  1529. def text=(text_add)
  1530. @text += text_add
  1531. end
  1532. #----------------------------------------------------------------------------
  1533. # • Adicionar uma nova linha.
  1534. #----------------------------------------------------------------------------
  1535. def text(text, nspace=0)
  1536. @text += "\r\n" + (" " * nspace) + text
  1537. end
  1538. #----------------------------------------------------------------------------
  1539. # • Adicionar comentário;
  1540. #----------------------------------------------------------------------------
  1541. def comment=(text_add, comment="#")
  1542. @text += comment + text_add
  1543. end
  1544. #----------------------------------------------------------------------------
  1545. # • Adicionar uma nova linha como comentário.
  1546. #----------------------------------------------------------------------------
  1547. def comment(text, nspace=0, comment="#")
  1548. @text += "\r\n" + (" " * nspace) + comment + text
  1549. end
  1550. #----------------------------------------------------------------------------
  1551. # • Salvar o texto.
  1552. #----------------------------------------------------------------------------
  1553. def save(filename="")
  1554. _file = File.open(filename, "a+").each { |file|
  1555. file.write(@text.to_s)
  1556. file.close
  1557. }
  1558. end
  1559. end
  1560. #==============================================================================
  1561. # • DRGSS | Comandos do RGSS...
  1562. #==============================================================================
  1563. Dax.register(:drgss)
  1564. module DRGSS
  1565. extend self
  1566. #----------------------------------------------------------------------------
  1567. # • Deleta a pasta, os arquivos.
  1568. #----------------------------------------------------------------------------
  1569. def recursive_delete(dir)
  1570. files = []
  1571. Dir.foreach(dir) do |fname|
  1572. next if fname == '.' || fname == '..'
  1573. path = dir + '/' + fname
  1574. if File.directory?(path)
  1575. puts "dir #{path}"
  1576. recursive_delete(path)
  1577. else
  1578. puts "file #{path}"
  1579. files << path
  1580. end
  1581. end
  1582. files.each do |path|
  1583. msgbox "delete file #{path}"
  1584. end
  1585. msgbox "delete dir #{dir}"
  1586. Dir.rmdir(dir)
  1587. end
  1588. #----------------------------------------------------------------------------
  1589. # • Deleta tudo.. Só use caso você saiba o que está fazendo
  1590. #----------------------------------------------------------------------------
  1591. def delete(directory)
  1592. if File.directory?(directory)
  1593. Dir.foreach(directory) do |file_or_directory|
  1594. File.delete(directory+"/"+file_or_directory) if file_or_directory != "." and file_or_directory != ".."
  1595. end
  1596. else
  1597. begin
  1598. File.delete(directory) if File.new(directory).stat.size == 0
  1599. rescue
  1600. msgbox "#{$!} Error in deleting zero size file "
  1601. end
  1602. end
  1603. end
  1604. #----------------------------------------------------------------------------
  1605. # • Extrair scripts.
  1606. #----------------------------------------------------------------------------
  1607. def extract_scripts(type=".txt",options={})
  1608. except = options[:except] || []
  1609. folder = options[:folder] || ""
  1610. id = 0 #
  1611. $RGSS_SCRIPTS.each do |script|
  1612. name = script[1]
  1613. data = script[3]
  1614. next if except.include? name or name.empty? or data.empty?
  1615. filename = sprintf("%03d", id) + "_" + name
  1616. p "Writing: #{filename}"
  1617. File.open(folder+filename+"#{type}", "wb") do |file|
  1618. file.write data
  1619. end
  1620. id += 1
  1621. end
  1622. end
  1623. #----------------------------------------------------------------------------
  1624. # • Carregar scripts.
  1625. #----------------------------------------------------------------------------
  1626. def load_scripts(type=".txt",options={})
  1627. skip = options[:skip] || []
  1628. folder = options[:folder] || ""
  1629. begin
  1630. Dir.foreach(folder) do |file|
  1631. file_id = file[0,3].to_i
  1632. break if file_id == options[:limit]
  1633. next if file == "." or file == ".." or File.extname(file) != "#{type}" or skip.include?(file_id)
  1634. r = load (folder+"#{file}")
  1635. p "Loaded: #{r}"
  1636. end
  1637. end
  1638. end
  1639. end
  1640. #==============================================================================
  1641. # • Módulo Touch
  1642. #==============================================================================
  1643. Dax.register(:touch)
  1644. module Touch
  1645. #============================================================================
  1646. # * Picture : Sistema onde você define uma imagem na qual pode ser acessada
  1647. # pelo mouse.
  1648. #============================================================================
  1649. class Picture < Sprite
  1650. #--------------------------------------------------------------------------
  1651. # * Variáveis públicas da instância;
  1652. #--------------------------------------------------------------------------
  1653. attr_accessor :show
  1654. #--------------------------------------------------------------------------
  1655. # ** Inicialização dos objetos **
  1656. #--------------------------------------------------------------------------
  1657. # Argumentos do método *** : ***
  1658. #
  1659. # name/args[0] : Nome do arquivo.
  1660. # x/args[1] : Coordenada X
  1661. # y/args[2] : Coordenada Y
  1662. # switche/args[3] : ID da switche para que quando ela estiver ativada, você não
  1663. # poderá acessar a imagem, caso ela não esteja ativada, você poderá
  1664. # acessar a imagem, agora caso você coloque 'nil' ela poderá ser acessada
  1665. # a qualquer momento.
  1666. # mode/args[4] : 0 - Para identificar se o arquivo está na pasta System
  1667. # 1 - Para identificar se o arquivo está na pasta Picture.
  1668. #--------------------------------------------------------------------------
  1669. def initialize(*args)
  1670. super((args[4] == 0 ? "S: " : "P: ") + args[0])
  1671. [1, 2].each { |number| self.x, self.y = args[number] }
  1672. @clicked, @in_area, @switche_id = false, args[3], false
  1673. self.z = 200
  1674. end
  1675. #--------------------------------------------------------------------------
  1676. # * Verifica se está na área do objeto.
  1677. #--------------------------------------------------------------------------
  1678. def in_area?
  1679. return @in_area
  1680. end
  1681. #--------------------------------------------------------------------------
  1682. # * Renovar os objetos
  1683. #--------------------------------------------------------------------------
  1684. def dispose
  1685. self.bitmap.dispose
  1686. super
  1687. end
  1688. #--------------------------------------------------------------------------
  1689. # * Atualizar os objetos.
  1690. #--------------------------------------------------------------------------
  1691. def update
  1692. self.visible = !$game_switches[@switche_id] unless @switche_id.nil?
  1693. if @show
  1694. if Mouse.in_area?(self)
  1695. @in_area = true
  1696. effect_on_area?
  1697. @clicked = trigger_or_repeat?(0x01)
  1698. action if @clicked && trigger_or_repeat?(0x01)
  1699. else
  1700. @in_area = false
  1701. effect_off_area?
  1702. @clicked = false if trigger_or_repeat?(0x01)
  1703. end
  1704. else
  1705. self.opacity = 0
  1706. end
  1707. end
  1708. #--------------------------------------------------------------------------
  1709. # * Ação ao clicar o mouse.
  1710. #--------------------------------------------------------------------------
  1711. def action
  1712. end
  1713. #--------------------------------------------------------------------------
  1714. # * Efeito de quando estiver na área.
  1715. #--------------------------------------------------------------------------
  1716. def effect_on_area?
  1717. self.opacity = 255
  1718. end
  1719. #--------------------------------------------------------------------------
  1720. # * Efeito de quando não estiver na área.
  1721. #--------------------------------------------------------------------------
  1722. def effect_off_area?
  1723. self.opacity = 127.5
  1724. end
  1725. end
  1726. #============================================================================
  1727. # * Simple_Picture : Versão simplificada da Picture
  1728. #============================================================================
  1729. class Simple_Picture < Picture
  1730. #--------------------------------------------------------------------------
  1731. # * Inicialização dos objetos
  1732. #--------------------------------------------------------------------------
  1733. def initialize(action, *args)
  1734. end
  1735. #--------------------------------------------------------------------------
  1736. # * Renovar
  1737. #--------------------------------------------------------------------------
  1738. def dispose
  1739. super
  1740. end
  1741. #--------------------------------------------------------------------------
  1742. # * Atualizar
  1743. #--------------------------------------------------------------------------
  1744. def update
  1745. super
  1746. end
  1747. #--------------------------------------------------------------------------
  1748. # * Ação
  1749. #--------------------------------------------------------------------------
  1750. def action
  1751. unless action.nil?
  1752. eval(action.to_s)
  1753. else
  1754. eval(@action.to_s) unless @action.nil?
  1755. end
  1756. end
  1757. #--------------------------------------------------------------------------
  1758. # * Efeito da área
  1759. #--------------------------------------------------------------------------
  1760. def effect_on_area?; super; end;
  1761. def effect_off_area?; super; end;
  1762. def in_area?; super; end;
  1763. #--------------------------------------------------------------------------
  1764. # * Conteúdo
  1765. #--------------------------------------------------------------------------
  1766. def self; self; end;
  1767. end
  1768. #============================================================================
  1769. # * Icon
  1770. #============================================================================
  1771. class Icon < Sprite
  1772. #--------------------------------------------------------------------------
  1773. # • Inicialização dos objetos.
  1774. # id : ID do ícone no database.
  1775. # x : Posição X do objeto.
  1776. # y : Posição Y do objeto.
  1777. # z : Altura do objeto.
  1778. #--------------------------------------------------------------------------
  1779. def initialize(*args)
  1780. super([24, 24])
  1781. (1..3).each { |number| self.x, self.y, self.z = args[number] }
  1782. self.bitmap.draw_icon(args[0].to_i, 0, 0)
  1783. @clicked = false
  1784. @switche_id = args[4]
  1785. @effect = args[5]
  1786. end
  1787. #--------------------------------------------------------------------------
  1788. # • Renovação dos objetos.
  1789. #--------------------------------------------------------------------------
  1790. def dispose
  1791. self.bitmap.dispose if !self.bitmap.nil?
  1792. super
  1793. end
  1794. #--------------------------------------------------------------------------
  1795. # • Atualizaçaõ dos objetos.
  1796. # action_clicked : Caso seja um nome em formato de String irá chamar uma
  1797. # scene, caso seja em formato de número irá chamar um evento comum.
  1798. #--------------------------------------------------------------------------
  1799. def update
  1800. if @effect == :visible then self.visible = !$game_switches[@switche_id] unless @switche_id.nil? end
  1801. unless @switche_id.nil? then self.opacity = 64 if @effect == :opacity and !$game_switches[@switche_id] end
  1802. if Mouse.in_area?(self)
  1803. effect_on_area?
  1804. @clicked = trigger?(0x01) or repeat?(0x01)
  1805. action if @clicked && trigger?(0x01) or repeat?(0x01)
  1806. else
  1807. effect_off_area?
  1808. @clicked = false if trigger?(0x01) or repeat?(0x01)
  1809. end
  1810. end
  1811. #----------------------------------------------------------------------------
  1812. # • Acão após o clique na imagem.
  1813. #----------------------------------------------------------------------------
  1814. def action
  1815. return if self.visible or self.opacity == 64
  1816. end
  1817. #----------------------------------------------------------------------------
  1818. # • Efeito quando estiver na área.
  1819. #----------------------------------------------------------------------------
  1820. def effect_on_area?
  1821. self.opacity = 255
  1822. end
  1823. #----------------------------------------------------------------------------
  1824. # • Efeito quando estiver fora da área.
  1825. #----------------------------------------------------------------------------
  1826. def effect_off_area?(new=nil)
  1827. self.opacity = new.nil? ? 128 : new
  1828. end
  1829. end
  1830. #==============================================================================
  1831. # • Simple_Icon
  1832. #============================================================================
  1833. class Simple_Icon < Icon
  1834. #----------------------------------------------------------------------------
  1835. # • Inicialização dos objetos.
  1836. #----------------------------------------------------------------------------
  1837. def initialize(action, *args)
  1838. super(*args)
  1839. self.opacity = 128
  1840. @action = action
  1841. end
  1842. #----------------------------------------------------------------------------
  1843. # • Renovação dos objetos.
  1844. #----------------------------------------------------------------------------
  1845. def dispose
  1846. super
  1847. end
  1848. #----------------------------------------------------------------------------
  1849. # • Atualização dos objetos.
  1850. #----------------------------------------------------------------------------
  1851. def update
  1852. super
  1853. end
  1854. #----------------------------------------------------------------------------
  1855. # • Ação após o clique.
  1856. #----------------------------------------------------------------------------
  1857. def action
  1858. super
  1859. eval(@action.to_s) unless @action.nil?
  1860. end
  1861. #----------------------------------------------------------------------------
  1862. # • Efeito do objeto quando estiver na área.
  1863. #----------------------------------------------------------------------------
  1864. def effect_on_area?
  1865. super
  1866. end
  1867. #----------------------------------------------------------------------------
  1868. # • Efeito do objeto quando estiver fora da área.
  1869. #----------------------------------------------------------------------------
  1870. def effect_off_area?(value=nil)
  1871. super(value)
  1872. end
  1873. #----------------------------------------------------------------------------
  1874. # • Retorna ao conteúdo.
  1875. #----------------------------------------------------------------------------
  1876. def contents
  1877. self
  1878. end
  1879. end
  1880. #==============================================================================
  1881. # • Mouse Extension | Touch Text
  1882. #==============================================================================
  1883. class Text < Sprite
  1884. #----------------------------------------------------------------------------
  1885. # • Inicialização dos objetos.
  1886. # id : ID do ícone no database.
  1887. # x : Posição X do objeto.
  1888. # y : Posição Y do objeto.
  1889. # z : Altura do objeto.
  1890. #----------------------------------------------------------------------------
  1891. def initialize(text="", x=0, y=0, z=0, switche_id=nil,color=[ColorBasic[-1], ColorBasic[7]],font=["Arial", 16],align=0)
  1892. super([font[1] + (text.split(//).size ** 2), args[6][1]])
  1893. (1..3).each { |xyz| self.x, self.y, self.z = args[xyz] }
  1894. self.bitmap.draw_text(0, 0, self.width, self.height, args[0], args[7])
  1895. @clicked = false
  1896. @switche_id = args[4]
  1897. @color = args[5]
  1898. self.bitmap.font.name, self.bitmap.font.size = args[6]
  1899. end
  1900. #----------------------------------------------------------------------------
  1901. # • Renovação dos objetos.
  1902. #----------------------------------------------------------------------------
  1903. def dispose
  1904. self.bitmap.dispose if !self.bitmap.nil?
  1905. super
  1906. end
  1907. #----------------------------------------------------------------------------
  1908. # • Atualizaçaõ dos objetos.
  1909. # action_clicked : Caso seja um nome em formato de String irá chamar uma
  1910. # scene, caso seja em formato de número irá chamar um evento comum.
  1911. #----------------------------------------------------------------------------
  1912. def update
  1913. self.visible = !$game_switches[@switche_id] unless @switche_id.nil?
  1914. if Mouse.in_area?(self)
  1915. effect_on_area?
  1916. @clicked = trigger?(0x01) or repeat?(0x01)
  1917. action if @clicked && trigger?(0x01) or repeat?(0x01)
  1918. else
  1919. effect_off_area?
  1920. @clicked = false if trigger?(0x01) or repeat?(0x01)
  1921. end
  1922. end
  1923. #----------------------------------------------------------------------------
  1924. # • Acão após o clique na imagem.
  1925. #----------------------------------------------------------------------------
  1926. def action
  1927.  
  1928. end
  1929. #----------------------------------------------------------------------------
  1930. # • Efeito quando estiver na área.
  1931. #----------------------------------------------------------------------------
  1932. def effect_on_area?
  1933. self.color = @color[1]
  1934. end
  1935. #----------------------------------------------------------------------------
  1936. # • Efeito quando estiver fora da área.
  1937. #----------------------------------------------------------------------------
  1938. def effect_off_area?
  1939. self.color = @color[0]
  1940. end
  1941. end
  1942. #============================================================================
  1943. # Simple Touch Icon
  1944. #============================================================================
  1945. class Simple_Text < Text
  1946. #----------------------------------------------------------------------------
  1947. # • Inicialização dos objetos.
  1948. #----------------------------------------------------------------------------
  1949. def initialize(action, *args)
  1950. super(*args)
  1951. @action = action
  1952. end
  1953. #----------------------------------------------------------------------------
  1954. # • Renovação dos objetos.
  1955. #----------------------------------------------------------------------------
  1956. def dispose
  1957. super
  1958. end
  1959. #----------------------------------------------------------------------------
  1960. # • Atualização dos objetos.
  1961. #----------------------------------------------------------------------------
  1962. def update
  1963. super
  1964. end
  1965. #----------------------------------------------------------------------------
  1966. # • Ação após o clique.
  1967. #----------------------------------------------------------------------------
  1968. def action
  1969. eval(@action.to_s) unless @action.nil?
  1970. end
  1971. #----------------------------------------------------------------------------
  1972. # • Efeito do objeto quando estiver na área.
  1973. #----------------------------------------------------------------------------
  1974. def effect_on_area?
  1975. super
  1976. end
  1977. #----------------------------------------------------------------------------
  1978. # • Efeito do objeto quando estiver fora da área.
  1979. #----------------------------------------------------------------------------
  1980. def effect_off_area?
  1981. super
  1982. end
  1983. #----------------------------------------------------------------------------
  1984. # • Retorna ao conteúdo.
  1985. #----------------------------------------------------------------------------
  1986. def contents
  1987. self
  1988. end
  1989. end
  1990. end
  1991. #==============================================================================
  1992. # • OutlineFillRect
  1993. #==============================================================================
  1994. Dax.register(:outline_fill_rect)
  1995. class OutlineFillRect < Sprite
  1996. #----------------------------------------------------------------------------
  1997. # • Inicialização dos objetos.
  1998. #----------------------------------------------------------------------------
  1999. def initialize(object, max=2, color=ColorBasic[-1])
  2000. super([object.width, object.height])
  2001. @object = object
  2002. self.x, self.y, self.z = object.x, object.y, object.z
  2003. self.bitmap.fill_rect(0, 0, max, self.height, color)
  2004. self.bitmap.fill_rect(self.width-max, 0, max, self.height, color)
  2005. self.bitmap.fill_rect(0, 0, self.width, max, color)
  2006. self.bitmap.fill_rect(0, self.height-max, self.width, max, color)
  2007. end
  2008. #----------------------------------------------------------------------------
  2009. # • Renovação dos objetos.
  2010. #----------------------------------------------------------------------------
  2011. def dispose
  2012. self.bitmap.dispose unless self.bitmap.disposed?
  2013. super
  2014. end
  2015. #----------------------------------------------------------------------------
  2016. # • Atualização das coordenadas.
  2017. #----------------------------------------------------------------------------
  2018. def update
  2019. self.x, self.y, self.z = @object.x, @object.y, @object.z
  2020. end
  2021. end
  2022.  
  2023. #==============================================================================
  2024. # • BackupSystem
  2025. #==============================================================================
  2026. Dax.register :backupsystem
  2027. $BACKUP = <<_SCRIPT_
  2028. if $TEST
  2029. time = Time.now
  2030. Dir.mkdir('Backup') unless File.directory?('Backup')
  2031. ftype = 'rvdata2'
  2032. flist = Dir.glob('./Data/*.{' + ftype + '}')
  2033. flist.each_index do |i|
  2034. flist[i] = flist[i].split('/').last
  2035. save_data(load_data('Data/' + flist[i]), 'Backup' + '/' + flist[i])
  2036. end
  2037. print("Backup em:" + (Time.now - time).to_s + ' segundos')
  2038. end
  2039. _SCRIPT_
  2040. def backup; eval($BACKUP); end;
  2041. #==============================================================================
  2042. # • BackString
  2043. #==============================================================================
  2044. Dax.register :dstring
  2045. module DString
  2046. extend self
  2047. #----------------------------------------------------------------------------
  2048. # • Deletar a útlima letra de uma string..
  2049. #----------------------------------------------------------------------------
  2050. def backslash(text)
  2051. text2 = ""
  2052. text = text.to_s.split(//)
  2053. text[text.size-1] = "" unless text[0].to_s.empty?
  2054. for i in 0..text.size-1
  2055. text2 += text[i].to_s
  2056. end
  2057. return text2
  2058. end
  2059. end
  2060. #==============================================================================
  2061. # * SceneManager
  2062. #==============================================================================
  2063. Dax.register :scenemanager
  2064. class << SceneManager
  2065. #----------------------------------------------------------------------------
  2066. # • Chama uma scene através de uma palavra.;
  2067. #----------------------------------------------------------------------------
  2068. def symbol(scene_symbol)
  2069. eval("self.call(#{scene_symbol.to_s})")
  2070. end
  2071. end
  2072. #==============================================================================
  2073. # • Sprite_Text
  2074. #==============================================================================
  2075. Dax.register(:sprite_text)
  2076. class Sprite_Text < Sprite
  2077. #----------------------------------------------------------------------------
  2078. # • Variáveis públicas da instância.
  2079. #----------------------------------------------------------------------------
  2080. attr_accessor :text # Mudar de texto...
  2081. #----------------------------------------------------------------------------
  2082. # • Inicialização dos objetos.
  2083. #----------------------------------------------------------------------------
  2084. def initialize(x, y, width, height, text, align=0)
  2085. super([width, height])
  2086. self.x, self.y = x, y
  2087. @text = text
  2088. self.bitmap.draw_text_rect(@text, align)
  2089. end
  2090. #----------------------------------------------------------------------------
  2091. # • Renovação dos objetos.
  2092. #----------------------------------------------------------------------------
  2093. def dispose
  2094. self.bitmap.dispose
  2095. super
  2096. end
  2097. #----------------------------------------------------------------------------
  2098. # • Atualização dos objetos.
  2099. #----------------------------------------------------------------------------
  2100. def update
  2101. self.bitmap.clear
  2102. super
  2103. self.bitmap.draw_text_rect(@text)
  2104. end
  2105. end
  2106. #==============================================================================
  2107. # • Opacity
  2108. #==============================================================================
  2109. Dax.register(:opacity)
  2110. module Opacity
  2111. extend self
  2112. @key ||= {}
  2113. #----------------------------------------------------------------------------
  2114. # • Efeito de opacidade + e -.
  2115. #----------------------------------------------------------------------------
  2116. def sprite_opacity(sprite, speed, max, min, hash=nil)
  2117. unless @key[hash]
  2118. sprite.opacity += speed unless sprite.opacity >= max
  2119. @key[hash] = sprite.opacity >= max
  2120. else
  2121. sprite.opacity -= speed unless sprite.opacity <= min
  2122. @key[hash] = false if sprite.opacity <= min
  2123. end
  2124. end
  2125. #----------------------------------------------------------------------------
  2126. # • Efeito de opacidade por fora.
  2127. #----------------------------------------------------------------------------
  2128. def sprite_opacity_out(sprite, speed, max)
  2129. sprite.opacity += speed unless sprite.opacity >= max
  2130. end
  2131. #----------------------------------------------------------------------------
  2132. # • Efeito de opacidade por dentro.
  2133. #----------------------------------------------------------------------------
  2134. def sprite_opacity_in(sprite, speed, min)
  2135. sprite.opacity -= speed unless sprite.opacity <= min
  2136. end
  2137. #--------------------------------------------------------------------------
  2138. # • Efeito de fade out em massa
  2139. # time : duração (em milesegundo)
  2140. #--------------------------------------------------------------------------
  2141. def fadeout_all(time = 1000)
  2142. RPG::BGM.fade(time)
  2143. RPG::BGS.fade(time)
  2144. RPG::ME.fade(time)
  2145. Graphics.fadeout(time * Graphics.frame_rate / 1000)
  2146. RPG::BGM.stop
  2147. RPG::BGS.stop
  2148. RPG::ME.stop
  2149. end
  2150. end
  2151. #==============================================================================
  2152. # • Rpg
  2153. #==============================================================================
  2154. Dax.register(:rpg)
  2155. module Rpg
  2156. def self.data_manager
  2157. end
  2158. #============================================================================
  2159. # • Hud
  2160. #============================================================================
  2161. module Hud
  2162.  
  2163. end
  2164. #============================================================================
  2165. # • Menu
  2166. #============================================================================
  2167. module Menu
  2168. extend self
  2169. def include_item?(item)
  2170. item.is_a?(RPG::Item) && !item.key_item?
  2171. end
  2172. #--------------------------------------------------------------------------
  2173. # • Cursor...
  2174. #--------------------------------------------------------------------------
  2175. def cursor_up(variable, max)
  2176. variable += 1 unless variable > max
  2177. variable = 0 if variable > max
  2178. return variable
  2179. end
  2180. #--------------------------------------------------------------------------
  2181. # • Cursor...
  2182. #--------------------------------------------------------------------------
  2183. def cursor_down(variable, max)
  2184. variable -= 1 unless variable < 0
  2185. variable = max if variable < 0
  2186. return variable
  2187. end
  2188. end
  2189. #============================================================================
  2190. # • Battle
  2191. #============================================================================
  2192. module Battle
  2193. end
  2194. #============================================================================
  2195. # • Title
  2196. #============================================================================
  2197. module Title
  2198. end
  2199. end
  2200. #==============================================================================
  2201. # • String
  2202. #==============================================================================
  2203. class String
  2204. #----------------------------------------------------------------------------
  2205. # • Comandos.
  2206. #----------------------------------------------------------------------------
  2207. def script
  2208. if self.match(/sprite: ([^>]*)/)
  2209. return Sprite.new($1)
  2210. elsif self.match(/cb|CB: (\d+)/)
  2211. return ColorBasic[$1.to_i]
  2212. elsif self.match(/window: x: (\d+) y: (\d+) width: (\d+) height: (\d+)/)
  2213. return Window_Base.new($1.to_i, $2.to_i, $3.to_i, $4.to_i)
  2214. elsif self.match(/G: ([^>]*)/)
  2215. return "Graphics/#{$1}"
  2216. elsif self.match(/C:(\w+):([^>]*)/)
  2217. case $1
  2218. when "S"
  2219. return Cache.system($2.to_s)
  2220. when "P"
  2221. return Cache.picture($2.to_s)
  2222. when "Pl"
  2223. return Cache.parallax($2.to_s)
  2224. when "C"
  2225. return Cache.character($2.to_s)
  2226. when "A"
  2227. return Cache.animation($2.to_s)
  2228. when "B1"
  2229. return Cache.battleback1($2.to_s)
  2230. when "B2"
  2231. return Cache.battleback2($2.to_s)
  2232. when "B"
  2233. return Cache.battler($2.to_s)
  2234. when "F"
  2235. return Cache.face($2.to_s)
  2236. when "T1"
  2237. return Cache.title1($2.to_s)
  2238. when "T2"
  2239. return Cache.title2($2.to_s)
  2240. when "T"
  2241. return Cache.tileset($2.to_s)
  2242. end
  2243. elsif self.match(/scene_call: (\w+)/)
  2244. return eval("SceneManager.call(#{$1})")
  2245. elsif self.match(/scene_goto: (\w+)/)
  2246. return eval("SceneManager.goto(#{$1})")
  2247. elsif self.match(/text: x: (\d+) y: (\d+) width: (\d+) height: (\d+) text: ([^>]*)/)
  2248. return Sprite_Text.new($1.to_f, $2.to_f, $3.to_f, $4.to_f, $5.to_s)
  2249. elsif self.match(/r(\d+) g(\d+) b(\d+) a(\d+)/)
  2250. return Color.new($1.to_f, $2.to_f, $3.to_f, $4.to_f)
  2251. end
  2252. end
  2253. end
  2254. #==============================================================================
  2255. # • Txt
  2256. #==============================================================================
  2257. Dax.register(:read, "Dax")
  2258. module Read
  2259. extend self
  2260. #----------------------------------------------------------------------------
  2261. # • Verificar valor numérico após uma palavra em um arquivo.
  2262. #----------------------------------------------------------------------------
  2263. def numeric(file, tag)
  2264. IO.readlines(file).each do |line|
  2265. return $1.to_i if line.match(/#{tag} (\d+)/)
  2266. end
  2267. end
  2268. #----------------------------------------------------------------------------
  2269. # • Verificar valor de uma palavra(string única) após uma palavra em um arquivo
  2270. #----------------------------------------------------------------------------
  2271. def string(file, tag)
  2272. IO.readlines(file).each do |line|
  2273. return $1.to_s if line.match(/#{tag} (\w+)/)
  2274. end
  2275. end
  2276. #----------------------------------------------------------------------------
  2277. # • Verificar um conteúdo após uma palavra de um arquivo.
  2278. #----------------------------------------------------------------------------
  2279. def content(file, tag)
  2280. IO.readlines(file).each do |line|
  2281. return $1 if line.match(/#{tag} ([^>]*)/)
  2282. end
  2283. end
  2284. #----------------------------------------------------------------------------
  2285. # • Multiplo número..
  2286. #----------------------------------------------------------------------------
  2287. def multiple_numeric(file, tag)
  2288. IO.readlines(file).each do |line|
  2289. return [$1.to_i, $2.to_i] if line.match(/#{tag} (\d+), (\d+)/)
  2290. end
  2291. end
  2292. #----------------------------------------------------------------------------
  2293. # • Multiplo string..
  2294. #----------------------------------------------------------------------------
  2295. def multiple_string(file, tag)
  2296. IO.readlines(file).each do |line|
  2297. return [$1.to_s, $2.to_s] if line.match(/#{tag} (\w+), (\w+)/)
  2298. end
  2299. end
  2300. #----------------------------------------------------------------------------
  2301. # • Triplo número.
  2302. #----------------------------------------------------------------------------
  2303. def triple_numeric(file, tag)
  2304. IO.readlines(file).each do |line|
  2305. return [$1.to_i, $2.to_i, $3.to_i] if line.match(/#{tag} (\d+), (\d+), (\d+)/)
  2306. end
  2307. end
  2308. #----------------------------------------------------------------------------
  2309. # • Triplo string.
  2310. #----------------------------------------------------------------------------
  2311. def triple_string(file, tag)
  2312. IO.readlines(file).each do |line|
  2313. return [$1.to_s, $2.to_s, $3.to_s] if line.match(/#{tag} (\w+), (\w+), (\w+)/)
  2314. end
  2315. end
  2316. # true or false
  2317. def of(file, tag)
  2318. IO.readlines(file).each do |line|
  2319. return $1.to_s == "true" ? true : false if line.match(/#{tag} ([^>]*)/)
  2320. end
  2321. end
  2322. end
  2323.  
  2324. #==============================================================================
  2325. # • Background
  2326. #==============================================================================
  2327. Dax.register :background
  2328. module Background
  2329. extend self
  2330. #----------------------------------------------------------------------------
  2331. # • Plano de fundo padrão...
  2332. #----------------------------------------------------------------------------
  2333. def default(alpha=128)
  2334. @background = Sprite.new
  2335. @background.bitmap = SceneManager.background_bitmap
  2336. @background.color.set(16, 16, 16, alpha)
  2337. end
  2338. #----------------------------------------------------------------------------
  2339. # • Plano de fundo padrão renovado.
  2340. #----------------------------------------------------------------------------
  2341. def default_dispose
  2342. return if @background.nil?
  2343. @background.dispose
  2344. end
  2345. end
  2346. #==============================================================================
  2347. # * Window_Base
  2348. #==============================================================================
  2349. Dax.register(:window_base)
  2350. Dax.required_class("Window_Base") {
  2351. class Window_Base < Window
  2352. #----------------------------------------------------------------------------
  2353. # • Slide pela direita.
  2354. # * speed : Velocidade | point : Ponto da coordenada X que irá chegar.
  2355. #----------------------------------------------------------------------------
  2356. def slide_right(speed, point)
  2357. self.x += speed unless self.x >= point
  2358. end
  2359. #----------------------------------------------------------------------------
  2360. # • Slide pela esquerda.
  2361. # * speed : Velocidade | point : Ponto da coordenada X que irá chegar.
  2362. #----------------------------------------------------------------------------
  2363. def slide_left(speed, point)
  2364. self.x -= speed unless self.x <= point
  2365. end
  2366. #----------------------------------------------------------------------------
  2367. # • Slide por cima.
  2368. # * speed : Velocidade | point : Ponto da coordenada Y que irá chegar.
  2369. #----------------------------------------------------------------------------
  2370. def slide_up(speed, point)
  2371. self.y -= speed unless self.y <= point
  2372. end
  2373. #----------------------------------------------------------------------------
  2374. # • Slide por baixo.
  2375. # * speed : Velocidade | point : Ponto da coordenada Y que irá chegar.
  2376. #----------------------------------------------------------------------------
  2377. def slide_down(speed, point)
  2378. self.y += speed unless self.y >= point
  2379. end
  2380. end
  2381. }
  2382. #==============================================================================
  2383. # • Map
  2384. #==============================================================================
  2385. Dax.register(:map)
  2386. module Map
  2387. extend self
  2388. #----------------------------------------------------------------------------
  2389. # • Mapeiar área.
  2390. # map : Objeto [SPRITE].. que será escaniado..
  2391. # scan_sprite : Objeto [SPRITE].. que irá projetar o scan.
  2392. # color : Cor do scan.
  2393. #----------------------------------------------------------------------------
  2394. def char_area(map, scan_sprite, color=ColorBasic[-1])
  2395. _table = Table.new(map.width, map.height)
  2396. for x in 0..._table.xsize
  2397. for y in 0..._table.ysize
  2398. next if map.bitmap.get_pixel(x, y).alpha == 0
  2399. scan_sprite.bitmap.set_pixel(x, y, color)
  2400. end
  2401. end
  2402. end
  2403. #----------------------------------------------------------------------------
  2404. # • Colidir com determinada cor de um objeto sprite.
  2405. # ar : [largura, altura, bloqueio da esquerda, bloqueio de cima]
  2406. # object : Objeto a colidir. [SPRITE]
  2407. # map : Mapa. [SPRITE]
  2408. # color : Cor, na qual quando o objeto colidir com está cor.. ativa.
  2409. #---------------------------------------------------------------------------
  2410. def collide_with_color(object, map, color, ar=[28,30,30,30])
  2411. (ar[0]...object.width).each { |w| (ar[1]...object.height).each { |h|
  2412. _r = map.bitmap.get_pixel(object.x+w, object.y+h) == color[:right]
  2413. _l = map.bitmap.get_pixel(object.x+ar[2]-w, object.y+h) == color[:left]
  2414. _d = map.bitmap.get_pixel(object.x+w, object.y+h) == color[:down]
  2415. _u = map.bitmap.get_pixel(object.x+w, object.y+ar[3]-h) == color[:up]
  2416. return {right: _r, left: _l, down: _d, up: _u}
  2417. }}
  2418. end
  2419. end
  2420. #==============================================================================
  2421. # * DataManager
  2422. #==============================================================================
  2423. class << DataManager
  2424. alias :new_init :init
  2425. def init
  2426. Rpg.data_manager
  2427. Mouse.start
  2428. new_init
  2429. end
  2430. end
  2431. #==============================================================================
  2432. # * Input
  2433. #==============================================================================
  2434. class << Input
  2435. alias :upft :update
  2436. def update
  2437. upft
  2438. Key.update
  2439. end
  2440. end
  2441.  
  2442. class << Graphics
  2443. alias :uptf :update
  2444. def update
  2445. uptf
  2446. Mouse.update
  2447. end
  2448. end
Advertisement
Add Comment
Please, Sign In to add comment