Class: GamesParadise::GameWindow

Inherits:
Gosu::Window show all
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

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, #set_font, #set_title, #sqrt, #tab_key?, #write_this_text

Constructor Details

#initializeGameWindow

#

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

#deltaObject

Returns the value of attribute delta.



19
20
21
# File 'lib/games_paradise/flappy_bird/gosu/flappy.rb', line 19

def delta
  @delta
end

#entitiesObject

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_runningObject

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

#wallsObject

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 button_down(id)
  case id
  when Gosu::KB_ESCAPE
    close
  end
end

#drawObject

#

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_heightinteger

#

ground_height

Return the height of ground

#

Returns:

  • (integer)


131
132
133
# File 'lib/games_paradise/flappy_bird/gosu/flappy.rb', line 131

def ground_height
  @ground.height
end

#ground_yObject

#

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

#resetObject

#

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_heightinteger

#

sky_height

Compute height of sky

#

Returns:

  • (integer)

    the 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

#updateObject

#

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 button_down?(Gosu::KbSpace)
      @start = true
      reset
    end
  end
end

#update_deltaObject

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