Class: GamesParadise::Duck
- Inherits:
-
Object
- Object
- GamesParadise::Duck
- Defined in:
- lib/games_paradise/gui/gosu/duck_hunt_calculator/duck.rb
Constant Summary collapse
- DUCK =
DUCK
Gosu::Image.load_tiles(::GamesParadise.base_directory?+'images/duck_hunt_calculator/duck.png', 48, 48)
- DUCK_SIGN =
DUCK_SIGN
Gosu::Image.new(::GamesParadise.base_directory?+'images/duck_hunt_calculator/duck_sign.png')
- USE_THIS_FONT =
USE_THIS_FONT
Gosu::Font.new(10)
- FALL_SOUND =
FALL_SOUND
Gosu::Sample.new(::GamesParadise.base_directory?+'gui/gosu/duck_hunt_calculator/fall.mp3')
- DUCK_SOUND =
DUCK_SOUND
Gosu::Sample.new(::GamesParadise.base_directory?+'gui/gosu/duck_hunt_calculator/duck.ogg')
Instance Attribute Summary collapse
-
#to_remove ⇒ Object
readonly
Returns the value of attribute to_remove.
Instance Method Summary collapse
-
#draw ⇒ Object
# === draw ========================================================================= #.
-
#initialize(number) ⇒ Duck
constructor
# === initialize ========================================================================= #.
-
#play_the_duck_sound ⇒ Object
# === play_the_duck_sound ========================================================================= #.
-
#reset ⇒ Object
# === reset ========================================================================= #.
-
#shoot(x, y) ⇒ Object
# === shoot ========================================================================= #.
-
#update ⇒ Object
# === update ========================================================================= #.
Constructor Details
#initialize(number) ⇒ Duck
#
initialize
#
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/games_paradise/gui/gosu/duck_hunt_calculator/duck.rb', line 31 def initialize(number) @position_x = (Gosu.random(0, 2) > 1) ? 0 : 240 # left or right @position_y = Gosu.random(0, 140) @vx = 1 if @position_x == 0 @vx = -1 if @position_x == 240 if @position_y > 90 @vy = -1 elsif @position_y < 90 @vy = 1 else @vy = Gosu.random(-1, 2) end @number = number play_the_duck_sound reset end |
Instance Attribute Details
#to_remove ⇒ Object (readonly)
Returns the value of attribute to_remove.
15 16 17 |
# File 'lib/games_paradise/gui/gosu/duck_hunt_calculator/duck.rb', line 15 def to_remove @to_remove end |
Instance Method Details
#draw ⇒ Object
#
draw
#
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/games_paradise/gui/gosu/duck_hunt_calculator/duck.rb', line 128 def draw frame = @frame.floor frame += 3 if @vx == 1 frame += 6 if @vx == -1 frame += 9 if @dead DUCK[frame].draw(@position_x, @position_y, 30) unless @dead # the spritesheet is not symetrical so we have to adjust position regarding x velocity if @vx > 0 DUCK_SIGN.draw(@position_x + 10, @position_y + 35, 29) USE_THIS_FONT.draw_text(@number, @position_x + 13, @position_y + 38, 29) else DUCK_SIGN.draw(@position_x + 24, @position_y + 35, 29) USE_THIS_FONT.draw_text(@number, @position_x + 26, @position_y + 38, 29) end end end |
#play_the_duck_sound ⇒ Object
#
play_the_duck_sound
#
63 64 65 |
# File 'lib/games_paradise/gui/gosu/duck_hunt_calculator/duck.rb', line 63 def play_the_duck_sound DUCK_SOUND.play end |
#reset ⇒ Object
#
reset
#
53 54 55 56 57 58 |
# File 'lib/games_paradise/gui/gosu/duck_hunt_calculator/duck.rb', line 53 def reset @boring_time = 0 @frame = 0 @dead = false @spawned = false end |
#shoot(x, y) ⇒ Object
#
shoot
#
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/games_paradise/gui/gosu/duck_hunt_calculator/duck.rb', line 109 def shoot(x, y) unless @dead if x >= @position_x + 14 and x <= @position_x + 48 - 14 if y >= @position_y + 14 and y <= @position_y + 48 - 14 @dead = true @vx = 0 @vy = 4 @frame = 0 FALL_SOUND.play return @number end end end return nil end |
#update ⇒ Object
#
update
#
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/games_paradise/gui/gosu/duck_hunt_calculator/duck.rb', line 70 def update speed = 1.5 @frame += 0.1 if @frame > 2 @frame = 0 @frame = 1 if @dead end @position_x += @vx * speed @position_y += @vy * (speed * 0.2) # we check boundaries when the duck has entered the scene @spawned = true if @position_x >= 0 and @position_x <= 240 - 48 and @position_y >= 0 and @position_y <= 140 if @spawned and !@dead @vx = -@vx if @position_x <= 0 or @position_x > 240 - 48 @vy = -@vy if @position_y <= 0 or @position_y > 140 end # we want to remove a duck that is dead and bottom of screen if @dead and @position_y > 180 @to_remove = true end # we'll set to remove a duck that got bored of flying unless @dead @boring_time += 1 if @boring_time > 400 @vy = -1 if @position_y < -48 @to_remove = true end end end end |