Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # • Dax Core X2
- #==============================================================================
- # Autor: Dax
- # Versão: X2
- # Site: www.dax-soft.weebly.com
- # Requerimento: N/A
- #==============================================================================
- # • Descrição:
- #------------------------------------------------------------------------------
- # Adiciona alguns requesitos necessarios para executar alguns script Dax.
- #==============================================================================
- # • Versões:
- #------------------------------------------------------------------------------
- # X :
- # - ColorBasic : Módulo que armazena informações de cores.
- # - API : Módulo com informação de algumas APIs.
- # - User32 : Módulo com informações de algumas APIs da dll User32. Em Inglês
- # - Key : Permite você utilizar as várias teclas do teclado.
- # - Zone : Calculos para achar a área de um objeto.
- # - Bitmap : Add-ons para está classe.
- # - Mouse : Sistema de mouse.
- # - String : Add-ons para está clasee.
- # - Sprite : Add-ons para está classe.
- # - Integer : Add-ons para está classe.
- # - Variable : Módulo para guardar informações de variávels em HASH.
- # - Switche : Módulo para guardar informações das switches em HASH.
- # - Object : Add-ons.
- # - Window Core : Criado
- # - Window Core : Criado.
- # - LetterInput : Criado.
- # - Position and Size : Criado.
- # - Text Base
- # - Psych : | 0.1
- # - Psych Core: Criado.
- # - LimitScreen : Criado.
- # - DRGSS | Criado | 2.1
- # - Extension : Criado | 1.0
- # - Mouse : Extensão para o mouse.
- # - Touch_Picture | Criado.
- # - Simple_Touch_Picture | Criado.
- # - Touch_Icon | Criado.
- # - Simple_Touch_Icon | Criado.
- # - Touch_Text : Criado.
- # - Simple_Touch_Text : Criado.
- # - Color : Add-ons.
- # - Entries : Criado.
- # - DMath : Criado. 1.0
- # - Numeric : Add-ons : 0.1
- # - Module : Add-ons.
- # X2 :
- # - OutlineFillRect : Add-ons;
- # - ColorMath : Criado.
- #==============================================================================
- module Dax
- extend self
- #----------------------------------------------------------------------------
- # • Font
- # Ajuste aqui as configurações básicas da fonte padrão do jogo.
- #----------------------------------------------------------------------------
- Font.default_name = ["VL Gothic"] # Nome padrão da fonte do jogo.
- Font.default_size = 18 # Tamanho padrão da fonte do jogo.
- Font.default_bold = false # true - Para usar negrito | false - para não usar.
- Font.default_italic = false # true - Para usar italico | false - para não usar.
- Font.default_shadow = false # true - Para usar sombra na fonte | false - para não usar.
- Font.default_outline = true # true - Para usar borda da fonte | false - para não usar.
- Font.default_out_color = Color.new(0, 0, 0) # Cor da fonte padrão da borda da fonte.
- Font.default_color = Color.new(255, 255, 255) # Cor da fonte padrão.
- #----------------------------------------------------------------------------
- # • Variável e constantes.
- #----------------------------------------------------------------------------
- @imported = {} # Importar script.
- @version_imported = {} # Versão do script importado.
- @actor_imported = {} # Autor do script importado.
- @data = {}
- Core = true # Chave do módulo.
- Version_PS = 0.3 # Versão do Psych.
- Version_WC = 1.2 # Versão do Window Core.
- Version_EX = 1.4 # Versão do Extension.
- DRGSS = 2.0 # Versão do Dax Rgss
- #----------------------------------------------------------------------------
- # • Mouse
- # Configure aqui, algumas coisas do mouse.
- #----------------------------------------------------------------------------
- # Caso você queira, que não aparece nenhuma imagem ou ícone, representando o
- # cursor do mouse, apenas deixe vázio as áspas. Caso você queira uma imagem,
- # representando o mouse, ponha entre as áspas o nome da imagem, que deve de estar
- # na pasta de Pictures. Caso você queira que um ícone represente o cursor do mouse
- # ponha o ID do ícone no lugar das áspas.
- Mouse_Name = "Mouse"
- #----------------------------------------------------------------------------
- # • Registrar script.
- #----------------------------------------------------------------------------
- def register(name, actor="Dax", version="X2", data='')
- @imported[name] = true
- @version_imported[name] = version
- @actor_imported[name] = actor
- @data[name] = data
- end
- #----------------------------------------------------------------------------
- # • Cria uma condição de requerimento de script.
- #----------------------------------------------------------------------------
- def required(name, actor="Dax", version="X2")
- @imported[name] && @version_imported[name] >= version && @actor_imported[name] == name
- end
- #----------------------------------------------------------------------------
- # • Remover um script existente.
- #----------------------------------------------------------------------------
- def remove(name_symbol)
- Object.send(:remove_const, name_symbol)
- end
- register(:Dax)
- end
- #==============================================================================
- # • Module
- #==============================================================================
- class Module
- #----------------------------------------------------------------------------
- # • Declarar uma variável pública da instância com valor.
- #----------------------------------------------------------------------------
- def attr_value_accessor(sym, default = 0)
- attr_writer sym
- attr_value_reader sym, default
- end
- #----------------------------------------------------------------------------
- # • Declara uma variável pública de leitura com valor.
- #----------------------------------------------------------------------------
- def attr_value_reader(sym, default = 0)
- sym = sym.id2name
- string = "def #{sym};" +
- " @#{sym} = #{default} if @#{sym}.nil?;" +
- " @#{sym};" +
- "end;"
- module_eval(string)
- end
- end
- #==============================================================================
- # • API
- #==============================================================================
- Dax.register(:API, 'Dax', 1.0)
- module API
- extend self
- #----------------------------------------------------------------------------
- # • Constantes de APIs.
- #----------------------------------------------------------------------------
- # Permite acessar as teclas do teclado.
- GetKeyState = Win32API.new('user32', 'GetAsyncKeyState', 'i', 'i')
- # Permite ativar/desativar o ícone do mouse.
- MouseShowCursor = Win32API.new("user32", "ShowCursor", "i", "i")
- # Permite achar a posição do mouse.
- CursorPosition = Win32API.new('user32', 'GetCursorPos', 'p', 'i')
- # Permite achar o tamanho da screen.
- ScreenToClient = Win32API.new('user32', 'ScreenToClient', %w(l p), 'i')
- # Permite fazer a leitura do game.ini.
- ReadIni = Win32API.new('kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l')
- # Permite achar o tamando da window.
- FindWindow = Win32API.new('user32', 'FindWindowA', %w(p p), 'l')
- # API da Message Box.
- MessageBoxA = Win32API.new('user32', 'MessageBoxA', %w(p p p i), 'i')
- # Recupera uma string especificada de um arquivo em inicialização.
- GetPrivateProfileString = Win32API.new('kernel32', 'GetPrivateProfileStringA',%w(p p p p l p),'l')
- # Get Systeme Metrics
- GetSystemMetrics = Win32API.new("user32", "GetSystemMetrics", "i", "i")
- #Set Windows Pos
- SetWindowPos = Win32API.new("user32", "SetWindowPos", "lliiiii", "i")
- #Get Windows Rect
- GetWindowRect = Win32API.new('user32','GetWindowRect',%w(l p),'i')
- # Define a Win32API do comando print
- MessageBoxW = Win32API.new("user32", "MessageBoxW", "LPPL", "L")
- # Caps Lock
- CapsLock = Win32API.new("user32", "GetKeyState", "i", "i").call(20) != 0
- # State Key
- StateKey = Win32API.new("user32", "GetKeyState", ["i"], "i")
- # SetCursorPos
- SetCursorPos = Win32API.new("user32", "SetCursorPos", "ll", "i")
- SetCursorPos = Win32API.new("user32", "SetCursorPos", "ii", "i")
- GetKeyboardState = Win32API.new('user32', 'GetKeyboardState', ['P'], 'V')
- GetAsyncKeyState = Win32API.new('user32', 'GetAsyncKeyState', 'i', 'i')
- # Criar uma nova pasta.
- CreateDirectory = Win32API.new("kernel32", "CreateDirectory", "p", "lll")
- # Remover uma pasta existente.
- RemoveDirectory = Win32API.new("kernel32", "RemoveDirectory", "p", "l")
- # retorna para a data do ponteiro.
- def copymen(len)
- buf = "\0" * len
- Win32API.new("kernel32", "RtlMoveMemory", "ppl", "").call(buf, self, len)
- buf
- end
- end
- #==============================================================================
- # • User32
- #==============================================================================
- Dax.register(:user32, "Dax", 1.0, "18/05/13")
- module User32
- GSM = Win32API.new('user32', 'GetSystemMetrics', 'I', 'I')
- SetWindowPos = Win32API.new('user32', 'SetWindowPos', 'LLIIIII', 'I')
- SetWindowLong = Win32API.new('user32', 'SetWindowLong', 'LIL', 'L')
- Keybd_Event = Win32API.new('user32', 'keybd_event', 'LLLL', '')
- FindWindow = Win32API.new('user32', 'FindWindow', 'PP', 'L')
- GetDesktopWindow = Win32API.new('user32', 'GetDesktopWindow', '', 'L')
- GetWindowInfo = Win32API.new('user32', 'GetWindowInfo', 'LP', 'I')
- SetForegroundWindow = Win32API.new('user32', 'SetForegroundWindow', 'L', 'L')
- GetCursorPos = Win32API.new('user32', 'GetCursorPos', 'P', 'I')
- ShowCursor = Win32API.new('user32', 'ShowCursor', 'L', 'L')
- ScreenToClient = Win32API.new('user32', 'ScreenToClient', 'LP', 'I')
- GetKeyState = Win32API.new('user32', 'GetKeyState', 'I', 'I')
- GetAsyncKeyState = Win32API.new('user32', 'GetAsyncKeyState', 'I', 'I')
- # GSM Constants: Visit the site: microsoft msdn
- # http://msdn.microsoft.com/en-us/library/ms724385(VS.85).aspx
- SM_CXSCREEN = 0 # Width of the current master screen resolution
- SM_CYSCREEN = 1 # Height of the current master screen resolution
- SM_CXVSCROLL = 2 # Width of a vertical scroll bar
- SM_CYHSCROLL = 3 # Height of a horizontal scroll bar
- SM_CYCAPTION = 4 # Height of a caption area
- SM_CXBORDER = 5 # Width of a window border
- SM_CYBORDER = 6 # Height of a window border
- SM_CXDLGFRAME = 7
- SM_CXFIXEDFRAME = 7 # Width of non-resizable captioned window frame
- SM_CYDLGFRAME = 8
- SM_CYFIXEDFRAME = 8 # Height of non-resizable captioned window frame
- SM_CYVTHUMB = 9 # Height of a thumb button on vertical scrollbars
- SM_CXHTHUMB = 10 # Width of a thumb button on horizontal scrollbars
- SM_CXICON = 11 # Default width of an icon
- SM_CYICON = 12 # Default height of an icon
- SM_CXCURSOR = 13 # Width of a cursor
- SM_CYCURSOR = 14 # Height of a cursor
- SM_CYMENU = 15 # Height of a single-line menu bar
- SM_CXFULLSCREEN = 16 # Width of client rect for a full-screen window
- SM_CYFULLSCREEN = 17 # Height of client rect for a full-screen window
- SM_CYKANJIWINDOW = 18 # Height of kanji window at bottom of screen, if there
- SM_MOUSEPRESENT = 19 # Non-zero if mouse is present; 0 if not
- SM_CYVSCROLL = 20 # Height of the arrow bitmap on vertical scrollbars
- SM_CXHSCROLL = 21 # Width of the arrow bitmap on horizontal scrollbars
- SM_DEBUG = 22 # Non-zero if debug User.exe is installed; 0 if not
- SM_SWAPBUTTON = 23 # Non-zero if mouse button values are swapped
- SM_CXMIN = 28 # Minimum width of a window
- SM_CYMIN = 29 # Minimum height of a window
- SM_CXSIZE = 30 # Width of a button in a window caption or title bar
- SM_CYSIZE = 31 # Height of a button in a window caption or title bar
- SM_CXFRAME = 32
- SM_CXSIZEFRAME = 32 # Width of the sizing border around a resizable window
- SM_CYFRAME = 33
- SM_CYSIZEFRAME = 33 # Height of the sizing border around a resizable window
- SM_CXMINTRACK = 34 # Minimum "tracking" width of a window
- SM_CYMINTRACK = 35 # Minimum "tracking" height of a window
- SM_CXDOUBLECLK = 36 # Width of rect which second click must be in for double
- SM_CYDOUBLECLK = 37 # Hght of rect which second click must be in for double
- SM_CXICONSPACING = 38 # Width of a grid cell for items in large icon view
- SM_CYICONSPACING = 39 # Height of a grid cell for items in large icon view
- SM_MENUDROPALIGNMENT = 40 # 0 if drop-down menus are left-aligned...
- SM_PENWINDOWS = 41 # Non-zero if Microsoft Windows for Pen computing
- # extensions are installed; 0 if not
- SM_DBCSENABLED = 42 # Non-zero if user32.dll supports DBCS; 0 if not
- SM_CMOUSEBUTTONS = 43 # Number of available mouse buttons, or 0 for no mouse
- SM_SECURE = 44 # Always returns 0
- SM_CXEDGE = 45 # Width of a 3-D style border
- SM_CYEDGE = 46 # Height of a 3-D style border
- SM_CXMINSPACING = 47 # Width of a grid cell for minimized windows
- SM_CYMINSPACING = 48 # Height of a grid cell for minimized windows
- SM_CXSMICON = 49 # Recommended width of a small icon
- SM_CYSMICON = 50 # Recommended height of a small icon
- SM_CYSMCAPTION = 51 # Height of a small caption
- SM_CXSMSIZE = 52 # Width of small caption buttons
- SM_CYSMSIZE = 53 # Height of small caption buttons
- SM_CXMENUSIZE = 54 # Width of menu bar buttons
- SM_CYMENUSIZE = 55 # Height of menu bar buttons
- SM_ARRANGE = 56 # Flags about how system the arranges minimized windows
- SM_CXMINIMIZED = 57 # Width of a minimized window
- SM_CYMINIMIZED = 58 # Height of a minimized window
- SM_CXMAXTRACK = 59 # Default maximum width of resizable windows
- SM_CYMAXTRACK = 60 # Default maximum height of resizable windows
- SM_CXMAXIMIZED = 61 # Default width of maximized top-level window
- SM_CYMAXIMIZED = 62 # Default height of maximized top-level window
- SM_NETWORK = 63 # The least significant bit is set if a network is
- # present; otherwise, it is cleared
- SM_CLEANBOOT = 67 # System boot type; 0:Normal, 1:Safe, 2:Safe w/network
- SM_CXDRAG = 68
- SM_CYDRAG = 69 # Number of pixels mouse can move before initiating drag
- SM_SHOWSOUNDS = 70 # Non-zero if user requires visible output; 0 if not
- SM_CXMENUCHECK = 71 # Width of the default menu check-mark bitmap
- SM_CYMENUCHECK = 72 # Height of the default menu check-mark bitmap
- SM_SLOWMACHINE = 73 # Non-zero if system has a slow processor; 0 if not
- # No, seriously, that's what Microsoft said!
- SM_MIDEASTENABLED = 74 # Non-zero if system can use Hebrew, Arabic languages
- SM_MOUSEWHEELPRESENT = 75 # Nonzero mouse has vertical scroll wheel; 0 if not
- SM_XVIRTUALSCREEN = 76 # Coordinates of the left side of the virtual screen
- SM_YVIRTUALSCREEN = 77 # Coordinates of the top of the virtual screen
- SM_CXVIRTUALSCREEN = 78 # Virtual width of all screens put together
- SM_CYVIRTUALSCREEN = 79 # Virtual height of all screen put together
- SM_CMONITORS = 80 # Numbers of display monitors on a desktop
- SM_SAMEDISPLAYFORMAT = 81 # Non-zero if all screen use same color depth...
- # SetWindowPos constants
- HWND_NOTOPMOST = -2 # Make window not always on top (and bring to front)
- HWND_TOPMOST = -1 # Put window in front and make it always on top
- HWND_TOP = 0 # Put window in front of all non-topmost windows
- HWND_BOTTOM = 1 # Put window behind all other windows
- SWP_NOSIZE = 0x0001 # Keep current size (ignores w and h)
- SWP_NOMOVE = 0x0002 # Keep current position (ignores X and Y)
- SWP_NOZORDER = 0x0004 # Keep current Z order (ignores hWndInsertAfter)
- SWP_NOREDRAW = 0x0008 # Does NOT redraw changes
- SWP_NOACTIVATE = 0x0010 # Does NOT automatically activate the window
- SWP_FRAMECHANGED = 0x0020 # Applies new frame styles set with SetWindowLong
- SWP_SHOWWINDOW = 0x0040 # Displays the window
- SWP_HIDEWINDOW = 0x0080 # Hides the window
- SWP_NOCOPYBITS = 0x0100 # Discards the entire contents of the client area
- SWP_NOOWNERZORDER = 0x0200 # Doesn't change the window display order
- SWP_NOSENDCHANGING = 0x0400 # Don't send WM_WINDOWPOSCHANGING
- SWP_DEFERERASE = 0x2000 # Prevents generation of the WM_SYNCPAINT message
- SWP_ASYNCWINDOWPOS = 0x4000 # Use if calling thread does not own the window
- # SetWindowLong constants
- GWL_USERDATA = -21 # Sets data reserved for use by the application
- GWL_EXSTYLE = -20 # Sets a new extended window style
- GWL_STYLE = -16 # Sets a new window style
- GWL_ID = -12 # Sets a new identifier of the window
- GWL_HWNDPARENT = -8 # Sets a new parent hWnd
- GWL_HINSTANCE = -6 # Sets a new application instance handle
- GWL_WNDPROC = -4 # Sets a new addr for the window calling procedure
- # Only available when the hWnd parameter identifies a dialog box:
- DWL_MSGRESULT = 0 # Sets the return message of the dialog box proc
- DWL_DLGPROC = 4 # Sets the new address of the dialog box proc
- DWL_USER = 8 # Sets new extra information private to application
- # Window Styles (SetWindowLong(hWnd, GWL_STYLE, WS_*))
- WS_OVERLAPPED = 0x00000000 # Overlapped window has title and border
- WS_TABSTOP = 0x00010000 # Can receive focus from TAB key
- WS_GROUP = 0x00020000 # First control of group of controls
- WS_MAXIMIZEBOX = 0x00010000 # Has a mazimize button
- WS_MINIMIZEBOX = 0x00020000 # Has a minimize button
- WS_THICKFRAME = 0x00040000 # Has sizing border
- WS_SYSMENU = 0x00080000 # Has buttons on title bar (reqs WS_CAPTION)
- WS_HSCROLL = 0x00100000 # Has horizontal scroll bar
- WS_VSCROLL = 0x00200000 # Has vertical scroll bar
- WS_DLGFRAME = 0x00400000 # Dialog-style border. Cannot have title bar
- WS_BORDER = 0x00800000 # Thin border
- WS_CAPTION = 0x00C00000 # Has a title bar (implies WS_BORDER)
- WS_MAXIMIZE = 0x01000000 # Initially maximized
- WS_CLIPCHILDREN = 0x02000000 # Exclude area for children when drawing
- WS_CLIPSIBLINGS = 0x04000000 # Exclude sibling client rects when drawing
- WS_DISABLED = 0x08000000 # Initially disabled (no input)
- WS_VISIBLE = 0x10000000 # Initially visible
- WS_MINIMIZE = 0x20000000 # Initially minimized
- WS_CHILD = 0x40000000 # Child cannot have menu bar or WS_POPUP
- WS_POPUP = 0x80000000 # Popup window
- # Window style aliases
- WS_OVERLAPPEDWINDOW = WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_THICKFRAME|
- WS_MINIMIZEBOX|WS_MAXIMIZEBOX
- WS_POPUPWINDOW = WS_POPUP|WS_BORDER|WS_SYSMENU
- WS_CHILDWINDOW = WS_CHILD
- WS_TILED = WS_OVERLAPPED
- WS_ICONIC = WS_MINIMIZE
- WS_SIZEBOX = WS_THICKFRAME
- WS_TILEDWINDOW = WS_OVERLAPPEDWINDOW
- end
- #==============================================================================
- # • String
- #==============================================================================
- Dax.register(:String, "Dax", 1.2)
- class String
- #----------------------------------------------------------------------------
- # • Constantes
- #----------------------------------------------------------------------------
- CP_ACP = 0 # ANSI
- CP_UTF7 = 65000 # UTF-7
- CP_UTF8 = 65001 # UTF-8
- EMPTY_STR = "".freeze
- #----------------------------------------------------------------------------
- # • Variáveis
- #----------------------------------------------------------------------------
- @@rm = Win32API.new('kernel32','RtlZeroMemory',%w(p l),'l').freeze
- @@mb2wc = Win32API.new('kernel32',
- 'MultiByteToWideChar', %w(i l p i p i), 'l').freeze
- @@wc2mb = Win32API.new('kernel32',
- 'WideCharToMultiByte', %w(i l p i p i p p), 'l').freeze
- #----------------------------------------------------------------------------
- # • Tamanho.
- #----------------------------------------------------------------------------
- def fsized
- self.to_s.split(//)
- end
- #----------------------------------------------------------------------------
- # • Substituir.
- #----------------------------------------------------------------------------
- def substitute(binding=TOPLEVEL_BINDING)
- eval(%{"#{self}"}, binding)
- end
- #----------------------------------------------------------------------------
- # • Obter tamanho real.
- #----------------------------------------------------------------------------
- def real_size
- _return, _next = 0, false
- for i in 0...self.size
- _next = false if _next
- next unless _next
- _return += 1
- char = self[i]
- _next = char == 195
- end
- _return
- end
- #----------------------------------------------------------------------------
- # • Encode
- #----------------------------------------------------------------------------
- def encode_by_
- for i in 0...(self.size)
- self[i] = 256 - self[i]
- end
- end
- #----------------------------------------------------------------------------
- # • Criptografar.
- #----------------------------------------------------------------------------
- def crypt
- return self.to_i(36)
- end
- end
- #==============================================================================
- # • Numeric
- #==============================================================================
- Dax.register(:numeric, 'Dax', 0.1, '16/05/13')
- class Numeric
- #----------------------------------------------------------------------------
- # • Calculo de '+ ou -' com um determinado número.
- #----------------------------------------------------------------------------
- def ±(number)
- return [self + number, self - number]
- end
- end
- #==============================================================================
- # • Integer
- #==============================================================================
- Dax.register(:Integer, "Dax", 0.30)
- class Integer
- #----------------------------------------------------------------------------
- # • Criptografar.
- #----------------------------------------------------------------------------
- def crypt
- return self.to_s(36)
- end
- #----------------------------------------------------------------------------
- # • Transformar em porcentagem
- # actual : Atual.
- # max : Máximo.
- #----------------------------------------------------------------------------
- def to_p(actual, max=100)
- self.to_f * actual.to_f / max.to_f
- end
- #----------------------------------------------------------------------------
- # • Retorna uma casa... Número
- #----------------------------------------------------------------------------
- def return
- return self - 1
- end
- end
- #==============================================================================
- # • Color
- #==============================================================================
- Dax.register(:Color, "Dax", 1.0)
- class Color
- HEXA = /\#([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})?/i
- #----------------------------------------------------------------------------
- # • Cores hexadécimal.
- #----------------------------------------------------------------------------
- alias dax_hex_color_initialize initialize
- def initialize(*args)
- if args.length == 1 and args[0].is_a? String and args[0][/\A#{HEX_REGEX}\z/]
- dax_hex_color_initialize($1.hex, $2.hex, $3.hex, ($4 ? $4.hex : 255))
- else
- dax_hex_color_initialize(*args)
- end
- end
- #----------------------------------------------------------------------------
- # • Efeito de cor opaca.
- #----------------------------------------------------------------------------
- def opacity
- self.set(self.red, self.green, self.blue, 128)
- end
- #----------------------------------------------------------------------------
- # • Inverter as cores.
- #----------------------------------------------------------------------------
- def invert!
- self.set(255-self.red, 255-self.green, 255-self.blue, self.alpha)
- end
- #----------------------------------------------------------------------------
- # • Reverter as cores.
- #----------------------------------------------------------------------------
- def revert
- colors = [self.red, self.green, self.blue, self.alpha].reverse!
- self.set(*colors)
- end
- #----------------------------------------------------------------------------
- # • Efeito de mudança de cores...Rotacionar..
- #----------------------------------------------------------------------------
- def rotate
- colors = [self.red, self.green, self.blue, self.alpha].rotate!(rand(2) == 0 ? 1 : - 1)
- self.set(*colors)
- end
- #----------------------------------------------------------------------------
- # • Converte para string.
- #----------------------------------------------------------------------------
- def to_s
- "red: #{self.red}\nblue: #{self.blue}\ngreen: #{self.green}\nalpha: #{self.alpha}"
- end
- end
- #==============================================================================
- # • DMath
- #==============================================================================
- Dax.register(:dmath, 'Dax', 1.0, '04/05/13')
- module DMath
- extend self
- #----------------------------------------------------------------------------
- # • circle_angle
- #----------------------------------------------------------------------------
- def circle_angle(iy, step)
- return Math.asin(iy * step)
- end
- #----------------------------------------------------------------------------
- # • circle_width
- #----------------------------------------------------------------------------
- def circle_width(r, angle)
- return r * Math.cos(angle)
- end
- #----------------------------------------------------------------------------
- # • elipse_arc
- #----------------------------------------------------------------------------
- def elipse_arc(i, height)
- return Math.asin i / height
- end
- #----------------------------------------------------------------------------
- # • elipse_width
- #----------------------------------------------------------------------------
- def elipse_width(arc, width)
- return Math.cos(arc) * width
- end
- #----------------------------------------------------------------------------
- # • Ângulo, para efeito de sombra.
- #----------------------------------------------------------------------------
- def angle_effect_shadow(ev1, ev2)
- return Math.atan2(ev1.screen_y - ev2.screen_y, ev1.screen_x - ev2.screen_x)
- end
- #----------------------------------------------------------------------------
- # • Método, para ângulo de sombras.
- #----------------------------------------------------------------------------
- def angle_effect_shadow_sprite(*args)
- return -57.3 * angle_effect_shadow(*args) + 90
- end
- #----------------------------------------------------------------------------
- # • Distância, para efeito de sombra.
- #----------------------------------------------------------------------------
- def distance_effect_shadow(ev1, ev2)
- return Math.hypot(ev1.screen_y - ev2.screen_y, ev1.screen_x - ev2.screen_x)
- end
- #----------------------------------------------------------------------------
- # • Rotc | Rotacionar.
- #----------------------------------------------------------------------------
- def rotc(vmn, v, vmx, c = 100)
- ((v - vmn) * c) / (vmx - vmn)
- end
- #----------------------------------------------------------------------------
- # • Ângulo, círuclo em X.
- #----------------------------------------------------------------------------
- def angle_circle_x(angle, radius)
- return Math.cos(angle * Math::PI / 180) * radius
- end
- #----------------------------------------------------------------------------
- # • Ângulo, círuclo em Y.
- #----------------------------------------------------------------------------
- def angle_circle_y(angle, radius)
- return Math.sin(angle * Math::PI / 180) * radius
- end
- #----------------------------------------------------------------------------
- # • Obter o X do centro da tela para um determinado objeto|sprite,bitmap.
- #----------------------------------------------------------------------------
- def get_x_center_screen(width)
- x = Graphics.width.to_f / 2.0 - (width.to_f / 2.0)
- return x
- end
- #----------------------------------------------------------------------------
- # • Obter o Y do centro da tela para um determinado objeto|sprite,bitmap.
- #----------------------------------------------------------------------------
- def get_y_center_screen(height)
- y = Graphics.height.to_f / 2.0 - (height.to_f / 2.0)
- return y
- end
- #----------------------------------------------------------------------------
- # • Tangente de alteração de ângulo. Para efeitos.
- #----------------------------------------------------------------------------
- def acc_tan_effect
- return Math.tan(Math::PI / 26)
- end
- #----------------------------------------------------------------------------
- # • Converter em graus, multiplique a variável com isto.
- #----------------------------------------------------------------------------
- def graus
- 360 / (2 * Math::PI)
- end
- #----------------------------------------------------------------------------
- # • Converter em degress
- #----------------------------------------------------------------------------
- def degrees(deg)
- ((deg) / (2 * Math::PI)) * 360
- end
- #----------------------------------------------------------------------------
- # • Para 4 decimals.
- #----------------------------------------------------------------------------
- def to_4_dec(n)
- ((n * 1000).ceil) / 1000
- end
- #----------------------------------------------------------------------------
- # • Área do quadrado.
- #----------------------------------------------------------------------------
- def square_area(l)
- l ** 2
- end
- #----------------------------------------------------------------------------
- # • Equação completa de 2 grau, retorna a uma array.
- #----------------------------------------------------------------------------
- def eq2(a,b,c)
- ∆ = (b**2) - (4*a*c)
- unless ∆ < 0
- x1 = (-b + Math.sqrt(∆)) / 2*a
- x2 = (-b - Math.sqrt(∆)) / 2*a
- return [x1, x2]
- end
- return [nil, nil]
- end
- #----------------------------------------------------------------------------
- # • Área de um retângulo.
- #----------------------------------------------------------------------------
- def rectangle_area(h, b)
- h * b
- end
- #----------------------------------------------------------------------------
- # • Área de um triângulo.
- #----------------------------------------------------------------------------
- def triangle_area(*args)
- x, y, x2, y2, x3, y3 = *args
- return (x2 - x) * (y3 - y) - (x3 - x) * (y2 - y)
- end
- #----------------------------------------------------------------------------
- # • Calcular distância para scripts como sensor.
- #----------------------------------------------------------------------------
- def distance_sensor(target, target2)
- return (target.x - target2.x).abs + (target.y - target2.y).abs
- end
- end
- #==============================================================================
- # • ColorMath
- #==============================================================================
- Dax.register(:color_math, "Dax", 0.5, "22/05/13")
- module ColorMath
- extend self
- #----------------------------------------------------------------------------
- # • Verificar se é uma cor?
- #----------------------------------------------------------------------------
- def is_color?(color, red, green, blue)
- return (color.red == red and color.blue == blue and color.green == green)
- end
- #----------------------------------------------------------------------------
- # • Verificar se é preto?
- #----------------------------------------------------------------------------
- def is_black?(color)
- is_color?(color, 0, 0, 0)
- end
- #----------------------------------------------------------------------------
- # • Verificar se é branco?
- #----------------------------------------------------------------------------
- def is_white?(color)
- is_color?(color, 255, 255, 255)
- end
- #----------------------------------------------------------------------------
- # • Verificar se é vermelho?
- #----------------------------------------------------------------------------
- def is_red?(color)
- is_red?(color, 255, 0, 0)
- end
- end
- #==============================================================================
- # • Keyboard | Método para usar todas as teclas do teclado.
- #==============================================================================
- Dax.register(:Key, "Dax", 1.0)
- module Key
- extend self
- #--------------------------------------------------------------------------
- # * Chaves diversos.
- #--------------------------------------------------------------------------
- CANCEL = 0x03 # Control-Break Processing
- BACKSPACE = 0x08 # Backspace Key
- TAB = 0x09 # Tab Key
- CLEAR = 0x0C # Clear Key
- RETURN = 0x0D # Enter Key
- SHIFT = 0x10 # Shift Key
- CONTROL = 0x11 # Ctrl Key
- MENU = 0x12 # Alt Key
- PAUSE = 0x13 # Pause Key
- ESCAPE = 0x1B # Esc Key
- CONVERT = 0x1C # IME Convert Key
- NONCONVERT = 0x1D # IME Nonconvert Key
- ACCEPT = 0x1E # IME Accept Key
- SPACE = 0x20 # Space Bar Key (Space, usually blank)
- PRIOR = 0x21 # Page Up Key
- NEXT = 0x22 # Page Down Key
- ENDS = 0x23 # End Key
- HOME = 0x24 # Home Key
- LEFT = 0x25 # Left Arrow Key
- UP = 0x26 # Up Arrow Key
- RIGHT = 0x27 # Right Arrow Key
- DOWN = 0x28 # Down Arrow Key
- SELECT = 0x29 # Select Key
- PRINT = 0x2A # Print Key
- EXECUTE = 0x2B # Execute Key
- SNAPSHOT = 0x2C # Print Screen Key
- DELETE = 0x2E # Delete Key
- HELP = 0x2F # Help Key
- LSHIFT = 0xA0 # Left Shift Key
- RSHIFT = 0xA1 # Right Shift Key
- LCONTROL = 0xA2 # Left Control Key (Ctrl)
- RCONTROL = 0xA3 # Right Control Key (Ctrl)
- LMENU = 0xA4 # Left Menu Key (Alt)
- RMENU = 0xA5 # Right Menu Key (Alt)
- PACKET = 0xE7 # Used to Pass Unicode Characters as Keystrokes
- MOUSE_RIGHT = 0x01 # Button Mouse Right
- MOUSE_LEFT = 0x02 # Button Mouse Left
- MOUSE_MIDDLE = 0x04 # Button Mouse Middle
- #--------------------------------------------------------------------------
- # * Chaves de números.
- #--------------------------------------------------------------------------
- N0 = 0x30 # 0 Key
- N1 = 0x31 # 1 Key
- N2 = 0x32 # 2 Key
- N3 = 0x33 # 3 Key
- N4 = 0x34 # 4 Key
- N5 = 0x35 # 5 Key
- N6 = 0x36 # 6 Key
- N7 = 0x37 # 7 Key
- N8 = 0x38 # 8 Key
- N9 = 0x39 # 9 Key
- #--------------------------------------------------------------------------
- # * Chaves de letras
- #--------------------------------------------------------------------------
- A = 0x41 # A Key
- B = 0x42 # B Key
- C = 0x43 # C Key
- D = 0x44 # D Key
- E = 0x45 # E Key
- F = 0x46 # F Key
- G = 0x47 # G Key
- H = 0x48 # H Key
- I = 0x49 # I Key
- J = 0x4A # J Key
- K = 0x4B # K Key
- L = 0x4C # L Key
- M = 0x4D # M Key
- N = 0x4E # N Key
- O = 0x4F # O Key
- P = 0x50 # P Key
- Q = 0x51 # Q Key
- R = 0x52 # R Key
- S = 0x53 # S Key
- T = 0x54 # T Key
- U = 0x55 # U Key
- V = 0x56 # V Key
- W = 0x57 # W Key
- X = 0x58 # X Key
- Y = 0x59 # Y Key
- Z = 0x5A # Z Key
- #--------------------------------------------------------------------------
- # * Chaves de windows
- #--------------------------------------------------------------------------
- LWIN = 0x5B # Left Windows Key (Natural keyboard)
- RWIN = 0x5C # Right Windows Key (Natural Keyboard)
- APPS = 0x5D # Applications Key (Natural keyboard)
- SLEEP = 0x5F # Computer Sleep Key
- BROWSER_BACK = 0xA6 # Browser Back Key
- BROWSER_FORWARD = 0xA7 # Browser Forward Key
- BROWSER_REFRESH = 0xA8 # Browser Refresh Key
- BROWSER_STOP = 0xA9 # Browser Stop Key
- BROWSER_SEARCH = 0xAA # Browser Search Key
- BROWSER_FAVORITES = 0xAB # Browser Favorites Key
- BROWSER_HOME = 0xAC # Browser Start and Home Key
- VOLUME_MUTE = 0xAD # Volume Mute Key
- VOLUME_DOWN = 0xAE # Volume Down Key
- VOLUME_UP = 0xAF # Volume Up Key
- MEDIA_NEXT_TRACK = 0xB0 # Next Track Key
- MEDIA_PREV_TRACK = 0xB1 # Previous Track Key
- MEDIA_STOP = 0xB2 # Stop Media Key
- MEDIA_PLAY_PAUSE = 0xB3 # Play/Pause Media Key
- LAUNCH_MAIL = 0xB4 # Start Mail Key
- LAUNCH_MEDIA_SELECT = 0xB5 # Select Media Key
- LAUNCH_APP1 = 0xB6 # Start Application 1 Key
- LAUNCH_APP2 = 0xB7 # Start Application 2 Key
- PROCESSKEY = 0xE5 # IME Process Key
- ATTN = 0xF6 # Attn Key
- CRSEL = 0xF7 # CrSel Key
- EXSEL = 0xF8 # ExSel Key
- EREOF = 0xF9 # Erase EOF Key
- PLAY = 0xFA # Play Key
- ZOOM = 0xFB # Zoom Key
- PA1 = 0xFD # PA1 Key
- #--------------------------------------------------------------------------
- # * Chaves do Numpad
- #--------------------------------------------------------------------------
- NUMPAD0 = 0x60 # Numeric Keypad 0 Key
- NUMPAD1 = 0x61 # Numeric Keypad 1 Key
- NUMPAD2 = 0x62 # Numeric Keypad 2 Key
- NUMPAD3 = 0x63 # Numeric Keypad 3 Key
- NUMPAD4 = 0x64 # Numeric Keypad 4 Key
- NUMPAD5 = 0x65 # Numeric Keypad 5 Key
- NUMPAD6 = 0x66 # Numeric Keypad 6 Key
- NUMPAD7 = 0x67 # Numeric Keypad 7 Key
- NUMPAD8 = 0x68 # Numeric Keypad 8 Key
- NUMPAD9 = 0x69 # Numeric Keypad 9 Key
- MULTIPLY = 0x6A # Multiply Key (*)
- ADD = 0x6B # Add Key (+)
- SEPARATOR = 0x6C # Separator Key
- SUBTRACT = 0x6D # Subtract Key (-)
- DECIMAL = 0x6E # Decimal Key (.)
- DIVIDE = 0x6F # Divide Key (/)
- #--------------------------------------------------------------------------
- # * Chaves de funções
- #--------------------------------------------------------------------------
- F1 = 0x70 # F1 Key
- F2 = 0x71 # F2 Key
- F3 = 0x72 # F3 Key
- F4 = 0x73 # F4 Key
- F5 = 0x74 # F5 Key
- F6 = 0x75 # F6 Key
- F7 = 0x76 # F7 Key
- F8 = 0x77 # F8 Key
- F9 = 0x78 # F9 Key
- F10 = 0x79 # F10 Key
- F11 = 0x7A # F11 Key
- F12 = 0x7B # F12 Key
- F13 = 0x7C # F13 Key
- F14 = 0x7D # F14 Key
- F15 = 0x7E # F15 Key
- F16 = 0x7F # F16 Key
- F17 = 0x80 # F17 Key
- F18 = 0x81 # F18 Key
- F19 = 0x82 # F19 Key
- F20 = 0x83 # F20 Key
- F21 = 0x84 # F21 Key
- F22 = 0x85 # F22 Key
- F23 = 0x86 # F23 Key
- F24 = 0x87 # F24 Key
- #--------------------------------------------------------------------------
- # * Chaves alternativas
- #--------------------------------------------------------------------------
- CAPITAL = 0x14 # Caps Lock Key
- KANA = 0x15 # IME Kana Mode Key
- HANGUL = 0x15 # IME Hangul Mode Key
- JUNJA = 0x17 # IME Junja Mode Key
- FINAL = 0x18 # IME Final Mode Key
- HANJA = 0x19 # IME Hanja Mode Key
- KANJI = 0x19 # IME Kanji Mode Key
- MODECHANGE = 0x1F # IME Mode Change Request Key
- INSERT = 0x2D # Insert Key
- NUMLOCK = 0x90 # Num Lock Key
- SCROLL = 0x91 # Scroll Lock Key
- #--------------------------------------------------------------------------
- # * Chaves OEM, variadas
- #--------------------------------------------------------------------------
- OEM_1 = 0xBA # Misc Characters (; : in USA 101/102 Keyboards)
- OEM_PLUS = 0xBB # + = Key
- OEM_COMMA = 0xBC # , < Key
- OEM_MINUS = 0xBD # - _ Key
- OEM_PERIOD = 0xBE # . > Key
- OEM_2 = 0xBF # Misc Characters (/ ? in USA 101/102 Keyboards)
- OEM_3 = 0xC0 # Misc Characters (` ~ in USA 101/102 Keyboards)
- OEM_4 = 0xDB # Misc Characters ([ { in USA 101/102 Keyboards)
- OEM_5 = 0xDC # Misc Characters (\ | in USA 101/102 Keyboards)
- OEM_6 = 0xDD # Misc Characters (] } in USA 101/102 Keyboards)
- OEM_7 = 0xDE # Misc Characters (' " in USA 101/102 Keyboards)
- OEM_8 = 0xDF # Misc Characters (Varies by Keyboard)
- OEM_9 = 0xE1 # OEM Specific
- OEM_10 = 0x92 # OEM Specific
- OEM_11 = 0x93 # OEM Specific
- OEM_12 = 0x94 # OEM Specific
- OEM_13 = 0x95 # OEM Specific
- OEM_14 = 0x96 # OEM Specific
- OEM_15 = 0xE3 # OEM Specific
- OEM_16 = 0xE4 # OEM Specific
- OEM_17 = 0xE6 # OEM Specific
- OEM_18 = 0xE9 # OEM Specific
- OEM_19 = 0xEA # OEM Specific
- OEM_20 = 0xEB # OEM Specific
- OEM_21 = 0xEC # OEM Specific
- OEM_22 = 0xED # OEM Specific
- OEM_23 = 0xEE # OEM Specific
- OEM_24 = 0xEF # OEM Specific
- OEM_25 = 0xF1 # OEM Specific
- OEM_26 = 0xF2 # OEM Specific
- OEM_27 = 0xF3 # OEM Specific
- OEM_28 = 0xF4 # OEM Specific
- OEM_29 = 0xF5 # OEM Specific
- OEM_102 = 0xE2 # Angle Bracket or Backslash on RT-102 Keyboards
- OEM_CLEAR = 0xFE # Clear Key
- #--------------------------------------------------------------------------
- # * Variáveis do módulo.
- #--------------------------------------------------------------------------
- @unpack_string = 'b'*256
- @last_array = '0'*256
- @press = Array.new(256, false)
- @trigger = Array.new(256, false)
- @repeat = Array.new(256, false)
- @release = Array.new(256, false)
- @repeat_counter = Array.new(256, 0)
- @getKeyboardState = API::GetKeyboardState
- @getAsyncKeyState = API::GetAsyncKeyState
- @getKeyboardState.call(@last_array)
- @last_array = @last_array.unpack(@unpack_string)
- for i in 0...@last_array.size
- @press[i] = @getAsyncKeyState.call(i) == 0 ? false : true
- end
- #--------------------------------------------------------------------------
- # * Atualização dos objetos do módulo.
- #--------------------------------------------------------------------------
- def update
- @trigger = Array.new(256, false)
- @repeat = Array.new(256, false)
- @release = Array.new(256, false)
- array = '0'*256
- @getKeyboardState.call(array)
- array = array.unpack(@unpack_string)
- for i in 0...array.size
- if array[i] != @last_array[i]
- @press[i] = @getAsyncKeyState.call(i) == 0 ? false : true
- if @repeat_counter[i] <= 0 && @press[i]
- @repeat[i] = true
- @repeat_counter[i] = 15
- end
- if !@press[i]
- @release[i] = true
- else
- @trigger[i] = true
- end
- else
- if @press[i] == true
- @press[i] = @getAsyncKeyState.call(i) == 0 ? false : true
- @release[i] = true if !@press[i]
- end
- if @repeat_counter[i] > 0 && @press[i] == true
- @repeat_counter[i] -= 1
- elsif @repeat_counter[i] <= 0 && @press[i] == true
- @repeat[i] = true
- @repeat_counter[i] = 3
- elsif @repeat_counter[i] != 0
- @repeat_counter[i] = 0
- end
- end
- end
- @last_array = array
- end
- #--------------------------------------------------------------------------
- # * Get Key Pressed State
- # key : key index
- #--------------------------------------------------------------------------
- def press?(key)
- return @press[key]
- end
- #--------------------------------------------------------------------------
- # * Get Key Triggered State
- # key : key index
- #--------------------------------------------------------------------------
- def trigger?(key)
- return @trigger[key]
- end
- #--------------------------------------------------------------------------
- # * Get Key Repeated State
- # key : key index
- #--------------------------------------------------------------------------
- def repeat?(key)
- return @repeat[key]
- end
- #--------------------------------------------------------------------------
- # * Get Key Released State
- # key : key index
- #--------------------------------------------------------------------------
- def release?(key)
- return @release[key]
- end
- end
- #==============================================================================
- # • Input | Atualização do Key
- #==============================================================================
- class << Input
- alias key_update update
- def update
- key_update
- Key.update
- end
- end
- #============================================================================
- # • Zone
- #============================================================================
- Dax.register(:Zone, "Dax", 1.3)
- class Zone
- #----------------------------------------------------------------------------
- # • Inicialização dos objetos.
- #----------------------------------------------------------------------------
- def initialize(object, object2)
- @object = object
- @object2 = object2
- end
- #--------------------------------------------------------------------------
- # • Verifica se um objeto está na área. Círculo | Circle
- #--------------------------------------------------------------------------
- def circle(size)
- ( (@object.x - @object2.x) ** 2) + ( (@object.y - @object2.y) ** 2) <= (size ** 2)
- end
- #--------------------------------------------------------------------------
- # • Verifica se um objeto está na área. Eclipse | Eclipse
- #--------------------------------------------------------------------------
- def eclipse
- rate_x = ((@object.x.to_f - @object2.x.to_f) ** 2.0 / (@object2.src_rect.width / 2.0))
- rate_y = ((@object.y.to_f - @object2.y.to_f) ** 2.0 / (@object2.src_rect.height / 2.0))
- rate_x + rate_y <= 1
- end
- #----------------------------------------------------------------------------
- # • Verifica se algum objeto está na área do object.
- #----------------------------------------------------------------------------
- def object_in_area?
- return @object.x.between?(@object2.x, @object2.x + @object2.bitmap.width) && @object.y.between?(@object2.y, @object2.y + @object2.bitmap.height)
- end
- end
- #==============================================================================
- # • Sprite
- #==============================================================================
- Dax.register(:Sprite, "Dax", 0.2)
- class Sprite
- #----------------------------------------------------------------------------
- # • Novo método.
- #----------------------------------------------------------------------------
- alias new_initialize initialize
- def initialize(viewport=nil)
- if viewport.is_a?(String)
- new_initialize(nil)
- self.bitmap = Bitmap.new(viewport)
- elsif viewport.is_a?(Array)
- new_initialize(nil)
- self.bitmap = Bitmap.new(viewport[0], viewport[1])
- elsif viewport.is_a?(Viewport)
- new_initialize(viewport)
- elsif viewport.nil?
- new_initialize(viewport)
- end
- end
- #----------------------------------------------------------------------------
- # • Define aqui uma posição fixa para um objeto.
- #----------------------------------------------------------------------------
- def position(command=0)
- return if command.nil?
- case command
- when 0 then self.x = 0
- when 1 then self.x = Graphics.width / 2 - self.width / 2
- when 2 then self.x = Graphics.width - self.width
- when 3 then self.y = 0
- when 4 then self.y = Graphics.height / 2 - self.height / 2
- when 5 then self.y = Graphics.height - self.height
- when :center
- self.x = Graphics.width / 2 - self.width / 2
- self.y = Graphics.height / 2 - self.height / 2
- when :center_left
- self.x = 0 + add_x
- self.y = Graphics.height / 2 - self.height / 2
- when :center_right
- self.x = Graphics.width - self.height
- self.y = Graphics.height / 2 - self.height / 2
- end
- end
- #----------------------------------------------------------------------------
- # • Se esta no alcance?
- #----------------------------------------------------------------------------
- def range?(pos, margin=0)
- rect = self.src_rect
- if pos.x >= rect.x + margin and pos.y >= rect.y + margin and
- pos.x < rect.x + rect.width - margin and
- pos.y < rect.y + rect.height - margin
- return true
- end
- return false
- end
- end
- #==============================================================================
- # • Bitmap
- #==============================================================================
- Dax.register(:Bitmap, "Dax", 1.2)
- class Bitmap
- #----------------------------------------------------------------------------
- # • Salvar em png.
- #----------------------------------------------------------------------------
- def save(file_name)
- def chunk(type, data)
- [data.size, type, data, Zlib.crc32(type + data)].pack("NA4A*N")
- end
- img_data = ""
- width, height = self.width, self.height
- for j in 0...(height)
- img_data << "\0"
- for i in 0...(width)
- pos_c = self.get_pixel(i, j)
- img_data << [pos_c.red, pos_c.green, pos_c.blue, pos_c.alpha].pack("C*")
- end
- end
- c = [
- "\x89PNG\r\n\x1a\n",
- chunk("IHDR", [width, height, 8, 6, 0, 0, 0].pack("N2C5")),
- chunk("IDAT", Zlib::Deflate.deflate(img_data)),
- chunk("IEND", "")
- ]
- File.open(file_name, "wb"){|file| c.each{|chunk| file.write(chunk) }}
- end
- #----------------------------------------------------------------------------
- # • Plano BLT.
- #----------------------------------------------------------------------------
- def plane_blt(dest_rect, bmp, src_rect=bmp.rect, op=255)
- stretch = (dest_rect.width != src_rect.width or
- dest_rect.height != src_rect.height)
- sx = src_rect.x % bmp.width
- dx = dest_rect.x
- swr = src_rect.width
- while (swr > 0)
- sy = src_rect.y % bmp.height
- dy = dest_rect.y
- shr = src_rect.height
- sw = [bmp.width - sx, swr].min
- dw = dest_rect.width * sw / src_rect.width
- while (shr > 0)
- sh = [bmp.height - sy, shr].min
- dh = dest_rect.height * sh / src_rect.height
- if stretch
- self.stretch_blt(Rect.new(dx,dy,dw,dh), bmp, Rect.new(sx,sy,sw,sh),op)
- else
- self.blt(dx, dy, bmp, Rect.new(sx, sy, sw, sh), op)
- end
- sy = 0
- shr -= sh
- dy += dh
- end
- sx = 0
- swr -= sw
- dx += dw
- end
- end
- #----------------------------------------------------------------------------
- # • Efeito negativo.
- #----------------------------------------------------------------------------
- def negative
- for i in 0...(self.width)
- for j in 0...(self.height)
- pix = self.get_pixel(i, j)
- pix.red = (pix.red - 255) * -1
- pix.blue = (pix.blue - 255) * -1
- pix.green = (pix.green - 255) * -1
- self.set_pixel(i, j, pix)
- end
- end
- end
- #----------------------------------------------------------------------------
- # • Grayscale
- #----------------------------------------------------------------------------
- def grayscale(rect = Rect.new(0, 0, self.width, self.height))
- for i in rect.x...rect.x + rect.width
- for j in rect.y...rect.y + rect.height
- colour = self.get_pixel(i,j)
- grey_pixel = (colour.red*0.3 + colour.green*0.59 + colour.blue*0.11)
- colour.red = colour.green = colour.blue = grey_pixel
- self.set_pixel(i,j,colour)
- end
- end
- end
- #----------------------------------------------------------------------------
- # • Contorno.
- #----------------------------------------------------------------------------
- def doutline(tw, th, min, max, color)
- temp = self.dup
- nx = self.width / tw
- ny = self.height / th
- rect = Rect.new(0, 0, tw, th)
- for y in 0...ny
- rect.y = y * th
- for x in 0...nx
- rect.x = x * tw
- for ty in 0...rect.height
- y = ty + rect.y
- for tx in 0...rect.width
- x = tx + rect.x
- self.set_pixel(x, y, color) if temp.get_pixel(x, y).alpha >= max && ((tx > 0 && temp.get_pixel(x - 1, y).alpha <= min) || (tx < rect.width - 1 && temp.get_pixel(x + 1, y).alpha <= min) || (ty > 0 && temp.get_pixel(x, y - 1).alpha <= min) || (ty < rect.height - 1 && temp.get_pixel(x, y + 1).alpha <= min))
- end
- end
- end
- end
- temp.dispose
- end
- #----------------------------------------------------------------------------
- # • Novo fornecedor de pixel.
- #----------------------------------------------------------------------------
- def set_pixel_s(x, y, color, size)
- for i in 0...size
- self.set_pixel(x+i, y, color)
- self.set_pixel(x-i, y, color)
- self.set_pixel(x, y+i, color)
- self.set_pixel(x, y-i, color)
- self.set_pixel(x+i, y+i, color)
- self.set_pixel(x-i, y-i, color)
- self.set_pixel(x+i, y-i, color)
- self.set_pixel(x-i, y+i, color)
- end
- end
- #----------------------------------------------------------------------------
- # • Desenhar uma linha.
- #----------------------------------------------------------------------------
- def draw_line(start_x, start_y, end_x, end_y, color, size=1)
- set_pixel_s(start_x, start_y, color, size)
- distance = (start_x - end_x).abs + (start_y - end_y).abs
- for i in 1..distance
- x = (start_x + 1.0 * (end_x - start_x) * i / distance).to_i
- y = (start_y + 1.0 * (end_y - start_y) * i / distance).to_i
- set_pixel_s(x, y, color, size)
- end
- set_pixel_s(end_x, end_y, color, size)
- end
- #----------------------------------------------------------------------------
- # • draw_bar(x, y, current, current_max, file)
- # x : Coordenadas X.
- # y : Coordenadas Y.
- # current : Valor atual da barra.
- # current_max : Valor maxímo da barra.
- # file : Imagem da barra.
- #----------------------------------------------------------------------------
- # Permite adicionar uma barra.
- #----------------------------------------------------------------------------
- def draw_bar(x, y, current, current_max, file, folder=0)
- bitmap = folder == 0 ? Cache.picture(file) : Cache.system(file)
- cw = self.width.to_p(current, current_max)
- ch = self.height
- src_rect = Rect.new(0, 0, cw, ch)
- self.blt(x, y, bitmap, src_rect)
- end
- #----------------------------------------------------------------------------
- # • draw_bar_gauge(x, y, current, current_max, border, colors)
- # x : Coordenadas X.
- # y : Coordenadas Y.
- # current : Valor atual da barra.
- # current_max : Valor maxímo da barra.
- # border : Expressura da borda.
- # colors : Cores. [0, 1, 2]
- #----------------------------------------------------------------------------
- # Permite adicionar uma barra.
- #----------------------------------------------------------------------------
- def draw_bar_gauge(x, y, current, current_max, colors=[])
- cw = self.width.to_p(current, current_max)
- ch = self.height
- self.gradient_fill_rect(x, y, self.width, self.height, colors[0], colors[1])
- src_rect = Rect.new(0, 0, cw, ch)
- self.blt(x, y, self, src_rect)
- end
- #----------------------------------------------------------------------------
- # • draw_icon(icon_index, x, y, enabled)
- # icon_index : ID do ícone.
- # x : Coordenadas X.
- # y : Coordenadas Y.
- # enabled : Habilitar flag, translucido quando false
- #----------------------------------------------------------------------------
- #----------------------------------------------------------------------------
- def draw_icon(icon_index, x, y, enabled = true)
- bitmap = Cache.system("Iconset")
- rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
- self.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha)
- end
- #----------------------------------------------------------------------------
- # • _fill(x, y, width, height, color1, color2)
- # x : Coordenada X.
- # y : Coordenada Y.
- # width : Largura da barra.
- # height : Altura da barra.
- # color1 : Cor da borda.
- # color2 : Cor da barra.
- #----------------------------------------------------------------------------
- # Permite criar uma barra em fill_rect simples.
- #----------------------------------------------------------------------------
- def _fill(x, y, width, height, color1, color2)
- self.fill_rect(x, y, width, height, color1)
- self.fill_rect(x+1, y+1, width-2, height-2, color2)
- end
- #----------------------------------------------------------------------------
- # • gradation_fill_rect(*args)
- # x : Posição X.
- # y : Posição Y.
- # width : Largura da barra.
- # height : Altura da barra.
- # color1 : Primeira cor.
- # color2 : Segunda cor.
- # aling : 0 - Gradiação normal, 1 - Gradiação na Vertical, 2 - Gradiação concetrada
- #----------------------------------------------------------------------------
- # Faz uma gradiação;
- #----------------------------------------------------------------------------
- def gradation_fill_rect(x, y, width, height, color1, color2, align=0)
- case align
- when 0
- for ix in x...x + width
- red = color1.red + (color2.red - color1.red) * (ix - x) / (width - 1)
- green = color1.green + (color2.green - color1.green) * (ix - x) / (width - 1)
- blue = color1.blue + (color2.blue - color1.blue) * (i - x) / (width - 1)
- alpha = color1.alpha + (color2.alpha - color1.alpha) * (i - x) / (width - 1)
- color = Color.new(red, green, blue, alpha)
- self.fill_rect(ix, y, 1, height, color)
- end
- when 1
- for iy in y...y + height
- red = color1.red + (color2.red - color1.red) * (iy - y) / (height - 1)
- green = color1.green + (color2.green - color1.green) * (iy - y) / (height - 1)
- blue = color1.blue + (color2.blue - color1.blue) * (iy - y) / (height - 1)
- alpha = color1.alpha + (color2.alpha - color1.alpha) * (iy - y) / (height - 1)
- color = Color.new(red, green, blue, alpha)
- fill_rect(x, iy, width, 1, color)
- end
- when 2
- for ix in x...x + width
- for ij in y...y + height
- red = color1.red + (color2.red - color1.red) * ((ix - x) / (width - 1.0) + (ij - y) / (height - 1.0)) / 2
- green = color1.green + (color2.green - color1.green) * ((ix - x) / (width - 1.0) + (ij - y) / (height - 1.0)) / 2
- blue = color1.blue + (color2.blue - color1.blue) * ((ix - x) / (width - 1.0) + (ij - y) / (height - 1.0)) / 2
- alpha = color1.alpha + (color2.alpha - color1.alpha) * ((ix - x) / (width - 1.0) + (ij - y) / (height - 1.0)) / 2
- color = Color.new(red, green, blue, alpha)
- set_pixel(ix, ij, color)
- end
- end
- end
- end
- #----------------------------------------------------------------------------
- # • draw_gradation_gauge(x, y, width, height, current, current_max, border, colors, align)
- # x : Coordenadas X.
- # y : Coordenadas Y.
- # width : Largura da barra.
- # height : Altura da barra.
- # current : Valor atual da barra.
- # current_max : Valor maxímo da barra.
- # border : Expressura da borda.
- # colors : Cores. [0, 1, 2]
- # align : Alinhamento.
- #----------------------------------------------------------------------------
- # Permite adicionar uma barra.
- #----------------------------------------------------------------------------
- def draw_gradation_gauge(x, y, current, current_max, border, colors=[], align=2)
- cw = self.width.to_p(current, current_max)
- ch = self.height
- self._fill(x, y, self.width, self.height, colors[0], colors[0])
- self.gradation_fill_rect(x+border, y+border, self.width-(border/2), self.height-(border/2), colors[1], colors[2], align)
- src_rect = Rect.new(0, 0, cw, ch)
- self.blt(x, y, self, src_rect)
- end
- #--------------------------------------------------------------------------
- # • Desenho do gráfico de rosto
- # face_name : nome do gráfico de face
- # face_index : índice do gráfico de face
- # x : coordenada X
- # y : coordenada Y
- # enabled : habilitar flag, translucido quando false
- #--------------------------------------------------------------------------
- def draw_face(face_name, face_index, x, y, enabled = true)
- bitmaps = Cache.face(face_name)
- rect = Rect.new(face_index % 4 * 96, face_index / 4 * 96, 96, 96)
- self.blt(x, y, bitmaps, rect, enabled ? 255 : translucent_alpha)
- end
- #--------------------------------------------------------------------------
- # • Desenho do gráfico de face do herói
- # actor : herói
- # x : coordenada X
- # y : coordenada Y
- # enabled : habilitar flag, translucido quando false
- #--------------------------------------------------------------------------
- def draw_actor_face(actor, x, y, enabled = true)
- draw_face(actor.face_name, actor.face_index, x, y, enabled)
- end
- #--------------------------------------------------------------------------
- # • Desenho do nível
- # actor : herói
- # x : coordenada X
- # y : coordenada Y
- #--------------------------------------------------------------------------
- def draw_actor_level(actor, x, y)
- self.font.name = "Comic Sans MS"
- self.font.color = ColorBasic[35]
- self.font.size = 18
- self.draw_text(x, y, 32, 20, Vocab::level_a)
- self.font.size = 22
- draw_text(x + 16, y, 32, 20, actor.level, 2)
- end
- #----------------------------------------------------------------------------
- # • Pegar a largura.
- #----------------------------------------------------------------------------
- def get_the_width(lstring)
- string_rect = self.text_size(lstring)
- width = string_rect.width
- return width
- end
- #----------------------------------------------------------------------------
- # • Desenhar um círuclo preenchido.
- #----------------------------------------------------------------------------
- def fill_circle(x, y, r, c)
- rr = r*r
- for i in 0...r
- adj = Math.sqrt(rr - (i*i)).ceil
- xd = x - adj
- wd = 2 * adj
- self.fill_rect(xd, y-i, wd, 1, c)
- self.fill_rect(xd, y+i, wd, 1, c)
- end
- end
- #----------------------------------------------------------------------------
- # • Desenhar um triângulo preenchido.
- #----------------------------------------------------------------------------
- def fill_triangle(x, y, w, h, c)
- dx = w / 2
- dy = h
- d = Math.sqrt(dx*dx + dy*dy)
- for i in 0...d
- nx = ((dx*i) / d).round
- ny = ((dy*i) / d).round
- fill_rect(x-nx+dx, y+ny, nx*2, 1, c)
- end
- fill_rect(x, y+h, w, 1, c)
- end
- #----------------------------------------------------------------------------
- # • Desenhar um triângulo.
- #----------------------------------------------------------------------------
- def triangle(pts, c)
- p1, p2, p3 = pts
- dx1 = p3[0] - p2[0]
- dy1 = p3[1] - p2[1]
- d1 = Math.sqrt(dx1*dx1 + dy1*dy1)
- xs = p1[0]
- ys = p1[1]
- for i1 in 0...d1
- xe = ((dx1*i1) / d1) + p2[0]
- ye = ((dy1*i1) / d1) + p2[1]
- dx2 = xe - xs
- dy2 = ye - ys
- d2 = Math.sqrt(dx2*dx2 + dy2*dy2)
- for i2 in 0...d2
- xd = ((dx2*i2) / d2) + xs
- yd = ((dy2*i2) / d2) + ys
- self.set_pixel(xd, yd, c)
- end
- end
- end
- #----------------------------------------------------------------------------
- # • Desenhar um triângulo diferente.
- #----------------------------------------------------------------------------
- def fill_triangle3(pts, c, pos=[0, 0])
- return if pts.size != 3
- pts.sort! {|a, b| a[1] - b[1]}
- pt1, pt2, pt3 = pts
- dxt = (pt3[0] - pt1[0]) / 2
- dyt = (pt3[1] - pt1[1]) / 2
- dxm = pt2[0] - pt1[0]
- dym = pt2[1] - pt1[1]
- dm = dym.abs
- if dm > 0 and dyt != 0
- for i in 0...(dm+2)
- ix = ((dxm*i) / (dm+1))
- iy = ((dym*i) / (dm+1))
- edx = ix - (dxt * iy / dyt)
- self.fill_rect(ix+pt1[0]-[edx,0].max-2+pos[0], iy+pt1[1]+pos[1], edx.abs+4, 1, c)
- end
- end
- dxm = pt2[0] - pt3[0]
- dym = pt2[1] - pt3[1]
- dm = dym.abs
- if dm > 0 and dyt != 0
- for i in 0...(dm+2)
- ix = ((dxm*i) / (dm+1))
- iy = ((dym*i) / (dm+1))
- edx = ix - (dxt * iy / dyt)
- self.fill_rect(ix+pt3[0]-[edx,0].max-2+pos[0], iy+pt3[1]+pos[1], edx.abs+4, 1, c)
- end
- end
- end
- #----------------------------------------------------------------------------
- # • Desenhar um polígono.
- #----------------------------------------------------------------------------
- def fill_polygon(pts, c, pos=[0, 0])
- return if pts.size <= 2
- n = pts.size - 2
- for i in 0...n
- self.fill_triangle3(pts[i..(i + 2)], c, pos)
- end
- end
- #----------------------------------------------------------------------------
- # • Desenhar |ngon|
- #----------------------------------------------------------------------------
- def ngon(cx, cy, w, h, n, c, offset_angle = 0)
- return if (n < 3)
- center = [cx, cy]
- angle_step = (Math::PI * 2 / n)
- angle = (offset_angle * Math::PI / 180)
- p2 = [cx + Math.sin(angle) * w, cy - Math.cos(angle) * h]
- for i in 1..n
- angle += angle_step
- p1 = p2
- p2 = [cx + Math.sin(angle) * w, cy - Math.cos(angle) * h]
- self.fill_triangle3([p1, p2, center], c)
- end
- end
- end
- #==============================================================================
- # • Mouse
- #==============================================================================
- Dax.register(:Mouse, "Dax", 1.1)
- module Mouse
- extend self
- #--------------------------------------------------------------------------
- # • Inicialização dos objetos.
- #--------------------------------------------------------------------------
- def start
- @cursor = Sprite.new
- @cursor.z = 100000
- @cursor.bitmap = Bitmap.new(1, 1)
- x = Dax::Mouse_Name.empty? ? 1 : 0
- API::MouseShowCursor.call(x)
- graphic Dax::Mouse_Name
- update
- end
- #--------------------------------------------------------------------------
- # • graphic(graphic_set)
- # graphic_set : Se for número é um ícone; Se for string é uma imagem.
- #--------------------------------------------------------------------------
- def graphic(graphic_set)
- return if graphic_set.empty? or graphic_set.nil?
- if graphic_set.is_a?(Fixnum)
- @cursor.bitmap = Bitmap.new(24, 24)
- @cursor.bitmap.draw_icon(graphic_set.to_i, 0, 0)
- else
- @cursor.bitmap = Cache.picture(graphic_set.to_s)
- end
- end
- #--------------------------------------------------------------------------
- # • show(visible)
- # visible : True - para mostrar o mouse | False - para esconder o mouse.
- #--------------------------------------------------------------------------
- def show(visible=true)
- @cursor.visible = visible
- end
- #--------------------------------------------------------------------------
- # • update (Atualização das coordenadas)
- #--------------------------------------------------------------------------
- def update
- return if @cursor.nil?
- @cursor.x, @cursor.y = position
- end
- #----------------------------------------------------------------------------
- # • Atualizar o gráfico do mouse.
- #----------------------------------------------------------------------------
- def update_graphic
- return if @cursor.nil?
- @cursor.update if Graphics.frame_count % 5 == 1
- end
- #--------------------------------------------------------------------------
- # • cursor
- #--------------------------------------------------------------------------
- def cursor
- @cursor
- end
- #--------------------------------------------------------------------------
- # • x (Coordenada X do Mouse)
- #--------------------------------------------------------------------------
- def x
- @cursor.x
- end
- #--------------------------------------------------------------------------
- # • y (Coordenada Y do Mouse)
- #--------------------------------------------------------------------------
- def y
- @cursor.y
- end
- #--------------------------------------------------------------------------
- # • position (Posição do Mouse!)
- #--------------------------------------------------------------------------
- def position
- x, y = get_client_position
- return x, y
- end
- #--------------------------------------------------------------------------
- # • get_client_position (Posição original do Mouse!)
- #--------------------------------------------------------------------------
- def get_client_position
- pos = [0, 0].pack('ll')
- API::CursorPosition.call(pos)
- API::ScreenToClient.call(WINDOW, pos)
- return pos.unpack('ll')
- end
- #--------------------------------------------------------------------------
- # • find_window (Tamanho da window)
- #--------------------------------------------------------------------------
- def find_window
- game_name = '\0' * 256
- API::ReadIni.call('Game', 'Title', '', game_name, 255, '.\\Game.ini')
- game_name.delete!('\0')
- return API::FindWindow.call('RGSS Player', game_name)
- end
- #--------------------------------------------------------------------------
- # • Verificação se o mouse está na área de um determinado objeto.
- #--------------------------------------------------------------------------
- def in_area?(object_sprite)
- return @cursor.x.between?(object_sprite.x, object_sprite.x + object_sprite.width) &&
- @cursor.y.between?(object_sprite.y, object_sprite.y + object_sprite.height)
- end
- #--------------------------------------------------------------------------
- # • Verificação um objeto está na área do mouse.
- #--------------------------------------------------------------------------
- def object_area?(x, y, xy, yx)
- return Zone.object_in_area?(@cursor, x, y, xy, yx)
- end
- #----------------------------------------------------------------------------
- # • Mudar posição do cursor.
- #----------------------------------------------------------------------------
- def set_mouse(pos)
- SetCursorPos.call(pos.x, pos.y)
- update
- @cursor.x = @pos.x
- @cursor.y = @pos.y
- end
- #--------------------------------------------------------------------------
- # • Verificando se o mouse está na zona de um determinado objeto.
- #--------------------------------------------------------------------------
- def in_zone?(object, circled=0)
- Zone.full(self, object, circled)
- end
- WINDOW = find_window
- end
- class << DataManager
- alias init_mouse init
- def init
- Mouse.start
- init_mouse
- end
- end
- class << Input
- #----------------------------------------------------------------------------
- # • Atualização dos objetos.
- #----------------------------------------------------------------------------
- alias ds_core_engine_update update
- def update
- ds_core_engine_update
- Mouse.update
- end
- end
- class << Graphics
- alias mouse_update_graphic update
- def update
- mouse_update_graphic
- Mouse.update_graphic
- end
- end
- #==============================================================================
- # • Variable
- #==============================================================================
- Dax.register(:Variable)
- class Variables
- #----------------------------------------------------------------------------
- # • Iniciar
- #----------------------------------------------------------------------------
- def initialize
- @variable = {}
- end
- #----------------------------------------------------------------------------
- # • ID da variável.
- #----------------------------------------------------------------------------
- def [](name)
- @variable[name] || 0
- end
- #----------------------------------------------------------------------------
- # • ID mais valor da variável.
- #----------------------------------------------------------------------------
- def []=(name, value)
- @variable[name] = value
- end
- end
- #==============================================================================
- # • Switche
- #==============================================================================
- Dax.register(:Switche)
- class Switches
- #----------------------------------------------------------------------------
- # • Iniciar
- #----------------------------------------------------------------------------
- def initialize
- @switche = {}
- end
- #----------------------------------------------------------------------------
- # • ID da variável.
- #----------------------------------------------------------------------------
- def [](name)
- @switche[name] || false
- end
- #----------------------------------------------------------------------------
- # • ID mais valor da variável.
- #----------------------------------------------------------------------------
- def []=(name, value)
- @switche[name] = value
- end
- end
- #==============================================================================
- # • DataManager
- #==============================================================================
- class << DataManager
- #--------------------------------------------------------------------------
- # • Criação dos objetos do jogo
- #--------------------------------------------------------------------------
- alias dax_create_game_objects create_game_objects
- def create_game_objects
- dax_create_game_objects
- $variables = Variables.new
- $switches = Switches.new
- end
- end
- #==============================================================================
- # • Object
- #==============================================================================
- Dax.register(:Object, "Dax", 1.3)
- class Object
- #----------------------------------------------------------------------------
- # • Requerir um arquivo.
- #----------------------------------------------------------------------------
- def require(dll)
- $LOAD_PATH << "./"
- p("Carregando...#{dll}")
- Kernel.send(:require, dll)
- end
- #----------------------------------------------------------------------------
- # • Carregar um arquivo.
- #----------------------------------------------------------------------------
- def load(dll)
- $LOAD_PATH << "./"
- p "Loading... #{dll}"
- begin
- Kernel.send(:load,dll)
- rescue => error
- send_error(error)
- end
- end
- #----------------------------------------------------------------------------
- # • Trigger
- #----------------------------------------------------------------------------
- def trigger?(key)
- return key.is_a?(Symbol) ? Input.trigger?(key) : Key.trigger?(key)
- end
- #----------------------------------------------------------------------------
- # • Press
- #----------------------------------------------------------------------------
- def press?(key)
- return key.is_a?(Symbol) ? Input.press?(key) : Key.press?(key)
- end
- #----------------------------------------------------------------------------
- # • Repeat
- #----------------------------------------------------------------------------
- def repeat?(key)
- return key.is_a?(Symbol) ? Input.repeat?(key) : Key.repeat?(key)
- end
- #----------------------------------------------------------------------------
- # • Chamar a class color.
- #----------------------------------------------------------------------------
- def RGB(*args)
- Color.new(*args)
- end
- end
- #==============================================================================
- # • ColorBasic
- #==============================================================================
- Dax.register(:ColorBasic, "Dax", 1.2)
- module ColorBasic
- extend self
- #----------------------------------------------------------------------------
- # • Cores em Index
- #----------------------------------------------------------------------------
- def [](id)
- case id
- when -1 then Color.new(255, 255, 255) # White
- when 0 then Color.new(240, 248, 255) # Alice Blue
- when 1 then Color.new(250, 235, 215) # Antique_White
- when 2 then Color.new(0, 255, 255) # Aqua
- when 3 then Color.new(127, 255, 255) # Aqua Marine
- when 4 then Color.new(240, 255, 255) # Azure
- when 5 then Color.new(245, 245, 220) # Beige
- when 6 then Color.new(255, 228, 196) # Bisque
- when 7 then Color.new(0, 0, 0) # Black
- when 8 then Color.new(255, 235, 205) # Blanchedalmond
- when 9 then Color.new(0, 0, 255) # Blue
- when 10 then Color.new(138, 43, 226) # Blue Violet
- when 11 then Color.new(165, 42, 42) # Brown
- when 12 then Color.new(222, 184, 135) # Burly Wood
- when 13 then Color.new(93, 158, 160) # Cadet Blue
- when 14 then Color.new(127, 255, 0) # Chatreuse
- when 15 then Color.new(210, 105, 30) # Chocolate
- when 16 then Color.new(255, 127, 80) # Coral
- when 17 then Color.new(100, 149, 237) # Corn Flower Blue
- when 18 then Color.new(255, 248, 220) # CornSilk
- when 19 then Color.new(220, 20, 60) # Crimson
- when 20 then Color.new(0, 255, 255) # Cyan
- when 21 then Color.new(0, 0, 139) # DarkBlue
- when 22 then Color.new(0, 139, 139) # DarkCyan
- when 23 then Color.new(184, 134, 11) # DarkGoldEnrod
- when 24 then Color.new(169, 169, 169) # Dark Gray
- when 25 then Color.new(0, 100, 0) # Dark Green
- when 26 then Color.new(189, 183, 107) # Dark Khaki
- when 27 then Color.new(139, 0, 139) # Dark Magenta
- when 28 then Color.new(85, 107, 47) # Dark Oliver Green
- when 29 then Color.new(255, 140, 0) # Dark Orange
- when 30 then Color.new(153, 50, 204) # Dark orchid
- when 31 then Color.new(139, 0, 0) # Dark Red
- when 32 then Color.new(233, 150, 120) # Dark Salmon
- when 33 then Color.new(143, 188, 143) # Dark Sea Green
- when 34 then Color.new(72, 61, 139) # Dark Slate Blue
- when 35 then RGB(255, 255, 0) # Yellow
- when 36 then RGB(255, 0, 0) # Red
- when 37 then RGB(0, 255, 0) # Green
- when 38 then RGB(255, 128, 0) # Orange
- else
- Color.new("#FFFFFF") # Cor neutra.
- end
- end
- end
- #==============================================================================
- # • Entries
- #==============================================================================
- Dax.register(:entries, 'Dax', 1.0, '02/05/13')
- class Entries
- #----------------------------------------------------------------------------
- # • Variável pública da instância.
- #----------------------------------------------------------------------------
- attr_accessor :file
- attr_reader :get_number
- attr_reader :get_file
- attr_reader :get_array
- attr_reader :name
- #----------------------------------------------------------------------------
- # • Inicialização dos objetos.
- #----------------------------------------------------------------------------
- def initialize(directory, typefile)
- return unless FileTest.directory?(directory)
- @file = Dir.glob(directory + "/*.{" + typefile + "}")
- @file.each_index { |i| @get_number = i.to_i }
- @file.each { |i| @get_file = i.to_s }
- @file.each_with_index { |i| @get_array = i }
- @name = split @file[0]
- end
- #----------------------------------------------------------------------------
- # • Split | Separar
- #----------------------------------------------------------------------------
- def split(file)
- file.to_s.split('/').last
- end
- #----------------------------------------------------------------------------
- # • Obter nome.
- #----------------------------------------------------------------------------
- def name(id)
- return split(@file[id])
- end
- end
- #==============================================================================
- # • Window Core
- #==============================================================================
- # Autor: Dax
- # Versão: 1.0
- # Site: www.dax-soft.weebly.com
- # Requerimento: Dax Core
- #==============================================================================
- Dax.register(:Window_Core, "Dax", Dax::Version_WC)
- #==============================================================================
- # • WC
- #==============================================================================
- module WC
- extend self
- #----------------------------------------------------------------------------
- # • Variável e constantes.
- #----------------------------------------------------------------------------
- @imported = {} # Importar script.
- @version_imported = {} # Versão do script importado.
- @actor_imported = {} # Autor do script importado.
- #----------------------------------------------------------------------------
- # • Registrar script.
- #----------------------------------------------------------------------------
- def register(name, actor="Dax", version=1.0)
- @imported[name] = true
- @version_imported[name] = version
- @actor_imported[name] = actor
- end
- #----------------------------------------------------------------------------
- # • Cria uma condição de requerimento de script.
- #----------------------------------------------------------------------------
- def required(name, actor="Dax", version=1.0)
- @imported[name] && @version_imported[name] >= version && @actor_imported[name] == name
- end
- end
- #==============================================================================
- # • Letter Input
- #==============================================================================
- WC.register(:Letter_Input, "Dax", 1.0)
- module WC::Letter_Input
- extend self
- #----------------------------------------------------------------------------
- # • Variáveis e constantes.
- #----------------------------------------------------------------------------
- $acent = nil
- $times = [25, 25, 25, 25, 25, 25, 25, 25, 25]
- #----------------------------------------------------------------------------
- # • Atualização dos objetos do módulo.
- #----------------------------------------------------------------------------
- def update
- $times[0] = $times[$times.size-1] if $times[0] < $times[$times.size-1] and API::StateKey.call(8) == 0
- $times[1] = $times[$times.size-1] if $times[1] < $times[$times.size-1] and API::StateKey.call(46) == 0
- $times[2] = $times[$times.size-1] if $times[2] < $times[$times.size-1] and API::StateKey.call(192) == 0
- $times[3] = $times[$times.size-1] if $times[3] < $times[$times.size-1] and API::StateKey.call(226) == 0
- $times[4] = $times[$times.size-1] if $times[4] < $times[$times.size-1] and API::StateKey.call(54) == 0
- $times[5] = $times[$times.size-1] if $times[5] < $times[$times.size-1] and API::StateKey.call(193) == 0
- $times[6] = $times[$times.size-1] if $times[6] < $times[$times.size-1] and API::StateKey.call(186) == 0
- $times[7] = $times[$times.size-1] if $times[7] < $times[$times.size-1] and API::StateKey.call(220) == 0
- end
- #----------------------------------------------------------------------------
- # • Input : Teclas.
- #----------------------------------------------------------------------------
- def input
- acent = get_acent
- na = false
- unless acent.nil?
- if $acent.nil?
- $acent = acent
- na = true
- else
- r = $acent + acent
- $acent = nil
- return r
- end
- end
- unless na
- r = get_symbol
- if !r.nil?
- if !$acent.nil?
- a = $acent
- $acent = nil
- return a + r.to_s
- else
- return r
- end
- end
- r = get_number
- if !r.nil?
- if !$acent.nil?
- a = $acent
- $acent = nil
- return a + r.to_s
- else
- return r
- end
- end
- end
- m = (get_shift or get_caps_lock)
- if $acent.nil?
- r = get_character(m)
- if r == ""
- if space?
- r = " "
- end
- end
- else
- r = get_character_acent($acent, m)
- unless r == ""
- $acent = nil
- else
- if space?
- a = $acent
- $acent = nil
- r = a + " "
- end
- end
- end
- return r if !r.empty?
- end
- #----------------------------------------------------------------------------
- # • Teclas.
- #----------------------------------------------------------------------------
- def space?; trigger?(Key::SPACE); end;
- def enter?; trigger?(Key::ENTER); end;
- def back?; trigger?(Key::BACKSPACE); end;
- def delete?; trigger?(Key::DELETE); end;
- def asp?; trigger?(Key::F8); end;
- def tra?; trigger?(226); end;
- def num6?; trigger?(Key::NUMPAD6); end;
- def backslash?; trigger?(193); end;
- def tc?; trigger?(186); end;
- def t220?; trigger?(220); end;
- def end?; trigger?(35); end;
- #----------------------------------------------------------------------------
- # • Acento.
- #----------------------------------------------------------------------------
- def acent
- if press?(16) and trigger?(19)
- return "`"
- elsif trigger?(19)
- return "´"
- elsif press?(16) and trigger?(222)
- return "^"
- elsif trigger?(222)
- return "~"
- elsif trigger?(54)
- return "¨"
- end
- return nil
- end
- #----------------------------------------------------------------------------
- # • Obter Caps Lock
- #----------------------------------------------------------------------------
- def get_caps_lock
- if API::StateKey.call(20) == 1
- return true
- else
- return false
- end
- end
- #----------------------------------------------------------------------------
- # • Obter Shift
- #----------------------------------------------------------------------------
- def get_shift
- if press?(Key::SHIFT)
- return true
- end
- return false
- end
- #----------------------------------------------------------------------------
- # • Obter Characters
- #----------------------------------------------------------------------------
- def get_character(up)
- c = ""
- if trigger?(Key::A)
- c = "a"
- elsif trigger?(Key::B)
- c = "b"
- elsif trigger?(Key::C)
- c = "c"
- elsif trigger?(Key::D)
- c = "d"
- elsif trigger?(Key::E)
- c = "e"
- elsif trigger?(Key::F)
- c = "f"
- elsif trigger?(Key::G)
- c = "g"
- elsif trigger?(Key::H)
- c = "h"
- elsif trigger?(Key::I)
- c = "i"
- elsif trigger?(Key::J)
- c = "j"
- elsif trigger?(Key::K)
- c = "k"
- elsif trigger?(Key::L)
- c = "l"
- elsif trigger?(Key::M)
- c = "m"
- elsif trigger?(Key::N)
- c = "n"
- elsif trigger?(Key::O)
- c = "o"
- elsif trigger?(Key::P)
- c = "p"
- elsif trigger?(Key::Q)
- c = "q"
- elsif trigger?(Key::R)
- c = "r"
- elsif trigger?(Key::S)
- c = "s"
- elsif trigger?(Key::T)
- c = "t"
- elsif trigger?(Key::U)
- c = "u"
- elsif trigger?(Key::V)
- c = "v"
- elsif trigger?(Key::W)
- c = "w"
- elsif trigger?(Key::X)
- c = "x"
- elsif trigger?(Key::Y)
- c = "y"
- elsif trigger?(Key::Z)
- c = "z"
- elsif tc?
- c = "ç"
- end
- if up
- c = c.upcase
- end
- return c
- end
- #----------------------------------------------------------------------------
- # • Obter acentos.
- #----------------------------------------------------------------------------
- def get_acent
- if press?(16) and trigger?(219)
- return "`"
- elsif trigger?(219)
- return "´"
- elsif press?(16) and trigger?(222)
- return "^"
- elsif trigger?(222)
- return "~"
- elsif press?(16) and trigger?(Key::N6)
- return "¨"
- end
- end
- #----------------------------------------------------------------------------
- # • Obter characters com acentos.
- #----------------------------------------------------------------------------
- def get_character_acent(acent, up)
- c = ""
- if trigger?(Key::A)
- if up
- case acent
- when "`"
- c = "À"
- when "´"
- c = "Á"
- when "^"
- c = "Â"
- when "~"
- c = "~A"
- when "¨"
- c = "Ä"
- end
- else
- case acent
- when "`"
- c = "à"
- when "´"
- c = "á"
- when "^"
- c = "â"
- when "~"
- c = "ã"
- when "¨"
- c = "ä"
- end
- end
- return c
- elsif trigger?(Key::E)
- if up
- case acent
- when "`"
- c = "È"
- when "´"
- c = "É"
- when "^"
- c = "Ê"
- when "~"
- c = "~E"
- when "¨"
- c = "Ë"
- end
- else
- case acent
- when "`"
- c = "è"
- when "´"
- c = "é"
- when "^"
- c = "ê"
- when "~"
- c = "~e"
- when "¨"
- c = "ë"
- end
- end
- return c
- elsif trigger?(Key::I)
- if up
- case acent
- when "`"
- c = "Ì"
- when "´"
- c = "Í"
- when "^"
- c = "Î"
- when "~"
- c = "~I"
- when "¨"
- c = "Ï"
- end
- else
- case acent
- when "`"
- c = "ì"
- when "´"
- c = "í"
- when "^"
- c = "î"
- when "~"
- c = "~i"
- when "¨"
- c = "ï"
- end
- end
- return c
- elsif trigger?(Key::O)
- if up
- case acent
- when "`"
- c = "Ò"
- when "´"
- c = "Ó"
- when "^"
- c = "Ô"
- when "~"
- c = "~O"
- when "¨"
- c = "Ö"
- end
- else
- case acent
- when "`"
- c = "ò"
- when "´"
- c = "ó"
- when "^"
- c = "ô"
- when "~"
- c = "õ"
- when "¨"
- c = "ö"
- end
- end
- return c
- elsif trigger?(Key::U)
- if up
- case acent
- when "`"
- c = "Ù"
- when "´"
- c = "Ú"
- when "^"
- c = "Û"
- when "~"
- c = "~U"
- when "¨"
- c = "Ü"
- end
- else
- case acent
- when "`"
- c = "ù"
- when "´"
- c = "ú"
- when "^"
- c = "û"
- when "~"
- c = "~u"
- when "¨"
- c = "ü"
- end
- end
- return c
- elsif trigger?(Key::B)
- c = acent + "b"
- elsif trigger?(Key::C)
- c = acent + "c"
- elsif trigger?(Key::D)
- c = acent + "d"
- elsif trigger?(Key::F)
- c = acent + "f"
- elsif trigger?(Key::G)
- c = acent + "g"
- elsif trigger?(Key::H)
- c = acent + "h"
- elsif trigger?(Key::J)
- c = acent + "j"
- elsif trigger?(Key::K)
- c = acent + "k"
- elsif trigger?(Key::L)
- c = acent + "l"
- elsif trigger?(Key::M)
- c = acent + "m"
- elsif trigger?(Key::N)
- c = acent + "n"
- elsif trigger?(Key::P)
- c = acent + "p"
- elsif trigger?(Key::Q)
- c = acent + "q"
- elsif trigger?(Key::R)
- c = acent + "r"
- elsif trigger?(Key::S)
- c = acent + "s"
- elsif trigger?(Key::T)
- c = acent + "t"
- elsif trigger?(Key::V)
- c = acent + "v"
- elsif trigger?(Key::W)
- c = acent + "w"
- elsif trigger?(Key::X)
- c = acent + "x"
- elsif trigger?(Key::Y)
- c = acent + "y"
- elsif trigger?(Key::Z)
- c = acent + "z"
- elsif tc?
- c = acent + "ç"
- end
- if up and c != ""
- c = c.upcase
- end
- return c
- end
- #----------------------------------------------------------------------------
- # • Obter número.
- #----------------------------------------------------------------------------
- def get_number
- if trigger?(Key::N0)
- c = 0
- elsif trigger?(Key::N1)
- c = 1
- elsif trigger?(Key::N2)
- c = 2
- elsif trigger?(Key::N3)
- c = 3
- elsif trigger?(Key::N4)
- c = 4
- elsif trigger?(Key::N5)
- c = 5
- elsif trigger?(Key::N6)
- c = 6
- elsif trigger?(Key::N7)
- c = 7
- elsif trigger?(Key::N8)
- c = 8
- elsif trigger?(Key::N9)
- c = 9
- elsif trigger?(Key::NUMPAD0)
- c = 0
- elsif trigger?(Key::NUMPAD1)
- c = 1
- elsif trigger?(Key::NUMPAD2)
- c = 2
- elsif trigger?(Key::NUMPAD3)
- c = 3
- elsif trigger?(Key::NUMPAD4)
- c = 4
- elsif trigger?(Key::NUMPAD5)
- c = 5
- elsif trigger?(Key::NUMPAD6)
- c = 6
- elsif trigger?(Key::NUMPAD7)
- c = 7
- elsif trigger?(Key::NUMPAD8)
- c = 8
- elsif trigger?(Key::NUMPAD9)
- c = 9
- end
- end
- #----------------------------------------------------------------------------
- # • Obter simbolos;
- #----------------------------------------------------------------------------
- def get_symbol
- if press?(16) and trigger?(189)
- c = "_"
- elsif trigger?(189)
- c = "-"
- elsif press?(17) and press?(18) and trigger?(187)
- c = "§"
- elsif press?(16) and trigger?(187)
- c = "+"
- elsif trigger?(187)
- c = "="
- elsif press?(17) and press?(18) and trigger?(221)
- c = "ª"
- elsif press?(16) and trigger?(221)
- c = "{"
- elsif trigger?(221)
- c = "["
- elsif press?(17) and press?(18) and t220?
- c = "º"
- elsif press?(16) and t220?
- c = "}"
- elsif t220?
- c = "]"
- elsif press?(16) and tra?
- c = "|"
- elsif tra?
- c = "\\"
- elsif press?(16) and trigger?(188)
- c = "<"
- elsif trigger?(188)
- c = ","
- elsif press?(16) and trigger?(190)
- c = ">"
- elsif trigger?(190)
- c = "."
- elsif press?(16) and trigger?(191)
- c = ":"
- elsif trigger?(191)
- c = ";"
- elsif press?(17) and press?(18) and backslash?
- c = "°"
- elsif press?(16) and backslash?
- c = "?"
- elsif backslash?
- c = "/"
- elsif press?(16) and asp?
- c = "\""
- elsif asp?
- c = "'"
- elsif trigger?(111)
- c = "/"
- elsif trigger?(106)
- c = "*"
- elsif trigger?(109)
- c = "-"
- elsif trigger?(107)
- c = "+"
- elsif trigger?(194)
- c = "."
- elsif trigger?(110)
- c = ","
- elsif press?(16) and trigger?(Key::N0)
- c = ")"
- elsif press?(17) and press?(18) and trigger?(Key::N1)
- c = "¹"
- elsif press?(16) and trigger?(Key::N1)
- c = "!"
- elsif press?(17) and press?(18) and trigger?(Key::N2)
- c = "²"
- elsif press?(16) and trigger?(Key::N3)
- c = "@"
- elsif press?(17) and press?(18) and trigger?(Key::N3)
- c = "³"
- elsif press?(16) and trigger?(Key::N3)
- c = "#"
- elsif press?(17) and press?(18) and trigger?(Key::N4)
- c = "£"
- elsif press?(16) and trigger?(Key::N4)
- c = "$"
- elsif press?(17) and press?(18) and trigger?(Key::N5)
- c = "¢"
- elsif press?(16) and trigger?(Key::N5)
- c = "%"
- elsif press?(17) and press?(18) and trigger?(Key::N6)
- c = "¬"
- elsif press?(16) and trigger?(Key::N7)
- c = "&"
- elsif press?(16) and trigger?(Key::N8)
- c = "*"
- elsif press?(16) and trigger?(Key::N9)
- c = "("
- end
- end
- end
- class << Input
- alias method_letter_input_update update
- def update
- method_letter_input_update
- WC::Letter_Input.update
- end
- end
- #==============================================================================
- # • Position
- #==============================================================================
- WC.register(:Pos_Size, "Dax", 1.0)
- class WC::Position < Struct.new(:x, :y)
- #----------------------------------------------------------------------------
- # • Inicialização dos objetos.
- #----------------------------------------------------------------------------
- def initialize(x, y)
- self.x = x.to_i
- self.y = y.to_i
- end
- #----------------------------------------------------------------------------
- # • Add.
- #----------------------------------------------------------------------------
- def +(add)
- rst = WC::Position.new(self.x, self.y)
- rst.x += add.x.to_i
- rst.y += add.y.to_i
- rst
- end
- #----------------------------------------------------------------------------
- # • Sub.
- #----------------------------------------------------------------------------
- def -(add)
- rst = WC::Position.new(self.x, self.y)
- rst.x -= add.x.to_i
- rst.y -= add.y.to_i
- rst
- end
- #----------------------------------------------------------------------------
- # • Set
- #----------------------------------------------------------------------------
- def set(pos)
- self.x = pos.x.to_i
- self.y = pos.y.to_i
- end
- #----------------------------------------------------------------------------
- # • Inspecionar
- #----------------------------------------------------------------------------
- def inspects
- "pos: #{self.to_s}"
- end
- #----------------------------------------------------------------------------
- # • Converter para string.
- #----------------------------------------------------------------------------
- def to_s
- "(#{self.x}, #{self.y})"
- end
- #----------------------------------------------------------------------------
- # • Converter para array.
- #----------------------------------------------------------------------------
- def to_a
- [self.x, self.y]
- end
- #----------------------------------------------------------------------------
- # • Achar o tamanho.
- #----------------------------------------------------------------------------
- def to_size
- WC::Size.new(self.x, self.y)
- end
- #----------------------------------------------------------------------------
- # • Verificar.
- #----------------------------------------------------------------------------
- def ==(obj)
- unless obj.is_a?(WC::Position)
- return false
- end
- if self.x == obj.x and self.y == obj.y
- return true
- end
- return false
- end
- #----------------------------------------------------------------------------
- # • Converter para um valor bruto.
- #----------------------------------------------------------------------------
- def abs
- WC::Position.new(self.x.abs, self.y.abs)
- end
- end
- #==============================================================================
- # • Size
- #==============================================================================
- WC.register(:Size, "Dax", 1.0)
- class WC::Size < Struct.new(:width, :height)
- #----------------------------------------------------------------------------
- # • Add.
- #----------------------------------------------------------------------------
- def +(add)
- rst = WC::Size.new(self.width, self.height)
- rst.width += add.width
- rst.height += add.height
- rst
- end
- #----------------------------------------------------------------------------
- # • Sub.
- #----------------------------------------------------------------------------
- def -(add)
- rst = WC::Size.new(self.width, self.height)
- rst.width -= add.width
- rst.height -= add.height
- rst
- end
- #----------------------------------------------------------------------------
- # • Set
- #----------------------------------------------------------------------------
- def set(size)
- self.width = size.width
- self.height = size.height
- end
- #----------------------------------------------------------------------------
- # • Inspecionar
- #----------------------------------------------------------------------------
- def inspect
- "size: #{self.to_s}"
- end
- #----------------------------------------------------------------------------
- # • Converter para string.
- #----------------------------------------------------------------------------
- def to_s
- "(#{self.width}, #{self.height})"
- end
- #----------------------------------------------------------------------------
- # • Converter para array.
- #----------------------------------------------------------------------------
- def to_a
- [self.width, self.height]
- end
- #----------------------------------------------------------------------------
- # • Converter para posição.
- #----------------------------------------------------------------------------
- def to_position
- WC::Position.new(self.width, self.height)
- end
- #----------------------------------------------------------------------------
- # • Igual
- #----------------------------------------------------------------------------
- def ==(s)
- unless s.is_a?(WC::Size)
- return false
- end
- if self.width == s.width and self.height == s.height
- return true
- else
- return false
- end
- end
- #----------------------------------------------------------------------------
- # • Converter para valor bruto.
- #----------------------------------------------------------------------------
- def abs
- WC::Size.new(self.width.abs, self.height.abs)
- end
- end
- #==============================================================================
- # • Kernel
- #==============================================================================
- WC.register(:Kernel, "Dax", 1.0)
- module Kernel
- #----------------------------------------------------------------------------
- # • Achar a posição.
- #----------------------------------------------------------------------------
- def wc_pos(x, y)
- WC::Position.new(x, y)
- end
- #----------------------------------------------------------------------------
- # • Achar o tamanho.
- #----------------------------------------------------------------------------
- def wc_size(w, h)
- WC::Size.new(w, h)
- end
- end
- #==============================================================================
- # • TextBase
- #==============================================================================
- WC.register(:text_base, "Dax", 1.0)
- class TextBase
- #----------------------------------------------------------------------------
- # • Inicialização dos objetos.
- #----------------------------------------------------------------------------
- def initialize
- @text = ""
- end
- #----------------------------------------------------------------------------
- # • Adicionar texto.
- #----------------------------------------------------------------------------
- def text=(text_add)
- @text += text_add
- end
- #----------------------------------------------------------------------------
- # • Adicionar uma nova linha.
- #----------------------------------------------------------------------------
- def text(text, nspace=0)
- @text += "\r\n" + (" " * nspace) + text
- end
- #----------------------------------------------------------------------------
- # • Adicionar comentário;
- #----------------------------------------------------------------------------
- def comment=(text_add, comment="#")
- @text += comment + text_add
- end
- #----------------------------------------------------------------------------
- # • Adicionar uma nova linha como comentário.
- #----------------------------------------------------------------------------
- def comment(text, nspace=0, comment="#")
- @text += "\r\n" + (" " * nspace) + comment + text
- end
- #----------------------------------------------------------------------------
- # • Salvar o texto.
- #----------------------------------------------------------------------------
- def save(filename="")
- _file = File.open(filename, "a+").each { |file|
- file.write(@text.to_s)
- file.close
- }
- end
- end
- #==============================================================================
- # • Psych Core
- #==============================================================================
- # Autor: Dax
- # Versão: 0.1
- # Site: www.dax-soft.weebly.com
- # Requerimento: Dax Core 1.9
- #==============================================================================
- # • Descrição:
- #------------------------------------------------------------------------------
- # Trata-se de vários scripts para proporcionar uma física simples.
- #==============================================================================
- Dax.register(:Psych_Core, "Dax", Dax::Version_PS)
- module PS
- extend self
- #----------------------------------------------------------------------------
- # • Variável e constantes.
- #----------------------------------------------------------------------------
- @imported = {} # Importar script.
- @version_imported = {} # Versão do script importado.
- @actor_imported = {} # Autor do script importado.
- #----------------------------------------------------------------------------
- # • Registrar script.
- #----------------------------------------------------------------------------
- def register(name, actor="Dax", version=Dax::Version_PS)
- @imported[name] = true
- @version_imported[name] = version
- @actor_imported[name] = actor
- end
- #----------------------------------------------------------------------------
- # • Cria uma condição de requerimento de script.
- #----------------------------------------------------------------------------
- def required(name, actor="Dax", version=Dax::Version_PS)
- @imported[name] && @version_imported[name] >= version && @actor_imported[name] == name
- end
- end
- #==============================================================================
- # • LimitScreen | Sisetma que cria uma condição para o objeto não passar os limites da tela.
- #==============================================================================
- PS.register(:LimitScreen, "Dax", 1.0)
- class PS::LimitScreen
- #----------------------------------------------------------------------------
- # • Inicialização dos objetos.
- #----------------------------------------------------------------------------
- def initialize(object, limit_screen=[Graphics.width, Graphics.height])
- @object = object
- @limit_screen = limit_screen
- up?
- down?
- left?
- right?
- end
- #----------------------------------------------------------------------------
- # • Verificar se o objeto está tentando passar do limite de cima.
- #----------------------------------------------------------------------------
- def up?
- if @object.y <= 0
- @object.y = 0
- end
- end
- #----------------------------------------------------------------------------
- # • Verificar se o objeto está tentando passar do limite de baixo.
- #----------------------------------------------------------------------------
- def down?
- if @object.y >= @limit_screen[1] - @object.height
- @object.y = @limit_screen[1] - @object.height
- end
- end
- #----------------------------------------------------------------------------
- # • Verificar se o objeto está tentando passar do limite da esquerda.
- #----------------------------------------------------------------------------
- def left?
- if @object.x <= 0
- @object.x = 0
- end
- end
- #----------------------------------------------------------------------------
- # • Verificar se o object está tentando passar do limite da direita.
- #----------------------------------------------------------------------------
- def right?
- if @object.x >= @limit_screen[0] - @object.width
- @object.x = @limit_screen[0] - @object.height
- end
- end
- end
- #==============================================================================
- # • DRGSS | Comandos do RGSS...
- #==============================================================================
- Dax.register(:DRGSS, "Dax", Dax::DRGSS)
- module DRGSS
- extend self
- #----------------------------------------------------------------------------
- # • Comandos simples do menu.
- #----------------------------------------------------------------------------
- def command_menu(buffer)
- return if buffer.nil?
- return "SceneManager.call(Scene_Item)" if buffer =~ /item/
- return "SceneManager.call(Scene_Skill)" if buffer =~ /skill/
- return "SceneManager.call(Scene_Equip)" if buffer =~ /equip/
- return "SceneManager.call(Scene_Status)" if buffer =~ /status/
- return "SceneManager.call(Scene_Save)" if buffer =~ /save/
- return "SceneManager.call(Scene_End)" if buffer =~ /end/
- end
- #----------------------------------------------------------------------------
- # • Ações básicas
- #----------------------------------------------------------------------------
- def action_base(buffer)
- return if buffer.nil?
- if buffer =~ /ani_player: (\d+)/ then $game_player.animation_id = $1.to_i end
- if buffer =~ /ani_event: (\d+), (\d+)/ then $game_map.events[$1.to_i].animation_id = $2.to_i end
- if buffer =~ /clear_vars: (\d+)..(\d+)/ then ($1.to_i...$2.to_i).each { |i| $game_variables[i] = 0 } end
- if buffer =~ /common_event: (\d+)/ then $game_temp.reserve_common_event($1.to_i) end
- end
- #----------------------------------------------------------------------------
- # • Condições básicas personagem.
- #----------------------------------------------------------------------------
- def if_player(buffer)
- return if buffer.nil?
- if buffer =~ /skill (\d+), (\d+)/ then return $game_party.members[$1.to_i].skill_learn?($data_skills[$2.to_i]) ? true : false end
- if buffer =~ /weapon (\d+), (\d+)/ then return $game_party.members[$1.to_i].weapons.include?($data_weapons[$2.to_i]) ? true : false end
- if buffer =~ /armor (\d+), (\d+)/ then return $game_party.members[$1.to_i].armors.include?($data_armors[$2.to_i]) ? true : false end
- end
- #----------------------------------------------------------------------------
- # • Extrair scripts.
- #----------------------------------------------------------------------------
- def extract_scripts(type=".txt",options={})
- except = options[:except] || []
- folder = options[:folder] || ""
- id = 0 #
- $RGSS_SCRIPTS.each do |script|
- name = script[1]
- data = script[3]
- next if except.include? name or name.empty? or data.empty?
- filename = sprintf("%03d", id) + "_" + name
- p "Writing: #{filename}"
- File.open(folder+filename+"#{type}", "wb") do |file|
- file.write data
- end
- id += 1
- end
- end
- #----------------------------------------------------------------------------
- # • Carregar scripts.
- #----------------------------------------------------------------------------
- def load_scripts(type=".txt",options={})
- skip = options[:skip] || []
- folder = options[:folder] || ""
- begin
- Dir.foreach(folder) do |file|
- file_id = file[0,3].to_i
- break if file_id == options[:limit]
- next if file == "." or file == ".." or File.extname(file) != "#{type}" or skip.include?(file_id)
- r = load (folder+"#{file}")
- p "Loaded: #{r}"
- end
- rescue => error
- send_error(error)
- end
- end
- end
- #==============================================================================
- # • Extension
- #==============================================================================
- # Autor: Dax
- # Versão: 1.0
- # Site: www.dax-soft.weebly.com
- # Requerimento: Dax Core 1.9>
- #==============================================================================
- Dax.register(:Extension, "Dax", Dax::Version_EX)
- #==============================================================================
- # • WC
- #==============================================================================
- module Extension
- extend self
- #----------------------------------------------------------------------------
- # • Variável e constantes.
- #----------------------------------------------------------------------------
- @imported = {} # Importar script.
- @version_imported = {} # Versão do script importado.
- @actor_imported = {} # Autor do script importado.
- #----------------------------------------------------------------------------
- # • Registrar script.
- #----------------------------------------------------------------------------
- def register(name, actor="Dax", version=1.0)
- @imported[name] = true
- @version_imported[name] = version
- @actor_imported[name] = actor
- end
- #----------------------------------------------------------------------------
- # • Cria uma condição de requerimento de script.
- #----------------------------------------------------------------------------
- def required(name, actor="Dax", version=1.0)
- @imported[name] && @version_imported[name] >= version && @actor_imported[name] == name
- end
- end
- #==============================================================================
- # • Mouse Extension | Picture Touch
- #==============================================================================
- Extension.register(:Mouse_Extension, "Dax", 1.0)
- class Touch_Picture < Sprite
- #----------------------------------------------------------------------------
- # • Inicialização dos objetos.
- # name : Nome da picture.
- # x : Posição X da picture.
- # y : Posição Y da picture.
- # z : Altura da picture.
- #----------------------------------------------------------------------------
- def initialize(name="",x=0,y=0,z=0,switche_id=nil)
- super()
- self.bitmap = Cache.picture(name)
- self.x, self.y, self.z = x, y, z
- @clicked = false
- @switche_id = switche_id
- end
- #----------------------------------------------------------------------------
- # • Renovação dos objetos.
- #----------------------------------------------------------------------------
- def dispose
- self.bitmap.dispose if !self.bitmap.nil?
- super
- end
- #----------------------------------------------------------------------------
- # • Atualizaçaõ dos objetos.
- # action_clicked : Caso seja um nome em formato de String irá chamar uma
- # scene, caso seja em formato de número irá chamar um evento comum.
- #----------------------------------------------------------------------------
- def update
- self.visible = !$game_switches[@switche_id] unless @switche_id.nil?
- if Mouse.in_area?(self)
- effect_on_area?
- @clicked = trigger?(0x01) or repeat?(0x01)
- action if @clicked && trigger?(0x01) or repeat?(0x01)
- else
- effect_off_area?
- @clicked = false if trigger?(0x01) or repeat?(0x01)
- end
- end
- #----------------------------------------------------------------------------
- # • Acão após o clique na imagem.
- #----------------------------------------------------------------------------
- def action
- end
- #----------------------------------------------------------------------------
- # • Efeito quando estiver na área.
- #----------------------------------------------------------------------------
- def effect_on_area?
- self.opacity = 255
- end
- #----------------------------------------------------------------------------
- # • Efeito quando estiver fora da área.
- #----------------------------------------------------------------------------
- def effect_off_area?
- self.opacity = 128
- end
- end
- #==============================================================================
- # • Simple Touch Picture | Mouse Extension
- #==============================================================================
- Extension.register(:Simple_Touch_Picture, "Dax", 1.0)
- class Simple_Touch_Picture < Touch_Picture
- #----------------------------------------------------------------------------
- # • Inicialização dos objetos.
- # name : Nome da picture.
- # x : Posição X da picture.
- # y : Posição Y da picture.
- # z : Altura da picture.
- # action : Ação após o clique do Mouse.
- #----------------------------------------------------------------------------
- def initialize(action, *args)
- super(*args)
- @action = action
- end
- #----------------------------------------------------------------------------
- # • Renovação dos objetos.
- #----------------------------------------------------------------------------
- def dispose
- super
- end
- #----------------------------------------------------------------------------
- # • Atualização dos objetos.
- #----------------------------------------------------------------------------
- def update
- super
- end
- #----------------------------------------------------------------------------
- # • Ação após o clique.
- #----------------------------------------------------------------------------
- def action
- eval(@action.to_s) unless @action.nil?
- end
- #----------------------------------------------------------------------------
- # • Efeito do objeto quando estiver na área.
- #----------------------------------------------------------------------------
- def effect_on_area?
- super
- end
- #----------------------------------------------------------------------------
- # • Efeito do objeto quando estiver fora da área.
- #----------------------------------------------------------------------------
- def effect_off_area?
- super
- end
- #----------------------------------------------------------------------------
- # • Retorna ao conteúdo.
- #----------------------------------------------------------------------------
- def contents
- self
- end
- end
- #==============================================================================
- # • Mouse Extension | Touch Icon
- #==============================================================================
- Extension.register(:Touch_Icon, "Dax", 1.0)
- class Touch_Icon < Sprite
- #----------------------------------------------------------------------------
- # • Inicialização dos objetos.
- # id : ID do ícone no database.
- # x : Posição X do objeto.
- # y : Posição Y do objeto.
- # z : Altura do objeto.
- #----------------------------------------------------------------------------
- def initialize(id=0, x=0, y=0, z=0, switche_id=nil,effect=:visible,texts=["", ColorBasic[-1], 2],font=["Arial", 16])
- super()
- self.x, self.y, self.z = x, y, z
- self.bitmap = Bitmap.new(24, 24)
- self.bitmap.draw_icon(id.to_i, 0, 0)
- @clicked = false
- @switche_id = switche_id
- @effect = effect
- unless texts[0].empty?
- @text = Sprite.new
- @text.bitmap = Bitmap.new(100 + texts[0].split(//).size, 24)
- @text.x, @text.y, @text.z = self.x + (28 + texts[2]), self.y + texts[2], self.z
- @text.opacity = 0
- @text.bitmap.draw_text(0, 0, @text.width, @text.height, texts[0].to_s)
- @text.bitmap.font.name, @text.bitmap.font.size = font
- end
- end
- #----------------------------------------------------------------------------
- # • Renovação dos objetos.
- #----------------------------------------------------------------------------
- def dispose
- self.bitmap.dispose if !self.bitmap.nil?
- super
- end
- #----------------------------------------------------------------------------
- # • Atualizaçaõ dos objetos.
- # action_clicked : Caso seja um nome em formato de String irá chamar uma
- # scene, caso seja em formato de número irá chamar um evento comum.
- #----------------------------------------------------------------------------
- def update
- if @effect == :visible then self.visible = !$game_switches[@switche_id] unless @switche_id.nil? end
- if @effect == (:visible or :opacity) then @text.visible = self.visible unless @text.nil? end
- unless @switche_id.nil? then self.opacity = 64 if @effect == :opacity and !$game_switches[@switche_id] end
- if Mouse.in_area?(self)
- @text.opacity = 255 unless @text.nil?
- effect_on_area?
- @clicked = trigger?(0x01) or repeat?(0x01)
- action if @clicked && trigger?(0x01) or repeat?(0x01)
- else
- @text.opacity = 0 unless @text.nil?
- effect_off_area?
- @clicked = false if trigger?(0x01) or repeat?(0x01)
- end
- end
- #----------------------------------------------------------------------------
- # • Acão após o clique na imagem.
- #----------------------------------------------------------------------------
- def action
- return if self.visible or self.opacity == 64
- @text.visible = false unless @text.nil?
- end
- #----------------------------------------------------------------------------
- # • Efeito quando estiver na área.
- #----------------------------------------------------------------------------
- def effect_on_area?
- self.opacity = 255
- end
- #----------------------------------------------------------------------------
- # • Efeito quando estiver fora da área.
- #----------------------------------------------------------------------------
- def effect_off_area?
- self.opacity = 128
- end
- end
- #==============================================================================
- # • Mouse Extension | Simple Touch Icon
- #==============================================================================
- Extension.register(:Simple_Touch_Icon, "Dax", 1.0)
- class Simple_Touch_Icon < Touch_Icon
- #----------------------------------------------------------------------------
- # • Inicialização dos objetos.
- #----------------------------------------------------------------------------
- def initialize(action, *args)
- super(*args)
- self.opacity = 128
- @action = action
- end
- #----------------------------------------------------------------------------
- # • Renovação dos objetos.
- #----------------------------------------------------------------------------
- def dispose
- super
- end
- #----------------------------------------------------------------------------
- # • Atualização dos objetos.
- #----------------------------------------------------------------------------
- def update
- super
- end
- #----------------------------------------------------------------------------
- # • Ação após o clique.
- #----------------------------------------------------------------------------
- def action
- super
- eval(@action.to_s) unless @action.nil?
- end
- #----------------------------------------------------------------------------
- # • Efeito do objeto quando estiver na área.
- #----------------------------------------------------------------------------
- def effect_on_area?
- super
- end
- #----------------------------------------------------------------------------
- # • Efeito do objeto quando estiver fora da área.
- #----------------------------------------------------------------------------
- def effect_off_area?
- super
- end
- #----------------------------------------------------------------------------
- # • Retorna ao conteúdo.
- #----------------------------------------------------------------------------
- def contents
- self
- end
- end
- #==============================================================================
- # • Mouse Extension | Touch Text
- #==============================================================================
- Extension.register(:Touch_Text, "Dax", 1.0)
- class Touch_Text < Sprite
- #----------------------------------------------------------------------------
- # • Inicialização dos objetos.
- # id : ID do ícone no database.
- # x : Posição X do objeto.
- # y : Posição Y do objeto.
- # z : Altura do objeto.
- #----------------------------------------------------------------------------
- def initialize(text="", x=0, y=0, z=0, switche_id=nil,color=[ColorBasic.new(:white), ColorBasic[7]],font=["Arial", 16],align=0)
- super()
- self.x, self.y, self.z = x, y, z
- self.bitmap = Bitmap.new(font[1] + (text.split(//).size ** 2), font[1])
- self.bitmap.draw_text(0, 0, self.width, self.height, text, align)
- @clicked = false
- @switche_id = switche_id
- @color = color
- self.bitmap.font.name, self.bitmap.font.size = font
- end
- #----------------------------------------------------------------------------
- # • Renovação dos objetos.
- #----------------------------------------------------------------------------
- def dispose
- self.bitmap.dispose if !self.bitmap.nil?
- super
- end
- #----------------------------------------------------------------------------
- # • Atualizaçaõ dos objetos.
- # action_clicked : Caso seja um nome em formato de String irá chamar uma
- # scene, caso seja em formato de número irá chamar um evento comum.
- #----------------------------------------------------------------------------
- def update
- self.visible = !$game_switches[@switche_id] unless @switche_id.nil?
- if Mouse.in_area?(self)
- effect_on_area?
- @clicked = trigger?(0x01) or repeat?(0x01)
- action if @clicked && trigger?(0x01) or repeat?(0x01)
- else
- effect_off_area?
- @clicked = false if trigger?(0x01) or repeat?(0x01)
- end
- end
- #----------------------------------------------------------------------------
- # • Acão após o clique na imagem.
- #----------------------------------------------------------------------------
- def action
- end
- #----------------------------------------------------------------------------
- # • Efeito quando estiver na área.
- #----------------------------------------------------------------------------
- def effect_on_area?
- self.color = @color[1]
- end
- #----------------------------------------------------------------------------
- # • Efeito quando estiver fora da área.
- #----------------------------------------------------------------------------
- def effect_off_area?
- self.color = @color[0]
- end
- end
- #==============================================================================
- # • Mouse Extension | Simple Touch Icon
- #==============================================================================
- Extension.register(:Simple_Touch_Icon, "Dax", 1.0)
- class Simple_Touch_Text < Touch_Text
- #----------------------------------------------------------------------------
- # • Inicialização dos objetos.
- #----------------------------------------------------------------------------
- def initialize(action, *args)
- super(*args)
- @action = action
- end
- #----------------------------------------------------------------------------
- # • Renovação dos objetos.
- #----------------------------------------------------------------------------
- def dispose
- super
- end
- #----------------------------------------------------------------------------
- # • Atualização dos objetos.
- #----------------------------------------------------------------------------
- def update
- super
- end
- #----------------------------------------------------------------------------
- # • Ação após o clique.
- #----------------------------------------------------------------------------
- def action
- eval(@action.to_s) unless @action.nil?
- end
- #----------------------------------------------------------------------------
- # • Efeito do objeto quando estiver na área.
- #----------------------------------------------------------------------------
- def effect_on_area?
- super
- end
- #----------------------------------------------------------------------------
- # • Efeito do objeto quando estiver fora da área.
- #----------------------------------------------------------------------------
- def effect_off_area?
- super
- end
- #----------------------------------------------------------------------------
- # • Retorna ao conteúdo.
- #----------------------------------------------------------------------------
- def contents
- self
- end
- end
- #==============================================================================
- # • OutlineFillRect
- #==============================================================================
- Dax.register(:outline_fill_rect)
- class OutlineFillRect < Sprite
- #----------------------------------------------------------------------------
- # • Variáveis públicas com valor.
- #----------------------------------------------------------------------------
- attr_value_accessor :on, "self.visible = true"
- attr_value_accessor :off, "self.visible = false"
- #----------------------------------------------------------------------------
- # • Inicialização dos objetos.
- #----------------------------------------------------------------------------
- def initialize(object, max=2, color=ColorBasic[-1])
- super([object.width, object.height])
- @object = object
- self.x, self.y, self.z = object.x, object.y, object.z
- self.bitmap.fill_rect(0, 0, max, self.height, color)
- self.bitmap.fill_rect(self.width-max, 0, max, self.height, color)
- self.bitmap.fill_rect(0, 0, self.width, max, color)
- self.bitmap.fill_rect(0, self.height-max, self.width, max, color)
- end
- #----------------------------------------------------------------------------
- # • Renovação dos objetos.
- #----------------------------------------------------------------------------
- def dispose
- self.bitmap.dispose unless self.bitmap.disposed?
- super
- end
- #----------------------------------------------------------------------------
- # • Atualização das coordenadas.
- #----------------------------------------------------------------------------
- def update
- self.x, self.y, self.z = @object.x, @object.y, @object.z
- end
- end
- #==============================================================================
- # • Send Error
- #==============================================================================
- if $DEBUG or $TEST
- #-----------------------------------------------------------------------------
- # Imprimir erro.
- #-----------------------------------------------------------------------------
- def send_error(error)
- puts "Error : " + error
- puts "TRACE : " + error.backtrace.join("\n")
- puts " "
- puts " Going to EXIT - Press Enter to Continue - "
- gets if $DEBUG or $TEST
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement