Class: LunarLander::Player
- Inherits:
-
Chingu::GameObject
- Object
- Chingu::GameObject
- LunarLander::Player
- Defined in:
- lib/lunar_lander/game_objects/player.rb
Instance Attribute Summary collapse
-
#fuel ⇒ Object
Returns the value of attribute fuel.
Instance Method Summary collapse
- #die ⇒ Object
- #rotate_left ⇒ Object
- #rotate_right ⇒ Object
- #setup ⇒ Object
- #should_die? ⇒ Boolean
- #stop ⇒ Object
- #stop_engine ⇒ Object
- #thrust ⇒ Object
- #update ⇒ Object
Instance Attribute Details
#fuel ⇒ Object
Returns the value of attribute fuel.
6 7 8 |
# File 'lib/lunar_lander/game_objects/player.rb', line 6 def fuel @fuel end |
Instance Method Details
#die ⇒ Object
93 94 95 96 |
# File 'lib/lunar_lander/game_objects/player.rb', line 93 def die @engine_sound.stop Gosu::Sound["explosion.wav"].play end |
#rotate_left ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/lunar_lander/game_objects/player.rb', line 20 def rotate_left @angle -= 0.5 Chingu::Particle.create( :x => @x + Gosu::offset_x(@angle + 60, 20 * @factor), :y => @y + Gosu::offset_y(@angle + 60, 20 * @factor), :animation => @particle_animation, :scale_rate => -0.03, :fade_rate => -35, :rotation_rate => +1, :mode => :default, :factor => @factor / 2 ) Chingu::Particle.each { |particle| particle.x -= Gosu::offset_x(@angle-90, 2 * @factor) particle.y -= Gosu::offset_y(@angle-90, 2 * @factor) } end |
#rotate_right ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/lunar_lander/game_objects/player.rb', line 39 def rotate_right @angle += 0.5 Chingu::Particle.create( :x => @x + Gosu::offset_x(@angle - 60, 20 * @factor), :y => @y + Gosu::offset_y(@angle - 60, 20 * @factor), :animation => @particle_animation, :scale_rate => -0.03, :fade_rate => -35, :rotation_rate => +1, :mode => :default, :factor => @factor / 2 ) Chingu::Particle.each { |particle| particle.x -= Gosu::offset_x(@angle+90, 2 * @factor) particle.y -= Gosu::offset_y(@angle+90, 2 * @factor) } end |
#setup ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/lunar_lander/game_objects/player.rb', line 8 def setup @x = $window.width / 2 @y = $window.height / 2 self.image = Gosu::Image["player.png"] @engine_sound = Gosu::Sound["fierce_wind.wav"].play(1, 1, true) @engine_sound.pause self.acceleration_y = 0.01 self.velocity_y = 1 @particle_animation = Chingu::Animation.new(:file => "particle.png", :size => [32, 32]) @fuel = 100.0 end |
#should_die? ⇒ Boolean
98 99 100 |
# File 'lib/lunar_lander/game_objects/player.rb', line 98 def should_die? velocity_x > 0.5 or velocity_y > 0.4 or angle.abs > 5 end |
#stop ⇒ Object
88 89 90 91 |
# File 'lib/lunar_lander/game_objects/player.rb', line 88 def stop self.velocity_x = 0 self.velocity_y = 0 end |
#stop_engine ⇒ Object
84 85 86 |
# File 'lib/lunar_lander/game_objects/player.rb', line 84 def stop_engine @engine_sound.pause end |
#thrust ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/lunar_lander/game_objects/player.rb', line 58 def thrust if @fuel > 0 self.velocity_x += Gosu::offset_x(@angle, 0.05) self.velocity_y += Gosu::offset_y(@angle, 0.05) Chingu::Particle.create( :x => @x - Gosu::offset_x(@angle, 20 * @factor), :y => @y - Gosu::offset_y(@angle, 20 * @factor), :animation => @particle_animation, :scale_rate => -0.03, :fade_rate => -35, :rotation_rate => +1, :mode => :default, :factor => @factor ) Chingu::Particle.each { |particle| particle.x -= Gosu::offset_x(@angle, 10 * @factor + rand(4)) particle.y -= Gosu::offset_y(@angle, 10 * @factor + rand(4)) } @engine_sound.resume unless @engine_sound. @fuel -= 0.5 end end |
#update ⇒ Object
102 103 104 105 |
# File 'lib/lunar_lander/game_objects/player.rb', line 102 def update super @engine_sound.stop if @fuel == 0 end |