Class: SceneKBookPages

Inherits:
Object
  • Object
show all
Includes:
Input
Defined in:
lib/games_paradise/gui/gosu/books/book.rb

Instance Method Summary collapse

Methods included from Input

[], #button_down, #button_down?, #button_up, #hold_down?, #press_L1?, #press_R1?, #press_down?, #press_enter?, #press_kb_right?, #press_left?, #press_quit?, #press_right?, #press_up?

Constructor Details

#initialize(id) ⇒ SceneKBookPages

initialize



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/games_paradise/gui/gosu/books/book.rb', line 98

def initialize(id)
  @id = id
  @bgm_index = @index = @ticks = 0
  @width = 8
  @book = []
  @pages = []
  @bgm = nil
  @bgms = []
  @default_font = 'High Tower Text'#'Liberation'#'DS-Digital'
  @default_color = Gosu::Color.new(255, 255, 255, 255) rescue nil
  @outline_color = Gosu::Color.new(255, 0, 0, 0) rescue nil
  @ok_se = Gosu::Sample.new('audio/Ok.ogg')
  @cancel_se = Gosu::Sample.new('audio/Cancel.ogg')
  @cursor_se = Gosu::Sample.new('audio/PageFlip.ogg')
  # The next sound was played when a wrong move was done.
  # @wrong_se = Gosu::Sample.new('audio/Wrong.ogg')
  book = Library.books[@id]
  pages = book.pages
  @max = pages.size
  @max.times {|n| @book << Sprite_Page.new(400, 50, n, pages[n]) }
end

Instance Method Details

#drawObject

#

draw

#


198
199
200
# File 'lib/games_paradise/gui/gosu/books/book.rb', line 198

def draw
  @book.each {|page| page.draw }
end

#play_bgm(name, volume = 80, non_stop = true) ⇒ Object

play_bgm



129
130
131
132
133
# File 'lib/games_paradise/gui/gosu/books/book.rb', line 129

def play_bgm(name, volume = 80, non_stop = true)
  @bgm = Gosu::Song.new('audio/' + name)
  @bgm.volume = volume / 100.0
  @bgm.play(non_stop)
end

#play_list(volume, *args) ⇒ Object

play_list



135
136
137
138
139
140
141
142
# File 'lib/games_paradise/gui/gosu/books/book.rb', line 135

def play_list(volume, *args)
  @bgm_index = 0
  @volume = volume / 100.0
  names = args.flatten
  names.each {|name| @bgms << Gosu::Song.new('audio/' + name)
              @bgms[-1].volume = @volume   }
  @bgms[@bgm_index].play(false)
end

#play_next_bgmObject

play_next_bgm



145
146
147
148
149
# File 'lib/games_paradise/gui/gosu/books/book.rb', line 145

def play_next_bgm
  return if @bgms.empty? or @bgms[@bgm_index].playing?
  @bgm_index = (@bgm_index + 1) % @bgms.size
  @bgms[@bgm_index].play(false)
end

#stop_bgmObject

stop_bgm



121
122
123
124
125
126
127
# File 'lib/games_paradise/gui/gosu/books/book.rb', line 121

def stop_bgm
  @bgm.stop if @bgm
  return if @bgms.empty?
  @bgms[@bgm_index].stop
  @bgms.clear
  @volume = @bgm_index = nil
end

#updateObject

update



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/games_paradise/gui/gosu/books/book.rb', line 152

def update
  play_next_bgm
  if @@down_ticks > 0
    @@down_ticks -= 1
    @@down_id = nil if @@down_ticks == 0
  end
  unless @pages.empty?
    @pages[0].update
    @pages.shift unless @pages[0].flip?
  end
  return @ticks -= 1 if @ticks > 0
  if Gosu.button_down?(Gosu::KbLeftAlt) and button_down?(:return)
    @fullscreen = Window.toggle_fullscreen
    @ticks = 6
    return
  end
  if press_quit?
    @cancel_se.play
    Window.close
  elsif press_left?
    if @index == 0
      return # @wrong_se.play
    else
      @cursor_se.play
      @index -= 1 unless  @index == @max - 1
      @pages = [@book[@index], @book[@index-1]]
      @index = [@index-1,0].max
      @pages.each {|page| page.flip(:left) }
      @ticks = 20
    end
  elsif press_right?
    if @index == @max - 1
      return # @wrong_se.play
    else
      @cursor_se.play
      @pages = @book[@index..@index+1]
      @pages.each {|page| page.flip(:right) }
      @index = [@index+2,@max-1].min
      @ticks = 20
    end
  end
end