Class: Core::GameWindow
- Includes:
- States
- Defined in:
- lib/game_window.rb
Instance Attribute Summary collapse
-
#saved ⇒ Object
Returns the value of attribute saved.
-
#state ⇒ Object
Returns the value of attribute state.
Instance Method Summary collapse
-
#advance(state) ⇒ Object
Advance to the next state.
- #draw ⇒ Object
-
#initialize ⇒ GameWindow
constructor
A new instance of GameWindow.
- #load ⇒ Object
-
#pressed?(key) ⇒ Boolean
Checks if a specific key is pressed.
-
#save ⇒ Object
Save current state so we can go back to it later.
- #unpress ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize ⇒ GameWindow
Returns a new instance of GameWindow.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/game_window.rb', line 20 def initialize super(1024, 768, false) self. = "Essytas - v#{Core::VERSION}" Core.window = self Core.particles = Core::Parse.particles Core.animations = Core::Parse.animations @state = StartMenu.new(self) @unpress = [] @font = Core.font(Core::DEFAULT_FONT, 20) @bg = Core.sprite("pixel", true) if (Core.config[:contrast] != 1.0 and Core.config[:opengl]) @contrast = Shader.new(self, "glsl/contrast") @contrast["contrast"] = Core.config[:contrast] else @contrast = nil end end |
Instance Attribute Details
#saved ⇒ Object
Returns the value of attribute saved.
16 17 18 |
# File 'lib/game_window.rb', line 16 def saved @saved end |
#state ⇒ Object
Returns the value of attribute state.
16 17 18 |
# File 'lib/game_window.rb', line 16 def state @state end |
Instance Method Details
#advance(state) ⇒ Object
Advance to the next state
Requires an EH::States::State instance
58 59 60 61 |
# File 'lib/game_window.rb', line 58 def advance(state) @state.finish @state = state end |
#draw ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/game_window.rb', line 44 def draw @state.draw if $DEBUG @bg.draw(16, 16, 999999, 160, 48, 0x99000000) @font.draw("Mouse: #{mouse_x.to_i}|#{mouse_y.to_i}", 32, 32, 999999) end if @contrast @contrast.apply end end |
#load ⇒ Object
70 71 72 |
# File 'lib/game_window.rb', line 70 def load @state = @saved end |
#pressed?(key) ⇒ Boolean
Checks if a specific key is pressed
Only returns true again if the key was held loose
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/game_window.rb', line 76 def pressed?(key) p = (key) if p if @unpress.include?(key) p = false else @unpress.push(key) end end return p end |
#save ⇒ Object
Save current state so we can go back to it later
The GameState is saved when switching to a MenuState
66 67 68 |
# File 'lib/game_window.rb', line 66 def save @saved = @state end |
#unpress ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/game_window.rb', line 87 def unpress @unpress.each { |key| if !(key) @unpress.delete(key) end } end |