Module: CyberarmEngine::Common
- Included in:
- BackgroundImage, BackgroundNineSlice, Console, Element, Element::Container, GameObject, GameState, GuiState, Window
- Defined in:
- lib/cyberarm_engine/common.rb
Defined Under Namespace
Classes: ImageBlob
Instance Method Summary collapse
- #alt_down? ⇒ Boolean
- #control_down? ⇒ Boolean
- #current_state ⇒ Object
- #darken(color, amount = 25) ⇒ Object
- #draw_rect(x, y, width, height, color, z = 0, mode = :default) ⇒ Object
- #fill(color, z = 0) ⇒ Object
- #find_element_by_tag(container, tag, list = []) ⇒ 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(state = nil) ⇒ Object
- #push_state(klass, options = {}) ⇒ Object
- #shift_down? ⇒ Boolean
- #shift_state ⇒ Object
- #show_cursor ⇒ Object
- #show_cursor=(boolean) ⇒ Object
- #window ⇒ Object
Instance Method Details
#alt_down? ⇒ Boolean
127 128 129 |
# File 'lib/cyberarm_engine/common.rb', line 127 def alt_down? Gosu.(Gosu::KB_LEFT_ALT) || Gosu.(Gosu::KB_RIGHT_ALT) end |
#control_down? ⇒ Boolean
119 120 121 |
# File 'lib/cyberarm_engine/common.rb', line 119 def control_down? Gosu.(Gosu::KB_LEFT_CONTROL) || Gosu.(Gosu::KB_RIGHT_CONTROL) end |
#current_state ⇒ Object
9 10 11 |
# File 'lib/cyberarm_engine/common.rb', line 9 def current_state window.current_state end |
#darken(color, amount = 25) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/cyberarm_engine/common.rb', line 64 def darken(color, amount = 25) if color.respond_to?(: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, mode = :default) ⇒ Object
48 49 50 |
# File 'lib/cyberarm_engine/common.rb', line 48 def draw_rect(x, y, width, height, color, z = 0, mode = :default) Gosu.draw_rect(x, y, width, height, color, z, mode) end |
#fill(color, z = 0) ⇒ Object
52 53 54 |
# File 'lib/cyberarm_engine/common.rb', line 52 def fill(color, z = 0) draw_rect(0, 0, window.width, window.height, color, z) end |
#find_element_by_tag(container, tag, list = []) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cyberarm_engine/common.rb', line 36 def find_element_by_tag(container, tag, list = []) return unless container container.children.each do |child| list << child if child.style.tag == tag find_element_by_tag(child, tag, list) if child.is_a?(CyberarmEngine::Element::Container) end list.first end |
#get_asset(path, hash, klass, retro = false, tileable = false) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/cyberarm_engine/common.rb', line 78 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 path_or_blob = path.is_a?(String) ? path : ImageBlob.new(path.to_blob, path.width, path.height) klass.new(path_or_blob, 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
103 104 105 |
# File 'lib/cyberarm_engine/common.rb', line 103 def get_image(path, retro: false, tileable: false) get_asset(path, Window::IMAGES, Gosu::Image, retro, tileable) end |
#get_sample(path) ⇒ Object
107 108 109 |
# File 'lib/cyberarm_engine/common.rb', line 107 def get_sample(path) get_asset(path, Window::SAMPLES, Gosu::Sample) end |
#get_song(path) ⇒ Object
111 112 113 |
# File 'lib/cyberarm_engine/common.rb', line 111 def get_song(path) get_asset(path, Window::SONGS, Gosu::Song) end |
#lighten(color, amount = 25) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/cyberarm_engine/common.rb', line 56 def lighten(color, amount = 25) if color.respond_to?(: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
72 73 74 75 76 |
# File 'lib/cyberarm_engine/common.rb', line 72 def opacity(color, ratio = 1.0) alpha = 255 * ratio Gosu::Color.rgba(color.red, color.green, color.blue, alpha) end |
#pop_state ⇒ Object
20 21 22 |
# File 'lib/cyberarm_engine/common.rb', line 20 def pop_state window.pop_state end |
#previous_state(state = nil) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/cyberarm_engine/common.rb', line 13 def previous_state(state = nil) raise "Only available for CyberarmEngine::GameState and subclasses" unless is_a?(CyberarmEngine::GameState) || state.is_a?(CyberarmEngine::GameState) i = window.states.index(state || self) window.states[i - 1] unless (i - 1).negative? end |
#push_state(klass, options = {}) ⇒ Object
5 6 7 |
# File 'lib/cyberarm_engine/common.rb', line 5 def push_state(klass, = {}) window.push_state(klass, ) end |
#shift_down? ⇒ Boolean
123 124 125 |
# File 'lib/cyberarm_engine/common.rb', line 123 def shift_down? Gosu.(Gosu::KB_LEFT_SHIFT) || Gosu.(Gosu::KB_RIGHT_SHIFT) end |
#shift_state ⇒ Object
24 25 26 |
# File 'lib/cyberarm_engine/common.rb', line 24 def shift_state window.shift_state end |
#show_cursor ⇒ Object
28 29 30 |
# File 'lib/cyberarm_engine/common.rb', line 28 def show_cursor window.show_cursor end |
#show_cursor=(boolean) ⇒ Object
32 33 34 |
# File 'lib/cyberarm_engine/common.rb', line 32 def show_cursor=(boolean) window.show_cursor = boolean end |
#window ⇒ Object
115 116 117 |
# File 'lib/cyberarm_engine/common.rb', line 115 def window CyberarmEngine::Window.instance end |