Class: GamesParadise::GameWindow
- Inherits:
-
Gosu::Window
- Object
- Gosu::Window
- GamesParadise::GameWindow
- Defined in:
- lib/games_paradise/flappy_bird/gosu/flappy.rb,
lib/games_paradise/gui/gosu/battle_city/window.rb
Constant Summary collapse
- TITLE =
#
TITLE
#
'Battle City'
Instance Attribute Summary collapse
-
#delta ⇒ Object
Returns the value of attribute delta.
-
#entities ⇒ Object
Returns the value of attribute entities.
-
#game_running ⇒ Object
Returns the value of attribute game_running.
-
#walls ⇒ Object
Returns the value of attribute walls.
Instance Method Summary collapse
-
#button_down(id) ⇒ Object
# === button_down ========================================================================= #.
-
#draw ⇒ Object
# === draw ========================================================================= #.
-
#ground_height ⇒ integer
# === ground_height.
-
#ground_y ⇒ Object
# === ground_y.
-
#initialize ⇒ GameWindow
constructor
# === initialize ========================================================================= #.
-
#reset ⇒ Object
# === reset ========================================================================= #.
-
#sky_height ⇒ integer
# === sky_height.
-
#update ⇒ Object
# === update ========================================================================= #.
-
#update_delta ⇒ Object
update_delta.
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, #set_font, #set_title, #sqrt, #tab_key?, #write_this_text
Constructor Details
#initialize ⇒ GameWindow
#
initialize
#
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/games_paradise/flappy_bird/gosu/flappy.rb', line 26 def initialize super(288, 512, false) # caption = 'GosuFlappy Game' @start = false @delta = 0 @last_time = 0 @background_image = Gosu::Image.new( GamesParadise.image_directory?+'flappy_bird/background.png' ) @ground = Ground.new(self) @player = Player.new(self) @wallfactory = WallFactory.new(self) @score = 0 @font = Gosu::Font.new(self, 'Courier', 40) @entities = [ @ground, @player ] end |
Instance Attribute Details
#delta ⇒ Object
Returns the value of attribute delta.
19 20 21 |
# File 'lib/games_paradise/flappy_bird/gosu/flappy.rb', line 19 def delta @delta end |
#entities ⇒ Object
Returns the value of attribute entities.
17 18 19 |
# File 'lib/games_paradise/flappy_bird/gosu/flappy.rb', line 17 def entities @entities end |
#game_running ⇒ Object
Returns the value of attribute game_running.
9 10 11 |
# File 'lib/games_paradise/gui/gosu/battle_city/window.rb', line 9 def game_running @game_running end |
#walls ⇒ Object
Returns the value of attribute walls.
18 19 20 |
# File 'lib/games_paradise/flappy_bird/gosu/flappy.rb', line 18 def walls @walls end |
Instance Method Details
#button_down(id) ⇒ Object
#
button_down
#
44 45 46 47 48 49 |
# File 'lib/games_paradise/gui/gosu/battle_city/window.rb', line 44 def (id) case id when Gosu::KB_ESCAPE close end end |
#draw ⇒ Object
#
draw
#
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/games_paradise/flappy_bird/gosu/flappy.rb', line 104 def draw @background_image.draw(0, 0, 0) # ======================================================================= # # draw the score # ======================================================================= # @font.draw_text("#{@score.to_i}", 10, 10, 20) @entities.each { |entry| entry.draw } end |
#ground_height ⇒ integer
#
ground_height
Return the height of ground
#
131 132 133 |
# File 'lib/games_paradise/flappy_bird/gosu/flappy.rb', line 131 def ground_height @ground.height end |
#ground_y ⇒ Object
#
ground_y
Return ground y position
#
142 143 144 |
# File 'lib/games_paradise/flappy_bird/gosu/flappy.rb', line 142 def ground_y @ground.y end |
#reset ⇒ Object
#
reset
#
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/games_paradise/flappy_bird/gosu/flappy.rb', line 51 def reset @delta = 0 @last_time = 0 @player = Player.new(self) @wallfactory = WallFactory.new(self) @score = 0 @walls = [] @entities = [ @ground, @player, @wallfactory ] end |
#sky_height ⇒ integer
#
sky_height
Compute height of sky
#
121 122 123 |
# File 'lib/games_paradise/flappy_bird/gosu/flappy.rb', line 121 def sky_height @background_image.height - self.ground_height end |
#update ⇒ Object
#
update
#
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/games_paradise/flappy_bird/gosu/flappy.rb', line 75 def update if @start update_delta if @player.dead @player.update @start = false if @player.killed? else @entities.each do |e| e.update end end @walls.each do |wall| @player.dead = true if @player.collision? wall @score += 0.5 if wall.score? @player end @walls.reject! {|wall| !wall.active } else if (Gosu::KbSpace) @start = true reset end end end |
#update_delta ⇒ Object
update_delta
Update delta param
68 69 70 71 72 |
# File 'lib/games_paradise/flappy_bird/gosu/flappy.rb', line 68 def update_delta current_time = ::Gosu.milliseconds / 1000.0 @delta = [current_time - @last_time, 0.25].min @last_time = current_time end |