Class: Core::GameWindow

Inherits:
Gosu::Window
  • Object
show all
Includes:
States
Defined in:
lib/game_window.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGameWindow

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.caption = "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

#savedObject

Returns the value of attribute saved.



16
17
18
# File 'lib/game_window.rb', line 16

def saved
  @saved
end

#stateObject

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

#drawObject



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

#loadObject



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

Returns:

  • (Boolean)


76
77
78
79
80
81
82
83
84
85
86
# File 'lib/game_window.rb', line 76

def pressed?(key)
  p = button_down?(key)
  if p
    if @unpress.include?(key)
      p = false
    else
      @unpress.push(key)
    end
  end
  return p
end

#saveObject

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

#unpressObject



87
88
89
90
91
92
93
# File 'lib/game_window.rb', line 87

def unpress
  @unpress.each { |key|
    if !button_down?(key)
      @unpress.delete(key)
    end
  }
end

#updateObject



38
39
40
41
42
# File 'lib/game_window.rb', line 38

def update
  @state.update
  unpress
  self.caption = "Essytas - v#{Core::VERSION} - #{Gosu.fps} FPS"
end