Class: PlayerInput
- Defined in:
- lib/entities/components/player_input.rb
Constant Summary collapse
- NAME_COLOR =
Dark green
Gosu::Color.argb(0xee084408)
Instance Attribute Summary collapse
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
Attributes inherited from Component
Instance Method Summary collapse
- #control(obj) ⇒ Object
- #draw(viewport) ⇒ Object
-
#initialize(name, camera, object_pool) ⇒ PlayerInput
constructor
A new instance of PlayerInput.
- #on_collision(with) ⇒ Object
- #on_damage(amount) ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(name, camera, object_pool) ⇒ PlayerInput
Returns a new instance of PlayerInput.
6 7 8 9 10 11 12 |
# File 'lib/entities/components/player_input.rb', line 6 def initialize(name, camera, object_pool) super(nil) @name = name @stats = Stats.new(name) @camera = camera @object_pool = object_pool end |
Instance Attribute Details
#stats ⇒ Object (readonly)
Returns the value of attribute stats.
4 5 6 |
# File 'lib/entities/components/player_input.rb', line 4 def stats @stats end |
Instance Method Details
#control(obj) ⇒ Object
14 15 16 17 |
# File 'lib/entities/components/player_input.rb', line 14 def control(obj) self.object = obj obj.components << self end |
#draw(viewport) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/entities/components/player_input.rb', line 47 def draw() @name_image ||= Gosu::Image.from_text( $window, @name, Gosu.default_font_name, 20) @name_image.draw( x - @name_image.width / 2 - 1, y + object.graphics.height / 2, 100, 1, 1, Gosu::Color::WHITE) @name_image.draw( x - @name_image.width / 2, y + object.graphics.height / 2, 100, 1, 1, NAME_COLOR) end |
#on_collision(with) ⇒ Object
19 20 |
# File 'lib/entities/components/player_input.rb', line 19 def on_collision(with) end |
#on_damage(amount) ⇒ Object
22 23 24 |
# File 'lib/entities/components/player_input.rb', line 22 def on_damage(amount) @stats.add_damage(amount) end |
#update ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/entities/components/player_input.rb', line 26 def update return respawn if object.health.dead? d_x, d_y = @camera.target_delta_on_screen atan = Math.atan2(($window.width / 2) - d_x - $window.mouse_x, ($window.height / 2) - d_y - $window.mouse_y) object.gun_angle = -atan * 180 / Math::PI = [Gosu::KbW, Gosu::KbS, Gosu::KbA, Gosu::KbD] if (*) object.throttle_down = true object.physics.change_direction( change_angle(object.direction, *)) else object.throttle_down = false end if Utils.(Gosu::MsLeft) object.shoot(*@camera.mouse_coords) end end |