Class: LunarLander::Play
- Inherits:
-
Chingu::GameState
- Object
- Chingu::GameState
- LunarLander::Play
- Defined in:
- lib/lunar_lander/game_states/play.rb
Instance Method Summary collapse
- #draw ⇒ Object
- #setup ⇒ Object
- #setup_hud ⇒ Object
- #test_colision ⇒ Object
- #update ⇒ Object
- #update_hud ⇒ Object
Instance Method Details
#draw ⇒ Object
56 57 58 59 60 |
# File 'lib/lunar_lander/game_states/play.rb', line 56 def draw super @background.draw(0,0,0) end |
#setup ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/lunar_lander/game_states/play.rb', line 3 def setup self.input = { :p => LunarLander::Pause } @player = Player.create({ :x => $window.width/2, :y => $window.height/2}) @player.input = {:holding_left => :rotate_left, :holding_right => :rotate_right, :holding_up => :thrust, :released_up => :stop_engine} @background = Gosu::Image["moon.png"] @surface = Chingu::Rect.new(0, $window.height-50, 800, 50) setup_hud end |
#setup_hud ⇒ Object
29 30 31 32 33 34 |
# File 'lib/lunar_lander/game_states/play.rb', line 29 def setup_hud @velocity_x_text = Chingu::Text.create("Velocidade Lateral: 0", :x => 10, :y => 10, :zorder => 55, :size=>20) @velocity_y_text = Chingu::Text.create("Velocidade Vertical: 0", :x => 10, :y => 30, :zorder => 55, :size=>20) @angle_text = Chingu::Text.create("Ângulo: 0", :x => 10, :y => 50, :zorder => 55, :size=>20) @fuel_text = Chingu::Text.create("Combustível: #{@player.fuel}", :x => 10, :y => 70, :zorder => 55, :size=>20) end |
#test_colision ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/lunar_lander/game_states/play.rb', line 45 def test_colision if @player.bounding_box.collide_rect?(@surface) if @player.should_die? @player.die switch_game_state LunarLander::Gameover end @player.stop end end |
#update ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/lunar_lander/game_states/play.rb', line 15 def update super game_objects.destroy_if { |object| if object.kind_of? Chingu::Particle object.outside_window? || object.color.alpha == 0 end } test_colision update_hud end |
#update_hud ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/lunar_lander/game_states/play.rb', line 36 def update_hud if @player @velocity_x_text.text = "Velocidade Lateral: #{(@player.velocity_x * 10).ceil.abs}" @velocity_y_text.text = "Velocidade Vertical: #{(@player.velocity_y * 10).ceil * -1}" @angle_text.text = "Ângulo: #{@player.angle}" @fuel_text.text = "Combustível: #{@player.fuel.ceil}" end end |