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
-
#initialize(options = {}) ⇒ Player
constructor
A new instance of Player.
- #rotate_left ⇒ Object
- #rotate_right ⇒ Object
- #setup ⇒ Object
- #should_die? ⇒ Boolean
- #stop ⇒ Object
- #stop_engine ⇒ Object
- #thrust ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Player
Returns a new instance of Player.
8 9 10 |
# File 'lib/lunar_lander/game_objects/player.rb', line 8 def initialize(={}) super(.merge(:image => Gosu::Image["player.png"])) end |
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
92 93 94 95 |
# File 'lib/lunar_lander/game_objects/player.rb', line 92 def die @engine_sound.stop Gosu::Sound["explosion.wav"].play end |
#rotate_left ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/lunar_lander/game_objects/player.rb', line 21 def rotate_left @angle -= 0.5 Chingu::Particle.create( :x => @x + Gosu::offset_x(@angle + 60, 20), :y => @y + Gosu::offset_y(@angle + 60, 20), :animation => @particle_animation, :scale_rate => -0.03, :fade_rate => -35, :rotation_rate => +1, :mode => :default, :factor => 0.5 ) Chingu::Particle.each { |particle| particle.y -= Gosu::offset_y(@angle-90, 2) particle.x -= Gosu::offset_x(@angle-90, 2) } end |
#rotate_right ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/lunar_lander/game_objects/player.rb', line 40 def rotate_right @angle += 0.5 Chingu::Particle.create( :x => @x + Gosu::offset_x(@angle - 60, 20), :y => @y + Gosu::offset_y(@angle - 60, 20), :animation => @particle_animation, :scale_rate => -0.03, :fade_rate => -35, :rotation_rate => +1, :mode => :default, :factor => 0.5 ) Chingu::Particle.each { |particle| particle.y -= Gosu::offset_y(@angle+90, 2) particle.x -= Gosu::offset_x(@angle+90, 2) } end |
#setup ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/lunar_lander/game_objects/player.rb', line 12 def setup @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
97 98 99 |
# File 'lib/lunar_lander/game_objects/player.rb', line 97 def should_die? velocity_x > 0.5 or velocity_y > 0.4 or angle.abs > 5 end |
#stop ⇒ Object
87 88 89 90 |
# File 'lib/lunar_lander/game_objects/player.rb', line 87 def stop self.velocity_x = 0 self.velocity_y = 0 end |
#stop_engine ⇒ Object
83 84 85 |
# File 'lib/lunar_lander/game_objects/player.rb', line 83 def stop_engine @engine_sound.pause end |
#thrust ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/lunar_lander/game_objects/player.rb', line 59 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), :y => @y - Gosu::offset_y(@angle, 20), :animation => @particle_animation, :scale_rate => -0.03, :fade_rate => -35, :rotation_rate => +1, :mode => :default ) Chingu::Particle.each { |particle| particle.y -= Gosu::offset_y(@angle, 10 + rand(4)) particle.x -= Gosu::offset_x(@angle, 10 + rand(4)) } @engine_sound.resume unless @engine_sound. @fuel -= 0.5 end end |
#update ⇒ Object
101 102 103 104 105 |
# File 'lib/lunar_lander/game_objects/player.rb', line 101 def update super @x %= $window.width #@y %= 480 end |