Class: GameWindow

Inherits:
Gosu::Window show all
Includes:
Singleton
Defined in:
lib/games_paradise/gui/gosu/chinguroids/chinguroids.rb,
lib/games_paradise/gui/gosu/garden_hero/core/game_window.rb

Overview

#

GameWindow - main window class

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Gosu::Window

#gosu_button_down?, #image, #image10?, #image1?, #image2?, #image3?, #image4?, #image5?, #image6?, #image7?, #image8?, #image9?, #on_left_arrow_pressed?, #on_right_arrow_pressed?, #q_means_quit, #reset, #set_font, #set_title, #sqrt, #tab_key?, #write_this_text

Constructor Details

#initializeGameWindow

initialize



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/games_paradise/gui/gosu/chinguroids/chinguroids.rb', line 30

def initialize
  super(800,600,false)
  $intro = true     # start out by defining some constants used later in the game
  $max_x = 815
  $max_y = 615
  $scr_edge = 15
  $cooling_down = 70
  $star_grab = Sound["media/audio/star_pickup.ogg"]
  $power_up  = Sound["media/audio/power_up.ogg"]
  self.caption = 'ChinguRoids'
  @cursor = true # false hides cursor
  self.input = { :esc => :exit,  # global controls
               [:q, :l] => :pop,
               :z => :log,
               :r => lambda{current_game_state.setup}
             }
  retrofy   # use retrofy for improved scaling of images
end

Instance Attribute Details

#levelObject (readonly)

Returns the value of attribute level.



23
24
25
# File 'lib/games_paradise/gui/gosu/garden_hero/core/game_window.rb', line 23

def level
  @level
end

#pauseObject

Returns the value of attribute pause.



24
25
26
# File 'lib/games_paradise/gui/gosu/garden_hero/core/game_window.rb', line 24

def pause
  @pause
end

#total_scoreObject

Returns the value of attribute total_score.



24
25
26
# File 'lib/games_paradise/gui/gosu/garden_hero/core/game_window.rb', line 24

def total_score
  @total_score
end

#win_gameObject

Returns the value of attribute win_game.



24
25
26
# File 'lib/games_paradise/gui/gosu/garden_hero/core/game_window.rb', line 24

def win_game
  @win_game
end

Instance Method Details

#button_down(key) ⇒ Object

button down event



40
41
42
43
44
45
46
47
# File 'lib/games_paradise/gui/gosu/garden_hero/core/game_window.rb', line 40

def button_down(key)
  case key
  when Gosu::KbEscape
    close
  when Gosu::KbP
    @pause = !@pause if @menu.display === false
  end
end

#drawObject

draw



27
28
29
30
# File 'lib/games_paradise/gui/gosu/garden_hero/core/game_window.rb', line 27

def draw
  @menu.draw
  @level.draw if @menu.display === false
end

#logObject

log

pressing ā€˜z’ at any time returns name of current gamestate.



57
58
59
# File 'lib/games_paradise/gui/gosu/chinguroids/chinguroids.rb', line 57

def log
  puts $window.current_game_state
end

#popObject

pop



62
63
64
65
66
67
68
# File 'lib/games_paradise/gui/gosu/chinguroids/chinguroids.rb', line 62

def pop  # pressing 'q' or 'l' at any time backs out of current gamestate
  if $window.current_game_state.to_s == "Introduction" or $window.current_game_state.to_s == "Level_1" then
    pop_game_state(setup: true)
  elsif $window.current_game_state.to_s != "OpeningCredits"
    pop_game_state(setup: false)
  end
end

#setupObject

setup



50
51
52
# File 'lib/games_paradise/gui/gosu/chinguroids/chinguroids.rb', line 50

def setup
  push_game_state(Beginning) # start by pushing Beginning gamestate
end

#updateObject

update



33
34
35
36
37
# File 'lib/games_paradise/gui/gosu/garden_hero/core/game_window.rb', line 33

def update
  @menu.display = true if win_game
  @menu.update if pause || win_game
  @level.update if not pause && win_game == false
end