Module: CyberarmEngine::Common
- Included in:
- BackgroundNineSlice, Element, Element::Container, GameObject, GameState, GuiState
- 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
- #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
43 44 45 46 47 48 49 |
# File 'lib/cyberarm_engine/common.rb', line 43 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
27 28 29 |
# File 'lib/cyberarm_engine/common.rb', line 27 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
31 32 33 |
# File 'lib/cyberarm_engine/common.rb', line 31 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
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/cyberarm_engine/common.rb', line 57 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
80 81 82 |
# File 'lib/cyberarm_engine/common.rb', line 80 def get_image(path, retro: false, tileable: false) get_asset(path, Window::IMAGES, Gosu::Image, retro, tileable) end |
#get_sample(path) ⇒ Object
84 85 86 |
# File 'lib/cyberarm_engine/common.rb', line 84 def get_sample(path) get_asset(path, Window::SAMPLES, Gosu::Sample) end |
#get_song(path) ⇒ Object
88 89 90 |
# File 'lib/cyberarm_engine/common.rb', line 88 def get_song(path) get_asset(path, Window::SONGS, Gosu::Song) end |
#lighten(color, amount = 25) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/cyberarm_engine/common.rb', line 35 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
51 52 53 54 55 |
# File 'lib/cyberarm_engine/common.rb', line 51 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 |
#show_cursor ⇒ Object
19 20 21 |
# File 'lib/cyberarm_engine/common.rb', line 19 def show_cursor window.show_cursor end |
#show_cursor=(boolean) ⇒ Object
23 24 25 |
# File 'lib/cyberarm_engine/common.rb', line 23 def show_cursor=(boolean) window.show_cursor = boolean end |
#window ⇒ Object
92 93 94 |
# File 'lib/cyberarm_engine/common.rb', line 92 def window $window end |