Module: CyberarmEngine::Common
- Included in:
- BackgroundNineSlice, Element, Element::Container, GameObject, GameState, GuiState, Window
- Defined in:
- lib/cyberarm_engine/common.rb
Instance Method Summary collapse
- #current_state ⇒ Object
- #darken(color, amount = 25) ⇒ Object
- #draw_rect(x, y, width, height, color, z = 0) ⇒ Object
- #fill(color, z = 0) ⇒ Object
- #get_asset(path, hash, klass, retro = false, tileable = false) ⇒ Object
- #get_image(path, retro: false, tileable: false) ⇒ Object
- #get_sample(path) ⇒ Object
- #get_song(path) ⇒ Object
- #lighten(color, amount = 25) ⇒ Object
- #opacity(color, ratio = 1.0) ⇒ Object
- #pop_state ⇒ Object
- #previous_state ⇒ Object
- #push_state(klass, options = {}) ⇒ Object
- #shift_state ⇒ Object
- #show_cursor ⇒ Object
- #show_cursor=(boolean) ⇒ Object
- #window ⇒ Object
Instance Method Details
#current_state ⇒ Object
7 8 9 |
# File 'lib/cyberarm_engine/common.rb', line 7 def current_state window.current_state end |
#darken(color, amount = 25) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/cyberarm_engine/common.rb', line 47 def darken(color, amount = 25) if defined?(color.alpha) Gosu::Color.rgba(color.red - amount, color.green - amount, color.blue - amount, color.alpha) else Gosu::Color.rgb(color.red - amount, color.green - amount, color.blue - amount) end end |
#draw_rect(x, y, width, height, color, z = 0) ⇒ Object
31 32 33 |
# File 'lib/cyberarm_engine/common.rb', line 31 def draw_rect(x, y, width, height, color, z = 0) Gosu.draw_rect(x, y, width, height, color, z) end |
#fill(color, z = 0) ⇒ Object
35 36 37 |
# File 'lib/cyberarm_engine/common.rb', line 35 def fill(color, z = 0) draw_rect(0, 0, window.width, window.height, color, z) end |
#get_asset(path, hash, klass, retro = false, tileable = false) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/cyberarm_engine/common.rb', line 61 def get_asset(path, hash, klass, retro = false, tileable = false) asset = nil hash.detect do |_asset, instance| if _asset == path asset = instance true end end unless asset instance = nil instance = if klass == Gosu::Image klass.new(path, retro: retro, tileable: tileable) else klass.new(path) end hash[path] = instance asset = instance end asset end |
#get_image(path, retro: false, tileable: false) ⇒ Object
85 86 87 |
# File 'lib/cyberarm_engine/common.rb', line 85 def get_image(path, retro: false, tileable: false) get_asset(path, Window::IMAGES, Gosu::Image, retro, tileable) end |
#get_sample(path) ⇒ Object
89 90 91 |
# File 'lib/cyberarm_engine/common.rb', line 89 def get_sample(path) get_asset(path, Window::SAMPLES, Gosu::Sample) end |
#get_song(path) ⇒ Object
93 94 95 |
# File 'lib/cyberarm_engine/common.rb', line 93 def get_song(path) get_asset(path, Window::SONGS, Gosu::Song) end |
#lighten(color, amount = 25) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/cyberarm_engine/common.rb', line 39 def lighten(color, amount = 25) if defined?(color.alpha) Gosu::Color.rgba(color.red + amount, color.green + amount, color.blue + amount, color.alpha) else Gosu::Color.rgb(color.red + amount, color.green + amount, color.blue + amount) end end |
#opacity(color, ratio = 1.0) ⇒ Object
55 56 57 58 59 |
# File 'lib/cyberarm_engine/common.rb', line 55 def opacity(color, ratio = 1.0) alpha = 255 * ratio Gosu::Color.rgba(color.red, color.green, color.blue, alpha) end |
#pop_state ⇒ Object
15 16 17 |
# File 'lib/cyberarm_engine/common.rb', line 15 def pop_state window.pop_state end |
#previous_state ⇒ Object
11 12 13 |
# File 'lib/cyberarm_engine/common.rb', line 11 def previous_state window.previous_state end |
#push_state(klass, options = {}) ⇒ Object
3 4 5 |
# File 'lib/cyberarm_engine/common.rb', line 3 def push_state(klass, = {}) window.push_state(klass, ) end |
#shift_state ⇒ Object
19 20 21 |
# File 'lib/cyberarm_engine/common.rb', line 19 def shift_state window.shift_state end |
#show_cursor ⇒ Object
23 24 25 |
# File 'lib/cyberarm_engine/common.rb', line 23 def show_cursor window.show_cursor end |
#show_cursor=(boolean) ⇒ Object
27 28 29 |
# File 'lib/cyberarm_engine/common.rb', line 27 def show_cursor=(boolean) window.show_cursor = boolean end |
#window ⇒ Object
97 98 99 |
# File 'lib/cyberarm_engine/common.rb', line 97 def window $window end |