Class: GamesParadise::DuckHuntCalculatorGame
- Inherits:
-
Gosu::Window
- Object
- Gosu::Window
- GamesParadise::DuckHuntCalculatorGame
- Defined in:
- lib/games_paradise/gui/gosu/duck_hunt_calculator/duck_hunt_calculator.rb
Constant Summary collapse
- TITLE =
#
TITLE
#
'Duck Hunt Calculator !'
Instance Method Summary collapse
-
#button_down(id) ⇒ Object
# === button_down ========================================================================= #.
-
#draw ⇒ Object
# === draw # ========================================================================= #.
-
#generate_duck ⇒ Object
# === generate_duck ========================================================================= #.
-
#initialize ⇒ DuckHuntCalculatorGame
constructor
# === initialize ========================================================================= #.
-
#needs_cursor? ⇒ Boolean
# === needs_cursor? ========================================================================= #.
-
#reset ⇒ Object
# === reset ========================================================================= #.
-
#shoot ⇒ Object
# === shoot ========================================================================= #.
-
#start_new_game ⇒ Object
# === start_new_game ========================================================================= #.
-
#update ⇒ Object
# === update ========================================================================= #.
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 ⇒ DuckHuntCalculatorGame
#
initialize
#
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/games_paradise/gui/gosu/duck_hunt_calculator/duck_hunt_calculator.rb', line 25 def initialize super(480, 480, false) set_title(TITLE) @bg = Gosu::Image.new(::GamesParadise.base_directory?+'images/duck_hunt_calculator/bg.png') @fg = Gosu::Image.new(::GamesParadise.base_directory?+'images/duck_hunt_calculator/fg.png') @dog_sign = Gosu::Image.new(::GamesParadise.base_directory?+'images/duck_hunt_calculator/dog_sign.png') @font = Gosu::Font.new(18) @duck_sound = Gosu::Sample.new(::GamesParadise.base_directory?+'gui/gosu/duck_hunt_calculator/fly.mp3') @shoot_sound = Gosu::Sample.new(::GamesParadise.base_directory?+'gui/gosu/duck_hunt_calculator/shoot.mp3') @correct_sound = Gosu::Sample.new(::GamesParadise.base_directory?+'gui/gosu/duck_hunt_calculator/correct.mp3') @false_sound = Gosu::Sample.new(::GamesParadise.base_directory?+'gui/gosu/duck_hunt_calculator/false.mp3') @duck_spawn_tick = Gosu.milliseconds @duck_sound_tick = Gosu.milliseconds reset start_new_game end |
Instance Method Details
#button_down(id) ⇒ Object
#
button_down
#
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/games_paradise/gui/gosu/duck_hunt_calculator/duck_hunt_calculator.rb', line 81 def (id) super exit if id == Gosu::KbEscape shoot if id == Gosu::MsLeft case id when Gosu::KbSpace @mode = (@mode == :standard) ? :cumulative : :standard start_new_game end end |
#draw ⇒ Object
#
draw # ========================================================================= #
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/games_paradise/gui/gosu/duck_hunt_calculator/duck_hunt_calculator.rb', line 101 def draw scale @scale do @bg.draw(0, 0, 0) @dog_sign.draw(0, @dog_sign_y, 40) @font.draw_text(@value_to_find, 131, 142 + @dog_sign_y, 41) @fg.draw(0, 0, 50) @ducks.each {|duck| duck.draw} if @display_shoot != false Gosu.draw_rect(0, 0, self.width, self.height, Gosu::Color::WHITE, 100) @display_shoot += 1 @display_shoot = false if @display_shoot > 3 end case @mode when :standard @font.draw_text("Number 1 : #@number1", 10, 201, 100, 1, 1, Gosu::Color::BLACK) @font.draw_text("Number 1 : #@number1", 10, 199, 100, 1, 1, Gosu::Color::BLACK) @font.draw_text("Number 1 : #@number1", 11, 200, 100, 1, 1, Gosu::Color::BLACK) @font.draw_text("Number 1 : #@number1", 9, 200, 100, 1, 1, Gosu::Color::BLACK) @font.draw_text("Number 1 : #@number1", 10, 200, 100, 1, 1, Gosu::Color::WHITE) @font.draw_text("Number 2 : #@number2", 9, 217, 100, 1, 1, Gosu::Color::BLACK) @font.draw_text("Number 2 : #@number2", 11, 217, 100, 1, 1, Gosu::Color::BLACK) @font.draw_text("Number 2 : #@number2", 10, 218, 100, 1, 1, Gosu::Color::BLACK) @font.draw_text("Number 2 : #@number2", 10, 216, 100, 1, 1, Gosu::Color::BLACK) @font.draw_text("Number 2 : #@number2", 10, 217, 100, 1, 1, Gosu::Color::WHITE) # cumulative mode else @font.draw_text("Total : #@number1", 10, 201, 100, 1, 1, Gosu::Color::BLACK) @font.draw_text("Total : #@number1", 10, 199, 100, 1, 1, Gosu::Color::BLACK) @font.draw_text("Total : #@number1", 11, 200, 100, 1, 1, Gosu::Color::BLACK) @font.draw_text("Total : #@number1", 9, 200, 100, 1, 1, Gosu::Color::BLACK) @font.draw_text("Total : #@number1", 10, 200, 100, 1, 1, Gosu::Color::WHITE) end @font.draw_text("Chain : #@score", 149, 200, 100, 1, 1, Gosu::Color::BLACK) @font.draw_text("Chain : #@score", 151, 200, 100, 1, 1, Gosu::Color::BLACK) @font.draw_text("Chain : #@score", 150, 199, 100, 1, 1, Gosu::Color::BLACK) @font.draw_text("Chain : #@score", 150, 201, 100, 1, 1, Gosu::Color::BLACK) @font.draw_text("Chain : #@score", 150, 200, 100, 1, 1, Gosu::Color::WHITE) end end |
#generate_duck ⇒ Object
#
generate_duck
#
45 46 47 48 49 50 51 52 |
# File 'lib/games_paradise/gui/gosu/duck_hunt_calculator/duck_hunt_calculator.rb', line 45 def generate_duck number = Gosu.random(1, 11).to_i # we want to have more chances to get suitable numbers good_number = Gosu.random(0, 4).to_i number = [@value1, @value2].sample if good_number == 0 @ducks.push Duck.new(number) @duck_spawn_tick = Gosu::milliseconds end |
#needs_cursor? ⇒ Boolean
#
needs_cursor?
#
95 96 97 |
# File 'lib/games_paradise/gui/gosu/duck_hunt_calculator/duck_hunt_calculator.rb', line 95 def needs_cursor? true end |
#reset ⇒ Object
#
reset
#
57 58 59 60 61 |
# File 'lib/games_paradise/gui/gosu/duck_hunt_calculator/duck_hunt_calculator.rb', line 57 def reset @scale = 2 @score = 0 @mode = :standard end |
#shoot ⇒ Object
#
shoot
#
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/games_paradise/gui/gosu/duck_hunt_calculator/duck_hunt_calculator.rb', line 177 def shoot result = nil @ducks.each { |duck| result = duck.shoot(self.mouse_x / @scale, self.mouse_y / @scale) break unless result.nil? } @shoot_sound.play @display_shoot = 0 unless result.nil? case @mode when :standard if @number1 == 0 @number1 = result else @number2 = result end # cumulative mode else if @number1 == 0 @number1 = result else @number1 *= result end end case @mode when :standard if @number1 > 0 and @number2 > 0 if @number1 * @number2 == @value_to_find @correct_sound.play @game_to_restart = true @score += 1 else @false_sound.play @game_to_restart = true @score = 0 end end # cumulative mode else if @number1 == @value_to_find @correct_sound.play @game_to_restart = true @score += 1 elsif @number1 > @value_to_find @false_sound.play @game_to_restart = true @score = 0 end end end end |
#start_new_game ⇒ Object
#
start_new_game
#
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/games_paradise/gui/gosu/duck_hunt_calculator/duck_hunt_calculator.rb', line 66 def start_new_game @game_to_restart = false @number1, @number2 = 0, 0 @ducks = Array.new @dog_sign_y = 60 @started = false @display_shoot = false @value1 = Gosu.random(1, 11).to_i @value2 = Gosu.random(1, 11).to_i @value_to_find = @value1 * @value2 end |
#update ⇒ Object
#
update
#
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/games_paradise/gui/gosu/duck_hunt_calculator/duck_hunt_calculator.rb', line 148 def update if !@started @dog_sign_y -= 1.8 @started = true if @dog_sign_y <= 0.0 elsif @game_to_restart @counter_to_restart ||= 0 @counter_to_restart += 1 if @counter_to_restart > 10 @counter_to_restart = 0 start_new_game end else self. = "Mode : #@mode - press Space to switch Mode" generate_duck if Gosu.milliseconds - @duck_spawn_tick >= 1200 @ducks.each {|duck| duck.update} @ducks.delete_if {|duck| duck.to_remove} unless @ducks.empty? if Gosu.milliseconds - @duck_sound_tick >= 500 @duck_sound.play(0.5, 0.5) @duck_sound_tick = Gosu.milliseconds end end end end |